mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-18 00:56:21 +00:00
fix(autocomplete): guard history completion safely
Prevent autocomplete crashes on asset failures when executing history subcommands without an active connection by validating the session state beforehand. Standardize JID resolution across command handlers to ensure consistent contact lookup behavior. Use auto_gchar gchar instead of GString for performance and readability purposes.
This commit is contained in:
@@ -1866,12 +1866,14 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ
|
||||
}
|
||||
|
||||
gchar* history_jid_subcmds[] = { "/history verify", "/history export", "/history import" };
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
for (size_t i = 0; i < ARRAY_SIZE(history_jid_subcmds); i++) {
|
||||
result = autocomplete_param_with_func(input, history_jid_subcmds[i], roster_barejid_autocomplete, previous, NULL);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = autocomplete_param_with_ac(input, "/history", history_ac, TRUE, previous);
|
||||
if (result) {
|
||||
@@ -3735,7 +3737,7 @@ _win_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
}
|
||||
|
||||
char* unquoted = strip_arg_quotes(input);
|
||||
result = autocomplete_param_with_func(unquoted, "/win", roster_contact_autocomplete, previous, NULL);
|
||||
result = _roster_jid_autocomplete(input, "/win", previous);
|
||||
free(unquoted);
|
||||
return result;
|
||||
}
|
||||
@@ -4230,14 +4232,12 @@ _software_autocomplete(ProfWin* window, const char* const input, gboolean previo
|
||||
{
|
||||
char* result = NULL;
|
||||
|
||||
if (window->type == WIN_CHAT) {
|
||||
if (window->type == WIN_CHAT && _is_connected()) {
|
||||
ProfChatWin* chatwin = (ProfChatWin*)window;
|
||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||
|
||||
GString* search_str = g_string_new("/software ");
|
||||
g_string_append(search_str, chatwin->barejid);
|
||||
result = autocomplete_param_with_func(search_str->str, "/software", roster_fulljid_autocomplete, previous, NULL);
|
||||
g_string_free(search_str, TRUE);
|
||||
auto_gchar gchar* search_str = g_strdup_printf("/software %s", chatwin->barejid);
|
||||
result = autocomplete_param_with_func(search_str, "/software", roster_fulljid_autocomplete, previous, NULL);
|
||||
} else if (window->type == WIN_MUC) {
|
||||
ProfMucWin* mucwin = (ProfMucWin*)window;
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
|
||||
Reference in New Issue
Block a user