1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Refactored roster push handling

This commit is contained in:
James Booth 2013-05-21 22:00:42 +01:00
parent 5a8e667e58
commit 7b20d8d4f4
7 changed files with 57 additions and 28 deletions

View File

@ -1122,7 +1122,7 @@ cmd_execute_default(const char * const inp)
message_send(inp, recipient); message_send(inp, recipient);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_jid(); const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);
chat_log_chat(jidp->barejid, recipient, inp, PROF_OUT_LOG, NULL); chat_log_chat(jidp->barejid, recipient, inp, PROF_OUT_LOG, NULL);
jid_destroy(jidp); jid_destroy(jidp);
@ -1553,7 +1553,7 @@ static gboolean
_cmd_disconnect(gchar **args, struct cmd_help_t help) _cmd_disconnect(gchar **args, struct cmd_help_t help)
{ {
if (jabber_get_connection_status() == JABBER_CONNECTED) { if (jabber_get_connection_status() == JABBER_CONNECTED) {
char *jid = strdup(jabber_get_jid()); char *jid = strdup(jabber_get_fulljid());
prof_handle_disconnect(jid); prof_handle_disconnect(jid);
free(jid); free(jid);
} else { } else {
@ -1979,7 +1979,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
ui_outgoing_msg("me", usr_jid, msg); ui_outgoing_msg("me", usr_jid, msg);
if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { 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); Jid *jidp = jid_create(jid);
chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL); chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL);
jid_destroy(jidp); jid_destroy(jidp);
@ -2344,7 +2344,7 @@ _cmd_join(gchar **args, struct cmd_help_t help)
char *nick = NULL; char *nick = NULL;
Jid *room_arg = jid_create(args[0]); Jid *room_arg = jid_create(args[0]);
GString *room_str = g_string_new(""); 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) // full room jid supplied (room@server)
if (room_arg->localpart != NULL) { if (room_arg->localpart != NULL) {
@ -2446,7 +2446,7 @@ _cmd_rooms(gchar **args, struct cmd_help_t help)
} }
if (args[0] == NULL) { 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."); GString *conference_node = g_string_new("conference.");
g_string_append(conference_node, strdup(jid->domainpart)); g_string_append(conference_node, strdup(jid->domainpart));
jid_destroy(jid); jid_destroy(jid);
@ -2473,7 +2473,7 @@ _cmd_disco(gchar **args, struct cmd_help_t help)
if (args[1] != NULL) { if (args[1] != NULL) {
jid = g_string_append(jid, args[1]); jid = g_string_append(jid, args[1]);
} else { } else {
Jid *jidp = jid_create(jabber_get_jid()); Jid *jidp = jid_create(jabber_get_fulljid());
jid = g_string_append(jid, strdup(jidp->domainpart)); jid = g_string_append(jid, strdup(jidp->domainpart));
jid_destroy(jidp); jid_destroy(jidp);
} }
@ -2533,7 +2533,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help)
message_send(tiny, recipient); message_send(tiny, recipient);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_jid(); const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);
chat_log_chat(jidp->barejid, recipient, tiny, PROF_OUT_LOG, NULL); chat_log_chat(jidp->barejid, recipient, tiny, PROF_OUT_LOG, NULL);
jid_destroy(jidp); jid_destroy(jidp);

View File

@ -115,7 +115,7 @@ prof_handle_incoming_message(char *from, char *message, gboolean priv)
if (prefs_get_boolean(PREF_CHLOG) && !priv) { if (prefs_get_boolean(PREF_CHLOG) && !priv) {
Jid *from_jid = jid_create(from); Jid *from_jid = jid_create(from);
const char *jid = jabber_get_jid(); const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);
chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, NULL); chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, NULL);
jid_destroy(jidp); 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) { if (prefs_get_boolean(PREF_CHLOG) && !priv) {
Jid *from_jid = jid_create(from); Jid *from_jid = jid_create(from);
const char *jid = jabber_get_jid(); const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);
chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, &tv_stamp); chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, &tv_stamp);
jid_destroy(jidp); jid_destroy(jidp);
@ -268,7 +268,7 @@ prof_handle_room_message(const char * const room_jid, const char * const nick,
ui_current_page_off(); ui_current_page_off();
if (prefs_get_boolean(PREF_GRLOG)) { 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); groupchat_log_chat(jid->barejid, room_jid, nick, message);
jid_destroy(jid); jid_destroy(jid);
} }

