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