From f71aacbbcf8e1ad0a0f64c47a99b4b323888dd3d Mon Sep 17 00:00:00 2001 From: qarkai Date: Wed, 16 Oct 2019 01:06:17 +0300 Subject: [PATCH] Use GSList functions instead of manual iterations --- libpurple/account.c | 58 ++++------------------- libpurple/connection.c | 8 +--- libpurple/prefs.c | 7 +-- libpurple/protocols/bonjour/buddy.c | 5 +- libpurple/protocols/bonjour/jabber.c | 24 ++++------ libpurple/protocols/bonjour/mdns_avahi.c | 6 +-- libpurple/protocols/irc/parse.c | 6 +-- libpurple/protocols/jabber/auth.c | 5 +- libpurple/protocols/jabber/buddy.c | 19 +++----- libpurple/protocols/jabber/google/google_roster.c | 18 +++---- libpurple/protocols/jabber/jabber.c | 5 +- libpurple/protocols/jabber/presence.c | 6 +-- libpurple/protocols/jabber/roster.c | 7 +-- libpurple/protocols/jabber/xdata.c | 10 +--- libpurple/protocols/novell/nmconference.c | 3 +- libpurple/protocols/novell/nmconn.c | 7 +-- libpurple/protocols/novell/nmcontact.c | 22 +-------- libpurple/protocols/novell/nmrtf.c | 11 +---- libpurple/protocols/novell/nmuser.c | 33 ++++--------- libpurple/protocols/novell/novell.c | 8 +--- libpurple/protocols/oscar/flap_connection.c | 14 ++---- libpurple/protocols/oscar/oscar.c | 25 ++++------ libpurple/protocols/oscar/oscar_data.c | 6 +-- libpurple/protocols/oscar/tlv.c | 17 +------ libpurple/protocols/simple/sipmsg.c | 33 +++++-------- libpurple/protocols/zephyr/zephyr.c | 14 +----- pidgin/plugins/spellchk.c | 7 ++- 27 files changed, 88 insertions(+), 296 deletions(-) diff --git a/libpurple/account.c b/libpurple/account.c index eeb9cf48c1..6969066ace 100644 --- a/libpurple/account.c +++ b/libpurple/account.c @@ -1072,15 +1072,8 @@ purple_account_finalize(GObject *object) g_hash_table_destroy(priv->settings); g_hash_table_destroy(priv->ui_settings); - while (priv->deny) { - g_free(priv->deny->data); - priv->deny = g_slist_delete_link(priv->deny, priv->deny); - } - - while (priv->permit) { - g_free(priv->permit->data); - priv->permit = g_slist_delete_link(priv->permit, priv->permit); - } + g_slist_free_full(priv->deny, g_free); + g_slist_free_full(priv->permit, g_free); G_OBJECT_CLASS(purple_account_parent_class)->finalize(object); } @@ -2291,7 +2284,6 @@ gboolean purple_account_privacy_permit_add(PurpleAccount *account, const char *who, gboolean local_only) { - GSList *l; char *name; PurpleBuddy *buddy; PurpleAccountPrivate *priv; @@ -2303,14 +2295,7 @@ purple_account_privacy_permit_add(PurpleAccount *account, const char *who, priv = purple_account_get_instance_private(account); name = g_strdup(purple_normalize(account, who)); - for (l = priv->permit; l != NULL; l = l->next) { - if (g_str_equal(name, l->data)) - /* This buddy already exists */ - break; - } - - if (l != NULL) - { + if (g_slist_find_custom(priv->permit, name, (GCompareFunc)g_strcmp0) != NULL) { /* This buddy already exists, so bail out */ g_free(name); return FALSE; @@ -2352,12 +2337,7 @@ purple_account_privacy_permit_remove(PurpleAccount *account, const char *who, priv = purple_account_get_instance_private(account); name = purple_normalize(account, who); - for (l = priv->permit; l != NULL; l = l->next) { - if (g_str_equal(name, l->data)) - /* We found the buddy we were looking for */ - break; - } - + l = g_slist_find_custom(priv->permit, name, (GCompareFunc)g_strcmp0); if (l == NULL) /* We didn't find the buddy we were looking for, so bail out */ return FALSE; @@ -2389,7 +2369,6 @@ gboolean purple_account_privacy_deny_add(PurpleAccount *account, const char *who, gboolean local_only) { - GSList *l; char *name; PurpleBuddy *buddy; PurpleAccountPrivate *priv; @@ -2401,14 +2380,7 @@ purple_account_privacy_deny_add(PurpleAccount *account, const char *who, priv = purple_account_get_instance_private(account); name = g_strdup(purple_normalize(account, who)); - for (l = priv->deny; l != NULL; l = l->next) { - if (g_str_equal(name, l->data)) - /* This buddy already exists */ - break; - } - - if (l != NULL) - { + if (g_slist_find_custom(priv->deny, name, (GCompareFunc)g_strcmp0) != NULL) { /* This buddy already exists, so bail out */ g_free(name); return FALSE; @@ -2449,12 +2421,7 @@ purple_account_privacy_deny_remove(PurpleAccount *account, const char *who, priv = purple_account_get_instance_private(account); normalized = purple_normalize(account, who); - for (l = priv->deny; l != NULL; l = l->next) { - if (g_str_equal(normalized, l->data)) - /* We found the buddy we were looking for */ - break; - } - + l = g_slist_find_custom(priv->deny, normalized, (GCompareFunc)g_strcmp0); if (l == NULL) /* We didn't find the buddy we were looking for, so bail out */ return FALSE; @@ -2599,7 +2566,6 @@ purple_account_privacy_get_denied(PurpleAccount *account) gboolean purple_account_privacy_check(PurpleAccount *account, const char *who) { - GSList *list; PurpleAccountPrivate *priv = purple_account_get_instance_private(account); switch (purple_account_get_privacy_type(account)) { @@ -2611,19 +2577,11 @@ purple_account_privacy_check(PurpleAccount *account, const char *who) case PURPLE_ACCOUNT_PRIVACY_ALLOW_USERS: who = purple_normalize(account, who); - for (list=priv->permit; list!=NULL; list=list->next) { - if (g_str_equal(who, list->data)) - return TRUE; - } - return FALSE; + return (g_slist_find_custom(priv->permit, who, (GCompareFunc)g_strcmp0) != NULL); case PURPLE_ACCOUNT_PRIVACY_DENY_USERS: who = purple_normalize(account, who); - for (list=priv->deny; list!=NULL; list=list->next) { - if (g_str_equal(who, list->data)) - return FALSE; - } - return TRUE; + return (g_slist_find_custom(priv->deny, who, (GCompareFunc)g_strcmp0) == NULL); case PURPLE_ACCOUNT_PRIVACY_ALLOW_BUDDYLIST: return (purple_blist_find_buddy(account, who) != NULL); diff --git a/libpurple/connection.c b/libpurple/connection.c index ab08be542e..ce92243a55 100644 --- a/libpurple/connection.c +++ b/libpurple/connection.c @@ -855,13 +855,7 @@ purple_connection_finalize(GObject *object) purple_signal_emit(purple_connections_get_handle(), "signing-off", gc); - while (priv->active_chats) - { - PurpleChatConversation *b = priv->active_chats->data; - - priv->active_chats = g_slist_remove(priv->active_chats, b); - purple_chat_conversation_leave(b); - } + g_slist_free_full(priv->active_chats, (GDestroyNotify)purple_chat_conversation_leave); update_keepalive(gc, FALSE); diff --git a/libpurple/prefs.c b/libpurple/prefs.c index caec049908..a98d0f21c6 100644 --- a/libpurple/prefs.c +++ b/libpurple/prefs.c @@ -763,7 +763,6 @@ static void remove_pref(struct purple_pref *pref) { char *name; - GSList *l; if(!pref) return; @@ -794,11 +793,7 @@ remove_pref(struct purple_pref *pref) free_pref_value(pref); - while((l = pref->callbacks) != NULL) { - pref->callbacks = pref->callbacks->next; - g_free(l->data); - g_slist_free_1(l); - } + g_slist_free_full(pref->callbacks, g_free); g_free(pref->name); g_free(pref); } diff --git a/libpurple/protocols/bonjour/buddy.c b/libpurple/protocols/bonjour/buddy.c index deab55f7f4..70b52dc105 100644 --- a/libpurple/protocols/bonjour/buddy.c +++ b/libpurple/protocols/bonjour/buddy.c @@ -243,10 +243,7 @@ void bonjour_buddy_delete(BonjourBuddy *buddy) { g_free(buddy->name); - while (buddy->ips != NULL) { - g_free(buddy->ips->data); - buddy->ips = g_slist_delete_link(buddy->ips, buddy->ips); - } + g_slist_free_full(buddy->ips, g_free); g_free(buddy->first); g_free(buddy->phsh); g_free(buddy->status); diff --git a/libpurple/protocols/bonjour/jabber.c b/libpurple/protocols/bonjour/jabber.c index 47fda8d995..10f461b0ca 100644 --- a/libpurple/protocols/bonjour/jabber.c +++ b/libpurple/protocols/bonjour/jabber.c @@ -801,7 +801,7 @@ _connected_to_buddy(GObject *source, GAsyncResult *res, gpointer user_data) if (conn == NULL) { PurpleConversation *conv = NULL; PurpleAccount *account = NULL; - GSList *tmp = bb->ips; + GSList *tmp; if (error && error->code == G_IO_ERROR_CANCELLED) { /* This conversation was closed before it started. */ @@ -821,8 +821,7 @@ _connected_to_buddy(GObject *source, GAsyncResult *res, gpointer user_data) * presence recieved (e.g. multiple interfaces). * We need to make sure that we find the previously used entry. */ - while (tmp && bb->conversation->ip_link != tmp->data) - tmp = g_slist_next(tmp); + tmp = g_slist_find(bb->ips, bb->conversation->ip_link); if (tmp) tmp = g_slist_next(tmp); @@ -1254,10 +1253,7 @@ bonjour_jabber_stop(BonjourJabber *jdata) g_slist_free(buddies); } - while (jdata->pending_conversations != NULL) { - bonjour_jabber_close_conversation(jdata->pending_conversations->data); - jdata->pending_conversations = g_slist_delete_link(jdata->pending_conversations, jdata->pending_conversations); - } + g_slist_free_full(jdata->pending_conversations, (GDestroyNotify)bonjour_jabber_close_conversation); } XepIq * @@ -1309,21 +1305,19 @@ check_if_blocked(PurpleBuddy *pb) gboolean blocked = FALSE; GSList *l = NULL; PurpleAccount *acc = purple_buddy_get_account(pb); + const gchar *name; if(acc == NULL) return FALSE; - acc = purple_buddy_get_account(pb); + l = purple_account_privacy_get_denied(acc); + name = purple_buddy_get_name(pb); - for(l = purple_account_privacy_get_denied(acc); l != NULL; l = l->next) { - const gchar *name = purple_buddy_get_name(pb); + if(g_slist_find_custom(l, name, (GCompareFunc)purple_utf8_strcasecmp) != NULL) { const gchar *username = bonjour_get_jid(acc); - if(!purple_utf8_strcasecmp(name, (char *)l->data)) { - purple_debug_info("bonjour", "%s has been blocked by %s.\n", name, username); - blocked = TRUE; - break; - } + purple_debug_info("bonjour", "%s has been blocked by %s.\n", name, username); + blocked = TRUE; } return blocked; } diff --git a/libpurple/protocols/bonjour/mdns_avahi.c b/libpurple/protocols/bonjour/mdns_avahi.c index 70b85db67e..00943cc1ea 100644 --- a/libpurple/protocols/bonjour/mdns_avahi.c +++ b/libpurple/protocols/bonjour/mdns_avahi.c @@ -603,11 +603,7 @@ void _mdns_delete_buddy(BonjourBuddy *buddy) { if (idata->buddy_icon_rec_browser != NULL) avahi_record_browser_free(idata->buddy_icon_rec_browser); - while(idata->resolvers != NULL) { - AvahiSvcResolverData *rd = idata->resolvers->data; - _cleanup_resolver_data(rd); - idata->resolvers = g_slist_delete_link(idata->resolvers, idata->resolvers); - } + g_slist_free_full(idata->resolvers, (GDestroyNotify)_cleanup_resolver_data); g_free(idata); diff --git a/libpurple/protocols/irc/parse.c b/libpurple/protocols/irc/parse.c index 8ce8f4dda4..32581ddc9e 100644 --- a/libpurple/protocols/irc/parse.c +++ b/libpurple/protocols/irc/parse.c @@ -239,11 +239,7 @@ void irc_register_commands(void) void irc_unregister_commands(void) { - while (cmds) { - PurpleCmdId id = GPOINTER_TO_UINT(cmds->data); - purple_cmd_unregister(id); - cmds = g_slist_delete_link(cmds, cmds); - } + g_slist_free_full(cmds, (GDestroyNotify)purple_cmd_unregister); } static char *irc_send_convert(struct irc_conn *irc, const char *string) diff --git a/libpurple/protocols/jabber/auth.c b/libpurple/protocols/jabber/auth.c index 08cff69eda..57db258074 100644 --- a/libpurple/protocols/jabber/auth.c +++ b/libpurple/protocols/jabber/auth.c @@ -178,10 +178,7 @@ jabber_auth_start(JabberStream *js, PurpleXmlNode *packet) } } - while (mechanisms) { - g_free(mechanisms->data); - mechanisms = g_slist_delete_link(mechanisms, mechanisms); - } + g_slist_free_full(mechanisms, g_free); if (js->auth_mech == NULL) { /* Found no good mechanisms... */ diff --git a/libpurple/protocols/jabber/buddy.c b/libpurple/protocols/jabber/buddy.c index 8252587f9a..9d62ffd7eb 100644 --- a/libpurple/protocols/jabber/buddy.c +++ b/libpurple/protocols/jabber/buddy.c @@ -880,10 +880,7 @@ static void jabber_buddy_info_show_if_ready(JabberBuddyInfo *jbi) purple_notify_userinfo(jbi->js->gc, jbi->jid, user_info, NULL, NULL); - while (jbi->vcard_images) { - g_object_unref(jbi->vcard_images->data); - jbi->vcard_images = g_slist_delete_link(jbi->vcard_images, jbi->vcard_images); - } + g_slist_free_full(jbi->vcard_images, g_object_unref); jbi->js->pending_buddy_info_requests = g_slist_remove(jbi->js->pending_buddy_info_requests, jbi); @@ -892,20 +889,18 @@ static void jabber_buddy_info_show_if_ready(JabberBuddyInfo *jbi) static void jabber_buddy_info_remove_id(JabberBuddyInfo *jbi, const char *id) { - GSList *l = jbi->ids; + GSList *l; char *comp_id; if(!id) return; - while(l) { + l = g_slist_find_custom(jbi->ids, id, (GCompareFunc)g_strcmp0); + if(l) { comp_id = l->data; - if(purple_strequal(id, comp_id)) { - jbi->ids = g_slist_remove(jbi->ids, comp_id); - g_free(comp_id); - return; - } - l = l->next; + jbi->ids = g_slist_remove(jbi->ids, comp_id); + g_free(comp_id); + return; } } diff --git a/libpurple/protocols/jabber/google/google_roster.c b/libpurple/protocols/jabber/google/google_roster.c index 5ffe810c35..7ebdc30c16 100644 --- a/libpurple/protocols/jabber/google/google_roster.c +++ b/libpurple/protocols/jabber/google/google_roster.c @@ -33,14 +33,11 @@ void jabber_google_roster_outgoing(JabberStream *js, PurpleXmlNode *query, Purpl const char *jid = purple_xmlnode_get_attrib(item, "jid"); char *jid_norm = (char *)jabber_normalize(account, jid); - while (list) { - if (purple_strequal(jid_norm, (char*)list->data)) { - purple_xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER); - purple_xmlnode_set_attrib(query, "gr:ext", "2"); - purple_xmlnode_set_attrib(item, "gr:t", "B"); - return; - } - list = list->next; + if (g_slist_find_custom(list, jid_norm, (GCompareFunc)g_strcmp0)) { + purple_xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER); + purple_xmlnode_set_attrib(query, "gr:ext", "2"); + purple_xmlnode_set_attrib(item, "gr:t", "B"); + return; } } @@ -75,10 +72,7 @@ gboolean jabber_google_roster_incoming(JabberStream *js, PurpleXmlNode *item) purple_debug_info("jabber", "Removing %s from local buddy list\n", jid_norm); - do { - purple_blist_remove_buddy(buddies->data); - buddies = g_slist_delete_link(buddies, buddies); - } while (buddies); + g_slist_free_full(buddies, (GDestroyNotify)purple_blist_remove_buddy); } g_free(jid_norm); diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c index df92d84857..8fef16d504 100644 --- a/libpurple/protocols/jabber/jabber.c +++ b/libpurple/protocols/jabber/jabber.c @@ -3767,10 +3767,7 @@ jabber_register_commands(PurpleProtocol *protocol) static void cmds_free_func(gpointer value) { GSList *commands = value; - while (commands) { - purple_cmd_unregister(GPOINTER_TO_UINT(commands->data)); - commands = g_slist_delete_link(commands, commands); - } + g_slist_free_full(commands, (GDestroyNotify)purple_cmd_unregister); } static void jabber_unregister_commands(PurpleProtocol *protocol) diff --git a/libpurple/protocols/jabber/presence.c b/libpurple/protocols/jabber/presence.c index e799956119..9fab30ad87 100644 --- a/libpurple/protocols/jabber/presence.c +++ b/libpurple/protocols/jabber/presence.c @@ -1055,11 +1055,7 @@ void jabber_presence_parse(JabberStream *js, PurpleXmlNode *packet) } out: - while (presence.chat_info.codes) - presence.chat_info.codes = - g_slist_delete_link(presence.chat_info.codes, - presence.chat_info.codes); - + g_slist_free(presence.chat_info.codes); g_free(presence.status); g_free(presence.vcard_avatar_hash); g_free(presence.nickname); diff --git a/libpurple/protocols/jabber/roster.c b/libpurple/protocols/jabber/roster.c index 7c2c1c1713..50438a987e 100644 --- a/libpurple/protocols/jabber/roster.c +++ b/libpurple/protocols/jabber/roster.c @@ -94,14 +94,11 @@ void jabber_roster_request(JabberStream *js) static void remove_purple_buddies(JabberStream *js, const char *jid) { - GSList *buddies, *l; + GSList *buddies; buddies = purple_blist_find_buddies(purple_connection_get_account(js->gc), jid); - for(l = buddies; l; l = l->next) - purple_blist_remove_buddy(l->data); - - g_slist_free(buddies); + g_slist_free_full(buddies, (GDestroyNotify)purple_blist_remove_buddy); } static void add_purple_buddy_to_groups(JabberStream *js, const char *jid, diff --git a/libpurple/protocols/jabber/xdata.c b/libpurple/protocols/jabber/xdata.c index 94bf0324c7..543b4e6ceb 100644 --- a/libpurple/protocols/jabber/xdata.c +++ b/libpurple/protocols/jabber/xdata.c @@ -141,10 +141,7 @@ static void jabber_x_data_ok_cb(struct jabber_x_data_data *data, PurpleRequestFi } g_hash_table_destroy(data->fields); - while(data->values) { - g_free(data->values->data); - data->values = g_slist_delete_link(data->values, data->values); - } + g_slist_free_full(data->values, g_free); g_list_free_full(data->actions, g_free); g_free(data); @@ -163,10 +160,7 @@ static void jabber_x_data_cancel_cb(struct jabber_x_data_data *data, PurpleReque JabberStream *js = data->js; gboolean hasActions = (data->actions != NULL); g_hash_table_destroy(data->fields); - while(data->values) { - g_free(data->values->data); - data->values = g_slist_delete_link(data->values, data->values); - } + g_slist_free_full(data->values, g_free); g_list_free_full(data->actions, g_free); g_free(data); diff --git a/libpurple/protocols/novell/nmconference.c b/libpurple/protocols/novell/nmconference.c index 7fc024b7c0..d597738842 100644 --- a/libpurple/protocols/novell/nmconference.c +++ b/libpurple/protocols/novell/nmconference.c @@ -165,8 +165,7 @@ nm_conference_remove_participant(NMConference * conference, const char *dn) nm_release_user_record((NMUserRecord *) element->data); element->data = NULL; conference->participants = - g_slist_remove_link(conference->participants, element); - g_slist_free_1(element); + g_slist_delete_link(conference->participants, element); } } diff --git a/libpurple/protocols/novell/nmconn.c b/libpurple/protocols/novell/nmconn.c index e9ad5a65b5..04d0c4e4d6 100644 --- a/libpurple/protocols/novell/nmconn.c +++ b/libpurple/protocols/novell/nmconn.c @@ -182,12 +182,7 @@ nm_create_conn(const char *addr, int port) void nm_release_conn(NMConn *conn) { if (conn) { - GSList *node; - for (node = conn->requests; node; node = node->next) { - if (node->data) - nm_release_request(node->data); - } - g_slist_free(conn->requests); + g_slist_free_full(conn->requests, (GDestroyNotify)nm_release_request); conn->requests = NULL; g_free(conn->ssl_conn); conn->ssl_conn = NULL; diff --git a/libpurple/protocols/novell/nmcontact.c b/libpurple/protocols/novell/nmcontact.c index 6c74e9e593..10c5f6d558 100644 --- a/libpurple/protocols/novell/nmcontact.c +++ b/libpurple/protocols/novell/nmcontact.c @@ -863,35 +863,17 @@ nm_folder_find_contact(NMFolder * folder, const char *dn) static void _release_folder_contacts(NMFolder * folder) { - GSList *cnode; - NMContact *contact; - - for (cnode = folder->contacts; cnode; cnode = cnode->next) { - contact = cnode->data; - cnode->data = NULL; - nm_release_contact(contact); - } - - g_slist_free(folder->contacts); + g_slist_free_full(folder->contacts, (GDestroyNotify)nm_release_contact); folder->contacts = NULL; } static void _release_folder_folders(NMFolder * folder) { - GSList *fnode; - NMFolder *subfolder; - if (folder == NULL) return; - for (fnode = folder->folders; fnode; fnode = fnode->next) { - subfolder = fnode->data; - fnode->data = NULL; - nm_release_folder(subfolder); - } - - g_slist_free(folder->folders); + g_slist_free_full(folder->folders, (GDestroyNotify)nm_release_folder); folder->folders = NULL; } diff --git a/libpurple/protocols/novell/nmrtf.c b/libpurple/protocols/novell/nmrtf.c index 13cfaa620a..b0b00872c1 100644 --- a/libpurple/protocols/novell/nmrtf.c +++ b/libpurple/protocols/novell/nmrtf.c @@ -244,7 +244,6 @@ nm_rtf_deinit(NMRtfContext *ctx) { GSList *node; NMRtfFont *font; - NMRtfStateSave *save; if (ctx) { for (node = ctx->font_table; node; node = node->next) { @@ -254,12 +253,7 @@ nm_rtf_deinit(NMRtfContext *ctx) node->data = NULL; } g_slist_free(ctx->font_table); - for (node = ctx->saved; node; node = node->next) { - save = node->data; - g_free(save); - node->data = NULL; - } - g_slist_free(ctx->saved); + g_slist_free_full(ctx->saved, g_free); g_string_free(ctx->ansi, TRUE); g_string_free(ctx->output, TRUE); g_free(ctx); @@ -489,8 +483,7 @@ rtf_pop_state(NMRtfContext *ctx) g_free(save_old); link_old = ctx->saved; - ctx->saved = g_slist_remove_link(ctx->saved, link_old); - g_slist_free_1(link_old); + ctx->saved = g_slist_delete_link(ctx->saved, link_old); return NMRTF_OK; } diff --git a/libpurple/protocols/novell/nmuser.c b/libpurple/protocols/novell/nmuser.c index 92315bea2f..e6de078b50 100644 --- a/libpurple/protocols/novell/nmuser.c +++ b/libpurple/protocols/novell/nmuser.c @@ -942,11 +942,10 @@ nm_send_remove_privacy_item(NMUser *user, const char *dn, gboolean allow_list, /* Remove item from the cached list */ if ((node = g_slist_find_custom(*list_ptr, dn, (GCompareFunc)purple_utf8_strcasecmp))) { - *list_ptr = g_slist_remove_link(*list_ptr, node); - g_slist_free_1(node); + *list_ptr = g_slist_delete_link(*list_ptr, node); } - fields = nm_field_add_pointer(fields, tag, 0, NMFIELD_METHOD_DELETE, 0, + fields = nm_field_add_pointer(fields, tag, 0, NMFIELD_METHOD_DELETE, 0, g_strdup(dn), NMFIELD_TYPE_DN); rc = nm_send_request(user->conn, "updateblocks", fields, callback, data, NULL); @@ -1070,22 +1069,11 @@ nm_conference_list_remove(NMUser * user, NMConference * conf) void nm_conference_list_free(NMUser * user) { - GSList *cnode; - NMConference *conference; - if (user == NULL) return; - if (user->conferences) { - for (cnode = user->conferences; cnode; cnode = cnode->next) { - conference = cnode->data; - cnode->data = NULL; - nm_release_conference(conference); - } - - g_slist_free(user->conferences); - user->conferences = NULL; - } + g_slist_free_full(user->conferences, (GDestroyNotify)nm_release_conference); + user->conferences = NULL; } NMConference * @@ -1520,14 +1508,11 @@ _handle_multiple_get_details_joinconf_cb(NMUser * user, NMERR_T ret_code, nm_conference_add_participant(conference, user_record); /* Find the user in the list and remove it */ - for (node = list; node; node = node->next) { - if (nm_utf8_str_equal(nm_user_record_get_dn(user_record), - (const char *) node->data)) { - g_free(node->data); - list = g_slist_delete_link(list, node); - nm_request_set_user_define(request, list); - break; - } + node = g_slist_find_custom(list, nm_user_record_get_dn(user_record), (GCompareFunc)purple_utf8_strcasecmp); + if (node) { + g_free(node->data); + list = g_slist_delete_link(list, node); + nm_request_set_user_define(request, list); } /* Time to callback? */ diff --git a/libpurple/protocols/novell/novell.c b/libpurple/protocols/novell/novell.c index e183ff05ea..e4959fd3e2 100644 --- a/libpurple/protocols/novell/novell.c +++ b/libpurple/protocols/novell/novell.c @@ -1242,7 +1242,6 @@ _remove_purple_buddies(NMUser *user) PurpleGroup *group; PurpleBuddy *buddy; GSList *rem_list = NULL; - GSList *l; NMFolder *folder = NULL; const char *gname = NULL; @@ -1276,12 +1275,7 @@ _remove_purple_buddies(NMUser *user) } } - if (rem_list) { - for (l = rem_list; l; l = l->next) { - purple_blist_remove_buddy(l->data); - } - g_slist_free(rem_list); - } + g_slist_free_full(rem_list, (GDestroyNotify)purple_blist_remove_buddy); } /* Add all of the contacts in the given folder to the Purple buddy list */ diff --git a/libpurple/protocols/oscar/flap_connection.c b/libpurple/protocols/oscar/flap_connection.c index b57d71ad10..a87403286b 100644 --- a/libpurple/protocols/oscar/flap_connection.c +++ b/libpurple/protocols/oscar/flap_connection.c @@ -500,11 +500,7 @@ flap_connection_destroy_cb(gpointer data) flap_connection_destroy_chat(od, conn); g_slist_free(conn->groups); - while (conn->rateclasses != NULL) - { - g_free(conn->rateclasses->data); - conn->rateclasses = g_slist_delete_link(conn->rateclasses, conn->rateclasses); - } + g_slist_free_full(conn->rateclasses, g_free); g_hash_table_destroy(conn->rateclass_members); @@ -651,15 +647,11 @@ flap_connection_findbygroup(OscarData *od, guint16 group) for (cur = od->oscar_connections; cur != NULL; cur = cur->next) { FlapConnection *conn; - GSList *l; conn = cur->data; - for (l = conn->groups; l != NULL; l = l->next) - { - if (GPOINTER_TO_UINT(l->data) == group) - return conn; - } + if (g_slist_find(conn->groups, GUINT_TO_POINTER(group)) != NULL) + return conn; } return NULL; diff --git a/libpurple/protocols/oscar/oscar.c b/libpurple/protocols/oscar/oscar.c index 5815face84..c8d05f5ed7 100644 --- a/libpurple/protocols/oscar/oscar.c +++ b/libpurple/protocols/oscar/oscar.c @@ -878,12 +878,7 @@ oscar_close(PurpleConnection *gc) od = purple_connection_get_protocol_data(gc); - while (od->oscar_chats) - { - struct chat_connection *cc = od->oscar_chats->data; - od->oscar_chats = g_slist_remove(od->oscar_chats, cc); - oscar_chat_destroy(cc); - } + g_slist_free_full(od->oscar_chats, (GDestroyNotify)oscar_chat_destroy); while (od->create_rooms) { struct create_room *cr = od->create_rooms->data; @@ -2980,10 +2975,9 @@ oscar_send_typing(PurpleConnection *gc, const char *name, PurpleIMTypingState st else { /* Don't send if this turkey is in our deny list */ PurpleAccount *account = purple_connection_get_account(gc); - GSList *list; + GSList *list = purple_account_privacy_get_denied(account); - for (list=purple_account_privacy_get_denied(account); (list && oscar_util_name_compare(name, list->data)); list=list->next); - if (!list) { + if (!g_slist_find_custom(list, name, (GCompareFunc)oscar_util_name_compare)) { struct buddyinfo *bi = g_hash_table_lookup(od->buddyinfo, purple_normalize(account, name)); if (bi && bi->typingnot) { if (state == PURPLE_IM_TYPING) @@ -3775,10 +3769,7 @@ static int purple_ssi_parselist(OscarData *od, FlapConnection *conn, FlapFrame * cur = g_slist_prepend(cur, b); } } - while (cur != NULL) { - purple_blist_remove_buddy(cur->data); - cur = g_slist_delete_link(cur, cur); - } + g_slist_free_full(cur, (GDestroyNotify)purple_blist_remove_buddy); /* Permit list (ICQ doesn't have one) */ if (!od->icq) { @@ -3889,8 +3880,8 @@ static int purple_ssi_parselist(OscarData *od, FlapConnection *conn, FlapFrame * case AIM_SSI_TYPE_PERMIT: { /* Permit buddy (unless we're on ICQ) */ if (!od->icq && curitem->name) { - for (cur = purple_account_privacy_get_permitted(account); (cur && oscar_util_name_compare(curitem->name, cur->data)); cur = cur->next); - if (!cur) { + cur = purple_account_privacy_get_permitted(account); + if (!g_slist_find_custom(cur, curitem->name, (GCompareFunc)oscar_util_name_compare)) { purple_debug_info("oscar", "ssi: adding permit buddy %s to local list\n", curitem->name); purple_account_privacy_permit_add(account, curitem->name, TRUE); @@ -3901,8 +3892,8 @@ static int purple_ssi_parselist(OscarData *od, FlapConnection *conn, FlapFrame * case AIM_SSI_TYPE_ICQDENY: case AIM_SSI_TYPE_DENY: { /* Deny buddy */ if (curitem->type == deny_entry_type && curitem->name) { - for (cur = purple_account_privacy_get_denied(account); (cur && oscar_util_name_compare(curitem->name, cur->data)); cur = cur->next); - if (!cur) { + cur = purple_account_privacy_get_denied(account); + if (!g_slist_find_custom(cur, curitem->name, (GCompareFunc)oscar_util_name_compare)) { purple_debug_info("oscar", "ssi: adding deny buddy %s to local list\n", curitem->name); purple_account_privacy_deny_add(account, curitem->name, TRUE); diff --git a/libpurple/protocols/oscar/oscar_data.c b/libpurple/protocols/oscar/oscar_data.c index 8faa7a6e6c..77a67253b4 100644 --- a/libpurple/protocols/oscar/oscar_data.c +++ b/libpurple/protocols/oscar/oscar_data.c @@ -111,11 +111,7 @@ oscar_data_destroy(OscarData *od) g_object_unref(od->http_conns); } - while (od->requesticon) - { - g_free(od->requesticon->data); - od->requesticon = g_slist_delete_link(od->requesticon, od->requesticon); - } + g_slist_free_full(od->requesticon, g_free); g_free(od->email); g_free(od->newp); g_free(od->oldp); diff --git a/libpurple/protocols/oscar/tlv.c b/libpurple/protocols/oscar/tlv.c index 04163b78f6..311cbdafc8 100644 --- a/libpurple/protocols/oscar/tlv.c +++ b/libpurple/protocols/oscar/tlv.c @@ -233,11 +233,7 @@ int aim_tlvlist_cmp(GSList *one, GSList *two) */ void aim_tlvlist_free(GSList *list) { - while (list != NULL) - { - freetlv(list->data); - list = g_slist_delete_link(list, list); - } + g_slist_free_full(list, (GDestroyNotify)freetlv); } /** @@ -248,16 +244,7 @@ void aim_tlvlist_free(GSList *list) */ int aim_tlvlist_count(GSList *list) { - GSList *cur; - int count; - - if (list == NULL) - return 0; - - for (cur = list, count = 0; cur; cur = cur->next) - count++; - - return count; + return (int)g_slist_length(list); } /** diff --git a/libpurple/protocols/simple/sipmsg.c b/libpurple/protocols/simple/sipmsg.c index 45e959d422..1259fd6998 100644 --- a/libpurple/protocols/simple/sipmsg.c +++ b/libpurple/protocols/simple/sipmsg.c @@ -193,32 +193,21 @@ void sipmsg_free(struct sipmsg *msg) { } void sipmsg_remove_header(struct sipmsg *msg, const gchar *name) { - struct siphdrelement *elem; - GSList *tmp = msg->headers; - while(tmp) { - elem = tmp->data; - if(g_ascii_strcasecmp(elem->name, name)==0) { - msg->headers = g_slist_remove(msg->headers, elem); - g_free(elem->name); - g_free(elem->value); - g_free(elem); - return; - } - tmp = g_slist_next(tmp); + GSList *tmp = g_slist_find_custom(msg->headers, name, (GCompareFunc)g_ascii_strcasecmp); + if(tmp) { + struct siphdrelement *elem = tmp->data; + msg->headers = g_slist_remove(msg->headers, elem); + g_free(elem->name); + g_free(elem->value); + g_free(elem); } - return; } const gchar *sipmsg_find_header(struct sipmsg *msg, const gchar *name) { - GSList *tmp; - struct siphdrelement *elem; - tmp = msg->headers; - while(tmp) { - elem = tmp->data; - if(g_ascii_strcasecmp(elem->name, name)==0) { - return elem->value; - } - tmp = g_slist_next(tmp); + GSList *tmp = g_slist_find_custom(msg->headers, name, (GCompareFunc)g_ascii_strcasecmp); + if(tmp) { + struct siphdrelement *elem = tmp->data; + return elem->value; } return NULL; } diff --git a/libpurple/protocols/zephyr/zephyr.c b/libpurple/protocols/zephyr/zephyr.c index f756b61aea..00ca15d6b6 100644 --- a/libpurple/protocols/zephyr/zephyr.c +++ b/libpurple/protocols/zephyr/zephyr.c @@ -1982,7 +1982,6 @@ static void write_anyone(zephyr_account *zephyr) static void zephyr_close(PurpleConnection * gc) { - GSList *s; zephyr_account *zephyr = purple_connection_get_protocol_data(gc); pid_t tzc_pid = zephyr->tzc_pid; @@ -1994,12 +1993,7 @@ static void zephyr_close(PurpleConnection * gc) if (purple_account_get_bool(purple_connection_get_account(gc), "write_zsubs", FALSE)) write_zsubs(zephyr); - s = zephyr->subscrips; - while (s) { - free_triple((zephyr_triple *) s->data); - s = s->next; - } - g_slist_free(zephyr->subscrips); + g_slist_free_full(zephyr->subscrips, (GDestroyNotify)free_triple); if (zephyr->nottimer) g_source_remove(zephyr->nottimer); @@ -2813,11 +2807,7 @@ static void zephyr_register_slash_commands(void) static void zephyr_unregister_slash_commands(void) { - while (cmds) { - PurpleCmdId id = GPOINTER_TO_UINT(cmds->data); - purple_cmd_unregister(id); - cmds = g_slist_delete_link(cmds, cmds); - } + g_slist_free_full(cmds, (GDestroyNotify)purple_cmd_unregister); } diff --git a/pidgin/plugins/spellchk.c b/pidgin/plugins/spellchk.c index 39fbb2b681..9c4b19a4ee 100644 --- a/pidgin/plugins/spellchk.c +++ b/pidgin/plugins/spellchk.c @@ -2012,13 +2012,13 @@ static void add_selected_row_to_list(GtkTreeModel *model, GtkTreePath *path, *list = g_slist_prepend(*list, row_reference); } -static void remove_row(void *data1, gpointer data2) +static void remove_row(void *data) { GtkTreeRowReference *row_reference; GtkTreePath *path; GtkTreeIter iter; - row_reference = (GtkTreeRowReference *)data1; + row_reference = (GtkTreeRowReference *)data; path = gtk_tree_row_reference_get_path(row_reference); if (gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path)) @@ -2036,8 +2036,7 @@ static void list_delete(void) sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); gtk_tree_selection_selected_foreach(sel, add_selected_row_to_list, &list); - g_slist_foreach(list, remove_row, NULL); - g_slist_free(list); + g_slist_free_full(list, remove_row); save_list(); } -- 2.11.4.GIT