5228
|
1 /*
|
|
2 * gaim
|
|
3 *
|
|
4 * Copyright (C) 2003, Sean Egan <sean.egan@binghamton.edu>
|
|
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>
|
|
27 #include <stdlib.h>
|
|
28 #include <sys/types.h>
|
|
29 #include <sys/stat.h>
|
|
30 #ifndef _WIN32
|
|
31 #include <unistd.h>
|
|
32 #else
|
|
33 #include <direct.h>
|
|
34 #endif
|
|
35 #include <ctype.h>
|
|
36 #include "gaim.h"
|
|
37 #include "prpl.h"
|
|
38 #include "blist.h"
|
|
39
|
|
40 #ifdef _WIN32
|
|
41 #include "win32dep.h"
|
|
42 #endif
|
|
43
|
|
44 #define PATHSIZE 1024
|
|
45
|
|
46 struct gaim_buddy_list *gaimbuddylist = NULL;
|
|
47 static struct gaim_blist_ui_ops *blist_ui_ops = NULL;
|
|
48
|
|
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 }
|
|
67
|
|
68 /*****************************************************************************
|
|
69 * Public API functions *
|
|
70 *****************************************************************************/
|
|
71
|
|
72 struct gaim_buddy_list *gaim_blist_new()
|
|
73 {
|
|
74 struct gaim_buddy_list *gbl = g_new0(struct gaim_buddy_list, 1);
|
|
75
|
|
76 gbl->ui_ops = gaim_get_blist_ui_ops();
|
|
77
|
|
78 if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL)
|
|
79 gbl->ui_ops->new_list(gbl);
|
|
80
|
|
81 return gbl;
|
|
82 }
|
|
83
|
|
84 void
|
|
85 gaim_set_blist(struct gaim_buddy_list *list)
|
|
86 {
|
|
87 gaimbuddylist = list;
|
|
88 }
|
|
89
|
|
90 struct gaim_buddy_list *
|
|
91 gaim_get_blist(void)
|
|
92 {
|
|
93 return gaimbuddylist;
|
|
94 }
|
|
95
|
|
96 void gaim_blist_show ()
|
|
97 {
|
|
98 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
99 if (ops)
|
|
100 ops->show(gaimbuddylist);
|
|
101 }
|
|
102
|
|
103 void gaim_blist_destroy()
|
|
104 {
|
|
105 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
106 if (ops)
|
|
107 ops->destroy(gaimbuddylist);
|
|
108 }
|
|
109
|
|
110 void gaim_blist_set_visible (gboolean show)
|
|
111 {
|
|
112 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
113 if (ops)
|
|
114 ops->set_visible(gaimbuddylist, show);
|
|
115 }
|
|
116
|
|
117 void gaim_blist_update_buddy_status (struct buddy *buddy, int status)
|
|
118 {
|
|
119 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
120 buddy->uc = status;
|
|
121
|
|
122 if(!(status & UC_UNAVAILABLE))
|
|
123 gaim_event_broadcast(event_buddy_back, buddy->account->gc, buddy->name);
|
|
124 else
|
|
125 gaim_event_broadcast(event_buddy_away, buddy->account->gc, buddy->name);
|
|
126
|
|
127 if (ops)
|
|
128 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
|
|
129 }
|
|
130
|
|
131 static gboolean presence_update_timeout_cb(struct buddy *buddy) {
|
|
132 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
133
|
|
134 if(buddy->present == GAIM_BUDDY_SIGNING_ON) {
|
|
135 buddy->present = GAIM_BUDDY_ONLINE;
|
|
136 gaim_event_broadcast(event_buddy_signon, buddy->account->gc, buddy->name);
|
|
137 } else if(buddy->present == GAIM_BUDDY_SIGNING_OFF) {
|
|
138 buddy->present = GAIM_BUDDY_OFFLINE;
|
|
139 }
|
|
140
|
|
141 buddy->timer = 0;
|
|
142
|
|
143 if (ops)
|
|
144 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
|
|
145
|
|
146 return FALSE;
|
|
147 }
|
|
148
|
|
149 void gaim_blist_update_buddy_presence(struct buddy *buddy, int presence) {
|
|
150 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
151 gboolean do_timer = FALSE;
|
|
152
|
|
153 if (!GAIM_BUDDY_IS_ONLINE(buddy) && presence) {
|
|
154 buddy->present = GAIM_BUDDY_SIGNING_ON;
|
|
155 gaim_event_broadcast(event_buddy_signon, buddy->account->gc, buddy->name);
|
|
156 do_timer = TRUE;
|
|
157 } else if(GAIM_BUDDY_IS_ONLINE(buddy) && !presence) {
|
|
158 buddy->present = GAIM_BUDDY_SIGNING_OFF;
|
|
159 gaim_event_broadcast(event_buddy_signoff, buddy->account->gc, buddy->name);
|
|
160 do_timer = TRUE;
|
|
161 }
|
|
162
|
|
163 if(do_timer) {
|
|
164 if(buddy->timer > 0)
|
|
165 g_source_remove(buddy->timer);
|
|
166 buddy->timer = g_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy);
|
|
167 }
|
|
168
|
|
169 if (ops)
|
|
170 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
|
|
171 }
|
|
172
|
|
173
|
|
174 void gaim_blist_update_buddy_idle (struct buddy *buddy, int idle)
|
|
175 {
|
|
176 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
177 buddy->idle = idle;
|
|
178 if (ops)
|
|
179 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
|
|
180 }
|
|
181 void gaim_blist_update_buddy_evil (struct buddy *buddy, int warning)
|
|
182 {
|
|
183 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
184 buddy->evil = warning;
|
|
185 if (ops)
|
|
186 ops->update(gaimbuddylist,(GaimBlistNode*)buddy);
|
|
187 }
|
|
188 void gaim_blist_update_buddy_icon(struct buddy *buddy) {
|
|
189 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
190 if(ops)
|
|
191 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
|
|
192 }
|
|
193 void gaim_blist_rename_buddy (struct buddy *buddy, const char *name)
|
|
194 {
|
|
195 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
196 g_free(buddy->name);
|
|
197 buddy->name = g_strdup(name);
|
|
198 if (ops)
|
|
199 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
|
|
200 }
|
5234
|
201
|
|
202 void gaim_blist_alias_chat(struct chat *chat, const char *alias)
|
|
203 {
|
|
204 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
205
|
5237
|
206 g_free(chat->alias);
|
5234
|
207
|
5237
|
208 if(alias && strlen(alias))
|
|
209 chat->alias = g_strdup(alias);
|
|
210 else
|
|
211 chat->alias = NULL;
|
|
212
|
5234
|
213 if(ops)
|
|
214 ops->update(gaimbuddylist, (GaimBlistNode*)chat);
|
|
215 }
|
|
216
|
5228
|
217 void gaim_blist_alias_buddy (struct buddy *buddy, const char *alias)
|
|
218 {
|
|
219 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
220 struct gaim_conversation *conv;
|
|
221
|
|
222 g_free(buddy->alias);
|
|
223
|
|
224 if(alias && strlen(alias))
|
|
225 buddy->alias = g_strdup(alias);
|
|
226 else
|
|
227 buddy->alias = NULL;
|
|
228
|
|
229 if (ops)
|
|
230 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
|
|
231
|
|
232 conv = gaim_find_conversation_with_account(buddy->name, buddy->account);
|
|
233
|
|
234 if (conv)
|
|
235 gaim_conversation_autoset_title(conv);
|
|
236 }
|
|
237
|
|
238 void gaim_blist_rename_group(struct group *group, const char *name)
|
|
239 {
|
|
240 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
241 g_free(group->name);
|
|
242 group->name = g_strdup(name);
|
|
243 if (ops)
|
|
244 ops->update(gaimbuddylist, (GaimBlistNode*)group);
|
|
245 }
|
5234
|
246
|
|
247 struct chat *gaim_chat_new(struct gaim_account *account, const char *alias, GHashTable *components)
|
|
248 {
|
|
249 struct chat *chat;
|
|
250 struct gaim_blist_ui_ops *ops;
|
|
251
|
5237
|
252 if(!components)
|
5234
|
253 return NULL;
|
|
254
|
|
255 chat = g_new0(struct chat, 1);
|
|
256 chat->account = account;
|
5237
|
257 if(alias && strlen(alias))
|
|
258 chat->alias = g_strdup(alias);
|
5234
|
259 chat->components = components;
|
|
260
|
|
261 ((GaimBlistNode*)chat)->type = GAIM_BLIST_CHAT_NODE;
|
|
262
|
|
263 ops = gaim_get_blist_ui_ops();
|
|
264
|
|
265 if (ops != NULL && ops->new_node != NULL)
|
|
266 ops->new_node((GaimBlistNode *)chat);
|
|
267
|
|
268 return chat;
|
|
269 }
|
|
270
|
5228
|
271 struct buddy *gaim_buddy_new(struct gaim_account *account, const char *screenname, const char *alias)
|
|
272 {
|
|
273 struct buddy *b;
|
|
274 struct gaim_blist_ui_ops *ops;
|
|
275
|
|
276 b = g_new0(struct buddy, 1);
|
|
277 b->account = account;
|
|
278 b->name = g_strdup(screenname);
|
|
279 b->alias = g_strdup(alias);
|
|
280 b->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
281 ((GaimBlistNode*)b)->type = GAIM_BLIST_BUDDY_NODE;
|
|
282
|
|
283 ops = gaim_get_blist_ui_ops();
|
|
284
|
|
285 if (ops != NULL && ops->new_node != NULL)
|
|
286 ops->new_node((GaimBlistNode *)b);
|
|
287
|
|
288 return b;
|
|
289 }
|
5234
|
290 void gaim_blist_add_chat(struct chat *chat, struct group *group, GaimBlistNode *node)
|
|
291 {
|
|
292 GaimBlistNode *n = node, *cnode = (GaimBlistNode*)chat;
|
|
293 struct group *g = group;
|
|
294 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
295 gboolean save = FALSE;
|
|
296
|
|
297 if (!n) {
|
|
298 if (!g) {
|
|
299 g = gaim_group_new(_("Chats"));
|
|
300 gaim_blist_add_group(g, NULL);
|
|
301 }
|
|
302 n = gaim_blist_get_last_child((GaimBlistNode*)g);
|
|
303 } else {
|
|
304 g = (struct group*)n->parent;
|
|
305 }
|
|
306
|
|
307 /* if we're moving to overtop of ourselves, do nothing */
|
|
308 if(cnode == n)
|
|
309 return;
|
|
310
|
|
311 if (cnode->parent) {
|
|
312 /* This chat was already in the list and is
|
|
313 * being moved.
|
|
314 */
|
|
315 if(cnode->next)
|
|
316 cnode->next->prev = cnode->prev;
|
|
317 if(cnode->prev)
|
|
318 cnode->prev->next = cnode->next;
|
|
319 if(cnode->parent->child == cnode)
|
|
320 cnode->parent->child = cnode->next;
|
|
321
|
|
322 ops->remove(gaimbuddylist, cnode);
|
|
323
|
|
324 save = TRUE;
|
|
325 }
|
|
326
|
|
327 if (n) {
|
|
328 if(n->next)
|
|
329 n->next->prev = cnode;
|
|
330 cnode->next = n->next;
|
|
331 cnode->prev = n;
|
|
332 cnode->parent = n->parent;
|
|
333 n->next = cnode;
|
|
334 } else {
|
|
335 ((GaimBlistNode*)g)->child = cnode;
|
|
336 cnode->next = cnode->prev = NULL;
|
|
337 cnode->parent = (GaimBlistNode*)g;
|
|
338 }
|
|
339
|
|
340 if (ops)
|
|
341 ops->update(gaimbuddylist, (GaimBlistNode*)cnode);
|
|
342 if (save)
|
|
343 gaim_blist_save();
|
|
344 }
|
|
345
|
5228
|
346 void gaim_blist_add_buddy (struct buddy *buddy, struct group *group, GaimBlistNode *node)
|
|
347 {
|
|
348 GaimBlistNode *n = node, *bnode = (GaimBlistNode*)buddy;
|
|
349 struct group *g = group;
|
|
350 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
351 gboolean save = FALSE;
|
|
352
|
|
353 if (!n) {
|
|
354 if (!g) {
|
|
355 g = gaim_group_new(_("Buddies"));
|
|
356 gaim_blist_add_group(g, NULL);
|
|
357 }
|
|
358 n = gaim_blist_get_last_child((GaimBlistNode*)g);
|
|
359 } else {
|
|
360 g = (struct group*)n->parent;
|
|
361 }
|
|
362
|
|
363 /* if we're moving to overtop of ourselves, do nothing */
|
|
364 if(bnode == n)
|
|
365 return;
|
|
366
|
|
367 if (bnode->parent) {
|
|
368 /* This buddy was already in the list and is
|
|
369 * being moved.
|
|
370 */
|
|
371 if(bnode->next)
|
|
372 bnode->next->prev = bnode->prev;
|
|
373 if(bnode->prev)
|
|
374 bnode->prev->next = bnode->next;
|
|
375 if(bnode->parent->child == bnode)
|
|
376 bnode->parent->child = bnode->next;
|
|
377
|
|
378 ops->remove(gaimbuddylist, bnode);
|
|
379
|
|
380 if (bnode->parent != ((GaimBlistNode*)g))
|
|
381 serv_move_buddy(buddy, (struct group*)bnode->parent, g);
|
|
382 save = TRUE;
|
|
383 }
|
|
384
|
|
385 if (n) {
|
|
386 if(n->next)
|
|
387 n->next->prev = (GaimBlistNode*)buddy;
|
|
388 ((GaimBlistNode*)buddy)->next = n->next;
|
|
389 ((GaimBlistNode*)buddy)->prev = n;
|
|
390 ((GaimBlistNode*)buddy)->parent = n->parent;
|
|
391 n->next = (GaimBlistNode*)buddy;
|
|
392 } else {
|
|
393 ((GaimBlistNode*)g)->child = (GaimBlistNode*)buddy;
|
|
394 ((GaimBlistNode*)buddy)->next = NULL;
|
|
395 ((GaimBlistNode*)buddy)->prev = NULL;
|
|
396 ((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g;
|
|
397 }
|
|
398
|
|
399 if (ops)
|
|
400 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
|
|
401 if (save)
|
|
402 gaim_blist_save();
|
|
403 }
|
|
404
|
|
405 struct group *gaim_group_new(const char *name)
|
|
406 {
|
|
407 struct group *g = gaim_find_group(name);
|
|
408
|
|
409 if (!g) {
|
|
410 struct gaim_blist_ui_ops *ops;
|
|
411 g= g_new0(struct group, 1);
|
|
412 g->name = g_strdup(name);
|
|
413 g->settings = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
414 g_free, g_free);
|
|
415 ((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE;
|
|
416
|
|
417 ops = gaim_get_blist_ui_ops();
|
|
418
|
|
419 if (ops != NULL && ops->new_node != NULL)
|
|
420 ops->new_node((GaimBlistNode *)g);
|
|
421
|
|
422 }
|
|
423 return g;
|
|
424 }
|
|
425
|
|
426 void gaim_blist_add_group (struct group *group, GaimBlistNode *node)
|
|
427 {
|
|
428 struct gaim_blist_ui_ops *ops;
|
|
429 GaimBlistNode *gnode = (GaimBlistNode*)group;
|
|
430 gboolean save = FALSE;
|
|
431
|
|
432 if (!gaimbuddylist)
|
|
433 gaimbuddylist = gaim_blist_new();
|
|
434 ops = gaimbuddylist->ui_ops;
|
|
435
|
|
436 if (!gaimbuddylist->root) {
|
|
437 gaimbuddylist->root = gnode;
|
|
438 return;
|
|
439 }
|
|
440
|
|
441 if (!node)
|
|
442 node = gaim_blist_get_last_sibling(gaimbuddylist->root);
|
|
443
|
|
444 /* if we're moving to overtop of ourselves, do nothing */
|
|
445 if(gnode == node)
|
|
446 return;
|
|
447
|
|
448 if (gaim_find_group(group->name)) {
|
|
449 /* This is just being moved */
|
|
450
|
|
451 ops->remove(gaimbuddylist, (GaimBlistNode*)group);
|
|
452
|
|
453 if(gnode == gaimbuddylist->root)
|
|
454 gaimbuddylist->root = gnode->next;
|
|
455 if(gnode->prev)
|
|
456 gnode->prev->next = gnode->next;
|
|
457 if(gnode->next)
|
|
458 gnode->next->prev = gnode->prev;
|
|
459
|
|
460 save = TRUE;
|
|
461 }
|
|
462
|
|
463 gnode->next = node->next;
|
|
464 gnode->prev = node;
|
|
465 if(node->next)
|
|
466 node->next->prev = gnode;
|
|
467 node->next = gnode;
|
|
468
|
|
469 if (ops) {
|
|
470 ops->update(gaimbuddylist, gnode);
|
|
471 for(node = gnode->child; node; node = node->next)
|
|
472 ops->update(gaimbuddylist, node);
|
|
473 }
|
|
474 if (save)
|
|
475 gaim_blist_save();
|
|
476 }
|
|
477
|
|
478 void gaim_blist_remove_buddy (struct buddy *buddy)
|
|
479 {
|
|
480 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
481
|
|
482 GaimBlistNode *gnode, *node = (GaimBlistNode*)buddy;
|
|
483 struct group *group;
|
|
484
|
|
485 gnode = node->parent;
|
|
486 group = (struct group *)gnode;
|
|
487
|
|
488 if(gnode->child == node)
|
|
489 gnode->child = node->next;
|
|
490 if (node->prev)
|
|
491 node->prev->next = node->next;
|
|
492 if (node->next)
|
|
493 node->next->prev = node->prev;
|
|
494
|
|
495 ops->remove(gaimbuddylist, node);
|
|
496 g_hash_table_destroy(buddy->settings);
|
|
497 g_free(buddy->name);
|
|
498 g_free(buddy->alias);
|
|
499 g_free(buddy);
|
|
500 }
|
|
501
|
5234
|
502 void gaim_blist_remove_chat (struct chat *chat)
|
|
503 {
|
|
504 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
505
|
|
506 GaimBlistNode *gnode, *node = (GaimBlistNode*)chat;
|
|
507 struct group *group;
|
|
508
|
|
509 gnode = node->parent;
|
|
510 group = (struct group *)gnode;
|
|
511
|
|
512 if(gnode->child == node)
|
|
513 gnode->child = node->next;
|
|
514 if (node->prev)
|
|
515 node->prev->next = node->next;
|
|
516 if (node->next)
|
|
517 node->next->prev = node->prev;
|
|
518
|
|
519 ops->remove(gaimbuddylist, node);
|
|
520 g_hash_table_destroy(chat->components);
|
|
521 g_free(chat->alias);
|
|
522 g_free(chat);
|
|
523 }
|
|
524
|
5228
|
525 void gaim_blist_remove_group (struct group *group)
|
|
526 {
|
|
527 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
528 GaimBlistNode *node = (GaimBlistNode*)group;
|
|
529
|
|
530 if(node->child) {
|
|
531 char *buf;
|
|
532 int count = 0;
|
|
533 GaimBlistNode *child = node->child;
|
|
534
|
|
535 while(child) {
|
|
536 count++;
|
|
537 child = child->next;
|
|
538 }
|
|
539
|
|
540 buf = g_strdup_printf(_("%d buddies from group %s were not "
|
|
541 "removed because their accounts were not logged in. These "
|
|
542 "buddies, and the group were not removed.\n"),
|
|
543 count, group->name);
|
|
544 do_error_dialog(_("Group Not Removed"), buf, GAIM_ERROR);
|
|
545 g_free(buf);
|
|
546 return;
|
|
547 }
|
|
548
|
|
549 if(gaimbuddylist->root == node)
|
|
550 gaimbuddylist->root = node->next;
|
|
551 if (node->prev)
|
|
552 node->prev->next = node->next;
|
|
553 if (node->next)
|
|
554 node->next->prev = node->prev;
|
|
555
|
|
556 ops->remove(gaimbuddylist, node);
|
|
557 g_free(group->name);
|
|
558 g_free(group);
|
|
559 }
|
|
560
|
|
561 char *gaim_get_buddy_alias_only(struct buddy *b) {
|
|
562 if(!b)
|
|
563 return NULL;
|
|
564 if(b->alias && b->alias[0])
|
|
565 return b->alias;
|
|
566 else if((misc_options & OPT_MISC_USE_SERVER_ALIAS) && b->server_alias)
|
|
567 return b->server_alias;
|
|
568 return NULL;
|
|
569 }
|
|
570
|
|
571 char * gaim_get_buddy_alias (struct buddy *buddy)
|
|
572 {
|
|
573 char *ret = gaim_get_buddy_alias_only(buddy);
|
|
574 if(!ret)
|
|
575 return buddy ? buddy->name : _("Unknown");
|
|
576 return ret;
|
|
577
|
|
578 }
|
|
579
|
|
580 struct buddy *gaim_find_buddy(struct gaim_account *account, const char *name)
|
|
581 {
|
|
582 GaimBlistNode *group;
|
|
583 GaimBlistNode *buddy;
|
|
584 char *norm_name = g_strdup(normalize(name));
|
|
585
|
|
586 if (!gaimbuddylist)
|
|
587 return NULL;
|
|
588
|
|
589 group = gaimbuddylist->root;
|
|
590 while (group) {
|
|
591 buddy = group->child;
|
|
592 while (buddy) {
|
5234
|
593 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) {
|
|
594 if (!gaim_utf8_strcasecmp(normalize(((struct buddy*)buddy)->name), norm_name) && account == ((struct buddy*)buddy)->account) {
|
|
595 g_free(norm_name);
|
|
596 return (struct buddy*)buddy;
|
|
597 }
|
5228
|
598 }
|
|
599 buddy = buddy->next;
|
|
600 }
|
|
601 group = group->next;
|
|
602 }
|
|
603 g_free(norm_name);
|
|
604 return NULL;
|
|
605 }
|
|
606
|
|
607 struct group *gaim_find_group(const char *name)
|
|
608 {
|
|
609 GaimBlistNode *node;
|
|
610 if (!gaimbuddylist)
|
|
611 return NULL;
|
|
612 node = gaimbuddylist->root;
|
|
613 while(node) {
|
|
614 if (!strcmp(((struct group*)node)->name, name))
|
|
615 return (struct group*)node;
|
|
616 node = node->next;
|
|
617 }
|
|
618 return NULL;
|
|
619 }
|
|
620 struct group *gaim_find_buddys_group(struct buddy *buddy)
|
|
621 {
|
|
622 if (!buddy)
|
|
623 return NULL;
|
|
624 return (struct group*)(((GaimBlistNode*)buddy)->parent);
|
|
625 }
|
|
626
|
|
627 GSList *gaim_group_get_accounts(struct group *g)
|
|
628 {
|
|
629 GSList *l = NULL;
|
|
630 GaimBlistNode *child = ((GaimBlistNode *)g)->child;
|
|
631
|
|
632 while (child) {
|
|
633 if (!g_slist_find(l, ((struct buddy*)child)->account))
|
|
634 l = g_slist_append(l, ((struct buddy*)child)->account);
|
|
635 child = child->next;
|
|
636 }
|
|
637 return l;
|
|
638 }
|
|
639
|
5234
|
640 void gaim_blist_add_account(struct gaim_account *account)
|
|
641 {
|
|
642 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
|
643 GaimBlistNode *group, *buddy;
|
|
644
|
|
645 if(!gaimbuddylist)
|
|
646 return;
|
|
647
|
|
648 for(group = gaimbuddylist->root; group; group = group->next) {
|
|
649 if(!GAIM_BLIST_NODE_IS_GROUP(group))
|
|
650 continue;
|
|
651 for(buddy = group->child; buddy; buddy = buddy->next) {
|
|
652 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) {
|
|
653 if (account == ((struct buddy*)buddy)->account) {
|
|
654 if(ops)
|
|
655 ops->update(gaimbuddylist, buddy);
|
|
656 }
|
|
657 } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) {
|
|
658 if (account == ((struct chat*)buddy)->account) {
|
|
659 if(ops)
|
|
660 ops->update(gaimbuddylist, buddy);
|
|
661 }
|
|
662 }
|
|
663 }
|
|
664 }
|
|
665 }
|
|
666
|
5228
|
667 void gaim_blist_remove_account(struct gaim_account *account)
|
|
668 {
|
|
669 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
|
5234
|
670 GaimBlistNode *group, *buddy;
|
|
671
|
5228
|
672 if (!gaimbuddylist)
|
|
673 return;
|
5234
|
674
|
|
675 for(group = gaimbuddylist->root; group; group = group->next) {
|
|
676 if(!GAIM_BLIST_NODE_IS_GROUP(group))
|
|
677 continue;
|
|
678 for(buddy = group->child; buddy; buddy = buddy->next) {
|
|
679 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) {
|
|
680 if (account == ((struct buddy*)buddy)->account) {
|
|
681 ((struct buddy*)buddy)->present = GAIM_BUDDY_OFFLINE;
|
|
682 if(ops)
|
|
683 ops->remove(gaimbuddylist, buddy);
|
|
684 }
|
|
685 } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) {
|
|
686 if (account == ((struct chat*)buddy)->account) {
|
|
687 if(ops)
|
|
688 ops->remove(gaimbuddylist, buddy);
|
|
689 }
|
5228
|
690 }
|
|
691 }
|
|
692 }
|
|
693 }
|
|
694
|
|
695 void parse_toc_buddy_list(struct gaim_account *account, char *config)
|
|
696 {
|
|
697 char *c;
|
|
698 char current[256];
|
|
699 GList *bud = NULL;
|
|
700
|
|
701
|
|
702 if (config != NULL) {
|
|
703
|
|
704 /* skip "CONFIG:" (if it exists) */
|
|
705 c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ?
|
|
706 strtok(config, "\n") :
|
|
707 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n");
|
|
708 do {
|
|
709 if (c == NULL)
|
|
710 break;
|
|
711 if (*c == 'g') {
|
|
712 char *utf8 = NULL;
|
|
713 utf8 = gaim_try_conv_to_utf8(c + 2);
|
|
714 if (utf8 == NULL) {
|
|
715 g_strlcpy(current, _("Invalid Groupname"), sizeof(current));
|
|
716 } else {
|
|
717 g_strlcpy(current, utf8, sizeof(current));
|
|
718 g_free(utf8);
|
|
719 }
|
|
720 if (!gaim_find_group(current)) {
|
|
721 struct group *g = gaim_group_new(current);
|
|
722 gaim_blist_add_group(g, NULL);
|
|
723 }
|
|
724 } else if (*c == 'b') { /*&& !gaim_find_buddy(user, c + 2)) {*/
|
|
725 char nm[80], sw[388], *a, *utf8 = NULL;
|
|
726
|
|
727 if ((a = strchr(c + 2, ':')) != NULL) {
|
|
728 *a++ = '\0'; /* nul the : */
|
|
729 }
|
|
730
|
|
731 g_strlcpy(nm, c + 2, sizeof(nm));
|
|
732 if (a) {
|
|
733 utf8 = gaim_try_conv_to_utf8(a);
|
|
734 if (utf8 == NULL) {
|
|
735 gaim_debug(GAIM_DEBUG_ERROR, "toc blist",
|
|
736 "Failed to convert alias for "
|
|
737 "'%s' to UTF-8\n", nm);
|
|
738 }
|
|
739 }
|
|
740 if (utf8 == NULL) {
|
|
741 sw[0] = '\0';
|
|
742 } else {
|
|
743 /* This can leave a partial sequence at the end,
|
|
744 * but who cares? */
|
|
745 g_strlcpy(sw, utf8, sizeof(sw));
|
|
746 g_free(utf8);
|
|
747 }
|
|
748
|
|
749 if (!gaim_find_buddy(account, nm)) {
|
|
750 struct buddy *b = gaim_buddy_new(account, nm, sw);
|
|
751 struct group *g = gaim_find_group(current);
|
|
752 gaim_blist_add_buddy(b, g, NULL);
|
|
753 bud = g_list_append(bud, g_strdup(nm));
|
|
754 }
|
|
755 } else if (*c == 'p') {
|
|
756 gaim_privacy_permit_add(account, c + 2);
|
|
757 } else if (*c == 'd') {
|
|
758 gaim_privacy_deny_add(account, c + 2);
|
|
759 } else if (!strncmp("toc", c, 3)) {
|
|
760 sscanf(c + strlen(c) - 1, "%d", &account->permdeny);
|
|
761 gaim_debug(GAIM_DEBUG_MISC, "toc blist",
|
|
762 "permdeny: %d\n", account->permdeny);
|
|
763 if (account->permdeny == 0)
|
|
764 account->permdeny = 1;
|
|
765 } else if (*c == 'm') {
|
|
766 sscanf(c + 2, "%d", &account->permdeny);
|
|
767 gaim_debug(GAIM_DEBUG_MISC, "toc blist",
|
|
768 "permdeny: %d\n", account->permdeny);
|
|
769 if (account->permdeny == 0)
|
|
770 account->permdeny = 1;
|
|
771 }
|
|
772 } while ((c = strtok(NULL, "\n")));
|
|
773
|
|
774 if(account->gc) {
|
|
775 if(bud) {
|
|
776 GList *node = bud;
|
|
777 serv_add_buddies(account->gc, bud);
|
|
778 while(node) {
|
|
779 g_free(node->data);
|
|
780 node = node->next;
|
|
781 }
|
|
782 }
|
|
783 serv_set_permit_deny(account->gc);
|
|
784 }
|
|
785 g_list_free(bud);
|
|
786 }
|
|
787 }
|
|
788
|
|
789 #if 0
|
|
790 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */
|
|
791 static GString *translate_lst(FILE *src_fp)
|
|
792 {
|
|
793 char line[BUF_LEN], *line2;
|
|
794 char *name;
|
|
795 int i;
|
|
796
|
|
797 GString *dest = g_string_new("m 1\n");
|
|
798
|
|
799 while (fgets(line, BUF_LEN, src_fp)) {
|
|
800 line2 = g_strchug(line);
|
|
801 if (strstr(line2, "group") == line2) {
|
|
802 name = strpbrk(line2, " \t\n\r\f") + 1;
|
|
803 dest = g_string_append(dest, "g ");
|
|
804 for (i = 0; i < strcspn(name, "\n\r"); i++)
|
|
805 if (name[i] != '\"')
|
|
806 dest = g_string_append_c(dest, name[i]);
|
|
807 dest = g_string_append_c(dest, '\n');
|
|
808 }
|
|
809 if (strstr(line2, "buddy") == line2) {
|
|
810 name = strpbrk(line2, " \t\n\r\f") + 1;
|
|
811 dest = g_string_append(dest, "b ");
|
|
812 for (i = 0; i < strcspn(name, "\n\r"); i++)
|
|
813 if (name[i] != '\"')
|
|
814 dest = g_string_append_c(dest, name[i]);
|
|
815 dest = g_string_append_c(dest, '\n');
|
|
816 }
|
|
817 }
|
|
818
|
|
819 return dest;
|
|
820 }
|
|
821
|
|
822
|
|
823 /* translate an AIM 4 buddylist (*.blt) to Gaim format */
|
|
824 static GString *translate_blt(FILE *src_fp)
|
|
825 {
|
|
826 int i;
|
|
827 char line[BUF_LEN];
|
|
828 char *buddy;
|
|
829
|
|
830 GString *dest = g_string_new("m 1\n");
|
|
831
|
|
832 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL);
|
|
833 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL);
|
|
834
|
|
835 while (1) {
|
|
836 fgets(line, BUF_LEN, src_fp); g_strchomp(line);
|
|
837 if (strchr(line, '}') != NULL)
|
|
838 break;
|
|
839
|
|
840 if (strchr(line, '{') != NULL) {
|
|
841 /* Syntax starting with "<group> {" */
|
|
842
|
|
843 dest = g_string_append(dest, "g ");
|
|
844 buddy = g_strchug(strtok(line, "{"));
|
|
845 for (i = 0; i < strlen(buddy); i++)
|
|
846 if (buddy[i] != '\"')
|
|
847 dest = g_string_append_c(dest, buddy[i]);
|
|
848 dest = g_string_append_c(dest, '\n');
|
|
849 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) {
|
|
850 gboolean pounce = FALSE;
|
|
851 char *e;
|
|
852 g_strchomp(line);
|
|
853 buddy = g_strchug(line);
|
|
854 gaim_debug(GAIM_DEBUG_MISC, "AIM 4 blt import",
|
|
855 "buddy: \"%s\"\n", buddy);
|
|
856 dest = g_string_append(dest, "b ");
|
|
857 if (strchr(buddy, '{') != NULL) {
|
|
858 /* buddy pounce, etc */
|
|
859 char *pos = strchr(buddy, '{') - 1;
|
|
860 *pos = 0;
|
|
861 pounce = TRUE;
|
|
862 }
|
|
863 if ((e = strchr(buddy, '\"')) != NULL) {
|
|
864 *e = '\0';
|
|
865 buddy++;
|
|
866 }
|
|
867 dest = g_string_append(dest, buddy);
|
|
868 dest = g_string_append_c(dest, '\n');
|
|
869 if (pounce)
|
|
870 do
|
|
871 fgets(line, BUF_LEN, src_fp);
|
|
872 while (!strchr(line, '}'));
|
|
873 }
|
|
874 } else {
|
|
875
|
|
876 /* Syntax "group buddy buddy ..." */
|
|
877 buddy = g_strchug(strtok(line, " \n"));
|
|
878 dest = g_string_append(dest, "g ");
|
|
879 if (strchr(buddy, '\"') != NULL) {
|
|
880 dest = g_string_append(dest, &buddy[1]);
|
|
881 dest = g_string_append_c(dest, ' ');
|
|
882 buddy = g_strchug(strtok(NULL, " \n"));
|
|
883 while (strchr(buddy, '\"') == NULL) {
|
|
884 dest = g_string_append(dest, buddy);
|
|
885 dest = g_string_append_c(dest, ' ');
|
|
886 buddy = g_strchug(strtok(NULL, " \n"));
|
|
887 }
|
|
888 buddy[strlen(buddy) - 1] = '\0';
|
|
889 dest = g_string_append(dest, buddy);
|
|
890 } else {
|
|
891 dest = g_string_append(dest, buddy);
|
|
892 }
|
|
893 dest = g_string_append_c(dest, '\n');
|
|
894 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) {
|
|
895 dest = g_string_append(dest, "b ");
|
|
896 if (strchr(buddy, '\"') != NULL) {
|
|
897 dest = g_string_append(dest, &buddy[1]);
|
|
898 dest = g_string_append_c(dest, ' ');
|
|
899 buddy = g_strchug(strtok(NULL, " \n"));
|
|
900 while (strchr(buddy, '\"') == NULL) {
|
|
901 dest = g_string_append(dest, buddy);
|
|
902 dest = g_string_append_c(dest, ' ');
|
|
903 buddy = g_strchug(strtok(NULL, " \n"));
|
|
904 }
|
|
905 buddy[strlen(buddy) - 1] = '\0';
|
|
906 dest = g_string_append(dest, buddy);
|
|
907 } else {
|
|
908 dest = g_string_append(dest, buddy);
|
|
909 }
|
|
910 dest = g_string_append_c(dest, '\n');
|
|
911 }
|
|
912 }
|
|
913 }
|
|
914
|
|
915 return dest;
|
|
916 }
|
|
917
|
|
918 static GString *translate_gnomeicu(FILE *src_fp)
|
|
919 {
|
|
920 char line[BUF_LEN];
|
|
921 GString *dest = g_string_new("m 1\ng Buddies\n");
|
|
922
|
|
923 while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL);
|
|
924
|
|
925 while (fgets(line, BUF_LEN, src_fp)) {
|
|
926 char *eq;
|
|
927 g_strchomp(line);
|
|
928 if (line[0] == '\n' || line[0] == '[')
|
|
929 break;
|
|
930 eq = strchr(line, '=');
|
|
931 if (!eq)
|
|
932 break;
|
|
933 *eq = ':';
|
|
934 eq = strchr(eq, ',');
|
|
935 if (eq)
|
|
936 *eq = '\0';
|
|
937 dest = g_string_append(dest, "b ");
|
|
938 dest = g_string_append(dest, line);
|
|
939 dest = g_string_append_c(dest, '\n');
|
|
940 }
|
|
941
|
|
942 return dest;
|
|
943 }
|
|
944 #endif
|
|
945
|
|
946 static gchar *get_screenname_filename(const char *name)
|
|
947 {
|
|
948 gchar **split;
|
|
949 gchar *good;
|
|
950 gchar *ret;
|
|
951
|
|
952 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1);
|
|
953 good = g_strjoinv(NULL, split);
|
|
954 g_strfreev(split);
|
|
955
|
|
956 ret = g_utf8_strup(good, -1);
|
|
957
|
|
958 g_free(good);
|
|
959
|
|
960 return ret;
|
|
961 }
|
|
962
|
|
963 static gboolean gaim_blist_read(const char *filename);
|
|
964
|
|
965
|
|
966 static void do_import(struct gaim_account *account, const char *filename)
|
|
967 {
|
|
968 GString *buf = NULL;
|
|
969 char first[64];
|
|
970 char path[PATHSIZE];
|
|
971 int len;
|
|
972 FILE *f;
|
|
973 struct stat st;
|
|
974
|
|
975 if (filename) {
|
|
976 g_snprintf(path, sizeof(path), "%s", filename);
|
|
977 } else {
|
|
978 char *g_screenname = get_screenname_filename(account->username);
|
|
979 char *file = gaim_user_dir();
|
|
980 int protocol = (account->protocol == GAIM_PROTO_OSCAR) ? (isalpha(account->username[0]) ? GAIM_PROTO_TOC : GAIM_PROTO_ICQ): account->protocol;
|
|
981
|
|
982 if (file != (char *)NULL) {
|
|
983 sprintf(path, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol);
|
|
984 g_free(g_screenname);
|
|
985 } else {
|
|
986 g_free(g_screenname);
|
|
987 return;
|
|
988 }
|
|
989 }
|
|
990
|
|
991 if (stat(path, &st)) {
|
|
992 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to stat %s.\n",
|
|
993 path);
|
|
994 return;
|
|
995 }
|
|
996
|
|
997 if (!(f = fopen(path, "r"))) {
|
|
998 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to open %s.\n",
|
|
999 path);
|
|
1000 return;
|
|
1001 }
|
|
1002
|
|
1003 fgets(first, 64, f);
|
|
1004
|
|
1005 if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n'))
|
|
1006 fgets(first, 64, f);
|
|
1007
|
|
1008 #if 0
|
|
1009 if (!g_strncasecmp(first, "<xml", strlen("<xml"))) {
|
|
1010 /* new gaim XML buddy list */
|
|
1011 gaim_blist_read(path);
|
|
1012
|
|
1013 /* We really don't need to bother doing stuf like translating AIM 3 buddy lists anymore */
|
|
1014
|
|
1015 } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) {
|
|
1016 /* AIM 4 buddy list */
|
|
1017 gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 4\n");
|
|
1018 rewind(f);
|
|
1019 buf = translate_blt(f);
|
|
1020 } else if (strstr(first, "group") != NULL) {
|
|
1021 /* AIM 3 buddy list */
|
|
1022 gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 3\n");
|
|
1023 rewind(f);
|
|
1024 buf = translate_lst(f);
|
|
1025 } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) {
|
|
1026 /* GnomeICU (hopefully) */
|
|
1027 gaim_debug(GAIM_DEBUG_MISC, "blist import", "gnomeicu\n");
|
|
1028 rewind(f);
|
|
1029 buf = translate_gnomeicu(f);
|
|
1030
|
|
1031 } else
|
|
1032 #endif
|
|
1033 if (first[0] == 'm') {
|
|
1034 /* Gaim buddy list - no translation */
|
|
1035 char buf2[BUF_LONG * 2];
|
|
1036 buf = g_string_new("");
|
|
1037 rewind(f);
|
|
1038 while (1) {
|
|
1039 len = fread(buf2, 1, BUF_LONG * 2 - 1, f);
|
|
1040 if (len <= 0)
|
|
1041 break;
|
|
1042 buf2[len] = '\0';
|
|
1043 buf = g_string_append(buf, buf2);
|
|
1044 if (len != BUF_LONG * 2 - 1)
|
|
1045 break;
|
|
1046 }
|
|
1047 }
|
|
1048
|
|
1049 fclose(f);
|
|
1050
|
|
1051 if (buf) {
|
|
1052 buf = g_string_prepend(buf, "toc_set_config {");
|
|
1053 buf = g_string_append(buf, "}\n");
|
|
1054 parse_toc_buddy_list(account, buf->str);
|
|
1055 g_string_free(buf, TRUE);
|
|
1056 }
|
|
1057 }
|
|
1058
|
|
1059 gboolean gaim_group_on_account(struct group *g, struct gaim_account *account) {
|
|
1060 GaimBlistNode *bnode;
|
|
1061 for(bnode = g->node.child; bnode; bnode = bnode->next) {
|
|
1062 struct buddy *b = (struct buddy *)bnode;
|
|
1063 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
|
|
1064 continue;
|
|
1065 if((!account && b->account->gc) || b->account == account)
|
|
1066 return TRUE;
|
|
1067 }
|
|
1068 return FALSE;
|
|
1069 }
|
|
1070
|
|
1071 static gboolean blist_safe_to_write = FALSE;
|
|
1072
|
|
1073 static char *blist_parser_group_name = NULL;
|
|
1074 static char *blist_parser_person_name = NULL;
|
|
1075 static char *blist_parser_account_name = NULL;
|
|
1076 static int blist_parser_account_protocol = 0;
|
5234
|
1077 static char *blist_parser_chat_alias = NULL;
|
|
1078 static char *blist_parser_component_name = NULL;
|
|
1079 static char *blist_parser_component_value = NULL;
|
5228
|
1080 static char *blist_parser_buddy_name = NULL;
|
|
1081 static char *blist_parser_buddy_alias = NULL;
|
|
1082 static char *blist_parser_setting_name = NULL;
|
|
1083 static char *blist_parser_setting_value = NULL;
|
|
1084 static GHashTable *blist_parser_buddy_settings = NULL;
|
|
1085 static GHashTable *blist_parser_group_settings = NULL;
|
5234
|
1086 static GHashTable *blist_parser_chat_components = NULL;
|
5228
|
1087 static int blist_parser_privacy_mode = 0;
|
|
1088 static GList *tag_stack = NULL;
|
|
1089 enum {
|
|
1090 BLIST_TAG_GAIM,
|
|
1091 BLIST_TAG_BLIST,
|
|
1092 BLIST_TAG_GROUP,
|
5234
|
1093 BLIST_TAG_CHAT,
|
|
1094 BLIST_TAG_COMPONENT,
|
5228
|
1095 BLIST_TAG_PERSON,
|
|
1096 BLIST_TAG_BUDDY,
|
|
1097 BLIST_TAG_NAME,
|
|
1098 BLIST_TAG_ALIAS,
|
|
1099 BLIST_TAG_SETTING,
|
|
1100 BLIST_TAG_PRIVACY,
|
|
1101 BLIST_TAG_ACCOUNT,
|
|
1102 BLIST_TAG_PERMIT,
|
|
1103 BLIST_TAG_BLOCK,
|
|
1104 BLIST_TAG_IGNORE
|
|
1105 };
|
|
1106 static gboolean blist_parser_error_occurred = FALSE;
|
|
1107
|
|
1108 static void blist_start_element_handler (GMarkupParseContext *context,
|
|
1109 const gchar *element_name,
|
|
1110 const gchar **attribute_names,
|
|
1111 const gchar **attribute_values,
|
|
1112 gpointer user_data,
|
|
1113 GError **error) {
|
|
1114 int i;
|
|
1115
|
|
1116 if(!strcmp(element_name, "gaim")) {
|
|
1117 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GAIM));
|
|
1118 } else if(!strcmp(element_name, "blist")) {
|
|
1119 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLIST));
|
|
1120 } else if(!strcmp(element_name, "group")) {
|
|
1121 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GROUP));
|
|
1122 for(i=0; attribute_names[i]; i++) {
|
|
1123 if(!strcmp(attribute_names[i], "name")) {
|
|
1124 g_free(blist_parser_group_name);
|
|
1125 blist_parser_group_name = g_strdup(attribute_values[i]);
|
|
1126 }
|
|
1127 }
|
|
1128 if(blist_parser_group_name) {
|
|
1129 struct group *g = gaim_group_new(blist_parser_group_name);
|
|
1130 gaim_blist_add_group(g,NULL);
|
|
1131 }
|
5234
|
1132 } else if(!strcmp(element_name, "chat")) {
|
|
1133 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_CHAT));
|
|
1134 for(i=0; attribute_names[i]; i++) {
|
|
1135 if(!strcmp(attribute_names[i], "account")) {
|
|
1136 g_free(blist_parser_account_name);
|
|
1137 blist_parser_account_name = g_strdup(attribute_values[i]);
|
|
1138 } else if(!strcmp(attribute_names[i], "protocol")) {
|
|
1139 blist_parser_account_protocol = atoi(attribute_values[i]);
|
|
1140 }
|
|
1141 }
|
5228
|
1142 } else if(!strcmp(element_name, "person")) {
|
|
1143 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERSON));
|
|
1144 for(i=0; attribute_names[i]; i++) {
|
|
1145 if(!strcmp(attribute_names[i], "name")) {
|
|
1146 g_free(blist_parser_person_name);
|
|
1147 blist_parser_person_name = g_strdup(attribute_values[i]);
|
|
1148 }
|
|
1149 }
|
|
1150 } else if(!strcmp(element_name, "buddy")) {
|
|
1151 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BUDDY));
|
|
1152 for(i=0; attribute_names[i]; i++) {
|
|
1153 if(!strcmp(attribute_names[i], "account")) {
|
|
1154 g_free(blist_parser_account_name);
|
|
1155 blist_parser_account_name = g_strdup(attribute_values[i]);
|
|
1156 } else if(!strcmp(attribute_names[i], "protocol")) {
|
|
1157 blist_parser_account_protocol = atoi(attribute_values[i]);
|
|
1158 }
|
|
1159 }
|
|
1160 } else if(!strcmp(element_name, "name")) {
|
|
1161 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_NAME));
|
|
1162 } else if(!strcmp(element_name, "alias")) {
|
|
1163 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ALIAS));
|
|
1164 } else if(!strcmp(element_name, "setting")) {
|
|
1165 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_SETTING));
|
|
1166 for(i=0; attribute_names[i]; i++) {
|
|
1167 if(!strcmp(attribute_names[i], "name")) {
|
|
1168 g_free(blist_parser_setting_name);
|
|
1169 blist_parser_setting_name = g_strdup(attribute_values[i]);
|
|
1170 }
|
|
1171 }
|
5234
|
1172 } else if(!strcmp(element_name, "component")) {
|
|
1173 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_COMPONENT));
|
|
1174 for(i=0; attribute_names[i]; i++) {
|
|
1175 if(!strcmp(attribute_names[i], "name")) {
|
|
1176 g_free(blist_parser_component_name);
|
|
1177 blist_parser_component_name = g_strdup(attribute_values[i]);
|
|
1178 }
|
|
1179 }
|
|
1180
|
5228
|
1181 } else if(!strcmp(element_name, "privacy")) {
|
|
1182 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PRIVACY));
|
|
1183 } else if(!strcmp(element_name, "account")) {
|
|
1184 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ACCOUNT));
|
|
1185 for(i=0; attribute_names[i]; i++) {
|
|
1186 if(!strcmp(attribute_names[i], "protocol"))
|
|
1187 blist_parser_account_protocol = atoi(attribute_values[i]);
|
|
1188 else if(!strcmp(attribute_names[i], "mode"))
|
|
1189 blist_parser_privacy_mode = atoi(attribute_values[i]);
|
|
1190 else if(!strcmp(attribute_names[i], "name")) {
|
|
1191 g_free(blist_parser_account_name);
|
|
1192 blist_parser_account_name = g_strdup(attribute_values[i]);
|
|
1193 }
|
|
1194 }
|
|
1195 } else if(!strcmp(element_name, "permit")) {
|
|
1196 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERMIT));
|
|
1197 } else if(!strcmp(element_name, "block")) {
|
|
1198 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLOCK));
|
|
1199 } else if(!strcmp(element_name, "ignore")) {
|
|
1200 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_IGNORE));
|
|
1201 }
|
|
1202 }
|
|
1203
|
|
1204 static void blist_end_element_handler(GMarkupParseContext *context,
|
|
1205 const gchar *element_name, gpointer user_data, GError **error) {
|
|
1206 if(!strcmp(element_name, "gaim")) {
|
|
1207 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
|
1208 } else if(!strcmp(element_name, "blist")) {
|
|
1209 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
|
1210 } else if(!strcmp(element_name, "group")) {
|
|
1211 if(blist_parser_group_settings) {
|
|
1212 struct group *g = gaim_find_group(blist_parser_group_name);
|
|
1213 g_hash_table_destroy(g->settings);
|
|
1214 g->settings = blist_parser_group_settings;
|
|
1215 }
|
|
1216 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
|
1217 blist_parser_group_settings = NULL;
|
5234
|
1218 } else if(!strcmp(element_name, "chat")) {
|
|
1219 struct gaim_account *account = gaim_account_find(blist_parser_account_name,
|
|
1220 blist_parser_account_protocol);
|
5237
|
1221 if(account) {
|
5234
|
1222 struct chat *chat = gaim_chat_new(account, blist_parser_chat_alias, blist_parser_chat_components);
|
|
1223 struct group *g = gaim_find_group(blist_parser_group_name);
|
|
1224 gaim_blist_add_chat(chat,g,NULL);
|
|
1225 }
|
|
1226 g_free(blist_parser_chat_alias);
|
|
1227 blist_parser_chat_alias = NULL;
|
|
1228 g_free(blist_parser_account_name);
|
|
1229 blist_parser_account_name = NULL;
|
|
1230 blist_parser_chat_components = NULL;
|
|
1231 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
5228
|
1232 } else if(!strcmp(element_name, "person")) {
|
|
1233 g_free(blist_parser_person_name);
|
|
1234 blist_parser_person_name = NULL;
|
|
1235 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
|
1236 } else if(!strcmp(element_name, "buddy")) {
|
|
1237 struct gaim_account *account = gaim_account_find(blist_parser_account_name,
|
|
1238 blist_parser_account_protocol);
|
|
1239 if(account) {
|
|
1240 struct buddy *b = gaim_buddy_new(account, blist_parser_buddy_name, blist_parser_buddy_alias);
|
|
1241 struct group *g = gaim_find_group(blist_parser_group_name);
|
|
1242 gaim_blist_add_buddy(b,g,NULL);
|
|
1243 if(blist_parser_buddy_settings) {
|
|
1244 g_hash_table_destroy(b->settings);
|
|
1245 b->settings = blist_parser_buddy_settings;
|
|
1246 }
|
|
1247 }
|
|
1248 g_free(blist_parser_buddy_name);
|
|
1249 blist_parser_buddy_name = NULL;
|
|
1250 g_free(blist_parser_buddy_alias);
|
|
1251 blist_parser_buddy_alias = NULL;
|
|
1252 g_free(blist_parser_account_name);
|
|
1253 blist_parser_account_name = NULL;
|
|
1254 blist_parser_buddy_settings = NULL;
|
|
1255 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
|
1256 } else if(!strcmp(element_name, "name")) {
|
|
1257 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
|
1258 } else if(!strcmp(element_name, "alias")) {
|
|
1259 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
5234
|
1260 } else if(!strcmp(element_name, "component")) {
|
|
1261 if(!blist_parser_chat_components)
|
|
1262 blist_parser_chat_components = g_hash_table_new_full(g_str_hash,
|
|
1263 g_str_equal, g_free, g_free);
|
|
1264 if(blist_parser_component_name && blist_parser_component_value) {
|
|
1265 g_hash_table_replace(blist_parser_chat_components,
|
|
1266 g_strdup(blist_parser_component_name),
|
|
1267 g_strdup(blist_parser_component_value));
|
|
1268 }
|
|
1269 g_free(blist_parser_component_name);
|
|
1270 g_free(blist_parser_component_value);
|
|
1271 blist_parser_component_name = NULL;
|
|
1272 blist_parser_component_value = NULL;
|
|
1273 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
5228
|
1274 } else if(!strcmp(element_name, "setting")) {
|
|
1275 if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) {
|
|
1276 if(!blist_parser_buddy_settings)
|
|
1277 blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash,
|
|
1278 g_str_equal, g_free, g_free);
|
|
1279 if(blist_parser_setting_name && blist_parser_setting_value) {
|
|
1280 g_hash_table_replace(blist_parser_buddy_settings,
|
|
1281 g_strdup(blist_parser_setting_name),
|
|
1282 g_strdup(blist_parser_setting_value));
|
|
1283 }
|
|
1284 } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_GROUP) {
|
|
1285 if(!blist_parser_group_settings)
|
|
1286 blist_parser_group_settings = g_hash_table_new_full(g_str_hash,
|
|
1287 g_str_equal, g_free, g_free);
|
|
1288 if(blist_parser_setting_name && blist_parser_setting_value) {
|
|
1289 g_hash_table_replace(blist_parser_group_settings,
|
|
1290 g_strdup(blist_parser_setting_name),
|
|
1291 g_strdup(blist_parser_setting_value));
|
|
1292 }
|
|
1293 }
|
|
1294 g_free(blist_parser_setting_name);
|
|
1295 g_free(blist_parser_setting_value);
|
|
1296 blist_parser_setting_name = NULL;
|
|
1297 blist_parser_setting_value = NULL;
|
|
1298 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
|
1299 } else if(!strcmp(element_name, "privacy")) {
|
|
1300 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
|
1301 } else if(!strcmp(element_name, "account")) {
|
|
1302 struct gaim_account *account = gaim_account_find(blist_parser_account_name,
|
|
1303 blist_parser_account_protocol);
|
|
1304 if(account) {
|
|
1305 account->permdeny = blist_parser_privacy_mode;
|
|
1306 }
|
|
1307 g_free(blist_parser_account_name);
|
|
1308 blist_parser_account_name = NULL;
|
|
1309 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
|
1310 } else if(!strcmp(element_name, "permit")) {
|
|
1311 struct gaim_account *account = gaim_account_find(blist_parser_account_name,
|
|
1312 blist_parser_account_protocol);
|
|
1313 if(account) {
|
|
1314 gaim_privacy_permit_add(account, blist_parser_buddy_name);
|
|
1315 }
|
|
1316 g_free(blist_parser_buddy_name);
|
|
1317 blist_parser_buddy_name = NULL;
|
|
1318 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
|
1319 } else if(!strcmp(element_name, "block")) {
|
|
1320 struct gaim_account *account = gaim_account_find(blist_parser_account_name,
|
|
1321 blist_parser_account_protocol);
|
|
1322 if(account) {
|
|
1323 gaim_privacy_deny_add(account, blist_parser_buddy_name);
|
|
1324 }
|
|
1325 g_free(blist_parser_buddy_name);
|
|
1326 blist_parser_buddy_name = NULL;
|
|
1327 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
|
1328 } else if(!strcmp(element_name, "ignore")) {
|
|
1329 /* we'll apparently do something with this later */
|
|
1330 tag_stack = g_list_delete_link(tag_stack, tag_stack);
|
|
1331 }
|
|
1332 }
|
|
1333
|
|
1334 static void blist_text_handler(GMarkupParseContext *context, const gchar *text,
|
|
1335 gsize text_len, gpointer user_data, GError **error) {
|
|
1336 switch(GPOINTER_TO_INT(tag_stack->data)) {
|
|
1337 case BLIST_TAG_NAME:
|
|
1338 blist_parser_buddy_name = g_strndup(text, text_len);
|
|
1339 break;
|
|
1340 case BLIST_TAG_ALIAS:
|
5234
|
1341 if(tag_stack->next &&
|
|
1342 GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY)
|
|
1343 blist_parser_buddy_alias = g_strndup(text, text_len);
|
|
1344 else if(tag_stack->next &&
|
|
1345 GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_CHAT)
|
|
1346 blist_parser_chat_alias = g_strndup(text, text_len);
|
5228
|
1347 break;
|
|
1348 case BLIST_TAG_PERMIT:
|
|
1349 case BLIST_TAG_BLOCK:
|
|
1350 case BLIST_TAG_IGNORE:
|
|
1351 blist_parser_buddy_name = g_strndup(text, text_len);
|
|
1352 break;
|
5234
|
1353 case BLIST_TAG_COMPONENT:
|
|
1354 blist_parser_component_value = g_strndup(text, text_len);
|
|
1355 break;
|
5228
|
1356 case BLIST_TAG_SETTING:
|
|
1357 blist_parser_setting_value = g_strndup(text, text_len);
|
|
1358 break;
|
|
1359 default:
|
|
1360 break;
|
|
1361 }
|
|
1362 }
|
|
1363
|
|
1364 static void blist_error_handler(GMarkupParseContext *context, GError *error,
|
|
1365 gpointer user_data) {
|
|
1366 blist_parser_error_occurred = TRUE;
|
|
1367 gaim_debug(GAIM_DEBUG_ERROR, "blist import",
|
|
1368 "Error parsing blist.xml: %s\n", error->message);
|
|
1369 }
|
|
1370
|
|
1371 static GMarkupParser blist_parser = {
|
|
1372 blist_start_element_handler,
|
|
1373 blist_end_element_handler,
|
|
1374 blist_text_handler,
|
|
1375 NULL,
|
|
1376 blist_error_handler
|
|
1377 };
|
|
1378
|
|
1379 static gboolean gaim_blist_read(const char *filename) {
|
|
1380 gchar *contents = NULL;
|
|
1381 gsize length;
|
|
1382 GMarkupParseContext *context;
|
|
1383 GError *error = NULL;
|
|
1384
|
|
1385 gaim_debug(GAIM_DEBUG_INFO, "blist import",
|
|
1386 "Reading %s\n", filename);
|
|
1387 if(!g_file_get_contents(filename, &contents, &length, &error)) {
|
|
1388 gaim_debug(GAIM_DEBUG_ERROR, "blist import",
|
|
1389 "Error reading blist: %s\n", error->message);
|
|
1390 g_error_free(error);
|
|
1391 return FALSE;
|
|
1392 }
|
|
1393
|
|
1394 context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL);
|
|
1395
|
|
1396 if(!g_markup_parse_context_parse(context, contents, length, NULL)) {
|
|
1397 g_markup_parse_context_free(context);
|
|
1398 g_free(contents);
|
|
1399 return FALSE;
|
|
1400 }
|
|
1401
|
|
1402 if(!g_markup_parse_context_end_parse(context, NULL)) {
|
|
1403 gaim_debug(GAIM_DEBUG_ERROR, "blist import",
|
|
1404 "Error parsing %s\n", filename);
|
|
1405 g_markup_parse_context_free(context);
|
|
1406 g_free(contents);
|
|
1407 return FALSE;
|
|
1408 }
|
|
1409
|
|
1410 g_markup_parse_context_free(context);
|
|
1411 g_free(contents);
|
|
1412
|
|
1413 if(blist_parser_error_occurred)
|
|
1414 return FALSE;
|
|
1415
|
|
1416 gaim_debug(GAIM_DEBUG_INFO, "blist import", "Finished reading %s\n",
|
|
1417 filename);
|
|
1418
|
|
1419 return TRUE;
|
|
1420 }
|
|
1421
|
|
1422 void gaim_blist_load() {
|
|
1423 GSList *accts;
|
|
1424 char *user_dir = gaim_user_dir();
|
|
1425 char *filename;
|
|
1426 char *msg;
|
|
1427
|
|
1428 blist_safe_to_write = TRUE;
|
|
1429
|
|
1430 if(!user_dir)
|
|
1431 return;
|
|
1432
|
|
1433 filename = g_build_filename(user_dir, "blist.xml", NULL);
|
|
1434
|
|
1435 if(g_file_test(filename, G_FILE_TEST_EXISTS)) {
|
|
1436 if(!gaim_blist_read(filename)) {
|
|
1437 msg = g_strdup_printf(_("An error was encountered parsing your "
|
|
1438 "buddy list. It has not been loaded."));
|
|
1439 do_error_dialog(_("Buddy List Error"), msg, GAIM_ERROR);
|
|
1440 g_free(msg);
|
|
1441 }
|
|
1442 } else if(g_slist_length(gaim_accounts)) {
|
|
1443 /* rob wants to inform the user that their buddy lists are
|
|
1444 * being converted */
|
|
1445 msg = g_strdup_printf(_("Gaim is converting your old buddy lists "
|
|
1446 "to a new format, which will now be located at %s"),
|
|
1447 filename);
|
|
1448 do_error_dialog(_("Converting Buddy List"), msg, GAIM_INFO);
|
|
1449 g_free(msg);
|
|
1450
|
|
1451 /* now, let gtk actually display the dialog before we start anything */
|
|
1452 while(gtk_events_pending())
|
|
1453 gtk_main_iteration();
|
|
1454
|
|
1455 /* read in the old lists, then save to the new format */
|
|
1456 for(accts = gaim_accounts; accts; accts = accts->next) {
|
|
1457 do_import(accts->data, NULL);
|
|
1458 }
|
|
1459 gaim_blist_save();
|
|
1460 }
|
|
1461
|
|
1462 g_free(filename);
|
|
1463 }
|
|
1464
|
|
1465 static void blist_print_group_settings(gpointer key, gpointer data,
|
|
1466 gpointer user_data) {
|
|
1467 char *key_val;
|
|
1468 char *data_val;
|
|
1469 FILE *file = user_data;
|
|
1470
|
|
1471 if(!key || !data)
|
|
1472 return;
|
|
1473
|
|
1474 key_val = g_markup_escape_text(key, -1);
|
|
1475 data_val = g_markup_escape_text(data, -1);
|
|
1476
|
|
1477 fprintf(file, "\t\t\t<setting name=\"%s\">%s</setting>\n", key_val,
|
|
1478 data_val);
|
|
1479 g_free(key_val);
|
|
1480 g_free(data_val);
|
|
1481 }
|
|
1482
|
|
1483 static void blist_print_buddy_settings(gpointer key, gpointer data,
|
|
1484 gpointer user_data) {
|
|
1485 char *key_val;
|
|
1486 char *data_val;
|
|
1487 FILE *file = user_data;
|
|
1488
|
|
1489 if(!key || !data)
|
|
1490 return;
|
|
1491
|
|
1492 key_val = g_markup_escape_text(key, -1);
|
|
1493 data_val = g_markup_escape_text(data, -1);
|
|
1494
|
|
1495 fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val,
|
|
1496 data_val);
|
|
1497 g_free(key_val);
|
|
1498 g_free(data_val);
|
|
1499 }
|
|
1500
|
5234
|
1501 static void blist_print_chat_components(gpointer key, gpointer data,
|
|
1502 gpointer user_data) {
|
|
1503 char *key_val;
|
|
1504 char *data_val;
|
|
1505 FILE *file = user_data;
|
|
1506
|
|
1507 if(!key || !data)
|
|
1508 return;
|
|
1509
|
|
1510 key_val = g_markup_escape_text(key, -1);
|
|
1511 data_val = g_markup_escape_text(data, -1);
|
|
1512
|
|
1513 fprintf(file, "\t\t\t\t<component name=\"%s\">%s</component>\n", key_val,
|
|
1514 data_val);
|
|
1515 g_free(key_val);
|
|
1516 g_free(data_val);
|
|
1517 }
|
|
1518
|
5228
|
1519 static void gaim_blist_write(FILE *file, struct gaim_account *exp_acct) {
|
|
1520 GSList *accounts, *buds;
|
|
1521 GaimBlistNode *gnode,*bnode;
|
|
1522 struct group *group;
|
|
1523 struct buddy *bud;
|
|
1524 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n");
|
|
1525 fprintf(file, "<gaim version=\"1\">\n");
|
|
1526 fprintf(file, "\t<blist>\n");
|
|
1527
|
|
1528 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) {
|
|
1529 if(!GAIM_BLIST_NODE_IS_GROUP(gnode))
|
|
1530 continue;
|
|
1531 group = (struct group *)gnode;
|
|
1532 if(!exp_acct || gaim_group_on_account(group, exp_acct)) {
|
|
1533 char *group_name = g_markup_escape_text(group->name, -1);
|
|
1534 fprintf(file, "\t\t<group name=\"%s\">\n", group_name);
|
|
1535 g_hash_table_foreach(group->settings, blist_print_group_settings, file);
|
|
1536 for(bnode = gnode->child; bnode; bnode = bnode->next) {
|
5234
|
1537 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) {
|
|
1538 bud = (struct buddy *)bnode;
|
|
1539 if(!exp_acct || bud->account == exp_acct) {
|
|
1540 char *bud_name = g_markup_escape_text(bud->name, -1);
|
|
1541 char *bud_alias = NULL;
|
|
1542 char *acct_name = g_markup_escape_text(bud->account->username, -1);
|
|
1543 if(bud->alias)
|
|
1544 bud_alias= g_markup_escape_text(bud->alias, -1);
|
|
1545 fprintf(file, "\t\t\t<person name=\"%s\">\n",
|
|
1546 bud_alias ? bud_alias : bud_name);
|
|
1547 fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" "
|
|
1548 "account=\"%s\">\n", bud->account->protocol,
|
|
1549 acct_name);
|
|
1550 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name);
|
|
1551 if(bud_alias) {
|
|
1552 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n",
|
|
1553 bud_alias);
|
|
1554 }
|
|
1555 g_hash_table_foreach(bud->settings,
|
|
1556 blist_print_buddy_settings, file);
|
|
1557 fprintf(file, "\t\t\t\t</buddy>\n");
|
|
1558 fprintf(file, "\t\t\t</person>\n");
|
|
1559 g_free(bud_name);
|
|
1560 g_free(bud_alias);
|
|
1561 g_free(acct_name);
|
5228
|
1562 }
|
5234
|
1563 } else if(GAIM_BLIST_NODE_IS_CHAT(bnode)) {
|
|
1564 struct chat *chat = (struct chat *)bnode;
|
|
1565 if(!exp_acct || chat->account == exp_acct) {
|
|
1566 char *acct_name = g_markup_escape_text(chat->account->username, -1);
|
|
1567 fprintf(file, "\t\t\t<chat protocol=\"%d\" account=\"%s\">\n", chat->account->protocol, acct_name);
|
5237
|
1568 if(chat->alias) {
|
|
1569 char *chat_alias = g_markup_escape_text(chat->alias, -1);
|
|
1570 fprintf(file, "\t\t\t\t<alias>%s</alias>\n", chat_alias);
|
|
1571 g_free(chat_alias);
|
|
1572 }
|
5234
|
1573 g_hash_table_foreach(chat->components,
|
|
1574 blist_print_chat_components, file);
|
|
1575 fprintf(file, "\t\t\t</chat>\n");
|
5237
|
1576 g_free(acct_name);
|
5234
|
1577 }
|
5228
|
1578 }
|
|
1579 }
|
|
1580 fprintf(file, "\t\t</group>\n");
|
|
1581 g_free(group_name);
|
|
1582 }
|
|
1583 }
|
|
1584
|
|
1585 fprintf(file, "\t</blist>\n");
|
|
1586 fprintf(file, "\t<privacy>\n");
|
|
1587
|
|
1588 for(accounts = gaim_accounts; accounts; accounts = accounts->next) {
|
|
1589 struct gaim_account *account = accounts->data;
|
|
1590 char *acct_name = g_markup_escape_text(account->username, -1);
|
|
1591 if(!exp_acct || account == exp_acct) {
|
|
1592 fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" "
|
|
1593 "mode=\"%d\">\n", account->protocol, acct_name, account->permdeny);
|
|
1594 for(buds = account->permit; buds; buds = buds->next) {
|
|
1595 char *bud_name = g_markup_escape_text(buds->data, -1);
|
|
1596 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name);
|
|
1597 g_free(bud_name);
|
|
1598 }
|
|
1599 for(buds = account->deny; buds; buds = buds->next) {
|
|
1600 char *bud_name = g_markup_escape_text(buds->data, -1);
|
|
1601 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name);
|
|
1602 g_free(bud_name);
|
|
1603 }
|
|
1604 fprintf(file, "\t\t</account>\n");
|
|
1605 }
|
|
1606 g_free(acct_name);
|
|
1607 }
|
|
1608
|
|
1609 fprintf(file, "\t</privacy>\n");
|
|
1610 fprintf(file, "</gaim>\n");
|
|
1611 }
|
|
1612
|
|
1613 void gaim_blist_save() {
|
|
1614 FILE *file;
|
|
1615 char *user_dir = gaim_user_dir();
|
|
1616 char *filename;
|
|
1617 char *filename_real;
|
|
1618
|
|
1619 if(!user_dir)
|
|
1620 return;
|
|
1621 if(!blist_safe_to_write) {
|
|
1622 gaim_debug(GAIM_DEBUG_WARNING, "blist save",
|
|
1623 "AHH!! Tried to write the blist before we read it!\n");
|
|
1624 return;
|
|
1625 }
|
|
1626
|
|
1627 file = fopen(user_dir, "r");
|
|
1628 if(!file)
|
|
1629 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR);
|
|
1630 else
|
|
1631 fclose(file);
|
|
1632
|
|
1633 filename = g_build_filename(user_dir, "blist.xml.save", NULL);
|
|
1634
|
|
1635 if((file = fopen(filename, "w"))) {
|
|
1636 gaim_blist_write(file, NULL);
|
|
1637 fclose(file);
|
|
1638 chmod(filename, S_IRUSR | S_IWUSR);
|
|
1639 } else {
|
|
1640 gaim_debug(GAIM_DEBUG_ERROR, "blist save", "Unable to write %s\n",
|
|
1641 filename);
|
|
1642 }
|
|
1643
|
|
1644 filename_real = g_build_filename(user_dir, "blist.xml", NULL);
|
|
1645
|
|
1646 if(rename(filename, filename_real) < 0)
|
|
1647 gaim_debug(GAIM_DEBUG_ERROR, "blist save",
|
|
1648 "Error renaming %s to %s\n", filename, filename_real);
|
|
1649
|
|
1650
|
|
1651 g_free(filename);
|
|
1652 g_free(filename_real);
|
|
1653 }
|
|
1654
|
|
1655 gboolean gaim_privacy_permit_add(struct gaim_account *account, const char *who) {
|
|
1656 GSList *d = account->permit;
|
|
1657 char *n = g_strdup(normalize(who));
|
|
1658 while(d) {
|
|
1659 if(!gaim_utf8_strcasecmp(n, normalize(d->data)))
|
|
1660 break;
|
|
1661 d = d->next;
|
|
1662 }
|
|
1663 g_free(n);
|
|
1664 if(!d) {
|
|
1665 account->permit = g_slist_append(account->permit, g_strdup(who));
|
|
1666 return TRUE;
|
|
1667 }
|
|
1668
|
|
1669 return FALSE;
|
|
1670 }
|
|
1671
|
|
1672 gboolean gaim_privacy_permit_remove(struct gaim_account *account, const char *who) {
|
|
1673 GSList *d = account->permit;
|
|
1674 char *n = g_strdup(normalize(who));
|
|
1675 while(d) {
|
|
1676 if(!gaim_utf8_strcasecmp(n, normalize(d->data)))
|
|
1677 break;
|
|
1678 d = d->next;
|
|
1679 }
|
|
1680 g_free(n);
|
|
1681 if(d) {
|
|
1682 account->permit = g_slist_remove(account->permit, d->data);
|
|
1683 g_free(d->data);
|
|
1684 return TRUE;
|
|
1685 }
|
|
1686 return FALSE;
|
|
1687 }
|
|
1688
|
|
1689 gboolean gaim_privacy_deny_add(struct gaim_account *account, const char *who) {
|
|
1690 GSList *d = account->deny;
|
|
1691 char *n = g_strdup(normalize(who));
|
|
1692 while(d) {
|
|
1693 if(!gaim_utf8_strcasecmp(n, normalize(d->data)))
|
|
1694 break;
|
|
1695 d = d->next;
|
|
1696 }
|
|
1697 g_free(n);
|
|
1698 if(!d) {
|
|
1699 account->deny = g_slist_append(account->deny, g_strdup(who));
|
|
1700 return TRUE;
|
|
1701 }
|
|
1702
|
|
1703 return FALSE;
|
|
1704 }
|
|
1705
|
|
1706 gboolean gaim_privacy_deny_remove(struct gaim_account *account, const char *who) {
|
|
1707 GSList *d = account->deny;
|
|
1708 char *n = g_strdup(normalize(who));
|
|
1709 while(d) {
|
|
1710 if(!gaim_utf8_strcasecmp(n, normalize(d->data)))
|
|
1711 break;
|
|
1712 d = d->next;
|
|
1713 }
|
|
1714 g_free(n);
|
|
1715 if(d) {
|
|
1716 account->deny = g_slist_remove(account->deny, d->data);
|
|
1717 g_free(d->data);
|
|
1718 return TRUE;
|
|
1719 }
|
|
1720 return FALSE;
|
|
1721 }
|
|
1722
|
|
1723 void gaim_group_set_setting(struct group *g, const char *key,
|
|
1724 const char *value) {
|
|
1725 if(!g)
|
|
1726 return;
|
|
1727 g_hash_table_replace(g->settings, g_strdup(key), g_strdup(value));
|
|
1728 }
|
|
1729
|
|
1730 char *gaim_group_get_setting(struct group *g, const char *key) {
|
|
1731 if(!g)
|
|
1732 return NULL;
|
|
1733 return g_strdup(g_hash_table_lookup(g->settings, key));
|
|
1734 }
|
|
1735
|
|
1736 void gaim_buddy_set_setting(struct buddy *b, const char *key,
|
|
1737 const char *value) {
|
|
1738 if(!b)
|
|
1739 return;
|
|
1740 g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value));
|
|
1741 }
|
|
1742
|
|
1743 char *gaim_buddy_get_setting(struct buddy *b, const char *key) {
|
|
1744 if(!b)
|
|
1745 return NULL;
|
|
1746 return g_strdup(g_hash_table_lookup(b->settings, key));
|
|
1747 }
|
|
1748
|
|
1749 void gaim_set_blist_ui_ops(struct gaim_blist_ui_ops *ops)
|
|
1750 {
|
|
1751 blist_ui_ops = ops;
|
|
1752 }
|
|
1753
|
|
1754 struct gaim_blist_ui_ops *
|
|
1755 gaim_get_blist_ui_ops(void)
|
|
1756 {
|
|
1757 return blist_ui_ops;
|
|
1758 }
|
|
1759
|
|
1760 int gaim_blist_get_group_size(struct group *group, gboolean offline) {
|
|
1761 GaimBlistNode *node;
|
|
1762 int count = 0;
|
|
1763
|
|
1764 if(!group)
|
|
1765 return 0;
|
|
1766
|
|
1767 for(node = group->node.child; node; node = node->next) {
|
|
1768 if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
|
|
1769 struct buddy *b = (struct buddy *)node;
|
|
1770 if(b->account->gc || offline)
|
|
1771 count++;
|
5234
|
1772 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
|
|
1773 struct chat *chat = (struct chat *)node;
|
|
1774 if(chat->account->gc || offline)
|
|
1775 count++;
|
5228
|
1776 }
|
|
1777 }
|
|
1778
|
|
1779 return count;
|
|
1780 }
|
|
1781
|
|
1782 int gaim_blist_get_group_online_count(struct group *group) {
|
|
1783 GaimBlistNode *node;
|
|
1784 int count = 0;
|
|
1785
|
|
1786 if(!group)
|
|
1787 return 0;
|
|
1788
|
|
1789 for(node = group->node.child; node; node = node->next) {
|
|
1790 if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
|
|
1791 struct buddy *b = (struct buddy *)node;
|
|
1792 if(GAIM_BUDDY_IS_ONLINE(b))
|
|
1793 count++;
|
5234
|
1794 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
|
|
1795 count++;
|
5228
|
1796 }
|
|
1797 }
|
|
1798
|
|
1799 return count;
|
|
1800 }
|
|
1801
|
|
1802
|