diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 7bc19040..098d192f 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -5233,54 +5233,43 @@ cmd_console(ProfWin* window, const char* const command, gchar** args) gboolean cmd_presence(ProfWin* window, const char* const command, gchar** args) { - if (strcmp(args[0], "console") != 0 && strcmp(args[0], "chat") != 0 && strcmp(args[0], "room") != 0 && strcmp(args[0], "titlebar") != 0) { - cons_bad_cmd_usage(command); - return TRUE; - } - if (strcmp(args[0], "titlebar") == 0) { _cmd_set_boolean_preference(args[1], "Contact presence", PREF_PRESENCE); return TRUE; } - if (strcmp(args[1], "all") != 0 && strcmp(args[1], "online") != 0 && strcmp(args[1], "none") != 0) { + const struct presence_preferences + { + preference_t pref; + const char *name, *description; + } presence_prefs[] = { + { .pref = PREF_STATUSES_CONSOLE, .name = "console", .description = "the console" }, + { .pref = PREF_STATUSES_CHAT, .name = "chat", .description = "chat windows" }, + { .pref = PREF_STATUSES_MUC, .name = "room", .description = "chat room windows" }, + }; + size_t n = 0; + for (; n < ARRAY_SIZE(presence_prefs); ++n) { + const struct presence_preferences* pp = &presence_prefs[n]; + if (g_strcmp0(args[0], pp->name) != 0) + continue; + if (strcmp(args[1], "all") == 0) { + cons_show("All presence updates will appear in %s.", pp->description); + } else if (strcmp(args[1], "online") == 0) { + cons_show("Only %s presence updates will appear in %s.", + pp->pref == PREF_STATUSES_MUC ? "join/leave" : "online/offline", + pp->description); + } else if (strcmp(args[1], "none") == 0) { + cons_show("Presence updates will not appear in %s.", pp->description); + } else { + cons_bad_cmd_usage(command); + return TRUE; + } + prefs_set_string(pp->pref, args[1]); + break; + } + if (n == ARRAY_SIZE(presence_prefs)) { cons_bad_cmd_usage(command); - return TRUE; } - - if (strcmp(args[0], "console") == 0) { - prefs_set_string(PREF_STATUSES_CONSOLE, args[1]); - if (strcmp(args[1], "all") == 0) { - cons_show("All presence updates will appear in the console."); - } else if (strcmp(args[1], "online") == 0) { - cons_show("Only online/offline presence updates will appear in the console."); - } else { - cons_show("Presence updates will not appear in the console."); - } - } - - if (strcmp(args[0], "chat") == 0) { - prefs_set_string(PREF_STATUSES_CHAT, args[1]); - if (strcmp(args[1], "all") == 0) { - cons_show("All presence updates will appear in chat windows."); - } else if (strcmp(args[1], "online") == 0) { - cons_show("Only online/offline presence updates will appear in chat windows."); - } else { - cons_show("Presence updates will not appear in chat windows."); - } - } - - if (strcmp(args[0], "room") == 0) { - prefs_set_string(PREF_STATUSES_MUC, args[1]); - if (strcmp(args[1], "all") == 0) { - cons_show("All presence updates will appear in chat room windows."); - } else if (strcmp(args[1], "online") == 0) { - cons_show("Only join/leave presence updates will appear in chat room windows."); - } else { - cons_show("Presence updates will not appear in chat room windows."); - } - } - return TRUE; } @@ -5314,7 +5303,8 @@ cmd_time(ProfWin* window, const char* const command, gchar** args) }; gboolean redraw = FALSE; gboolean set_all = g_strcmp0(args[0], "all") == 0; - for (size_t n = 0; n < ARRAY_SIZE(time_prefs); ++n) { + size_t n = 0; + for (; n < ARRAY_SIZE(time_prefs); ++n) { if (!set_all && g_strcmp0(args[0], time_prefs[n].name) != 0) continue; const struct time_preferences* tp = &time_prefs[n]; @@ -5355,6 +5345,9 @@ cmd_time(ProfWin* window, const char* const command, gchar** args) return TRUE; } } + if (!set_all && n == ARRAY_SIZE(time_prefs)) { + cons_bad_cmd_usage(command); + } if (redraw) ui_redraw(); return TRUE; diff --git a/src/tools/aesgcm_download.c b/src/tools/aesgcm_download.c index e12b6987..6daece5b 100644 --- a/src/tools/aesgcm_download.c +++ b/src/tools/aesgcm_download.c @@ -140,6 +140,9 @@ aesgcm_file_get(void* userdata) "Downloading '%s' failed: Failed to decrypt " "file (%s).", https_url, gcry_strerror(crypt_res)); + } else { + http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, + "Decrypted file saved to '%s'", aesgcm_dl->filename); } if (aesgcm_dl->cmd_template != NULL) { diff --git a/src/ui/window_list.c b/src/ui/window_list.c index 7ddf4bf5..5735f019 100644 --- a/src/ui/window_list.c +++ b/src/ui/window_list.c @@ -258,22 +258,20 @@ GList* wins_get_private_chats(const char* const roomjid) { GList* result = NULL; - GString* prefix = g_string_new(roomjid); - g_string_append(prefix, "/"); + auto_gchar gchar* prefix = g_strdup_printf("%s/", roomjid); GList* curr = values; while (curr) { ProfWin* window = curr->data; if (window->type == WIN_PRIVATE) { ProfPrivateWin* privatewin = (ProfPrivateWin*)window; - if (roomjid == NULL || g_str_has_prefix(privatewin->fulljid, prefix->str)) { + if (roomjid == NULL || g_str_has_prefix(privatewin->fulljid, prefix)) { result = g_list_append(result, privatewin); } } curr = g_list_next(curr); } - g_string_free(prefix, TRUE); return result; } @@ -1067,19 +1065,13 @@ wins_create_summary(gboolean unread) while (curr) { ProfWin* window = g_hash_table_lookup(windows, curr->data); if (!unread || (unread && win_unread(window) > 0)) { - GString* line = g_string_new(""); - int ui_index = GPOINTER_TO_INT(curr->data); auto_gchar gchar* winstring = win_to_string(window); if (!winstring) { - g_string_free(line, TRUE); continue; } - - g_string_append_printf(line, "%d: %s", ui_index, winstring); - - result = g_slist_append(result, strdup(line->str)); - g_string_free(line, TRUE); + gchar* line = g_strdup_printf("%d: %s", ui_index, winstring); + result = g_slist_append(result, line); } curr = g_list_next(curr); @@ -1108,19 +1100,13 @@ wins_create_summary_attention() has_attention = mucwin->has_attention; } if (has_attention) { - GString* line = g_string_new(""); - int ui_index = GPOINTER_TO_INT(curr->data); auto_gchar gchar* winstring = win_to_string(window); if (!winstring) { - g_string_free(line, TRUE); continue; } - - g_string_append_printf(line, "%d: %s", ui_index, winstring); - - result = g_slist_append(result, strdup(line->str)); - g_string_free(line, TRUE); + gchar* line = g_strdup_printf("%d: %s", ui_index, winstring); + result = g_slist_append(result, line); } curr = g_list_next(curr); } diff --git a/src/xmpp/jid.c b/src/xmpp/jid.c index 1f3b1a66..6b5bb62c 100644 --- a/src/xmpp/jid.c +++ b/src/xmpp/jid.c @@ -190,7 +190,7 @@ get_nick_from_full_jid(const char* const full_room_jid) /* * get the fulljid, fall back to the barejid */ -char* +const char* jid_fulljid_or_barejid(Jid* jid) { if (jid->fulljid) { diff --git a/src/xmpp/jid.h b/src/xmpp/jid.h index 8c1b683d..a591b743 100644 --- a/src/xmpp/jid.h +++ b/src/xmpp/jid.h @@ -63,7 +63,7 @@ gboolean jid_is_valid_room_form(Jid* jid); char* create_fulljid(const char* const barejid, const char* const resource); char* get_nick_from_full_jid(const char* const full_room_jid); -char* jid_fulljid_or_barejid(Jid* jid); +const char* jid_fulljid_or_barejid(Jid* jid); gchar* jid_random_resource(void); #endif diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 56cbb379..05123d08 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -621,7 +621,7 @@ _available_handler(xmpp_stanza_t* const stanza) } return; } else { - char* jid = jid_fulljid_or_barejid(xmpp_presence->jid); + const char* jid = jid_fulljid_or_barejid(xmpp_presence->jid); log_debug("Presence available handler fired for: %s", jid); } @@ -632,7 +632,7 @@ _available_handler(xmpp_stanza_t* const stanza) XMPPCaps* caps = stanza_parse_caps(stanza); if ((g_strcmp0(my_jid->fulljid, xmpp_presence->jid->fulljid) != 0) && caps) { log_debug("Presence contains capabilities."); - char* jid = jid_fulljid_or_barejid(xmpp_presence->jid); + const char* jid = jid_fulljid_or_barejid(xmpp_presence->jid); _handle_caps(jid, caps); } stanza_free_caps(caps); diff --git a/src/xmpp/roster_list.c b/src/xmpp/roster_list.c index 40b8210d..771c7af1 100644 --- a/src/xmpp/roster_list.c +++ b/src/xmpp/roster_list.c @@ -275,11 +275,8 @@ roster_remove(const char* const name, const char* const barejid) if (contact) { GList* resources = p_contact_get_available_resources(contact); while (resources) { - GString* fulljid = g_string_new(barejid); - g_string_append(fulljid, "/"); - g_string_append(fulljid, resources->data); - autocomplete_remove(roster->fulljid_ac, fulljid->str); - g_string_free(fulljid, TRUE); + auto_gchar gchar* fulljid = g_strdup_printf("%s/%s", barejid, (char*)resources->data); + autocomplete_remove(roster->fulljid_ac, fulljid); resources = g_list_next(resources); } g_list_free(resources); diff --git a/tests/unittests/test_jid.c b/tests/unittests/test_jid.c index 2650d5da..645a7b0a 100644 --- a/tests/unittests/test_jid.c +++ b/tests/unittests/test_jid.c @@ -219,7 +219,7 @@ returns_fulljid_when_exists(void** state) { Jid* jid = jid_create("localpart@domainpart/resourcepart"); - char* result = jid_fulljid_or_barejid(jid); + const char* result = jid_fulljid_or_barejid(jid); assert_string_equal("localpart@domainpart/resourcepart", result); @@ -231,7 +231,7 @@ returns_barejid_when_fulljid_not_exists(void** state) { Jid* jid = jid_create("localpart@domainpart"); - char* result = jid_fulljid_or_barejid(jid); + const char* result = jid_fulljid_or_barejid(jid); assert_string_equal("localpart@domainpart", result);