Mercurial > pidgin
annotate libgaim/protocols/msn/sync.c @ 20389:e354528c4163
propagate from branch 'im.pidgin.gaim' (head 70ac931e4936c7916eec18a07fe46a0af0fd7403)
to branch 'im.pidgin.rlaager.merging.soc-msnp13-to-svn18164' (head 5b5cde92182d2a922a8e7e6c2308342a5490a8c9)
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 15 Apr 2007 02:10:37 +0000 |
parents | 60b1bc8dbf37 |
children | 0b0ecee55091 |
rev | line source |
---|---|
14192 | 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 | |
20389
e354528c4163
propagate from branch 'im.pidgin.gaim' (head 70ac931e4936c7916eec18a07fe46a0af0fd7403)
Richard Laager <rlaager@wiktel.com>
parents:
14192
diff
changeset
|
38 if (!g_ascii_strcasecmp(list_name, "AL")){ |
14192 | 39 /* |
40 * If the current setting is AL, messages from users who | |
41 * are not in BL will be delivered. | |
42 * | |
43 * In other words, deny some. | |
44 */ | |
45 gc->account->perm_deny = GAIM_PRIVACY_DENY_USERS; | |
20389
e354528c4163
propagate from branch 'im.pidgin.gaim' (head 70ac931e4936c7916eec18a07fe46a0af0fd7403)
Richard Laager <rlaager@wiktel.com>
parents:
14192
diff
changeset
|
46 }else{ |
14192 | 47 /* If the current setting is BL, only messages from people |
48 * who are in the AL will be delivered. | |
49 * | |
50 * In other words, permit some. | |
51 */ | |
52 gc->account->perm_deny = GAIM_PRIVACY_ALLOW_USERS; | |
53 } | |
54 } | |
55 | |
56 static void | |
57 prp_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
58 { | |
59 MsnSession *session = cmdproc->session; | |
60 const char *type, *value; | |
61 | |
62 type = cmd->params[0]; | |
63 value = cmd->params[1]; | |
64 | |
65 if (cmd->param_count == 2) | |
66 { | |
67 if (!strcmp(type, "PHH")) | |
68 msn_user_set_home_phone(session->user, gaim_url_decode(value)); | |
69 else if (!strcmp(type, "PHW")) | |
70 msn_user_set_work_phone(session->user, gaim_url_decode(value)); | |
71 else if (!strcmp(type, "PHM")) | |
72 msn_user_set_mobile_phone(session->user, gaim_url_decode(value)); | |
73 } | |
74 else | |
75 { | |
76 if (!strcmp(type, "PHH")) | |
77 msn_user_set_home_phone(session->user, NULL); | |
78 else if (!strcmp(type, "PHW")) | |
79 msn_user_set_work_phone(session->user, NULL); | |
80 else if (!strcmp(type, "PHM")) | |
81 msn_user_set_mobile_phone(session->user, NULL); | |
82 } | |
83 } | |
84 | |
85 static void | |
86 lsg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
87 { | |
88 MsnSession *session = cmdproc->session; | |
89 const char *name; | |
90 int group_id; | |
91 | |
92 group_id = atoi(cmd->params[0]); | |
93 name = gaim_url_decode(cmd->params[1]); | |
94 | |
95 msn_group_new(session->userlist, group_id, name); | |
96 | |
97 /* HACK */ | |
98 if (group_id == 0) | |
99 /* Group of ungroupped buddies */ | |
100 return; | |
101 | |
102 if ((gaim_find_group(name)) == NULL) | |
103 { | |
104 GaimGroup *g = gaim_group_new(name); | |
105 gaim_blist_add_group(g, NULL); | |
106 } | |
107 } | |
108 | |
109 static void | |
110 lst_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
111 { | |
112 MsnSession *session = cmdproc->session; | |
113 char *passport = NULL; | |
114 const char *friend = NULL; | |
115 int list_op; | |
116 MsnUser *user; | |
117 | |
118 passport = cmd->params[0]; | |
119 friend = gaim_url_decode(cmd->params[1]); | |
120 list_op = atoi(cmd->params[2]); | |
121 | |
122 user = msn_user_new(session->userlist, passport, friend); | |
123 | |
124 msn_userlist_add_user(session->userlist, user); | |
125 | |
126 session->sync->last_user = user; | |
127 | |
128 /* TODO: This can be improved */ | |
129 | |
130 if (list_op & MSN_LIST_FL_OP) | |
131 { | |
132 char **c; | |
133 char **tokens; | |
134 const char *group_nums; | |
135 GSList *group_ids; | |
136 | |
137 group_nums = cmd->params[3]; | |
138 | |
139 group_ids = NULL; | |
140 | |
141 tokens = g_strsplit(group_nums, ",", -1); | |
142 | |
143 for (c = tokens; *c != NULL; c++) | |
144 { | |
145 int id; | |
146 | |
147 id = atoi(*c); | |
148 group_ids = g_slist_append(group_ids, GINT_TO_POINTER(id)); | |
149 } | |
150 | |
151 g_strfreev(tokens); | |
152 | |
153 msn_got_lst_user(session, user, list_op, group_ids); | |
154 | |
155 g_slist_free(group_ids); | |
156 } | |
157 else | |
158 { | |
159 msn_got_lst_user(session, user, list_op, NULL); | |
160 } | |
161 | |
162 session->sync->num_users++; | |
163 | |
164 if (session->sync->num_users == session->sync->total_users) | |
165 { | |
166 cmdproc->cbs_table = session->sync->old_cbs_table; | |
167 | |
168 msn_session_finish_login(session); | |
169 | |
170 msn_sync_destroy(session->sync); | |
171 session->sync = NULL; | |
172 } | |
173 } | |
174 | |
175 static void | |
176 bpr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
177 { | |
178 MsnSync *sync = cmdproc->session->sync; | |
179 const char *type, *value; | |
180 MsnUser *user; | |
181 | |
182 user = sync->last_user; | |
183 | |
184 type = cmd->params[0]; | |
185 value = cmd->params[1]; | |
186 | |
187 if (value) | |
188 { | |
189 if (!strcmp(type, "MOB")) | |
190 { | |
191 if (!strcmp(value, "Y")) | |
192 user->mobile = TRUE; | |
193 } | |
194 else if (!strcmp(type, "PHH")) | |
195 msn_user_set_home_phone(user, gaim_url_decode(value)); | |
196 else if (!strcmp(type, "PHW")) | |
197 msn_user_set_work_phone(user, gaim_url_decode(value)); | |
198 else if (!strcmp(type, "PHM")) | |
199 msn_user_set_mobile_phone(user, gaim_url_decode(value)); | |
200 } | |
201 } | |
202 | |
203 void | |
204 msn_sync_init(void) | |
205 { | |
206 /* TODO: check prp, blp, bpr */ | |
207 | |
208 cbs_table = msn_table_new(); | |
209 | |
210 /* Syncing */ | |
211 msn_table_add_cmd(cbs_table, NULL, "GTC", NULL); | |
212 msn_table_add_cmd(cbs_table, NULL, "BLP", blp_cmd); | |
213 msn_table_add_cmd(cbs_table, NULL, "PRP", prp_cmd); | |
214 msn_table_add_cmd(cbs_table, NULL, "LSG", lsg_cmd); | |
215 msn_table_add_cmd(cbs_table, NULL, "LST", lst_cmd); | |
216 msn_table_add_cmd(cbs_table, NULL, "BPR", bpr_cmd); | |
217 } | |
218 | |
219 void | |
220 msn_sync_end(void) | |
221 { | |
222 msn_table_destroy(cbs_table); | |
223 } | |
224 | |
225 MsnSync * | |
226 msn_sync_new(MsnSession *session) | |
227 { | |
228 MsnSync *sync; | |
229 | |
230 sync = g_new0(MsnSync, 1); | |
231 | |
232 sync->session = session; | |
233 sync->cbs_table = cbs_table; | |
234 | |
235 return sync; | |
236 } | |
237 | |
238 void | |
239 msn_sync_destroy(MsnSync *sync) | |
240 { | |
241 g_free(sync); | |
242 } |