Mercurial > pidgin.yaz
annotate src/list.c @ 4263:74f65a3d2a1f
[gaim-migrate @ 4514]
I wanted to get this into cvs before I went to bed. Now proto-specific
themes will work. The code's a bit crude at parts and it's not as fast
as I'd like, but I can work some more on it tomorrow. Just figured you'd
want to get a look at this.
8 penguin points to whoever finds out why gtk_smiley_tree_destroy (commented
out right now, causing leakage) segfaults on me now.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 09 Jan 2003 09:41:49 +0000 |
parents | a614423c648f |
children | 0c68d402f59f |
rev | line source |
---|---|
2382 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 #include <config.h> | |
24 #endif | |
25 #include <string.h> | |
26 #include <sys/types.h> | |
27 #include <sys/stat.h> | |
3630 | 28 #ifndef _WIN32 |
2382 | 29 #include <unistd.h> |
3630 | 30 #else |
31 #include <direct.h> | |
32 #endif | |
2382 | 33 #include "gaim.h" |
34 #include "prpl.h" | |
35 | |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
36 #ifdef _WIN32 |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
37 #include "win32dep.h" |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
38 #endif |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
39 |
2382 | 40 #define PATHSIZE 1024 |
41 | |
42 void remove_buddy(struct gaim_connection *gc, struct group *rem_g, struct buddy *rem_b) | |
43 { | |
44 GSList *grp; | |
45 GSList *mem; | |
46 | |
47 struct group *delg; | |
48 struct buddy *delb; | |
49 | |
50 /* we assume that gc is not NULL and that the buddy exists somewhere within the | |
51 * gc's buddy list, therefore we can safely remove it. we need to ensure this | |
52 * via the UI | |
53 */ | |
54 | |
55 grp = g_slist_find(gc->groups, rem_g); | |
56 delg = (struct group *)grp->data; | |
57 mem = delg->members; | |
58 | |
59 mem = g_slist_find(mem, rem_b); | |
60 delb = (struct buddy *)mem->data; | |
61 | |
62 delg->members = g_slist_remove(delg->members, delb); | |
63 | |
64 ui_remove_buddy(gc, rem_g, rem_b); | |
65 | |
66 g_free(rem_b); | |
67 | |
68 /* we don't flush buddy list to cache because in the case of remove_group that would | |
69 * mean writing to the buddy list file once for each buddy, plus one more time */ | |
70 } | |
71 | |
72 void remove_group(struct gaim_connection *gc, struct group *rem_g) | |
73 { | |
74 GSList *grp; | |
75 GSList *mem; | |
76 GList *tmp = NULL; | |
77 | |
78 struct group *delg; | |
79 struct buddy *delb; | |
80 | |
81 /* we assume that the group actually does exist within the gc, and that the gc is not NULL. | |
82 * the UI is responsible for this */ | |
83 | |
84 grp = g_slist_find(gc->groups, rem_g); | |
85 delg = (struct group *)grp->data; | |
86 mem = delg->members; | |
87 | |
88 while (delg->members) { | |
89 delb = (struct buddy *)delg->members->data; | |
90 tmp = g_list_append(tmp, g_strdup(delb->name)); | |
91 remove_buddy(gc, delg, delb); /* this should take care of removing | |
92 the group_show if necessary */ | |
93 } | |
94 | |
95 gc->groups = g_slist_remove(gc->groups, delg); | |
96 | |
2681
37d80035e77f
[gaim-migrate @ 2694]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2662
diff
changeset
|
97 serv_remove_buddies(gc, tmp, rem_g->name); |
2382 | 98 while (tmp) { |
99 g_free(tmp->data); | |
100 tmp = g_list_remove(tmp, tmp->data); | |
101 } | |
102 | |
103 ui_remove_group(gc, rem_g); | |
104 | |
105 g_free(rem_g); | |
106 | |
107 /* don't flush buddy list to cache in order to be consistent with remove_buddy, | |
108 * mostly. remove_group is only called from one place, so we'll let it handle it. */ | |
109 } | |
110 | |
3466 | 111 struct buddy *add_buddy(struct gaim_connection *gc, const char *group, const char *buddy, const char *show) |
2382 | 112 { |
113 struct buddy *b; | |
114 struct group *g; | |
3466 | 115 const char *good; |
2382 | 116 |
2586
0f5390176949
[gaim-migrate @ 2599]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2548
diff
changeset
|
117 if (!g_slist_find(connections, gc)) |
0f5390176949
[gaim-migrate @ 2599]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2548
diff
changeset
|
118 return NULL; |
0f5390176949
[gaim-migrate @ 2599]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2548
diff
changeset
|
119 |
2382 | 120 if ((b = find_buddy(gc, buddy)) != NULL) |
121 return b; | |
122 | |
123 g = find_group(gc, group); | |
124 | |
125 if (g == NULL) | |
126 g = add_group(gc, group); | |
127 | |
128 b = (struct buddy *)g_new0(struct buddy, 1); | |
129 | |
130 if (!b) | |
131 return NULL; | |
132 | |
133 b->gc = gc; | |
134 b->present = 0; | |
135 | |
136 if (gc->prpl->normalize) | |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
137 good = gc->prpl->normalize(buddy); |
2382 | 138 else |
139 good = buddy; | |
140 | |
141 g_snprintf(b->name, sizeof(b->name), "%s", good); | |
4227 | 142 if(show && show[0]) |
143 g_snprintf(b->alias, sizeof(b->alias), "%s", show); | |
144 else | |
145 b->alias[0] = '\0'; | |
2382 | 146 |
147 g->members = g_slist_append(g->members, b); | |
148 | |
149 b->idle = 0; | |
150 b->caps = 0; | |
151 | |
152 ui_add_buddy(gc, g, b); | |
153 | |
154 return b; | |
155 } | |
156 | |
3466 | 157 struct group *add_group(struct gaim_connection *gc, const char *group) |
2382 | 158 { |
159 struct group *g = find_group(gc, group); | |
160 if (g) | |
161 return g; | |
2586
0f5390176949
[gaim-migrate @ 2599]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2548
diff
changeset
|
162 if (!g_slist_find(connections, gc)) |
0f5390176949
[gaim-migrate @ 2599]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2548
diff
changeset
|
163 return NULL; |
2382 | 164 g = (struct group *)g_new0(struct group, 1); |
165 if (!g) | |
166 return NULL; | |
167 | |
168 g->gc = gc; | |
169 strncpy(g->name, group, sizeof(g->name)); | |
170 gc->groups = g_slist_append(gc->groups, g); | |
171 | |
172 g->members = NULL; | |
173 | |
174 ui_add_group(gc, g); | |
175 | |
176 return g; | |
177 } | |
178 | |
3466 | 179 struct group *find_group(struct gaim_connection *gc, const char *group) |
2382 | 180 { |
181 struct group *g; | |
182 GSList *grp; | |
183 GSList *c = connections; | |
184 struct gaim_connection *z; | |
185 char *grpname = g_malloc(strlen(group) + 1); | |
186 | |
187 strcpy(grpname, normalize (group)); | |
188 if (gc) { | |
2586
0f5390176949
[gaim-migrate @ 2599]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2548
diff
changeset
|
189 if (!g_slist_find(connections, gc)) |
0f5390176949
[gaim-migrate @ 2599]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2548
diff
changeset
|
190 return NULL; |
2382 | 191 grp = gc->groups; |
192 while (grp) { | |
193 g = (struct group *)grp->data; | |
194 if (!g_strcasecmp(normalize (g->name), grpname)) { | |
195 g_free(grpname); | |
196 return g; | |
197 } | |
198 grp = g_slist_next(grp); | |
199 } | |
200 | |
201 g_free(grpname); | |
202 return NULL; | |
203 } else { | |
204 while (c) { | |
205 z = (struct gaim_connection *)c->data; | |
206 grp = z->groups; | |
207 while (grp) { | |
208 g = (struct group *)grp->data; | |
209 if (!g_strcasecmp(normalize (g->name), grpname)) { | |
210 g_free(grpname); | |
211 return g; | |
212 } | |
213 grp = g_slist_next(grp); | |
214 } | |
215 | |
216 c = c->next; | |
217 } | |
218 g_free(grpname); | |
219 return NULL; | |
220 } | |
221 } | |
222 | |
3466 | 223 struct group *find_group_by_buddy(struct gaim_connection *gc, const char *who) |
2382 | 224 { |
225 struct group *g; | |
226 struct buddy *b; | |
227 GSList *grp; | |
228 GSList *mem; | |
229 char *whoname; | |
230 char *(*norm)(const char *); | |
231 | |
232 if (gc) { | |
233 if (gc->prpl->normalize) | |
234 norm = gc->prpl->normalize; | |
235 else | |
236 norm = normalize; | |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
237 whoname = g_strdup(norm(who)); |
2382 | 238 grp = gc->groups; |
239 while (grp) { | |
240 g = (struct group *)grp->data; | |
241 | |
242 mem = g->members; | |
243 while (mem) { | |
244 b = (struct buddy *)mem->data; | |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
245 if (!strcmp(norm(b->name), whoname)) { |
2382 | 246 g_free(whoname); |
247 return g; | |
248 } | |
249 mem = mem->next; | |
250 } | |
251 grp = g_slist_next(grp); | |
252 } | |
253 g_free(whoname); | |
254 return NULL; | |
255 } else { | |
256 GSList *c = connections; | |
257 struct gaim_connection *z; | |
258 while (c) { | |
259 z = (struct gaim_connection *)c->data; | |
260 if (z->prpl->normalize) | |
261 norm = z->prpl->normalize; | |
262 else | |
263 norm = normalize; | |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
264 whoname = g_strdup(norm(who)); |
2382 | 265 grp = z->groups; |
266 while (grp) { | |
267 g = (struct group *)grp->data; | |
268 | |
269 mem = g->members; | |
270 while (mem) { | |
271 b = (struct buddy *)mem->data; | |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
272 if (!strcmp(norm(b->name), whoname)) { |
2382 | 273 g_free(whoname); |
274 return g; | |
275 } | |
276 mem = mem->next; | |
277 } | |
278 grp = g_slist_next(grp); | |
279 } | |
280 c = c->next; | |
281 g_free(whoname); | |
282 } | |
283 return NULL; | |
284 } | |
285 } | |
286 | |
3466 | 287 struct buddy *find_buddy(struct gaim_connection *gc, const char *who) |
2382 | 288 { |
289 struct group *g; | |
290 struct buddy *b; | |
291 GSList *grp; | |
292 GSList *c; | |
293 struct gaim_connection *z; | |
294 GSList *mem; | |
295 char *whoname; | |
296 char *(*norm)(const char *); | |
297 | |
298 if (gc) { | |
2586
0f5390176949
[gaim-migrate @ 2599]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2548
diff
changeset
|
299 if (!g_slist_find(connections, gc)) |
0f5390176949
[gaim-migrate @ 2599]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2548
diff
changeset
|
300 return NULL; |
2382 | 301 if (gc->prpl->normalize) |
302 norm = gc->prpl->normalize; | |
303 else | |
304 norm = normalize; | |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
305 whoname = g_strdup(norm(who)); |
2382 | 306 grp = gc->groups; |
307 while (grp) { | |
308 g = (struct group *)grp->data; | |
309 | |
310 mem = g->members; | |
311 while (mem) { | |
312 b = (struct buddy *)mem->data; | |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
313 if (!strcmp(norm(b->name), whoname)) { |
2382 | 314 g_free(whoname); |
315 return b; | |
316 } | |
317 mem = mem->next; | |
318 } | |
319 grp = g_slist_next(grp); | |
320 } | |
321 g_free(whoname); | |
322 return NULL; | |
323 } else { | |
324 c = connections; | |
325 while (c) { | |
326 z = (struct gaim_connection *)c->data; | |
327 if (z->prpl->normalize) | |
328 norm = z->prpl->normalize; | |
329 else | |
330 norm = normalize; | |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
331 whoname = g_strdup(norm(who)); |
2382 | 332 grp = z->groups; |
333 while (grp) { | |
334 g = (struct group *)grp->data; | |
335 | |
336 mem = g->members; | |
337 while (mem) { | |
338 b = (struct buddy *)mem->data; | |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
339 if (!strcmp(norm(b->name), whoname)) { |
2382 | 340 g_free(whoname); |
341 return b; | |
342 } | |
343 mem = mem->next; | |
344 } | |
345 grp = g_slist_next(grp); | |
346 } | |
347 c = c->next; | |
348 g_free(whoname); | |
349 } | |
350 return NULL; | |
351 } | |
352 } | |
353 | |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
354 void parse_toc_buddy_list(struct gaim_connection *gc, char *config) |
2382 | 355 { |
356 char *c; | |
357 char current[256]; | |
358 char *name; | |
359 GList *bud; | |
360 int how_many = 0; | |
361 | |
362 bud = NULL; | |
2998 | 363 |
2382 | 364 if (config != NULL) { |
2998 | 365 |
2382 | 366 /* skip "CONFIG:" (if it exists) */ |
367 c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
2998 | 368 strtok(config, "\n") : |
369 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
2382 | 370 do { |
371 if (c == NULL) | |
372 break; | |
373 if (*c == 'g') { | |
374 strncpy(current, c + 2, sizeof(current)); | |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
375 if (!find_group(gc, current)) { |
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
376 add_group(gc, current); |
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
377 how_many++; |
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
378 } |
2382 | 379 } else if (*c == 'b' && !find_buddy(gc, c + 2)) { |
3136 | 380 char nm[80], sw[BUDDY_ALIAS_MAXLEN], *tmp = c + 2; |
2382 | 381 int i = 0; |
2998 | 382 while (*tmp != ':' && *tmp && i < sizeof(nm) - 1) |
383 nm[i++] = *tmp++; | |
384 | |
2382 | 385 while (*tmp != ':' && *tmp) |
3048 | 386 tmp++; |
2998 | 387 |
2382 | 388 if (*tmp == ':') |
389 *tmp++ = '\0'; | |
2998 | 390 |
2382 | 391 nm[i] = '\0'; |
392 i = 0; | |
2998 | 393 while (*tmp && i < sizeof(sw) - 1) |
2382 | 394 sw[i++] = *tmp++; |
395 sw[i] = '\0'; | |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
396 if (!find_buddy(gc, nm)) { |
2382 | 397 add_buddy(gc, current, nm, sw); |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
398 how_many++; |
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
399 bud = g_list_append(bud, c + 2); |
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
400 } |
2382 | 401 } else if (*c == 'p') { |
402 GSList *d = gc->permit; | |
403 char *n; | |
404 name = g_malloc(strlen(c + 2) + 2); | |
405 g_snprintf(name, strlen(c + 2) + 1, "%s", c + 2); | |
406 n = g_strdup(normalize (name)); | |
407 while (d) { | |
408 if (!g_strcasecmp(n, normalize (d->data))) | |
2998 | 409 break; |
2382 | 410 d = d->next; |
411 } | |
412 g_free(n); | |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
413 if (!d) { |
2382 | 414 gc->permit = g_slist_append(gc->permit, name); |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
415 how_many++; |
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
416 } else |
2382 | 417 g_free(name); |
418 } else if (*c == 'd') { | |
419 GSList *d = gc->deny; | |
420 char *n; | |
421 name = g_malloc(strlen(c + 2) + 2); | |
422 g_snprintf(name, strlen(c + 2) + 1, "%s", c + 2); | |
423 n = g_strdup(normalize (name)); | |
424 while (d) { | |
425 if (!g_strcasecmp(n, normalize (d->data))) | |
2998 | 426 break; |
427 d = d->next; | |
428 } | |
429 g_free(n); | |
430 if (!d) { | |
431 gc->deny = g_slist_append(gc->deny, name); | |
432 how_many++; | |
433 } else | |
434 g_free(name); | |
2382 | 435 } else if (!strncmp("toc", c, 3)) { |
436 sscanf(c + strlen(c) - 1, "%d", &gc->permdeny); | |
437 debug_printf("permdeny: %d\n", gc->permdeny); | |
438 if (gc->permdeny == 0) | |
439 gc->permdeny = 1; | |
440 } else if (*c == 'm') { | |
441 sscanf(c + 2, "%d", &gc->permdeny); | |
442 debug_printf("permdeny: %d\n", gc->permdeny); | |
443 if (gc->permdeny == 0) | |
444 gc->permdeny = 1; | |
445 } | |
446 } while ((c = strtok(NULL, "\n"))); | |
2998 | 447 |
2382 | 448 if (bud != NULL) { |
449 serv_add_buddies(gc, bud); | |
450 g_list_free(bud); | |
451 } | |
452 serv_set_permit_deny(gc); | |
453 } | |
2998 | 454 |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
455 if (how_many != 0) |
2382 | 456 do_export(gc); |
2998 | 457 |
2382 | 458 } |
459 | |
460 void toc_build_config(struct gaim_connection *gc, char *s, int len, gboolean show) | |
461 { | |
462 GSList *grp = gc->groups; | |
463 GSList *mem; | |
464 struct group *g; | |
465 struct buddy *b; | |
466 GSList *plist = gc->permit; | |
467 GSList *dlist = gc->deny; | |
468 | |
469 int pos = 0; | |
470 | |
471 if (!gc->permdeny) | |
472 gc->permdeny = 1; | |
473 | |
474 pos += g_snprintf(&s[pos], len - pos, "m %d\n", gc->permdeny); | |
475 while (len > pos && grp) { | |
476 g = (struct group *)grp->data; | |
477 pos += g_snprintf(&s[pos], len - pos, "g %s\n", g->name); | |
478 mem = g->members; | |
479 while (len > pos && mem) { | |
480 b = (struct buddy *)mem->data; | |
481 pos += g_snprintf(&s[pos], len - pos, "b %s%s%s\n", b->name, | |
4227 | 482 (show && b->alias[0]) ? ":" : "", |
483 (show && b->alias[0]) ? b->alias : ""); | |
2382 | 484 mem = mem->next; |
485 } | |
486 grp = g_slist_next(grp); | |
487 } | |
488 | |
489 while (len > pos && plist) { | |
490 pos += g_snprintf(&s[pos], len - pos, "p %s\n", (char *)plist->data); | |
491 plist = plist->next; | |
492 } | |
493 | |
494 while (len > pos && dlist) { | |
495 pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data); | |
496 dlist = dlist->next; | |
497 } | |
498 } | |
499 | |
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
500 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
501 static GString *translate_lst(FILE *src_fp) |
2382 | 502 { |
503 char line[BUF_LEN], *line2; | |
504 char *name; | |
505 int i; | |
506 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
507 GString *dest = g_string_new("m 1\n"); |
2382 | 508 |
509 while (fgets(line, BUF_LEN, src_fp)) { | |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
510 line2 = g_strchug(line); |
2382 | 511 if (strstr(line2, "group") == line2) { |
512 name = strpbrk(line2, " \t\n\r\f") + 1; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
513 dest = g_string_append(dest, "g "); |
2382 | 514 for (i = 0; i < strcspn(name, "\n\r"); i++) |
515 if (name[i] != '\"') | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
516 dest = g_string_append_c(dest, name[i]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
517 dest = g_string_append_c(dest, '\n'); |
2382 | 518 } |
519 if (strstr(line2, "buddy") == line2) { | |
520 name = strpbrk(line2, " \t\n\r\f") + 1; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
521 dest = g_string_append(dest, "b "); |
2382 | 522 for (i = 0; i < strcspn(name, "\n\r"); i++) |
523 if (name[i] != '\"') | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
524 dest = g_string_append_c(dest, name[i]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
525 dest = g_string_append_c(dest, '\n'); |
2382 | 526 } |
527 } | |
528 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
529 return dest; |
2382 | 530 } |
531 | |
532 | |
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
533 /* translate an AIM 4 buddylist (*.blt) to Gaim format */ |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
534 static GString *translate_blt(FILE *src_fp) |
2382 | 535 { |
536 int i; | |
537 char line[BUF_LEN]; | |
538 char *buddy; | |
539 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
540 GString *dest = g_string_new("m 1\n"); |
2382 | 541 |
542 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
543 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
544 | |
545 while (1) { | |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
546 fgets(line, BUF_LEN, src_fp); g_strchomp(line); |
2382 | 547 if (strchr(line, '}') != NULL) |
548 break; | |
549 | |
550 if (strchr(line, '{') != NULL) { | |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
551 /* Syntax starting with "<group> {" */ |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
552 |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
553 dest = g_string_append(dest, "g "); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
554 buddy = g_strchug(strtok(line, "{")); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
555 for (i = 0; i < strlen(buddy); i++) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
556 if (buddy[i] != '\"') |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
557 dest = g_string_append_c(dest, buddy[i]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
558 dest = g_string_append_c(dest, '\n'); |
2382 | 559 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
560 gboolean pounce = FALSE; |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
561 char *e; |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
562 g_strchomp(line); |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
563 buddy = g_strchug(line); |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
564 debug_printf("\nbuddy: \"%s\"\n\n", buddy); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
565 dest = g_string_append(dest, "b "); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
566 if (strchr(buddy, '{') != NULL) { |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
567 /* buddy pounce, etc */ |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
568 char *pos = strchr(buddy, '{') - 1; |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
569 *pos = 0; |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
570 pounce = TRUE; |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
571 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
572 if ((e = strchr(buddy, '\"')) != NULL) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
573 *e = '\0'; |
2382 | 574 buddy++; |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
575 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
576 dest = g_string_append(dest, buddy); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
577 dest = g_string_append_c(dest, '\n'); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
578 if (pounce) |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
579 do |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
580 fgets(line, BUF_LEN, src_fp); |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
581 while (!strchr(line, '}')); |
2382 | 582 } |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
583 } else { |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
584 |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
585 /* Syntax "group buddy buddy ..." */ |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
586 buddy = g_strchug(strtok(line, " \n")); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
587 dest = g_string_append(dest, "g "); |
2382 | 588 if (strchr(buddy, '\"') != NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
589 dest = g_string_append(dest, &buddy[1]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
590 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
591 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 592 while (strchr(buddy, '\"') == NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
593 dest = g_string_append(dest, buddy); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
594 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
595 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 596 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
597 buddy[strlen(buddy) - 1] = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
598 dest = g_string_append(dest, buddy); |
2382 | 599 } else { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
600 dest = g_string_append(dest, buddy); |
2382 | 601 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
602 dest = g_string_append_c(dest, '\n'); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
603 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
604 dest = g_string_append(dest, "b "); |
2382 | 605 if (strchr(buddy, '\"') != NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
606 dest = g_string_append(dest, &buddy[1]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
607 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
608 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 609 while (strchr(buddy, '\"') == NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
610 dest = g_string_append(dest, buddy); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
611 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
612 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 613 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
614 buddy[strlen(buddy) - 1] = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
615 dest = g_string_append(dest, buddy); |
2382 | 616 } else { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
617 dest = g_string_append(dest, buddy); |
2382 | 618 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
619 dest = g_string_append_c(dest, '\n'); |
2382 | 620 } |
621 } | |
622 } | |
623 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
624 return dest; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
625 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
626 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
627 static GString *translate_gnomeicu(FILE *src_fp) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
628 { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
629 char line[BUF_LEN]; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
630 GString *dest = g_string_new("m 1\ng Buddies\n"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
631 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
632 while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
633 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
634 while (fgets(line, BUF_LEN, src_fp)) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
635 char *eq; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
636 g_strchomp(line); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
637 if (line[0] == '\n' || line[0] == '[') |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
638 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
639 eq = strchr(line, '='); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
640 if (!eq) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
641 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
642 *eq = ':'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
643 eq = strchr(eq, ','); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
644 if (eq) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
645 *eq = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
646 dest = g_string_append(dest, "b "); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
647 dest = g_string_append(dest, line); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
648 dest = g_string_append_c(dest, '\n'); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
649 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
650 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
651 return dest; |
2382 | 652 } |
653 | |
654 static gchar *get_screenname_filename(const char *name) | |
655 { | |
656 gchar **split; | |
657 gchar *good; | |
658 | |
659 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
660 good = g_strjoinv(NULL, split); | |
661 g_strfreev(split); | |
662 | |
663 g_strup(good); | |
664 | |
665 return good; | |
666 } | |
667 | |
668 /* see if a buddy list cache file for this user exists */ | |
669 | |
670 gboolean bud_list_cache_exists(struct gaim_connection *gc) | |
671 { | |
672 gboolean ret = FALSE; | |
673 char path[PATHSIZE]; | |
674 char *file; | |
675 struct stat sbuf; | |
676 char *g_screenname; | |
677 | |
678 g_screenname = get_screenname_filename(gc->username); | |
679 | |
680 file = gaim_user_dir(); | |
681 if (file != (char *)NULL) { | |
3630 | 682 g_snprintf(path, sizeof path, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, gc->protocol); |
2382 | 683 if (!stat(path, &sbuf)) { |
684 debug_printf("%s exists.\n", path); | |
685 ret = TRUE; | |
686 } else { | |
687 char path2[PATHSIZE]; | |
688 debug_printf("%s does not exist.\n", path); | |
3630 | 689 g_snprintf(path2, sizeof path2, "%s" G_DIR_SEPARATOR_S "%s.blist", file, g_screenname); |
2382 | 690 if (!stat(path2, &sbuf)) { |
691 debug_printf("%s exists, moving to %s\n", path2, path); | |
692 if (rename(path2, path)) | |
693 debug_printf("rename didn't work!\n"); | |
694 else | |
695 ret = TRUE; | |
696 } | |
697 } | |
698 } | |
699 g_free(g_screenname); | |
700 return ret; | |
701 } | |
702 | |
3466 | 703 void do_import(struct gaim_connection *gc, const char *filename) |
2382 | 704 { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
705 GString *buf = NULL; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
706 char first[64]; |
2382 | 707 char path[PATHSIZE]; |
708 int len; | |
709 FILE *f; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
710 struct stat st; |
2382 | 711 |
712 if (filename) { | |
713 g_snprintf(path, sizeof(path), "%s", filename); | |
714 } else { | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
715 char *g_screenname = get_screenname_filename(gc->username); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
716 char *file = gaim_user_dir(); |
2382 | 717 |
718 if (file != (char *)NULL) { | |
3630 | 719 sprintf(path, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, gc->protocol); |
2382 | 720 g_free(g_screenname); |
721 } else { | |
722 g_free(g_screenname); | |
723 return; | |
724 } | |
725 } | |
726 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
727 if (stat(path, &st)) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
728 debug_printf("Unable to stat %s.\n", path); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
729 return; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
730 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
731 |
2382 | 732 if (!(f = fopen(path, "r"))) { |
733 debug_printf("Unable to open %s.\n", path); | |
734 return; | |
735 } | |
736 | |
737 fgets(first, 64, f); | |
738 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
739 if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
740 fgets(first, 64, f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
741 |
2382 | 742 if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
743 /* AIM 4 buddy list */ |
2382 | 744 debug_printf("aim 4\n"); |
745 rewind(f); | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
746 buf = translate_blt(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
747 } else if (strstr(first, "group") != NULL) { |
2382 | 748 /* AIM 3 buddy list */ |
749 debug_printf("aim 3\n"); | |
750 rewind(f); | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
751 buf = translate_lst(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
752 } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
753 /* GnomeICU (hopefully) */ |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
754 debug_printf("gnomeicu\n"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
755 rewind(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
756 buf = translate_gnomeicu(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
757 } else if (first[0] == 'm') { |
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
758 /* Gaim buddy list - no translation */ |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
759 char buf2[BUF_LONG * 2]; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
760 buf = g_string_new(""); |
2382 | 761 rewind(f); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
762 while (1) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
763 len = fread(buf2, 1, BUF_LONG * 2 - 1, f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
764 if (len <= 0) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
765 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
766 buf2[len] = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
767 buf = g_string_append(buf, buf2); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
768 if (len != BUF_LONG * 2 - 1) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
769 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
770 } |
2382 | 771 } |
772 | |
773 fclose(f); | |
774 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
775 if (buf) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
776 buf = g_string_prepend(buf, "toc_set_config {"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
777 buf = g_string_append(buf, "}\n"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
778 parse_toc_buddy_list(gc, buf->str); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
779 g_string_free(buf, TRUE); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
780 } |
2382 | 781 } |
782 | |
783 void do_export(struct gaim_connection *g) | |
784 { | |
785 FILE *dir; | |
786 FILE *f; | |
787 char buf[32 * 1024]; | |
788 char *file; | |
789 char path[PATHSIZE]; | |
790 char *g_screenname; | |
791 | |
792 file = gaim_user_dir(); | |
793 if (!file) | |
794 return; | |
795 | |
796 strcpy(buf, file); | |
797 dir = fopen(buf, "r"); | |
798 if (!dir) | |
799 mkdir(buf, S_IRUSR | S_IWUSR | S_IXUSR); | |
800 else | |
801 fclose(dir); | |
802 | |
803 g_screenname = get_screenname_filename(g->username); | |
804 | |
3630 | 805 sprintf(path, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, g->protocol); |
2382 | 806 if ((f = fopen(path, "w"))) { |
807 debug_printf("writing %s\n", path); | |
808 toc_build_config(g, buf, 8192 - 1, TRUE); | |
809 fprintf(f, "%s\n", buf); | |
810 fclose(f); | |
3398 | 811 chmod(path, S_IRUSR | S_IWUSR); |
2382 | 812 } else { |
813 debug_printf("unable to write %s\n", path); | |
814 } | |
815 | |
816 g_free(g_screenname); | |
817 } | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
818 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
819 static gboolean is_blocked(struct buddy *b) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
820 { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
821 struct gaim_connection *gc = b->gc; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
822 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
823 if (gc->permdeny == PERMIT_ALL) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
824 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
825 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
826 if (gc->permdeny == PERMIT_NONE) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
827 if (g_strcasecmp(b->name, gc->displayname)) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
828 return TRUE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
829 else |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
830 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
831 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
832 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
833 if (gc->permdeny == PERMIT_SOME) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
834 char *x = g_strdup(normalize(b->name)); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
835 GSList *s = gc->permit; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
836 while (s) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
837 if (!g_strcasecmp(x, normalize(s->data))) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
838 break; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
839 s = s->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
840 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
841 g_free(x); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
842 if (s) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
843 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
844 return TRUE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
845 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
846 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
847 if (gc->permdeny == DENY_SOME) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
848 char *x = g_strdup(normalize(b->name)); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
849 GSList *s = gc->deny; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
850 while (s) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
851 if (!g_strcasecmp(x, normalize(s->data))) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
852 break; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
853 s = s->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
854 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
855 g_free(x); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
856 if (s) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
857 return TRUE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
858 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
859 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
860 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
861 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
862 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
863 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
864 void signoff_blocked(struct gaim_connection *gc) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
865 { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
866 GSList *g = gc->groups; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
867 while (g) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
868 GSList *m = ((struct group *)g->data)->members; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
869 while (m) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
870 struct buddy *b = m->data; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
871 if (is_blocked(b)) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
872 serv_got_update(gc, b->name, 0, 0, 0, 0, 0, 0); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
873 m = m->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
874 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
875 g = g->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
876 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
877 } |
4227 | 878 |
879 char *get_buddy_alias_only(struct buddy *b) { | |
880 if(!b) | |
881 return NULL; | |
882 if(b->alias[0]) | |
883 return b->alias; | |
884 else if((misc_options & OPT_MISC_USE_SERVER_ALIAS) && b->server_alias[0]) | |
885 return b->server_alias; | |
886 return NULL; | |
887 } | |
888 | |
889 | |
890 char *get_buddy_alias(struct buddy *b) { | |
891 char *ret = get_buddy_alias_only(b); | |
892 if(!ret) | |
893 return b ? b->name : _("Unknown"); | |
894 return ret; | |
895 } | |
896 |