Add pre chat and room message blocking

This commit is contained in:
James Booth
2017-01-22 18:08:29 +00:00
parent 7090f85d85
commit 83385cdbc0
9 changed files with 85 additions and 21 deletions

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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)
{

View File

@@ -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);