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