Mercurial > pidgin
annotate src/privacy.c @ 13623:51d436a267ac
[gaim-migrate @ 16009]
Use the GSlice allocator (for logs and log sets) when compiling with glib 2.10 or greater and eliminate some unnecessary memory zeroing. This cuts the log loading time in half for one of Luke's contacts.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Tue, 11 Apr 2006 16:06:24 +0000 |
parents | 18e621aa8a43 |
children | 7f276f375789 |
rev | line source |
---|---|
6371 | 1 /** |
2 * gaim | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
8007
a13118091bc7
[gaim-migrate @ 8685]
Christian Hammond <chipx86@chipx86.com>
parents:
7581
diff
changeset
|
7 * |
6371 | 8 * This program is free software; you can redistribute it and/or modify |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 #include "internal.h" | |
23 | |
24 #include "account.h" | |
25 #include "privacy.h" | |
26 #include "server.h" | |
27 #include "util.h" | |
28 | |
29 static GaimPrivacyUiOps *privacy_ops = NULL; | |
30 | |
31 gboolean | |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
32 gaim_privacy_permit_add(GaimAccount *account, const char *who, |
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
33 gboolean local_only) |
6371 | 34 { |
35 GSList *l; | |
36 char *name; | |
37 | |
38 g_return_val_if_fail(account != NULL, FALSE); | |
39 g_return_val_if_fail(who != NULL, FALSE); | |
40 | |
7261 | 41 name = g_strdup(gaim_normalize(account, who)); |
6371 | 42 |
43 for (l = account->permit; l != NULL; l = l->next) { | |
7261 | 44 if (!gaim_utf8_strcasecmp(name, gaim_normalize(account, (char *)l->data))) |
6371 | 45 break; |
46 } | |
47 | |
48 g_free(name); | |
49 | |
50 if (l != NULL) | |
51 return FALSE; | |
52 | |
53 account->permit = g_slist_append(account->permit, g_strdup(who)); | |
54 | |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
55 if (!local_only && gaim_account_is_connected(account)) |
6373
4d61775a5741
[gaim-migrate @ 6878]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
56 serv_add_permit(gaim_account_get_connection(account), who); |
4d61775a5741
[gaim-migrate @ 6878]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
57 |
6371 | 58 if (privacy_ops != NULL && privacy_ops->permit_added != NULL) |
59 privacy_ops->permit_added(account, who); | |
60 | |
10704 | 61 gaim_blist_schedule_save(); |
62 | |
6371 | 63 return TRUE; |
64 } | |
65 | |
66 gboolean | |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
67 gaim_privacy_permit_remove(GaimAccount *account, const char *who, |
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
68 gboolean local_only) |
6371 | 69 { |
70 GSList *l; | |
71 char *name; | |
72 | |
73 g_return_val_if_fail(account != NULL, FALSE); | |
74 g_return_val_if_fail(who != NULL, FALSE); | |
75 | |
7261 | 76 name = g_strdup(gaim_normalize(account, who)); |
6371 | 77 |
78 for (l = account->permit; l != NULL; l = l->next) { | |
7261 | 79 if (!gaim_utf8_strcasecmp(name, gaim_normalize(account, (char *)l->data))) |
6371 | 80 break; |
81 } | |
82 | |
83 g_free(name); | |
84 | |
85 if (l == NULL) | |
86 return FALSE; | |
87 | |
88 g_free(l->data); | |
11719
109ee3bfeac5
[gaim-migrate @ 14010]
Richard Laager <rlaager@wiktel.com>
parents:
11111
diff
changeset
|
89 account->permit = g_slist_delete_link(account->permit, l); |
6371 | 90 |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
91 if (!local_only && gaim_account_is_connected(account)) |
7581 | 92 serv_rem_permit(gaim_account_get_connection(account), who); |
6373
4d61775a5741
[gaim-migrate @ 6878]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
93 |
6371 | 94 if (privacy_ops != NULL && privacy_ops->permit_removed != NULL) |
95 privacy_ops->permit_removed(account, who); | |
96 | |
10704 | 97 gaim_blist_schedule_save(); |
98 | |
6371 | 99 return TRUE; |
100 } | |
101 | |
102 gboolean | |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
103 gaim_privacy_deny_add(GaimAccount *account, const char *who, |
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
104 gboolean local_only) |
6371 | 105 { |
106 GSList *l; | |
107 char *name; | |
108 | |
109 g_return_val_if_fail(account != NULL, FALSE); | |
110 g_return_val_if_fail(who != NULL, FALSE); | |
111 | |
7261 | 112 name = g_strdup(gaim_normalize(account, who)); |
6371 | 113 |
114 for (l = account->deny; l != NULL; l = l->next) { | |
7261 | 115 if (!gaim_utf8_strcasecmp(name, gaim_normalize(account, (char *)l->data))) |
6371 | 116 break; |
117 } | |
118 | |
119 g_free(name); | |
120 | |
121 if (l != NULL) | |
122 return FALSE; | |
123 | |
124 account->deny = g_slist_append(account->deny, g_strdup(who)); | |
125 | |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
126 if (!local_only && gaim_account_is_connected(account)) |
6373
4d61775a5741
[gaim-migrate @ 6878]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
127 serv_add_deny(gaim_account_get_connection(account), who); |
4d61775a5741
[gaim-migrate @ 6878]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
128 |
6371 | 129 if (privacy_ops != NULL && privacy_ops->deny_added != NULL) |
130 privacy_ops->deny_added(account, who); | |
131 | |
10704 | 132 gaim_blist_schedule_save(); |
133 | |
6371 | 134 return TRUE; |
135 } | |
136 | |
137 gboolean | |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
138 gaim_privacy_deny_remove(GaimAccount *account, const char *who, |
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
139 gboolean local_only) |
6371 | 140 { |
141 GSList *l; | |
142 char *name; | |
143 | |
144 g_return_val_if_fail(account != NULL, FALSE); | |
145 g_return_val_if_fail(who != NULL, FALSE); | |
146 | |
7261 | 147 name = g_strdup(gaim_normalize(account, who)); |
6371 | 148 |
149 for (l = account->deny; l != NULL; l = l->next) { | |
7261 | 150 if (!gaim_utf8_strcasecmp(name, gaim_normalize(account, (char *)l->data))) |
6371 | 151 break; |
152 } | |
153 | |
154 g_free(name); | |
155 | |
156 if (l == NULL) | |
157 return FALSE; | |
158 | |
13149
18e621aa8a43
[gaim-migrate @ 15512]
Richard Laager <rlaager@wiktel.com>
parents:
11719
diff
changeset
|
159 name = l->data; |
11719
109ee3bfeac5
[gaim-migrate @ 14010]
Richard Laager <rlaager@wiktel.com>
parents:
11111
diff
changeset
|
160 account->deny = g_slist_delete_link(account->deny, l); |
6371 | 161 |
8150 | 162 if (!local_only && gaim_account_is_connected(account)) |
13149
18e621aa8a43
[gaim-migrate @ 15512]
Richard Laager <rlaager@wiktel.com>
parents:
11719
diff
changeset
|
163 serv_rem_deny(gaim_account_get_connection(account), name); |
6373
4d61775a5741
[gaim-migrate @ 6878]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
164 |
6371 | 165 if (privacy_ops != NULL && privacy_ops->deny_removed != NULL) |
13149
18e621aa8a43
[gaim-migrate @ 15512]
Richard Laager <rlaager@wiktel.com>
parents:
11719
diff
changeset
|
166 privacy_ops->deny_removed(account, name); |
6371 | 167 |
13149
18e621aa8a43
[gaim-migrate @ 15512]
Richard Laager <rlaager@wiktel.com>
parents:
11719
diff
changeset
|
168 g_free(name); |
10704 | 169 gaim_blist_schedule_save(); |
170 | |
6371 | 171 return TRUE; |
172 } | |
173 | |
11111
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
174 gboolean |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
175 gaim_privacy_check(GaimAccount *account, const char *who) |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
176 { |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
177 GSList *list; |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
178 |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
179 switch (account->perm_deny) { |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
180 case GAIM_PRIVACY_ALLOW_ALL: |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
181 return TRUE; |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
182 |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
183 case GAIM_PRIVACY_DENY_ALL: |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
184 return FALSE; |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
185 |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
186 case GAIM_PRIVACY_ALLOW_USERS: |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
187 for (list=account->permit; list!=NULL; list=list->next) { |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
188 if (!gaim_utf8_strcasecmp(who, gaim_normalize(account, (char *)list->data))) |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
189 return TRUE; |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
190 } |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
191 return FALSE; |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
192 |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
193 case GAIM_PRIVACY_DENY_USERS: |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
194 for (list=account->deny; list!=NULL; list=list->next) { |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
195 if (!gaim_utf8_strcasecmp(who, gaim_normalize( account, (char *)list->data ))) |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
196 return FALSE; |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
197 } |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
198 return TRUE; |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
199 |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
200 case GAIM_PRIVACY_ALLOW_BUDDYLIST: |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
201 return (gaim_find_buddy(account, who) != NULL); |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
202 |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
203 default: |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
204 g_return_val_if_reached(TRUE); |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
205 } |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
206 } |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
207 |
6371 | 208 void |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
209 gaim_privacy_set_ui_ops(GaimPrivacyUiOps *ops) |
6371 | 210 { |
211 privacy_ops = ops; | |
212 } | |
213 | |
214 GaimPrivacyUiOps * | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
215 gaim_privacy_get_ui_ops(void) |
6371 | 216 { |
217 return privacy_ops; | |
218 } | |
219 | |
220 void | |
221 gaim_privacy_init(void) | |
222 { | |
223 } |