Mercurial > pidgin
annotate src/list.c @ 4375:90eaa3486949
[gaim-migrate @ 4641]
Fixed the problem where changing themes would crash gaim.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Tue, 21 Jan 2003 05:12:53 +0000 |
parents | d0cef2cc9660 |
children | 16f7f9451814 |
rev | line source |
---|---|
2382 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 #include <config.h> | |
24 #endif | |
25 #include <string.h> | |
4349 | 26 #include <stdlib.h> |
2382 | 27 #include <sys/types.h> |
28 #include <sys/stat.h> | |
3630 | 29 #ifndef _WIN32 |
2382 | 30 #include <unistd.h> |
3630 | 31 #else |
32 #include <direct.h> | |
33 #endif | |
4349 | 34 #include <ctype.h> |
2382 | 35 #include "gaim.h" |
36 #include "prpl.h" | |
37 | |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
38 #ifdef _WIN32 |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
39 #include "win32dep.h" |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
40 #endif |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
41 |
2382 | 42 #define PATHSIZE 1024 |
43 | |
4349 | 44 void remove_buddy(struct buddy *rem_b) |
2382 | 45 { |
4349 | 46 if(rem_b->user->gc) { |
47 struct group *rem_g = find_group_by_buddy(rem_b); | |
2382 | 48 |
4349 | 49 ui_remove_buddy(rem_b); |
2382 | 50 |
4349 | 51 rem_g->members = g_slist_remove(rem_g->members, rem_b); |
2382 | 52 |
4349 | 53 g_hash_table_destroy(rem_b->settings); |
2382 | 54 |
4349 | 55 g_free(rem_b); |
56 } else { | |
57 char *buf = g_strdup_printf(_("%s was not removed from your buddy " | |
58 "list, because your account (%s) is not logged in."), | |
59 rem_b->name, rem_b->user->username); | |
60 do_error_dialog(_("Buddy Not Removed"), buf, GAIM_ERROR); | |
61 g_free(buf); | |
62 } | |
2382 | 63 } |
64 | |
4349 | 65 void remove_group(struct group *rem_g) |
2382 | 66 { |
4349 | 67 GSList *users; |
2382 | 68 |
4349 | 69 for(users = aim_users; users; users = users->next) { |
70 struct aim_user *user = users->data; | |
71 if(user->gc) { | |
72 GList *tmp = NULL; | |
73 GSList *buds = rem_g->members; | |
74 | |
75 while (buds) { | |
76 struct buddy *delb = (struct buddy *)buds->data; | |
77 buds = buds->next; | |
2382 | 78 |
4349 | 79 if(delb->user == user) { |
80 tmp = g_list_append(tmp, g_strdup(delb->name)); | |
81 remove_buddy(delb); /* this should take care of removing | |
82 the group_show if necessary */ | |
83 } | |
84 } | |
2382 | 85 |
4349 | 86 if(tmp) |
87 serv_remove_buddies(user->gc, tmp, rem_g->name); | |
2382 | 88 |
4349 | 89 while (tmp) { |
90 g_free(tmp->data); | |
91 tmp = g_list_remove(tmp, tmp->data); | |
92 } | |
93 } | |
2382 | 94 } |
95 | |
4349 | 96 if(rem_g->members) { |
97 char *buf = g_strdup_printf(_("%d buddies from group %s were not " | |
98 "removed because their accounts were not logged in. These " | |
99 "buddies, and the group were not removed.\n"), | |
100 g_slist_length(rem_g->members), rem_g->name); | |
101 do_error_dialog(_("Group Not Removed"), buf, GAIM_ERROR); | |
102 g_free(buf); | |
2382 | 103 |
4349 | 104 return; |
2382 | 105 } |
106 | |
4349 | 107 ui_remove_group(rem_g); |
108 | |
109 groups = g_slist_remove(groups, rem_g); | |
2382 | 110 |
111 g_free(rem_g); | |
112 | |
113 /* don't flush buddy list to cache in order to be consistent with remove_buddy, | |
114 * mostly. remove_group is only called from one place, so we'll let it handle it. */ | |
115 } | |
116 | |
4349 | 117 struct buddy *add_buddy(struct aim_user *user, const char *group, const char *buddy, const char *show) |
2382 | 118 { |
119 struct buddy *b; | |
120 struct group *g; | |
3466 | 121 const char *good; |
2382 | 122 |
4349 | 123 if ((b = find_buddy(user, buddy)) != NULL) |
2382 | 124 return b; |
125 | |
4349 | 126 g = find_group(group); |
2382 | 127 |
128 if (g == NULL) | |
4349 | 129 g = add_group(group); |
2382 | 130 |
131 b = (struct buddy *)g_new0(struct buddy, 1); | |
132 | |
133 if (!b) | |
134 return NULL; | |
135 | |
4349 | 136 b->user = user; |
2382 | 137 b->present = 0; |
138 | |
4349 | 139 b->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
140 | |
141 good = buddy; | |
2382 | 142 |
143 g_snprintf(b->name, sizeof(b->name), "%s", good); | |
4227 | 144 if(show && show[0]) |
145 g_snprintf(b->alias, sizeof(b->alias), "%s", show); | |
146 else | |
147 b->alias[0] = '\0'; | |
2382 | 148 |
149 g->members = g_slist_append(g->members, b); | |
150 | |
151 b->idle = 0; | |
152 b->caps = 0; | |
153 | |
4349 | 154 ui_add_buddy(user->gc, g, b); |
2382 | 155 |
156 return b; | |
157 } | |
158 | |
4349 | 159 struct group *add_group(const char *group) |
2382 | 160 { |
4349 | 161 struct group *g = find_group(group); |
2382 | 162 if (g) |
163 return g; | |
164 g = (struct group *)g_new0(struct group, 1); | |
165 if (!g) | |
166 return NULL; | |
167 | |
168 strncpy(g->name, group, sizeof(g->name)); | |
4349 | 169 groups = g_slist_append(groups, g); |
2382 | 170 |
171 g->members = NULL; | |
172 | |
4349 | 173 ui_add_group(g); |
2382 | 174 |
175 return g; | |
176 } | |
177 | |
4349 | 178 struct group *find_group(const char *group) |
2382 | 179 { |
180 struct group *g; | |
181 GSList *grp; | |
4349 | 182 char *grpname = g_strdup(normalize(group)); |
2382 | 183 |
4349 | 184 grp = groups; |
185 while (grp) { | |
186 g = (struct group *)grp->data; | |
187 if (!g_strcasecmp(normalize (g->name), grpname)) { | |
188 g_free(grpname); | |
189 return g; | |
2382 | 190 } |
4349 | 191 grp = g_slist_next(grp); |
2382 | 192 } |
4349 | 193 g_free(grpname); |
194 return NULL; | |
2382 | 195 } |
196 | |
4349 | 197 struct group *find_group_by_buddy(struct buddy *b) |
198 { | |
199 GSList *grp = groups; | |
200 | |
201 while(grp) { | |
202 struct group *g = grp->data; | |
203 if(g_slist_find(g->members, b)) | |
204 return g; | |
205 grp = grp->next; | |
206 } | |
207 return NULL; | |
208 } | |
209 | |
210 struct buddy *find_buddy(struct aim_user *user, const char *who) | |
2382 | 211 { |
212 struct group *g; | |
213 struct buddy *b; | |
214 GSList *grp; | |
215 GSList *mem; | |
4349 | 216 char *whoname = NULL; |
2382 | 217 char *(*norm)(const char *); |
218 | |
4349 | 219 grp = groups; |
220 while (grp) { | |
221 g = (struct group *)grp->data; | |
2382 | 222 |
4349 | 223 mem = g->members; |
224 while (mem) { | |
225 b = (struct buddy *)mem->data; | |
226 /* | |
227 norm = (b->user->gc && b->user->gc->prpl->normalize) ? b->user->gc->prpl->normalize : normalize; | |
228 */ | |
229 norm = normalize; | |
230 whoname = g_strdup(norm(who)); | |
231 if ((b->user == user || !user) && !strcmp(norm(b->name), whoname)) { | |
232 g_free(whoname); | |
233 return b; | |
2382 | 234 } |
4349 | 235 g_free(whoname); |
236 mem = mem->next; | |
2382 | 237 } |
4349 | 238 grp = g_slist_next(grp); |
2382 | 239 } |
4349 | 240 return NULL; |
2382 | 241 } |
242 | |
4349 | 243 void parse_toc_buddy_list(struct aim_user *user, char *config) |
2382 | 244 { |
245 char *c; | |
246 char current[256]; | |
4351 | 247 GList *bud = NULL; |
4349 | 248 |
2382 | 249 |
250 if (config != NULL) { | |
4349 | 251 |
2382 | 252 /* skip "CONFIG:" (if it exists) */ |
253 c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
2998 | 254 strtok(config, "\n") : |
255 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
2382 | 256 do { |
257 if (c == NULL) | |
258 break; | |
259 if (*c == 'g') { | |
260 strncpy(current, c + 2, sizeof(current)); | |
4349 | 261 if (!find_group(current)) { |
262 add_group(current); | |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
263 } |
4349 | 264 } else if (*c == 'b' && !find_buddy(user, c + 2)) { |
3136 | 265 char nm[80], sw[BUDDY_ALIAS_MAXLEN], *tmp = c + 2; |
2382 | 266 int i = 0; |
2998 | 267 while (*tmp != ':' && *tmp && i < sizeof(nm) - 1) |
268 nm[i++] = *tmp++; | |
4349 | 269 |
2382 | 270 while (*tmp != ':' && *tmp) |
3048 | 271 tmp++; |
4349 | 272 |
2382 | 273 if (*tmp == ':') |
274 *tmp++ = '\0'; | |
4349 | 275 |
2382 | 276 nm[i] = '\0'; |
277 i = 0; | |
2998 | 278 while (*tmp && i < sizeof(sw) - 1) |
2382 | 279 sw[i++] = *tmp++; |
280 sw[i] = '\0'; | |
4349 | 281 if (!find_buddy(user, nm)) { |
282 add_buddy(user, current, nm, sw); | |
4351 | 283 bud = g_list_append(bud, c + 2); |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
284 } |
2382 | 285 } else if (*c == 'p') { |
4349 | 286 gaim_privacy_permit_add(user, c + 2); |
2382 | 287 } else if (*c == 'd') { |
4349 | 288 gaim_privacy_deny_add(user, c + 2); |
2382 | 289 } else if (!strncmp("toc", c, 3)) { |
4349 | 290 sscanf(c + strlen(c) - 1, "%d", &user->permdeny); |
291 debug_printf("permdeny: %d\n", user->permdeny); | |
292 if (user->permdeny == 0) | |
293 user->permdeny = 1; | |
2382 | 294 } else if (*c == 'm') { |
4349 | 295 sscanf(c + 2, "%d", &user->permdeny); |
296 debug_printf("permdeny: %d\n", user->permdeny); | |
297 if (user->permdeny == 0) | |
298 user->permdeny = 1; | |
2382 | 299 } |
300 } while ((c = strtok(NULL, "\n"))); | |
4351 | 301 |
302 if(user->gc) { | |
303 if(bud) | |
304 serv_add_buddies(user->gc, bud); | |
305 serv_set_permit_deny(user->gc); | |
306 } | |
307 g_list_free(bud); | |
2382 | 308 } |
309 } | |
310 | |
4349 | 311 void toc_build_config(struct aim_user *user, char *s, int len, gboolean show) |
2382 | 312 { |
4349 | 313 GSList *grp = groups; |
2382 | 314 GSList *mem; |
315 struct group *g; | |
316 struct buddy *b; | |
4349 | 317 GSList *plist = user->permit; |
318 GSList *dlist = user->deny; | |
2382 | 319 |
320 int pos = 0; | |
321 | |
4349 | 322 if (!user->permdeny) |
323 user->permdeny = 1; | |
2382 | 324 |
4349 | 325 pos += g_snprintf(&s[pos], len - pos, "m %d\n", user->permdeny); |
2382 | 326 while (len > pos && grp) { |
327 g = (struct group *)grp->data; | |
4349 | 328 if(gaim_group_on_account(g, user)) { |
329 pos += g_snprintf(&s[pos], len - pos, "g %s\n", g->name); | |
330 mem = g->members; | |
331 while (len > pos && mem) { | |
332 b = (struct buddy *)mem->data; | |
333 if(b->user == user) { | |
334 pos += g_snprintf(&s[pos], len - pos, "b %s%s%s\n", b->name, | |
335 (show && b->alias[0]) ? ":" : "", | |
336 (show && b->alias[0]) ? b->alias : ""); | |
337 } | |
338 mem = mem->next; | |
339 } | |
2382 | 340 } |
341 grp = g_slist_next(grp); | |
342 } | |
343 | |
344 while (len > pos && plist) { | |
345 pos += g_snprintf(&s[pos], len - pos, "p %s\n", (char *)plist->data); | |
346 plist = plist->next; | |
347 } | |
348 | |
349 while (len > pos && dlist) { | |
350 pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data); | |
351 dlist = dlist->next; | |
352 } | |
353 } | |
354 | |
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
355 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
356 static GString *translate_lst(FILE *src_fp) |
2382 | 357 { |
358 char line[BUF_LEN], *line2; | |
359 char *name; | |
360 int i; | |
361 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
362 GString *dest = g_string_new("m 1\n"); |
2382 | 363 |
364 while (fgets(line, BUF_LEN, src_fp)) { | |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
365 line2 = g_strchug(line); |
2382 | 366 if (strstr(line2, "group") == line2) { |
367 name = strpbrk(line2, " \t\n\r\f") + 1; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
368 dest = g_string_append(dest, "g "); |
2382 | 369 for (i = 0; i < strcspn(name, "\n\r"); i++) |
370 if (name[i] != '\"') | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
371 dest = g_string_append_c(dest, name[i]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
372 dest = g_string_append_c(dest, '\n'); |
2382 | 373 } |
374 if (strstr(line2, "buddy") == line2) { | |
375 name = strpbrk(line2, " \t\n\r\f") + 1; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
376 dest = g_string_append(dest, "b "); |
2382 | 377 for (i = 0; i < strcspn(name, "\n\r"); i++) |
378 if (name[i] != '\"') | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
379 dest = g_string_append_c(dest, name[i]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
380 dest = g_string_append_c(dest, '\n'); |
2382 | 381 } |
382 } | |
383 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
384 return dest; |
2382 | 385 } |
386 | |
387 | |
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
388 /* translate an AIM 4 buddylist (*.blt) to Gaim format */ |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
389 static GString *translate_blt(FILE *src_fp) |
2382 | 390 { |
391 int i; | |
392 char line[BUF_LEN]; | |
393 char *buddy; | |
394 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
395 GString *dest = g_string_new("m 1\n"); |
2382 | 396 |
397 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
398 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
399 | |
400 while (1) { | |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
401 fgets(line, BUF_LEN, src_fp); g_strchomp(line); |
2382 | 402 if (strchr(line, '}') != NULL) |
403 break; | |
404 | |
405 if (strchr(line, '{') != NULL) { | |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
406 /* Syntax starting with "<group> {" */ |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
407 |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
408 dest = g_string_append(dest, "g "); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
409 buddy = g_strchug(strtok(line, "{")); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
410 for (i = 0; i < strlen(buddy); i++) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
411 if (buddy[i] != '\"') |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
412 dest = g_string_append_c(dest, buddy[i]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
413 dest = g_string_append_c(dest, '\n'); |
2382 | 414 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
415 gboolean pounce = FALSE; |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
416 char *e; |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
417 g_strchomp(line); |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
418 buddy = g_strchug(line); |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
419 debug_printf("\nbuddy: \"%s\"\n\n", buddy); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
420 dest = g_string_append(dest, "b "); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
421 if (strchr(buddy, '{') != NULL) { |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
422 /* buddy pounce, etc */ |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
423 char *pos = strchr(buddy, '{') - 1; |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
424 *pos = 0; |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
425 pounce = TRUE; |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
426 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
427 if ((e = strchr(buddy, '\"')) != NULL) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
428 *e = '\0'; |
2382 | 429 buddy++; |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
430 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
431 dest = g_string_append(dest, buddy); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
432 dest = g_string_append_c(dest, '\n'); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
433 if (pounce) |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
434 do |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
435 fgets(line, BUF_LEN, src_fp); |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
436 while (!strchr(line, '}')); |
2382 | 437 } |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
438 } else { |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
439 |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
440 /* Syntax "group buddy buddy ..." */ |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
441 buddy = g_strchug(strtok(line, " \n")); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
442 dest = g_string_append(dest, "g "); |
2382 | 443 if (strchr(buddy, '\"') != NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
444 dest = g_string_append(dest, &buddy[1]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
445 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
446 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 447 while (strchr(buddy, '\"') == NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
448 dest = g_string_append(dest, buddy); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
449 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
450 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 451 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
452 buddy[strlen(buddy) - 1] = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
453 dest = g_string_append(dest, buddy); |
2382 | 454 } else { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
455 dest = g_string_append(dest, buddy); |
2382 | 456 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
457 dest = g_string_append_c(dest, '\n'); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
458 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
459 dest = g_string_append(dest, "b "); |
2382 | 460 if (strchr(buddy, '\"') != NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
461 dest = g_string_append(dest, &buddy[1]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
462 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
463 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 464 while (strchr(buddy, '\"') == NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
465 dest = g_string_append(dest, buddy); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
466 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
467 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 468 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
469 buddy[strlen(buddy) - 1] = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
470 dest = g_string_append(dest, buddy); |
2382 | 471 } else { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
472 dest = g_string_append(dest, buddy); |
2382 | 473 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
474 dest = g_string_append_c(dest, '\n'); |
2382 | 475 } |
476 } | |
477 } | |
478 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
479 return dest; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
480 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
481 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
482 static GString *translate_gnomeicu(FILE *src_fp) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
483 { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
484 char line[BUF_LEN]; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
485 GString *dest = g_string_new("m 1\ng Buddies\n"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
486 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
487 while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
488 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
489 while (fgets(line, BUF_LEN, src_fp)) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
490 char *eq; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
491 g_strchomp(line); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
492 if (line[0] == '\n' || line[0] == '[') |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
493 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
494 eq = strchr(line, '='); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
495 if (!eq) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
496 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
497 *eq = ':'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
498 eq = strchr(eq, ','); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
499 if (eq) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
500 *eq = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
501 dest = g_string_append(dest, "b "); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
502 dest = g_string_append(dest, line); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
503 dest = g_string_append_c(dest, '\n'); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
504 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
505 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
506 return dest; |
2382 | 507 } |
508 | |
509 static gchar *get_screenname_filename(const char *name) | |
510 { | |
511 gchar **split; | |
512 gchar *good; | |
513 | |
514 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
515 good = g_strjoinv(NULL, split); | |
516 g_strfreev(split); | |
517 | |
518 g_strup(good); | |
519 | |
520 return good; | |
521 } | |
522 | |
4349 | 523 static gboolean gaim_blist_read(const char *filename); |
2382 | 524 |
4349 | 525 void do_import(struct aim_user *user, const char *filename) |
2382 | 526 { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
527 GString *buf = NULL; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
528 char first[64]; |
2382 | 529 char path[PATHSIZE]; |
530 int len; | |
531 FILE *f; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
532 struct stat st; |
2382 | 533 |
534 if (filename) { | |
535 g_snprintf(path, sizeof(path), "%s", filename); | |
536 } else { | |
4349 | 537 char *g_screenname = get_screenname_filename(user->username); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
538 char *file = gaim_user_dir(); |
4349 | 539 int protocol = (user->protocol == PROTO_OSCAR) ? (isalpha(user->username[0]) ? PROTO_TOC : PROTO_ICQ): user->protocol; |
2382 | 540 |
541 if (file != (char *)NULL) { | |
4349 | 542 sprintf(path, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
2382 | 543 g_free(g_screenname); |
544 } else { | |
545 g_free(g_screenname); | |
546 return; | |
547 } | |
548 } | |
549 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
550 if (stat(path, &st)) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
551 debug_printf("Unable to stat %s.\n", path); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
552 return; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
553 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
554 |
2382 | 555 if (!(f = fopen(path, "r"))) { |
556 debug_printf("Unable to open %s.\n", path); | |
557 return; | |
558 } | |
559 | |
560 fgets(first, 64, f); | |
561 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
562 if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
563 fgets(first, 64, f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
564 |
4349 | 565 if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { |
566 /* new gaim XML buddy list */ | |
567 gaim_blist_read(path); | |
568 } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
569 /* AIM 4 buddy list */ |
2382 | 570 debug_printf("aim 4\n"); |
571 rewind(f); | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
572 buf = translate_blt(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
573 } else if (strstr(first, "group") != NULL) { |
2382 | 574 /* AIM 3 buddy list */ |
575 debug_printf("aim 3\n"); | |
576 rewind(f); | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
577 buf = translate_lst(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
578 } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
579 /* GnomeICU (hopefully) */ |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
580 debug_printf("gnomeicu\n"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
581 rewind(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
582 buf = translate_gnomeicu(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
583 } else if (first[0] == 'm') { |
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
584 /* Gaim buddy list - no translation */ |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
585 char buf2[BUF_LONG * 2]; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
586 buf = g_string_new(""); |
2382 | 587 rewind(f); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
588 while (1) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
589 len = fread(buf2, 1, BUF_LONG * 2 - 1, f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
590 if (len <= 0) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
591 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
592 buf2[len] = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
593 buf = g_string_append(buf, buf2); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
594 if (len != BUF_LONG * 2 - 1) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
595 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
596 } |
2382 | 597 } |
598 | |
599 fclose(f); | |
600 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
601 if (buf) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
602 buf = g_string_prepend(buf, "toc_set_config {"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
603 buf = g_string_append(buf, "}\n"); |
4349 | 604 parse_toc_buddy_list(user, buf->str); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
605 g_string_free(buf, TRUE); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
606 } |
2382 | 607 } |
608 | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
609 static gboolean is_blocked(struct buddy *b) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
610 { |
4349 | 611 struct aim_user *user = b->user; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
612 |
4349 | 613 if (user->permdeny == PERMIT_ALL) |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
614 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
615 |
4349 | 616 if (user->permdeny == PERMIT_NONE) { |
617 if (user->gc && g_strcasecmp(b->name, user->gc->username)) | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
618 return TRUE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
619 else |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
620 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
621 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
622 |
4349 | 623 if (user->permdeny == PERMIT_SOME) { |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
624 char *x = g_strdup(normalize(b->name)); |
4349 | 625 GSList *s = user->permit; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
626 while (s) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
627 if (!g_strcasecmp(x, normalize(s->data))) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
628 break; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
629 s = s->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
630 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
631 g_free(x); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
632 if (s) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
633 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
634 return TRUE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
635 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
636 |
4349 | 637 if (user->permdeny == DENY_SOME) { |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
638 char *x = g_strdup(normalize(b->name)); |
4349 | 639 GSList *s = user->deny; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
640 while (s) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
641 if (!g_strcasecmp(x, normalize(s->data))) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
642 break; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
643 s = s->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
644 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
645 g_free(x); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
646 if (s) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
647 return TRUE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
648 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
649 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
650 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
651 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
652 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
653 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
654 void signoff_blocked(struct gaim_connection *gc) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
655 { |
4349 | 656 GSList *g = groups; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
657 while (g) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
658 GSList *m = ((struct group *)g->data)->members; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
659 while (m) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
660 struct buddy *b = m->data; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
661 if (is_blocked(b)) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
662 serv_got_update(gc, b->name, 0, 0, 0, 0, 0, 0); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
663 m = m->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
664 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
665 g = g->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
666 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
667 } |
4227 | 668 |
669 char *get_buddy_alias_only(struct buddy *b) { | |
670 if(!b) | |
671 return NULL; | |
672 if(b->alias[0]) | |
673 return b->alias; | |
674 else if((misc_options & OPT_MISC_USE_SERVER_ALIAS) && b->server_alias[0]) | |
675 return b->server_alias; | |
676 return NULL; | |
677 } | |
678 | |
679 | |
680 char *get_buddy_alias(struct buddy *b) { | |
681 char *ret = get_buddy_alias_only(b); | |
682 if(!ret) | |
683 return b ? b->name : _("Unknown"); | |
684 return ret; | |
685 } | |
686 | |
4349 | 687 GSList *gaim_group_get_accounts(struct group *g) { |
688 GSList *buds = g->members; | |
689 GSList *ret = NULL; | |
690 while(buds) { | |
691 struct buddy *b = buds->data; | |
692 if(!g_slist_find(ret, b->user)) | |
693 ret = g_slist_append(ret, b->user); | |
694 buds = buds->next; | |
695 } | |
696 return ret; | |
697 } | |
698 | |
699 gboolean gaim_group_on_account(struct group *g, struct aim_user *user) { | |
700 GSList *buds = g->members; | |
701 while(buds) { | |
702 struct buddy *b = buds->data; | |
703 if((!user && b->user->gc) || b->user == user) | |
704 return TRUE; | |
705 buds = buds->next; | |
706 } | |
707 return FALSE; | |
708 } | |
709 | |
710 | |
711 static char *blist_parser_group_name = NULL; | |
712 static char *blist_parser_person_name = NULL; | |
713 static char *blist_parser_account_name = NULL; | |
714 static int blist_parser_account_protocol = 0; | |
715 static char *blist_parser_buddy_name = NULL; | |
716 static char *blist_parser_buddy_alias = NULL; | |
717 static char *blist_parser_setting_name = NULL; | |
718 static char *blist_parser_setting_value = NULL; | |
719 static GHashTable *blist_parser_buddy_settings = NULL; | |
720 static int blist_parser_privacy_mode = 0; | |
721 static enum { | |
722 BLIST_TAG_GAIM, | |
723 BLIST_TAG_BLIST, | |
724 BLIST_TAG_GROUP, | |
725 BLIST_TAG_PERSON, | |
726 BLIST_TAG_BUDDY, | |
727 BLIST_TAG_NAME, | |
728 BLIST_TAG_ALIAS, | |
729 BLIST_TAG_SETTING, | |
730 BLIST_TAG_PRIVACY, | |
731 BLIST_TAG_ACCOUNT, | |
732 BLIST_TAG_PERMIT, | |
733 BLIST_TAG_BLOCK, | |
734 BLIST_TAG_IGNORE | |
735 } blist_parser_current_tag; | |
736 | |
737 static void blist_start_element_handler (GMarkupParseContext *context, | |
738 const gchar *element_name, | |
739 const gchar **attribute_names, | |
740 const gchar **attribute_values, | |
741 gpointer user_data, | |
742 GError **error) { | |
743 int i; | |
744 | |
745 if(!strcmp(element_name, "gaim")) { | |
746 blist_parser_current_tag = BLIST_TAG_GAIM; | |
747 } else if(!strcmp(element_name, "blist")) { | |
748 blist_parser_current_tag = BLIST_TAG_BLIST; | |
749 } else if(!strcmp(element_name, "group")) { | |
750 blist_parser_current_tag = BLIST_TAG_GROUP; | |
751 for(i=0; attribute_names[i]; i++) { | |
752 if(!strcmp(attribute_names[i], "name")) | |
753 blist_parser_group_name = g_strdup(attribute_values[i]); | |
754 } | |
755 if(blist_parser_group_name) { | |
756 add_group(blist_parser_group_name); | |
757 } | |
758 } else if(!strcmp(element_name, "person")) { | |
759 blist_parser_current_tag = BLIST_TAG_PERSON; | |
760 for(i=0; attribute_names[i]; i++) { | |
761 if(!strcmp(attribute_names[i], "name")) | |
762 blist_parser_person_name = g_strdup(attribute_values[i]); | |
763 } | |
764 } else if(!strcmp(element_name, "buddy")) { | |
765 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
766 for(i=0; attribute_names[i]; i++) { | |
767 if(!strcmp(attribute_names[i], "account")) | |
768 blist_parser_account_name = g_strdup(attribute_values[i]); | |
769 else if(!strcmp(attribute_names[i], "protocol")) | |
770 blist_parser_account_protocol = atoi(attribute_values[i]); | |
771 } | |
772 } else if(!strcmp(element_name, "name")) { | |
773 blist_parser_current_tag = BLIST_TAG_NAME; | |
774 } else if(!strcmp(element_name, "alias")) { | |
775 blist_parser_current_tag = BLIST_TAG_ALIAS; | |
776 } else if(!strcmp(element_name, "setting")) { | |
777 blist_parser_current_tag = BLIST_TAG_SETTING; | |
778 for(i=0; attribute_names[i]; i++) { | |
779 if(!strcmp(attribute_names[i], "name")) | |
780 blist_parser_setting_name = g_strdup(attribute_values[i]); | |
781 } | |
782 } else if(!strcmp(element_name, "privacy")) { | |
783 blist_parser_current_tag = BLIST_TAG_PRIVACY; | |
784 } else if(!strcmp(element_name, "account")) { | |
785 blist_parser_current_tag = BLIST_TAG_ACCOUNT; | |
786 for(i=0; attribute_names[i]; i++) { | |
787 if(!strcmp(attribute_names[i], "protocol")) | |
788 blist_parser_account_protocol = atoi(attribute_values[i]); | |
789 else if(!strcmp(attribute_names[i], "mode")) | |
790 blist_parser_privacy_mode = atoi(attribute_values[i]); | |
791 else if(!strcmp(attribute_names[i], "name")) | |
792 blist_parser_account_name = g_strdup(attribute_values[i]); | |
793 } | |
794 } else if(!strcmp(element_name, "permit")) { | |
795 blist_parser_current_tag = BLIST_TAG_PERMIT; | |
796 } else if(!strcmp(element_name, "block")) { | |
797 blist_parser_current_tag = BLIST_TAG_BLOCK; | |
798 } else if(!strcmp(element_name, "ignore")) { | |
799 blist_parser_current_tag = BLIST_TAG_IGNORE; | |
800 } | |
801 } | |
802 | |
803 static void blist_end_element_handler(GMarkupParseContext *context, | |
804 const gchar *element_name, gpointer user_data, GError **error) { | |
805 if(!strcmp(element_name, "gaim")) { | |
806 } else if(!strcmp(element_name, "blist")) { | |
807 blist_parser_current_tag = BLIST_TAG_GAIM; | |
808 } else if(!strcmp(element_name, "group")) { | |
809 blist_parser_current_tag = BLIST_TAG_BLIST; | |
810 } else if(!strcmp(element_name, "person")) { | |
811 blist_parser_current_tag = BLIST_TAG_GROUP; | |
812 g_free(blist_parser_person_name); | |
813 blist_parser_person_name = NULL; | |
814 } else if(!strcmp(element_name, "buddy")) { | |
815 struct aim_user *user = find_user(blist_parser_account_name, | |
816 blist_parser_account_protocol); | |
817 if(user) { | |
818 struct buddy *b = add_buddy(user, blist_parser_group_name, | |
819 blist_parser_buddy_name, blist_parser_buddy_alias); | |
820 if(blist_parser_buddy_settings) { | |
821 g_hash_table_destroy(b->settings); | |
822 b->settings = blist_parser_buddy_settings; | |
823 } | |
824 } | |
825 blist_parser_current_tag = BLIST_TAG_PERSON; | |
826 g_free(blist_parser_buddy_name); | |
827 blist_parser_buddy_name = NULL; | |
828 g_free(blist_parser_buddy_alias); | |
829 blist_parser_buddy_alias = NULL; | |
830 g_free(blist_parser_account_name); | |
831 blist_parser_account_name = NULL; | |
832 blist_parser_buddy_settings = NULL; | |
833 } else if(!strcmp(element_name, "name")) { | |
834 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
835 } else if(!strcmp(element_name, "alias")) { | |
836 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
837 } else if(!strcmp(element_name, "setting")) { | |
838 if(!blist_parser_buddy_settings) | |
839 blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash, | |
840 g_str_equal, g_free, g_free); | |
841 if(blist_parser_setting_name && blist_parser_setting_value) { | |
842 g_hash_table_replace(blist_parser_buddy_settings, | |
843 g_strdup(blist_parser_setting_name), | |
844 g_strdup(blist_parser_setting_value)); | |
845 } | |
846 g_free(blist_parser_setting_name); | |
847 g_free(blist_parser_setting_value); | |
848 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
849 } else if(!strcmp(element_name, "privacy")) { | |
850 blist_parser_current_tag = BLIST_TAG_GAIM; | |
851 } else if(!strcmp(element_name, "account")) { | |
852 struct aim_user *user = find_user(blist_parser_account_name, | |
853 blist_parser_account_protocol); | |
854 if(user) { | |
855 user->permdeny = blist_parser_privacy_mode; | |
856 } | |
857 blist_parser_current_tag = BLIST_TAG_PRIVACY; | |
858 g_free(blist_parser_account_name); | |
859 blist_parser_account_name = NULL; | |
860 } else if(!strcmp(element_name, "permit")) { | |
861 struct aim_user *user = find_user(blist_parser_account_name, | |
862 blist_parser_account_protocol); | |
863 if(user) { | |
864 gaim_privacy_permit_add(user, blist_parser_buddy_name); | |
865 } | |
866 blist_parser_current_tag = BLIST_TAG_ACCOUNT; | |
867 } else if(!strcmp(element_name, "block")) { | |
868 struct aim_user *user = find_user(blist_parser_account_name, | |
869 blist_parser_account_protocol); | |
870 if(user) { | |
871 gaim_privacy_deny_add(user, blist_parser_buddy_name); | |
872 } | |
873 blist_parser_current_tag = BLIST_TAG_ACCOUNT; | |
874 } else if(!strcmp(element_name, "ignore")) { | |
875 /* we'll apparently do something with this later */ | |
876 blist_parser_current_tag = BLIST_TAG_ACCOUNT; | |
877 } | |
878 } | |
879 | |
880 static void blist_text_handler(GMarkupParseContext *context, const gchar *text, | |
881 gsize text_len, gpointer user_data, GError **error) { | |
882 switch(blist_parser_current_tag) { | |
883 case BLIST_TAG_NAME: | |
884 blist_parser_buddy_name = g_strndup(text, text_len); | |
885 break; | |
886 case BLIST_TAG_ALIAS: | |
887 blist_parser_buddy_alias = g_strndup(text, text_len); | |
888 break; | |
889 case BLIST_TAG_PERMIT: | |
890 case BLIST_TAG_BLOCK: | |
891 case BLIST_TAG_IGNORE: | |
892 blist_parser_buddy_name = g_strndup(text, text_len); | |
893 break; | |
894 case BLIST_TAG_SETTING: | |
895 blist_parser_setting_value = g_strndup(text, text_len); | |
896 break; | |
897 default: | |
898 break; | |
899 } | |
900 } | |
901 | |
902 static GMarkupParser blist_parser = { | |
903 blist_start_element_handler, | |
904 blist_end_element_handler, | |
905 blist_text_handler, | |
906 NULL, | |
907 NULL | |
908 }; | |
909 | |
910 static gboolean gaim_blist_read(const char *filename) { | |
911 gchar *contents; | |
912 gsize length; | |
913 GMarkupParseContext *context; | |
914 GError *error = NULL; | |
915 if(!g_file_get_contents(filename, &contents, &length, &error)) { | |
916 debug_printf("error reading blist: %s\n", error->message); | |
917 g_error_free(error); | |
918 return FALSE; | |
919 } | |
920 | |
921 context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL); | |
922 | |
923 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
924 g_markup_parse_context_free(context); | |
925 return FALSE; | |
926 } | |
927 | |
928 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
929 debug_printf("error parsing blist\n"); | |
930 g_markup_parse_context_free(context); | |
931 return FALSE; | |
932 } | |
933 | |
934 g_markup_parse_context_free(context); | |
935 return TRUE; | |
936 } | |
937 | |
938 void gaim_blist_load() { | |
939 GSList *accts; | |
940 char *user_dir = gaim_user_dir(); | |
941 char *filename; | |
942 char *msg; | |
943 | |
944 if(!user_dir) | |
945 return; | |
946 | |
947 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
948 | |
949 if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
950 if(!gaim_blist_read(filename)) { | |
951 msg = g_strdup_printf(_("An error was encountered parsing your " | |
952 "buddy list. It has not been loaded.")); | |
953 do_error_dialog(_("Buddy List Error"), msg, GAIM_ERROR); | |
954 g_free(msg); | |
955 } | |
4352 | 956 } else if(g_slist_length(aim_users)) { |
4349 | 957 /* rob wants to inform the user that their buddy lists are |
958 * being converted */ | |
959 msg = g_strdup_printf(_("Gaim is converting your old buddy lists " | |
960 "to a new format, which will now be located at %s"), | |
961 filename); | |
962 do_error_dialog(_("Converting Buddy List"), msg, GAIM_INFO); | |
963 g_free(msg); | |
964 | |
965 /* now, let gtk actually display the dialog before we start anything */ | |
966 while(gtk_events_pending()) | |
967 gtk_main_iteration(); | |
968 | |
969 /* read in the old lists, then save to the new format */ | |
970 for(accts = aim_users; accts; accts = accts->next) { | |
971 do_import(accts->data, NULL); | |
972 } | |
973 gaim_blist_save(); | |
974 } | |
975 | |
976 g_free(filename); | |
977 } | |
978 | |
979 static void blist_print_buddy_settings(gpointer key, gpointer data, | |
980 gpointer user_data) { | |
981 char *key_val = g_markup_escape_text(key, -1); | |
982 char *data_val = g_markup_escape_text(data, -1); | |
983 FILE *file = user_data; | |
984 fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
985 data_val); | |
986 g_free(key_val); | |
987 g_free(data_val); | |
988 } | |
989 | |
990 static void gaim_blist_write(FILE *file, struct aim_user *user) { | |
991 GSList *grps, *buds, *users; | |
992 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); | |
993 fprintf(file, "<gaim version=\"1\">\n"); | |
994 fprintf(file, "\t<blist>\n"); | |
995 | |
996 for(grps = groups; grps; grps = grps->next) { | |
997 struct group *g = grps->data; | |
998 if(!user || gaim_group_on_account(g, user)) { | |
999 char *group_name = g_markup_escape_text(g->name, -1); | |
1000 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | |
1001 for(buds = g->members; buds; buds = buds->next) { | |
1002 struct buddy *b = buds->data; | |
1003 if(!user || b->user == user) { | |
1004 char *bud_name = g_markup_escape_text(b->name, -1); | |
1005 char *bud_alias = NULL; | |
1006 char *acct_name = g_markup_escape_text(b->user->username, -1); | |
1007 if(b->alias[0]) | |
1008 bud_alias= g_markup_escape_text(b->alias, -1); | |
1009 fprintf(file, "\t\t\t<person name=\"%s\">\n", | |
1010 bud_alias ? bud_alias : bud_name); | |
1011 fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" " | |
1012 "account=\"%s\">\n", b->user->protocol, | |
1013 acct_name); | |
1014 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); | |
1015 if(bud_alias) { | |
1016 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", | |
1017 bud_alias); | |
1018 } | |
1019 g_hash_table_foreach(b->settings, | |
1020 blist_print_buddy_settings, file); | |
1021 fprintf(file, "\t\t\t\t</buddy>\n"); | |
1022 fprintf(file, "\t\t\t</person>\n"); | |
1023 g_free(bud_name); | |
1024 g_free(bud_alias); | |
1025 g_free(acct_name); | |
1026 } | |
1027 } | |
1028 fprintf(file, "\t\t</group>\n"); | |
1029 g_free(group_name); | |
1030 } | |
1031 } | |
1032 | |
1033 fprintf(file, "\t</blist>\n"); | |
1034 fprintf(file, "\t<privacy>\n"); | |
1035 | |
1036 for(users = aim_users; users; users = users->next) { | |
1037 struct aim_user *usr = users->data; | |
1038 char *acct_name = g_markup_escape_text(usr->username, -1); | |
1039 if(!user || usr == user) { | |
1040 fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" " | |
1041 "mode=\"%d\">\n", usr->protocol, acct_name, usr->permdeny); | |
1042 for(buds = usr->permit; buds; buds = buds->next) { | |
1043 char *bud_name = g_markup_escape_text(buds->data, -1); | |
1044 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
1045 g_free(bud_name); | |
1046 } | |
1047 for(buds = usr->deny; buds; buds = buds->next) { | |
1048 char *bud_name = g_markup_escape_text(buds->data, -1); | |
1049 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
1050 g_free(bud_name); | |
1051 } | |
1052 fprintf(file, "\t\t</account>\n"); | |
1053 } | |
1054 } | |
1055 | |
1056 fprintf(file, "\t</privacy>\n"); | |
1057 fprintf(file, "</gaim>\n"); | |
1058 } | |
1059 | |
1060 void gaim_blist_save() { | |
1061 FILE *file; | |
1062 char *user_dir = gaim_user_dir(); | |
1063 char *filename; | |
1064 | |
1065 if(!user_dir) | |
1066 return; | |
1067 | |
1068 file = fopen(user_dir, "r"); | |
1069 if(!file) | |
1070 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
1071 else | |
1072 fclose(file); | |
1073 | |
1074 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
1075 | |
1076 if((file = fopen(filename, "w"))) { | |
1077 gaim_blist_write(file, NULL); | |
1078 fclose(file); | |
1079 chmod(filename, S_IRUSR | S_IWUSR); | |
1080 } else { | |
1081 debug_printf("unable to write %s\n", filename); | |
1082 } | |
1083 | |
1084 g_free(filename); | |
1085 } | |
1086 | |
1087 gboolean gaim_privacy_permit_add(struct aim_user *user, const char *who) { | |
1088 GSList *d = user->permit; | |
1089 char *n = g_strdup(normalize(who)); | |
1090 while(d) { | |
1091 if(!g_strcasecmp(n, normalize(d->data))) | |
1092 break; | |
1093 d = d->next; | |
1094 } | |
1095 g_free(n); | |
1096 if(!d) { | |
1097 user->permit = g_slist_append(user->permit, g_strdup(who)); | |
1098 return TRUE; | |
1099 } | |
1100 | |
1101 return FALSE; | |
1102 } | |
1103 | |
1104 gboolean gaim_privacy_permit_remove(struct aim_user *user, const char *who) { | |
1105 GSList *d = user->permit; | |
1106 char *n = g_strdup(normalize(who)); | |
1107 while(d) { | |
1108 if(!g_strcasecmp(n, normalize(d->data))) | |
1109 break; | |
1110 d = d->next; | |
1111 } | |
1112 g_free(n); | |
1113 if(d) { | |
1114 user->permit = g_slist_remove(user->permit, d->data); | |
1115 g_free(d->data); | |
1116 return TRUE; | |
1117 } | |
1118 return FALSE; | |
1119 } | |
1120 | |
1121 gboolean gaim_privacy_deny_add(struct aim_user *user, const char *who) { | |
1122 GSList *d = user->deny; | |
1123 char *n = g_strdup(normalize(who)); | |
1124 while(d) { | |
1125 if(!g_strcasecmp(n, normalize(d->data))) | |
1126 break; | |
1127 d = d->next; | |
1128 } | |
1129 g_free(n); | |
1130 if(!d) { | |
1131 user->deny = g_slist_append(user->deny, g_strdup(who)); | |
1132 return TRUE; | |
1133 } | |
1134 | |
1135 return FALSE; | |
1136 } | |
1137 | |
1138 gboolean gaim_privacy_deny_remove(struct aim_user *user, const char *who) { | |
1139 GSList *d = user->deny; | |
1140 char *n = g_strdup(normalize(who)); | |
1141 while(d) { | |
1142 if(!g_strcasecmp(n, normalize(d->data))) | |
1143 break; | |
1144 d = d->next; | |
1145 } | |
1146 g_free(n); | |
1147 if(d) { | |
1148 user->deny = g_slist_remove(user->deny, d->data); | |
1149 g_free(d->data); | |
1150 return TRUE; | |
1151 } | |
1152 return FALSE; | |
1153 } | |
1154 | |
1155 void gaim_buddy_set_setting(struct buddy *b, const char *key, | |
1156 const char *value) { | |
1157 if(!b) | |
1158 return; | |
1159 g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value)); | |
1160 } | |
1161 | |
1162 char *gaim_buddy_get_setting(struct buddy *b, const char *key) { | |
1163 if(!b) | |
1164 return NULL; | |
1165 return g_strdup(g_hash_table_lookup(b->settings, key)); | |
1166 } |