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