annotate src/list.c @ 4673:049ea04f99d9

[gaim-migrate @ 4984] somehow I was too lazy to code this for the earlier fix. *shrug* committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 08 Mar 2003 06:51:40 +0000
parents 5968bcd8ddb6
children 283fb289c510
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /*
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 * gaim
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 *
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 *
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 * (at your option) any later version.
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 *
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 * GNU General Public License for more details.
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 *
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 *
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 */
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 #ifdef HAVE_CONFIG_H
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 #include <config.h>
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 #endif
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 #include <string.h>
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
26 #include <stdlib.h>
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 #include <sys/types.h>
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 #include <sys/stat.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3466
diff changeset
29 #ifndef _WIN32
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 #include <unistd.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3466
diff changeset
31 #else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3466
diff changeset
32 #include <direct.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3466
diff changeset
33 #endif
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
34 #include <ctype.h>
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 #include "gaim.h"
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 #include "prpl.h"
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 #define PATHSIZE 1024
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
44 void remove_buddy(struct buddy *rem_b)
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
46 if(rem_b->account->gc) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
47 struct group *rem_g = find_group_by_buddy(rem_b);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
49 ui_remove_buddy(rem_b);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
51 rem_g->members = g_slist_remove(rem_g->members, rem_b);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
53 g_hash_table_destroy(rem_b->settings);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
55 g_free(rem_b);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
56 } else {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
57 char *buf = g_strdup_printf(_("%s was not removed from your buddy "
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
58 "list, because your account (%s) is not logged in."),
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
59 rem_b->name, rem_b->account->username);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
60 do_error_dialog(_("Buddy Not Removed"), buf, GAIM_ERROR);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
61 g_free(buf);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
62 }
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
65 void remove_group(struct group *rem_g)
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
67 GSList *accounts;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
69 for(accounts = gaim_accounts; accounts; accounts = accounts->next) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
70 struct gaim_account *account = accounts->data;
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
71 if(account->gc) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
72 GList *tmp = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
73 GSList *buds = rem_g->members;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
74
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
75 while (buds) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
76 struct buddy *delb = (struct buddy *)buds->data;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
77 buds = buds->next;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
79 if(delb->account == account) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
80 tmp = g_list_append(tmp, g_strdup(delb->name));
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
81 remove_buddy(delb); /* this should take care of removing
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
82 the group_show if necessary */
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
83 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
84 }
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
86 if(tmp)
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
87 serv_remove_buddies(account->gc, tmp, rem_g->name);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
89 while (tmp) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
90 g_free(tmp->data);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
91 tmp = g_list_remove(tmp, tmp->data);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
92 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
93 }
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
96 if(rem_g->members) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
97 char *buf = g_strdup_printf(_("%d buddies from group %s were not "
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
98 "removed because their accounts were not logged in. These "
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
99 "buddies, and the group were not removed.\n"),
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
100 g_slist_length(rem_g->members), rem_g->name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
101 do_error_dialog(_("Group Not Removed"), buf, GAIM_ERROR);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
102 g_free(buf);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
104 return;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
107 ui_remove_group(rem_g);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
108
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
109 groups = g_slist_remove(groups, rem_g);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111 g_free(rem_g);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 /* don't flush buddy list to cache in order to be consistent with remove_buddy,
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114 * mostly. remove_group is only called from one place, so we'll let it handle it. */
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
115 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
117 struct buddy *add_buddy(struct gaim_account *account, const char *group, const char *buddy, const char *show)
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 struct buddy *b;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120 struct group *g;
3466
7a3f16a375a5 [gaim-migrate @ 3516]
Sean Egan <seanegan@gmail.com>
parents: 3398
diff changeset
121 const char *good;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
123 if ((b = find_buddy(account, buddy)) != NULL)
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 return b;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
126 g = find_group(group);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128 if (g == NULL)
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
129 g = add_group(group);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131 b = (struct buddy *)g_new0(struct buddy, 1);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133 if (!b)
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 return NULL;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
136 b->account = account;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137 b->present = 0;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
139 b->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
140
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
141 good = buddy;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 g_snprintf(b->name, sizeof(b->name), "%s", good);
4227
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
144 if(show && show[0])
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
145 g_snprintf(b->alias, sizeof(b->alias), "%s", show);
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
146 else
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
147 b->alias[0] = '\0';
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149 g->members = g_slist_append(g->members, b);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151 b->idle = 0;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152 b->caps = 0;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
154 ui_add_buddy(account->gc, g, b);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156 return b;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
159 struct group *add_group(const char *group)
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
161 struct group *g = find_group(group);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 if (g)
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 return g;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164 g = (struct group *)g_new0(struct group, 1);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 if (!g)
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 return NULL;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 strncpy(g->name, group, sizeof(g->name));
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
169 groups = g_slist_append(groups, g);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
170
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171 g->members = NULL;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
172
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
173 ui_add_group(g);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175 return g;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
178 struct group *find_group(const char *group)
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
179 {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180 struct group *g;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 GSList *grp;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
182 char *grpname = g_strdup(normalize(group));
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
184 grp = groups;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
185 while (grp) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
186 g = (struct group *)grp->data;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
187 if (!g_strcasecmp(normalize (g->name), grpname)) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
188 g_free(grpname);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
189 return g;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190 }
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
191 grp = g_slist_next(grp);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
192 }
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
193 g_free(grpname);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
194 return NULL;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
197 struct group *find_group_by_buddy(struct buddy *b)
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
198 {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
199 GSList *grp = groups;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
200
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
201 while(grp) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
202 struct group *g = grp->data;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
203 if(g_slist_find(g->members, b))
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
204 return g;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
205 grp = grp->next;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
206 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
207 return NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
208 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
209
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
210 struct buddy *find_buddy(struct gaim_account *account, const char *who)
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211 {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
212 struct group *g;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
213 struct buddy *b;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214 GSList *grp;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
215 GSList *mem;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
216 char *whoname = NULL;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
217 char *(*norm)(const char *);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
218
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
219 grp = groups;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
220 while (grp) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
221 g = (struct group *)grp->data;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
222
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
223 mem = g->members;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
224 while (mem) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
225 b = (struct buddy *)mem->data;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
226 /*
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
227 norm = (b->user->gc && b->user->gc->prpl->normalize) ? b->user->gc->prpl->normalize : normalize;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
228 */
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
229 norm = normalize;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
230 whoname = g_strdup(norm(who));
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
231 if ((b->account == account || !account) && !strcmp(norm(b->name), whoname)) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
232 g_free(whoname);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
233 return b;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
234 }
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
235 g_free(whoname);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
236 mem = mem->next;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
237 }
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
238 grp = g_slist_next(grp);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
239 }
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
240 return NULL;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
241 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
242
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
243 void parse_toc_buddy_list(struct gaim_account *account, char *config)
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
244 {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
245 char *c;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
246 char current[256];
4351
bd1db4c2e00b [gaim-migrate @ 4616]
Nathan Walp <nwalp@pidgin.im>
parents: 4349
diff changeset
247 GList *bud = NULL;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
248
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
249
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
250 if (config != NULL) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
251
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
252 /* skip "CONFIG:" (if it exists) */
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
253 c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ?
2998
6fe330f1b951 [gaim-migrate @ 3011]
Sean Egan <seanegan@gmail.com>
parents: 2962
diff changeset
254 strtok(config, "\n") :
6fe330f1b951 [gaim-migrate @ 3011]
Sean Egan <seanegan@gmail.com>
parents: 2962
diff changeset
255 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n");
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
256 do {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
257 if (c == NULL)
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
258 break;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
259 if (*c == 'g') {
4404
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
260 char *utf8 = NULL;
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4444
diff changeset
261 utf8 = gaim_try_conv_to_utf8(c + 2);
4404
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
262 if (utf8 == NULL) {
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
263 g_strlcpy(current, _("Invalid Groupname"), sizeof(current));
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
264 } else {
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
265 g_strlcpy(current, utf8, sizeof(current));
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
266 g_free(utf8);
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
267 }
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
268 if (!find_group(current)) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
269 add_group(current);
2526
413a81136e3a [gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2382
diff changeset
270 }
4404
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
271 } else if (*c == 'b') { /*&& !find_buddy(user, c + 2)) {*/
4408
94bf204f837e [gaim-migrate @ 4677]
Nathan Walp <nwalp@pidgin.im>
parents: 4404
diff changeset
272 char nm[80], sw[BUDDY_ALIAS_MAXLEN], *a, *utf8 = NULL;
94bf204f837e [gaim-migrate @ 4677]
Nathan Walp <nwalp@pidgin.im>
parents: 4404
diff changeset
273
4404
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
274 if ((a = strchr(c + 2, ':')) != NULL) {
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
275 *a++ = '\0'; /* nul the : */
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
276 }
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
277
4404
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
278 g_strlcpy(nm, c + 2, sizeof(nm));
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
279 if (a) {
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4444
diff changeset
280 utf8 = gaim_try_conv_to_utf8(a);
4404
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
281 if (utf8 == NULL) {
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
282 debug_printf ("Failed to convert alias for '%s' to UTF-8\n", nm);
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
283 }
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
284 }
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
285 if (utf8 == NULL) {
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
286 sw[0] = '\0';
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
287 } else {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
288 /* This can leave a partial sequence at the end,
4404
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
289 * but who cares? */
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
290 g_strlcpy(sw, utf8, sizeof(sw));
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
291 g_free(utf8);
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
292 }
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
293
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
294 if (!find_buddy(account, nm)) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
295 add_buddy(account, current, nm, sw);
4404
16f7f9451814 [gaim-migrate @ 4673]
Mark Doliner <mark@kingant.net>
parents: 4352
diff changeset
296 bud = g_list_append(bud, nm);
2526
413a81136e3a [gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2382
diff changeset
297 }
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
298 } else if (*c == 'p') {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
299 gaim_privacy_permit_add(account, c + 2);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
300 } else if (*c == 'd') {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
301 gaim_privacy_deny_add(account, c + 2);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
302 } else if (!strncmp("toc", c, 3)) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
303 sscanf(c + strlen(c) - 1, "%d", &account->permdeny);
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
304 debug_printf("permdeny: %d\n", account->permdeny);
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
305 if (account->permdeny == 0)
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
306 account->permdeny = 1;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
307 } else if (*c == 'm') {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
308 sscanf(c + 2, "%d", &account->permdeny);
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
309 debug_printf("permdeny: %d\n", account->permdeny);
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
310 if (account->permdeny == 0)
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
311 account->permdeny = 1;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
312 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
313 } while ((c = strtok(NULL, "\n")));
4351
bd1db4c2e00b [gaim-migrate @ 4616]
Nathan Walp <nwalp@pidgin.im>
parents: 4349
diff changeset
314
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
315 if(account->gc) {
4351
bd1db4c2e00b [gaim-migrate @ 4616]
Nathan Walp <nwalp@pidgin.im>
parents: 4349
diff changeset
316 if(bud)
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
317 serv_add_buddies(account->gc, bud);
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
318 serv_set_permit_deny(account->gc);
4351
bd1db4c2e00b [gaim-migrate @ 4616]
Nathan Walp <nwalp@pidgin.im>
parents: 4349
diff changeset
319 }
bd1db4c2e00b [gaim-migrate @ 4616]
Nathan Walp <nwalp@pidgin.im>
parents: 4349
diff changeset
320 g_list_free(bud);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
321 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
322 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
323
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
324 void toc_build_config(struct gaim_account *account, char *s, int len, gboolean show)
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
325 {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
326 GSList *grp = groups;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
327 GSList *mem;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
328 struct group *g;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
329 struct buddy *b;
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
330 GSList *plist = account->permit;
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
331 GSList *dlist = account->deny;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
332
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
333 int pos = 0;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
334
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
335 if (!account->permdeny)
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
336 account->permdeny = 1;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
337
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
338 pos += g_snprintf(&s[pos], len - pos, "m %d\n", account->permdeny);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
339 while (len > pos && grp) {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
340 g = (struct group *)grp->data;
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
341 if(gaim_group_on_account(g, account)) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
342 pos += g_snprintf(&s[pos], len - pos, "g %s\n", g->name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
343 mem = g->members;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
344 while (len > pos && mem) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
345 b = (struct buddy *)mem->data;
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
346 if(b->account == account) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
347 pos += g_snprintf(&s[pos], len - pos, "b %s%s%s\n", b->name,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
348 (show && b->alias[0]) ? ":" : "",
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
349 (show && b->alias[0]) ? b->alias : "");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
350 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
351 mem = mem->next;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
352 }
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
353 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
354 grp = g_slist_next(grp);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
355 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
356
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
357 while (len > pos && plist) {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
358 pos += g_snprintf(&s[pos], len - pos, "p %s\n", (char *)plist->data);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
359 plist = plist->next;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
360 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
361
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
362 while (len > pos && dlist) {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
363 pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
364 dlist = dlist->next;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
365 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
366 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
370 {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
371 char line[BUF_LEN], *line2;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
372 char *name;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
373 int i;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
376
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
379 if (strstr(line2, "group") == line2) {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
382 for (i = 0; i < strcspn(name, "\n\r"); i++)
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
386 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
387 if (strstr(line2, "buddy") == line2) {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
390 for (i = 0; i < strcspn(name, "\n\r"); i++)
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
394 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
395 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
396
2825
8cd878c14090 [gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2681
diff changeset
397 return dest;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
398 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
399
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
403 {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
404 int i;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
405 char line[BUF_LEN];
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
406 char *buddy;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
409
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
410 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
411 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
412
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
415 if (strchr(line, '}') != NULL)
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
416 break;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
417
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
467 } else {
2825
8cd878c14090 [gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2681
diff changeset
468 dest = g_string_append(dest, buddy);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
484 } else {
2825
8cd878c14090 [gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2681
diff changeset
485 dest = g_string_append(dest, buddy);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
486 }
2825
8cd878c14090 [gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2681
diff changeset
487 dest = g_string_append_c(dest, '\n');
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
488 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
489 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
490 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
520 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
521
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
522 static gchar *get_screenname_filename(const char *name)
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
523 {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
524 gchar **split;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
525 gchar *good;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
526
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
527 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
528 good = g_strjoinv(NULL, split);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
529 g_strfreev(split);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
530
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
531 g_strup(good);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
532
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
533 return good;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
534 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
535
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
536 static gboolean gaim_blist_read(const char *filename);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
537
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
538 void do_import(struct gaim_account *account, const char *filename)
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
542 char path[PATHSIZE];
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
543 int len;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
544 FILE *f;
2825
8cd878c14090 [gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2681
diff changeset
545 struct stat st;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
546
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
547 if (filename) {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
548 g_snprintf(path, sizeof(path), "%s", filename);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
549 } else {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
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
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
552 int protocol = (account->protocol == PROTO_OSCAR) ? (isalpha(account->username[0]) ? PROTO_TOC : PROTO_ICQ): account->protocol;
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
553
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
554 if (file != (char *)NULL) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
555 sprintf(path, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol);
2382
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
556 g_free(g_screenname);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
557 } else {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
558 g_free(g_screenname);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
559 return;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
560 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
561 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
568 if (!(f = fopen(path, "r"))) {
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
569 debug_printf("Unable to open %s.\n", path);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
570 return;
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
571 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
572
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
573 fgets(first, 64, f);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
578 if (!g_strncasecmp(first, "<xml", strlen("<xml"))) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
579 /* new gaim XML buddy list */
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
580 gaim_blist_read(path);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
583 debug_printf("aim 4\n");
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
587 /* AIM 3 buddy list */
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
588 debug_printf("aim 3\n");
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
610 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
611
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
612 fclose(f);
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
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
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
620 }
569ae9f2bb89 [gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
624 struct gaim_account *account = b->account;
2597
2ced57c58653 [gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2590
diff changeset
625
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
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
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
629 if (account->permdeny == PERMIT_NONE) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
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
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
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
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
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
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
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
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
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
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
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
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
681
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
682 char *get_buddy_alias_only(struct buddy *b) {
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
683 if(!b)
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
684 return NULL;
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
685 if(b->alias[0])
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
686 return b->alias;
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
687 else if((misc_options & OPT_MISC_USE_SERVER_ALIAS) && b->server_alias[0])
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
688 return b->server_alias;
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
689 return NULL;
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
690 }
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
691
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
692
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
693 char *get_buddy_alias(struct buddy *b) {
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
694 char *ret = get_buddy_alias_only(b);
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
695 if(!ret)
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
696 return b ? b->name : _("Unknown");
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
697 return ret;
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
698 }
a614423c648f [gaim-migrate @ 4471]
Mark Doliner <mark@kingant.net>
parents: 3717
diff changeset
699
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
700 GSList *gaim_group_get_accounts(struct group *g) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
701 GSList *buds = g->members;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
702 GSList *ret = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
703 while(buds) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
704 struct buddy *b = buds->data;
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
705 if(!g_slist_find(ret, b->account))
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
706 ret = g_slist_append(ret, b->account);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
707 buds = buds->next;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
708 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
709 return ret;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
710 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
711
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
712 gboolean gaim_group_on_account(struct group *g, struct gaim_account *account) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
713 GSList *buds = g->members;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
714 while(buds) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
715 struct buddy *b = buds->data;
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
716 if((!account && b->account->gc) || b->account == account)
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
717 return TRUE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
718 buds = buds->next;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
719 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
720 return FALSE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
721 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
722
4497
5968bcd8ddb6 [gaim-migrate @ 4772]
Nathan Walp <nwalp@pidgin.im>
parents: 4496
diff changeset
723 static gboolean blist_safe_to_write = FALSE;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
724
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
725 static char *blist_parser_group_name = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
726 static char *blist_parser_person_name = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
727 static char *blist_parser_account_name = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
728 static int blist_parser_account_protocol = 0;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
729 static char *blist_parser_buddy_name = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
730 static char *blist_parser_buddy_alias = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
731 static char *blist_parser_setting_name = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
732 static char *blist_parser_setting_value = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
733 static GHashTable *blist_parser_buddy_settings = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
734 static int blist_parser_privacy_mode = 0;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
735 static enum {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
736 BLIST_TAG_GAIM,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
737 BLIST_TAG_BLIST,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
738 BLIST_TAG_GROUP,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
739 BLIST_TAG_PERSON,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
740 BLIST_TAG_BUDDY,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
741 BLIST_TAG_NAME,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
742 BLIST_TAG_ALIAS,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
743 BLIST_TAG_SETTING,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
744 BLIST_TAG_PRIVACY,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
745 BLIST_TAG_ACCOUNT,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
746 BLIST_TAG_PERMIT,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
747 BLIST_TAG_BLOCK,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
748 BLIST_TAG_IGNORE
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
749 } blist_parser_current_tag;
4439
7693d84255e7 [gaim-migrate @ 4714]
Nathan Walp <nwalp@pidgin.im>
parents: 4408
diff changeset
750 static gboolean blist_parser_error_occurred = FALSE;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
751
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
752 static void blist_start_element_handler (GMarkupParseContext *context,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
753 const gchar *element_name,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
754 const gchar **attribute_names,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
755 const gchar **attribute_values,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
756 gpointer user_data,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
757 GError **error) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
758 int i;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
759
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
760 if(!strcmp(element_name, "gaim")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
761 blist_parser_current_tag = BLIST_TAG_GAIM;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
762 } else if(!strcmp(element_name, "blist")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
763 blist_parser_current_tag = BLIST_TAG_BLIST;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
764 } else if(!strcmp(element_name, "group")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
765 blist_parser_current_tag = BLIST_TAG_GROUP;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
766 for(i=0; attribute_names[i]; i++) {
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
767 if(!strcmp(attribute_names[i], "name")) {
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
768 g_free(blist_parser_group_name);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
769 blist_parser_group_name = g_strdup(attribute_values[i]);
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
770 }
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
771 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
772 if(blist_parser_group_name) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
773 add_group(blist_parser_group_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
774 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
775 } else if(!strcmp(element_name, "person")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
776 blist_parser_current_tag = BLIST_TAG_PERSON;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
777 for(i=0; attribute_names[i]; i++) {
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
778 if(!strcmp(attribute_names[i], "name")) {
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
779 g_free(blist_parser_person_name);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
780 blist_parser_person_name = g_strdup(attribute_values[i]);
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
781 }
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
782 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
783 } else if(!strcmp(element_name, "buddy")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
784 blist_parser_current_tag = BLIST_TAG_BUDDY;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
785 for(i=0; attribute_names[i]; i++) {
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
786 if(!strcmp(attribute_names[i], "account")) {
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
787 g_free(blist_parser_account_name);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
788 blist_parser_account_name = g_strdup(attribute_values[i]);
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
789 } else if(!strcmp(attribute_names[i], "protocol")) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
790 blist_parser_account_protocol = atoi(attribute_values[i]);
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
791 }
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
792 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
793 } else if(!strcmp(element_name, "name")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
794 blist_parser_current_tag = BLIST_TAG_NAME;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
795 } else if(!strcmp(element_name, "alias")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
796 blist_parser_current_tag = BLIST_TAG_ALIAS;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
797 } else if(!strcmp(element_name, "setting")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
798 blist_parser_current_tag = BLIST_TAG_SETTING;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
799 for(i=0; attribute_names[i]; i++) {
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
800 if(!strcmp(attribute_names[i], "name")) {
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
801 g_free(blist_parser_setting_name);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
802 blist_parser_setting_name = g_strdup(attribute_values[i]);
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
803 }
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
804 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
805 } else if(!strcmp(element_name, "privacy")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
806 blist_parser_current_tag = BLIST_TAG_PRIVACY;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
807 } else if(!strcmp(element_name, "account")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
808 blist_parser_current_tag = BLIST_TAG_ACCOUNT;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
809 for(i=0; attribute_names[i]; i++) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
810 if(!strcmp(attribute_names[i], "protocol"))
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
811 blist_parser_account_protocol = atoi(attribute_values[i]);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
812 else if(!strcmp(attribute_names[i], "mode"))
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
813 blist_parser_privacy_mode = atoi(attribute_values[i]);
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
814 else if(!strcmp(attribute_names[i], "name")) {
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
815 g_free(blist_parser_account_name);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
816 blist_parser_account_name = g_strdup(attribute_values[i]);
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
817 }
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
818 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
819 } else if(!strcmp(element_name, "permit")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
820 blist_parser_current_tag = BLIST_TAG_PERMIT;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
821 } else if(!strcmp(element_name, "block")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
822 blist_parser_current_tag = BLIST_TAG_BLOCK;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
823 } else if(!strcmp(element_name, "ignore")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
824 blist_parser_current_tag = BLIST_TAG_IGNORE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
825 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
826 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
827
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
828 static void blist_end_element_handler(GMarkupParseContext *context,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
829 const gchar *element_name, gpointer user_data, GError **error) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
830 if(!strcmp(element_name, "gaim")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
831 } else if(!strcmp(element_name, "blist")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
832 blist_parser_current_tag = BLIST_TAG_GAIM;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
833 } else if(!strcmp(element_name, "group")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
834 blist_parser_current_tag = BLIST_TAG_BLIST;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
835 } else if(!strcmp(element_name, "person")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
836 blist_parser_current_tag = BLIST_TAG_GROUP;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
837 g_free(blist_parser_person_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
838 blist_parser_person_name = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
839 } else if(!strcmp(element_name, "buddy")) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
840 struct gaim_account *account = gaim_account_find(blist_parser_account_name,
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
841 blist_parser_account_protocol);
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
842 if(account) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
843 struct buddy *b = add_buddy(account, blist_parser_group_name,
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
844 blist_parser_buddy_name, blist_parser_buddy_alias);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
845 if(blist_parser_buddy_settings) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
846 g_hash_table_destroy(b->settings);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
847 b->settings = blist_parser_buddy_settings;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
848 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
849 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
850 blist_parser_current_tag = BLIST_TAG_PERSON;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
851 g_free(blist_parser_buddy_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
852 blist_parser_buddy_name = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
853 g_free(blist_parser_buddy_alias);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
854 blist_parser_buddy_alias = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
855 g_free(blist_parser_account_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
856 blist_parser_account_name = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
857 blist_parser_buddy_settings = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
858 } else if(!strcmp(element_name, "name")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
859 blist_parser_current_tag = BLIST_TAG_BUDDY;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
860 } else if(!strcmp(element_name, "alias")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
861 blist_parser_current_tag = BLIST_TAG_BUDDY;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
862 } else if(!strcmp(element_name, "setting")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
863 if(!blist_parser_buddy_settings)
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
864 blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
865 g_str_equal, g_free, g_free);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
866 if(blist_parser_setting_name && blist_parser_setting_value) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
867 g_hash_table_replace(blist_parser_buddy_settings,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
868 g_strdup(blist_parser_setting_name),
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
869 g_strdup(blist_parser_setting_value));
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
870 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
871 g_free(blist_parser_setting_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
872 g_free(blist_parser_setting_value);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
873 blist_parser_current_tag = BLIST_TAG_BUDDY;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
874 } else if(!strcmp(element_name, "privacy")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
875 blist_parser_current_tag = BLIST_TAG_GAIM;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
876 } else if(!strcmp(element_name, "account")) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
877 struct gaim_account *account = gaim_account_find(blist_parser_account_name,
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
878 blist_parser_account_protocol);
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
879 if(account) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
880 account->permdeny = blist_parser_privacy_mode;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
881 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
882 blist_parser_current_tag = BLIST_TAG_PRIVACY;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
883 g_free(blist_parser_account_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
884 blist_parser_account_name = NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
885 } else if(!strcmp(element_name, "permit")) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
886 struct gaim_account *account = gaim_account_find(blist_parser_account_name,
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
887 blist_parser_account_protocol);
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
888 if(account) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
889 gaim_privacy_permit_add(account, blist_parser_buddy_name);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
890 }
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
891 blist_parser_current_tag = BLIST_TAG_ACCOUNT;
4442
fd53864d880f [gaim-migrate @ 4717]
Nathan Walp <nwalp@pidgin.im>
parents: 4441
diff changeset
892 g_free(blist_parser_buddy_name);
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
893 blist_parser_buddy_name = NULL;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
894 } else if(!strcmp(element_name, "block")) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
895 struct gaim_account *account = gaim_account_find(blist_parser_account_name,
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
896 blist_parser_account_protocol);
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
897 if(account) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
898 gaim_privacy_deny_add(account, blist_parser_buddy_name);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
899 }
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
900 blist_parser_current_tag = BLIST_TAG_ACCOUNT;
4442
fd53864d880f [gaim-migrate @ 4717]
Nathan Walp <nwalp@pidgin.im>
parents: 4441
diff changeset
901 g_free(blist_parser_buddy_name);
4444
fd83159169db [gaim-migrate @ 4719]
Nathan Walp <nwalp@pidgin.im>
parents: 4442
diff changeset
902 blist_parser_buddy_name = NULL;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
903 } else if(!strcmp(element_name, "ignore")) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
904 /* we'll apparently do something with this later */
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
905 blist_parser_current_tag = BLIST_TAG_ACCOUNT;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
906 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
907 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
908
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
909 static void blist_text_handler(GMarkupParseContext *context, const gchar *text,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
910 gsize text_len, gpointer user_data, GError **error) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
911 switch(blist_parser_current_tag) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
912 case BLIST_TAG_NAME:
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
913 blist_parser_buddy_name = g_strndup(text, text_len);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
914 break;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
915 case BLIST_TAG_ALIAS:
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
916 blist_parser_buddy_alias = g_strndup(text, text_len);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
917 break;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
918 case BLIST_TAG_PERMIT:
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
919 case BLIST_TAG_BLOCK:
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
920 case BLIST_TAG_IGNORE:
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
921 blist_parser_buddy_name = g_strndup(text, text_len);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
922 break;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
923 case BLIST_TAG_SETTING:
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
924 blist_parser_setting_value = g_strndup(text, text_len);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
925 break;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
926 default:
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
927 break;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
928 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
929 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
930
4439
7693d84255e7 [gaim-migrate @ 4714]
Nathan Walp <nwalp@pidgin.im>
parents: 4408
diff changeset
931 static void blist_error_handler(GMarkupParseContext *context, GError *error,
7693d84255e7 [gaim-migrate @ 4714]
Nathan Walp <nwalp@pidgin.im>
parents: 4408
diff changeset
932 gpointer user_data) {
7693d84255e7 [gaim-migrate @ 4714]
Nathan Walp <nwalp@pidgin.im>
parents: 4408
diff changeset
933 blist_parser_error_occurred = TRUE;
7693d84255e7 [gaim-migrate @ 4714]
Nathan Walp <nwalp@pidgin.im>
parents: 4408
diff changeset
934 debug_printf("error parsing blist.xml: %s\n", error->message);
7693d84255e7 [gaim-migrate @ 4714]
Nathan Walp <nwalp@pidgin.im>
parents: 4408
diff changeset
935 }
7693d84255e7 [gaim-migrate @ 4714]
Nathan Walp <nwalp@pidgin.im>
parents: 4408
diff changeset
936
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
937 static GMarkupParser blist_parser = {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
938 blist_start_element_handler,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
939 blist_end_element_handler,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
940 blist_text_handler,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
941 NULL,
4439
7693d84255e7 [gaim-migrate @ 4714]
Nathan Walp <nwalp@pidgin.im>
parents: 4408
diff changeset
942 blist_error_handler
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
943 };
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
944
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
945 static gboolean gaim_blist_read(const char *filename) {
4441
474a0a88dd5e [gaim-migrate @ 4716]
Nathan Walp <nwalp@pidgin.im>
parents: 4439
diff changeset
946 gchar *contents = NULL;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
947 gsize length;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
948 GMarkupParseContext *context;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
949 GError *error = NULL;
4496
71e8b8e62a54 [gaim-migrate @ 4771]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
950
71e8b8e62a54 [gaim-migrate @ 4771]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
951 debug_printf("gaim_blist_read: reading %s\n", filename);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
952 if(!g_file_get_contents(filename, &contents, &length, &error)) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
953 debug_printf("error reading blist: %s\n", error->message);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
954 g_error_free(error);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
955 return FALSE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
956 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
957
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
958 context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
959
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
960 if(!g_markup_parse_context_parse(context, contents, length, NULL)) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
961 g_markup_parse_context_free(context);
4441
474a0a88dd5e [gaim-migrate @ 4716]
Nathan Walp <nwalp@pidgin.im>
parents: 4439
diff changeset
962 g_free(contents);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
963 return FALSE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
964 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
965
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
966 if(!g_markup_parse_context_end_parse(context, NULL)) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
967 debug_printf("error parsing blist\n");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
968 g_markup_parse_context_free(context);
4441
474a0a88dd5e [gaim-migrate @ 4716]
Nathan Walp <nwalp@pidgin.im>
parents: 4439
diff changeset
969 g_free(contents);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
970 return FALSE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
971 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
972
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
973 g_markup_parse_context_free(context);
4441
474a0a88dd5e [gaim-migrate @ 4716]
Nathan Walp <nwalp@pidgin.im>
parents: 4439
diff changeset
974 g_free(contents);
474a0a88dd5e [gaim-migrate @ 4716]
Nathan Walp <nwalp@pidgin.im>
parents: 4439
diff changeset
975
4439
7693d84255e7 [gaim-migrate @ 4714]
Nathan Walp <nwalp@pidgin.im>
parents: 4408
diff changeset
976 if(blist_parser_error_occurred)
7693d84255e7 [gaim-migrate @ 4714]
Nathan Walp <nwalp@pidgin.im>
parents: 4408
diff changeset
977 return FALSE;
7693d84255e7 [gaim-migrate @ 4714]
Nathan Walp <nwalp@pidgin.im>
parents: 4408
diff changeset
978
4496
71e8b8e62a54 [gaim-migrate @ 4771]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
979 debug_printf("gaim_blist_read: finished reading %s\n", filename);
71e8b8e62a54 [gaim-migrate @ 4771]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
980
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
981 return TRUE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
982 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
983
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
984 void gaim_blist_load() {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
985 GSList *accts;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
986 char *user_dir = gaim_user_dir();
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
987 char *filename;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
988 char *msg;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
989
4497
5968bcd8ddb6 [gaim-migrate @ 4772]
Nathan Walp <nwalp@pidgin.im>
parents: 4496
diff changeset
990 blist_safe_to_write = TRUE;
5968bcd8ddb6 [gaim-migrate @ 4772]
Nathan Walp <nwalp@pidgin.im>
parents: 4496
diff changeset
991
5968bcd8ddb6 [gaim-migrate @ 4772]
Nathan Walp <nwalp@pidgin.im>
parents: 4496
diff changeset
992 if(!user_dir)
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
993 return;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
994
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
995 filename = g_build_filename(user_dir, "blist.xml", NULL);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
996
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
997 if(g_file_test(filename, G_FILE_TEST_EXISTS)) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
998 if(!gaim_blist_read(filename)) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
999 msg = g_strdup_printf(_("An error was encountered parsing your "
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1000 "buddy list. It has not been loaded."));
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1001 do_error_dialog(_("Buddy List Error"), msg, GAIM_ERROR);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1002 g_free(msg);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1003 }
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1004 } else if(g_slist_length(gaim_accounts)) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1005 /* rob wants to inform the user that their buddy lists are
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1006 * being converted */
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1007 msg = g_strdup_printf(_("Gaim is converting your old buddy lists "
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1008 "to a new format, which will now be located at %s"),
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1009 filename);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1010 do_error_dialog(_("Converting Buddy List"), msg, GAIM_INFO);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1011 g_free(msg);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1012
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1013 /* now, let gtk actually display the dialog before we start anything */
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1014 while(gtk_events_pending())
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1015 gtk_main_iteration();
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1016
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1017 /* read in the old lists, then save to the new format */
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1018 for(accts = gaim_accounts; accts; accts = accts->next) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1019 do_import(accts->data, NULL);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1020 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1021 gaim_blist_save();
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1022 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1023
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1024 g_free(filename);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1025 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1026
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1027 static void blist_print_buddy_settings(gpointer key, gpointer data,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1028 gpointer user_data) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1029 char *key_val = g_markup_escape_text(key, -1);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1030 char *data_val = g_markup_escape_text(data, -1);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1031 FILE *file = user_data;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1032 fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1033 data_val);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1034 g_free(key_val);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1035 g_free(data_val);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1036 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1037
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1038 static void gaim_blist_write(FILE *file, struct gaim_account *exp_acct) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1039 GSList *grps, *buds, *accounts;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1040 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1041 fprintf(file, "<gaim version=\"1\">\n");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1042 fprintf(file, "\t<blist>\n");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1043
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1044 for(grps = groups; grps; grps = grps->next) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1045 struct group *g = grps->data;
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1046 if(!exp_acct || gaim_group_on_account(g, exp_acct)) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1047 char *group_name = g_markup_escape_text(g->name, -1);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1048 fprintf(file, "\t\t<group name=\"%s\">\n", group_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1049 for(buds = g->members; buds; buds = buds->next) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1050 struct buddy *b = buds->data;
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1051 if(!exp_acct || b->account == exp_acct) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1052 char *bud_name = g_markup_escape_text(b->name, -1);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1053 char *bud_alias = NULL;
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1054 char *acct_name = g_markup_escape_text(b->account->username, -1);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1055 if(b->alias[0])
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1056 bud_alias= g_markup_escape_text(b->alias, -1);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1057 fprintf(file, "\t\t\t<person name=\"%s\">\n",
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1058 bud_alias ? bud_alias : bud_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1059 fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" "
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1060 "account=\"%s\">\n", b->account->protocol,
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1061 acct_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1062 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1063 if(bud_alias) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1064 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n",
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1065 bud_alias);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1066 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1067 g_hash_table_foreach(b->settings,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1068 blist_print_buddy_settings, file);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1069 fprintf(file, "\t\t\t\t</buddy>\n");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1070 fprintf(file, "\t\t\t</person>\n");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1071 g_free(bud_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1072 g_free(bud_alias);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1073 g_free(acct_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1074 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1075 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1076 fprintf(file, "\t\t</group>\n");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1077 g_free(group_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1078 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1079 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1080
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1081 fprintf(file, "\t</blist>\n");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1082 fprintf(file, "\t<privacy>\n");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1083
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1084 for(accounts = gaim_accounts; accounts; accounts = accounts->next) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1085 struct gaim_account *account = accounts->data;
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1086 char *acct_name = g_markup_escape_text(account->username, -1);
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1087 if(!exp_acct || account == exp_acct) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1088 fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" "
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1089 "mode=\"%d\">\n", account->protocol, acct_name, account->permdeny);
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1090 for(buds = account->permit; buds; buds = buds->next) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1091 char *bud_name = g_markup_escape_text(buds->data, -1);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1092 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1093 g_free(bud_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1094 }
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1095 for(buds = account->deny; buds; buds = buds->next) {
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1096 char *bud_name = g_markup_escape_text(buds->data, -1);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1097 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1098 g_free(bud_name);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1099 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1100 fprintf(file, "\t\t</account>\n");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1101 }
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1102 g_free(acct_name);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1103 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1104
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1105 fprintf(file, "\t</privacy>\n");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1106 fprintf(file, "</gaim>\n");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1107 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1108
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1109 void gaim_blist_save() {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1110 FILE *file;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1111 char *user_dir = gaim_user_dir();
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1112 char *filename;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1113
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1114 if(!user_dir)
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1115 return;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1116
4497
5968bcd8ddb6 [gaim-migrate @ 4772]
Nathan Walp <nwalp@pidgin.im>
parents: 4496
diff changeset
1117 if(!blist_safe_to_write) {
5968bcd8ddb6 [gaim-migrate @ 4772]
Nathan Walp <nwalp@pidgin.im>
parents: 4496
diff changeset
1118 debug_printf("AHH!! tried to write the blist before we read it!\n");
5968bcd8ddb6 [gaim-migrate @ 4772]
Nathan Walp <nwalp@pidgin.im>
parents: 4496
diff changeset
1119 return;
5968bcd8ddb6 [gaim-migrate @ 4772]
Nathan Walp <nwalp@pidgin.im>
parents: 4496
diff changeset
1120 }
5968bcd8ddb6 [gaim-migrate @ 4772]
Nathan Walp <nwalp@pidgin.im>
parents: 4496
diff changeset
1121
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1122 file = fopen(user_dir, "r");
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1123 if(!file)
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1124 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1125 else
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1126 fclose(file);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1127
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1128 filename = g_build_filename(user_dir, "blist.xml", NULL);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1129
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1130 if((file = fopen(filename, "w"))) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1131 gaim_blist_write(file, NULL);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1132 fclose(file);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1133 chmod(filename, S_IRUSR | S_IWUSR);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1134 } else {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1135 debug_printf("unable to write %s\n", filename);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1136 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1137
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1138 g_free(filename);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1139 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1140
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1141 gboolean gaim_privacy_permit_add(struct gaim_account *account, const char *who) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1142 GSList *d = account->permit;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1143 char *n = g_strdup(normalize(who));
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1144 while(d) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1145 if(!g_strcasecmp(n, normalize(d->data)))
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1146 break;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1147 d = d->next;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1148 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1149 g_free(n);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1150 if(!d) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1151 account->permit = g_slist_append(account->permit, g_strdup(who));
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1152 return TRUE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1153 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1154
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1155 return FALSE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1156 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1157
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1158 gboolean gaim_privacy_permit_remove(struct gaim_account *account, const char *who) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1159 GSList *d = account->permit;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1160 char *n = g_strdup(normalize(who));
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1161 while(d) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1162 if(!g_strcasecmp(n, normalize(d->data)))
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1163 break;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1164 d = d->next;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1165 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1166 g_free(n);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1167 if(d) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1168 account->permit = g_slist_remove(account->permit, d->data);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1169 g_free(d->data);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1170 return TRUE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1171 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1172 return FALSE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1173 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1174
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1175 gboolean gaim_privacy_deny_add(struct gaim_account *account, const char *who) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1176 GSList *d = account->deny;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1177 char *n = g_strdup(normalize(who));
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1178 while(d) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1179 if(!g_strcasecmp(n, normalize(d->data)))
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1180 break;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1181 d = d->next;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1182 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1183 g_free(n);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1184 if(!d) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1185 account->deny = g_slist_append(account->deny, g_strdup(who));
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1186 return TRUE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1187 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1188
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1189 return FALSE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1190 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1191
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1192 gboolean gaim_privacy_deny_remove(struct gaim_account *account, const char *who) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1193 GSList *d = account->deny;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1194 char *n = g_strdup(normalize(who));
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1195 while(d) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1196 if(!g_strcasecmp(n, normalize(d->data)))
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1197 break;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1198 d = d->next;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1199 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1200 g_free(n);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1201 if(d) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4458
diff changeset
1202 account->deny = g_slist_remove(account->deny, d->data);
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1203 g_free(d->data);
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1204 return TRUE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1205 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1206 return FALSE;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1207 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1208
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1209 void gaim_buddy_set_setting(struct buddy *b, const char *key,
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1210 const char *value) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1211 if(!b)
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1212 return;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1213 g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value));
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1214 }
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1215
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1216 char *gaim_buddy_get_setting(struct buddy *b, const char *key) {
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1217 if(!b)
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1218 return NULL;
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1219 return g_strdup(g_hash_table_lookup(b->settings, key));
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4227
diff changeset
1220 }