diff options
-rw-r--r-- | src/command/command.c | 14 | ||||
-rw-r--r-- | src/profanity.c | 6 | ||||
-rw-r--r-- | src/ui/core.c | 4 | ||||
-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 |
7 files changed, 57 insertions, 28 deletions
diff --git a/src/command/command.c b/src/command/command.c index 84b7999a..840ce6a0 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1122,7 +1122,7 @@ cmd_execute_default(const char * const inp) message_send(inp, recipient); if (prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_jid(); + const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); chat_log_chat(jidp->barejid, recipient, inp, PROF_OUT_LOG, NULL); jid_destroy(jidp); @@ -1553,7 +1553,7 @@ static gboolean _cmd_disconnect(gchar **args, struct cmd_help_t help) { if (jabber_get_connection_status() == JABBER_CONNECTED) { - char *jid = strdup(jabber_get_jid()); + char *jid = strdup(jabber_get_fulljid()); prof_handle_disconnect(jid); free(jid); } else { @@ -1979,7 +1979,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help) ui_outgoing_msg("me", usr_jid, msg); if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_jid(); + const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL); jid_destroy(jidp); @@ -2344,7 +2344,7 @@ _cmd_join(gchar **args, struct cmd_help_t help) char *nick = NULL; Jid *room_arg = jid_create(args[0]); GString *room_str = g_string_new(""); - Jid *my_jid = jid_create(jabber_get_jid()); + Jid *my_jid = jid_create(jabber_get_fulljid()); // full room jid supplied (room@server) if (room_arg->localpart != NULL) { @@ -2446,7 +2446,7 @@ _cmd_rooms(gchar **args, struct cmd_help_t help) } if (args[0] == NULL) { - Jid *jid = jid_create(jabber_get_jid()); + Jid *jid = jid_create(jabber_get_fulljid()); GString *conference_node = g_string_new("conference."); g_string_append(conference_node, strdup(jid->domainpart)); jid_destroy(jid); @@ -2473,7 +2473,7 @@ _cmd_disco(gchar **args, struct cmd_help_t help) if (args[1] != NULL) { jid = g_string_append(jid, args[1]); } else { - Jid *jidp = jid_create(jabber_get_jid()); + Jid *jidp = jid_create(jabber_get_fulljid()); jid = g_string_append(jid, strdup(jidp->domainpart)); jid_destroy(jidp); } @@ -2533,7 +2533,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help) message_send(tiny, recipient); if (prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_jid(); + const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); chat_log_chat(jidp->barejid, recipient, tiny, PROF_OUT_LOG, NULL); jid_destroy(jidp); diff --git a/src/profanity.c b/src/profanity.c index c19dc9b9..ac58514e 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -115,7 +115,7 @@ prof_handle_incoming_message(char *from, char *message, gboolean priv) if (prefs_get_boolean(PREF_CHLOG) && !priv) { Jid *from_jid = jid_create(from); - const char *jid = jabber_get_jid(); + const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, NULL); jid_destroy(jidp); @@ -132,7 +132,7 @@ prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp, if (prefs_get_boolean(PREF_CHLOG) && !priv) { Jid *from_jid = jid_create(from); - const char *jid = jabber_get_jid(); + const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, &tv_stamp); jid_destroy(jidp); @@ -268,7 +268,7 @@ prof_handle_room_message(const char * const room_jid, const char * const nick, ui_current_page_off(); if (prefs_get_boolean(PREF_GRLOG)) { - Jid *jid = jid_create(jabber_get_jid()); + Jid *jid = jid_create(jabber_get_fulljid()); groupchat_log_chat(jid->barejid, room_jid, nick, message); jid_destroy(jid); } diff --git a/src/ui/core.c b/src/ui/core.c index 12cb02f0..1b6c8790 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1362,7 +1362,7 @@ _ui_draw_win_title(void) jabber_conn_status_t status = jabber_get_connection_status(); if (status == JABBER_CONNECTED) { - const char * const jid = jabber_get_jid(); + const char * const jid = jabber_get_fulljid(); gint unread = ui_unread(); if (unread != 0) { @@ -1667,7 +1667,7 @@ _win_show_history(WINDOW *win, int win_index, const char * const contact) { if (!windows[win_index]->history_shown) { GSList *history = NULL; - Jid *jid = jid_create(jabber_get_jid()); + Jid *jid = jid_create(jabber_get_fulljid()); history = chat_log_get_previous(jid->barejid, contact, history); jid_destroy(jid); while (history != NULL) { 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); |