Mercurial > pidgin
annotate src/protocols/msn/session.c @ 11464:610a243b4504
[gaim-migrate @ 13704]
Fix Gaim's crash-on-exit bug in CVS HEAD
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 07 Sep 2005 04:37:02 +0000 |
parents | 10066662176a |
children | c824e39db0e7 |
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); |
10044 | 42 session->sync_userlist = msn_userlist_new(session); |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
43 |
10481 | 44 session->user = msn_user_new(session->userlist, |
45 gaim_account_get_username(account), NULL); | |
46 | |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
47 session->protocol_ver = 9; |
10621 | 48 session->conv_seq = 1; |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
49 |
5309 | 50 return session; |
51 } | |
52 | |
53 void | |
54 msn_session_destroy(MsnSession *session) | |
55 { | |
56 g_return_if_fail(session != NULL); | |
57 | |
10296 | 58 session->destroying = TRUE; |
59 | |
5309 | 60 if (session->connected) |
61 msn_session_disconnect(session); | |
62 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
63 if (session->notification != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
64 msn_notification_destroy(session->notification); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
65 |
5309 | 66 while (session->switches != NULL) |
67 msn_switchboard_destroy(session->switches->data); | |
68 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
69 while (session->slplinks != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
70 msn_slplink_destroy(session->slplinks->data); |
5309 | 71 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
72 msn_userlist_destroy(session->userlist); |
5309 | 73 |
10044 | 74 if (session->sync_userlist != NULL) |
75 msn_userlist_destroy(session->sync_userlist); | |
76 | |
6827
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
77 if (session->passport_info.kv != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
78 g_free(session->passport_info.kv); |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
79 |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
80 if (session->passport_info.sid != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
81 g_free(session->passport_info.sid); |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
82 |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
83 if (session->passport_info.mspauth != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
84 g_free(session->passport_info.mspauth); |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
85 |
10284 | 86 if (session->passport_info.client_ip != NULL) |
87 g_free(session->passport_info.client_ip); | |
88 | |
6827
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
89 if (session->passport_info.file != NULL) |
10275 | 90 { |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10582
diff
changeset
|
91 g_unlink(session->passport_info.file); |
6827
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
92 g_free(session->passport_info.file); |
10275 | 93 } |
5427 | 94 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
95 if (session->sync != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
96 msn_sync_destroy(session->sync); |
7590
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
97 |
8171
d0ba2f7b40e7
[gaim-migrate @ 8884]
Christian Hammond <chipx86@chipx86.com>
parents:
7590
diff
changeset
|
98 if (session->nexus != NULL) |
d0ba2f7b40e7
[gaim-migrate @ 8884]
Christian Hammond <chipx86@chipx86.com>
parents:
7590
diff
changeset
|
99 msn_nexus_destroy(session->nexus); |
d0ba2f7b40e7
[gaim-migrate @ 8884]
Christian Hammond <chipx86@chipx86.com>
parents:
7590
diff
changeset
|
100 |
10481 | 101 if (session->user != NULL) |
102 msn_user_destroy(session->user); | |
103 | |
5309 | 104 g_free(session); |
105 } | |
106 | |
107 gboolean | |
10481 | 108 msn_session_connect(MsnSession *session, const char *host, int port, |
109 gboolean http_method) | |
5309 | 110 { |
111 g_return_val_if_fail(session != NULL, FALSE); | |
112 g_return_val_if_fail(!session->connected, TRUE); | |
113 | |
114 session->connected = TRUE; | |
10481 | 115 session->http_method = http_method; |
5309 | 116 |
10463 | 117 if (session->notification == NULL) |
118 { | |
119 gaim_debug_error("msn", "This shouldn't happen\n"); | |
120 g_return_val_if_reached(FALSE); | |
121 } | |
122 | |
10481 | 123 if (msn_notification_connect(session->notification, host, port)) |
8831
ffecda0c1f45
[gaim-migrate @ 9595]
Christian Hammond <chipx86@chipx86.com>
parents:
8808
diff
changeset
|
124 { |
ffecda0c1f45
[gaim-migrate @ 9595]
Christian Hammond <chipx86@chipx86.com>
parents:
8808
diff
changeset
|
125 return TRUE; |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
126 } |
5309 | 127 |
128 return FALSE; | |
129 } | |
130 | |
131 void | |
132 msn_session_disconnect(MsnSession *session) | |
133 { | |
134 g_return_if_fail(session != NULL); | |
135 g_return_if_fail(session->connected); | |
136 | |
10481 | 137 session->connected = FALSE; |
138 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8831
diff
changeset
|
139 while (session->switches != NULL) |
10463 | 140 msn_switchboard_close(session->switches->data); |
5309 | 141 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
142 if (session->notification != NULL) |
10463 | 143 msn_notification_close(session->notification); |
5309 | 144 } |
145 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
146 /* TODO: This must go away when conversation is redesigned */ |
5309 | 147 MsnSwitchBoard * |
10621 | 148 msn_session_find_swboard(MsnSession *session, const char *username) |
5309 | 149 { |
150 GList *l; | |
151 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8831
diff
changeset
|
152 g_return_val_if_fail(session != NULL, NULL); |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
153 g_return_val_if_fail(username != NULL, NULL); |
5309 | 154 |
8499
467b01d02f9c
[gaim-migrate @ 9235]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
155 for (l = session->switches; l != NULL; l = l->next) |
467b01d02f9c
[gaim-migrate @ 9235]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
156 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
157 MsnSwitchBoard *swboard; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
158 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
159 swboard = l->data; |
5309 | 160 |
10621 | 161 if ((swboard->im_user != NULL) && !strcmp(username, swboard->im_user)) |
10602 | 162 return swboard; |
5309 | 163 } |
164 | |
165 return NULL; | |
166 } | |
167 | |
168 MsnSwitchBoard * | |
10621 | 169 msn_session_find_swboard_with_conv(MsnSession *session, GaimConversation *conv) |
170 { | |
171 GList *l; | |
172 | |
173 g_return_val_if_fail(session != NULL, NULL); | |
174 g_return_val_if_fail(conv != NULL, NULL); | |
175 | |
176 for (l = session->switches; l != NULL; l = l->next) | |
177 { | |
178 MsnSwitchBoard *swboard; | |
179 | |
180 swboard = l->data; | |
181 | |
182 if (swboard->conv == conv) | |
183 return swboard; | |
184 } | |
185 | |
186 return NULL; | |
187 } | |
188 | |
189 MsnSwitchBoard * | |
190 msn_session_find_swboard_with_id(const MsnSession *session, int chat_id) | |
5309 | 191 { |
192 GList *l; | |
193 | |
194 g_return_val_if_fail(session != NULL, NULL); | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
195 g_return_val_if_fail(chat_id >= 0, NULL); |
5309 | 196 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8831
diff
changeset
|
197 for (l = session->switches; l != NULL; l = l->next) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8831
diff
changeset
|
198 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
199 MsnSwitchBoard *swboard; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
200 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
201 swboard = l->data; |
5309 | 202 |
10621 | 203 if (swboard->chat_id == chat_id) |
5309 | 204 return swboard; |
205 } | |
206 | |
207 return NULL; | |
208 } | |
209 | |
210 MsnSwitchBoard * | |
10773 | 211 msn_session_get_swboard(MsnSession *session, const char *username, |
212 MsnSBFlag flag) | |
5309 | 213 { |
214 MsnSwitchBoard *swboard; | |
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 { | |
234 GList *l; | |
235 | |
236 l = session->sync_userlist->users; | |
237 | |
238 while (l != NULL) | |
239 { | |
240 MsnUser *local_user; | |
241 | |
242 local_user = (MsnUser *)l->data; | |
243 | |
244 if (local_user->passport != NULL) | |
245 { | |
246 MsnUser *remote_user; | |
247 | |
248 remote_user = msn_userlist_find_user(session->userlist, | |
249 local_user->passport); | |
250 | |
251 if (remote_user == NULL || | |
252 ((local_user->list_op & ( 1 << MSN_LIST_FL)) && | |
253 !(remote_user->list_op & ( 1 << MSN_LIST_FL)))) | |
254 { | |
255 /* The user was not on the server list */ | |
256 msn_show_sync_issue(session, local_user->passport, NULL); | |
257 } | |
258 else | |
259 { | |
260 GList *l; | |
261 | |
262 for (l = local_user->group_ids; l != NULL; l = l->next) | |
263 { | |
264 const char *group_name; | |
265 int gid; | |
266 gboolean found = FALSE; | |
267 GList *l2; | |
268 | |
269 group_name = | |
270 msn_userlist_find_group_name(local_user->userlist, | |
10112 | 271 GPOINTER_TO_INT(l->data)); |
10044 | 272 |
273 gid = msn_userlist_find_group_id(remote_user->userlist, | |
274 group_name); | |
275 | |
276 for (l2 = remote_user->group_ids; l2 != NULL; l2 = l2->next) | |
277 { | |
10112 | 278 if (GPOINTER_TO_INT(l2->data) == gid) |
10044 | 279 { |
280 found = TRUE; | |
281 break; | |
282 } | |
283 } | |
284 | |
285 if (!found) | |
286 { | |
287 /* The user was not on that group on the server list */ | |
288 msn_show_sync_issue(session, local_user->passport, | |
289 group_name); | |
290 } | |
291 } | |
292 } | |
293 } | |
294 | |
295 l = l->next; | |
296 } | |
297 | |
298 msn_userlist_destroy(session->sync_userlist); | |
299 session->sync_userlist = NULL; | |
300 } | |
301 | |
302 void | |
10481 | 303 msn_session_set_error(MsnSession *session, MsnErrorType error, |
304 const char *info) | |
305 { | |
306 GaimConnection *gc; | |
307 char *msg; | |
308 | |
10568 | 309 gc = gaim_account_get_connection(session->account); |
10481 | 310 |
311 switch (error) | |
312 { | |
313 case MSN_ERROR_SERVCONN: | |
314 msg = g_strdup(info); | |
315 break; | |
10519 | 316 case MSN_ERROR_UNSUPPORTED_PROTOCOL: |
10481 | 317 msg = g_strdup(_("Our protocol is not supported by the " |
318 "server.")); | |
319 break; | |
320 case MSN_ERROR_HTTP_MALFORMED: | |
321 msg = g_strdup(_("Error parsing HTTP.")); | |
322 break; | |
323 case MSN_ERROR_SIGN_OTHER: | |
324 gc->wants_to_die = TRUE; | |
325 msg = g_strdup(_("You have signed on from another location.")); | |
326 break; | |
10568 | 327 case MSN_ERROR_SERV_UNAVAILABLE: |
328 msg = g_strdup(_("The MSN servers are temporarily " | |
329 "unavailable. Please wait and try " | |
330 "again.")); | |
331 break; | |
10481 | 332 case MSN_ERROR_SERV_DOWN: |
333 msg = g_strdup(_("The MSN servers are going down " | |
334 "temporarily.")); | |
335 break; | |
336 case MSN_ERROR_AUTH: | |
337 msg = g_strdup_printf(_("Unable to authenticate: %s"), | |
338 (info == NULL ) ? | |
339 _("Unknown error") : info); | |
340 break; | |
341 case MSN_ERROR_BAD_BLIST: | |
342 msg = g_strdup(_("Your MSN buddy list is temporarily " | |
343 "unavailable. Please wait and try " | |
344 "again.")); | |
345 break; | |
346 default: | |
347 msg = g_strdup(_("Unknown error.")); | |
348 break; | |
349 } | |
350 | |
351 msn_session_disconnect(session); | |
10533 | 352 |
10481 | 353 gaim_connection_error(gc, msg); |
354 | |
355 g_free(msg); | |
356 } | |
357 | |
358 static const char * | |
359 get_login_step_text(MsnSession *session) | |
360 { | |
361 const char *steps_text[] = { | |
362 _("Connecting"), | |
363 _("Handshaking"), | |
10514 | 364 _("Transferring"), |
365 _("Handshaking"), | |
10481 | 366 _("Starting authentication"), |
367 _("Getting cookie"), | |
368 _("Authenticating"), | |
369 _("Sending cookie"), | |
370 _("Retrieving buddy list") | |
371 }; | |
372 | |
373 return steps_text[session->login_step]; | |
374 } | |
375 | |
376 void | |
377 msn_session_set_login_step(MsnSession *session, MsnLoginStep step) | |
378 { | |
379 GaimConnection *gc; | |
380 | |
10519 | 381 /* Prevent the connection progress going backwards, eg. if we get |
382 * transferred several times during login */ | |
10582 | 383 if (session->login_step > step) |
10519 | 384 return; |
385 | |
386 /* If we're already logged in, we're probably here because of a | |
387 * mid-session XFR from the notification server, so we don't want to | |
388 * popup the connection progress dialog */ | |
389 if (session->logged_in) | |
390 return; | |
391 | |
10481 | 392 gc = session->account->gc; |
393 | |
394 session->login_step = step; | |
395 | |
396 gaim_connection_update_progress(gc, get_login_step_text(session), step, | |
397 MSN_LOGIN_STEPS); | |
398 } | |
399 | |
400 void | |
10044 | 401 msn_session_finish_login(MsnSession *session) |
402 { | |
403 GaimAccount *account; | |
404 GaimConnection *gc; | |
11303
10066662176a
[gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents:
10908
diff
changeset
|
405 char *icon; |
10044 | 406 |
10533 | 407 if (session->logged_in) |
408 return; | |
409 | |
10044 | 410 account = session->account; |
411 gc = gaim_account_get_connection(account); | |
412 | |
11303
10066662176a
[gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents:
10908
diff
changeset
|
413 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
|
414 msn_user_set_buddy_icon(session->user, icon); |
10066662176a
[gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents:
10908
diff
changeset
|
415 g_free(icon); |
10044 | 416 |
10908 | 417 session->logged_in = TRUE; |
418 | |
419 msn_change_status(session, session->state == 0 ? MSN_ONLINE : session->state); | |
10044 | 420 |
421 gaim_connection_set_state(gc, GAIM_CONNECTED); | |
422 | |
423 /* Sync users */ | |
424 msn_session_sync_users(session); | |
425 } |