mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Plugins: Added prof_disco_add_feature()
This commit is contained in:
parent
a718e6f91b
commit
623fbe9e47
@ -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 \
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
65
src/plugins/disco.c
Normal file
65
src/plugins/disco.c
Normal file
@ -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;
|
||||
}
|
||||
}
|
43
src/plugins/disco.h
Normal file
43
src/plugins/disco.h
Normal file
@ -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
|
||||
|
@ -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 *
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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 }
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user