diff options
Diffstat (limited to 'src/plugins')
-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 |
6 files changed, 73 insertions, 15 deletions
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); |