mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Added function to create room jid from room and nick
This commit is contained in:
parent
77888c3841
commit
7958a450bd
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
10
src/stanza.c
10
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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user