diff --git a/src/xmpp.h b/src/xmpp.h index a050dd03..81e19c3f 100644 --- a/src/xmpp.h +++ b/src/xmpp.h @@ -163,9 +163,7 @@ void jabber_conn_set_status(const char * const message); char* jabber_get_account_name(void); // message functions - -int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, - void * const userdata); +void message_add_handlers(void); void message_send(const char * const msg, const char * const recipient); void message_send_groupchat(const char * const msg, const char * const recipient); void message_send_inactive(const char * const recipient); diff --git a/src/xmpp_conn.c b/src/xmpp_conn.c index 36f9973b..c0940bf2 100644 --- a/src/xmpp_conn.c +++ b/src/xmpp_conn.c @@ -403,8 +403,7 @@ _connection_handler(xmpp_conn_t * const conn, chat_sessions_init(); - xmpp_handler_add(conn, message_handler, NULL, STANZA_NAME_MESSAGE, NULL, ctx); - + message_add_handlers(); presence_add_handlers(); iq_add_handlers(); diff --git a/src/xmpp_message.c b/src/xmpp_message.c index 532b7c1b..c75df16a 100644 --- a/src/xmpp_message.c +++ b/src/xmpp_message.c @@ -32,9 +32,21 @@ #include "profanity.h" #include "xmpp.h" +#define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_MESSAGE, type, ctx) + +static int _message_handler(xmpp_conn_t * const conn, + xmpp_stanza_t * const stanza, void * const userdata); static int _groupchat_message_handler(xmpp_stanza_t * const stanza); static int _chat_message_handler(xmpp_stanza_t * const stanza); +void +message_add_handlers(void) +{ + xmpp_conn_t * const conn = jabber_get_conn(); + xmpp_ctx_t * const ctx = jabber_get_ctx(); + HANDLE(NULL, NULL, _message_handler); +} + void message_send(const char * const msg, const char * const recipient) { @@ -124,8 +136,8 @@ message_send_gone(const char * const recipient) chat_session_set_sent(recipient); } -int -message_handler(xmpp_conn_t * const conn, +static int +_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { gchar *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);