Mercurial > pidgin
annotate src/protocols/msn/sync.c @ 9363:997c28571364
[gaim-migrate @ 10171]
Patches by Felipe (shx) to clean up some code, add some segfault
precautions, fix chats so that we'll see the other users in the chat
correctly after invites, and to have MSN ignore the local buddy list adds
if we're not already signed on (which fixes a *very* annoying bug I was
having). Thanks again!
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 23 Jun 2004 19:38:58 +0000 |
parents | 554ef91db2dd |
children | 86a6d78b070b |
rev | line source |
---|---|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
1 /** |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
2 * @file sync.c MSN list synchronization functions |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
3 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
4 * gaim |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
5 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 * source distribution. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
9 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
10 * This program is free software; you can redistribute it and/or modify |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
11 * it under the terms of the GNU General Public License as published by |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
12 * the Free Software Foundation; either version 2 of the License, or |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
13 * (at your option) any later version. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
14 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
15 * This program is distributed in the hope that it will be useful, |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
18 * GNU General Public License for more details. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
19 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
20 * You should have received a copy of the GNU General Public License |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
21 * along with this program; if not, write to the Free Software |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
23 */ |
9193 | 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 MsnGroup *group; | |
93 GaimGroup *g; | |
94 const char *name; | |
95 int group_id; | |
96 | |
97 group_id = atoi(cmd->params[0]); | |
98 name = gaim_url_decode(cmd->params[1]); | |
99 | |
100 group = msn_group_new(session->userlist, group_id, name); | |
101 | |
102 if ((g = gaim_find_group(name)) == NULL) | |
103 { | |
104 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 GaimAccount *account = session->account; | |
114 GaimConnection *gc = gaim_account_get_connection(account); | |
115 char *passport = NULL; | |
116 const char *friend = NULL; | |
117 int list_op; | |
118 MsnUser *user; | |
119 | |
120 passport = cmd->params[0]; | |
121 friend = gaim_url_decode(cmd->params[1]); | |
122 list_op = atoi(cmd->params[2]); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
123 |
9225
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
124 #if 0 |
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
125 gaim_debug_misc("msn", "Got list op = %d\n", list_op); |
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
126 gaim_debug_misc("msn", "FL = %d\n", (list_op & MSN_LIST_FL_OP)); |
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
127 gaim_debug_misc("msn", "AL = %d\n", (list_op & MSN_LIST_AL_OP)); |
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
128 gaim_debug_misc("msn", "BL = %d\n", (list_op & MSN_LIST_BL_OP)); |
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
129 gaim_debug_misc("msn", "RL = %d\n", (list_op & MSN_LIST_RL_OP)); |
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
130 #endif |
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
131 |
9193 | 132 user = msn_user_new(session->userlist, passport, friend); |
133 | |
134 msn_userlist_add_user(session->userlist, user); | |
135 | |
136 session->sync->last_user = user; | |
137 | |
138 /* TODO: This can be improved */ | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
139 |
9193 | 140 if (list_op & MSN_LIST_FL_OP) |
141 { | |
142 char **c; | |
143 char **tokens; | |
144 const char *group_nums; | |
145 GSList *group_ids; | |
146 | |
147 group_nums = cmd->params[3]; | |
148 | |
149 group_ids = NULL; | |
150 | |
151 tokens = g_strsplit(group_nums, ",", -1); | |
152 | |
153 for (c = tokens; *c != NULL; c++) | |
154 { | |
155 int id; | |
156 | |
157 id = atoi(*c); | |
158 group_ids = g_slist_append(group_ids, GINT_TO_POINTER(id)); | |
159 } | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
160 |
9193 | 161 g_strfreev(tokens); |
162 | |
163 msn_got_lst_user(session, user, list_op, group_ids); | |
164 | |
165 g_slist_free(group_ids); | |
166 } | |
167 else | |
168 { | |
169 msn_got_lst_user(session, user, list_op, NULL); | |
170 } | |
171 | |
172 session->sync->num_users++; | |
173 | |
174 if (session->sync->num_users == session->sync->total_users) | |
175 { | |
176 cmdproc->cbs_table = session->sync->old_cbs_table; | |
177 | |
178 msn_user_set_buddy_icon(session->user, | |
179 gaim_account_get_buddy_icon(session->account)); | |
180 | |
181 msn_change_status(session, MSN_ONLINE); | |
182 | |
183 gaim_connection_set_state(gc, GAIM_CONNECTED); | |
9363
997c28571364
[gaim-migrate @ 10171]
Christian Hammond <chipx86@chipx86.com>
parents:
9225
diff
changeset
|
184 session->logged_in = TRUE; |
997c28571364
[gaim-migrate @ 10171]
Christian Hammond <chipx86@chipx86.com>
parents:
9225
diff
changeset
|
185 |
9193 | 186 serv_finish_login(gc); |
187 | |
188 msn_sync_destroy(session->sync); | |
189 session->sync = NULL; | |
190 } | |
191 } | |
192 | |
193 static void | |
194 bpr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
195 { | |
196 MsnSync *sync = cmdproc->session->sync; | |
197 const char *type, *value; | |
198 MsnUser *user; | |
199 | |
200 user = sync->last_user; | |
201 | |
202 type = cmd->params[0]; | |
203 value = cmd->params[1]; | |
204 | |
205 if (value) | |
206 { | |
207 if (!strcmp(type, "MOB")) | |
208 { | |
209 if (!strcmp(value, "Y")) | |
210 user->mobile = TRUE; | |
211 } | |
212 else if (!strcmp(type, "PHH")) | |
213 msn_user_set_home_phone(user, gaim_url_decode(value)); | |
214 else if (!strcmp(type, "PHW")) | |
215 msn_user_set_work_phone(user, gaim_url_decode(value)); | |
216 else if (!strcmp(type, "PHM")) | |
217 msn_user_set_mobile_phone(user, gaim_url_decode(value)); | |
218 } | |
219 } | |
220 | |
221 void | |
222 msn_sync_init(void) | |
223 { | |
224 /* TODO: check prp, blp, bpr */ | |
225 | |
226 cbs_table = msn_table_new(); | |
227 | |
228 /* Syncing */ | |
229 msn_table_add_cmd(cbs_table, NULL, "GTC", NULL); | |
230 msn_table_add_cmd(cbs_table, NULL, "BLP", blp_cmd); | |
231 msn_table_add_cmd(cbs_table, NULL, "PRP", prp_cmd); | |
232 msn_table_add_cmd(cbs_table, NULL, "LSG", lsg_cmd); | |
233 msn_table_add_cmd(cbs_table, NULL, "LST", lst_cmd); | |
234 msn_table_add_cmd(cbs_table, NULL, "BPR", bpr_cmd); | |
235 } | |
236 | |
237 void | |
238 msn_sync_end(void) | |
239 { | |
240 msn_table_destroy(cbs_table); | |
241 } | |
242 | |
243 MsnSync * | |
244 msn_sync_new(MsnSession *session) | |
245 { | |
246 MsnSync *sync; | |
247 | |
248 sync = g_new0(MsnSync, 1); | |
249 | |
250 sync->session = session; | |
251 sync->cbs_table = cbs_table; | |
252 | |
253 return sync; | |
254 } | |
255 | |
256 void | |
257 msn_sync_destroy(MsnSync *sync) | |
258 { | |
259 g_free(sync); | |
260 } |