about summary refs log tree commit diff stats
path: root/src/plugins
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-03-27 21:36:29 +0100
committerJames Booth <boothj5@gmail.com>2016-03-27 21:36:29 +0100
commit8933d59b03aaf4ef54a6f7cfc8513cd36b8cf67a (patch)
tree176f69242b8d5185b5f80a2d35697ccc148a9953 /src/plugins
parent18555ffcb431adab1f0968ed49d5cc66b9847205 (diff)
downloadprofani-tty-8933d59b03aaf4ef54a6f7cfc8513cd36b8cf67a.tar.gz
Added basic stanza receive eooks
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/c_plugins.c45
-rw-r--r--src/plugins/c_plugins.h5
-rw-r--r--src/plugins/plugins.c54
-rw-r--r--src/plugins/plugins.h10
-rw-r--r--src/plugins/python_plugins.c87
-rw-r--r--src/plugins/python_plugins.h3
6 files changed, 204 insertions, 0 deletions
diff --git a/src/plugins/c_plugins.c b/src/plugins/c_plugins.c
index 167c6c01..b9452206 100644
--- a/src/plugins/c_plugins.c
+++ b/src/plugins/c_plugins.c
@@ -98,8 +98,11 @@ c_plugin_create(const char * const filename)
     plugin->pre_priv_message_send = c_pre_priv_message_send_hook;
     plugin->post_priv_message_send = c_post_priv_message_send_hook;
     plugin->on_message_stanza_send = c_on_message_stanza_send_hook;
+    plugin->on_message_stanza_receive = c_on_message_stanza_receive_hook;
     plugin->on_presence_stanza_send = c_on_presence_stanza_send_hook;
+    plugin->on_presence_stanza_receive = c_on_presence_stanza_receive_hook;
     plugin->on_iq_stanza_send = c_on_iq_stanza_send_hook;
+    plugin->on_iq_stanza_receive = c_on_iq_stanza_receive_hook;
 
     g_string_free(path, TRUE);
     g_free(module_name);
@@ -364,6 +367,20 @@ c_on_message_stanza_send_hook(ProfPlugin *plugin, const char * const text)
     return func (text);
 }
 
+gboolean
+c_on_message_stanza_receive_hook(ProfPlugin *plugin, const char *const text)
+{
+    void * f = NULL;
+    int (*func)(const char * const __text);
+    assert (plugin && plugin->module);
+
+    if (NULL == (f = dlsym (plugin->module, "prof_on_message_stanza_receive")))
+        return TRUE;
+
+    func = (int (*)(const char * const)) f;
+    return func (text);
+}
+
 char *
 c_on_presence_stanza_send_hook(ProfPlugin *plugin, const char * const text)
 {
@@ -378,6 +395,20 @@ c_on_presence_stanza_send_hook(ProfPlugin *plugin, const char * const text)
     return func (text);
 }
 
+gboolean
+c_on_presence_stanza_receive_hook(ProfPlugin *plugin, const char *const text)
+{
+    void * f = NULL;
+    int (*func)(const char * const __text);
+    assert (plugin && plugin->module);
+
+    if (NULL == (f = dlsym (plugin->module, "prof_on_presence_stanza_receive")))
+        return TRUE;
+
+    func = (int (*)(const char * const)) f;
+    return func (text);
+}
+
 char *
 c_on_iq_stanza_send_hook(ProfPlugin *plugin, const char * const text)
 {
@@ -392,6 +423,20 @@ c_on_iq_stanza_send_hook(ProfPlugin *plugin, const char * const text)
     return func (text);
 }
 
