Added basic stanza receive eooks

This commit is contained in:
James Booth
2016-03-27 21:36:29 +01:00
parent 18555ffcb4
commit 8933d59b03
11 changed files with 490 additions and 133 deletions

View File

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