mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added stanza send hooks for plugins
This commit is contained in:
parent
ce9b0836a0
commit
d0397f3da5
@ -97,6 +97,9 @@ c_plugin_create(const char * const filename)
|
||||
plugin->post_priv_message_display = c_post_priv_message_display_hook;
|
||||
plugin->pre_priv_message_send = c_pre_priv_message_send_hook;
|
||||
plugin->post_priv_message_send = c_post_priv_message_send_hook;
|
||||
plugin->on_message_stanza_send = c_on_message_stanza_send_hook;
|
||||
plugin->on_presence_stanza_send = c_on_presence_stanza_send_hook;
|
||||
plugin->on_iq_stanza_send = c_on_iq_stanza_send_hook;
|
||||
|
||||
g_string_free(path, TRUE);
|
||||
g_free(module_name);
|
||||
@ -347,6 +350,48 @@ c_post_priv_message_send_hook(ProfPlugin *plugin, const char * const room, const
|
||||
func (room, nick, message);
|
||||
}
|
||||
|
||||
char *
|
||||
c_on_message_stanza_send_hook(ProfPlugin *plugin, const char * const text)
|
||||
{
|
||||
void * f = NULL;
|
||||
char* (*func)(const char * const __text);
|
||||
assert (plugin && plugin->module);
|
||||
|
||||
if (NULL == (f = dlsym (plugin->module, "prof_on_message_stanza_send")))
|
||||
return NULL;
|
||||
|
||||
func = (char* (*)(const char * const)) f;
|
||||
return func (text);
|
||||
}
|
||||
|
||||
char *
|
||||
c_on_presence_stanza_send_hook(ProfPlugin *plugin, const char * const text)
|
||||
{
|
||||
void * f = NULL;
|
||||
char* (*func)(const char * const __text);
|
||||
assert (plugin && plugin->module);
|
||||
|
||||
if (NULL == (f = dlsym (plugin->module, "prof_on_presence_stanza_send")))
|
||||
return NULL;
|
||||
|
||||
func = (char* (*)(const char * const)) f;
|
||||
return func (text);
|
||||
}
|
||||
|
||||
char *
|
||||
c_on_iq_stanza_send_hook(ProfPlugin *plugin, const char * const text)
|
||||
{
|
||||
void * f = NULL;
|
||||
char* (*func)(const char * const __text);
|
||||
assert (plugin && plugin->module);
|
||||
|
||||
if (NULL == (f = dlsym (plugin->module, "prof_on_iq_stanza_send")))
|
||||
return NULL;
|
||||
|
||||
func = (char* (*)(const char * const)) f;
|
||||
return func (text);
|
||||
}
|
||||
|
||||
void
|
||||
c_plugin_destroy(ProfPlugin *plugin)
|
||||
{
|
||||
|
@ -64,4 +64,8 @@ void c_post_priv_message_display_hook(ProfPlugin *plugin, const char * const ro
|
||||
char* c_pre_priv_message_send_hook(ProfPlugin *plugin, const char * const room, const char * const nick, const char * const message);
|
||||
void c_post_priv_message_send_hook(ProfPlugin *plugin, const char * const room, const char * const nick, const char * const message);
|
||||
|
||||
char* c_on_message_stanza_send_hook(ProfPlugin *plugin, const char *const text);
|
||||
char* c_on_presence_stanza_send_hook(ProfPlugin *plugin, const char *const text);
|
||||
char* c_on_iq_stanza_send_hook(ProfPlugin *plugin, const char *const text);
|
||||
|
||||
#endif
|
||||
|
@ -409,6 +409,69 @@ plugins_post_priv_message_send(const char * const jid, const char * const messag
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
char*
|
||||
plugins_on_message_stanza_send(const char *const text)
|
||||
{
|
||||
char *new_stanza = NULL;
|
||||
char *curr_stanza = strdup(text);
|
||||
|
||||
GSList *curr = plugins;
|
||||
while (curr) {
|
||||
ProfPlugin *plugin = curr->data;
|
||||
new_stanza = plugin->on_message_stanza_send(plugin, curr_stanza);
|
||||
if (new_stanza) {
|
||||
free(curr_stanza);
|
||||
curr_stanza = strdup(new_stanza);
|
||||
free(new_stanza);
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
return curr_stanza;
|
||||
}
|
||||
|
||||
char*
|
||||
plugins_on_presence_stanza_send(const char *const text)
|
||||
{
|
||||
char *new_stanza = NULL;
|
||||
char *curr_stanza = strdup(text);
|
||||
|
||||
GSList *curr = plugins;
|
||||
while (curr) {
|
||||
ProfPlugin *plugin = curr->data;
|
||||
new_stanza = plugin->on_presence_stanza_send(plugin, curr_stanza);
|
||||
if (new_stanza) {
|
||||
free(curr_stanza);
|
||||
curr_stanza = strdup(new_stanza);
|
||||
free(new_stanza);
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
return curr_stanza;
|
||||
}
|
||||
|
||||
char*
|
||||
plugins_on_iq_stanza_send(const char *const text)
|
||||
{
|
||||
char *new_stanza = NULL;
|
||||
char *curr_stanza = strdup(text);
|
||||
|
||||
GSList *curr = plugins;
|
||||
while (curr) {
|
||||
ProfPlugin *plugin = curr->data;
|
||||
new_stanza = plugin->on_iq_stanza_send(plugin, curr_stanza);
|
||||
if (new_stanza) {
|
||||
free(curr_stanza);
|
||||
curr_stanza = strdup(new_stanza);
|
||||
free(new_stanza);
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
return curr_stanza;
|
||||
}
|
||||
|
||||
void
|
||||
plugins_shutdown(void)
|
||||
{
|
||||
|
@ -70,6 +70,9 @@ typedef struct prof_plugin_t {
|
||||
char* (*pre_priv_message_send)(struct prof_plugin_t* plugin, const char * const room, const char * const nick, const char * const message);
|
||||
void (*post_priv_message_send)(struct prof_plugin_t* plugin, const char * const room, const char * const nick, const char * const message);
|
||||
|
||||
char* (*on_message_stanza_send)(struct prof_plugin_t* plugin, const char *const text);
|
||||
char* (*on_presence_stanza_send)(struct prof_plugin_t* plugin, const char *const text);
|
||||
char* (*on_iq_stanza_send)(struct prof_plugin_t* plugin, const char *const text);
|
||||
} ProfPlugin;
|
||||
|
||||
void plugins_init(void);
|
||||
@ -100,12 +103,16 @@ void plugins_post_priv_message_display(const char * const jid, const char *mess
|
||||
char* plugins_pre_priv_message_send(const char * const jid, const char * const message);
|
||||
void plugins_post_priv_message_send(const char * const jid, const char * const message);
|
||||
|
||||
void plugins_win_process_line(char *win, const char * const line);
|
||||
|
||||
char* plugins_on_message_stanza_send(const char *const text);
|
||||
char* plugins_on_presence_stanza_send(const char *const text);
|
||||
char* plugins_on_iq_stanza_send(const char *const text);
|
||||
|
||||
gboolean plugins_run_command(const char * const cmd);
|
||||
void plugins_run_timed(void);
|
||||
GList* plugins_get_command_names(void);
|
||||
gchar * plugins_get_dir(void);
|
||||
CommandHelp* plugins_get_help(const char *const cmd);
|
||||
|
||||
void plugins_win_process_line(char *win, const char * const line);
|
||||
|
||||
#endif
|
||||
|
@ -115,6 +115,9 @@ python_plugin_create(const char * const filename)
|
||||
plugin->post_priv_message_display = python_post_priv_message_display_hook;
|
||||
plugin->pre_priv_message_send = python_pre_priv_message_send_hook;
|
||||
plugin->post_priv_message_send = python_post_priv_message_send_hook;
|
||||
plugin->on_message_stanza_send = python_on_message_stanza_send_hook;
|
||||
plugin->on_presence_stanza_send = python_on_presence_stanza_send_hook;
|
||||
plugin->on_iq_stanza_send = python_on_iq_stanza_send_hook;
|
||||
g_free(module_name);
|
||||
|
||||
allow_python_threads();
|
||||
@ -568,6 +571,114 @@ python_post_priv_message_send_hook(ProfPlugin *plugin, const char * const room,
|
||||
allow_python_threads();
|
||||
}
|
||||
|
||||
char*
|
||||
python_on_message_stanza_send_hook(ProfPlugin *plugin, const char *const text)
|
||||
{
|
||||
disable_python_threads();
|
||||
PyObject *p_args = Py_BuildValue("(s)", text);
|
||||
PyObject *p_function;
|
||||
|
||||
PyObject *p_module = plugin->module;
|
||||
if (PyObject_HasAttrString(p_module, "prof_on_message_stanza_send")) {
|
||||
p_function = PyObject_GetAttrString(p_module, "prof_on_message_stanza_send");
|
||||
python_check_error();
|
||||
if (p_function && PyCallable_Check(p_function)) {
|
||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||
python_check_error();
|
||||
Py_XDECREF(p_function);
|
||||
if (PyUnicode_Check(result)) {
|
||||
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
||||
Py_XDECREF(result);
|
||||
allow_python_threads();
|
||||
return result_str;
|
||||
} else if (result != Py_None) {
|
||||
char *result_str = strdup(PyString_AsString(result));
|
||||
Py_XDECREF(result);
|
||||
allow_python_threads();
|
||||
return result_str;
|
||||
} else {
|
||||
allow_python_threads();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allow_python_threads();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char*
|
||||
python_on_presence_stanza_send_hook(ProfPlugin *plugin, const char *const text)
|
||||
{
|
||||
disable_python_threads();
|
||||
PyObject *p_args = Py_BuildValue("(s)", text);
|
||||
PyObject *p_function;
|
||||
|
||||
PyObject *p_module = plugin->module;
|
||||
if (PyObject_HasAttrString(p_module, "prof_on_presence_stanza_send")) {
|
||||
p_function = PyObject_GetAttrString(p_module, "prof_on_presence_stanza_send");
|
||||
python_check_error();
|
||||
if (p_function && PyCallable_Check(p_function)) {
|
||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||
python_check_error();
|
||||
Py_XDECREF(p_function);
|
||||
if (PyUnicode_Check(result)) {
|
||||
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
||||
Py_XDECREF(result);
|
||||
allow_python_threads();
|
||||
return result_str;
|
||||
} else if (result != Py_None) {
|
||||
char *result_str = strdup(PyString_AsString(result));
|
||||
Py_XDECREF(result);
|
||||
allow_python_threads();
|
||||
return result_str;
|
||||
} else {
|
||||
allow_python_threads();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allow_python_threads();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char*
|
||||
python_on_iq_stanza_send_hook(ProfPlugin *plugin, const char *const text)
|
||||
{
|
||||
disable_python_threads();
|
||||
PyObject *p_args = Py_BuildValue("(s)", text);
|
||||
PyObject *p_function;
|
||||
|
||||
PyObject *p_module = plugin->module;
|
||||
if (PyObject_HasAttrString(p_module, "prof_on_iq_stanza_send")) {
|
||||
p_function = PyObject_GetAttrString(p_module, "prof_on_iq_stanza_send");
|
||||
python_check_error();
|
||||
if (p_function && PyCallable_Check(p_function)) {
|
||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||
python_check_error();
|
||||
Py_XDECREF(p_function);
|
||||
if (PyUnicode_Check(result)) {
|
||||
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
||||
Py_XDECREF(result);
|
||||
allow_python_threads();
|
||||
return result_str;
|
||||
} else if (result != Py_None) {
|
||||
char *result_str = strdup(PyString_AsString(result));
|
||||
Py_XDECREF(result);
|
||||
allow_python_threads();
|
||||
return result_str;
|
||||
} else {
|
||||
allow_python_threads();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allow_python_threads();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
python_check_error(void)
|
||||
{
|
||||
|
@ -64,5 +64,8 @@ void python_post_priv_message_display_hook(ProfPlugin *plugin, const char * con
|
||||
char* python_pre_priv_message_send_hook(ProfPlugin *plugin, const char * const room, const char * const nick, const char * const message);
|
||||
void python_post_priv_message_send_hook(ProfPlugin *plugin, const char * const room, const char * const nick, const char * const message);
|
||||
|
||||
char* python_on_message_stanza_send_hook(ProfPlugin *plugin, const char *const text);
|
||||
char* python_on_presence_stanza_send_hook(ProfPlugin *plugin, const char *const text);
|
||||
char* python_on_iq_stanza_send_hook(ProfPlugin *plugin, const char *const text);
|
||||
|
||||
#endif
|
||||
|
@ -56,6 +56,7 @@
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "xmpp/bookmark.h"
|
||||
#include "ui/ui.h"
|
||||
#include "plugins/plugins.h"
|
||||
|
||||
#define BOOKMARK_TIMEOUT 5000
|
||||
|
||||
@ -70,6 +71,8 @@ static void _bookmark_item_destroy(gpointer item);
|
||||
static int _match_bookmark_by_jid(gconstpointer a, gconstpointer b);
|
||||
static void _send_bookmarks(void);
|
||||
|
||||
static void _send_iq_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza);
|
||||
|
||||
void
|
||||
bookmark_request(void)
|
||||
{
|
||||
@ -92,7 +95,7 @@ bookmark_request(void)
|
||||
|
||||
iq = stanza_create_bookmarks_storage_request(ctx);
|
||||
xmpp_stanza_set_id(iq, id);
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -474,6 +477,21 @@ _send_bookmarks(void)
|
||||
xmpp_stanza_release(storage);
|
||||
xmpp_stanza_release(query);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
static void
|
||||
_send_iq_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza)
|
||||
{
|
||||
char *text;
|
||||
size_t text_size;
|
||||
xmpp_stanza_to_text(stanza, &text, &text_size);
|
||||
|
||||
char *plugin_text = plugins_on_iq_stanza_send(text);
|
||||
if (plugin_text) {
|
||||
xmpp_send_raw(conn, plugin_text, strlen(plugin_text));
|
||||
} else {
|
||||
xmpp_send_raw(conn, text, text_size);
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,7 @@
|
||||
#include "xmpp/form.h"
|
||||
#include "roster_list.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "plugins/plugins.h"
|
||||
|
||||
#define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_IQ, type, ctx)
|
||||
|
||||
@ -98,6 +99,8 @@ static int _caps_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const
|
||||
static int _caps_response_handler_for_jid(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
|
||||
|
||||
static void _send_iq_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza);
|
||||
|
||||
static gboolean autoping_wait = FALSE;
|
||||
static GTimer *autoping_time = NULL;
|
||||
|
||||
@ -179,7 +182,7 @@ iq_room_list_request(gchar *conferencejid)
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, "confreq", conferencejid);
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -193,7 +196,7 @@ iq_enable_carbons(void)
|
||||
|
||||
xmpp_id_handler_add(conn, _enable_carbons_handler, id, NULL);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -207,7 +210,7 @@ iq_disable_carbons(void)
|
||||
|
||||
xmpp_id_handler_add(conn, _disable_carbons_handler, id, NULL);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -223,7 +226,7 @@ iq_disco_info_request(gchar *jid)
|
||||
|
||||
free(id);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -239,7 +242,7 @@ iq_last_activity_request(gchar *jid)
|
||||
|
||||
free(id);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -259,7 +262,7 @@ iq_room_info_request(const char *const room, gboolean display_result)
|
||||
|
||||
free(id);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -288,7 +291,7 @@ iq_send_caps_request_for_jid(const char *const to, const char *const id,
|
||||
|
||||
xmpp_id_handler_add(conn, _caps_response_handler_for_jid, id, strdup(to));
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -315,7 +318,7 @@ iq_send_caps_request(const char *const to, const char *const id,
|
||||
|
||||
xmpp_id_handler_add(conn, _caps_response_handler, id, NULL);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -342,7 +345,7 @@ iq_send_caps_request_legacy(const char *const to, const char *const id,
|
||||
xmpp_id_handler_add(conn, _caps_response_handler_legacy, id, node_str->str);
|
||||
g_string_free(node_str, FALSE);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -352,7 +355,7 @@ iq_disco_items_request(gchar *jid)
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, "discoitemsreq", jid);
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -366,7 +369,7 @@ iq_send_software_version(const char *const fulljid)
|
||||
char *id = xmpp_stanza_get_id(iq);
|
||||
xmpp_id_handler_add(conn, _version_result_handler, id, strdup(fulljid));
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -376,7 +379,7 @@ iq_confirm_instant_room(const char *const room_jid)
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_instant_room_request_iq(ctx, room_jid);
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -390,7 +393,7 @@ iq_destroy_room(const char *const room_jid)
|
||||
char *id = xmpp_stanza_get_id(iq);
|
||||
xmpp_id_handler_add(conn, _destroy_room_result_handler, id, NULL);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -404,7 +407,7 @@ iq_request_room_config_form(const char *const room_jid)
|
||||
char *id = xmpp_stanza_get_id(iq);
|
||||
xmpp_id_handler_add(conn, _room_config_handler, id, NULL);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -418,7 +421,7 @@ iq_submit_room_config(const char *const room, DataForm *form)
|
||||
char *id = xmpp_stanza_get_id(iq);
|
||||
xmpp_id_handler_add(conn, _room_config_submit_handler, id, NULL);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -428,7 +431,7 @@ iq_room_config_cancel(const char *const room_jid)
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_room_config_cancel_iq(ctx, room_jid);
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -442,7 +445,7 @@ iq_room_affiliation_list(const char *const room, char *affiliation)
|
||||
char *id = xmpp_stanza_get_id(iq);
|
||||
xmpp_id_handler_add(conn, _room_affiliation_list_result_handler, id, strdup(affiliation));
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -456,7 +459,7 @@ iq_room_kick_occupant(const char *const room, const char *const nick, const char
|
||||
char *id = xmpp_stanza_get_id(iq);
|
||||
xmpp_id_handler_add(conn, _room_kick_result_handler, id, strdup(nick));
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -481,7 +484,7 @@ iq_room_affiliation_set(const char *const room, const char *const jid, char *aff
|
||||
|
||||
xmpp_id_handler_add(conn, _room_affiliation_set_result_handler, id, affiliation_set);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -501,7 +504,7 @@ iq_room_role_set(const char *const room, const char *const nick, char *role,
|
||||
|
||||
xmpp_id_handler_add(conn, _room_role_set_result_handler, id, role_set);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -515,7 +518,7 @@ iq_room_role_list(const char *const room, char *role)
|
||||
char *id = xmpp_stanza_get_id(iq);
|
||||
xmpp_id_handler_add(conn, _room_role_list_result_handler, id, strdup(role));
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -530,7 +533,7 @@ iq_send_ping(const char *const target)
|
||||
GDateTime *now = g_date_time_new_now_local();
|
||||
xmpp_id_handler_add(conn, _manual_pong_handler, id, now);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -900,7 +903,7 @@ _autoping_timed_handler(xmpp_conn_t *const conn, void *const userdata)
|
||||
// add pong handler
|
||||
xmpp_id_handler_add(conn, _auto_pong_handler, id, ctx);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
autoping_wait = TRUE;
|
||||
if (autoping_time) {
|
||||
@ -1039,7 +1042,7 @@ _ping_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
|
||||
xmpp_stanza_set_attribute(pong, STANZA_ATTR_ID, id);
|
||||
}
|
||||
|
||||
xmpp_send(conn, pong);
|
||||
_send_iq_stanza(conn, pong);
|
||||
xmpp_stanza_release(pong);
|
||||
|
||||
return 1;
|
||||
@ -1099,7 +1102,7 @@ _version_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
|
||||
xmpp_stanza_add_child(query, version);
|
||||
xmpp_stanza_add_child(response, query);
|
||||
|
||||
xmpp_send(conn, response);
|
||||
_send_iq_stanza(conn, response);
|
||||
|
||||
g_string_free(version_str, TRUE);
|
||||
xmpp_stanza_release(name_txt);
|
||||
@ -1137,7 +1140,7 @@ _disco_items_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
|
||||
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
|
||||
xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS);
|
||||
xmpp_stanza_add_child(response, query);
|
||||
xmpp_send(conn, response);
|
||||
_send_iq_stanza(conn, response);
|
||||
|
||||
xmpp_stanza_release(response);
|
||||
}
|
||||
@ -1175,7 +1178,7 @@ _last_activity_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
|
||||
xmpp_stanza_add_child(response, query);
|
||||
xmpp_stanza_release(query);
|
||||
|
||||
xmpp_send(conn, response);
|
||||
_send_iq_stanza(conn, response);
|
||||
|
||||
xmpp_stanza_release(response);
|
||||
} else {
|
||||
@ -1199,7 +1202,7 @@ _last_activity_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
|
||||
xmpp_stanza_add_child(response, error);
|
||||
xmpp_stanza_release(error);
|
||||
|
||||
xmpp_send(conn, response);
|
||||
_send_iq_stanza(conn, response);
|
||||
|
||||
xmpp_stanza_release(response);
|
||||
}
|
||||
@ -1236,7 +1239,7 @@ _disco_info_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
|
||||
xmpp_stanza_set_attribute(query, STANZA_ATTR_NODE, node_str);
|
||||
}
|
||||
xmpp_stanza_add_child(response, query);
|
||||
xmpp_send(conn, response);
|
||||
_send_iq_stanza(conn, response);
|
||||
|
||||
xmpp_stanza_release(query);
|
||||
xmpp_stanza_release(response);
|
||||
@ -1833,3 +1836,18 @@ _disco_items_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
_send_iq_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza)
|
||||
{
|
||||
char *text;
|
||||
size_t text_size;
|
||||
xmpp_stanza_to_text(stanza, &text, &text_size);
|
||||
|
||||
char *plugin_text = plugins_on_iq_stanza_send(text);
|
||||
if (plugin_text) {
|
||||
xmpp_send_raw(conn, plugin_text, strlen(plugin_text));
|
||||
} else {
|
||||
xmpp_send_raw(conn, text, text_size);
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,7 @@
|
||||
#include "xmpp/stanza.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "pgp/gpg.h"
|
||||
#include "plugins/plugins.h"
|
||||
|
||||
#define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_MESSAGE, type, ctx)
|
||||
|
||||
@ -68,6 +69,7 @@ static int _conference_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const sta
|
||||
static int _captcha_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _message_error_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _receipt_received_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static void _send_message_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza);
|
||||
|
||||
void
|
||||
message_add_handlers(void)
|
||||
@ -139,7 +141,7 @@ message_send_chat(const char *const barejid, const char *const msg)
|
||||
stanza_attach_receipt_request(ctx, message);
|
||||
}
|
||||
|
||||
xmpp_send(conn, message);
|
||||
_send_message_stanza(conn, message);
|
||||
xmpp_stanza_release(message);
|
||||
|
||||
return id;
|
||||
@ -195,7 +197,7 @@ message_send_chat_pgp(const char *const barejid, const char *const msg)
|
||||
stanza_attach_receipt_request(ctx, message);
|
||||
}
|
||||
|
||||
xmpp_send(conn, message);
|
||||
_send_message_stanza(conn, message);
|
||||
xmpp_stanza_release(message);
|
||||
|
||||
return id;
|
||||
@ -226,7 +228,7 @@ message_send_chat_otr(const char *const barejid, const char *const msg)
|
||||
stanza_attach_receipt_request(ctx, message);
|
||||
}
|
||||
|
||||
xmpp_send(conn, message);
|
||||
_send_message_stanza(conn, message);
|
||||
xmpp_stanza_release(message);
|
||||
|
||||
return id;
|
||||
@ -241,7 +243,7 @@ message_send_private(const char *const fulljid, const char *const msg)
|
||||
xmpp_stanza_t *message = stanza_create_message(ctx, id, fulljid, STANZA_TYPE_CHAT, msg);
|
||||
free(id);
|
||||
|
||||
xmpp_send(conn, message);
|
||||
_send_message_stanza(conn, message);
|
||||
xmpp_stanza_release(message);
|
||||
}
|
||||
|
||||
@ -254,7 +256,7 @@ message_send_groupchat(const char *const roomjid, const char *const msg)
|
||||
xmpp_stanza_t *message = stanza_create_message(ctx, id, roomjid, STANZA_TYPE_GROUPCHAT, msg);
|
||||
free(id);
|
||||
|
||||
xmpp_send(conn, message);
|
||||
_send_message_stanza(conn, message);
|
||||
xmpp_stanza_release(message);
|
||||
}
|
||||
|
||||
@ -265,7 +267,7 @@ message_send_groupchat_subject(const char *const roomjid, const char *const subj
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *message = stanza_create_room_subject_message(ctx, roomjid, subject);
|
||||
|
||||
xmpp_send(conn, message);
|
||||
_send_message_stanza(conn, message);
|
||||
xmpp_stanza_release(message);
|
||||
}
|
||||
|
||||
@ -288,7 +290,7 @@ message_send_invite(const char *const roomjid, const char *const contact,
|
||||
stanza = stanza_create_mediated_invite(ctx, roomjid, contact, reason);
|
||||
}
|
||||
|
||||
xmpp_send(conn, stanza);
|
||||
_send_message_stanza(conn, stanza);
|
||||
xmpp_stanza_release(stanza);
|
||||
}
|
||||
|
||||
@ -299,7 +301,7 @@ message_send_composing(const char *const jid)
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
|
||||
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid, STANZA_NAME_COMPOSING);
|
||||
xmpp_send(conn, stanza);
|
||||
_send_message_stanza(conn, stanza);
|
||||
xmpp_stanza_release(stanza);
|
||||
|
||||
}
|
||||
@ -310,7 +312,7 @@ message_send_paused(const char *const jid)
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid, STANZA_NAME_PAUSED);
|
||||
xmpp_send(conn, stanza);
|
||||
_send_message_stanza(conn, stanza);
|
||||
xmpp_stanza_release(stanza);
|
||||
}
|
||||
|
||||
@ -321,7 +323,7 @@ message_send_inactive(const char *const jid)
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid, STANZA_NAME_INACTIVE);
|
||||
|
||||
xmpp_send(conn, stanza);
|
||||
_send_message_stanza(conn, stanza);
|
||||
xmpp_stanza_release(stanza);
|
||||
}
|
||||
|
||||
@ -331,7 +333,7 @@ message_send_gone(const char *const jid)
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid, STANZA_NAME_GONE);
|
||||
xmpp_send(conn, stanza);
|
||||
_send_message_stanza(conn, stanza);
|
||||
xmpp_stanza_release(stanza);
|
||||
}
|
||||
|
||||
@ -601,7 +603,7 @@ _message_send_receipt(const char *const fulljid, const char *const message_id)
|
||||
xmpp_stanza_add_child(message, receipt);
|
||||
xmpp_stanza_release(receipt);
|
||||
|
||||
xmpp_send(conn, message);
|
||||
_send_message_stanza(conn, message);
|
||||
xmpp_stanza_release(message);
|
||||
}
|
||||
|
||||
@ -830,3 +832,18 @@ _chat_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const
|
||||
jid_destroy(jid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
_send_message_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza)
|
||||
{
|
||||
char *text;
|
||||
size_t text_size;
|
||||
xmpp_stanza_to_text(stanza, &text, &text_size);
|
||||
|
||||
char *plugin_text = plugins_on_message_stanza_send(text);
|
||||
if (plugin_text) {
|
||||
xmpp_send_raw(conn, plugin_text, strlen(plugin_text));
|
||||
} else {
|
||||
xmpp_send_raw(conn, text, text_size);
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,7 @@
|
||||
#include "xmpp/connection.h"
|
||||
#include "xmpp/stanza.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "plugins/plugins.h"
|
||||
|
||||
static Autocomplete sub_requests_ac;
|
||||
|
||||
@ -75,6 +76,9 @@ static int _presence_error_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const
|
||||
void _send_caps_request(char *node, char *caps_key, char *id, char *from);
|
||||
static void _send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence);
|
||||
|
||||
static void _send_presence_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza);
|
||||
static void _send_iq_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza);
|
||||
|
||||
void
|
||||
presence_sub_requests_init(void)
|
||||
{
|
||||
@ -134,7 +138,7 @@ presence_subscription(const char *const jid, const jabber_subscr_t action)
|
||||
xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE);
|
||||
xmpp_stanza_set_type(presence, type);
|
||||
xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, jidp->barejid);
|
||||
xmpp_send(conn, presence);
|
||||
_send_presence_stanza(conn, presence);
|
||||
xmpp_stanza_release(presence);
|
||||
|
||||
jid_destroy(jidp);
|
||||
@ -239,7 +243,7 @@ presence_send(const resource_presence_t presence_type, const char *const msg, co
|
||||
stanza_attach_last_activity(ctx, presence, idle);
|
||||
}
|
||||
stanza_attach_caps(ctx, presence);
|
||||
xmpp_send(conn, presence);
|
||||
_send_presence_stanza(conn, presence);
|
||||
_send_room_presence(conn, presence);
|
||||
xmpp_stanza_release(presence);
|
||||
|
||||
@ -269,7 +273,7 @@ _send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence)
|
||||
|
||||
xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid);
|
||||
log_debug("Sending presence to room: %s", full_room_jid);
|
||||
xmpp_send(conn, presence);
|
||||
_send_presence_stanza(conn, presence);
|
||||
free(full_room_jid);
|
||||
}
|
||||
|
||||
@ -302,7 +306,7 @@ presence_join_room(char *room, char *nick, char * passwd)
|
||||
stanza_attach_priority(ctx, presence, pri);
|
||||
stanza_attach_caps(ctx, presence);
|
||||
|
||||
xmpp_send(conn, presence);
|
||||
_send_presence_stanza(conn, presence);
|
||||
xmpp_stanza_release(presence);
|
||||
|
||||
jid_destroy(jid);
|
||||
@ -332,7 +336,7 @@ presence_change_room_nick(const char *const room, const char *const nick)
|
||||
stanza_attach_priority(ctx, presence, pri);
|
||||
stanza_attach_caps(ctx, presence);
|
||||
|
||||
xmpp_send(conn, presence);
|
||||
_send_presence_stanza(conn, presence);
|
||||
xmpp_stanza_release(presence);
|
||||
|
||||
free(full_room_jid);
|
||||
@ -351,7 +355,7 @@ presence_leave_chat_room(const char *const room_jid)
|
||||
if (nick) {
|
||||
xmpp_stanza_t *presence = stanza_create_room_leave_presence(ctx, room_jid,
|
||||
nick);
|
||||
xmpp_send(conn, presence);
|
||||
_send_presence_stanza(conn, presence);
|
||||
xmpp_stanza_release(presence);
|
||||
}
|
||||
}
|
||||
@ -649,7 +653,7 @@ _send_caps_request(char *node, char *caps_key, char *id, char *from)
|
||||
if (!caps_contains(caps_key)) {
|
||||
log_debug("Capabilities not cached for '%s', sending discovery IQ.", from);
|
||||
xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, from, node);
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
} else {
|
||||
log_debug("Capabilities already cached, for %s", caps_key);
|
||||
@ -811,3 +815,33 @@ _muc_user_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *co
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
_send_presence_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza)
|
||||
{
|
||||
char *text;
|
||||
size_t text_size;
|
||||
xmpp_stanza_to_text(stanza, &text, &text_size);
|
||||
|
||||
char *plugin_text = plugins_on_presence_stanza_send(text);
|
||||
if (plugin_text) {
|
||||
xmpp_send_raw(conn, plugin_text, strlen(plugin_text));
|
||||
} else {
|
||||
xmpp_send_raw(conn, text, text_size);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_send_iq_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza)
|
||||
{
|
||||
char *text;
|
||||
size_t text_size;
|
||||
xmpp_stanza_to_text(stanza, &text, &text_size);
|
||||
|
||||
char *plugin_text = plugins_on_iq_stanza_send(text);
|
||||
if (plugin_text) {
|
||||
xmpp_send_raw(conn, plugin_text, strlen(plugin_text));
|
||||
} else {
|
||||
xmpp_send_raw(conn, text, text_size);
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,7 @@
|
||||
#include "roster_list.h"
|
||||
#include "xmpp/stanza.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "plugins/plugins.h"
|
||||
|
||||
#define HANDLE(type, func) xmpp_handler_add(conn, func, XMPP_NS_ROSTER, STANZA_NAME_IQ, type, ctx)
|
||||
|
||||
@ -77,6 +78,8 @@ static int _roster_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const
|
||||
static int _group_add_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _group_remove_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
|
||||
|
||||
static void _send_iq_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza);
|
||||
|
||||
// helper functions
|
||||
GSList* _get_groups_from_item(xmpp_stanza_t *item);
|
||||
|
||||
@ -96,7 +99,7 @@ roster_request(void)
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_roster_iq(ctx);
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -108,7 +111,7 @@ roster_send_add_new(const char *const barejid, const char *const name)
|
||||
char *id = create_unique_id("roster");
|
||||
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, id, barejid, name, NULL);
|
||||
free(id);
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -118,7 +121,7 @@ roster_send_remove(const char *const barejid)
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_roster_remove_set(ctx, barejid);
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -130,7 +133,7 @@ roster_send_name_change(const char *const barejid, const char *const new_name, G
|
||||
char *id = create_unique_id("roster");
|
||||
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, id, barejid, new_name, groups);
|
||||
free(id);
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
@ -160,7 +163,7 @@ roster_send_add_to_group(const char *const group, PContact contact)
|
||||
xmpp_id_handler_add(conn, _group_add_handler, unique_id, data);
|
||||
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, unique_id, p_contact_barejid(contact),
|
||||
p_contact_name(contact), new_groups);
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
free(unique_id);
|
||||
}
|
||||
@ -207,7 +210,7 @@ roster_send_remove_from_group(const char *const group, PContact contact)
|
||||
xmpp_id_handler_add(conn, _group_remove_handler, unique_id, data);
|
||||
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, unique_id, p_contact_barejid(contact),
|
||||
p_contact_name(contact), new_groups);
|
||||
xmpp_send(conn, iq);
|
||||
_send_iq_stanza(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
free(unique_id);
|
||||
}
|
||||
@ -358,3 +361,18 @@ _get_groups_from_item(xmpp_stanza_t *item)
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
static void
|
||||
_send_iq_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza)
|
||||
{
|
||||
char *text;
|
||||
size_t text_size;
|
||||
xmpp_stanza_to_text(stanza, &text, &text_size);
|
||||
|
||||
char *plugin_text = plugins_on_iq_stanza_send(text);
|
||||
if (plugin_text) {
|
||||
xmpp_send_raw(conn, plugin_text, strlen(plugin_text));
|
||||
} else {
|
||||
xmpp_send_raw(conn, text, text_size);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user