about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-02-17 02:10:56 +0000
committerJames Booth <boothj5@gmail.com>2013-02-17 02:10:56 +0000
commitbced3d4b36c2080b6dee2c2aa14b64c8cf405cc5 (patch)
tree96aeb660a422139f6524842cb68e1309176e80e9 /src/xmpp
parent44d2f8da7a235997049bac68fea746682ae49e9f (diff)
downloadprofani-tty-bced3d4b36c2080b6dee2c2aa14b64c8cf405cc5.tar.gz
Added autocomplete for /software command
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/iq.c52
-rw-r--r--src/xmpp/stanza.c19
-rw-r--r--src/xmpp/stanza.h1
-rw-r--r--src/xmpp/xmpp.h3
4 files changed, 75 insertions, 0 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 070fefba..b98d3bc6 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -30,6 +30,7 @@
 #include "common.h"
 #include "contact_list.h"
 #include "log.h"
+#include "profanity.h"
 #include "xmpp/capabilities.h"
 #include "xmpp/connection.h"
 #include "xmpp/iq.h"
@@ -52,6 +53,8 @@ static int _iq_handle_discoinfo_get(xmpp_conn_t * const conn,
     xmpp_stanza_t * const stanza, void * const userdata);
 static int _iq_handle_discoinfo_result(xmpp_conn_t * const conn,
     xmpp_stanza_t * const stanza, void * const userdata);
+static int _iq_handle_version_result(xmpp_conn_t * const conn,
+    xmpp_stanza_t * const stanza, void * const userdata);
 
 void
 iq_add_handlers(void)
@@ -64,6 +67,7 @@ iq_add_handlers(void)
     HANDLE(XMPP_NS_DISCO_INFO,  STANZA_TYPE_GET,    _iq_handle_discoinfo_get);
     HANDLE(XMPP_NS_DISCO_INFO,  STANZA_TYPE_RESULT, _iq_handle_discoinfo_result);
     HANDLE(STANZA_NS_VERSION,   STANZA_TYPE_GET,    _iq_handle_version_get);
+    HANDLE(STANZA_NS_VERSION,   STANZA_TYPE_RESULT, _iq_handle_version_result);
     HANDLE(STANZA_NS_PING,      STANZA_TYPE_GET,    _iq_handle_ping_get);
 }
 
@@ -77,6 +81,16 @@ iq_roster_request(void)
     xmpp_stanza_release(iq);
 }
 
+void
+iq_send_software_version(const char * const fulljid)
+{
+    xmpp_conn_t * const conn = connection_get_conn();
+    xmpp_ctx_t * const ctx = connection_get_ctx();
+    xmpp_stanza_t *iq = stanza_create_software_version_iq(ctx, fulljid);
+    xmpp_send(conn, iq);
+    xmpp_stanza_release(iq);
+}
+
 static int
 _iq_handle_error(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
     void * const userdata)
@@ -161,6 +175,44 @@ _iq_handle_roster_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
 }
 
 static int
+_iq_handle_version_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
+    void * const userdata)
+{
+    const char *jid = xmpp_stanza_get_attribute(stanza, "from");
+
+    xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
+    if (query == NULL) {
+        return 1;
+    }
+
+    char *ns = xmpp_stanza_get_ns(query);
+    if (g_strcmp0(ns, STANZA_NS_VERSION) != 0) {
+        return 1;
+    }
+
+    char *name_str = NULL;
+    char *version_str = NULL;
+    char *os_str = NULL;
+    xmpp_stanza_t *name = xmpp_stanza_get_child_by_name(query, "name");
+    xmpp_stanza_t *version = xmpp_stanza_get_child_by_name(query, "version");
+    xmpp_stanza_t *os = xmpp_stanza_get_child_by_name(query, "os");
+
+    if (name != NULL) {
+        name_str = xmpp_stanza_get_text(name);
+    }
+    if (version != NULL) {
+        version_str = xmpp_stanza_get_text(version);
+    }
+    if (os != NULL) {
+        os_str = xmpp_stanza_get_text(os);
+    }
+
+    prof_handle_version_result(jid, name_str, version_str, os_str);
+
+    return 1;
+}
+
+static int
 _iq_handle_ping_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
     void * const userdata)
 {
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 40076939..8e023430 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -140,6 +140,25 @@ stanza_create_presence(xmpp_ctx_t * const ctx)
 }
 
 xmpp_stanza_t *
+stanza_create_software_version_iq(xmpp_ctx_t *ctx, const char * const fulljid)
+{
+    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
+    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
+    xmpp_stanza_set_id(iq, "sv");
+    xmpp_stanza_set_attribute(iq, "to", fulljid);
+
+    xmpp_stanza_t *query = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
+    xmpp_stanza_set_ns(query, STANZA_NS_VERSION);
+
+    xmpp_stanza_add_child(iq, query);
+    xmpp_stanza_release(query);
+
+    return iq;
+}
+
+xmpp_stanza_t *
 stanza_create_roster_iq(xmpp_ctx_t *ctx)
 {
     xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index 2f3e0216..d07568a7 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -162,5 +162,6 @@ void stanza_attach_status(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence
     const char * const status);
 
 const char * stanza_get_presence_string_from_type(resource_presence_t presence_type);
+xmpp_stanza_t * stanza_create_software_version_iq(xmpp_ctx_t *ctx, const char * const fulljid);
 
 #endif
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 5edd253e..44f89407 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -88,6 +88,9 @@ void presence_leave_chat_room(const char * const room_jid);
 void presence_update(resource_presence_t status, const char * const msg,
     int idle);
 
+// iq functions
+void iq_send_software_version(const char * const fulljid);
+
 // caps functions
 Capabilities* caps_get(const char * const caps_str);
 void caps_close(void);