From ab08d0a3780474b1b01e23acb2985bcb7de7439e Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 28 Feb 2016 23:06:45 +0000 Subject: [PATCH 01/10] Added current_win_is_console to plugins api --- src/plugins/api.c | 11 +++++++++++ src/plugins/api.h | 2 ++ src/plugins/c_api.c | 7 +++++++ src/plugins/profapi.c | 1 + src/plugins/profapi.h | 1 + 5 files changed, 22 insertions(+) diff --git a/src/plugins/api.c b/src/plugins/api.c index 495a0d58..a3740f2f 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) { diff --git a/src/plugins/api.h b/src/plugins/api.h index 3f1b7d1c..b56be781 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, diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index e2b7517a..d8619c49 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) { @@ -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/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); From 7fdf50eb31f5cb9f15082c9ebb1e4e421756d4a2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 1 Mar 2016 00:03:11 +0000 Subject: [PATCH 02/10] Add plugin wins to /win and /close autocompletion --- src/ui/window.c | 2 +- src/window_list.c | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/ui/window.c b/src/ui/window.c index 585c0b21..05eaf586 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; diff --git a/src/window_list.c b/src/window_list.c index 35f49fdd..5fab7ba0 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -389,6 +389,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 +544,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 +652,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 From 09cfbb7e05b90af640e0e9f8c9876839747b1974 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 3 Mar 2016 00:31:27 +0000 Subject: [PATCH 03/10] Fixed /help group formatting --- src/command/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. " From e1b15182a4a519843b5ed706b2f71a1b0ed46e73 Mon Sep 17 00:00:00 2001 From: Klement Sekera Date: Mon, 7 Mar 2016 14:06:10 +0100 Subject: [PATCH 04/10] Fix typo maxinum->maximum --- src/command/commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 355adb117cf1e66eca95a162bb1986b4fd049043 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 7 Mar 2016 18:24:04 +0000 Subject: [PATCH 05/10] Added WIN_PLUGIN case to win_free() --- src/ui/window.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/ui/window.c b/src/ui/window.c index 05eaf586..f52ebc41 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -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); From 958dc6b18454774f13f2a4976a06f5800154039d Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 7 Mar 2016 18:30:13 +0000 Subject: [PATCH 06/10] Free GList in wins_get_plugin --- src/window_list.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/window_list.c b/src/window_list.c index 5fab7ba0..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; } } From 72f940360dbb483177475f4dc97dae8227243619 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 7 Mar 2016 18:32:32 +0000 Subject: [PATCH 07/10] Free GLists in plugin autocompleters --- src/plugins/autocompleters.c | 4 ++++ 1 file changed, 4 insertions(+) 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) From 4094b75ccc19780e2e013ba897a09645a5ee4978 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 7 Mar 2016 18:39:24 +0000 Subject: [PATCH 08/10] Fixed valgrind libotr suppressions --- prof.supp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 ... } From 5cabcf9b79880d550782da2967b9d67a531a8f7d Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 7 Mar 2016 20:36:25 +0000 Subject: [PATCH 09/10] Plugins: Added callbacks init and close functions Included destroy function in PluginWindowCallback --- src/plugins/api.c | 6 +++++- src/plugins/api.h | 5 ++++- src/plugins/c_api.c | 2 +- src/plugins/callbacks.c | 25 +++++++++++++++++++++---- src/plugins/callbacks.h | 4 ++++ src/plugins/plugins.c | 2 ++ 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/plugins/api.c b/src/plugins/api.c index a3740f2f..e81467a9 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -239,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 b56be781..6494097e 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -61,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/c_api.c b/src/plugins/c_api.c index d8619c49..f2cce6a6 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -167,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 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 * From 1ddfa47313579d8fb67b70bb8702e75573479d31 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 8 Mar 2016 20:25:36 +0000 Subject: [PATCH 10/10] Free TLSCertificate memory --- src/config/tlscerts.c | 2 ++ 1 file changed, 2 insertions(+) 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); } }