comparison libpurple/privacy.c @ 15822:32c366eeeb99

sed -ie 's/gaim/purple/g'
author Sean Egan <seanegan@gmail.com>
date Mon, 19 Mar 2007 07:01:17 +0000
parents 5fe8042783c1
children 10f175539cfe
comparison
equal deleted inserted replaced
15821:84b0f9b23ede 15822:32c366eeeb99
1 /** 1 /**
2 * gaim 2 * purple
3 * 3 *
4 * Gaim is the legal property of its developers, whose names are too numerous 4 * Purple 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 5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution. 6 * source distribution.
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 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 9 * it under the terms of the GNU General Public License as published by
24 #include "account.h" 24 #include "account.h"
25 #include "privacy.h" 25 #include "privacy.h"
26 #include "server.h" 26 #include "server.h"
27 #include "util.h" 27 #include "util.h"
28 28
29 static GaimPrivacyUiOps *privacy_ops = NULL; 29 static PurplePrivacyUiOps *privacy_ops = NULL;
30 30
31 gboolean 31 gboolean
32 gaim_privacy_permit_add(GaimAccount *account, const char *who, 32 purple_privacy_permit_add(PurpleAccount *account, const char *who,
33 gboolean local_only) 33 gboolean local_only)
34 { 34 {
35 GSList *l; 35 GSList *l;
36 char *name; 36 char *name;
37 GaimBuddy *buddy; 37 PurpleBuddy *buddy;
38 38
39 g_return_val_if_fail(account != NULL, FALSE); 39 g_return_val_if_fail(account != NULL, FALSE);
40 g_return_val_if_fail(who != NULL, FALSE); 40 g_return_val_if_fail(who != NULL, FALSE);
41 41
42 name = g_strdup(gaim_normalize(account, who)); 42 name = g_strdup(purple_normalize(account, who));
43 43
44 for (l = account->permit; l != NULL; l = l->next) { 44 for (l = account->permit; l != NULL; l = l->next) {
45 if (!gaim_utf8_strcasecmp(name, (char *)l->data)) 45 if (!purple_utf8_strcasecmp(name, (char *)l->data))
46 break; 46 break;
47 } 47 }
48 48
49 if (l != NULL) 49 if (l != NULL)
50 { 50 {
52 return FALSE; 52 return FALSE;
53 } 53 }
54 54
55 account->permit = g_slist_append(account->permit, name); 55 account->permit = g_slist_append(account->permit, name);
56 56
57 if (!local_only && gaim_account_is_connected(account)) 57 if (!local_only && purple_account_is_connected(account))
58 serv_add_permit(gaim_account_get_connection(account), who); 58 serv_add_permit(purple_account_get_connection(account), who);
59 59
60 if (privacy_ops != NULL && privacy_ops->permit_added != NULL) 60 if (privacy_ops != NULL && privacy_ops->permit_added != NULL)
61 privacy_ops->permit_added(account, who); 61 privacy_ops->permit_added(account, who);
62 62
63 gaim_blist_schedule_save(); 63 purple_blist_schedule_save();
64 64
65 /* This lets the UI know a buddy has had its privacy setting changed */ 65 /* This lets the UI know a buddy has had its privacy setting changed */
66 buddy = gaim_find_buddy(account, name); 66 buddy = purple_find_buddy(account, name);
67 if (buddy != NULL) { 67 if (buddy != NULL) {
68 gaim_signal_emit(gaim_blist_get_handle(), 68 purple_signal_emit(purple_blist_get_handle(),
69 "buddy-privacy-changed", buddy); 69 "buddy-privacy-changed", buddy);
70 } 70 }
71 return TRUE; 71 return TRUE;
72 } 72 }
73 73
74 gboolean 74 gboolean
75 gaim_privacy_permit_remove(GaimAccount *account, const char *who, 75 purple_privacy_permit_remove(PurpleAccount *account, const char *who,
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 PurpleBuddy *buddy;
81 char *del; 81 char *del;
82 82
83 g_return_val_if_fail(account != NULL, FALSE); 83 g_return_val_if_fail(account != NULL, FALSE);
84 g_return_val_if_fail(who != NULL, FALSE); 84 g_return_val_if_fail(who != NULL, FALSE);
85 85
86 name = gaim_normalize(account, who); 86 name = purple_normalize(account, who);
87 87
88 for (l = account->permit; l != NULL; l = l->next) { 88 for (l = account->permit; l != NULL; l = l->next) {
89 if (!gaim_utf8_strcasecmp(name, (char *)l->data)) 89 if (!purple_utf8_strcasecmp(name, (char *)l->data))
90 break; 90 break;
91 } 91 }
92 92
93 if (l == NULL) 93 if (l == NULL)
94 return FALSE; 94 return FALSE;
97 * l->data == who. In such cases, freeing l->data here can cause crashes 97 * l->data == who. In such cases, freeing l->data here can cause crashes
98 * later when who is used. */ 98 * later when who is used. */
99 del = l->data; 99 del = l->data;
100 account->permit = g_slist_delete_link(account->permit, l); 100 account->permit = g_slist_delete_link(account->permit, l);
101 101
102 if (!local_only && gaim_account_is_connected(account)) 102 if (!local_only && purple_account_is_connected(account))
103 serv_rem_permit(gaim_account_get_connection(account), who); 103 serv_rem_permit(purple_account_get_connection(account), who);
104 104
105 if (privacy_ops != NULL && privacy_ops->permit_removed != NULL) 105 if (privacy_ops != NULL && privacy_ops->permit_removed != NULL)
106 privacy_ops->permit_removed(account, who); 106 privacy_ops->permit_removed(account, who);
107 107
108 gaim_blist_schedule_save(); 108 purple_blist_schedule_save();
109 109
110 buddy = gaim_find_buddy(account, name); 110 buddy = purple_find_buddy(account, name);
111 if (buddy != NULL) { 111 if (buddy != NULL) {
112 gaim_signal_emit(gaim_blist_get_handle(), 112 purple_signal_emit(purple_blist_get_handle(),
113 "buddy-privacy-changed", buddy); 113 "buddy-privacy-changed", buddy);
114 } 114 }
115 g_free(del); 115 g_free(del);
116 return TRUE; 116 return TRUE;
117 } 117 }
118 118
119 gboolean 119 gboolean
120 gaim_privacy_deny_add(GaimAccount *account, const char *who, 120 purple_privacy_deny_add(PurpleAccount *account, const char *who,
121 gboolean local_only) 121 gboolean local_only)
122 { 122 {
123 GSList *l; 123 GSList *l;
124 char *name; 124 char *name;
125 GaimBuddy *buddy; 125 PurpleBuddy *buddy;
126 126
127 g_return_val_if_fail(account != NULL, FALSE); 127 g_return_val_if_fail(account != NULL, FALSE);
128 g_return_val_if_fail(who != NULL, FALSE); 128 g_return_val_if_fail(who != NULL, FALSE);
129 129
130 name = g_strdup(gaim_normalize(account, who)); 130 name = g_strdup(purple_normalize(account, who));
131 131
132 for (l = account->deny; l != NULL; l = l->next) { 132 for (l = account->deny; l != NULL; l = l->next) {
133 if (!gaim_utf8_strcasecmp(name, gaim_normalize(account, (char *)l->data))) 133 if (!purple_utf8_strcasecmp(name, purple_normalize(account, (char *)l->data)))
134 break; 134 break;
135 } 135 }
136 136
137 if (l != NULL) 137 if (l != NULL)
138 { 138 {
140 return FALSE; 140 return FALSE;
141 } 141 }
142 142
143 account->deny = g_slist_append(account->deny, name); 143 account->deny = g_slist_append(account->deny, name);
144 144
145 if (!local_only && gaim_account_is_connected(account)) 145 if (!local_only && purple_account_is_connected(account))
146 serv_add_deny(gaim_account_get_connection(account), who); 146 serv_add_deny(purple_account_get_connection(account), who);
147 147
148 if (privacy_ops != NULL && privacy_ops->deny_added != NULL) 148 if (privacy_ops != NULL && privacy_ops->deny_added != NULL)
149 privacy_ops->deny_added(account, who); 149 privacy_ops->deny_added(account, who);
150 150
151 gaim_blist_schedule_save(); 151 purple_blist_schedule_save();
152 152
153 buddy = gaim_find_buddy(account, name); 153 buddy = purple_find_buddy(account, name);
154 if (buddy != NULL) { 154 if (buddy != NULL) {
155 gaim_signal_emit(gaim_blist_get_handle(), 155 purple_signal_emit(purple_blist_get_handle(),
156 "buddy-privacy-changed", buddy); 156 "buddy-privacy-changed", buddy);
157 } 157 }
158 return TRUE; 158 return TRUE;
159 } 159 }
160 160
161 gboolean 161 gboolean
162 gaim_privacy_deny_remove(GaimAccount *account, const char *who, 162 purple_privacy_deny_remove(PurpleAccount *account, const char *who,
163 gboolean local_only) 163 gboolean local_only)
164 { 164 {
165 GSList *l; 165 GSList *l;
166 const char *normalized; 166 const char *normalized;
167 char *name; 167 char *name;
168 GaimBuddy *buddy; 168 PurpleBuddy *buddy;
169 169
170 g_return_val_if_fail(account != NULL, FALSE); 170 g_return_val_if_fail(account != NULL, FALSE);
171 g_return_val_if_fail(who != NULL, FALSE); 171 g_return_val_if_fail(who != NULL, FALSE);
172 172
173 normalized = gaim_normalize(account, who); 173 normalized = purple_normalize(account, who);
174 174
175 for (l = account->deny; l != NULL; l = l->next) { 175 for (l = account->deny; l != NULL; l = l->next) {
176 if (!gaim_utf8_strcasecmp(normalized, (char *)l->data)) 176 if (!purple_utf8_strcasecmp(normalized, (char *)l->data))
177 break; 177 break;
178 } 178 }
179 179
180 buddy = gaim_find_buddy(account, normalized); 180 buddy = purple_find_buddy(account, normalized);
181 181
182 if (l == NULL) 182 if (l == NULL)
183 return FALSE; 183 return FALSE;
184 184
185 name = l->data; 185 name = l->data;
186 account->deny = g_slist_delete_link(account->deny, l); 186 account->deny = g_slist_delete_link(account->deny, l);
187 187
188 if (!local_only && gaim_account_is_connected(account)) 188 if (!local_only && purple_account_is_connected(account))
189 serv_rem_deny(gaim_account_get_connection(account), name); 189 serv_rem_deny(purple_account_get_connection(account), name);
190 190
191 if (privacy_ops != NULL && privacy_ops->deny_removed != NULL) 191 if (privacy_ops != NULL && privacy_ops->deny_removed != NULL)
192 privacy_ops->deny_removed(account, who); 192 privacy_ops->deny_removed(account, who);
193 193
194 if (buddy != NULL) { 194 if (buddy != NULL) {
195 gaim_signal_emit(gaim_blist_get_handle(), 195 purple_signal_emit(purple_blist_get_handle(),
196 "buddy-privacy-changed", buddy); 196 "buddy-privacy-changed", buddy);
197 } 197 }
198 198
199 g_free(name); 199 g_free(name);
200 gaim_blist_schedule_save(); 200 purple_blist_schedule_save();
201 201
202 return TRUE; 202 return TRUE;
203 } 203 }
204 204
205 /* This makes sure that only all the buddies are in the permit list. */ 205 /* This makes sure that only all the buddies are in the permit list. */
206 static void 206 static void
207 add_buddies_in_permit(GaimAccount *account, gboolean local) 207 add_buddies_in_permit(PurpleAccount *account, gboolean local)
208 { 208 {
209 GSList *list, *iter; 209 GSList *list, *iter;
210 /* Remove anyone in the permit list who is not in the buddylist */ 210 /* Remove anyone in the permit list who is not in the buddylist */
211 for (list = account->permit; list != NULL; ) { 211 for (list = account->permit; list != NULL; ) {
212 char *person = list->data; 212 char *person = list->data;
213 list = list->next; 213 list = list->next;
214 if (!gaim_find_buddy(account, person)) 214 if (!purple_find_buddy(account, person))
215 gaim_privacy_permit_remove(account, person, local); 215 purple_privacy_permit_remove(account, person, local);
216 } 216 }
217 /* Now make sure everyone in the buddylist is in the permit list */ 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) { 218 for (iter = list = purple_find_buddies(account, NULL); iter; iter = iter->next) {
219 GaimBuddy *buddy = iter->data; 219 PurpleBuddy *buddy = iter->data;
220 if (!g_slist_find_custom(account->permit, buddy->name, (GCompareFunc)g_utf8_collate)) 220 if (!g_slist_find_custom(account->permit, buddy->name, (GCompareFunc)g_utf8_collate))
221 gaim_privacy_permit_add(account, buddy->name, local); 221 purple_privacy_permit_add(account, buddy->name, local);
222 } 222 }
223 g_slist_free(list); 223 g_slist_free(list);
224 } 224 }
225 225
226 void 226 void
227 gaim_privacy_allow(GaimAccount *account, const char *who, gboolean local, 227 purple_privacy_allow(PurpleAccount *account, const char *who, gboolean local,
228 gboolean restore) 228 gboolean restore)
229 { 229 {
230 GSList *list; 230 GSList *list;
231 231
232 switch (account->perm_deny) { 232 switch (account->perm_deny) {
233 case GAIM_PRIVACY_ALLOW_ALL: 233 case PURPLE_PRIVACY_ALLOW_ALL:
234 return; 234 return;
235 case GAIM_PRIVACY_ALLOW_USERS: 235 case PURPLE_PRIVACY_ALLOW_USERS:
236 gaim_privacy_permit_add(account, who, local); 236 purple_privacy_permit_add(account, who, local);
237 break; 237 break;
238 case GAIM_PRIVACY_DENY_USERS: 238 case PURPLE_PRIVACY_DENY_USERS:
239 gaim_privacy_deny_remove(account, who, local); 239 purple_privacy_deny_remove(account, who, local);
240 break; 240 break;
241 case GAIM_PRIVACY_DENY_ALL: 241 case PURPLE_PRIVACY_DENY_ALL:
242 if (!restore) { 242 if (!restore) {
243 /* Empty the allow-list. */ 243 /* Empty the allow-list. */
244 for (list = account->permit; list != NULL;) { 244 for (list = account->permit; list != NULL;) {
245 char *who = list->data; 245 char *who = list->data;
246 list = list->next; 246 list = list->next;
247 gaim_privacy_permit_remove(account, who, local); 247 purple_privacy_permit_remove(account, who, local);
248 } 248 }
249 } 249 }
250 gaim_privacy_permit_add(account, who, local); 250 purple_privacy_permit_add(account, who, local);
251 account->perm_deny = GAIM_PRIVACY_ALLOW_USERS; 251 account->perm_deny = PURPLE_PRIVACY_ALLOW_USERS;
252 break; 252 break;
253 case GAIM_PRIVACY_ALLOW_BUDDYLIST: 253 case PURPLE_PRIVACY_ALLOW_BUDDYLIST:
254 if (!gaim_find_buddy(account, who)) { 254 if (!purple_find_buddy(account, who)) {
255 add_buddies_in_permit(account, local); 255 add_buddies_in_permit(account, local);
256 gaim_privacy_permit_add(account, who, local); 256 purple_privacy_permit_add(account, who, local);
257 account->perm_deny = GAIM_PRIVACY_ALLOW_USERS; 257 account->perm_deny = PURPLE_PRIVACY_ALLOW_USERS;
258 } 258 }
259 break; 259 break;
260 default: 260 default:
261 g_return_if_reached(); 261 g_return_if_reached();
262 } 262 }
263 } 263 }
264 264
265 void 265 void
266 gaim_privacy_deny(GaimAccount *account, const char *who, gboolean local, 266 purple_privacy_deny(PurpleAccount *account, const char *who, gboolean local,
267 gboolean restore) 267 gboolean restore)
268 { 268 {
269 GSList *list; 269 GSList *list;
270 270
271 switch (account->perm_deny) { 271 switch (account->perm_deny) {
272 case GAIM_PRIVACY_ALLOW_ALL: 272 case PURPLE_PRIVACY_ALLOW_ALL:
273 if (!restore) { 273 if (!restore) {
274 /* Empty the deny-list. */ 274 /* Empty the deny-list. */
275 for (list = account->deny; list != NULL; ) { 275 for (list = account->deny; list != NULL; ) {
276 char *person = list->data; 276 char *person = list->data;
277 list = list->next; 277 list = list->next;
278 gaim_privacy_deny_remove(account, person, local); 278 purple_privacy_deny_remove(account, person, local);
279 } 279 }
280 } 280 }
281 gaim_privacy_deny_add(account, who, local); 281 purple_privacy_deny_add(account, who, local);
282 account->perm_deny = GAIM_PRIVACY_DENY_USERS; 282 account->perm_deny = PURPLE_PRIVACY_DENY_USERS;
283 break; 283 break;
284 case GAIM_PRIVACY_ALLOW_USERS: 284 case PURPLE_PRIVACY_ALLOW_USERS:
285 gaim_privacy_permit_remove(account, who, local); 285 purple_privacy_permit_remove(account, who, local);
286 break; 286 break;
287 case GAIM_PRIVACY_DENY_USERS: 287 case PURPLE_PRIVACY_DENY_USERS:
288 gaim_privacy_deny_add(account, who, local); 288 purple_privacy_deny_add(account, who, local);
289 break; 289 break;
290 case GAIM_PRIVACY_DENY_ALL: 290 case PURPLE_PRIVACY_DENY_ALL:
291 break; 291 break;
292 case GAIM_PRIVACY_ALLOW_BUDDYLIST: 292 case PURPLE_PRIVACY_ALLOW_BUDDYLIST:
293 if (gaim_find_buddy(account, who)) { 293 if (purple_find_buddy(account, who)) {
294 add_buddies_in_permit(account, local); 294 add_buddies_in_permit(account, local);
295 gaim_privacy_permit_remove(account, who, local); 295 purple_privacy_permit_remove(account, who, local);
296 account->perm_deny = GAIM_PRIVACY_ALLOW_USERS; 296 account->perm_deny = PURPLE_PRIVACY_ALLOW_USERS;
297 } 297 }
298 break; 298 break;
299 default: 299 default:
300 g_return_if_reached(); 300 g_return_if_reached();
301 } 301 }
302 } 302 }
303 303
304 gboolean 304 gboolean
305 gaim_privacy_check(GaimAccount *account, const char *who) 305 purple_privacy_check(PurpleAccount *account, const char *who)
306 { 306 {
307 GSList *list; 307 GSList *list;
308 308
309 switch (account->perm_deny) { 309 switch (account->perm_deny) {
310 case GAIM_PRIVACY_ALLOW_ALL: 310 case PURPLE_PRIVACY_ALLOW_ALL:
311 return TRUE; 311 return TRUE;
312 312
313 case GAIM_PRIVACY_DENY_ALL: 313 case PURPLE_PRIVACY_DENY_ALL:
314 return FALSE; 314 return FALSE;
315 315
316 case GAIM_PRIVACY_ALLOW_USERS: 316 case PURPLE_PRIVACY_ALLOW_USERS:
317 who = gaim_normalize(account, who); 317 who = purple_normalize(account, who);
318 for (list=account->permit; list!=NULL; list=list->next) { 318 for (list=account->permit; list!=NULL; list=list->next) {
319 if (!gaim_utf8_strcasecmp(who, (char *)list->data)) 319 if (!purple_utf8_strcasecmp(who, (char *)list->data))
320 return TRUE; 320 return TRUE;
321 } 321 }
322 return FALSE; 322 return FALSE;
323 323
324 case GAIM_PRIVACY_DENY_USERS: 324 case PURPLE_PRIVACY_DENY_USERS:
325 who = gaim_normalize(account, who); 325 who = purple_normalize(account, who);
326 for (list=account->deny; list!=NULL; list=list->next) { 326 for (list=account->deny; list!=NULL; list=list->next) {
327 if (!gaim_utf8_strcasecmp(who, (char *)list->data )) 327 if (!purple_utf8_strcasecmp(who, (char *)list->data ))
328 return FALSE; 328 return FALSE;
329 } 329 }
330 return TRUE; 330 return TRUE;
331 331
332 case GAIM_PRIVACY_ALLOW_BUDDYLIST: 332 case PURPLE_PRIVACY_ALLOW_BUDDYLIST:
333 return (gaim_find_buddy(account, who) != NULL); 333 return (purple_find_buddy(account, who) != NULL);
334 334
335 default: 335 default:
336 g_return_val_if_reached(TRUE); 336 g_return_val_if_reached(TRUE);
337 } 337 }
338 } 338 }
339 339
340 void 340 void
341 gaim_privacy_set_ui_ops(GaimPrivacyUiOps *ops) 341 purple_privacy_set_ui_ops(PurplePrivacyUiOps *ops)
342 { 342 {
343 privacy_ops = ops; 343 privacy_ops = ops;
344 } 344 }
345 345
346 GaimPrivacyUiOps * 346 PurplePrivacyUiOps *
347 gaim_privacy_get_ui_ops(void) 347 purple_privacy_get_ui_ops(void)
348 { 348 {
349 return privacy_ops; 349 return privacy_ops;
350 } 350 }
351 351
352 void 352 void
353 gaim_privacy_init(void) 353 purple_privacy_init(void)
354 { 354 {
355 } 355 }