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