+gboolean
+c_on_iq_stanza_receive_hook(ProfPlugin *plugin, const char *const text)
+{
+    void * f = NULL;
+    int (*func)(const char * const __text);
+    assert (plugin && plugin->module);
+
+    if (NULL == (f = dlsym (plugin->module, "prof_on_iq_stanza_receive")))
+        return TRUE;
+
+    func = (int (*)(const char * const)) f;
+    return func (text);
+}
+
 void
 c_plugin_destroy(ProfPlugin *plugin)
 {
diff --git a/src/plugins/c_plugins.h b/src/plugins/c_plugins.h
index 4ddbee89..86faef61 100644
--- a/src/plugins/c_plugins.h
+++ b/src/plugins/c_plugins.h
@@ -65,7 +65,12 @@ char* c_pre_priv_message_send_hook(ProfPlugin *plugin, const char * const room,
 void  c_post_priv_message_send_hook(ProfPlugin *plugin, const char * const room, const char * const nick, const char * const message);
 
 char* c_on_message_stanza_send_hook(ProfPlugin *plugin, const char *const text);
+gboolean c_on_message_stanza_receive_hook(ProfPlugin *plugin, const char *const text);
+
 char* c_on_presence_stanza_send_hook(ProfPlugin *plugin, const char *const text);
+gboolean c_on_presence_stanza_receive_hook(ProfPlugin *plugin, const char *const text);
+
 char* c_on_iq_stanza_send_hook(ProfPlugin *plugin, const char *const text);
+gboolean c_on_iq_stanza_receive_hook(ProfPlugin *plugin, const char *const text);
 
 #endif
diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c
index 9ec3f5c7..eaee2b05 100644
--- a/src/plugins/plugins.c
+++ b/src/plugins/plugins.c
@@ -430,6 +430,24 @@ plugins_on_message_stanza_send(const char *const text)
     return curr_stanza;
 }
 
+gboolean
+plugins_on_message_stanza_receive(const char *const text)
+{
+    gboolean cont = TRUE;
+
+    GSList *curr = plugins;
+    while (curr) {
+        ProfPlugin *plugin = curr->data;
+        gboolean res = plugin->on_message_stanza_receive(plugin, text);
+        if (res == FALSE) {
+            cont = FALSE;
+        }
+        curr = g_slist_next(curr);
+    }
+
+    return cont;
+}
+
 char*
 plugins_on_presence_stanza_send(const char *const text)
 {
@@ -451,6 +469,24 @@ plugins_on_presence_stanza_send(const char *const text)
     return curr_stanza;
 }
 
+gboolean
+plugins_on_presence_stanza_receive(const char *const text)
+{
+    gboolean cont = TRUE;
+
+    GSList *curr = plugins;
+    while (curr) {
+        ProfPlugin *plugin = curr->data;
+        gboolean res = plugin->on_presence_stanza_receive(plugin, text);
+        if (res == FALSE) {
+            cont = FALSE;
+        }
+        curr = g_slist_next(curr);
+    }
+
+    return cont;
+}
+
 char*
 plugins_on_iq_stanza_send(const char *const text)
 {
@@ -472,6 +508,24 @@ plugins_on_iq_stanza_send(const char *const text)
     return curr_stanza;
 }
 
+gboolean
+plugins_on_iq_stanza_receive(const char *const text)
+{
+    gboolean cont = TRUE;
+
+    GSList *curr = plugins;
+    while (curr) {
+        ProfPlugin *plugin = curr->data;
+        gboolean res = plugin->on_iq_stanza_receive(plugin, text);
+        if (res == FALSE) {
+            cont = FALSE;
+        }
+        curr = g_slist_next(curr);
+    }
+
+    return cont;
+}
+
 void
 plugins_shutdown(void)
 {
diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h
index 0e5fa823..4ff3fdc8 100644
--- a/src/plugins/plugins.h
+++ b/src/plugins/plugins.h
@@ -71,8 +71,13 @@ typedef struct prof_plugin_t {
     void  (*post_priv_message_send)(struct prof_plugin_t* plugin, const char * const room, const char * const nick, const char * const message);
 
     char* (*on_message_stanza_send)(struct prof_plugin_t* plugin, const char *const text);
+    gboolean (*on_message_stanza_receive)(struct prof_plugin_t* plugin, const char *const text);
+
     char* (*on_presence_stanza_send)(struct prof_plugin_t* plugin, const char *const text);
+    gboolean (*on_presence_stanza_receive)(struct prof_plugin_t* plugin, const char *const text);
+
     char* (*on_iq_stanza_send)(struct prof_plugin_t* plugin, const char *const text);
+    gboolean (*on_iq_stanza_receive)(struct prof_plugin_t* plugin, const char *const text);
 } ProfPlugin;
 
 void plugins_init(void);
@@ -106,8 +111,13 @@ void  plugins_post_priv_message_send(const char * const jid, const char * const
 void plugins_win_process_line(char *win, const char * const line);
 
 char* plugins_on_message_stanza_send(const char *const text);
+gboolean plugins_on_message_stanza_receive(const char *const text);
+
 char* plugins_on_presence_stanza_send(const char *const text);
+gboolean plugins_on_presence_stanza_receive(const char *const text);
+
 char* plugins_on_iq_stanza_send(const char *const text);
+gboolean plugins_on_iq_stanza_receive(const char *const text);
 
 gboolean plugins_run_command(const char * const cmd);
 void plugins_run_timed(void);
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)
 {
diff --git a/src/plugins/python_plugins.h b/src/plugins/python_plugins.h
index 68c611b1..137bd407 100644
--- a/src/plugins/python_plugins.h
+++ b/src/plugins/python_plugins.h
@@ -65,7 +65,10 @@ char* python_pre_priv_message_send_hook(ProfPlugin *plugin, const char * const r
 void  python_post_priv_message_send_hook(ProfPlugin *plugin, const char * const room, const char * const nick, const char * const message);
 
 char* python_on_message_stanza_send_hook(ProfPlugin *plugin, const char *const text);
+gboolean python_on_message_stanza_receive_hook(ProfPlugin *plugin, const char *const text);
 char* python_on_presence_stanza_send_hook(ProfPlugin *plugin, const char *const text);
+gboolean python_on_presence_stanza_receive_hook(ProfPlugin *plugin, const char *const text);
 char* python_on_iq_stanza_send_hook(ProfPlugin *plugin, const char *const text);
+gboolean python_on_iq_stanza_receive_hook(ProfPlugin *plugin, const char *const text);
 
 #endif