mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Remove disco features added by plugins on unload
This commit is contained in:
parent
bb676cc0fc
commit
a65403c54a
@ -468,13 +468,14 @@ api_incoming_message(const char *const barejid, const char *const resource, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
api_disco_add_feature(char *feature)
|
api_disco_add_feature(char *plugin_name, char *feature)
|
||||||
{
|
{
|
||||||
if (feature == NULL) {
|
if (feature == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
disco_add_feature(feature);
|
disco_add_feature(plugin_name, feature);
|
||||||
|
|
||||||
caps_reset_ver();
|
caps_reset_ver();
|
||||||
|
|
||||||
// resend presence to update server's disco info data for this client
|
// resend presence to update server's disco info data for this client
|
||||||
|
@ -91,6 +91,6 @@ int api_settings_string_list_clear(const char *const group, const char *const ke
|
|||||||
|
|
||||||
void api_incoming_message(const char *const barejid, const char *const resource, const char *const message);
|
void api_incoming_message(const char *const barejid, const char *const resource, const char *const message);
|
||||||
|
|
||||||
void api_disco_add_feature(char *feature);
|
void api_disco_add_feature(char *plugin_name, char *feature);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -317,9 +317,11 @@ c_api_incoming_message(char *barejid, char *resource, char *message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
c_api_disco_add_feature(char *feature)
|
c_api_disco_add_feature(const char *filename, char *feature)
|
||||||
{
|
{
|
||||||
api_disco_add_feature(feature);
|
char *plugin_name = _c_plugin_name(filename);
|
||||||
|
api_disco_add_feature(plugin_name, feature);
|
||||||
|
free(plugin_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -386,7 +388,7 @@ c_api_init(void)
|
|||||||
prof_settings_string_list_remove = c_api_settings_string_list_remove;
|
prof_settings_string_list_remove = c_api_settings_string_list_remove;
|
||||||
prof_settings_string_list_clear = c_api_settings_string_list_clear;
|
prof_settings_string_list_clear = c_api_settings_string_list_clear;
|
||||||
prof_incoming_message = c_api_incoming_message;
|
prof_incoming_message = c_api_incoming_message;
|
||||||
prof_disco_add_feature = c_api_disco_add_feature;
|
_prof_disco_add_feature = c_api_disco_add_feature;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#include "config/files.h"
|
#include "config/files.h"
|
||||||
#include "plugins/api.h"
|
#include "plugins/api.h"
|
||||||
#include "plugins/callbacks.h"
|
#include "plugins/callbacks.h"
|
||||||
|
#include "plugins/disco.h"
|
||||||
#include "plugins/plugins.h"
|
#include "plugins/plugins.h"
|
||||||
#include "plugins/c_plugins.h"
|
#include "plugins/c_plugins.h"
|
||||||
#include "plugins/c_api.h"
|
#include "plugins/c_api.h"
|
||||||
@ -541,6 +542,8 @@ c_plugin_destroy(ProfPlugin *plugin)
|
|||||||
|
|
||||||
callbacks_remove(plugin->name);
|
callbacks_remove(plugin->name);
|
||||||
|
|
||||||
|
disco_remove_features(plugin->name);
|
||||||
|
|
||||||
if (dlclose (plugin->module)) {
|
if (dlclose (plugin->module)) {
|
||||||
log_warning ("dlclose failed to close `%s' with `%s'", plugin->name, dlerror ());
|
log_warning ("dlclose failed to close `%s' with `%s'", plugin->name, dlerror ());
|
||||||
}
|
}
|
||||||
|
@ -37,29 +37,78 @@
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
static GList *disco_features = NULL;
|
static GHashTable *plugin_to_features = NULL;
|
||||||
|
|
||||||
|
static void
|
||||||
|
_free_features(GList *features)
|
||||||
|
{
|
||||||
|
g_list_free_full(features, free);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
disco_add_feature(char* feature)
|
disco_add_feature(const char *plugin_name, char* feature)
|
||||||
{
|
{
|
||||||
if (feature == NULL) {
|
if (feature == NULL || plugin_name == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
disco_features = g_list_append(disco_features, strdup(feature));
|
if (!plugin_to_features) {
|
||||||
|
plugin_to_features = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_features);
|
||||||
|
}
|
||||||
|
|
||||||
|
GList *features = g_hash_table_lookup(plugin_to_features, plugin_name);
|
||||||
|
if (!features) {
|
||||||
|
features = g_list_append(features, strdup(feature));
|
||||||
|
g_hash_table_insert(plugin_to_features, strdup(plugin_name), features);
|
||||||
|
} else {
|
||||||
|
features = g_list_append(features, strdup(feature));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
disco_remove_features(const char *plugin_name)
|
||||||
|
{
|
||||||
|
if (!plugin_to_features) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_hash_table_contains(plugin_to_features, plugin_name)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_hash_table_remove(plugin_to_features, plugin_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
GList*
|
GList*
|
||||||
disco_get_features(void)
|
disco_get_features(void)
|
||||||
{
|
{
|
||||||
return disco_features;
|
GList *result = NULL;
|
||||||
|
if (!plugin_to_features) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
GList *lists = g_hash_table_get_values(plugin_to_features);
|
||||||
|
GList *curr_list = lists;
|
||||||
|
while (curr_list) {
|
||||||
|
GList *features = curr_list->data;
|
||||||
|
GList *curr = features;
|
||||||
|
while (curr) {
|
||||||
|
result = g_list_append(result, curr->data);
|
||||||
|
curr = g_list_next(curr);
|
||||||
|
}
|
||||||
|
curr_list = g_list_next(curr_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_list_free(lists);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
disco_close(void)
|
disco_close(void)
|
||||||
{
|
{
|
||||||
if (disco_features) {
|
if (plugin_to_features) {
|
||||||
g_list_free_full(disco_features, free);
|
g_hash_table_destroy(plugin_to_features);
|
||||||
disco_features = NULL;
|
plugin_to_features = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,8 @@
|
|||||||
#ifndef PLUGINS_DISCO_H
|
#ifndef PLUGINS_DISCO_H
|
||||||
#define PLUGINS_DISCO_H
|
#define PLUGINS_DISCO_H
|
||||||
|
|
||||||
void disco_add_feature(char *feature);
|
void disco_add_feature(const char* plugin_name, char *feature);
|
||||||
|
void disco_remove_features(const char *plugin_name);
|
||||||
GList* disco_get_features(void);
|
GList* disco_get_features(void);
|
||||||
void disco_close(void);
|
void disco_close(void);
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "config/files.h"
|
#include "config/files.h"
|
||||||
#include "config/preferences.h"
|
#include "config/preferences.h"
|
||||||
|
#include "event/client_events.h"
|
||||||
#include "plugins/callbacks.h"
|
#include "plugins/callbacks.h"
|
||||||
#include "plugins/autocompleters.h"
|
#include "plugins/autocompleters.h"
|
||||||
#include "plugins/api.h"
|
#include "plugins/api.h"
|
||||||
@ -207,6 +208,15 @@ plugins_unload(const char *const name)
|
|||||||
#endif
|
#endif
|
||||||
prefs_remove_plugin(name);
|
prefs_remove_plugin(name);
|
||||||
g_hash_table_remove(plugins, name);
|
g_hash_table_remove(plugins, name);
|
||||||
|
|
||||||
|
caps_reset_ver();
|
||||||
|
// resend presence to update server's disco info data for this client
|
||||||
|
if (connection_get_status() == JABBER_CONNECTED) {
|
||||||
|
char* account_name = session_get_account_name();
|
||||||
|
resource_presence_t last_presence = accounts_get_last_presence(account_name);
|
||||||
|
char *msg = connection_get_presence_msg();
|
||||||
|
cl_ev_presence_send(last_presence, msg, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -88,4 +88,4 @@ int (*prof_settings_string_list_clear)(char *group, char *key) = NULL;
|
|||||||
|
|
||||||
void (*prof_incoming_message)(char *barejid, char *resource, char *message) = NULL;
|
void (*prof_incoming_message)(char *barejid, char *resource, char *message) = NULL;
|
||||||
|
|
||||||
void (*prof_disco_add_feature)(char *feature) = NULL;
|
void (*_prof_disco_add_feature)(const char *filename, char *feature) = NULL;
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#define prof_completer_remove(key, items) _prof_completer_remove(__FILE__, key, items)
|
#define prof_completer_remove(key, items) _prof_completer_remove(__FILE__, key, items)
|
||||||
#define prof_completer_clear(key) _prof_completer_clear(__FILE__, key)
|
#define prof_completer_clear(key) _prof_completer_clear(__FILE__, key)
|
||||||
#define prof_win_create(win, input_handler) _prof_win_create(__FILE__, win, input_handler)
|
#define prof_win_create(win, input_handler) _prof_win_create(__FILE__, win, input_handler)
|
||||||
|
#define prof_disco_add_feature(feature) _prof_disco_add_feature(__FILE__, feature)
|
||||||
|
|
||||||
typedef char* PROF_WIN_TAG;
|
typedef char* PROF_WIN_TAG;
|
||||||
typedef void(*CMD_CB)(char **args);
|
typedef void(*CMD_CB)(char **args);
|
||||||
@ -98,6 +99,6 @@ int (*prof_settings_string_list_clear)(char *group, char *key);
|
|||||||
|
|
||||||
void (*prof_incoming_message)(char *barejid, char *resource, char *message);
|
void (*prof_incoming_message)(char *barejid, char *resource, char *message);
|
||||||
|
|
||||||
void (*prof_disco_add_feature)(char *feature);
|
void (*_prof_disco_add_feature)(const char *filename, char *feature);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -974,12 +974,15 @@ python_api_disco_add_feature(PyObject *self, PyObject *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *feature_str = python_str_or_unicode_to_string(feature);
|
char *feature_str = python_str_or_unicode_to_string(feature);
|
||||||
|
char *plugin_name = _python_plugin_name();
|
||||||
|
|
||||||
allow_python_threads();
|
allow_python_threads();
|
||||||
api_disco_add_feature(feature_str);
|
api_disco_add_feature(plugin_name, feature_str);
|
||||||
free(feature_str);
|
free(feature_str);
|
||||||
disable_python_threads();
|
disable_python_threads();
|
||||||
|
|
||||||
|
free(plugin_name);
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "config/files.h"
|
#include "config/files.h"
|
||||||
#include "plugins/api.h"
|
#include "plugins/api.h"
|
||||||
#include "plugins/callbacks.h"
|
#include "plugins/callbacks.h"
|
||||||
|
#include "plugins/disco.h"
|
||||||
#include "plugins/plugins.h"
|
#include "plugins/plugins.h"
|
||||||
#include "plugins/python_api.h"
|
#include "plugins/python_api.h"
|
||||||
#include "plugins/python_plugins.h"
|
#include "plugins/python_plugins.h"
|
||||||
@ -826,6 +827,7 @@ python_plugin_destroy(ProfPlugin *plugin)
|
|||||||
{
|
{
|
||||||
disable_python_threads();
|
disable_python_threads();
|
||||||
callbacks_remove(plugin->name);
|
callbacks_remove(plugin->name);
|
||||||
|
disco_remove_features(plugin->name);
|
||||||
free(plugin->name);
|
free(plugin->name);
|
||||||
free(plugin);
|
free(plugin);
|
||||||
allow_python_threads();
|
allow_python_threads();
|
||||||
|
@ -653,6 +653,7 @@ caps_create_query_response_stanza(xmpp_ctx_t *const ctx)
|
|||||||
|
|
||||||
curr = g_list_next(curr);
|
curr = g_list_next(curr);
|
||||||
}
|
}
|
||||||
|
g_list_free(plugin_features);
|
||||||
|
|
||||||
xmpp_stanza_release(feature_receipts);
|
xmpp_stanza_release(feature_receipts);
|
||||||
xmpp_stanza_release(feature_ping);
|
xmpp_stanza_release(feature_ping);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user