about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-01-29 00:45:03 +0000
committerJames Booth <boothj5@gmail.com>2013-01-29 00:45:03 +0000
commitf60864f87040761ce4142736b3932711ab8c9e94 (patch)
treed3bebe5b46c84c987227f9f9b9f0e03f51d45ef5 /src
parent0f01f30b9c6cefcb0b6e79e4e5f59652bf50eb73 (diff)
downloadprofani-tty-f60864f87040761ce4142736b3932711ab8c9e94.tar.gz
Added message_add_handlers()
Diffstat (limited to 'src')
-rw-r--r--src/xmpp.h4
-rw-r--r--src/xmpp_conn.c3
-rw-r--r--src/xmpp_message.c16
3 files changed, 16 insertions, 7 deletions
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,10 +32,22 @@
 #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)
 {
     xmpp_conn_t * const conn = jabber_get_conn();
@@ -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);