diff options
author | James Booth <boothj5@gmail.com> | 2013-03-14 23:41:36 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-03-14 23:41:36 +0000 |
commit | e2bc9bde749a5a0b48ffc2a331a9bf4cfa10af65 (patch) | |
tree | f90e17474273a8c97c0f3a84044d0b9c672d7406 /src/xmpp | |
parent | 7bd7c15994b50228b6f494a91daecd706eed9267 (diff) | |
download | profani-tty-e2bc9bde749a5a0b48ffc2a331a9bf4cfa10af65.tar.gz |
Implemented output for /disco info
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/iq.c | 74 | ||||
-rw-r--r-- | src/xmpp/stanza.h | 1 | ||||
-rw-r--r-- | src/xmpp/xmpp.h | 6 |
3 files changed, 79 insertions, 2 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index fbd1b360..4cbcf374 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -366,15 +366,85 @@ _iq_handle_discoinfo_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, return 1; } +static void +_identity_destroy(DiscoIdentity *identity) +{ + if (identity != NULL) { + FREE_SET_NULL(identity->name); + FREE_SET_NULL(identity->type); + FREE_SET_NULL(identity->category); + FREE_SET_NULL(identity); + } +} + +static void +_item_destroy(DiscoItem *item) +{ + if (item != NULL) { + FREE_SET_NULL(item->jid); + FREE_SET_NULL(item->name); + FREE_SET_NULL(item); + } +} + static int _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { log_debug("Recieved diso#info response"); const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (g_strcmp0(id, "discoinforeq") == 0) { - cons_show("GOT DISO INFO RESULT"); + GSList *identities = NULL; + GSList *features = NULL; + + xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); + + if (query != NULL) { + xmpp_stanza_t *child = xmpp_stanza_get_children(query); + while (child != NULL) { + const char *stanza_name = xmpp_stanza_get_name(child); + if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) { + const char *var = xmpp_stanza_get_attribute(child, STANZA_ATTR_VAR); + if (var != NULL) { + features = g_slist_append(features, strdup(var)); + } + } else if (g_strcmp0(stanza_name, STANZA_NAME_IDENTITY) == 0) { + const char *name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME); + const char *type = xmpp_stanza_get_attribute(child, STANZA_ATTR_TYPE); + const char *category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY); + + if ((name != NULL) || (category != NULL) || (type != NULL)) { + DiscoIdentity *identity = malloc(sizeof(struct disco_identity_t)); + + if (name != NULL) { + identity->name = strdup(name); + } else { + identity->name = NULL; + } + if (category != NULL) { + identity->category = strdup(category); + } else { + identity->category = NULL; + } + if (type != NULL) { + identity->type = strdup(type); + } else { + identity->type = NULL; + } + + identities = g_slist_append(identities, identity); + } + } + + child = xmpp_stanza_get_next(child); + } + + prof_handle_disco_info(from, identities, features); + g_slist_free_full(features, free); + g_slist_free_full(identities, (GDestroyNotify)_identity_destroy); + } } else if ((id != NULL) && (g_str_has_prefix(id, "disco"))) { log_debug("Response to query: %s", id); xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); @@ -531,7 +601,7 @@ _iq_handle_discoitems_result(xmpp_conn_t * const conn, xmpp_stanza_t * const sta prof_handle_disco_items(items, from); } - g_slist_free_full(items, free); + g_slist_free_full(items, (GDestroyNotify)_item_destroy); return 1; } diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index d6fb777a..e92d3186 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -78,6 +78,7 @@ #define STANZA_ATTR_VER "ver" #define STANZA_ATTR_VAR "var" #define STANZA_ATTR_HASH "hash" +#define STANZA_ATTR_CATEGORY "category" #define STANZA_TEXT_AWAY "away" #define STANZA_TEXT_DND "dnd" diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index eb3c3c09..4a1e0b15 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -62,6 +62,12 @@ typedef struct disco_item_t { char *name; } DiscoItem; +typedef struct disco_identity_t { + char *name; + char *type; + char *category; +} DiscoIdentity; + // connection functions void jabber_init(const int disable_tls); jabber_conn_status_t jabber_connect_with_details(const char * const jid, |