diff options
-rw-r--r-- | apidocs/c/profhooks.h | 6 | ||||
-rw-r--r-- | apidocs/python/src/plugin.py | 6 | ||||
-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 |
9 files changed, 85 insertions, 21 deletions
diff --git a/apidocs/c/profhooks.h b/apidocs/c/profhooks.h index d0beed28..cb14e794 100644 --- a/apidocs/c/profhooks.h +++ b/apidocs/c/profhooks.h @@ -61,7 +61,7 @@ void prof_post_chat_message_display(const char * const barejid, const char *cons Called before a chat message is sent @param barejid Jabber ID of the message recipient @param message the message to be sent -@return the new message to send, or NULL to preserve the original message +@return the modified or original message to send, or NULL to cancel sending of the message */ char* prof_pre_chat_message_send(const char * const barejid, const char *message); @@ -93,7 +93,7 @@ void prof_post_room_message_display(const char * const barejid, const char * con Called before a chat room message is sent @param barejid Jabber ID of the room @param message the message to be sent -@return the new message to send, or NULL to preserve the original message +@return the modified or original message to send, or NULL to cancel sending of the message */ char* prof_pre_room_message_send(const char * const barejid, const char *message); @@ -135,7 +135,7 @@ Called before a private chat room message is sent @param barejid Jabber ID of the room @param nick nickname of message recipient @param message the message to be sent -@return the new message to send, or NULL to preserve the original message +@return the modified or original message to send, or NULL to cancel sending of the message */ char* prof_pre_priv_message_send(const char * const barejid, const char * const nick, const char *message); diff --git a/apidocs/python/src/plugin.py b/apidocs/python/src/plugin.py index 7e22d5e5..6e200bad 100644 --- a/apidocs/python/src/plugin.py +++ b/apidocs/python/src/plugin.py @@ -106,7 +106,7 @@ def prof_pre_chat_message_send(barejid, message): :param message: the message to be sent :type barejid: str or unicode :type message: str or unicode - :return: the new message to send, or ``None`` to preserve the original message + :return: the modified or original message to send, or ``None`` to cancel sending of the message :rtype: str or unicode """ pass @@ -158,7 +158,7 @@ def prof_pre_room_message_send(barejid, message): :param message: the message to be sent :type barejid: str or unicode :type message: str or unicode - :return: the new message to send, or ``None`` to preserve the original message + :return: the modified or original message to send, or ``None`` to cancel sending of the message :rtype: str or unicode """ pass @@ -227,7 +227,7 @@ def prof_pre_priv_message_send(barejid, nick, message): :type barejid: str or unicode :type nick: str or unicode :type message: str or unicode - :return: the new message to send, or ``None`` to preserve the original message + :return: the modified or original message to send, or ``None`` to cancel sending of the message :rtype: str or unicode """ pass 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); |