diff options
author | James Booth <boothj5@gmail.com> | 2017-01-22 18:08:29 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2017-01-22 18:09:04 +0000 |
commit | 83385cdbc0106c5aae61d87975a2e082abdbf634 (patch) | |
tree | 6445a23a717d34b474efbc46267c04134fda54a5 /src | |
parent | 7090f85d853b32ac6799bdc5641cd81502ff65dc (diff) | |
download | profani-tty-83385cdbc0106c5aae61d87975a2e082abdbf634.tar.gz |
Add pre chat and room message blocking
Diffstat (limited to 'src')
-rw-r--r-- | src/event/client_events.c | 6 | ||||
-rw-r--r-- | src/plugins/c_plugins.c | 11 | ||||
-rw-r--r-- | src/plugins/c_plugins.h | 3 | ||||
-rw-r--r-- | src/plugins/plugins.c | 52 | ||||
-rw-r--r-- | src/plugins/plugins.h | 2 | ||||
-rw-r--r-- | src/plugins/python_plugins.c | 17 | ||||
-rw-r--r-- | src/plugins/python_plugins.h | 3 |
7 files changed, 79 insertions, 15 deletions
diff --git a/src/event/client_events.c b/src/event/client_events.c index 3ef193b1..bdc25931 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -136,6 +136,9 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo } char *plugin_msg = plugins_pre_chat_message_send(chatwin->barejid, msg); + if (plugin_msg == NULL) { + return; + } // OTR suported, PGP supported #ifdef HAVE_LIBOTR @@ -218,6 +221,9 @@ void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const oob_url) { char *plugin_msg = plugins_pre_room_message_send(mucwin->roomjid, msg); + if (plugin_msg == NULL) { + return; + } message_send_groupchat(mucwin->roomjid, plugin_msg, oob_url); diff --git a/src/plugins/c_plugins.c b/src/plugins/c_plugins.c index e6ec2b7d..675457e5 100644 --- a/src/plugins/c_plugins.c +++ b/src/plugins/c_plugins.c @@ -81,6 +81,7 @@ c_plugin_create(const char *const filename) plugin->lang = LANG_C; plugin->module = handle; plugin->init_func = c_init_hook; + plugin->contains_hook = c_contains_hook; plugin->on_start_func = c_on_start_hook; plugin->on_shutdown_func = c_on_shutdown_hook; plugin->on_unload_func = c_on_unload_hook; @@ -136,6 +137,16 @@ c_init_hook(ProfPlugin *plugin, const char *const version, const char *const sta func(version, status, account_name, fulljid); } +gboolean +c_contains_hook(ProfPlugin *plugin, const char *const hook) +{ + if (dlsym(plugin->module, hook)) { + return TRUE; + } else { + return FALSE; + } +} + void c_on_start_hook(ProfPlugin *plugin) { diff --git a/src/plugins/c_plugins.h b/src/plugins/c_plugins.h index c802d5a5..42c65f38 100644 --- a/src/plugins/c_plugins.h +++ b/src/plugins/c_plugins.h @@ -45,6 +45,9 @@ void c_shutdown(void); void c_init_hook(ProfPlugin *plugin, const char *const version, const char *const status, const char *const account_name, const char *const fulljid); + +gboolean c_contains_hook(ProfPlugin *plugin, const char *const hook); + void c_on_start_hook(ProfPlugin *plugin); void c_on_shutdown_hook(ProfPlugin *plugin); void c_on_unload_hook(ProfPlugin *plugin); diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index 054cb8e1..f190a8d0 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -413,11 +413,18 @@ plugins_pre_chat_message_send(const char * const barejid, const char *message) GList *curr = values; while (curr) { ProfPlugin *plugin = curr->data; - new_message = plugin->pre_chat_message_send(plugin, barejid, curr_message); - if (new_message) { - free(curr_message); - curr_message = strdup(new_message); - free(new_message); + if (plugin->contains_hook(plugin, "prof_pre_chat_message_send")) { + new_message = plugin->pre_chat_message_send(plugin, barejid, curr_message); + if (new_message) { + free(curr_message); + curr_message = strdup(new_message); + free(new_message); + } else { + free(curr_message); + g_list_free(values); + + return NULL; + } } curr = g_list_next(curr); } @@ -485,11 +492,18 @@ plugins_pre_room_message_send(const char * const barejid, const char *message) GList *curr = values; while (curr) { ProfPlugin *plugin = curr->data; - new_message = plugin->pre_room_message_send(plugin, barejid, curr_message); - if (new_message) { - free(curr_message); - curr_message = strdup(new_message); - free(new_message); + if (plugin->contains_hook(plugin, "prof_pre_room_message_send")) { + new_message = plugin->pre_room_message_send(plugin, barejid, curr_message); + if (new_message) { + free(curr_message); + curr_message = strdup(new_message); + free(new_message); + } else { + free(curr_message); + g_list_free(values); + + return NULL; + } } curr = g_list_next(curr); } @@ -587,11 +601,19 @@ plugins_pre_priv_message_send(const char * const fulljid, const char * const mes GList *curr = values; while (curr) { ProfPlugin *plugin = curr->data; - new_message = plugin->pre_priv_message_send(plugin, jidp->barejid, jidp->resourcepart, curr_message); - if (new_message) { - free(curr_message); - curr_message = strdup(new_message); - free(new_message); + if (plugin->contains_hook(plugin, "prof_pre_priv_message_send")) { + new_message = plugin->pre_priv_message_send(plugin, jidp->barejid, jidp->resourcepart, curr_message); + if (new_message) { + free(curr_message); + curr_message = strdup(new_message); + free(new_message); + } else { + free(curr_message); + g_list_free(values); + jid_destroy(jidp); + + return NULL; + } } curr = g_list_next(curr); } diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index b7fdf297..ce97237d 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -49,6 +49,8 @@ typedef struct prof_plugin_t { void (*init_func)(struct prof_plugin_t* plugin, const char * const version, const char * const status, const char *const account_name, const char *const fulljid); + gboolean (*contains_hook)(struct prof_plugin_t* plugin, const char *const hook); + void (*on_start_func)(struct prof_plugin_t* plugin); void (*on_shutdown_func)(struct prof_plugin_t* plugin); void (*on_unload_func)(struct prof_plugin_t* plugin); diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c index 66efec54..897f7b54 100644 --- a/src/plugins/python_plugins.c +++ b/src/plugins/python_plugins.c @@ -125,6 +125,7 @@ python_plugin_create(const char *const filename) plugin->lang = LANG_PYTHON; plugin->module = p_module; plugin->init_func = python_init_hook; + plugin->contains_hook = python_contains_hook; plugin->on_start_func = python_on_start_hook; plugin->on_shutdown_func = python_on_shutdown_hook; plugin->on_unload_func = python_on_unload_hook; @@ -184,6 +185,22 @@ python_init_hook(ProfPlugin *plugin, const char *const version, const char *cons allow_python_threads(); } +gboolean +python_contains_hook(ProfPlugin *plugin, const char *const hook) +{ + disable_python_threads(); + gboolean res = FALSE; + + PyObject *p_module = plugin->module; + if (PyObject_HasAttrString(p_module, hook)) { + res = TRUE; + } + + allow_python_threads(); + + return res; +} + void python_on_start_hook(ProfPlugin *plugin) { diff --git a/src/plugins/python_plugins.h b/src/plugins/python_plugins.h index 0969b700..24b04b8c 100644 --- a/src/plugins/python_plugins.h +++ b/src/plugins/python_plugins.h @@ -47,6 +47,9 @@ const char* python_get_version(void); void python_init_hook(ProfPlugin *plugin, const char *const version, const char *const status, const char *const account_name, const char *const fulljid); + +gboolean python_contains_hook(ProfPlugin *plugin, const char *const hook); + void python_on_start_hook(ProfPlugin *plugin); void python_on_shutdown_hook(ProfPlugin *plugin); void python_on_unload_hook(ProfPlugin *plugin); |