diff options
author | James Booth <boothj5@gmail.com> | 2016-04-30 23:00:07 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-04-30 23:00:07 +0100 |
commit | 623fbe9e4727f80ff3adaf820f3133e918a3f87e (patch) | |
tree | c43c52297197513d7c5e503a4526586c73c16c68 | |
parent | a718e6f91b53139e35450fb119a3ccd83e48ab26 (diff) | |
download | profani-tty-623fbe9e4727f80ff3adaf820f3133e918a3f87e.tar.gz |
Plugins: Added prof_disco_add_feature()
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | src/plugins/api.c | 20 | ||||
-rw-r--r-- | src/plugins/api.h | 2 | ||||
-rw-r--r-- | src/plugins/c_api.c | 7 | ||||
-rw-r--r-- | src/plugins/disco.c | 65 | ||||
-rw-r--r-- | src/plugins/disco.h | 43 | ||||
-rw-r--r-- | src/plugins/plugins.c | 8 | ||||
-rw-r--r-- | src/plugins/plugins.h | 2 | ||||
-rw-r--r-- | src/plugins/profapi.c | 2 | ||||
-rw-r--r-- | src/plugins/profapi.h | 2 | ||||
-rw-r--r-- | src/plugins/python_api.c | 16 | ||||
-rw-r--r-- | src/xmpp/capabilities.c | 22 | ||||
-rw-r--r-- | src/xmpp/xmpp.h | 1 | ||||
-rw-r--r-- | tests/unittests/xmpp/stub_xmpp.c | 1 |
14 files changed, 193 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index ff08149c..95f6df92 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,7 @@ core_sources = \ src/plugins/autocompleters.c src/plugins/autocompleters.h \ src/plugins/themes.c src/plugins/themes.h \ src/plugins/settings.c src/plugins/settings.h \ + src/plugins/disco.c src/plugins/disco.h \ src/tray.h src/tray.c unittest_sources = \ @@ -84,6 +85,7 @@ unittest_sources = \ src/plugins/autocompleters.c src/plugins/autocompleters.h \ src/plugins/themes.c src/plugins/themes.h \ src/plugins/settings.c src/plugins/settings.h \ + src/plugins/disco.c src/plugins/disco.h \ src/window_list.c src/window_list.h \ src/event/server_events.c src/event/server_events.h \ src/event/client_events.c src/event/client_events.h \ diff --git a/src/plugins/api.c b/src/plugins/api.c index 1aedee1f..0de9bab0 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -40,10 +40,12 @@ #include "log.h" #include "event/server_events.h" +#include "event/client_events.h" #include "plugins/callbacks.h" #include "plugins/autocompleters.h" #include "plugins/themes.h" #include "plugins/settings.h" +#include "plugins/disco.h" #include "profanity.h" #include "ui/ui.h" #include "config/theme.h" @@ -426,3 +428,21 @@ api_incoming_message(const char *const barejid, const char *const resource, cons // TODO handle all states sv_ev_activity((char*)barejid, (char*)resource, FALSE); } + +void +api_disco_add_feature(char *feature) +{ + if (feature == NULL) { + return; + } + + disco_add_feature(feature); + caps_reset_ver(); + + // resend presence to update server's disco info data for this client + if (jabber_get_connection_status() == JABBER_CONNECTED) { + resource_presence_t last_presence = accounts_get_last_presence(jabber_get_account_name()); + cl_ev_presence_send(last_presence, jabber_get_presence_message(), 0); + } +} + diff --git a/src/plugins/api.h b/src/plugins/api.h index c22fb217..a835cd8b 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -86,4 +86,6 @@ void api_settings_set_int(const char *const group, const char *const key, int va void api_incoming_message(const char *const barejid, const char *const resource, const char *const message); +void api_disco_add_feature(char *feature); + #endif diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index 464bf39b..770fd9a3 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -260,6 +260,12 @@ c_api_incoming_message(char *barejid, char *resource, char *message) api_incoming_message(barejid, resource, message); } +static void +c_api_disco_add_feature(char *feature) +{ + api_disco_add_feature(feature); +} + void c_command_callback(PluginCommand *command, gchar **args) { @@ -320,4 +326,5 @@ c_api_init(void) 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; + prof_disco_add_feature = c_api_disco_add_feature; } diff --git a/src/plugins/disco.c b/src/plugins/disco.c new file mode 100644 index 00000000..1d47ad9a --- /dev/null +++ b/src/plugins/disco.c @@ -0,0 +1,65 @@ +/* + * disco.c + * + * Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com> + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see <http://www.gnu.org/licenses/>. + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#include <string.h> +#include <stdlib.h> + +#include <glib.h> + +static GList *disco_features = NULL; + +void +disco_add_feature(char* feature) +{ + if (feature == NULL) { + return; + } + + disco_features = g_list_append(disco_features, strdup(feature)); +} + +GList* +disco_get_features(void) +{ + return disco_features; +} + +void +disco_close(void) +{ + if (disco_features) { + g_list_free_full(disco_features, free); + disco_features = NULL; + } +} diff --git a/src/plugins/disco.h b/src/plugins/disco.h new file mode 100644 index 00000000..9c7975c2 --- /dev/null +++ b/src/plugins/disco.h @@ -0,0 +1,43 @@ +/* + * disco.h + * + * Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com> + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see <http://www.gnu.org/licenses/>. + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#ifndef DISCO_H +#define DISCO_H + +void disco_add_feature(char *feature); +GList* disco_get_features(void); +void disco_close(void); + +#endif + diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index cb222a32..6cde92ad 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -45,6 +45,7 @@ #include "plugins/plugins.h" #include "plugins/themes.h" #include "plugins/settings.h" +#include "plugins/disco.h" #ifdef HAVE_PYTHON #include "plugins/python_plugins.h" @@ -665,6 +666,12 @@ plugins_on_room_win_focus(const char *const roomjid) } } +GList* +plugins_get_disco_features(void) +{ + return disco_get_features(); +} + void plugins_shutdown(void) { @@ -695,6 +702,7 @@ plugins_shutdown(void) plugin_themes_close(); plugin_settings_close(); callbacks_close(); + disco_close(); } gchar * diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index d59bc280..b7eb4c80 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -153,4 +153,6 @@ GList* plugins_get_command_names(void); gchar * plugins_get_dir(void); CommandHelp* plugins_get_help(const char *const cmd); +GList* plugins_get_disco_features(void); + #endif diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index 6e8637b0..4b18da3b 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -83,3 +83,5 @@ 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; + +void (*prof_disco_add_feature)(char *feature) = NULL; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index 7d0ed6e5..54497c8d 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -84,4 +84,6 @@ void (*prof_settings_set_int)(char *group, char *key, int value); void (*prof_incoming_message)(char *barejid, char *resource, char *message); +void (*prof_disco_add_feature)(char *feature); + #endif diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c index 34e81f11..5c4cf913 100644 --- a/src/plugins/python_api.c +++ b/src/plugins/python_api.c @@ -665,6 +665,21 @@ python_api_incoming_message(PyObject *self, PyObject *args) return Py_BuildValue(""); } +static PyObject* +python_api_disco_add_feature(PyObject *self, PyObject *args) +{ + char *feature = NULL; + if (!PyArg_ParseTuple(args, "s", &feature)) { + return Py_BuildValue(""); + } + + allow_python_threads(); + api_disco_add_feature(feature); + disable_python_threads(); + + return Py_BuildValue(""); +} + void python_command_callback(PluginCommand *command, gchar **args) { @@ -766,6 +781,7 @@ static PyMethodDef apiMethods[] = { { "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." }, + { "disco_add_feature", python_api_disco_add_feature, METH_VARARGS, "Add a feature to disco info response." }, { NULL, NULL, 0, NULL } }; diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index db840246..358f6bff 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -57,6 +57,7 @@ #include "xmpp/stanza.h" #include "xmpp/form.h" #include "xmpp/capabilities.h" +#include "plugins/plugins.h" static gchar *cache_loc; static GKeyFile *cache; @@ -552,6 +553,15 @@ caps_get_my_sha1(xmpp_ctx_t *const ctx) return my_sha1; } +void +caps_reset_ver(void) +{ + if (my_sha1) { + g_free(my_sha1); + my_sha1 = NULL; + } +} + xmpp_stanza_t* caps_create_query_response_stanza(xmpp_ctx_t *const ctx) { @@ -632,6 +642,18 @@ caps_create_query_response_stanza(xmpp_ctx_t *const ctx) xmpp_stanza_add_child(query, feature_ping); xmpp_stanza_add_child(query, feature_receipts); + GList *plugin_features = plugins_get_disco_features(); + GList *curr = plugin_features; + while (curr) { + xmpp_stanza_t *feature = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(feature, STANZA_NAME_FEATURE); + xmpp_stanza_set_attribute(feature, STANZA_ATTR_VAR, curr->data); + xmpp_stanza_add_child(query, feature); + xmpp_stanza_release(feature); + + curr = g_list_next(curr); + } + xmpp_stanza_release(feature_receipts); xmpp_stanza_release(feature_ping); xmpp_stanza_release(feature_conference); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index ea8a6e1d..56a4bf5f 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -190,6 +190,7 @@ void iq_http_upload_request(HTTPUpload *upload); Capabilities* caps_lookup(const char *const jid); void caps_close(void); void caps_destroy(Capabilities *caps); +void caps_reset_ver(void); gboolean bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str); gboolean bookmark_update(const char *jid, const char *nick, const char *password, const char *autojoin_str); diff --git a/tests/unittests/xmpp/stub_xmpp.c b/tests/unittests/xmpp/stub_xmpp.c index 6437de86..a68186dc 100644 --- a/tests/unittests/xmpp/stub_xmpp.c +++ b/tests/unittests/xmpp/stub_xmpp.c @@ -190,6 +190,7 @@ Capabilities* caps_lookup(const char * const jid) void caps_close(void) {} void caps_destroy(Capabilities *caps) {} +void caps_reset_ver(void) {} gboolean bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str) { |