From 194c53c4fa52361bad8deceb3685ce383b69d271 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 29 Mar 2016 23:44:54 +0100 Subject: [PATCH] Plugins: Added basic incoming message function --- src/plugins/api.c | 10 ++++++++++ src/plugins/api.h | 2 ++ src/plugins/c_api.c | 7 +++++++ src/plugins/profapi.c | 2 ++ src/plugins/profapi.h | 2 ++ src/plugins/python_api.c | 31 +++++++++++++++++++++++++------ 6 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/plugins/api.c b/src/plugins/api.c index 5851ed91..d3f159b0 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -39,6 +39,7 @@ #include #include "log.h" +#include "event/server_events.h" #include "plugins/callbacks.h" #include "plugins/autocompleters.h" #include "plugins/themes.h" @@ -368,3 +369,12 @@ api_settings_set_int(const char *const group, const char *const key, int value) { plugin_settings_set_int(group, key, value); } + +void +api_incoming_message(const char *const barejid, const char *const resource, const char *const message) +{ + sv_ev_incoming_message((char*)barejid, (char*)resource, (char*)message, NULL, NULL); + + // TODO handle all states + sv_ev_activity((char*)barejid, (char*)resource, FALSE); +} diff --git a/src/plugins/api.h b/src/plugins/api.h index 82223c08..531eddd7 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -79,4 +79,6 @@ void api_settings_set_string(const char *const group, const char *const key, con int api_settings_get_int(const char *const group, const char *const key, int def); void api_settings_set_int(const char *const group, const char *const key, int value); +void api_incoming_message(const char *const barejid, const char *const resource, const char *const message); + #endif diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index 2427b46a..c860be42 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -230,6 +230,12 @@ c_api_settings_set_int(char *group, char *key, int value) api_settings_set_int(group, key, value); } +static void +c_api_incoming_message(char *barejid, char *resource, char *message) +{ + api_incoming_message(barejid, resource, message); +} + void c_command_callback(PluginCommand *command, gchar **args) { @@ -285,4 +291,5 @@ c_api_init(void) prof_settings_set_string = c_api_settings_set_string; prof_settings_get_int = c_api_settings_get_int; prof_settings_set_int = c_api_settings_set_int; + prof_incoming_message = c_api_incoming_message; } diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index 3ea3bded..372db3b1 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -77,3 +77,5 @@ char* (*prof_settings_get_string)(char *group, char *key, char *def) = NULL; void (*prof_settings_set_string)(char *group, char *key, char *value) = NULL; int (*prof_settings_get_int)(char *group, char *key, int def) = NULL; void (*prof_settings_set_int)(char *group, char *key, int value) = NULL; + +void (*prof_incoming_message)(char *barejid, char *resource, char *message) = NULL; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index e7bcd1aa..c6f54d88 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -78,4 +78,6 @@ void (*prof_settings_set_string)(char *group, char *key, char *value); int (*prof_settings_get_int)(char *group, char *key, int def); void (*prof_settings_set_int)(char *group, char *key, int value); +void (*prof_incoming_message)(char *barejid, char *resource, char *message); + #endif diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c index 148a7eb0..e830be29 100644 --- a/src/plugins/python_api.c +++ b/src/plugins/python_api.c @@ -571,6 +571,24 @@ python_api_settings_set_int(PyObject *self, PyObject *args) return Py_BuildValue(""); } +static PyObject* +python_api_incoming_message(PyObject *self, PyObject *args) +{ + char *barejid = NULL; + char *resource = NULL; + char *message = NULL; + + if (!PyArg_ParseTuple(args, "sss", &barejid, &resource, &message)) { + return Py_BuildValue(""); + } + + allow_python_threads(); + api_incoming_message(barejid, resource, message); + disable_python_threads(); + + return Py_BuildValue(""); +} + void python_command_callback(PluginCommand *command, gchar **args) { @@ -661,12 +679,13 @@ static PyMethodDef apiMethods[] = { { "win_show", python_api_win_show, METH_VARARGS, "Show text in the window." }, { "win_show_themed", python_api_win_show_themed, METH_VARARGS, "Show themed text in the window." }, { "send_stanza", python_api_send_stanza, METH_VARARGS, "Send an XMPP stanza." }, - { "settings_get_boolean", python_api_settings_get_boolean, METH_VARARGS, "Get a boolean setting" }, - { "settings_set_boolean", python_api_settings_set_boolean, METH_VARARGS, "Set a boolean setting" }, - { "settings_get_string", python_api_settings_get_string, METH_VARARGS, "Get a string setting" }, - { "settings_set_string", python_api_settings_set_string, METH_VARARGS, "Set a string setting" }, - { "settings_get_int", python_api_settings_get_int, METH_VARARGS, "Get a integer setting" }, - { "settings_set_int", python_api_settings_set_int, METH_VARARGS, "Set a integer setting" }, + { "settings_get_boolean", python_api_settings_get_boolean, METH_VARARGS, "Get a boolean setting." }, + { "settings_set_boolean", python_api_settings_set_boolean, METH_VARARGS, "Set a boolean setting." }, + { "settings_get_string", python_api_settings_get_string, METH_VARARGS, "Get a string setting." }, + { "settings_set_string", python_api_settings_set_string, METH_VARARGS, "Set a string setting." }, + { "settings_get_int", python_api_settings_get_int, METH_VARARGS, "Get a integer setting." }, + { "settings_set_int", python_api_settings_set_int, METH_VARARGS, "Set a integer setting." }, + { "incoming_message", python_api_incoming_message, METH_VARARGS, "Show an incoming message." }, { NULL, NULL, 0, NULL } };