Mercurial > pidgin
annotate src/protocols/msn/session.c @ 19788:8b4653986e8e
[gaim-migrate @ 16600]
change to add SOAP HTTP header retrieve
Now Can do the OIM Message XML process
submitted by Ma Yuan<mayuan2006@gmail.com>
committer: Ethan Blanton <elb@pidgin.im>
author | Ma Yuan <mayuan2006@gmail.com> |
---|---|
date | Sun, 30 Jul 2006 13:44:34 +0000 |
parents | b99512bd6d85 |
children | 90f89601d6d3 |
rev | line source |
---|---|
5309 | 1 /** |
2 * @file session.c MSN session functions | |
3 * | |
4 * gaim | |
5 * | |
9198
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. |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
9 * |
5309 | 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 "session.h" | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
26 #include "notification.h" |
5309 | 27 |
10044 | 28 #include "dialog.h" |
29 | |
5309 | 30 MsnSession * |
10481 | 31 msn_session_new(GaimAccount *account) |
5309 | 32 { |
33 MsnSession *session; | |
34 | |
35 g_return_val_if_fail(account != NULL, NULL); | |
36 | |
37 session = g_new0(MsnSession, 1); | |
38 | |
10481 | 39 session->account = account; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
40 session->notification = msn_notification_new(session); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
41 session->userlist = msn_userlist_new(session); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
42 |
10481 | 43 session->user = msn_user_new(session->userlist, |
44 gaim_account_get_username(account), NULL); | |
45 | |
19786 | 46 /*if you want to chat with Yahoo Messenger*/ |
47 //session->protocol_ver = WLM_YAHOO_PROT_VER; | |
19783 | 48 session->protocol_ver = WLM_PROT_VER; |
10621 | 49 session->conv_seq = 1; |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
50 |
5309 | 51 return session; |
52 } | |
53 | |
54 void | |
55 msn_session_destroy(MsnSession *session) | |
56 { | |
57 g_return_if_fail(session != NULL); | |
58 | |
10296 | 59 session->destroying = TRUE; |
60 | |
5309 | 61 if (session->connected) |
62 msn_session_disconnect(session); | |
63 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
64 if (session->notification != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
65 msn_notification_destroy(session->notification); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
66 |
5309 | 67 while (session->switches != NULL) |
68 msn_switchboard_destroy(session->switches->data); | |
69 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
70 while (session->slplinks != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
71 msn_slplink_destroy(session->slplinks->data); |
5309 | 72 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
73 msn_userlist_destroy(session->userlist); |
5309 | 74 |
19784 | 75 g_free(session->passport_info.t); |
76 g_free(session->passport_info.p); | |
13693
510b7b7dd645
[gaim-migrate @ 16096]
Richard Laager <rlaager@wiktel.com>
parents:
13634
diff
changeset
|
77 g_free(session->passport_info.kv); |
510b7b7dd645
[gaim-migrate @ 16096]
Richard Laager <rlaager@wiktel.com>
parents:
13634
diff
changeset
|
78 g_free(session->passport_info.sid); |
510b7b7dd645
[gaim-migrate @ 16096]
Richard Laager <rlaager@wiktel.com>
parents:
13634
diff
changeset
|
79 g_free(session->passport_info.mspauth); |
510b7b7dd645
[gaim-migrate @ 16096]
Richard Laager <rlaager@wiktel.com>
parents:
13634
diff
changeset
|
80 g_free(session->passport_info.client_ip); |
10284 | 81 |
6827
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
82 if (session->passport_info.file != NULL) |
10275 | 83 { |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10582
diff
changeset
|
84 g_unlink(session->passport_info.file); |
6827
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
85 g_free(session->passport_info.file); |
10275 | 86 } |
5427 | 87 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
88 if (session->sync != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
89 msn_sync_destroy(session->sync); |
7590
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
90 |
8171
d0ba2f7b40e7
[gaim-migrate @ 8884]
Christian Hammond <chipx86@chipx86.com>
parents:
7590
diff
changeset
|
91 if (session->nexus != NULL) |
d0ba2f7b40e7
[gaim-migrate @ 8884]
Christian Hammond <chipx86@chipx86.com>
parents:
7590
diff
changeset
|
92 msn_nexus_destroy(session->nexus); |
d0ba2f7b40e7
[gaim-migrate @ 8884]
Christian Hammond <chipx86@chipx86.com>
parents:
7590
diff
changeset
|
93 |
19788 | 94 if (session->contact != NULL) |
95 msn_contact_destroy(session->contact); | |
96 if (session->oim != NULL) | |
97 msn_oim_destroy(session->oim); | |
98 | |
10481 | 99 if (session->user != NULL) |
100 msn_user_destroy(session->user); | |
101 | |
5309 | 102 g_free(session); |
103 } | |
104 | |
105 gboolean | |
10481 | 106 msn_session_connect(MsnSession *session, const char *host, int port, |
107 gboolean http_method) | |
5309 | 108 { |
109 g_return_val_if_fail(session != NULL, FALSE); | |
110 g_return_val_if_fail(!session->connected, TRUE); | |
111 | |
112 session->connected = TRUE; | |
10481 | 113 session->http_method = http_method; |
5309 | 114 |
10463 | 115 if (session->notification == NULL) |
116 { | |
117 gaim_debug_error("msn", "This shouldn't happen\n"); | |
118 g_return_val_if_reached(FALSE); | |
119 } | |
120 | |
10481 | 121 if (msn_notification_connect(session->notification, host, port)) |
8831
ffecda0c1f45
[gaim-migrate @ 9595]
Christian Hammond <chipx86@chipx86.com>
parents:
8808
diff
changeset
|
122 { |
ffecda0c1f45
[gaim-migrate @ 9595]
Christian Hammond <chipx86@chipx86.com>
parents:
8808
diff
changeset
|
123 return TRUE; |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
124 } |
5309 | 125 |
126 return FALSE; | |
127 } | |
128 | |
129 void | |
130 msn_session_disconnect(MsnSession *session) | |
131 { | |
132 g_return_if_fail(session != NULL); | |
133 g_return_if_fail(session->connected); | |
134 | |
10481 | 135 session->connected = FALSE; |
136 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8831
diff
changeset
|
137 while (session->switches != NULL) |
10463 | 138 msn_switchboard_close(session->switches->data); |
5309 | 139 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
140 if (session->notification != NULL) |
10463 | 141 msn_notification_close(session->notification); |
5309 | 142 } |
143 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
144 /* TODO: This must go away when conversation is redesigned */ |
5309 | 145 MsnSwitchBoard * |
10621 | 146 msn_session_find_swboard(MsnSession *session, const char *username) |
5309 | 147 { |
148 GList *l; | |
149 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8831
diff
changeset
|
150 g_return_val_if_fail(session != NULL, NULL); |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
151 g_return_val_if_fail(username != NULL, NULL); |
5309 | 152 |
8499
467b01d02f9c
[gaim-migrate @ 9235]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
153 for (l = session->switches; l != NULL; l = l->next) |
467b01d02f9c
[gaim-migrate @ 9235]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
154 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
155 MsnSwitchBoard *swboard; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
156 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
157 swboard = l->data; |
5309 | 158 |
10621 | 159 if ((swboard->im_user != NULL) && !strcmp(username, swboard->im_user)) |
10602 | 160 return swboard; |
5309 | 161 } |
162 | |
163 return NULL; | |
164 } | |
165 | |
166 MsnSwitchBoard * | |
10621 | 167 msn_session_find_swboard_with_conv(MsnSession *session, GaimConversation *conv) |
168 { | |
169 GList *l; | |
170 | |
171 g_return_val_if_fail(session != NULL, NULL); | |
172 g_return_val_if_fail(conv != NULL, NULL); | |
173 | |
174 for (l = session->switches; l != NULL; l = l->next) | |
175 { | |
176 MsnSwitchBoard *swboard; | |
177 | |
178 swboard = l->data; | |
179 | |
180 if (swboard->conv == conv) | |
181 return swboard; | |
182 } | |
183 | |
184 return NULL; | |
185 } | |
186 | |
187 MsnSwitchBoard * | |
188 msn_session_find_swboard_with_id(const MsnSession *session, int chat_id) | |
5309 | 189 { |
190 GList *l; | |
191 | |
192 g_return_val_if_fail(session != NULL, NULL); | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
193 g_return_val_if_fail(chat_id >= 0, NULL); |
5309 | 194 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8831
diff
changeset
|
195 for (l = session->switches; l != NULL; l = l->next) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8831
diff
changeset
|
196 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
197 MsnSwitchBoard *swboard; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
198 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
199 swboard = l->data; |
5309 | 200 |
10621 | 201 if (swboard->chat_id == chat_id) |
5309 | 202 return swboard; |
203 } | |
204 | |
205 return NULL; | |
206 } | |
207 | |
208 MsnSwitchBoard * | |
10773 | 209 msn_session_get_swboard(MsnSession *session, const char *username, |
210 MsnSBFlag flag) | |
5309 | 211 { |
212 MsnSwitchBoard *swboard; | |
213 | |
13634 | 214 g_return_val_if_fail(session != NULL, NULL); |
215 | |
10621 | 216 swboard = msn_session_find_swboard(session, username); |
5309 | 217 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
218 if (swboard == NULL) |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8831
diff
changeset
|
219 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
220 swboard = msn_switchboard_new(session); |
10225 | 221 swboard->im_user = g_strdup(username); |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
222 msn_switchboard_request(swboard); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
223 msn_switchboard_request_add_user(swboard, username); |
5309 | 224 } |
225 | |
10773 | 226 swboard->flag |= flag; |
227 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
228 return swboard; |
5309 | 229 } |
10044 | 230 |
231 static void | |
232 msn_session_sync_users(MsnSession *session) | |
233 { | |
11992 | 234 GaimBlistNode *gnode, *cnode, *bnode; |
235 GaimConnection *gc = gaim_account_get_connection(session->account); | |
10044 | 236 |
11992 | 237 g_return_if_fail(gc != NULL); |
10044 | 238 |
11992 | 239 /* The core used to use msn_add_buddy to add all buddies before |
240 * being logged in. This no longer happens, so we manually iterate | |
241 * over the whole buddy list to identify sync issues. */ | |
19787 | 242 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next){ |
11992 | 243 GaimGroup *group = (GaimGroup *)gnode; |
244 const char *group_name = group->name; | |
245 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
246 continue; | |
19787 | 247 if(!g_strcasecmp(group_name, MSN_INDIVIDUALS_GROUP_NAME) |
248 || !g_strcasecmp(group_name,MSN_NON_IM_GROUP_NAME)){ | |
249 continue; | |
250 } | |
11992 | 251 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
252 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
253 continue; | |
254 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
255 GaimBuddy *b; | |
256 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
257 continue; | |
258 b = (GaimBuddy *)bnode; | |
19787 | 259 if(b->account == gc->account){ |
11992 | 260 MsnUser *remote_user; |
10044 | 261 gboolean found = FALSE; |
11992 | 262 |
19786 | 263 gaim_debug_info("MaYuan","buddy name:%s,group name:%s\n",b->name,group_name); |
11992 | 264 remote_user = msn_userlist_find_user(session->userlist, b->name); |
10044 | 265 |
19785 | 266 if ((remote_user != NULL) && (remote_user->list_op & MSN_LIST_FL_OP)){ |
19787 | 267 const char *group_id; |
11992 | 268 GList *l; |
10044 | 269 |
11992 | 270 group_id = msn_userlist_find_group_id(remote_user->userlist, |
271 group_name); | |
19787 | 272 if(group_id == NULL){ |
273 continue; | |
274 } | |
10044 | 275 |
19785 | 276 for (l = remote_user->group_ids; l != NULL; l = l->next){ |
19786 | 277 if (!g_strcasecmp(group_id ,l->data)){ |
11992 | 278 found = TRUE; |
279 break; | |
280 } | |
10044 | 281 } |
282 } | |
283 | |
19785 | 284 if (!found){ |
11992 | 285 /* The user was not on the server list or not in that group |
286 * on the server list */ | |
287 msn_show_sync_issue(session, b->name, group_name); | |
10044 | 288 } |
289 } | |
290 } | |
291 } | |
292 } | |
293 } | |
294 | |
295 void | |
10481 | 296 msn_session_set_error(MsnSession *session, MsnErrorType error, |
297 const char *info) | |
298 { | |
299 GaimConnection *gc; | |
300 char *msg; | |
301 | |
10568 | 302 gc = gaim_account_get_connection(session->account); |
10481 | 303 |
304 switch (error) | |
305 { | |
306 case MSN_ERROR_SERVCONN: | |
307 msg = g_strdup(info); | |
308 break; | |
10519 | 309 case MSN_ERROR_UNSUPPORTED_PROTOCOL: |
10481 | 310 msg = g_strdup(_("Our protocol is not supported by the " |
311 "server.")); | |
312 break; | |
313 case MSN_ERROR_HTTP_MALFORMED: | |
314 msg = g_strdup(_("Error parsing HTTP.")); | |
315 break; | |
316 case MSN_ERROR_SIGN_OTHER: | |
317 gc->wants_to_die = TRUE; | |
318 msg = g_strdup(_("You have signed on from another location.")); | |
319 break; | |
10568 | 320 case MSN_ERROR_SERV_UNAVAILABLE: |
321 msg = g_strdup(_("The MSN servers are temporarily " | |
322 "unavailable. Please wait and try " | |
323 "again.")); | |
324 break; | |
10481 | 325 case MSN_ERROR_SERV_DOWN: |
326 msg = g_strdup(_("The MSN servers are going down " | |
327 "temporarily.")); | |
328 break; | |
329 case MSN_ERROR_AUTH: | |
330 msg = g_strdup_printf(_("Unable to authenticate: %s"), | |
331 (info == NULL ) ? | |
332 _("Unknown error") : info); | |
333 break; | |
334 case MSN_ERROR_BAD_BLIST: | |
335 msg = g_strdup(_("Your MSN buddy list is temporarily " | |
336 "unavailable. Please wait and try " | |
337 "again.")); | |
338 break; | |
339 default: | |
340 msg = g_strdup(_("Unknown error.")); | |
341 break; | |
342 } | |
343 | |
344 msn_session_disconnect(session); | |
10533 | 345 |
10481 | 346 gaim_connection_error(gc, msg); |
347 | |
348 g_free(msg); | |
349 } | |
350 | |
351 static const char * | |
352 get_login_step_text(MsnSession *session) | |
353 { | |
354 const char *steps_text[] = { | |
355 _("Connecting"), | |
356 _("Handshaking"), | |
10514 | 357 _("Transferring"), |
358 _("Handshaking"), | |
10481 | 359 _("Starting authentication"), |
360 _("Getting cookie"), | |
361 _("Authenticating"), | |
362 _("Sending cookie"), | |
363 _("Retrieving buddy list") | |
364 }; | |
365 | |
366 return steps_text[session->login_step]; | |
367 } | |
368 | |
369 void | |
370 msn_session_set_login_step(MsnSession *session, MsnLoginStep step) | |
371 { | |
372 GaimConnection *gc; | |
373 | |
10519 | 374 /* Prevent the connection progress going backwards, eg. if we get |
375 * transferred several times during login */ | |
10582 | 376 if (session->login_step > step) |
10519 | 377 return; |
378 | |
379 /* If we're already logged in, we're probably here because of a | |
380 * mid-session XFR from the notification server, so we don't want to | |
381 * popup the connection progress dialog */ | |
382 if (session->logged_in) | |
383 return; | |
384 | |
10481 | 385 gc = session->account->gc; |
386 | |
387 session->login_step = step; | |
388 | |
389 gaim_connection_update_progress(gc, get_login_step_text(session), step, | |
390 MSN_LOGIN_STEPS); | |
391 } | |
392 | |
393 void | |
10044 | 394 msn_session_finish_login(MsnSession *session) |
395 { | |
396 GaimAccount *account; | |
397 GaimConnection *gc; | |
11303
10066662176a
[gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents:
10908
diff
changeset
|
398 char *icon; |
10044 | 399 |
10533 | 400 if (session->logged_in) |
401 return; | |
402 | |
10044 | 403 account = session->account; |
404 gc = gaim_account_get_connection(account); | |
405 | |
11303
10066662176a
[gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents:
10908
diff
changeset
|
406 icon = gaim_buddy_icons_get_full_path(gaim_account_get_buddy_icon(session->account)); |
10066662176a
[gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents:
10908
diff
changeset
|
407 msn_user_set_buddy_icon(session->user, icon); |
10066662176a
[gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents:
10908
diff
changeset
|
408 g_free(icon); |
10044 | 409 |
10908 | 410 session->logged_in = TRUE; |
411 | |
11992 | 412 msn_change_status(session); |
10044 | 413 |
414 gaim_connection_set_state(gc, GAIM_CONNECTED); | |
415 | |
416 /* Sync users */ | |
417 msn_session_sync_users(session); | |
418 } | |
19785 | 419 |