View File

@ -1362,7 +1362,7 @@ _ui_draw_win_title(void)
jabber_conn_status_t status = jabber_get_connection_status(); jabber_conn_status_t status = jabber_get_connection_status();
if (status == JABBER_CONNECTED) { if (status == JABBER_CONNECTED) {
const char * const jid = jabber_get_jid(); const char * const jid = jabber_get_fulljid();
gint unread = ui_unread(); gint unread = ui_unread();
if (unread != 0) { 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) { if (!windows[win_index]->history_shown) {
GSList *history = NULL; 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); history = chat_log_get_previous(jid->barejid, contact, history);
jid_destroy(jid); jid_destroy(jid);
while (history != NULL) { while (history != NULL) {

View File

@ -256,7 +256,7 @@ connection_get_ctx(void)
} }
const char * const char *
jabber_get_jid(void) jabber_get_fulljid(void)
{ {
return xmpp_conn_get_jid(jabber_conn.conn); return xmpp_conn_get_jid(jabber_conn.conn);
} }
@ -473,7 +473,7 @@ _connection_handler(xmpp_conn_t * const conn,
_connection_free_saved_details(); _connection_free_saved_details();
} }
Jid *myJid = jid_create(jabber_get_jid()); Jid *myJid = jid_create(jabber_get_fulljid());
jabber_conn.domain = strdup(myJid->domainpart); jabber_conn.domain = strdup(myJid->domainpart);
jid_destroy(myJid); jid_destroy(myJid);

View File

@ -548,7 +548,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
char *nick = from_jid->resourcepart; char *nick = from_jid->resourcepart;
// handle self presence // 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); char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
gboolean nick_change = stanza_is_room_nick_change(stanza); gboolean nick_change = stanza_is_room_nick_change(stanza);

View File

@ -88,7 +88,8 @@ static int
_roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, _roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata) 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_t *item =
xmpp_stanza_get_child_by_name(query, STANZA_NAME_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; 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 *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME);
const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); 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 // remove from roster
if (g_strcmp0(sub, "remove") == 0) { 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); autocomplete_remove(name_ac, name);
g_hash_table_remove(name_to_barejid, name); g_hash_table_remove(name_to_barejid, name);
g_hash_table_remove(contacts, jid);
return 1;
}
gboolean pending_out = FALSE; // remove each fulljid
const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); PContact contact = roster_get_contact(barejid);
if ((ask != NULL) && (strcmp(ask, "subscribe") == 0)) { GList *resources = p_contact_get_available_resources(contact);
pending_out = TRUE; 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);
}
roster_update(jid, name, sub, pending_out); // remove the contact
g_hash_table_remove(contacts, barejid);
// otherwise update local roster
} else {
// 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; return 1;
} }

View File

@ -83,7 +83,7 @@ jabber_conn_status_t jabber_connect_with_account(const ProfAccount * const accou
void jabber_disconnect(void); void jabber_disconnect(void);
void jabber_shutdown(void); void jabber_shutdown(void);
void jabber_process_events(void); void jabber_process_events(void);
const char * jabber_get_jid(void); const char * jabber_get_fulljid(void);
const char * jabber_get_domain(void); const char * jabber_get_domain(void);
jabber_conn_status_t jabber_get_connection_status(void); jabber_conn_status_t jabber_get_connection_status(void);
char * jabber_get_presence_message(void); char * jabber_get_presence_message(void);