diff options
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/connection.c | 4 | ||||
-rw-r--r-- | src/xmpp/presence.c | 2 | ||||
-rw-r--r-- | src/xmpp/roster.c | 53 | ||||
-rw-r--r-- | src/xmpp/xmpp.h | 2 |
4 files changed, 45 insertions, 16 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index da21cbca..7cc46846 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -256,7 +256,7 @@ connection_get_ctx(void) } const char * -jabber_get_jid(void) +jabber_get_fulljid(void) { return xmpp_conn_get_jid(jabber_conn.conn); } @@ -473,7 +473,7 @@ _connection_handler(xmpp_conn_t * const conn, _connection_free_saved_details(); } - Jid *myJid = jid_create(jabber_get_jid()); + Jid *myJid = jid_create(jabber_get_fulljid()); jabber_conn.domain = strdup(myJid->domainpart); jid_destroy(myJid); diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 8a0e6611..6a7c214f 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -548,7 +548,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *nick = from_jid->resourcepart; // handle self presence - if (stanza_is_muc_self_presence(stanza, jabber_get_jid())) { + if (stanza_is_muc_self_presence(stanza, jabber_get_fulljid())) { char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); gboolean nick_change = stanza_is_room_nick_change(stanza); diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 5df8fd4c..59fa2a4e 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -88,7 +88,8 @@ static int _roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { - xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); + xmpp_stanza_t *query = + xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(query, STANZA_NAME_ITEM); @@ -96,26 +97,54 @@ _roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, return 1; } - const char *jid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); + // if from attribute exists and it is not current users barejid, ignore push + Jid *my_jid = jid_create(jabber_get_fulljid()); + const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + if ((from != NULL) && (strcmp(from, my_jid->barejid) != 0)) { + jid_destroy(my_jid); + return 1; + } + jid_destroy(my_jid); + + const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); + const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); // remove from roster if (g_strcmp0(sub, "remove") == 0) { - autocomplete_remove(barejid_ac, jid); + // remove barejid and name + autocomplete_remove(barejid_ac, barejid); autocomplete_remove(name_ac, name); g_hash_table_remove(name_to_barejid, name); - g_hash_table_remove(contacts, jid); - return 1; - } - gboolean pending_out = FALSE; - const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); - if ((ask != NULL) && (strcmp(ask, "subscribe") == 0)) { - pending_out = TRUE; - } + // remove each fulljid + PContact contact = roster_get_contact(barejid); + GList *resources = p_contact_get_available_resources(contact); + while (resources != NULL) { + GString *fulljid = g_string_new(strdup(barejid)); + g_string_append(fulljid, "/"); + g_string_append(fulljid, strdup(resources->data)); + autocomplete_remove(fulljid_ac, fulljid->str); + g_string_free(fulljid, TRUE); + resources = g_list_next(resources); + } + + // remove the contact + g_hash_table_remove(contacts, barejid); + + // otherwise update local roster + } else { - roster_update(jid, name, sub, pending_out); + // check for pending out subscriptions + gboolean pending_out = FALSE; + if ((ask != NULL) && (strcmp(ask, "subscribe") == 0)) { + pending_out = TRUE; + } + + // update the local roster + roster_update(barejid, name, sub, pending_out); + } return 1; } diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index ae0328b1..3d789074 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -83,7 +83,7 @@ jabber_conn_status_t jabber_connect_with_account(const ProfAccount * const accou void jabber_disconnect(void); void jabber_shutdown(void); void jabber_process_events(void); -const char * jabber_get_jid(void); +const char * jabber_get_fulljid(void); const char * jabber_get_domain(void); jabber_conn_status_t jabber_get_connection_status(void); char * jabber_get_presence_message(void); |