diff options
author | James Booth <boothj5@gmail.com> | 2016-04-08 00:11:33 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-04-08 00:11:33 +0100 |
commit | 93672eba9f625800406aaf89e43d43a4dbc58dde (patch) | |
tree | da966c6b1250db5acf378bb7c132236793931f65 /src/plugins | |
parent | 2f432a942d3c72f5fb3f25775b8ea52cd92b612d (diff) | |
download | profani-tty-93672eba9f625800406aaf89e43d43a4dbc58dde.tar.gz |
Plugins: Added on_room_history_message
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/c_plugins.c | 17 | ||||
-rw-r--r-- | src/plugins/c_plugins.h | 2 | ||||
-rw-r--r-- | src/plugins/plugins.c | 21 | ||||
-rw-r--r-- | src/plugins/plugins.h | 4 | ||||
-rw-r--r-- | src/plugins/python_plugins.c | 23 | ||||
-rw-r--r-- | src/plugins/python_plugins.h | 2 |
6 files changed, 69 insertions, 0 deletions
diff --git a/src/plugins/c_plugins.c b/src/plugins/c_plugins.c index 7caa742e..07a618b6 100644 --- a/src/plugins/c_plugins.c +++ b/src/plugins/c_plugins.c @@ -93,6 +93,7 @@ c_plugin_create(const char *const filename) plugin->post_room_message_display = c_post_room_message_display_hook; plugin->pre_room_message_send = c_pre_room_message_send_hook; plugin->post_room_message_send = c_post_room_message_send_hook; + plugin->on_room_history_message = c_on_room_history_message_hook; plugin->pre_priv_message_display = c_pre_priv_message_display_hook; plugin->post_priv_message_display = c_post_priv_message_display_hook; plugin->pre_priv_message_send = c_pre_priv_message_send_hook; @@ -302,6 +303,22 @@ c_post_room_message_send_hook(ProfPlugin *plugin, const char *const room, const func(room, message); } +void +c_on_room_history_message_hook(ProfPlugin *plugin, const char *const room, const char *const nick, + const char *const message, const char *const timestamp) +{ + void *f = NULL; + void (*func)(const char *const __room, const char *const __nick, const char *const __message, + const char *const __timestamp); + assert(plugin && plugin->module); + + if (NULL == (f = dlsym(plugin->module, "prof_on_room_history_message"))) + return; + + func = (void (*)(const char *const, const char *const, const char *const, const char *const))f; + func(room, nick, message, timestamp); +} + char* c_pre_priv_message_display_hook(ProfPlugin *plugin, const char *const room, const char *const nick, const char *message) { diff --git a/src/plugins/c_plugins.h b/src/plugins/c_plugins.h index b8725b3b..1517ecb2 100644 --- a/src/plugins/c_plugins.h +++ b/src/plugins/c_plugins.h @@ -60,6 +60,8 @@ void c_post_room_message_display_hook(ProfPlugin *plugin, const char *const room const char *message); char* c_pre_room_message_send_hook(ProfPlugin *plugin, const char *const room, const char *message); void c_post_room_message_send_hook(ProfPlugin *plugin, const char *const room, const char *message); +void c_on_room_history_message_hook(ProfPlugin *plugin, const char *const room, const char *const nick, + const char *const message, const char *const timestamp); char* c_pre_priv_message_display_hook(ProfPlugin *plugin, const char *const room, const char *const nick, const char *message); diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index f0c3de01..32e1247e 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -333,6 +333,27 @@ plugins_post_room_message_send(const char * const room, const char *message) } } +void +plugins_on_room_history_message(const char *const room, const char *const nick, const char *const message, + GDateTime *timestamp) +{ + char *timestamp_str = NULL; + GTimeVal timestamp_tv; + gboolean res = g_date_time_to_timeval(timestamp, ×tamp_tv); + if (res) { + timestamp_str = g_time_val_to_iso8601(×tamp_tv); + } + + GSList *curr = plugins; + while (curr) { + ProfPlugin *plugin = curr->data; + plugin->on_room_history_message(plugin, room, nick, message, NULL); + curr = g_slist_next(curr); + } + + free(timestamp_str); +} + char* plugins_pre_priv_message_display(const char * const jid, const char *message) { diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index aa3040ab..335bf8f5 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -67,6 +67,8 @@ typedef struct prof_plugin_t { const char *message); char* (*pre_room_message_send)(struct prof_plugin_t* plugin, const char *const room, const char *message); void (*post_room_message_send)(struct prof_plugin_t* plugin, const char *const room, const char *message); + void (*on_room_history_message)(struct prof_plugin_t* plugin, const char *const room, const char *const nick, const char *const message, + const char *const timestamp); char* (*pre_priv_message_display)(struct prof_plugin_t* plugin, const char *const room, const char *const nick, const char *message); @@ -117,6 +119,8 @@ char* plugins_pre_room_message_display(const char *const room, const char *const void plugins_post_room_message_display(const char *const room, const char *const nick, const char *message); char* plugins_pre_room_message_send(const char *const room, const char *message); void plugins_post_room_message_send(const char *const room, const char *message); +void plugins_on_room_history_message(const char *const room, const char *const nick, const char *const message, + GDateTime *timestamp); char* plugins_pre_priv_message_display(const char *const jid, const char *message); void plugins_post_priv_message_display(const char *const jid, const char *message); diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c index 67afc551..90ff36ed 100644 --- a/src/plugins/python_plugins.c +++ b/src/plugins/python_plugins.c @@ -111,6 +111,7 @@ python_plugin_create(const char *const filename) plugin->post_room_message_display = python_post_room_message_display_hook; plugin->pre_room_message_send = python_pre_room_message_send_hook; plugin->post_room_message_send = python_post_room_message_send_hook; + plugin->on_room_history_message = python_on_room_history_message_hook; plugin->pre_priv_message_display = python_pre_priv_message_display_hook; plugin->post_priv_message_display = python_post_priv_message_display_hook; plugin->pre_priv_message_send = python_pre_priv_message_send_hook; @@ -463,6 +464,28 @@ python_post_room_message_send_hook(ProfPlugin *plugin, const char *const room, c allow_python_threads(); } +void +python_on_room_history_message_hook(ProfPlugin *plugin, const char *const room, const char *const nick, + const char *const message, const char *const timestamp) +{ + disable_python_threads(); + PyObject *p_args = Py_BuildValue("ssss", room, nick, message, timestamp); + PyObject *p_function; + + PyObject *p_module = plugin->module; + if (PyObject_HasAttrString(p_module, "prof_on_room_history_message")) { + p_function = PyObject_GetAttrString(p_module, "prof_on_room_history_message"); + python_check_error(); + if (p_function && PyCallable_Check(p_function)) { + PyObject_CallObject(p_function, p_args); + python_check_error(); + Py_XDECREF(p_function); + } + } + + allow_python_threads(); +} + char* python_pre_priv_message_display_hook(ProfPlugin *plugin, const char *const room, const char *const nick, const char *message) diff --git a/src/plugins/python_plugins.h b/src/plugins/python_plugins.h index 2e914b53..6f81e2b8 100644 --- a/src/plugins/python_plugins.h +++ b/src/plugins/python_plugins.h @@ -60,6 +60,8 @@ void python_post_room_message_display_hook(ProfPlugin *plugin, const char *const const char *message); char* python_pre_room_message_send_hook(ProfPlugin *plugin, const char *const room, const char *message); void python_post_room_message_send_hook(ProfPlugin *plugin, const char *const room, const char *message); +void python_on_room_history_message_hook(ProfPlugin *plugin, const char *const room, const char *const nick, + const char *const message, const char *const timestamp); char* python_pre_priv_message_display_hook(ProfPlugin *plugin, const char *const room, const char *const nick, const char *message); |