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