From 0da40a34d5da95008578133980bcbc005b74346e Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Nov 2012 00:25:42 +0000 Subject: [PATCH] Moved roster iq creation to stanza --- src/jabber.c | 14 +------------- src/stanza.c | 18 ++++++++++++++++++ src/stanza.h | 4 +++- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/jabber.c b/src/jabber.c index 01002d14..4ac303b6 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -309,19 +309,7 @@ jabber_free_resources(void) static void _jabber_roster_request(void) { - xmpp_stanza_t *iq, *query; - - iq = xmpp_stanza_new(jabber_conn.ctx); - xmpp_stanza_set_name(iq, STANZA_NAME_IQ); - xmpp_stanza_set_type(iq, STANZA_TYPE_GET); - xmpp_stanza_set_id(iq, "roster"); - - query = xmpp_stanza_new(jabber_conn.ctx); - xmpp_stanza_set_name(query, STANZA_NAME_QUERY); - xmpp_stanza_set_ns(query, XMPP_NS_ROSTER); - - xmpp_stanza_add_child(iq, query); - xmpp_stanza_release(query); + xmpp_stanza_t *iq = stanza_create_roster_iq(jabber_conn.ctx); xmpp_send(jabber_conn.conn, iq); xmpp_stanza_release(iq); } diff --git a/src/stanza.c b/src/stanza.c index 75c758c5..eb4bbc67 100644 --- a/src/stanza.c +++ b/src/stanza.c @@ -150,3 +150,21 @@ stanza_create_presence(xmpp_ctx_t *ctx, const char * const show, return presence; } + +xmpp_stanza_t * +stanza_create_roster_iq(xmpp_ctx_t *ctx) +{ + 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, "roster"); + + xmpp_stanza_t *query = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(query, STANZA_NAME_QUERY); + xmpp_stanza_set_ns(query, XMPP_NS_ROSTER); + + xmpp_stanza_add_child(iq, query); + xmpp_stanza_release(query); + + return iq; +} diff --git a/src/stanza.h b/src/stanza.h index b279b52a..fdf18ef2 100644 --- a/src/stanza.h +++ b/src/stanza.h @@ -81,7 +81,9 @@ xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t *ctx, xmpp_stanza_t* stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char * const room, const char * const nick); -xmpp_stanza_t * stanza_create_presence(xmpp_ctx_t *ctx, const char * const show, +xmpp_stanza_t* stanza_create_presence(xmpp_ctx_t *ctx, const char * const show, const char * const status); +xmpp_stanza_t* stanza_create_roster_iq(xmpp_ctx_t *ctx); + #endif