14192
|
1 /**
|
|
2 * gaim
|
|
3 *
|
|
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.
|
|
7 *
|
|
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
|
|
32 gaim_privacy_permit_add(GaimAccount *account, const char *who,
|
|
33 gboolean local_only)
|
|
34 {
|
|
35 GSList *l;
|
|
36 char *name;
|
|
37 GaimBuddy *buddy;
|
|
38
|
|
39 g_return_val_if_fail(account != NULL, FALSE);
|
|
40 g_return_val_if_fail(who != NULL, FALSE);
|
|
41
|
|
42 name = g_strdup(gaim_normalize(account, who));
|
|
43
|
|
44 for (l = account->permit; l != NULL; l = l->next) {
|
|
45 if (!gaim_utf8_strcasecmp(name, (char *)l->data))
|
|
46 break;
|
|
47 }
|
|
48
|
|
49 if (l != NULL)
|
|
50 {
|
|
51 g_free(name);
|
|
52 return FALSE;
|
|
53 }
|
|
54
|
|
55 account->permit = g_slist_append(account->permit, name);
|
|
56
|
|
57 if (!local_only && gaim_account_is_connected(account))
|
|
58 serv_add_permit(gaim_account_get_connection(account), who);
|
|
59
|
|
60 if (privacy_ops != NULL && privacy_ops->permit_added != NULL)
|
|
61 privacy_ops->permit_added(account, who);
|
|
62
|
|
63 gaim_blist_schedule_save();
|
|
64
|
|
65 /* This lets the UI know a buddy has had its privacy setting changed */
|
|
66 buddy = gaim_find_buddy(account, name);
|
|
67 if (buddy != NULL) {
|
|
68 gaim_signal_emit(gaim_blist_get_handle(),
|
|
69 "buddy-privacy-changed", buddy);
|
|
70 }
|
|
71 return TRUE;
|
|
72 }
|
|
73
|
|
74 gboolean
|
|
75 gaim_privacy_permit_remove(GaimAccount *account, const char *who,
|
|
76 gboolean local_only)
|
|
77 {
|
|
78 GSList *l;
|
14212
|
79 const char *name;
|
14192
|
80 GaimBuddy *buddy;
|
|
81
|
|
82 g_return_val_if_fail(account != NULL, FALSE);
|
|
83 g_return_val_if_fail(who != NULL, FALSE);
|
|
84
|
|
85 name = gaim_normalize(account, who);
|
|
86
|
|
87 for (l = account->permit; l != NULL; l = l->next) {
|
|
88 if (!gaim_utf8_strcasecmp(name, (char *)l->data))
|
|
89 break;
|
|
90 }
|
|
91
|
|
92 if (l == NULL)
|
|
93 return FALSE;
|
|
94
|
|
95 g_free(l->data);
|
|
96 account->permit = g_slist_delete_link(account->permit, l);
|
|
97
|
|
98 if (!local_only && gaim_account_is_connected(account))
|
|
99 serv_rem_permit(gaim_account_get_connection(account), who);
|
|
100
|
|
101 if (privacy_ops != NULL && privacy_ops->permit_removed != NULL)
|
|
102 privacy_ops->permit_removed(account, who);
|
|
103
|
|
104 gaim_blist_schedule_save();
|
|
105
|
|
106 buddy = gaim_find_buddy(account, name);
|
|
107 if (buddy != NULL) {
|
|
108 gaim_signal_emit(gaim_blist_get_handle(),
|
|
109 "buddy-privacy-changed", buddy);
|
|
110 }
|
|
111 return TRUE;
|
|
112 }
|
|
113
|
|
114 gboolean
|
|
115 gaim_privacy_deny_add(GaimAccount *account, const char *who,
|
|
116 gboolean local_only)
|
|
117 {
|
|
118 GSList *l;
|
|
119 char *name;
|
|
120 GaimBuddy *buddy;
|
|
121
|
|
122 g_return_val_if_fail(account != NULL, FALSE);
|
|
123 g_return_val_if_fail(who != NULL, FALSE);
|
|
124
|
|
125 name = g_strdup(gaim_normalize(account, who));
|
|
126
|
|
127 for (l = account->deny; l != NULL; l = l->next) {
|
|
128 if (!gaim_utf8_strcasecmp(name, gaim_normalize(account, (char *)l->data)))
|
|
129 break;
|
|
130 }
|
|
131
|
|
132 if (l != NULL)
|
|
133 {
|
|
134 g_free(name);
|
|
135 return FALSE;
|
|
136 }
|
|
137
|
|
138 account->deny = g_slist_append(account->deny, name);
|
|
139
|
|
140 if (!local_only && gaim_account_is_connected(account))
|
|
141 serv_add_deny(gaim_account_get_connection(account), who);
|
|
142
|
|
143 if (privacy_ops != NULL && privacy_ops->deny_added != NULL)
|
|
144 privacy_ops->deny_added(account, who);
|
|
145
|
|
146 gaim_blist_schedule_save();
|
|
147
|
|
148 buddy = gaim_find_buddy(account, name);
|
|
149 if (buddy != NULL) {
|
|
150 gaim_signal_emit(gaim_blist_get_handle(),
|
|
151 "buddy-privacy-changed", buddy);
|
|
152 }
|
|
153 return TRUE;
|
|
154 }
|
|
155
|
|
156 gboolean
|
|
157 gaim_privacy_deny_remove(GaimAccount *account, const char *who,
|
|
158 gboolean local_only)
|
|
159 {
|
|
160 GSList *l;
|
14212
|
161 const char *normalized;
|
14192
|
162 char *name;
|
|
163 GaimBuddy *buddy;
|
|
164
|
|
165 g_return_val_if_fail(account != NULL, FALSE);
|
|
166 g_return_val_if_fail(who != NULL, FALSE);
|
|
167
|
14212
|
168 normalized = gaim_normalize(account, who);
|
14192
|
169
|
|
170 for (l = account->deny; l != NULL; l = l->next) {
|
14212
|
171 if (!gaim_utf8_strcasecmp(normalized, (char *)l->data))
|
14192
|
172 break;
|
|
173 }
|
|
174
|
14212
|
175 buddy = gaim_find_buddy(account, normalized);
|
14192
|
176
|
|
177 if (l == NULL)
|
|
178 return FALSE;
|
|
179
|
|
180 name = l->data;
|
|
181 account->deny = g_slist_delete_link(account->deny, l);
|
|
182
|
|
183 if (!local_only && gaim_account_is_connected(account))
|
|
184 serv_rem_deny(gaim_account_get_connection(account), name);
|
|
185
|
|
186 if (privacy_ops != NULL && privacy_ops->deny_removed != NULL)
|
|
187 privacy_ops->deny_removed(account, who);
|
|
188
|
|
189 if (buddy != NULL) {
|
|
190 gaim_signal_emit(gaim_blist_get_handle(),
|
|
191 "buddy-privacy-changed", buddy);
|
|
192 }
|
|
193
|
|
194 g_free(name);
|
|
195 gaim_blist_schedule_save();
|
|
196
|
|
197 return TRUE;
|
|
198 }
|
|
199
|
|
200 gboolean
|
|
201 gaim_privacy_check(GaimAccount *account, const char *who)
|
|
202 {
|
|
203 GSList *list;
|
|
204
|
|
205 switch (account->perm_deny) {
|
|
206 case GAIM_PRIVACY_ALLOW_ALL:
|
|
207 return TRUE;
|
|
208
|
|
209 case GAIM_PRIVACY_DENY_ALL:
|
|
210 return FALSE;
|
|
211
|
|
212 case GAIM_PRIVACY_ALLOW_USERS:
|
|
213 who = gaim_normalize(account, who);
|
|
214 for (list=account->permit; list!=NULL; list=list->next) {
|
|
215 if (!gaim_utf8_strcasecmp(who, (char *)list->data))
|
|
216 return TRUE;
|
|
217 }
|
|
218 return FALSE;
|
|
219
|
|
220 case GAIM_PRIVACY_DENY_USERS:
|
|
221 who = gaim_normalize(account, who);
|
|
222 for (list=account->deny; list!=NULL; list=list->next) {
|
|
223 if (!gaim_utf8_strcasecmp(who, (char *)list->data ))
|
|
224 return FALSE;
|
|
225 }
|
|
226 return TRUE;
|
|
227
|
|
228 case GAIM_PRIVACY_ALLOW_BUDDYLIST:
|
|
229 return (gaim_find_buddy(account, who) != NULL);
|
|
230
|
|
231 default:
|
|
232 g_return_val_if_reached(TRUE);
|
|
233 }
|
|
234 }
|
|
235
|
|
236 void
|
|
237 gaim_privacy_set_ui_ops(GaimPrivacyUiOps *ops)
|
|
238 {
|
|
239 privacy_ops = ops;
|
|
240 }
|
|
241
|
|
242 GaimPrivacyUiOps *
|
|
243 gaim_privacy_get_ui_ops(void)
|
|
244 {
|
|
245 return privacy_ops;
|
|
246 }
|
|
247
|
|
248 void
|
|
249 gaim_privacy_init(void)
|
|
250 {
|
|
251 }
|