Mercurial > pidgin
comparison libgaim/protocols/msn/sync.c @ 14192:60b1bc8dbf37
[gaim-migrate @ 16863]
Renamed 'core' to 'libgaim'
committer: Tailor Script <tailor@pidgin.im>
author | Evan Schoenberg <evan.s@dreskin.net> |
---|---|
date | Sat, 19 Aug 2006 01:50:10 +0000 |
parents | |
children | e354528c4163 |
comparison
equal
deleted
inserted
replaced
14191:009db0b357b5 | 14192:60b1bc8dbf37 |
---|---|
1 /** | |
2 * @file sync.c MSN list synchronization functions | |
3 * | |
4 * gaim | |
5 * | |
6 * Gaim is the legal property of its developers, whose names are too numerous | |
7 * to list here. Please refer to the COPYRIGHT file distributed with this | |
8 * source distribution. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 */ | |
24 #include "msn.h" | |
25 #include "sync.h" | |
26 #include "state.h" | |
27 | |
28 static MsnTable *cbs_table; | |
29 | |
30 static void | |
31 blp_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
32 { | |
33 GaimConnection *gc = cmdproc->session->account->gc; | |
34 const char *list_name; | |
35 | |
36 list_name = cmd->params[0]; | |
37 | |
38 if (!g_ascii_strcasecmp(list_name, "AL")) | |
39 { | |
40 /* | |
41 * If the current setting is AL, messages from users who | |
42 * are not in BL will be delivered. | |
43 * | |
44 * In other words, deny some. | |
45 */ | |
46 gc->account->perm_deny = GAIM_PRIVACY_DENY_USERS; | |
47 } | |
48 else | |
49 { | |
50 /* If the current setting is BL, only messages from people | |
51 * who are in the AL will be delivered. | |
52 * | |
53 * In other words, permit some. | |
54 */ | |
55 gc->account->perm_deny = GAIM_PRIVACY_ALLOW_USERS; | |
56 } | |
57 } | |
58 | |
59 static void | |
60 prp_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
61 { | |
62 MsnSession *session = cmdproc->session; | |
63 const char *type, *value; | |
64 | |
65 type = cmd->params[0]; | |
66 value = cmd->params[1]; | |
67 | |
68 if (cmd->param_count == 2) | |
69 { | |
70 if (!strcmp(type, "PHH")) | |
71 msn_user_set_home_phone(session->user, gaim_url_decode(value)); | |
72 else if (!strcmp(type, "PHW")) | |
73 msn_user_set_work_phone(session->user, gaim_url_decode(value)); | |
74 else if (!strcmp(type, "PHM")) | |
75 msn_user_set_mobile_phone(session->user, gaim_url_decode(value)); | |
76 } | |
77 else | |
78 { | |
79 if (!strcmp(type, "PHH")) | |
80 msn_user_set_home_phone(session->user, NULL); | |
81 else if (!strcmp(type, "PHW")) | |
82 msn_user_set_work_phone(session->user, NULL); | |
83 else if (!strcmp(type, "PHM")) | |
84 msn_user_set_mobile_phone(session->user, NULL); | |
85 } | |
86 } | |
87 | |
88 static void | |
89 lsg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
90 { | |
91 MsnSession *session = cmdproc->session; | |
92 const char *name; | |
93 int group_id; | |
94 | |
95 group_id = atoi(cmd->params[0]); | |
96 name = gaim_url_decode(cmd->params[1]); | |
97 | |
98 msn_group_new(session->userlist, group_id, name); | |
99 | |
100 /* HACK */ | |
101 if (group_id == 0) | |
102 /* Group of ungroupped buddies */ | |
103 return; | |
104 | |
105 if ((gaim_find_group(name)) == NULL) | |
106 { | |
107 GaimGroup *g = gaim_group_new(name); | |
108 gaim_blist_add_group(g, NULL); | |
109 } | |
110 } | |
111 | |
112 static void | |
113 lst_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
114 { | |
115 MsnSession *session = cmdproc->session; | |
116 char *passport = NULL; | |
117 const char *friend = NULL; | |
118 int list_op; | |
119 MsnUser *user; | |
120 | |
121 passport = cmd->params[0]; | |
122 friend = gaim_url_decode(cmd->params[1]); | |
123 list_op = atoi(cmd->params[2]); | |
124 | |
125 user = msn_user_new(session->userlist, passport, friend); | |
126 | |
127 msn_userlist_add_user(session->userlist, user); | |
128 | |
129 session->sync->last_user = user; | |
130 | |
131 /* TODO: This can be improved */ | |
132 | |
133 if (list_op & MSN_LIST_FL_OP) | |
134 { | |
135 char **c; | |
136 char **tokens; | |
137 const char *group_nums; | |
138 GSList *group_ids; | |
139 | |
140 group_nums = cmd->params[3]; | |
141 | |
142 group_ids = NULL; | |
143 | |
144 tokens = g_strsplit(group_nums, ",", -1); | |
145 | |
146 for (c = tokens; *c != NULL; c++) | |
147 { | |
148 int id; | |
149 | |
150 id = atoi(*c); | |
151 group_ids = g_slist_append(group_ids, GINT_TO_POINTER(id)); | |
152 } | |
153 | |
154 g_strfreev(tokens); | |
155 | |
156 msn_got_lst_user(session, user, list_op, group_ids); | |
157 | |
158 g_slist_free(group_ids); | |
159 } | |
160 else | |
161 { | |
162 msn_got_lst_user(session, user, list_op, NULL); | |
163 } | |
164 | |
165 session->sync->num_users++; | |
166 | |
167 if (session->sync->num_users == session->sync->total_users) | |
168 { | |
169 cmdproc->cbs_table = session->sync->old_cbs_table; | |
170 | |
171 msn_session_finish_login(session); | |
172 | |
173 msn_sync_destroy(session->sync); | |
174 session->sync = NULL; | |
175 } | |
176 } | |
177 | |
178 static void | |
179 bpr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
180 { | |
181 MsnSync *sync = cmdproc->session->sync; | |
182 const char *type, *value; | |
183 MsnUser *user; | |
184 | |
185 user = sync->last_user; | |
186 | |
187 type = cmd->params[0]; | |
188 value = cmd->params[1]; | |
189 | |
190 if (value) | |
191 { | |
192 if (!strcmp(type, "MOB")) | |
193 { | |
194 if (!strcmp(value, "Y")) | |
195 user->mobile = TRUE; | |
196 } | |
197 else if (!strcmp(type, "PHH")) | |
198 msn_user_set_home_phone(user, gaim_url_decode(value)); | |
199 else if (!strcmp(type, "PHW")) | |
200 msn_user_set_work_phone(user, gaim_url_decode(value)); | |
201 else if (!strcmp(type, "PHM")) | |
202 msn_user_set_mobile_phone(user, gaim_url_decode(value)); | |
203 } | |
204 } | |
205 | |
206 void | |
207 msn_sync_init(void) | |
208 { | |
209 /* TODO: check prp, blp, bpr */ | |
210 | |
211 cbs_table = msn_table_new(); | |
212 | |
213 /* Syncing */ | |
214 msn_table_add_cmd(cbs_table, NULL, "GTC", NULL); | |
215 msn_table_add_cmd(cbs_table, NULL, "BLP", blp_cmd); | |
216 msn_table_add_cmd(cbs_table, NULL, "PRP", prp_cmd); | |
217 msn_table_add_cmd(cbs_table, NULL, "LSG", lsg_cmd); | |
218 msn_table_add_cmd(cbs_table, NULL, "LST", lst_cmd); | |
219 msn_table_add_cmd(cbs_table, NULL, "BPR", bpr_cmd); | |
220 } | |
221 | |
222 void | |
223 msn_sync_end(void) | |
224 { | |
225 msn_table_destroy(cbs_table); | |
226 } | |
227 | |
228 MsnSync * | |
229 msn_sync_new(MsnSession *session) | |
230 { | |
231 MsnSync *sync; | |
232 | |
233 sync = g_new0(MsnSync, 1); | |
234 | |
235 sync->session = session; | |
236 sync->cbs_table = cbs_table; | |
237 | |
238 return sync; | |
239 } | |
240 | |
241 void | |
242 msn_sync_destroy(MsnSync *sync) | |
243 { | |
244 g_free(sync); | |
245 } |