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