diff options
Diffstat (limited to 'src/plugins/python_plugins.c')
-rw-r--r-- | src/plugins/python_plugins.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c index 0aef2e8f..5ae03879 100644 --- a/src/plugins/python_plugins.c +++ b/src/plugins/python_plugins.c @@ -116,8 +116,11 @@ python_plugin_create(const char * const filename) plugin->pre_priv_message_send = python_pre_priv_message_send_hook; plugin->post_priv_message_send = python_post_priv_message_send_hook; plugin->on_message_stanza_send = python_on_message_stanza_send_hook; + plugin->on_message_stanza_receive = python_on_message_stanza_receive_hook; plugin->on_presence_stanza_send = python_on_presence_stanza_send_hook; + plugin->on_presence_stanza_receive = python_on_presence_stanza_receive_hook; plugin->on_iq_stanza_send = python_on_iq_stanza_send_hook; + plugin->on_iq_stanza_receive = python_on_iq_stanza_receive_hook; g_free(module_name); allow_python_threads(); @@ -607,6 +610,34 @@ python_on_message_stanza_send_hook(ProfPlugin *plugin, const char *const text) return NULL; } +gboolean +python_on_message_stanza_receive_hook(ProfPlugin *plugin, const char *const text) +{ + disable_python_threads(); + PyObject *p_args = Py_BuildValue("(s)", text); + PyObject *p_function; + + PyObject *p_module = plugin->module; + if (PyObject_HasAttrString(p_module, "prof_on_message_stanza_receive")) { + p_function = PyObject_GetAttrString(p_module, "prof_on_message_stanza_receive"); + python_check_error(); + if (p_function && PyCallable_Check(p_function)) { + PyObject *result = PyObject_CallObject(p_function, p_args); + python_check_error(); + Py_XDECREF(p_function); + if (PyBool_Check(result)) { + allow_python_threads(); + return TRUE; + } else { + allow_python_threads(); + return FALSE; + } + } + } + + return TRUE; +} + char* python_on_presence_stanza_send_hook(ProfPlugin *plugin, const char *const text) { @@ -643,6 +674,34 @@ python_on_presence_stanza_send_hook(ProfPlugin *plugin, const char *const text) return NULL; } +gboolean +python_on_presence_stanza_receive_hook(ProfPlugin *plugin, const char *const text) +{ + disable_python_threads(); + PyObject *p_args = Py_BuildValue("(s)", text); + PyObject *p_function; + + PyObject *p_module = plugin->module; + if (PyObject_HasAttrString(p_module, "prof_on_presence_stanza_receive")) { + p_function = PyObject_GetAttrString(p_module, "prof_on_presence_stanza_receive"); + python_check_error(); + if (p_function && PyCallable_Check(p_function)) { + PyObject *result = PyObject_CallObject(p_function, p_args); + python_check_error(); + Py_XDECREF(p_function); + if (PyBool_Check(result)) { + allow_python_threads(); + return TRUE; + } else { + allow_python_threads(); + return FALSE; + } + } + } + + return TRUE; +} + char* python_on_iq_stanza_send_hook(ProfPlugin *plugin, const char *const text) { @@ -679,6 +738,34 @@ python_on_iq_stanza_send_hook(ProfPlugin *plugin, const char *const text) return NULL; } +gboolean +python_on_iq_stanza_receive_hook(ProfPlugin *plugin, const char *const text) +{ + disable_python_threads(); + PyObject *p_args = Py_BuildValue("(s)", text); + PyObject *p_function; + + PyObject *p_module = plugin->module; + if (PyObject_HasAttrString(p_module, "prof_on_iq_stanza_receive")) { + p_function = PyObject_GetAttrString(p_module, "prof_on_iq_stanza_receive"); + python_check_error(); + if (p_function && PyCallable_Check(p_function)) { + PyObject *result = PyObject_CallObject(p_function, p_args); + python_check_error(); + Py_XDECREF(p_function); + if (PyBool_Check(result)) { + allow_python_threads(); + return TRUE; + } else { + allow_python_threads(); + return FALSE; + } + } + } + + return TRUE; +} + void python_check_error(void) { |