comparison libpurple/protocols/msnp9/sync.c @ 21312:a07cfce78345

Add MSNP9 back as an alternative alongside the existing MSN prpl. Cowardly old fools like me who prefer the stability of our MSNP9 code over the features of MSNP14 can enable this using the --disable-msnp14 ./configure option. If we want to release from i.p.p and MSN stability is the only blocker, we can trivially flick the default to use MSNP9 in configure.ac
author Stu Tomlinson <stu@nosnilmot.com>
date Sun, 11 Nov 2007 12:57:52 +0000
parents
children 6e5d37105189
comparison
equal deleted inserted replaced
21311:7d031cec5ba2 21312:a07cfce78345
1 /**
2 * @file sync.c MSN list synchronization functions
3 *
4 * purple
5 *
6 * Purple 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 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 PurpleConnection *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 = PURPLE_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 = PURPLE_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, purple_url_decode(value));
72 else if (!strcmp(type, "PHW"))
73 msn_user_set_work_phone(session->user, purple_url_decode(value));
74 else if (!strcmp(type, "PHM"))
75 msn_user_set_mobile_phone(session->user, purple_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 = purple_url_decode(cmd->params[1]);
97
98 msn_group_new(session->userlist, group_id, name);
99
100 /* HACK */
101 if (group_id == 0)
102 {
103 /* Group of ungroupped buddies */
104 if (session->sync->total_users == 0)
105 {
106 cmdproc->cbs_table = session->sync->old_cbs_table;
107
108 msn_session_finish_login(session);
109
110 msn_sync_destroy(session->sync);
111 session->sync = NULL;
112 }
113 return;
114 }
115
116 if ((purple_find_group(name)) == NULL)
117 {
118 PurpleGroup *g = purple_group_new(name);
119 purple_blist_add_group(g, NULL);
120 }
121 }
122
123 static void
124 lst_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
125 {
126 MsnSession *session = cmdproc->session;
127 char *passport = NULL;
128 const char *friend = NULL;
129 int list_op;
130 MsnUser *user;
131
132 passport = cmd->params[0];
133 friend = purple_url_decode(cmd->params[1]);
134 list_op = atoi(cmd->params[2]);
135
136 user = msn_user_new(session->userlist, passport, friend);
137
138 msn_userlist_add_user(session->userlist, user);
139
140 session->sync->last_user = user;
141
142 /* TODO: This can be improved */
143
144 if (list_op & MSN_LIST_FL_OP)
145 {
146 char **c;
147 char **tokens;
148 const char *group_nums;
149 GSList *group_ids;
150
151 group_nums = cmd->params[3];
152
153 group_ids = NULL;
154
155 tokens = g_strsplit(group_nums, ",", -1);
156
157 for (c = tokens; *c != NULL; c++)
158 {
159 int id;
160
161 id = atoi(*c);
162 group_ids = g_slist_append(group_ids, GINT_TO_POINTER(id));
163 }
164
165 g_strfreev(tokens);
166
167 msn_got_lst_user(session, user, list_op, group_ids);
168
169 g_slist_free(group_ids);
170 }
171 else
172 {
173 msn_got_lst_user(session, user, list_op, NULL);
174 }
175
176 session->sync->num_users++;
177
178 if (session->sync->num_users == session->sync->total_users)
179 {
180 cmdproc->cbs_table = session->sync->old_cbs_table;
181
182 msn_session_finish_login(session);
183
184 msn_sync_destroy(session->sync);
185 session->sync = NULL;
186 }
187 }
188
189 static void
190 bpr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
191 {
192 MsnSync *sync = cmdproc->session->sync;
193 const char *type, *value;
194 MsnUser *user;
195
196 user = sync->last_user;
197
198 g_return_if_fail(user != NULL);
199
200 type = cmd->params[0];
201 value = cmd->params[1];
202
203 if (value)
204 {
205 if (!strcmp(type, "MOB"))
206 {
207 if (!strcmp(value, "Y"))
208 user->mobile = TRUE;
209 }
210 else if (!strcmp(type, "PHH"))
211 msn_user_set_home_phone(user, purple_url_decode(value));
212 else if (!strcmp(type, "PHW"))
213 msn_user_set_work_phone(user, purple_url_decode(value));
214 else if (!strcmp(type, "PHM"))
215 msn_user_set_mobile_phone(user, purple_url_decode(value));
216 }
217 }
218
219 void
220 msn_sync_init(void)
221 {
222 /* TODO: check prp, blp, bpr */
223
224 cbs_table = msn_table_new();
225
226 /* Syncing */
227 msn_table_add_cmd(cbs_table, NULL, "GTC", NULL);
228 msn_table_add_cmd(cbs_table, NULL, "BLP", blp_cmd);
229 msn_table_add_cmd(cbs_table, NULL, "PRP", prp_cmd);
230 msn_table_add_cmd(cbs_table, NULL, "LSG", lsg_cmd);
231 msn_table_add_cmd(cbs_table, NULL, "LST", lst_cmd);
232 msn_table_add_cmd(cbs_table, NULL, "BPR", bpr_cmd);
233 }
234
235 void
236 msn_sync_end(void)
237 {
238 msn_table_destroy(cbs_table);
239 }
240
241 MsnSync *
242 msn_sync_new(MsnSession *session)
243 {
244 MsnSync *sync;
245
246 sync = g_new0(MsnSync, 1);
247
248 sync->session = session;
249 sync->cbs_table = cbs_table;
250
251 return sync;
252 }
253
254 void
255 msn_sync_destroy(MsnSync *sync)
256 {
257 g_free(sync);
258 }