about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-01-20 13:56:50 +0000
committerJames Booth <boothj5@gmail.com>2013-01-20 13:56:50 +0000
commit4ecb69bfab47b5c08f8b5fca97008fe10abc96ba (patch)
treef8889c1c8babf89a452db04f9d490adb278fc789
parent3386ba3a1ea9f0abd620934d044c3e3f05660eec (diff)
downloadprofani-tty-4ecb69bfab47b5c08f8b5fca97008fe10abc96ba.tar.gz
Moved processing of caps str to stanza.c
-rw-r--r--src/jabber.c31
-rw-r--r--src/stanza.c19
-rw-r--r--src/stanza.h4
3 files changed, 20 insertions, 34 deletions
diff --git a/src/jabber.c b/src/jabber.c
index e947bdf0..f6f104b8 100644
--- a/src/jabber.c
+++ b/src/jabber.c
@@ -1054,21 +1054,7 @@ _room_presence_handler(const char * const jid, xmpp_stanza_t * const stanza)
     } else {
         char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
         char *show_str, *status_str;
-
-        char *caps_str = NULL;
-        xmpp_stanza_t *caps = stanza_get_caps(stanza);
-        if (caps != NULL) {
-            char *node = xmpp_stanza_get_attribute(caps, STANZA_ATTR_NODE);
-            char *ver = xmpp_stanza_get_attribute(caps, STANZA_ATTR_VER);
-
-            if ((node != NULL) && (ver != NULL)) {
-                GString *caps_gstr = g_string_new(node);
-                g_string_append(caps_gstr, "#");
-                g_string_append(caps_gstr, ver);
-                caps_str = caps_gstr->str;
-                g_string_free(caps_gstr, FALSE);
-            }
-        }
+        char *caps_str = stanza_get_caps_str(stanza);
 
         if (caps_str != NULL) {
             if (!caps_contains(caps_str)) {
@@ -1158,20 +1144,7 @@ _presence_handler(xmpp_conn_t * const conn,
             g_date_time_unref(now);
         }
 
-        char *caps_str = NULL;
-        xmpp_stanza_t *caps = stanza_get_caps(stanza);
-        if (caps != NULL) {
-            char *node = xmpp_stanza_get_attribute(caps, STANZA_ATTR_NODE);
-            char *ver = xmpp_stanza_get_attribute(caps, STANZA_ATTR_VER);
-
-            if ((node != NULL) && (ver != NULL)) {
-                GString *caps_gstr = g_string_new(node);
-                g_string_append(caps_gstr, "#");
-                g_string_append(caps_gstr, ver);
-                caps_str = caps_gstr->str;
-                g_string_free(caps_gstr, FALSE);
-            }
-        }
+        char *caps_str = stanza_get_caps_str(stanza);
 
         if (caps_str != NULL) {
             if (!caps_contains(caps_str)) {
diff --git a/src/stanza.c b/src/stanza.c
index 9ea9df31..ea592127 100644
--- a/src/stanza.c
+++ b/src/stanza.c
@@ -413,8 +413,8 @@ stanza_get_idle_time(xmpp_stanza_t * const stanza)
     }
 }
 
-xmpp_stanza_t *
-stanza_get_caps(xmpp_stanza_t * const stanza)
+char *
+stanza_get_caps_str(xmpp_stanza_t * const stanza)
 {
     xmpp_stanza_t *caps = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_C);
 
@@ -426,5 +426,18 @@ stanza_get_caps(xmpp_stanza_t * const stanza)
         return NULL;
     }
 
-    return caps;
+    char *node = xmpp_stanza_get_attribute(caps, STANZA_ATTR_NODE);
+    char *ver = xmpp_stanza_get_attribute(caps, STANZA_ATTR_VER);
+
+    if ((node == NULL) || (ver == NULL)) {
+        return NULL;
+    }
+
+    GString *caps_gstr = g_string_new(node);
+    g_string_append(caps_gstr, "#");
+    g_string_append(caps_gstr, ver);
+    char *caps_str = caps_gstr->str;
+    g_string_free(caps_gstr, FALSE);
+
+    return  caps_str;
 }
diff --git a/src/stanza.h b/src/stanza.h
index c5cec333..adebc37d 100644
--- a/src/stanza.h
+++ b/src/stanza.h
@@ -121,9 +121,9 @@ gboolean stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
     const char * const self_jid);
 gboolean stanza_is_room_nick_change(xmpp_stanza_t * const stanza);
 
-char* stanza_get_new_nick(xmpp_stanza_t * const stanza);
+char * stanza_get_new_nick(xmpp_stanza_t * const stanza);
 
 int stanza_get_idle_time(xmpp_stanza_t * const stanza);
-xmpp_stanza_t * stanza_get_caps(xmpp_stanza_t * const stanza);
+char * stanza_get_caps_str(xmpp_stanza_t * const stanza);
 
 #endif