Mercurial > pidgin
annotate libgaim/protocols/msn/sync.c @ 20397:6ac7e33fdabf
propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-1-rlaager-whitespace' (head 5083cfbc09503360bacf3ff0ebf528700770e6af)
to branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4-rlaager-whitespace' (head 4d82c29e56bd33cd6f94302e343dfeb5d68ab3eb)
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 15 Apr 2007 03:04:05 +0000 |
parents | 0b0ecee55091 |
children |
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; | |
20391
0b0ecee55091
The second msn.tgz from SF Patch #1621854 from Ka-Hing Cheung.
Ka-Hing Cheung <khc@hxbc.us>
parents:
20389
diff
changeset
|
89 const char *name, *group_id; |
14192 | 90 |
20391
0b0ecee55091
The second msn.tgz from SF Patch #1621854 from Ka-Hing Cheung.
Ka-Hing Cheung <khc@hxbc.us>
parents:
20389
diff
changeset
|
91 group_id = cmd->params[0]; |
14192 | 92 name = gaim_url_decode(cmd->params[1]); |
93 | |
94 msn_group_new(session->userlist, group_id, name); | |
95 | |
96 /* HACK */ | |
97 if (group_id == 0) | |
98 /* Group of ungroupped buddies */ | |
99 return; | |
100 | |
101 if ((gaim_find_group(name)) == NULL) | |
102 { | |
103 GaimGroup *g = gaim_group_new(name); | |
104 gaim_blist_add_group(g, NULL); | |
105 } | |
106 } | |
107 | |
108 static void | |
109 lst_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
110 { | |
111 MsnSession *session = cmdproc->session; | |
112 char *passport = NULL; | |
113 const char *friend = NULL; | |
114 int list_op; | |
115 MsnUser *user; | |
116 | |
117 passport = cmd->params[0]; | |
118 friend = gaim_url_decode(cmd->params[1]); | |
119 list_op = atoi(cmd->params[2]); | |
120 | |
121 user = msn_user_new(session->userlist, passport, friend); | |
122 | |
123 msn_userlist_add_user(session->userlist, user); | |
124 | |
125 session->sync->last_user = user; | |
126 | |
127 /* TODO: This can be improved */ | |
128 | |
129 if (list_op & MSN_LIST_FL_OP) | |
130 { | |
131 char **c; | |
132 char **tokens; | |
133 const char *group_nums; | |
134 GSList *group_ids; | |
135 | |
136 group_nums = cmd->params[3]; | |
137 | |
138 group_ids = NULL; | |
139 | |
140 tokens = g_strsplit(group_nums, ",", -1); | |
141 | |
142 for (c = tokens; *c != NULL; c++) | |
143 { | |
144 int id; | |
145 | |
146 id = atoi(*c); | |
147 group_ids = g_slist_append(group_ids, GINT_TO_POINTER(id)); | |
148 } | |
149 | |
150 g_strfreev(tokens); | |
151 | |
152 msn_got_lst_user(session, user, list_op, group_ids); | |
153 | |
154 g_slist_free(group_ids); | |
155 } | |
156 else | |
157 { | |
158 msn_got_lst_user(session, user, list_op, NULL); | |
159 } | |
160 | |
161 session->sync->num_users++; | |
162 | |
163 if (session->sync->num_users == session->sync->total_users) | |
164 { | |
165 cmdproc->cbs_table = session->sync->old_cbs_table; | |
166 | |
167 msn_session_finish_login(session); | |
168 | |
169 msn_sync_destroy(session->sync); | |
170 session->sync = NULL; | |
171 } | |
172 } | |
173 | |
174 static void | |
175 bpr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
176 { | |
177 MsnSync *sync = cmdproc->session->sync; | |
178 const char *type, *value; | |
179 MsnUser *user; | |
180 | |
181 user = sync->last_user; | |
182 | |
183 type = cmd->params[0]; | |
184 value = cmd->params[1]; | |
185 | |
186 if (value) | |
187 { | |
188 if (!strcmp(type, "MOB")) | |
189 { | |
190 if (!strcmp(value, "Y")) | |
191 user->mobile = TRUE; | |
192 } | |
193 else if (!strcmp(type, "PHH")) | |
194 msn_user_set_home_phone(user, gaim_url_decode(value)); | |
195 else if (!strcmp(type, "PHW")) | |
196 msn_user_set_work_phone(user, gaim_url_decode(value)); | |
197 else if (!strcmp(type, "PHM")) | |
198 msn_user_set_mobile_phone(user, gaim_url_decode(value)); | |
199 } | |
200 } | |
201 | |
202 void | |
203 msn_sync_init(void) | |
204 { | |
205 /* TODO: check prp, blp, bpr */ | |
206 | |
207 cbs_table = msn_table_new(); | |
208 | |
209 /* Syncing */ | |
210 msn_table_add_cmd(cbs_table, NULL, "GTC", NULL); | |
211 msn_table_add_cmd(cbs_table, NULL, "BLP", blp_cmd); | |
212 msn_table_add_cmd(cbs_table, NULL, "PRP", prp_cmd); | |
213 msn_table_add_cmd(cbs_table, NULL, "LSG", lsg_cmd); | |
214 msn_table_add_cmd(cbs_table, NULL, "LST", lst_cmd); | |
215 msn_table_add_cmd(cbs_table, NULL, "BPR", bpr_cmd); | |
216 } | |
217 | |
218 void | |
219 msn_sync_end(void) | |
220 { | |
221 msn_table_destroy(cbs_table); | |
222 } | |
223 | |
224 MsnSync * | |
225 msn_sync_new(MsnSession *session) | |
226 { | |
227 MsnSync *sync; | |
228 | |
229 sync = g_new0(MsnSync, 1); | |
230 | |
231 sync->session = session; | |
232 sync->cbs_table = cbs_table; | |
233 | |
234 return sync; | |
235 } | |
236 | |
237 void | |
238 msn_sync_destroy(MsnSync *sync) | |
239 { | |
240 g_free(sync); | |
241 } |