diff --git a/src/jabber.c b/src/jabber.c index 19a5d462..f16a4737 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -234,12 +234,15 @@ jabber_subscribe(const char * const recipient) void jabber_join(const char * const room, const char * const nick) { + char *full_room_jid = room_create_full_room_jid(room, nick); xmpp_stanza_t *presence = stanza_create_room_join_presence(jabber_conn.ctx, - room, nick); + full_room_jid); xmpp_send(jabber_conn.conn, presence); xmpp_stanza_release(presence); room_join(room, nick); + + free(full_room_jid); } void diff --git a/src/room_chat.c b/src/room_chat.c index 677aded1..8e843f9a 100644 --- a/src/room_chat.c +++ b/src/room_chat.c @@ -114,6 +114,37 @@ room_get_room_from_full_jid(const char * const full_room_jid) } } +char * +room_get_nick_from_full_jid(const char * const full_room_jid) +{ + char **tokens = g_strsplit(full_room_jid, "/", 0); + char *nick_part; + + if (tokens == NULL || tokens[1] == NULL) { + return NULL; + } else { + nick_part = strdup(tokens[1]); + + g_strfreev(tokens); + + return nick_part; + } +} + +char * +room_create_full_room_jid(const char * const room, const char * const nick) +{ + GString *full_jid = g_string_new(room); + g_string_append(full_jid, "/"); + g_string_append(full_jid, nick); + + char *result = strdup(full_jid->str); + + g_string_free(full_jid, TRUE); + + return result; +} + gboolean room_parse_room_jid(const char * const full_room_jid, char **room, char **nick) { diff --git a/src/room_chat.h b/src/room_chat.h index 7c4baf9a..02ef3a5e 100644 --- a/src/room_chat.h +++ b/src/room_chat.h @@ -30,6 +30,7 @@ void room_leave(const char * const room); gboolean room_is_active(const char * const full_room_jid); char * room_get_nick_for_room(const char * const room); char * room_get_room_from_full_jid(const char * const full_room_jid); +char * room_get_nick_from_full_jid(const char * const full_room_jid); gboolean room_parse_room_jid(const char * const full_room_jid, char **room, char **nick); void room_add_to_roster(const char * const room, const char * const nick); @@ -37,5 +38,7 @@ GList * room_get_roster(const char * const room); void room_set_roster_received(const char * const room); gboolean room_get_roster_received(const char * const room); void room_remove_from_roster(const char * const room, const char * const nick); +char * room_create_full_room_jid(const char * const room, + const char * const nick); #endif diff --git a/src/stanza.c b/src/stanza.c index 5644d0ff..bef10751 100644 --- a/src/stanza.c +++ b/src/stanza.c @@ -81,16 +81,12 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, } xmpp_stanza_t * -stanza_create_room_join_presence(xmpp_ctx_t *ctx, const char * const room, - const char * const nick) +stanza_create_room_join_presence(xmpp_ctx_t *ctx, + const char * const full_room_jid) { - 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_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); xmpp_stanza_t *x = xmpp_stanza_new(ctx); xmpp_stanza_set_name(x, STANZA_NAME_X); diff --git a/src/stanza.h b/src/stanza.h index 150ec857..6f244327 100644 --- a/src/stanza.h +++ b/src/stanza.h @@ -78,7 +78,7 @@ xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx, const char * const message, const char * const state); xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t *ctx, - const char * const room, const char * const nick); + const char * const full_room_jid); xmpp_stanza_t* stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char * const room, const char * const nick);