1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Removed hash_table_iter usage for room roster

This commit is contained in:
James Booth 2014-11-03 21:27:41 +00:00
parent 7a03dd7641
commit 74a2d4601f
6 changed files with 32 additions and 30 deletions

View File

@ -1,6 +1,3 @@
Test with valgrind using new commands
fix muc roster leak
Update website help
Tag libstrophe release 0.8.7

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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,