comparison src/dbus-useful.c @ 14035:8bda65b88e49

[gaim-migrate @ 16638] A bunch of small changes. Mostly remove "if not null" checks before calling g_free, g_list_free, g_slist_free and g_strdup. Also use g_list_foreach() to call g_free to free strings in an array. And some whitespace changes here and there. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 05 Aug 2006 08:27:39 +0000
parents c9312177821a
children
comparison
equal deleted inserted replaced
14034:0839a7b71325 14035:8bda65b88e49
5 #include "conversation.h" 5 #include "conversation.h"
6 #include "util.h" 6 #include "util.h"
7 7
8 8
9 GaimAccount * 9 GaimAccount *
10 gaim_accounts_find_ext(const char *name, const char *protocol_id, 10 gaim_accounts_find_ext(const char *name, const char *protocol_id,
11 gboolean (*account_test)(const GaimAccount *account)) 11 gboolean (*account_test)(const GaimAccount *account))
12 { 12 {
13 GaimAccount *result = NULL; 13 GaimAccount *result = NULL;
14 GList *l; 14 GList *l;
15 char *who; 15 char *who;
16
17 if (name)
18 who = g_strdup(gaim_normalize(NULL, name));
19 else
20 who = NULL;
21
22 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) {
23 GaimAccount *account = (GaimAccount *)l->data;
24
25 if (who && strcmp(gaim_normalize(NULL, gaim_account_get_username(account)), who))
26 continue;
27 16
28 if (protocol_id && strcmp(account->protocol_id, protocol_id)) 17 if (name)
29 continue; 18 who = g_strdup(gaim_normalize(NULL, name));
19 else
20 who = NULL;
30 21
31 if (account_test && !account_test(account)) 22 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) {
32 continue; 23 GaimAccount *account = (GaimAccount *)l->data;
33 24
34 result = account; 25 if (who && strcmp(gaim_normalize(NULL, gaim_account_get_username(account)), who))
35 break; 26 continue;
36 }
37 27
38 g_free(who); 28 if (protocol_id && strcmp(account->protocol_id, protocol_id))
29 continue;
39 30
40 return result; 31 if (account_test && !account_test(account))
32 continue;
33
34 result = account;
35 break;
36 }
37
38 g_free(who);
39
40 return result;
41 } 41 }
42 42
43 GaimAccount *gaim_accounts_find_any(const char *name, const char *protocol) 43 GaimAccount *gaim_accounts_find_any(const char *name, const char *protocol)
44 { 44 {
45 return gaim_accounts_find_ext(name, protocol, NULL); 45 return gaim_accounts_find_ext(name, protocol, NULL);
46 } 46 }
47 47
48 GaimAccount *gaim_accounts_find_connected(const char *name, const char *protocol) 48 GaimAccount *gaim_accounts_find_connected(const char *name, const char *protocol)
49 { 49 {
50 return gaim_accounts_find_ext(name, protocol, gaim_account_is_connected); 50 return gaim_accounts_find_ext(name, protocol, gaim_account_is_connected);
51 } 51 }
52 52
53 53