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