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