Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/commands.c @ 2266:bdee1ede7572
Filter out pgp_passphrase as well
Refactor do_set() a little bit.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 07 May 2016 21:12:10 +0200 |
parents | b79a34e21076 |
children | f5402d705f67 |
comparison
equal
deleted
inserted
replaced
2265:b79a34e21076 | 2266:bdee1ede7572 |
---|---|
2301 update_roster = TRUE; | 2301 update_roster = TRUE; |
2302 } | 2302 } |
2303 | 2303 |
2304 static void list_option_cb(char *k, char *v, void *f) | 2304 static void list_option_cb(char *k, char *v, void *f) |
2305 { | 2305 { |
2306 if (strcmp(k, "password")) { | 2306 if (strncmp(k, "password", 8) && strcmp(k, "pgp_passphrase")) { |
2307 GSList **list = f; | 2307 GSList **list = f; |
2308 *list = g_slist_insert_sorted(*list, k, (GCompareFunc)strcmp); | 2308 *list = g_slist_insert_sorted(*list, k, (GCompareFunc)strcmp); |
2309 } | 2309 } |
2310 } | 2310 } |
2311 | 2311 |
2314 guint assign; | 2314 guint assign; |
2315 gchar *option, *value; | 2315 gchar *option, *value; |
2316 gchar *option_utf8; | 2316 gchar *option_utf8; |
2317 | 2317 |
2318 if (!*arg) { | 2318 if (!*arg) { |
2319 // list all set options | 2319 // List all set options |
2320 gsize max = 0; | |
2321 gsize maxmax = scr_gettextwidth() / 3; | |
2322 GSList *lel; | |
2323 gchar *format; | |
2320 GSList *list = NULL; | 2324 GSList *list = NULL; |
2321 // Get sorted list of keys | 2325 // Get sorted list of keys |
2322 settings_foreach(SETTINGS_TYPE_OPTION, list_option_cb, &list); | 2326 settings_foreach(SETTINGS_TYPE_OPTION, list_option_cb, &list); |
2323 if (list) { | 2327 if (!list) { |
2324 gsize max = 0; | 2328 scr_LogPrint(LPRINT_NORMAL, "No options found."); |
2325 gsize maxmax = scr_gettextwidth() / 3; | 2329 return; |
2326 GSList *lel; | 2330 } |
2327 gchar *format; | 2331 // Find out maximum key length |
2328 // Find out maximum key length | 2332 for (lel = list; lel; lel = lel->next) { |
2329 for (lel = list; lel; lel = lel->next) { | 2333 const gchar *key = lel->data; |
2330 const gchar *key = lel->data; | 2334 gsize len = strlen(key); |
2331 gsize len = strlen(key); | 2335 if (len > max) { |
2332 if (len > max) { | 2336 max = len; |
2333 max = len; | 2337 if (max > maxmax) { |
2334 if (max > maxmax) { | 2338 max = maxmax; |
2335 max = maxmax; | 2339 break; |
2336 break; | |
2337 } | |
2338 } | 2340 } |
2339 } | 2341 } |
2340 // Print out list of options | 2342 } |
2341 format = g_strdup_printf("%%-%us = [%%s]", (unsigned)max); | 2343 // Print out list of options |
2342 for (lel = list; lel; lel = lel->next) { | 2344 format = g_strdup_printf("%%-%us = [%%s]", (unsigned)max); |
2343 const gchar *key = lel->data; | 2345 for (lel = list; lel; lel = lel->next) { |
2344 if (g_ascii_strncasecmp(key, "password", 8) != 0) | 2346 const gchar *key = lel->data; |
2345 scr_LogPrint(LPRINT_NORMAL, format, key, settings_opt_get(key)); | 2347 scr_LogPrint(LPRINT_NORMAL, format, key, settings_opt_get(key)); |
2346 } | 2348 } |
2347 g_free(format); | 2349 g_free(format); |
2348 scr_setmsgflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE); | 2350 scr_setmsgflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE); |
2349 scr_setattentionflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE, | 2351 scr_setattentionflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE, |
2350 ROSTER_UI_PRIO_STATUS_WIN_MESSAGE, prio_max); | 2352 ROSTER_UI_PRIO_STATUS_WIN_MESSAGE, prio_max); |
2351 } else { | |
2352 scr_LogPrint(LPRINT_NORMAL, "No options found."); | |
2353 } | |
2354 return; | 2353 return; |
2355 } | 2354 } |
2356 | 2355 |
2357 assign = parse_assigment(arg, &option, &value); | 2356 assign = parse_assigment(arg, &option, &value); |
2358 if (!option) { | 2357 if (!option) { |
2362 option_utf8 = to_utf8(option); | 2361 option_utf8 = to_utf8(option); |
2363 g_free(option); | 2362 g_free(option); |
2364 if (!assign) { // This is a query | 2363 if (!assign) { // This is a query |
2365 const gchar *val = settings_opt_get(option_utf8); | 2364 const gchar *val = settings_opt_get(option_utf8); |
2366 if (val) { | 2365 if (val) { |
2367 if (g_ascii_strncasecmp(option_utf8, "password", 8) == 0) | 2366 if (g_ascii_strncasecmp(option_utf8, "password", 8) == 0 || |
2368 val = NULL; | 2367 g_ascii_strcasecmp(option_utf8, "pgp_passphrase") == 0) |
2368 val = "***"; | |
2369 scr_LogPrint(LPRINT_NORMAL, "%s = [%s]", option_utf8, val); | 2369 scr_LogPrint(LPRINT_NORMAL, "%s = [%s]", option_utf8, val); |
2370 } else { | 2370 } else { |
2371 scr_LogPrint(LPRINT_NORMAL, "Option %s is not set", option_utf8); | 2371 scr_LogPrint(LPRINT_NORMAL, "Option %s is not set", option_utf8); |
2372 } | 2372 } |
2373 g_free(option_utf8); | 2373 g_free(option_utf8); |