diff options
author | James Booth <boothj5@gmail.com> | 2013-01-20 04:33:31 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-01-20 04:33:31 +0000 |
commit | b4ea35d40adfb1fbaf962f2c90c4b0db7a958082 (patch) | |
tree | 8255ae7dee80869f383541c1e80b7ea976d7f282 | |
parent | cae7717e73ccc90ab10bed037744ccb2dea1bd69 (diff) | |
download | profani-tty-b4ea35d40adfb1fbaf962f2c90c4b0db7a958082.tar.gz |
Added client to /info command in chat rooms
-rw-r--r-- | src/contact.c | 11 | ||||
-rw-r--r-- | src/contact.h | 3 | ||||
-rw-r--r-- | src/contact_list.c | 4 | ||||
-rw-r--r-- | src/jabber.c | 33 | ||||
-rw-r--r-- | src/muc.c | 6 | ||||
-rw-r--r-- | src/muc.h | 3 | ||||
-rw-r--r-- | src/profanity.c | 9 | ||||
-rw-r--r-- | src/profanity.h | 5 | ||||
-rw-r--r-- | src/windows.c | 1 |
9 files changed, 54 insertions, 21 deletions
diff --git a/src/contact.c b/src/contact.c index 2d8e89c5..aad7f630 100644 --- a/src/contact.c +++ b/src/contact.c @@ -42,7 +42,8 @@ struct p_contact_t { PContact p_contact_new(const char * const jid, const char * const name, const char * const presence, const char * const status, - const char * const subscription, gboolean pending_out) + const char * const subscription, gboolean pending_out, + const char * const caps_str) { PContact contact = malloc(sizeof(struct p_contact_t)); contact->jid = strdup(jid); @@ -66,11 +67,15 @@ p_contact_new(const char * const jid, const char * const name, if (subscription != NULL) contact->subscription = strdup(subscription); else - contact->subscription = strdup("none");; + contact->subscription = strdup("none"); + + if (caps_str != NULL) + contact->caps_str = strdup(caps_str); + else + contact->caps_str = NULL; contact->pending_out = pending_out; contact->last_activity = NULL; - contact->caps_str = NULL; return contact; } diff --git a/src/contact.h b/src/contact.h index a0115cfb..0e9ec42e 100644 --- a/src/contact.h +++ b/src/contact.h @@ -27,7 +27,8 @@ typedef struct p_contact_t *PContact; PContact p_contact_new(const char * const jid, const char * const name, const char * const presence, const char * const status, - const char * const subscription, gboolean pending_out); + const char * const subscription, gboolean pending_out, + const char * const caps_str); void p_contact_free(PContact contact); const char* p_contact_jid(PContact contact); const char* p_contact_name(PContact contact); diff --git a/src/contact_list.c b/src/contact_list.c index 2c96ca29..50a63475 100644 --- a/src/contact_list.c +++ b/src/contact_list.c @@ -70,7 +70,7 @@ contact_list_add(const char * const jid, const char * const name, if (contact == NULL) { contact = p_contact_new(jid, name, presence, status, subscription, - pending_out); + pending_out, NULL); g_hash_table_insert(contacts, strdup(jid), contact); p_autocomplete_add(ac, strdup(jid)); added = TRUE; @@ -126,7 +126,7 @@ contact_list_update_subscription(const char * const jid, if (contact == NULL) { contact = p_contact_new(jid, NULL, "offline", NULL, subscription, - pending_out); + pending_out, NULL); g_hash_table_insert(contacts, strdup(jid), contact); } else { p_contact_set_subscription(contact, subscription); diff --git a/src/jabber.c b/src/jabber.c index 48b51730..ca6bce30 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -792,7 +792,7 @@ _iq_handler(xmpp_conn_t * const conn, if (g_strcmp0(id, "roster") == 0) { return _roster_handler(conn, stanza, userdata); - // handle the initial roster request + // handle diso requests } else if ((g_strcmp0(id, "disco") == 0) && (g_strcmp0(type, "result") == 0)) { return _disco_handler(conn, stanza, userdata); @@ -1032,6 +1032,29 @@ _room_presence_handler(const char * const jid, xmpp_stanza_t * const stanza) char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); char *show_str, *status_str; + char *caps_str = NULL; + xmpp_stanza_t *caps = stanza_get_caps(stanza); + if (caps != NULL) { + char *node = xmpp_stanza_get_attribute(caps, STANZA_ATTR_NODE); + char *ver = xmpp_stanza_get_attribute(caps, STANZA_ATTR_VER); + + if ((node != NULL) && (ver != NULL)) { + GString *caps_gstr = g_string_new(node); + g_string_append(caps_gstr, "#"); + g_string_append(caps_gstr, ver); + caps_str = caps_gstr->str; + g_string_free(caps_gstr, FALSE); + } + } + + if (caps_str != NULL) { + if (!caps_contains(caps_str)) { + xmpp_stanza_t *iq = stanza_create_disco_iq(jabber_conn.ctx, jid, caps_str); + xmpp_send(jabber_conn.conn, iq); + xmpp_stanza_release(iq); + } + } + xmpp_stanza_t *status = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_STATUS); if (status != NULL) { status_str = xmpp_stanza_get_text(status); @@ -1056,18 +1079,18 @@ _room_presence_handler(const char * const jid, xmpp_stanza_t * const stanza) show_str = "online"; } if (!muc_get_roster_received(room)) { - muc_add_to_roster(room, nick, show_str, status_str); + muc_add_to_roster(room, nick, show_str, status_str, caps_str); } else { char *old_nick = muc_complete_roster_nick_change(room, nick); if (old_nick != NULL) { - muc_add_to_roster(room, nick, show_str, status_str); + muc_add_to_roster(room, nick, show_str, status_str, caps_str); prof_handle_room_member_nick_change(room, old_nick, nick); } else { if (!muc_nick_in_roster(room, nick)) { - prof_handle_room_member_online(room, nick, show_str, status_str); + prof_handle_room_member_online(room, nick, show_str, status_str, caps_str); } else { - prof_handle_room_member_presence(room, nick, show_str, status_str); + prof_handle_room_member_presence(room, nick, show_str, status_str, caps_str); } } } diff --git a/src/muc.c b/src/muc.c index ece77818..efe22abd 100644 --- a/src/muc.c +++ b/src/muc.c @@ -204,7 +204,8 @@ muc_nick_in_roster(const char * const room, const char * const nick) */ gboolean muc_add_to_roster(const char * const room, const char * const nick, - const char * const show, const char * const status) + const char * const show, const char * const status, + const char * const caps_str) { ChatRoom *chat_room = g_hash_table_lookup(rooms, room); gboolean updated = FALSE; @@ -219,8 +220,7 @@ muc_add_to_roster(const char * const room, const char * const nick, (g_strcmp0(p_contact_status(old), status) != 0)) { updated = TRUE; } - - PContact contact = p_contact_new(nick, NULL, show, status, NULL, FALSE); + PContact contact = p_contact_new(nick, NULL, show, status, NULL, FALSE, caps_str); g_hash_table_replace(chat_room->roster, strdup(nick), contact); } diff --git a/src/muc.h b/src/muc.h index 8411cb39..8b8ed018 100644 --- a/src/muc.h +++ b/src/muc.h @@ -39,7 +39,8 @@ void muc_complete_room_nick_change(const char * const room, const char * const nick); gboolean muc_add_to_roster(const char * const room, const char * const nick, - const char * const show, const char * const status); + const char * const show, const char * const status, + const char * const caps_str); void muc_remove_from_roster(const char * const room, const char * const nick); GList * muc_get_roster(const char * const room); PAutocomplete muc_get_roster_ac(const char * const room); diff --git a/src/profanity.c b/src/profanity.c index 0eec13a5..47707595 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -312,9 +312,9 @@ prof_handle_room_roster_complete(const char * const room) void prof_handle_room_member_presence(const char * const room, const char * const nick, const char * const show, - const char * const status) + const char * const status, const char * const caps_str) { - gboolean updated = muc_add_to_roster(room, nick, show, status); + gboolean updated = muc_add_to_roster(room, nick, show, status, caps_str); if (updated) { win_show_room_member_presence(room, nick, show, status); @@ -324,9 +324,10 @@ prof_handle_room_member_presence(const char * const room, void prof_handle_room_member_online(const char * const room, const char * const nick, - const char * const show, const char * const status) + const char * const show, const char * const status, + const char * const caps_str) { - muc_add_to_roster(room, nick, show, status); + muc_add_to_roster(room, nick, show, status, caps_str); win_show_room_member_online(room, nick, show, status); win_current_page_off(); } diff --git a/src/profanity.h b/src/profanity.h index 1bc825e8..a28bd292 100644 --- a/src/profanity.h +++ b/src/profanity.h @@ -51,12 +51,13 @@ void prof_handle_room_subject(const char * const room_jid, const char * const subject); void prof_handle_room_roster_complete(const char * const room); void prof_handle_room_member_online(const char * const room, - const char * const nick, const char * const show, const char * const status); + const char * const nick, const char * const show, const char * const status, + const char * const caps_str); void prof_handle_room_member_offline(const char * const room, const char * const nick, const char * const show, const char * const status); void prof_handle_room_member_presence(const char * const room, const char * const nick, const char * const show, - const char * const status); + const char * const status, const char * const caps_str); void prof_handle_leave_room(const char * const room); void prof_handle_room_member_nick_change(const char * const room, const char * const old_nick, const char * const nick); diff --git a/src/windows.c b/src/windows.c index c3aa14ec..46bac6ea 100644 --- a/src/windows.c +++ b/src/windows.c @@ -2405,6 +2405,7 @@ _win_show_info(WINDOW *win, PContact pcontact) wprintw(win, "Client : %s\n", caps->client); } } + } void |