comparison libgaim/privacy.c @ 15318:b17a907065cc

[gaim-migrate @ 18109] Patch #1259960 ((HEAD) Additions to the privacy API) and #1236132 (Allow/Block option in buddy-context menu). committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 12 Jan 2007 00:47:58 +0000
parents f23506e8f812
children
comparison
equal deleted inserted replaced
15317:d928cf5ead1b 15318:b17a907065cc
76 gboolean local_only) 76 gboolean local_only)
77 { 77 {
78 GSList *l; 78 GSList *l;
79 const char *name; 79 const char *name;
80 GaimBuddy *buddy; 80 GaimBuddy *buddy;
81 char *del;
81 82
82 g_return_val_if_fail(account != NULL, FALSE); 83 g_return_val_if_fail(account != NULL, FALSE);
83 g_return_val_if_fail(who != NULL, FALSE); 84 g_return_val_if_fail(who != NULL, FALSE);
84 85
85 name = gaim_normalize(account, who); 86 name = gaim_normalize(account, who);
90 } 91 }
91 92
92 if (l == NULL) 93 if (l == NULL)
93 return FALSE; 94 return FALSE;
94 95
95 g_free(l->data); 96 /* We should not free l->data just yet. There can be occasions where
97 * l->data == who. In such cases, freeing l->data here can cause crashes
98 * later when who is used. */
99 del = l->data;
96 account->permit = g_slist_delete_link(account->permit, l); 100 account->permit = g_slist_delete_link(account->permit, l);
97 101
98 if (!local_only && gaim_account_is_connected(account)) 102 if (!local_only && gaim_account_is_connected(account))
99 serv_rem_permit(gaim_account_get_connection(account), who); 103 serv_rem_permit(gaim_account_get_connection(account), who);
100 104
106 buddy = gaim_find_buddy(account, name); 110 buddy = gaim_find_buddy(account, name);
107 if (buddy != NULL) { 111 if (buddy != NULL) {
108 gaim_signal_emit(gaim_blist_get_handle(), 112 gaim_signal_emit(gaim_blist_get_handle(),
109 "buddy-privacy-changed", buddy); 113 "buddy-privacy-changed", buddy);
110 } 114 }
115 g_free(del);
111 return TRUE; 116 return TRUE;
112 } 117 }
113 118
114 gboolean 119 gboolean
115 gaim_privacy_deny_add(GaimAccount *account, const char *who, 120 gaim_privacy_deny_add(GaimAccount *account, const char *who,
193 198
194 g_free(name); 199 g_free(name);
195 gaim_blist_schedule_save(); 200 gaim_blist_schedule_save();
196 201
197 return TRUE; 202 return TRUE;
203 }
204
205 /* This makes sure that only all the buddies are in the permit list. */
206 static void
207 add_buddies_in_permit(GaimAccount *account, gboolean local)
208 {
209 GSList *list, *iter;
210 /* Remove anyone in the permit list who is not in the buddylist */
211 for (list = account->permit; list != NULL; ) {
212 char *person = list->data;
213 list = list->next;
214 if (!gaim_find_buddy(account, person))
215 gaim_privacy_permit_remove(account, person, local);
216 }
217 /* Now make sure everyone in the buddylist is in the permit list */
218 for (iter = list = gaim_find_buddies(account, NULL); iter; iter = iter->next) {
219 GaimBuddy *buddy = iter->data;
220 if (!g_slist_find_custom(account->permit, buddy->name, (GCompareFunc)g_utf8_collate))
221 gaim_privacy_permit_add(account, buddy->name, local);
222 }
223 g_slist_free(list);
224 }
225
226 void
227 gaim_privacy_allow(GaimAccount *account, const char *who, gboolean local,
228 gboolean restore)
229 {
230 GSList *list;
231
232 switch (account->perm_deny) {
233 case GAIM_PRIVACY_ALLOW_ALL:
234 return;
235 case GAIM_PRIVACY_ALLOW_USERS:
236 gaim_privacy_permit_add(account, who, local);
237 break;
238 case GAIM_PRIVACY_DENY_USERS:
239 gaim_privacy_deny_remove(account, who, local);
240 break;
241 case GAIM_PRIVACY_DENY_ALL:
242 if (!restore) {
243 /* Empty the allow-list. */
244 for (list = account->permit; list != NULL;) {
245 char *who = list->data;
246 list = list->next;
247 gaim_privacy_permit_remove(account, who, local);
248 }
249 }
250 gaim_privacy_permit_add(account, who, local);
251 account->perm_deny = GAIM_PRIVACY_ALLOW_USERS;
252 break;
253 case GAIM_PRIVACY_ALLOW_BUDDYLIST:
254 if (!gaim_find_buddy(account, who)) {
255 add_buddies_in_permit(account, local);
256 gaim_privacy_permit_add(account, who, local);
257 account->perm_deny = GAIM_PRIVACY_ALLOW_USERS;
258 }
259 break;
260 default:
261 g_return_if_reached();
262 }
263 }
264
265 void
266 gaim_privacy_deny(GaimAccount *account, const char *who, gboolean local,
267 gboolean restore)
268 {
269 GSList *list;
270
271 switch (account->perm_deny) {
272 case GAIM_PRIVACY_ALLOW_ALL:
273 if (!restore) {
274 /* Empty the deny-list. */
275 for (list = account->deny; list != NULL; ) {
276 char *person = list->data;
277 list = list->next;
278 gaim_privacy_deny_remove(account, person, local);
279 }
280 }
281 gaim_privacy_deny_add(account, who, local);
282 account->perm_deny = GAIM_PRIVACY_DENY_USERS;
283 break;
284 case GAIM_PRIVACY_ALLOW_USERS:
285 gaim_privacy_permit_remove(account, who, local);
286 break;
287 case GAIM_PRIVACY_DENY_USERS:
288 gaim_privacy_deny_add(account, who, local);
289 break;
290 case GAIM_PRIVACY_DENY_ALL:
291 break;
292 case GAIM_PRIVACY_ALLOW_BUDDYLIST:
293 if (gaim_find_buddy(account, who)) {
294 add_buddies_in_permit(account, local);
295 gaim_privacy_permit_remove(account, who, local);
296 account->perm_deny = GAIM_PRIVACY_ALLOW_USERS;
297 }
298 break;
299 default:
300 g_return_if_reached();
301 }
198 } 302 }
199 303
200 gboolean 304 gboolean
201 gaim_privacy_check(GaimAccount *account, const char *who) 305 gaim_privacy_check(GaimAccount *account, const char *who)
202 { 306 {