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