diff options
Diffstat (limited to 'src/xmpp/presence.c')
-rw-r--r-- | src/xmpp/presence.c | 89 |
1 files changed, 66 insertions, 23 deletions
diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index c05ba198..ec439871 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -156,14 +156,23 @@ presence_sub_request_find(char * search_str) gboolean presence_sub_request_exists(const char * const bare_jid) { - GSList *requests = autocomplete_get_list(sub_requests_ac); + gboolean result = FALSE; + GSList *requests_p = autocomplete_get_list(sub_requests_ac); + GSList *requests = requests_p; + while (requests != NULL) { if (strcmp(requests->data, bare_jid) == 0) { - return TRUE; + result = TRUE; + break; } requests = g_slist_next(requests); } - return FALSE; + + if (requests_p != NULL) { + g_slist_free_full(requests_p, free); + } + + return result; } void @@ -220,20 +229,28 @@ presence_update(const resource_presence_t presence_type, const char * const msg, static void _send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence) { - GList *rooms = muc_get_active_room_list(); + GList *rooms_p = muc_get_active_room_list(); + GList *rooms = rooms_p; + while (rooms != NULL) { const char *room = rooms->data; const char *nick = muc_get_room_nick(room); - char *full_room_jid = create_fulljid(room, nick); - xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); - log_debug("Sending presence to room: %s", full_room_jid); - xmpp_send(conn, presence); - free(full_room_jid); + if (nick != NULL) { + char *full_room_jid = create_fulljid(room, nick); + + xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); + log_debug("Sending presence to room: %s", full_room_jid); + xmpp_send(conn, presence); + free(full_room_jid); + } rooms = g_list_next(rooms); } - g_list_free(rooms); + + if (rooms_p != NULL) { + g_list_free(rooms_p); + } } void @@ -347,9 +364,13 @@ _subscribe_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - Jid *from_jid = jid_create(from); log_debug("Subscribe presence handler fired for %s", from); + Jid *from_jid = jid_create(from); + if (from_jid == NULL) { + return 1; + } + prof_handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE); autocomplete_add(sub_requests_ac, strdup(from_jid->barejid)); @@ -368,6 +389,11 @@ _unavailable_handler(xmpp_conn_t * const conn, Jid *my_jid = jid_create(jid); Jid *from_jid = jid_create(from); + if (my_jid == NULL || from_jid == NULL) { + jid_destroy(my_jid); + jid_destroy(from_jid); + return 1; + } char *status_str = stanza_get_status(stanza, NULL); @@ -385,7 +411,7 @@ _unavailable_handler(xmpp_conn_t * const conn, } } - FREE_SET_NULL(status_str); + free(status_str); jid_destroy(my_jid); jid_destroy(from_jid); @@ -420,6 +446,11 @@ _available_handler(xmpp_conn_t * const conn, Jid *my_jid = jid_create(jid); Jid *from_jid = jid_create(from); + if (my_jid == NULL || from_jid == NULL) { + jid_destroy(my_jid); + jid_destroy(from_jid); + return 1; + } char *show_str = stanza_get_show(stanza, "online"); char *status_str = stanza_get_status(stanza, NULL); @@ -462,7 +493,7 @@ _available_handler(xmpp_conn_t * const conn, } // self presence - if (strcmp(my_jid->barejid, from_jid->barejid) ==0) { + if (strcmp(my_jid->barejid, from_jid->barejid) == 0) { connection_add_available_resource(resource); // contact presence @@ -471,8 +502,9 @@ _available_handler(xmpp_conn_t * const conn, last_activity); } - FREE_SET_NULL(status_str); - FREE_SET_NULL(show_str); + free(caps_key); + free(status_str); + free(show_str); jid_destroy(my_jid); jid_destroy(from_jid); @@ -515,6 +547,10 @@ _get_caps_key(xmpp_stanza_t * const stanza) log_debug("Presence contains capabilities."); + if (node == NULL) { + return NULL; + } + // xep-0115 if ((hash_type != NULL) && (strcmp(hash_type, "sha-1") == 0)) { log_debug("Hash type %s supported.", hash_type); @@ -544,6 +580,8 @@ _get_caps_key(xmpp_stanza_t * const stanza) g_string_free(id_str, TRUE); } + g_free(node); + return caps_key; } @@ -556,10 +594,11 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, return 1; } - const char *jid = xmpp_conn_get_jid(conn); char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - Jid *my_jid = jid_create(jid); Jid *from_jid = jid_create(from); + if (from_jid == NULL || from_jid->resourcepart == NULL) { + return 1; + } char *room = from_jid->barejid; char *nick = from_jid->resourcepart; @@ -592,7 +631,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // handle presence from room members } else { char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); - char *show_str, *status_str; + char *status_str; char *caps_key = NULL; if (stanza_contains_caps(stanza)) { @@ -608,12 +647,15 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // handle nickname change if (stanza_is_room_nick_change(stanza)) { char *new_nick = stanza_get_new_nick(stanza); - muc_set_roster_pending_nick_change(room, new_nick, nick); + if (new_nick != NULL) { + muc_set_roster_pending_nick_change(room, new_nick, nick); + free(new_nick); + } } else { prof_handle_room_member_offline(room, nick, "offline", status_str); } } else { - show_str = stanza_get_show(stanza, "online"); + char *show_str = stanza_get_show(stanza, "online"); if (!muc_get_roster_received(room)) { muc_add_to_roster(room, nick, show_str, status_str, caps_key); } else { @@ -622,6 +664,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, if (old_nick != NULL) { muc_add_to_roster(room, nick, show_str, status_str, caps_key); prof_handle_room_member_nick_change(room, old_nick, nick); + free(old_nick); } else { if (!muc_nick_in_roster(room, nick)) { prof_handle_room_member_online(room, nick, show_str, status_str, caps_key); @@ -631,13 +674,13 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } } - FREE_SET_NULL(show_str); + free(show_str); } - FREE_SET_NULL(status_str); + free(status_str); + free(caps_key); } - jid_destroy(my_jid); jid_destroy(from_jid); return 1; |