Added basic /rooms command to get chat room list

This commit is contained in:
James Booth
2013-03-13 23:38:26 +00:00
parent ed2212a0ca
commit b960b76034
7 changed files with 126 additions and 0 deletions

View File

@@ -39,6 +39,8 @@
#include "xmpp/stanza.h"
#include "xmpp/xmpp.h"
#include "ui/ui.h"
#define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_IQ, type, ctx)
static int _iq_handle_error(xmpp_conn_t * const conn,
@@ -57,6 +59,8 @@ 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);
static int _iq_handle_discoitems_result(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
void
iq_add_handlers(void)
@@ -68,6 +72,7 @@ iq_add_handlers(void)
HANDLE(XMPP_NS_ROSTER, STANZA_TYPE_RESULT, _iq_handle_roster_result);
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(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_RESULT, _iq_handle_discoitems_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);
@@ -83,6 +88,16 @@ iq_roster_request(void)
xmpp_stanza_release(iq);
}
void
iq_room_list_request(gchar *conferencejid)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, "confreq", conferencejid);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
void
iq_send_software_version(const char * const fulljid)
{
@@ -448,3 +463,39 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan
return 1;
}
}
static int
_iq_handle_discoitems_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
GSList *rooms = NULL;
log_debug("Recieved diso#items response");
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if ((id != NULL) && (g_strcmp0(id, "confreq") == 0)) {
log_debug("Response to query: %s", id);
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 *name = xmpp_stanza_get_name(child);
if ((name != NULL) && (g_strcmp0(name, STANZA_NAME_ITEM) == 0)) {
const char *jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
if (jid != NULL) {
rooms = g_slist_append(rooms, strdup(jid));
}
}
child = xmpp_stanza_get_next(child);
}
}
}
prof_handle_room_list(rooms, from);
g_slist_free_full(rooms, free);
return 1;
}

View File

@@ -198,6 +198,26 @@ stanza_create_disco_iq(xmpp_ctx_t *ctx, const char * const id, const char * cons
return iq;
}
xmpp_stanza_t *
stanza_create_disco_items_iq(xmpp_ctx_t *ctx, const char * const id,
const char * const jid)
{
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_attribute(iq, STANZA_ATTR_TO, jid);
xmpp_stanza_set_id(iq, id);
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS);
xmpp_stanza_add_child(iq, query);
xmpp_stanza_release(query);
return iq;
}
gboolean
stanza_contains_chat_state(xmpp_stanza_t *stanza)
{

View File

@@ -163,5 +163,7 @@ void stanza_attach_status(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence
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);
xmpp_stanza_t * stanza_create_disco_items_iq(xmpp_ctx_t *ctx, const char * const id,
const char * const jid);
#endif

View File

@@ -92,6 +92,7 @@ void presence_update(resource_presence_t status, const char * const msg,
// iq functions
void iq_send_software_version(const char * const fulljid);
void iq_room_list_request(gchar *conferencejid);
// caps functions
Capabilities* caps_get(const char * const caps_str);