Mercurial > pidgin
annotate src/list.c @ 4523:64d03b6a0864
[gaim-migrate @ 4801]
added gtkft.c
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Wed, 05 Feb 2003 00:40:46 +0000 |
parents | 5968bcd8ddb6 |
children | 283fb289c510 |
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> | |
4349 | 26 #include <stdlib.h> |
2382 | 27 #include <sys/types.h> |
28 #include <sys/stat.h> | |
3630 | 29 #ifndef _WIN32 |
2382 | 30 #include <unistd.h> |
3630 | 31 #else |
32 #include <direct.h> | |
33 #endif | |
4349 | 34 #include <ctype.h> |
2382 | 35 #include "gaim.h" |
36 #include "prpl.h" | |
37 | |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
38 #ifdef _WIN32 |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
39 #include "win32dep.h" |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
40 #endif |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
41 |
2382 | 42 #define PATHSIZE 1024 |
43 | |
4349 | 44 void remove_buddy(struct buddy *rem_b) |
2382 | 45 { |
4491 | 46 if(rem_b->account->gc) { |
4349 | 47 struct group *rem_g = find_group_by_buddy(rem_b); |
2382 | 48 |
4349 | 49 ui_remove_buddy(rem_b); |
2382 | 50 |
4349 | 51 rem_g->members = g_slist_remove(rem_g->members, rem_b); |
2382 | 52 |
4349 | 53 g_hash_table_destroy(rem_b->settings); |
2382 | 54 |
4349 | 55 g_free(rem_b); |
56 } else { | |
57 char *buf = g_strdup_printf(_("%s was not removed from your buddy " | |
58 "list, because your account (%s) is not logged in."), | |
4491 | 59 rem_b->name, rem_b->account->username); |
4349 | 60 do_error_dialog(_("Buddy Not Removed"), buf, GAIM_ERROR); |
61 g_free(buf); | |
62 } | |
2382 | 63 } |
64 | |
4349 | 65 void remove_group(struct group *rem_g) |
2382 | 66 { |
4491 | 67 GSList *accounts; |
2382 | 68 |
4491 | 69 for(accounts = gaim_accounts; accounts; accounts = accounts->next) { |
70 struct gaim_account *account = accounts->data; | |
71 if(account->gc) { | |
4349 | 72 GList *tmp = NULL; |
73 GSList *buds = rem_g->members; | |
74 | |
75 while (buds) { | |
76 struct buddy *delb = (struct buddy *)buds->data; | |
77 buds = buds->next; | |
2382 | 78 |
4491 | 79 if(delb->account == account) { |
4349 | 80 tmp = g_list_append(tmp, g_strdup(delb->name)); |
81 remove_buddy(delb); /* this should take care of removing | |
82 the group_show if necessary */ | |
83 } | |
84 } | |
2382 | 85 |
4349 | 86 if(tmp) |
4491 | 87 serv_remove_buddies(account->gc, tmp, rem_g->name); |
2382 | 88 |
4349 | 89 while (tmp) { |
90 g_free(tmp->data); | |
91 tmp = g_list_remove(tmp, tmp->data); | |
92 } | |
93 } | |
2382 | 94 } |
95 | |
4349 | 96 if(rem_g->members) { |
97 char *buf = g_strdup_printf(_("%d buddies from group %s were not " | |
98 "removed because their accounts were not logged in. These " | |
99 "buddies, and the group were not removed.\n"), | |
100 g_slist_length(rem_g->members), rem_g->name); | |
101 do_error_dialog(_("Group Not Removed"), buf, GAIM_ERROR); | |
102 g_free(buf); | |
2382 | 103 |
4349 | 104 return; |
2382 | 105 } |
106 | |
4349 | 107 ui_remove_group(rem_g); |
108 | |
109 groups = g_slist_remove(groups, rem_g); | |
2382 | 110 |
111 g_free(rem_g); | |
112 | |
113 /* don't flush buddy list to cache in order to be consistent with remove_buddy, | |
114 * mostly. remove_group is only called from one place, so we'll let it handle it. */ | |
115 } | |
116 | |
4491 | 117 struct buddy *add_buddy(struct gaim_account *account, const char *group, const char *buddy, const char *show) |
2382 | 118 { |
119 struct buddy *b; | |
120 struct group *g; | |
3466 | 121 const char *good; |
2382 | 122 |
4491 | 123 if ((b = find_buddy(account, buddy)) != NULL) |
2382 | 124 return b; |
125 | |
4349 | 126 g = find_group(group); |
2382 | 127 |
128 if (g == NULL) | |
4349 | 129 g = add_group(group); |
2382 | 130 |
131 b = (struct buddy *)g_new0(struct buddy, 1); | |
132 | |
133 if (!b) | |
134 return NULL; | |
135 | |
4491 | 136 b->account = account; |
2382 | 137 b->present = 0; |
138 | |
4349 | 139 b->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
140 | |
141 good = buddy; | |
2382 | 142 |
143 g_snprintf(b->name, sizeof(b->name), "%s", good); | |
4227 | 144 if(show && show[0]) |
145 g_snprintf(b->alias, sizeof(b->alias), "%s", show); | |
146 else | |
147 b->alias[0] = '\0'; | |
2382 | 148 |
149 g->members = g_slist_append(g->members, b); | |
150 | |
151 b->idle = 0; | |
152 b->caps = 0; | |
153 | |
4491 | 154 ui_add_buddy(account->gc, g, b); |
2382 | 155 |
156 return b; | |
157 } | |
158 | |
4349 | 159 struct group *add_group(const char *group) |
2382 | 160 { |
4349 | 161 struct group *g = find_group(group); |
2382 | 162 if (g) |
163 return g; | |
164 g = (struct group *)g_new0(struct group, 1); | |
165 if (!g) | |
166 return NULL; | |
167 | |
168 strncpy(g->name, group, sizeof(g->name)); | |
4349 | 169 groups = g_slist_append(groups, g); |
2382 | 170 |
171 g->members = NULL; | |
172 | |
4349 | 173 ui_add_group(g); |
2382 | 174 |
175 return g; | |
176 } | |
177 | |
4349 | 178 struct group *find_group(const char *group) |
2382 | 179 { |
180 struct group *g; | |
181 GSList *grp; | |
4349 | 182 char *grpname = g_strdup(normalize(group)); |
2382 | 183 |
4349 | 184 grp = groups; |
185 while (grp) { | |
186 g = (struct group *)grp->data; | |
187 if (!g_strcasecmp(normalize (g->name), grpname)) { | |
188 g_free(grpname); | |
189 return g; | |
2382 | 190 } |
4349 | 191 grp = g_slist_next(grp); |
2382 | 192 } |
4349 | 193 g_free(grpname); |
194 return NULL; | |
2382 | 195 } |
196 | |
4349 | 197 struct group *find_group_by_buddy(struct buddy *b) |
198 { | |
199 GSList *grp = groups; | |
200 | |
201 while(grp) { | |
202 struct group *g = grp->data; | |
203 if(g_slist_find(g->members, b)) | |
204 return g; | |
205 grp = grp->next; | |
206 } | |
207 return NULL; | |
208 } | |
209 | |
4491 | 210 struct buddy *find_buddy(struct gaim_account *account, const char *who) |
2382 | 211 { |
212 struct group *g; | |
213 struct buddy *b; | |
214 GSList *grp; | |
215 GSList *mem; | |
4349 | 216 char *whoname = NULL; |
2382 | 217 char *(*norm)(const char *); |
218 | |
4349 | 219 grp = groups; |
220 while (grp) { | |
221 g = (struct group *)grp->data; | |
2382 | 222 |
4349 | 223 mem = g->members; |
224 while (mem) { | |
225 b = (struct buddy *)mem->data; | |
226 /* | |
227 norm = (b->user->gc && b->user->gc->prpl->normalize) ? b->user->gc->prpl->normalize : normalize; | |
228 */ | |
229 norm = normalize; | |
230 whoname = g_strdup(norm(who)); | |
4491 | 231 if ((b->account == account || !account) && !strcmp(norm(b->name), whoname)) { |
4349 | 232 g_free(whoname); |
233 return b; | |
2382 | 234 } |
4349 | 235 g_free(whoname); |
236 mem = mem->next; | |
2382 | 237 } |
4349 | 238 grp = g_slist_next(grp); |
2382 | 239 } |
4349 | 240 return NULL; |
2382 | 241 } |
242 | |
4491 | 243 void parse_toc_buddy_list(struct gaim_account *account, char *config) |
2382 | 244 { |
245 char *c; | |
246 char current[256]; | |
4351 | 247 GList *bud = NULL; |
4349 | 248 |
2382 | 249 |
250 if (config != NULL) { | |
4349 | 251 |
2382 | 252 /* skip "CONFIG:" (if it exists) */ |
253 c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
2998 | 254 strtok(config, "\n") : |
255 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
2382 | 256 do { |
257 if (c == NULL) | |
258 break; | |
259 if (*c == 'g') { | |
4404 | 260 char *utf8 = NULL; |
4458 | 261 utf8 = gaim_try_conv_to_utf8(c + 2); |
4404 | 262 if (utf8 == NULL) { |
263 g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
264 } else { | |
265 g_strlcpy(current, utf8, sizeof(current)); | |
266 g_free(utf8); | |
267 } | |
4349 | 268 if (!find_group(current)) { |
269 add_group(current); | |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
270 } |
4404 | 271 } else if (*c == 'b') { /*&& !find_buddy(user, c + 2)) {*/ |
4408 | 272 char nm[80], sw[BUDDY_ALIAS_MAXLEN], *a, *utf8 = NULL; |
273 | |
4404 | 274 if ((a = strchr(c + 2, ':')) != NULL) { |
275 *a++ = '\0'; /* nul the : */ | |
276 } | |
4349 | 277 |
4404 | 278 g_strlcpy(nm, c + 2, sizeof(nm)); |
279 if (a) { | |
4458 | 280 utf8 = gaim_try_conv_to_utf8(a); |
4404 | 281 if (utf8 == NULL) { |
282 debug_printf ("Failed to convert alias for '%s' to UTF-8\n", nm); | |
283 } | |
284 } | |
285 if (utf8 == NULL) { | |
286 sw[0] = '\0'; | |
287 } else { | |
4491 | 288 /* This can leave a partial sequence at the end, |
4404 | 289 * but who cares? */ |
290 g_strlcpy(sw, utf8, sizeof(sw)); | |
291 g_free(utf8); | |
292 } | |
4491 | 293 |
294 if (!find_buddy(account, nm)) { | |
295 add_buddy(account, current, nm, sw); | |
4404 | 296 bud = g_list_append(bud, nm); |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
297 } |
2382 | 298 } else if (*c == 'p') { |
4491 | 299 gaim_privacy_permit_add(account, c + 2); |
2382 | 300 } else if (*c == 'd') { |
4491 | 301 gaim_privacy_deny_add(account, c + 2); |
2382 | 302 } else if (!strncmp("toc", c, 3)) { |
4491 | 303 sscanf(c + strlen(c) - 1, "%d", &account->permdeny); |
304 debug_printf("permdeny: %d\n", account->permdeny); | |
305 if (account->permdeny == 0) | |
306 account->permdeny = 1; | |
2382 | 307 } else if (*c == 'm') { |
4491 | 308 sscanf(c + 2, "%d", &account->permdeny); |
309 debug_printf("permdeny: %d\n", account->permdeny); | |
310 if (account->permdeny == 0) | |
311 account->permdeny = 1; | |
2382 | 312 } |
313 } while ((c = strtok(NULL, "\n"))); | |
4351 | 314 |
4491 | 315 if(account->gc) { |
4351 | 316 if(bud) |
4491 | 317 serv_add_buddies(account->gc, bud); |
318 serv_set_permit_deny(account->gc); | |
4351 | 319 } |
320 g_list_free(bud); | |
2382 | 321 } |
322 } | |
323 | |
4491 | 324 void toc_build_config(struct gaim_account *account, char *s, int len, gboolean show) |
2382 | 325 { |
4349 | 326 GSList *grp = groups; |
2382 | 327 GSList *mem; |
328 struct group *g; | |
329 struct buddy *b; | |
4491 | 330 GSList *plist = account->permit; |
331 GSList *dlist = account->deny; | |
2382 | 332 |
333 int pos = 0; | |
334 | |
4491 | 335 if (!account->permdeny) |
336 account->permdeny = 1; | |
2382 | 337 |
4491 | 338 pos += g_snprintf(&s[pos], len - pos, "m %d\n", account->permdeny); |
2382 | 339 while (len > pos && grp) { |
340 g = (struct group *)grp->data; | |
4491 | 341 if(gaim_group_on_account(g, account)) { |
4349 | 342 pos += g_snprintf(&s[pos], len - pos, "g %s\n", g->name); |
343 mem = g->members; | |
344 while (len > pos && mem) { | |
345 b = (struct buddy *)mem->data; | |
4491 | 346 if(b->account == account) { |
4349 | 347 pos += g_snprintf(&s[pos], len - pos, "b %s%s%s\n", b->name, |
348 (show && b->alias[0]) ? ":" : "", | |
349 (show && b->alias[0]) ? b->alias : ""); | |
350 } | |
351 mem = mem->next; | |
352 } | |
2382 | 353 } |
354 grp = g_slist_next(grp); | |
355 } | |
356 | |
357 while (len > pos && plist) { | |
358 pos += g_snprintf(&s[pos], len - pos, "p %s\n", (char *)plist->data); | |
359 plist = plist->next; | |
360 } | |
361 | |
362 while (len > pos && dlist) { | |
363 pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data); | |
364 dlist = dlist->next; | |
365 } | |
366 } | |
367 | |
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
368 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
369 static GString *translate_lst(FILE *src_fp) |
2382 | 370 { |
371 char line[BUF_LEN], *line2; | |
372 char *name; | |
373 int i; | |
374 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
375 GString *dest = g_string_new("m 1\n"); |
2382 | 376 |
377 while (fgets(line, BUF_LEN, src_fp)) { | |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
378 line2 = g_strchug(line); |
2382 | 379 if (strstr(line2, "group") == line2) { |
380 name = strpbrk(line2, " \t\n\r\f") + 1; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
381 dest = g_string_append(dest, "g "); |
2382 | 382 for (i = 0; i < strcspn(name, "\n\r"); i++) |
383 if (name[i] != '\"') | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
384 dest = g_string_append_c(dest, name[i]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
385 dest = g_string_append_c(dest, '\n'); |
2382 | 386 } |
387 if (strstr(line2, "buddy") == line2) { | |
388 name = strpbrk(line2, " \t\n\r\f") + 1; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
389 dest = g_string_append(dest, "b "); |
2382 | 390 for (i = 0; i < strcspn(name, "\n\r"); i++) |
391 if (name[i] != '\"') | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
392 dest = g_string_append_c(dest, name[i]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
393 dest = g_string_append_c(dest, '\n'); |
2382 | 394 } |
395 } | |
396 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
397 return dest; |
2382 | 398 } |
399 | |
400 | |
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
401 /* translate an AIM 4 buddylist (*.blt) to Gaim format */ |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
402 static GString *translate_blt(FILE *src_fp) |
2382 | 403 { |
404 int i; | |
405 char line[BUF_LEN]; | |
406 char *buddy; | |
407 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
408 GString *dest = g_string_new("m 1\n"); |
2382 | 409 |
410 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
411 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
412 | |
413 while (1) { | |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
414 fgets(line, BUF_LEN, src_fp); g_strchomp(line); |
2382 | 415 if (strchr(line, '}') != NULL) |
416 break; | |
417 | |
418 if (strchr(line, '{') != NULL) { | |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
419 /* Syntax starting with "<group> {" */ |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
420 |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
421 dest = g_string_append(dest, "g "); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
422 buddy = g_strchug(strtok(line, "{")); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
423 for (i = 0; i < strlen(buddy); i++) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
424 if (buddy[i] != '\"') |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
425 dest = g_string_append_c(dest, buddy[i]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
426 dest = g_string_append_c(dest, '\n'); |
2382 | 427 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
428 gboolean pounce = FALSE; |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
429 char *e; |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
430 g_strchomp(line); |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
431 buddy = g_strchug(line); |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
432 debug_printf("\nbuddy: \"%s\"\n\n", buddy); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
433 dest = g_string_append(dest, "b "); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
434 if (strchr(buddy, '{') != NULL) { |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
435 /* buddy pounce, etc */ |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
436 char *pos = strchr(buddy, '{') - 1; |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
437 *pos = 0; |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
438 pounce = TRUE; |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
439 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
440 if ((e = strchr(buddy, '\"')) != NULL) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
441 *e = '\0'; |
2382 | 442 buddy++; |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
443 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
444 dest = g_string_append(dest, buddy); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
445 dest = g_string_append_c(dest, '\n'); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
446 if (pounce) |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
447 do |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
448 fgets(line, BUF_LEN, src_fp); |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
449 while (!strchr(line, '}')); |
2382 | 450 } |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
451 } else { |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
452 |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
453 /* Syntax "group buddy buddy ..." */ |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
454 buddy = g_strchug(strtok(line, " \n")); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
455 dest = g_string_append(dest, "g "); |
2382 | 456 if (strchr(buddy, '\"') != NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
457 dest = g_string_append(dest, &buddy[1]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
458 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
459 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 460 while (strchr(buddy, '\"') == NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
461 dest = g_string_append(dest, buddy); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
462 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
463 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 464 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
465 buddy[strlen(buddy) - 1] = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
466 dest = g_string_append(dest, buddy); |
2382 | 467 } else { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
468 dest = g_string_append(dest, buddy); |
2382 | 469 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
470 dest = g_string_append_c(dest, '\n'); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
471 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
472 dest = g_string_append(dest, "b "); |
2382 | 473 if (strchr(buddy, '\"') != NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
474 dest = g_string_append(dest, &buddy[1]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
475 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
476 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 477 while (strchr(buddy, '\"') == NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
478 dest = g_string_append(dest, buddy); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
479 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
480 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 481 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
482 buddy[strlen(buddy) - 1] = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
483 dest = g_string_append(dest, buddy); |
2382 | 484 } else { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
485 dest = g_string_append(dest, buddy); |
2382 | 486 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
487 dest = g_string_append_c(dest, '\n'); |
2382 | 488 } |
489 } | |
490 } | |
491 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
492 return dest; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
493 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
494 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
495 static GString *translate_gnomeicu(FILE *src_fp) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
496 { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
497 char line[BUF_LEN]; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
498 GString *dest = g_string_new("m 1\ng Buddies\n"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
499 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
500 while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
501 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
502 while (fgets(line, BUF_LEN, src_fp)) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
503 char *eq; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
504 g_strchomp(line); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
505 if (line[0] == '\n' || line[0] == '[') |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
506 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
507 eq = strchr(line, '='); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
508 if (!eq) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
509 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
510 *eq = ':'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
511 eq = strchr(eq, ','); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
512 if (eq) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
513 *eq = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
514 dest = g_string_append(dest, "b "); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
515 dest = g_string_append(dest, line); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
516 dest = g_string_append_c(dest, '\n'); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
517 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
518 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
519 return dest; |
2382 | 520 } |
521 | |
522 static gchar *get_screenname_filename(const char *name) | |
523 { | |
524 gchar **split; | |
525 gchar *good; | |
526 | |
527 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
528 good = g_strjoinv(NULL, split); | |
529 g_strfreev(split); | |
530 | |
531 g_strup(good); | |
532 | |
533 return good; | |
534 } | |
535 | |
4349 | 536 static gboolean gaim_blist_read(const char *filename); |
2382 | 537 |
4491 | 538 void do_import(struct gaim_account *account, const char *filename) |
2382 | 539 { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
540 GString *buf = NULL; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
541 char first[64]; |
2382 | 542 char path[PATHSIZE]; |
543 int len; | |
544 FILE *f; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
545 struct stat st; |
2382 | 546 |
547 if (filename) { | |
548 g_snprintf(path, sizeof(path), "%s", filename); | |
549 } else { | |
4491 | 550 char *g_screenname = get_screenname_filename(account->username); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
551 char *file = gaim_user_dir(); |
4491 | 552 int protocol = (account->protocol == PROTO_OSCAR) ? (isalpha(account->username[0]) ? PROTO_TOC : PROTO_ICQ): account->protocol; |
2382 | 553 |
554 if (file != (char *)NULL) { | |
4349 | 555 sprintf(path, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
2382 | 556 g_free(g_screenname); |
557 } else { | |
558 g_free(g_screenname); | |
559 return; | |
560 } | |
561 } | |
562 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
563 if (stat(path, &st)) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
564 debug_printf("Unable to stat %s.\n", path); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
565 return; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
566 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
567 |
2382 | 568 if (!(f = fopen(path, "r"))) { |
569 debug_printf("Unable to open %s.\n", path); | |
570 return; | |
571 } | |
572 | |
573 fgets(first, 64, f); | |
574 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
575 if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
576 fgets(first, 64, f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
577 |
4349 | 578 if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { |
579 /* new gaim XML buddy list */ | |
580 gaim_blist_read(path); | |
581 } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
582 /* AIM 4 buddy list */ |
2382 | 583 debug_printf("aim 4\n"); |
584 rewind(f); | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
585 buf = translate_blt(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
586 } else if (strstr(first, "group") != NULL) { |
2382 | 587 /* AIM 3 buddy list */ |
588 debug_printf("aim 3\n"); | |
589 rewind(f); | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
590 buf = translate_lst(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
591 } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
592 /* GnomeICU (hopefully) */ |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
593 debug_printf("gnomeicu\n"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
594 rewind(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
595 buf = translate_gnomeicu(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
596 } else if (first[0] == 'm') { |
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
597 /* Gaim buddy list - no translation */ |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
598 char buf2[BUF_LONG * 2]; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
599 buf = g_string_new(""); |
2382 | 600 rewind(f); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
601 while (1) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
602 len = fread(buf2, 1, BUF_LONG * 2 - 1, f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
603 if (len <= 0) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
604 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
605 buf2[len] = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
606 buf = g_string_append(buf, buf2); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
607 if (len != BUF_LONG * 2 - 1) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
608 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
609 } |
2382 | 610 } |
611 | |
612 fclose(f); | |
613 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
614 if (buf) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
615 buf = g_string_prepend(buf, "toc_set_config {"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
616 buf = g_string_append(buf, "}\n"); |
4491 | 617 parse_toc_buddy_list(account, buf->str); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
618 g_string_free(buf, TRUE); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
619 } |
2382 | 620 } |
621 | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
622 static gboolean is_blocked(struct buddy *b) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
623 { |
4491 | 624 struct gaim_account *account = b->account; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
625 |
4491 | 626 if (account->permdeny == PERMIT_ALL) |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
627 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
628 |
4491 | 629 if (account->permdeny == PERMIT_NONE) { |
630 if (account->gc && g_strcasecmp(b->name, account->gc->username)) | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
631 return TRUE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
632 else |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
633 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
634 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
635 |
4491 | 636 if (account->permdeny == PERMIT_SOME) { |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
637 char *x = g_strdup(normalize(b->name)); |
4491 | 638 GSList *s = account->permit; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
639 while (s) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
640 if (!g_strcasecmp(x, normalize(s->data))) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
641 break; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
642 s = s->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
643 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
644 g_free(x); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
645 if (s) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
646 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
647 return TRUE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
648 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
649 |
4491 | 650 if (account->permdeny == DENY_SOME) { |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
651 char *x = g_strdup(normalize(b->name)); |
4491 | 652 GSList *s = account->deny; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
653 while (s) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
654 if (!g_strcasecmp(x, normalize(s->data))) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
655 break; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
656 s = s->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
657 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
658 g_free(x); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
659 if (s) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
660 return TRUE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
661 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
662 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
663 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
664 return FALSE; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
665 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
666 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
667 void signoff_blocked(struct gaim_connection *gc) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
668 { |
4349 | 669 GSList *g = groups; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
670 while (g) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
671 GSList *m = ((struct group *)g->data)->members; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
672 while (m) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
673 struct buddy *b = m->data; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
674 if (is_blocked(b)) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
675 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
|
676 m = m->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
677 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
678 g = g->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
679 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2590
diff
changeset
|
680 } |
4227 | 681 |
682 char *get_buddy_alias_only(struct buddy *b) { | |
683 if(!b) | |
684 return NULL; | |
685 if(b->alias[0]) | |
686 return b->alias; | |
687 else if((misc_options & OPT_MISC_USE_SERVER_ALIAS) && b->server_alias[0]) | |
688 return b->server_alias; | |
689 return NULL; | |
690 } | |
691 | |
692 | |
693 char *get_buddy_alias(struct buddy *b) { | |
694 char *ret = get_buddy_alias_only(b); | |
695 if(!ret) | |
696 return b ? b->name : _("Unknown"); | |
697 return ret; | |
698 } | |
699 | |
4349 | 700 GSList *gaim_group_get_accounts(struct group *g) { |
701 GSList *buds = g->members; | |
702 GSList *ret = NULL; | |
703 while(buds) { | |
704 struct buddy *b = buds->data; | |
4491 | 705 if(!g_slist_find(ret, b->account)) |
706 ret = g_slist_append(ret, b->account); | |
4349 | 707 buds = buds->next; |
708 } | |
709 return ret; | |
710 } | |
711 | |
4491 | 712 gboolean gaim_group_on_account(struct group *g, struct gaim_account *account) { |
4349 | 713 GSList *buds = g->members; |
714 while(buds) { | |
715 struct buddy *b = buds->data; | |
4491 | 716 if((!account && b->account->gc) || b->account == account) |
4349 | 717 return TRUE; |
718 buds = buds->next; | |
719 } | |
720 return FALSE; | |
721 } | |
722 | |
4497 | 723 static gboolean blist_safe_to_write = FALSE; |
4349 | 724 |
725 static char *blist_parser_group_name = NULL; | |
726 static char *blist_parser_person_name = NULL; | |
727 static char *blist_parser_account_name = NULL; | |
728 static int blist_parser_account_protocol = 0; | |
729 static char *blist_parser_buddy_name = NULL; | |
730 static char *blist_parser_buddy_alias = NULL; | |
731 static char *blist_parser_setting_name = NULL; | |
732 static char *blist_parser_setting_value = NULL; | |
733 static GHashTable *blist_parser_buddy_settings = NULL; | |
734 static int blist_parser_privacy_mode = 0; | |
735 static enum { | |
736 BLIST_TAG_GAIM, | |
737 BLIST_TAG_BLIST, | |
738 BLIST_TAG_GROUP, | |
739 BLIST_TAG_PERSON, | |
740 BLIST_TAG_BUDDY, | |
741 BLIST_TAG_NAME, | |
742 BLIST_TAG_ALIAS, | |
743 BLIST_TAG_SETTING, | |
744 BLIST_TAG_PRIVACY, | |
745 BLIST_TAG_ACCOUNT, | |
746 BLIST_TAG_PERMIT, | |
747 BLIST_TAG_BLOCK, | |
748 BLIST_TAG_IGNORE | |
749 } blist_parser_current_tag; | |
4439 | 750 static gboolean blist_parser_error_occurred = FALSE; |
4349 | 751 |
752 static void blist_start_element_handler (GMarkupParseContext *context, | |
753 const gchar *element_name, | |
754 const gchar **attribute_names, | |
755 const gchar **attribute_values, | |
756 gpointer user_data, | |
757 GError **error) { | |
758 int i; | |
759 | |
760 if(!strcmp(element_name, "gaim")) { | |
761 blist_parser_current_tag = BLIST_TAG_GAIM; | |
762 } else if(!strcmp(element_name, "blist")) { | |
763 blist_parser_current_tag = BLIST_TAG_BLIST; | |
764 } else if(!strcmp(element_name, "group")) { | |
765 blist_parser_current_tag = BLIST_TAG_GROUP; | |
766 for(i=0; attribute_names[i]; i++) { | |
4444 | 767 if(!strcmp(attribute_names[i], "name")) { |
768 g_free(blist_parser_group_name); | |
4349 | 769 blist_parser_group_name = g_strdup(attribute_values[i]); |
4444 | 770 } |
4349 | 771 } |
772 if(blist_parser_group_name) { | |
773 add_group(blist_parser_group_name); | |
774 } | |
775 } else if(!strcmp(element_name, "person")) { | |
776 blist_parser_current_tag = BLIST_TAG_PERSON; | |
777 for(i=0; attribute_names[i]; i++) { | |
4444 | 778 if(!strcmp(attribute_names[i], "name")) { |
779 g_free(blist_parser_person_name); | |
4349 | 780 blist_parser_person_name = g_strdup(attribute_values[i]); |
4444 | 781 } |
4349 | 782 } |
783 } else if(!strcmp(element_name, "buddy")) { | |
784 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
785 for(i=0; attribute_names[i]; i++) { | |
4444 | 786 if(!strcmp(attribute_names[i], "account")) { |
787 g_free(blist_parser_account_name); | |
4349 | 788 blist_parser_account_name = g_strdup(attribute_values[i]); |
4444 | 789 } else if(!strcmp(attribute_names[i], "protocol")) { |
4349 | 790 blist_parser_account_protocol = atoi(attribute_values[i]); |
4444 | 791 } |
4349 | 792 } |
793 } else if(!strcmp(element_name, "name")) { | |
794 blist_parser_current_tag = BLIST_TAG_NAME; | |
795 } else if(!strcmp(element_name, "alias")) { | |
796 blist_parser_current_tag = BLIST_TAG_ALIAS; | |
797 } else if(!strcmp(element_name, "setting")) { | |
798 blist_parser_current_tag = BLIST_TAG_SETTING; | |
799 for(i=0; attribute_names[i]; i++) { | |
4444 | 800 if(!strcmp(attribute_names[i], "name")) { |
801 g_free(blist_parser_setting_name); | |
4349 | 802 blist_parser_setting_name = g_strdup(attribute_values[i]); |
4444 | 803 } |
4349 | 804 } |
805 } else if(!strcmp(element_name, "privacy")) { | |
806 blist_parser_current_tag = BLIST_TAG_PRIVACY; | |
807 } else if(!strcmp(element_name, "account")) { | |
808 blist_parser_current_tag = BLIST_TAG_ACCOUNT; | |
809 for(i=0; attribute_names[i]; i++) { | |
810 if(!strcmp(attribute_names[i], "protocol")) | |
811 blist_parser_account_protocol = atoi(attribute_values[i]); | |
812 else if(!strcmp(attribute_names[i], "mode")) | |
813 blist_parser_privacy_mode = atoi(attribute_values[i]); | |
4444 | 814 else if(!strcmp(attribute_names[i], "name")) { |
815 g_free(blist_parser_account_name); | |
4349 | 816 blist_parser_account_name = g_strdup(attribute_values[i]); |
4444 | 817 } |
4349 | 818 } |
819 } else if(!strcmp(element_name, "permit")) { | |
820 blist_parser_current_tag = BLIST_TAG_PERMIT; | |
821 } else if(!strcmp(element_name, "block")) { | |
822 blist_parser_current_tag = BLIST_TAG_BLOCK; | |
823 } else if(!strcmp(element_name, "ignore")) { | |
824 blist_parser_current_tag = BLIST_TAG_IGNORE; | |
825 } | |
826 } | |
827 | |
828 static void blist_end_element_handler(GMarkupParseContext *context, | |
829 const gchar *element_name, gpointer user_data, GError **error) { | |
830 if(!strcmp(element_name, "gaim")) { | |
831 } else if(!strcmp(element_name, "blist")) { | |
832 blist_parser_current_tag = BLIST_TAG_GAIM; | |
833 } else if(!strcmp(element_name, "group")) { | |
834 blist_parser_current_tag = BLIST_TAG_BLIST; | |
835 } else if(!strcmp(element_name, "person")) { | |
836 blist_parser_current_tag = BLIST_TAG_GROUP; | |
837 g_free(blist_parser_person_name); | |
838 blist_parser_person_name = NULL; | |
839 } else if(!strcmp(element_name, "buddy")) { | |
4491 | 840 struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
4349 | 841 blist_parser_account_protocol); |
4491 | 842 if(account) { |
843 struct buddy *b = add_buddy(account, blist_parser_group_name, | |
4349 | 844 blist_parser_buddy_name, blist_parser_buddy_alias); |
845 if(blist_parser_buddy_settings) { | |
846 g_hash_table_destroy(b->settings); | |
847 b->settings = blist_parser_buddy_settings; | |
848 } | |
849 } | |
850 blist_parser_current_tag = BLIST_TAG_PERSON; | |
851 g_free(blist_parser_buddy_name); | |
852 blist_parser_buddy_name = NULL; | |
853 g_free(blist_parser_buddy_alias); | |
854 blist_parser_buddy_alias = NULL; | |
855 g_free(blist_parser_account_name); | |
856 blist_parser_account_name = NULL; | |
857 blist_parser_buddy_settings = NULL; | |
858 } else if(!strcmp(element_name, "name")) { | |
859 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
860 } else if(!strcmp(element_name, "alias")) { | |
861 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
862 } else if(!strcmp(element_name, "setting")) { | |
863 if(!blist_parser_buddy_settings) | |
864 blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash, | |
865 g_str_equal, g_free, g_free); | |
866 if(blist_parser_setting_name && blist_parser_setting_value) { | |
867 g_hash_table_replace(blist_parser_buddy_settings, | |
868 g_strdup(blist_parser_setting_name), | |
869 g_strdup(blist_parser_setting_value)); | |
870 } | |
871 g_free(blist_parser_setting_name); | |
872 g_free(blist_parser_setting_value); | |
873 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
874 } else if(!strcmp(element_name, "privacy")) { | |
875 blist_parser_current_tag = BLIST_TAG_GAIM; | |
876 } else if(!strcmp(element_name, "account")) { | |
4491 | 877 struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
4349 | 878 blist_parser_account_protocol); |
4491 | 879 if(account) { |
880 account->permdeny = blist_parser_privacy_mode; | |
4349 | 881 } |
882 blist_parser_current_tag = BLIST_TAG_PRIVACY; | |
883 g_free(blist_parser_account_name); | |
884 blist_parser_account_name = NULL; | |
885 } else if(!strcmp(element_name, "permit")) { | |
4491 | 886 struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
4349 | 887 blist_parser_account_protocol); |
4491 | 888 if(account) { |
889 gaim_privacy_permit_add(account, blist_parser_buddy_name); | |
4349 | 890 } |
4444 | 891 blist_parser_current_tag = BLIST_TAG_ACCOUNT; |
4442 | 892 g_free(blist_parser_buddy_name); |
4444 | 893 blist_parser_buddy_name = NULL; |
4349 | 894 } else if(!strcmp(element_name, "block")) { |
4491 | 895 struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
4349 | 896 blist_parser_account_protocol); |
4491 | 897 if(account) { |
898 gaim_privacy_deny_add(account, blist_parser_buddy_name); | |
4349 | 899 } |
4444 | 900 blist_parser_current_tag = BLIST_TAG_ACCOUNT; |
4442 | 901 g_free(blist_parser_buddy_name); |
4444 | 902 blist_parser_buddy_name = NULL; |
4349 | 903 } else if(!strcmp(element_name, "ignore")) { |
904 /* we'll apparently do something with this later */ | |
905 blist_parser_current_tag = BLIST_TAG_ACCOUNT; | |
906 } | |
907 } | |
908 | |
909 static void blist_text_handler(GMarkupParseContext *context, const gchar *text, | |
910 gsize text_len, gpointer user_data, GError **error) { | |
911 switch(blist_parser_current_tag) { | |
912 case BLIST_TAG_NAME: | |
913 blist_parser_buddy_name = g_strndup(text, text_len); | |
914 break; | |
915 case BLIST_TAG_ALIAS: | |
916 blist_parser_buddy_alias = g_strndup(text, text_len); | |
917 break; | |
918 case BLIST_TAG_PERMIT: | |
919 case BLIST_TAG_BLOCK: | |
920 case BLIST_TAG_IGNORE: | |
921 blist_parser_buddy_name = g_strndup(text, text_len); | |
922 break; | |
923 case BLIST_TAG_SETTING: | |
924 blist_parser_setting_value = g_strndup(text, text_len); | |
925 break; | |
926 default: | |
927 break; | |
928 } | |
929 } | |
930 | |
4439 | 931 static void blist_error_handler(GMarkupParseContext *context, GError *error, |
932 gpointer user_data) { | |
933 blist_parser_error_occurred = TRUE; | |
934 debug_printf("error parsing blist.xml: %s\n", error->message); | |
935 } | |
936 | |
4349 | 937 static GMarkupParser blist_parser = { |
938 blist_start_element_handler, | |
939 blist_end_element_handler, | |
940 blist_text_handler, | |
941 NULL, | |
4439 | 942 blist_error_handler |
4349 | 943 }; |
944 | |
945 static gboolean gaim_blist_read(const char *filename) { | |
4441 | 946 gchar *contents = NULL; |
4349 | 947 gsize length; |
948 GMarkupParseContext *context; | |
949 GError *error = NULL; | |
4496 | 950 |
951 debug_printf("gaim_blist_read: reading %s\n", filename); | |
4349 | 952 if(!g_file_get_contents(filename, &contents, &length, &error)) { |
953 debug_printf("error reading blist: %s\n", error->message); | |
954 g_error_free(error); | |
955 return FALSE; | |
956 } | |
957 | |
958 context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL); | |
959 | |
960 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
961 g_markup_parse_context_free(context); | |
4441 | 962 g_free(contents); |
4349 | 963 return FALSE; |
964 } | |
965 | |
966 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
967 debug_printf("error parsing blist\n"); | |
968 g_markup_parse_context_free(context); | |
4441 | 969 g_free(contents); |
4349 | 970 return FALSE; |
971 } | |
972 | |
973 g_markup_parse_context_free(context); | |
4441 | 974 g_free(contents); |
975 | |
4439 | 976 if(blist_parser_error_occurred) |
977 return FALSE; | |
978 | |
4496 | 979 debug_printf("gaim_blist_read: finished reading %s\n", filename); |
980 | |
4349 | 981 return TRUE; |
982 } | |
983 | |
984 void gaim_blist_load() { | |
985 GSList *accts; | |
986 char *user_dir = gaim_user_dir(); | |
987 char *filename; | |
988 char *msg; | |
989 | |
4497 | 990 blist_safe_to_write = TRUE; |
991 | |
992 if(!user_dir) | |
4349 | 993 return; |
994 | |
995 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
996 | |
997 if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
998 if(!gaim_blist_read(filename)) { | |
999 msg = g_strdup_printf(_("An error was encountered parsing your " | |
1000 "buddy list. It has not been loaded.")); | |
1001 do_error_dialog(_("Buddy List Error"), msg, GAIM_ERROR); | |
1002 g_free(msg); | |
1003 } | |
4491 | 1004 } else if(g_slist_length(gaim_accounts)) { |
4349 | 1005 /* rob wants to inform the user that their buddy lists are |
1006 * being converted */ | |
1007 msg = g_strdup_printf(_("Gaim is converting your old buddy lists " | |
1008 "to a new format, which will now be located at %s"), | |
1009 filename); | |
1010 do_error_dialog(_("Converting Buddy List"), msg, GAIM_INFO); | |
1011 g_free(msg); | |
1012 | |
1013 /* now, let gtk actually display the dialog before we start anything */ | |
1014 while(gtk_events_pending()) | |
1015 gtk_main_iteration(); | |
1016 | |
1017 /* read in the old lists, then save to the new format */ | |
4491 | 1018 for(accts = gaim_accounts; accts; accts = accts->next) { |
4349 | 1019 do_import(accts->data, NULL); |
1020 } | |
1021 gaim_blist_save(); | |
1022 } | |
1023 | |
1024 g_free(filename); | |
1025 } | |
1026 | |
1027 static void blist_print_buddy_settings(gpointer key, gpointer data, | |
1028 gpointer user_data) { | |
1029 char *key_val = g_markup_escape_text(key, -1); | |
1030 char *data_val = g_markup_escape_text(data, -1); | |
1031 FILE *file = user_data; | |
1032 fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
1033 data_val); | |
1034 g_free(key_val); | |
1035 g_free(data_val); | |
1036 } | |
1037 | |
4491 | 1038 static void gaim_blist_write(FILE *file, struct gaim_account *exp_acct) { |
1039 GSList *grps, *buds, *accounts; | |
4349 | 1040 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
1041 fprintf(file, "<gaim version=\"1\">\n"); | |
1042 fprintf(file, "\t<blist>\n"); | |
1043 | |
1044 for(grps = groups; grps; grps = grps->next) { | |
1045 struct group *g = grps->data; | |
4491 | 1046 if(!exp_acct || gaim_group_on_account(g, exp_acct)) { |
4349 | 1047 char *group_name = g_markup_escape_text(g->name, -1); |
1048 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | |
1049 for(buds = g->members; buds; buds = buds->next) { | |
1050 struct buddy *b = buds->data; | |
4491 | 1051 if(!exp_acct || b->account == exp_acct) { |
4349 | 1052 char *bud_name = g_markup_escape_text(b->name, -1); |
1053 char *bud_alias = NULL; | |
4491 | 1054 char *acct_name = g_markup_escape_text(b->account->username, -1); |
4349 | 1055 if(b->alias[0]) |
1056 bud_alias= g_markup_escape_text(b->alias, -1); | |
1057 fprintf(file, "\t\t\t<person name=\"%s\">\n", | |
1058 bud_alias ? bud_alias : bud_name); | |
1059 fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" " | |
4491 | 1060 "account=\"%s\">\n", b->account->protocol, |
4349 | 1061 acct_name); |
1062 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); | |
1063 if(bud_alias) { | |
1064 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", | |
1065 bud_alias); | |
1066 } | |
1067 g_hash_table_foreach(b->settings, | |
1068 blist_print_buddy_settings, file); | |
1069 fprintf(file, "\t\t\t\t</buddy>\n"); | |
1070 fprintf(file, "\t\t\t</person>\n"); | |
1071 g_free(bud_name); | |
1072 g_free(bud_alias); | |
1073 g_free(acct_name); | |
1074 } | |
1075 } | |
1076 fprintf(file, "\t\t</group>\n"); | |
1077 g_free(group_name); | |
1078 } | |
1079 } | |
1080 | |
1081 fprintf(file, "\t</blist>\n"); | |
1082 fprintf(file, "\t<privacy>\n"); | |
1083 | |
4491 | 1084 for(accounts = gaim_accounts; accounts; accounts = accounts->next) { |
1085 struct gaim_account *account = accounts->data; | |
1086 char *acct_name = g_markup_escape_text(account->username, -1); | |
1087 if(!exp_acct || account == exp_acct) { | |
4349 | 1088 fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" " |
4491 | 1089 "mode=\"%d\">\n", account->protocol, acct_name, account->permdeny); |
1090 for(buds = account->permit; buds; buds = buds->next) { | |
4349 | 1091 char *bud_name = g_markup_escape_text(buds->data, -1); |
1092 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
1093 g_free(bud_name); | |
1094 } | |
4491 | 1095 for(buds = account->deny; buds; buds = buds->next) { |
4349 | 1096 char *bud_name = g_markup_escape_text(buds->data, -1); |
1097 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
1098 g_free(bud_name); | |
1099 } | |
1100 fprintf(file, "\t\t</account>\n"); | |
1101 } | |
4491 | 1102 g_free(acct_name); |
4349 | 1103 } |
1104 | |
1105 fprintf(file, "\t</privacy>\n"); | |
1106 fprintf(file, "</gaim>\n"); | |
1107 } | |
1108 | |
1109 void gaim_blist_save() { | |
1110 FILE *file; | |
1111 char *user_dir = gaim_user_dir(); | |
1112 char *filename; | |
1113 | |
1114 if(!user_dir) | |
1115 return; | |
1116 | |
4497 | 1117 if(!blist_safe_to_write) { |
1118 debug_printf("AHH!! tried to write the blist before we read it!\n"); | |
1119 return; | |
1120 } | |
1121 | |
4349 | 1122 file = fopen(user_dir, "r"); |
1123 if(!file) | |
1124 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
1125 else | |
1126 fclose(file); | |
1127 | |
1128 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
1129 | |
1130 if((file = fopen(filename, "w"))) { | |
1131 gaim_blist_write(file, NULL); | |
1132 fclose(file); | |
1133 chmod(filename, S_IRUSR | S_IWUSR); | |
1134 } else { | |
1135 debug_printf("unable to write %s\n", filename); | |
1136 } | |
1137 | |
1138 g_free(filename); | |
1139 } | |
1140 | |
4491 | 1141 gboolean gaim_privacy_permit_add(struct gaim_account *account, const char *who) { |
1142 GSList *d = account->permit; | |
4349 | 1143 char *n = g_strdup(normalize(who)); |
1144 while(d) { | |
1145 if(!g_strcasecmp(n, normalize(d->data))) | |
1146 break; | |
1147 d = d->next; | |
1148 } | |
1149 g_free(n); | |
1150 if(!d) { | |
4491 | 1151 account->permit = g_slist_append(account->permit, g_strdup(who)); |
4349 | 1152 return TRUE; |
1153 } | |
1154 | |
1155 return FALSE; | |
1156 } | |
1157 | |
4491 | 1158 gboolean gaim_privacy_permit_remove(struct gaim_account *account, const char *who) { |
1159 GSList *d = account->permit; | |
4349 | 1160 char *n = g_strdup(normalize(who)); |
1161 while(d) { | |
1162 if(!g_strcasecmp(n, normalize(d->data))) | |
1163 break; | |
1164 d = d->next; | |
1165 } | |
1166 g_free(n); | |
1167 if(d) { | |
4491 | 1168 account->permit = g_slist_remove(account->permit, d->data); |
4349 | 1169 g_free(d->data); |
1170 return TRUE; | |
1171 } | |
1172 return FALSE; | |
1173 } | |
1174 | |
4491 | 1175 gboolean gaim_privacy_deny_add(struct gaim_account *account, const char *who) { |
1176 GSList *d = account->deny; | |
4349 | 1177 char *n = g_strdup(normalize(who)); |
1178 while(d) { | |
1179 if(!g_strcasecmp(n, normalize(d->data))) | |
1180 break; | |
1181 d = d->next; | |
1182 } | |
1183 g_free(n); | |
1184 if(!d) { | |
4491 | 1185 account->deny = g_slist_append(account->deny, g_strdup(who)); |
4349 | 1186 return TRUE; |
1187 } | |
1188 | |
1189 return FALSE; | |
1190 } | |
1191 | |
4491 | 1192 gboolean gaim_privacy_deny_remove(struct gaim_account *account, const char *who) { |
1193 GSList *d = account->deny; | |
4349 | 1194 char *n = g_strdup(normalize(who)); |
1195 while(d) { | |
1196 if(!g_strcasecmp(n, normalize(d->data))) | |
1197 break; | |
1198 d = d->next; | |
1199 } | |
1200 g_free(n); | |
1201 if(d) { | |
4491 | 1202 account->deny = g_slist_remove(account->deny, d->data); |
4349 | 1203 g_free(d->data); |
1204 return TRUE; | |
1205 } | |
1206 return FALSE; | |
1207 } | |
1208 | |
1209 void gaim_buddy_set_setting(struct buddy *b, const char *key, | |
1210 const char *value) { | |
1211 if(!b) | |
1212 return; | |
1213 g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value)); | |
1214 } | |
1215 | |
1216 char *gaim_buddy_get_setting(struct buddy *b, const char *key) { | |
1217 if(!b) | |
1218 return NULL; | |
1219 return g_strdup(g_hash_table_lookup(b->settings, key)); | |
1220 } |