From 187ea6e8b87705c43dfbd91a0b17cdac124fce4d Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 9 Nov 2012 01:04:32 +0000 Subject: Moved room join stanza creation --- src/jabber.c | 16 ++-------------- src/stanza.c | 21 +++++++++++++++++++++ src/stanza.h | 3 +++ 3 files changed, 26 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/jabber.c b/src/jabber.c index ae030c9d..abda6f3a 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -234,20 +234,8 @@ jabber_subscribe(const char * const recipient) void jabber_join(const char * const room_jid, const char * const nick) { - GString *to = g_string_new(room_jid); - g_string_append(to, "/"); - g_string_append(to, nick); - - xmpp_stanza_t *presence = xmpp_stanza_new(jabber_conn.ctx); - xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); - xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, to->str); - - xmpp_stanza_t *x = xmpp_stanza_new(jabber_conn.ctx); - xmpp_stanza_set_name(x, STANZA_NAME_X); - xmpp_stanza_set_ns(x, STANZA_NS_MUC); - - xmpp_stanza_add_child(presence, x); - + xmpp_stanza_t *presence = stanza_create_room_presence(jabber_conn.ctx, + room_jid, nick); xmpp_send(jabber_conn.conn, presence); xmpp_stanza_release(presence); diff --git a/src/stanza.c b/src/stanza.c index 3757ea7c..bc84f1e6 100644 --- a/src/stanza.c +++ b/src/stanza.c @@ -78,3 +78,24 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, return msg; } +xmpp_stanza_t * +stanza_create_room_presence(xmpp_ctx_t *ctx, const char * const room, + const char * const nick) +{ + GString *to = g_string_new(room); + g_string_append(to, "/"); + g_string_append(to, nick); + + xmpp_stanza_t *presence = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); + xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, to->str); + + xmpp_stanza_t *x = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(x, STANZA_NAME_X); + xmpp_stanza_set_ns(x, STANZA_NS_MUC); + + xmpp_stanza_add_child(presence, x); + + return presence; +} + diff --git a/src/stanza.h b/src/stanza.h index 02cd9d97..7da1bcf2 100644 --- a/src/stanza.h +++ b/src/stanza.h @@ -74,4 +74,7 @@ xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx, xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, const char * const type, const char * const message, const char * const state); + +xmpp_stanza_t* stanza_create_room_presence(xmpp_ctx_t *ctx, + const char * const room, const char * const nick); #endif -- cgit 1.4.1-2-gfad0