diff --git a/prof.supp b/prof.supp index e456551b..4f182054 100644 --- a/prof.supp +++ b/prof.supp @@ -12,9 +12,7 @@ otrl_init Memcheck:Leak ... - fun:_otr_init - fun:_init - fun:prof_run + fun:otrl_init ... } diff --git a/src/command/command.c b/src/command/command.c index 82f6a4b0..2f4fb8d2 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -398,7 +398,7 @@ static struct cmd_t command_defs[] = CMD_SYN( "/group", "/group show ", - "/group add " + "/group add ", "/group remove ") CMD_DESC( "View, add to, and remove from roster groups. " diff --git a/src/command/commands.c b/src/command/commands.c index 79b4def9..093bc43d 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -5160,7 +5160,7 @@ cmd_log(ProfWin *window, const char *const command, gchar **args) gboolean res = strtoi_range(value, &intval, PREFS_MIN_LOG_SIZE, INT_MAX, &err_msg); if (res) { prefs_set_max_log_size(intval); - cons_show("Log maxinum size set to %d bytes", intval); + cons_show("Log maximum size set to %d bytes", intval); } else { cons_show(err_msg); free(err_msg); diff --git a/src/config/tlscerts.c b/src/config/tlscerts.c index 87e88cfa..c0c691a4 100644 --- a/src/config/tlscerts.c +++ b/src/config/tlscerts.c @@ -411,6 +411,8 @@ tlscerts_free(TLSCertificate *cert) free(cert->key_alg); free(cert->signature_alg); + + free(cert); } } diff --git a/src/plugins/api.c b/src/plugins/api.c index 495a0d58..e81467a9 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -197,6 +197,17 @@ api_get_current_muc(void) } } +int +api_current_win_is_console(void) +{ + ProfWin *current = wins_get_current(); + if (current && current->type == WIN_CONSOLE) { + return 1; + } else { + return 0; + } +} + void api_log_debug(const char *message) { @@ -228,12 +239,16 @@ api_win_exists(const char *tag) } void -api_win_create(const char *tag, void *callback, +api_win_create( + const char *tag, + void *callback, + void(*destroy)(void *callback), void(*callback_func)(PluginWindowCallback *window_callback, const char *tag, const char * const line)) { PluginWindowCallback *window = malloc(sizeof(PluginWindowCallback)); window->callback = callback; window->callback_func = callback_func; + window->destroy = destroy; callbacks_add_window_handler(tag, window); wins_new_plugin(tag); diff --git a/src/plugins/api.h b/src/plugins/api.h index 3f1b7d1c..6494097e 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -43,8 +43,10 @@ int api_cons_show_themed(const char *const group, const char *const item, const int api_cons_bad_cmd_usage(const char *const cmd); void api_notify(const char *message, const char *category, int timeout_ms); void api_send_line(char *line); + char * api_get_current_recipient(void); char * api_get_current_muc(void); +gboolean api_current_win_is_console(void); void api_register_command(const char *command_name, int min_args, int max_args, const char **synopsis, const char *description, const char *arguments[][2], const char **examples, @@ -59,7 +61,10 @@ void api_log_warning(const char *message); void api_log_error(const char *message); int api_win_exists(const char *tag); -void api_win_create(const char *tag, void *callback, +void api_win_create( + const char *tag, + void *callback, + void(*destroy)(void *callback), void(*callback_func)(PluginWindowCallback *window_callback, char *tag, char *line)); int api_win_focus(const char *tag); int api_win_show(const char *tag, const char *line); diff --git a/src/plugins/autocompleters.c b/src/plugins/autocompleters.c index 631987b1..483af7ca 100644 --- a/src/plugins/autocompleters.c +++ b/src/plugins/autocompleters.c @@ -67,10 +67,12 @@ autocompleters_complete(const char * const input) while (curr) { result = autocomplete_param_with_ac(input, curr->data, g_hash_table_lookup(autocompleters, curr->data), TRUE); if (result) { + g_list_free(keys); return result; } curr = g_list_next(curr); } + g_list_free(keys); return NULL; } @@ -84,6 +86,8 @@ autocompleters_reset(void) autocomplete_reset(curr->data); curr = g_list_next(curr); } + + g_list_free(acs); } void autocompleters_destroy(void) diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index e2b7517a..f2cce6a6 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -126,6 +126,12 @@ c_api_get_current_muc(void) return api_get_current_muc(); } +static int +c_api_current_win_is_console() +{ + return api_current_win_is_console(); +} + static void c_api_log_debug(const char *message) { @@ -161,7 +167,7 @@ c_api_win_create(char *tag, void(*callback)(char *tag, char *line)) { WindowWrapper *wrapper = malloc(sizeof(WindowWrapper)); wrapper->func = callback; - api_win_create(tag, wrapper, c_window_callback); + api_win_create(tag, wrapper, free, c_window_callback); } static int @@ -220,6 +226,7 @@ c_api_init(void) prof_send_line = c_api_send_line; prof_get_current_recipient = c_api_get_current_recipient; prof_get_current_muc = c_api_get_current_muc; + prof_current_win_is_console = c_api_current_win_is_console; prof_log_debug = c_api_log_debug; prof_log_info = c_api_log_info; prof_log_warning = c_api_log_warning; diff --git a/src/plugins/callbacks.c b/src/plugins/callbacks.c index a3cbfc1d..6f796259 100644 --- a/src/plugins/callbacks.c +++ b/src/plugins/callbacks.c @@ -46,6 +46,27 @@ static GSList *p_commands = NULL; static GSList *p_timed_functions = NULL; static GHashTable *p_window_callbacks = NULL; +static void +_free_window_callback(PluginWindowCallback *window_callback) +{ + if (window_callback->destroy) { + window_callback->destroy(window_callback->callback); + } + free(window_callback); +} + +void +callbacks_init(void) +{ + p_window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_window_callback); +} + +void +callbacks_close(void) +{ + g_hash_table_destroy(p_window_callbacks); +} + void callbacks_add_command(PluginCommand *command) { @@ -64,10 +85,6 @@ callbacks_add_timed(PluginTimedFunction *timed_function) void callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback) { - if (p_window_callbacks == NULL) { - p_window_callbacks = g_hash_table_new(g_str_hash, g_str_equal); - } - g_hash_table_insert(p_window_callbacks, strdup(tag), window_callback); } diff --git a/src/plugins/callbacks.h b/src/plugins/callbacks.h index 09dc0375..dc6b78bb 100644 --- a/src/plugins/callbacks.h +++ b/src/plugins/callbacks.h @@ -57,9 +57,13 @@ typedef struct p_timed_function { typedef struct p_window_input_callback { void *callback; + void (*destroy)(void *callback); void (*callback_func)(struct p_window_input_callback *window_callback, const char *tag, const char * const line); } PluginWindowCallback; +void callbacks_init(void); +void callbacks_close(void); + void callbacks_add_command(PluginCommand *command); void callbacks_add_timed(PluginTimedFunction *timed_function); void callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback); diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index 20293c88..c1c7df3a 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -57,6 +57,7 @@ void plugins_init(void) { plugins = NULL; + callbacks_init(); autocompleters_init(); plugin_themes_init(); @@ -404,6 +405,7 @@ plugins_shutdown(void) autocompleters_destroy(); plugin_themes_close(); + callbacks_close(); } gchar * diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index 5157ec72..84670c33 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -56,6 +56,7 @@ void (*prof_send_line)(char *line) = NULL; char* (*prof_get_current_recipient)(void) = NULL; char* (*prof_get_current_muc)(void) = NULL; +int (*prof_current_win_is_console)(void) = NULL; void (*prof_log_debug)(const char *message) = NULL; void (*prof_log_info)(const char *message) = NULL; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index 1be99820..77288f94 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -56,6 +56,7 @@ void (*prof_send_line)(char *line); char* (*prof_get_current_recipient)(void); char* (*prof_get_current_muc)(void); +int (*prof_current_win_is_console)(void); void (*prof_log_debug)(const char *message); void (*prof_log_info)(const char *message); diff --git a/src/ui/window.c b/src/ui/window.c index 585c0b21..f52ebc41 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -350,7 +350,7 @@ win_get_string(ProfWin *window) { ProfPluginWin *pluginwin = (ProfPluginWin*)window; GString *gstring = g_string_new(""); - g_string_append_printf(gstring, "%s plugin", pluginwin->tag); + g_string_append_printf(gstring, "Plugin: %s", pluginwin->tag); char *res = gstring->str; g_string_free(gstring, FALSE); return res; @@ -419,27 +419,42 @@ win_free(ProfWin* window) } free(window->layout); - if (window->type == WIN_CHAT) { + switch (window->type) { + case WIN_CHAT: + { ProfChatWin *chatwin = (ProfChatWin*)window; free(chatwin->barejid); free(chatwin->resource_override); chat_state_free(chatwin->state); + break; } - - if (window->type == WIN_MUC) { + case WIN_MUC: + { ProfMucWin *mucwin = (ProfMucWin*)window; free(mucwin->roomjid); + break; } - - if (window->type == WIN_MUC_CONFIG) { + case WIN_MUC_CONFIG: + { ProfMucConfWin *mucconf = (ProfMucConfWin*)window; free(mucconf->roomjid); form_destroy(mucconf->form); + break; } - - if (window->type == WIN_PRIVATE) { + case WIN_PRIVATE: + { ProfPrivateWin *privatewin = (ProfPrivateWin*)window; free(privatewin->fulljid); + break; + } + case WIN_PLUGIN: + { + ProfPluginWin *pluginwin = (ProfPluginWin*)window; + free(pluginwin->tag); + break; + } + default: + break; } free(window); diff --git a/src/window_list.c b/src/window_list.c index 35f49fdd..9e4ede98 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -212,6 +212,7 @@ wins_get_plugin(const char *const tag) if (window->type == WIN_PLUGIN) { ProfPluginWin *pluginwin = (ProfPluginWin*)window; if (g_strcmp0(pluginwin->tag, tag) == 0) { + g_list_free(values); return pluginwin; } } @@ -389,6 +390,11 @@ wins_get_by_string(char *str) return (ProfWin*)privwin; } + ProfPluginWin *pluginwin = wins_get_plugin(str); + if (pluginwin) { + return (ProfWin*)pluginwin; + } + return NULL; } @@ -539,6 +545,13 @@ wins_close_by_num(int i) autocomplete_remove(wins_close_ac, "xmlconsole"); break; } + case WIN_PLUGIN: + { + ProfPluginWin *pluginwin = (ProfPluginWin*)window; + autocomplete_remove(wins_ac, pluginwin->tag); + autocomplete_remove(wins_close_ac, pluginwin->tag); + break; + } case WIN_MUC_CONFIG: default: break; @@ -640,10 +653,12 @@ wins_new_plugin(const char * const tag) { GList *keys = g_hash_table_get_keys(windows); int result = get_next_available_win_num(keys); - ProfWin *new = win_create_plugin(tag); - g_hash_table_insert(windows, GINT_TO_POINTER(result), new); g_list_free(keys); - return new; + ProfWin *newwin = win_create_plugin(tag); + g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin); + autocomplete_add(wins_ac, tag); + autocomplete_add(wins_close_ac, tag); + return newwin; } gboolean