about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-03 21:27:41 +0000
committerJames Booth <boothj5@gmail.com>2014-11-03 21:27:41 +0000
commit74a2d4601f2f3cf47eda17647a39482ad3a3b667 (patch)
tree1bfedd8a8041cf4adf63ce78c0e61d93bae46673
parent7a03dd7641d97a4f44bd78e82e7132213c88bd54 (diff)
downloadprofani-tty-74a2d4601f2f3cf47eda17647a39482ad3a3b667.tar.gz
Removed hash_table_iter usage for room roster
-rw-r--r--TODO_0453
-rw-r--r--src/command/commands.c24
-rw-r--r--src/muc.c14
-rw-r--r--src/server_events.c5
-rw-r--r--src/ui/core.c14
-rw-r--r--src/ui/ui.h2
6 files changed, 32 insertions, 30 deletions
diff --git a/TODO_045 b/TODO_045
index f370df2b..835c52b9 100644
--- a/TODO_045
+++ b/TODO_045
@@ -1,6 +1,3 @@
-Test with valgrind using new commands
-    fix muc roster leak
-
 Update website help
 
 Tag libstrophe release 0.8.7
diff --git a/src/command/commands.c b/src/command/commands.c
index a4808b8a..e81c1714 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -769,22 +769,22 @@ _who_room(gchar **args, struct cmd_help_t help)
             (g_strcmp0(args[0], "any") == 0)) {
 
         char *presence = args[0];
-        GList *list = muc_roster(room);
+        GList *occupants = muc_roster(room);
 
         // no arg, show all contacts
         if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) {
-            ui_room_roster(room, list, NULL);
+            ui_room_roster(room, occupants, NULL);
 
         // available
         } else if (strcmp("available", presence) == 0) {
             GList *filtered = NULL;
 
-            while (list != NULL) {
-                Occupant *occupant = list->data;
+            while (occupants != NULL) {
+                Occupant *occupant = occupants->data;
                 if (muc_occupant_available(occupant)) {
                     filtered = g_list_append(filtered, occupant);
                 }
-                list = g_list_next(list);
+                occupants = g_list_next(occupants);
             }
 
             ui_room_roster(room, filtered, "available");
@@ -793,12 +793,12 @@ _who_room(gchar **args, struct cmd_help_t help)
         } else if (strcmp("unavailable", presence) == 0) {
             GList *filtered = NULL;
 
-            while (list != NULL) {
-                Occupant *occupant = list->data;
+            while (occupants != NULL) {
+                Occupant *occupant = occupants->data;
                 if (!muc_occupant_available(occupant)) {
                     filtered = g_list_append(filtered, occupant);
                 }
-                list = g_list_next(list);
+                occupants = g_list_next(occupants);
             }
 
             ui_room_roster(room, filtered, "unavailable");
@@ -807,18 +807,20 @@ _who_room(gchar **args, struct cmd_help_t help)
         } else {
             GList *filtered = NULL;
 
-            while (list != NULL) {
-                Occupant *occupant = list->data;
+            while (occupants != NULL) {
+                Occupant *occupant = occupants->data;
                 const char *presence_str = string_from_resource_presence(occupant->presence);
                 if (strcmp(presence_str, presence) == 0) {
                     filtered = g_list_append(filtered, occupant);
                 }
-                list = g_list_next(list);
+                occupants = g_list_next(occupants);
             }
 
             ui_room_roster(room, filtered, presence);
         }
 
+        g_list_free(occupants);
+
     // role or affiliation filter
     } else {
         ProfWin *window = wins_get_by_recipient(room);
diff --git a/src/muc.c b/src/muc.c
index 731505b8..f3505647 100644
--- a/src/muc.c
+++ b/src/muc.c
@@ -454,7 +454,6 @@ muc_roster_item(const char * const room, const char * const nick)
 
 /*
  * Return a list of PContacts representing the room members in the room's roster
- * The list is owned by the room and must not be mofified or freed
  */
 GList *
 muc_roster(const char * const room)
@@ -462,15 +461,16 @@ muc_roster(const char * const room)
     ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
     if (chat_room) {
         GList *result = NULL;
-        GHashTableIter iter;
-        gpointer key;
-        gpointer value;
+        GList *occupants = g_hash_table_get_values(chat_room->roster);
 
-        g_hash_table_iter_init(&iter, chat_room->roster);
-        while (g_hash_table_iter_next(&iter, &key, &value)) {
-            result = g_list_insert_sorted(result, value, (GCompareFunc)_compare_occupants);
+        GList *curr = occupants;
+        while (curr) {
+            result = g_list_insert_sorted(result, curr->data, (GCompareFunc)_compare_occupants);
+            curr = g_list_next(curr);
         }
 
+        g_list_free(occupants);
+
         return result;
     } else {
         return NULL;
diff --git a/src/server_events.c b/src/server_events.c
index a15ebaf4..01281215 100644
--- a/src/server_events.c
+++ b/src/server_events.c
@@ -681,8 +681,9 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea
 
         // show roster if occupants list disabled by default
         if (!prefs_get_boolean(PREF_OCCUPANTS)) {
-            GList *roster = muc_roster(room);
-            ui_room_roster(room, roster, NULL);
+            GList *occupants = muc_roster(room);
+            ui_room_roster(room, occupants, NULL);
+            g_list_free(occupants);
         }
 
         char *subject = muc_subject(room);
diff --git a/src/ui/core.c b/src/ui/core.c
index 08a1afb8..85605cad 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -2816,15 +2816,15 @@ _ui_muc_roster(const char * const room)
 {
     ProfWin *window = wins_get_by_recipient(room);
     if (window) {
-        GList *roster = muc_roster(room);
-        if (roster) {
+        GList *occupants = muc_roster(room);
+        if (occupants) {
             werase(window->subwin);
 
             if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
                 wattron(window->subwin, COLOUR_ROOMINFO);
                 wprintw(window->subwin, " -Moderators\n");
                 wattroff(window->subwin, COLOUR_ROOMINFO);
-                GList *roster_curr = roster;
+                GList *roster_curr = occupants;
                 while (roster_curr) {
                     Occupant *occupant = roster_curr->data;
                     if (occupant->role == MUC_ROLE_MODERATOR) {
@@ -2842,7 +2842,7 @@ _ui_muc_roster(const char * const room)
                 wattron(window->subwin, COLOUR_ROOMINFO);
                 wprintw(window->subwin, " -Participants\n");
                 wattroff(window->subwin, COLOUR_ROOMINFO);
-                roster_curr = roster;
+                roster_curr = occupants;
                 while (roster_curr) {
                     Occupant *occupant = roster_curr->data;
                     if (occupant->role == MUC_ROLE_PARTICIPANT) {
@@ -2860,7 +2860,7 @@ _ui_muc_roster(const char * const room)
                 wattron(window->subwin, COLOUR_ROOMINFO);
                 wprintw(window->subwin, " -Visitors\n");
                 wattroff(window->subwin, COLOUR_ROOMINFO);
-                roster_curr = roster;
+                roster_curr = occupants;
                 while (roster_curr) {
                     Occupant *occupant = roster_curr->data;
                     if (occupant->role == MUC_ROLE_VISITOR) {
@@ -2878,7 +2878,7 @@ _ui_muc_roster(const char * const room)
                 wattron(window->subwin, COLOUR_ROOMINFO);
                 wprintw(window->subwin, " -Occupants\n");
                 wattroff(window->subwin, COLOUR_ROOMINFO);
-                GList *roster_curr = roster;
+                GList *roster_curr = occupants;
                 while (roster_curr) {
                     Occupant *occupant = roster_curr->data;
                     wprintw(window->subwin, "   ");
@@ -2892,6 +2892,8 @@ _ui_muc_roster(const char * const room)
                 }
             }
         }
+
+        g_list_free(occupants);
     }
 }
 
diff --git a/src/ui/ui.h b/src/ui/ui.h
index eb610801..b3c5be1f 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -143,7 +143,7 @@ void (*ui_room_occupant_affiliation_change)(const char * const room, const char
     const char * const actor, const char * const reason);
 void (*ui_room_occupant_role_and_affiliation_change)(const char * const room, const char * const nick, const char * const role,
     const char * const affiliation, const char * const actor, const char * const reason);
-void (*ui_room_roster)(const char * const room, GList *roster, const char * const presence);
+void (*ui_room_roster)(const char * const room, GList *occupants, const char * const presence);
 void (*ui_room_history)(const char * const room_jid, const char * const nick,
     GTimeVal tv_stamp, const char * const message);
 void (*ui_room_message)(const char * const room_jid, const char * const nick,