14192
|
1 /**
|
|
2 * @file notification.c Notification server functions
|
|
3 *
|
|
4 * gaim
|
|
5 *
|
|
6 * Gaim is the legal property of its developers, whose names are too numerous
|
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
8 * source distribution.
|
|
9 *
|
|
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 "notification.h"
|
|
26 #include "state.h"
|
|
27 #include "error.h"
|
|
28 #include "msn-utils.h"
|
|
29 #include "page.h"
|
|
30
|
|
31 #include "userlist.h"
|
|
32 #include "sync.h"
|
|
33 #include "slplink.h"
|
|
34
|
|
35 static MsnTable *cbs_table;
|
|
36
|
|
37 /**************************************************************************
|
|
38 * Main
|
|
39 **************************************************************************/
|
|
40
|
|
41 static void
|
|
42 destroy_cb(MsnServConn *servconn)
|
|
43 {
|
|
44 MsnNotification *notification;
|
|
45
|
|
46 notification = servconn->cmdproc->data;
|
|
47 g_return_if_fail(notification != NULL);
|
|
48
|
|
49 msn_notification_destroy(notification);
|
|
50 }
|
|
51
|
|
52 MsnNotification *
|
|
53 msn_notification_new(MsnSession *session)
|
|
54 {
|
|
55 MsnNotification *notification;
|
|
56 MsnServConn *servconn;
|
|
57
|
|
58 g_return_val_if_fail(session != NULL, NULL);
|
|
59
|
|
60 notification = g_new0(MsnNotification, 1);
|
|
61
|
|
62 notification->session = session;
|
|
63 notification->servconn = servconn = msn_servconn_new(session, MSN_SERVCONN_NS);
|
|
64 msn_servconn_set_destroy_cb(servconn, destroy_cb);
|
|
65
|
|
66 notification->cmdproc = servconn->cmdproc;
|
|
67 notification->cmdproc->data = notification;
|
|
68 notification->cmdproc->cbs_table = cbs_table;
|
|
69
|
|
70 return notification;
|
|
71 }
|
|
72
|
|
73 void
|
|
74 msn_notification_destroy(MsnNotification *notification)
|
|
75 {
|
|
76 notification->cmdproc->data = NULL;
|
|
77
|
|
78 msn_servconn_set_destroy_cb(notification->servconn, NULL);
|
|
79
|
|
80 msn_servconn_destroy(notification->servconn);
|
|
81
|
|
82 g_free(notification);
|
|
83 }
|
|
84
|
|
85 /**************************************************************************
|
|
86 * Connect
|
|
87 **************************************************************************/
|
|
88
|
|
89 static void
|
|
90 connect_cb(MsnServConn *servconn)
|
|
91 {
|
|
92 MsnCmdProc *cmdproc;
|
|
93 MsnSession *session;
|
|
94 GaimAccount *account;
|
|
95 char **a, **c, *vers;
|
|
96 int i;
|
|
97
|
|
98 g_return_if_fail(servconn != NULL);
|
|
99
|
|
100 cmdproc = servconn->cmdproc;
|
|
101 session = servconn->session;
|
|
102 account = session->account;
|
|
103
|
|
104 /* Allocate an array for CVR0, NULL, and all the versions */
|
|
105 a = c = g_new0(char *, session->protocol_ver - 8 + 3);
|
|
106
|
|
107 for (i = session->protocol_ver; i >= 8; i--)
|
|
108 *c++ = g_strdup_printf("MSNP%d", i);
|
|
109
|
|
110 *c++ = g_strdup("CVR0");
|
|
111
|
|
112 vers = g_strjoinv(" ", a);
|
|
113
|
|
114 if (session->login_step == MSN_LOGIN_STEP_START)
|
|
115 msn_session_set_login_step(session, MSN_LOGIN_STEP_HANDSHAKE);
|
|
116 else
|
|
117 msn_session_set_login_step(session, MSN_LOGIN_STEP_HANDSHAKE2);
|
|
118
|
|
119 msn_cmdproc_send(cmdproc, "VER", "%s", vers);
|
|
120
|
|
121 g_strfreev(a);
|
|
122 g_free(vers);
|
|
123 }
|
|
124
|
|
125 gboolean
|
|
126 msn_notification_connect(MsnNotification *notification, const char *host, int port)
|
|
127 {
|
|
128 MsnServConn *servconn;
|
|
129
|
|
130 g_return_val_if_fail(notification != NULL, FALSE);
|
|
131
|
|
132 servconn = notification->servconn;
|
|
133
|
|
134 msn_servconn_set_connect_cb(servconn, connect_cb);
|
|
135 notification->in_use = msn_servconn_connect(servconn, host, port);
|
|
136
|
|
137 return notification->in_use;
|
|
138 }
|
|
139
|
|
140 void
|
|
141 msn_notification_disconnect(MsnNotification *notification)
|
|
142 {
|
|
143 g_return_if_fail(notification != NULL);
|
|
144 g_return_if_fail(notification->in_use);
|
|
145
|
|
146 msn_servconn_disconnect(notification->servconn);
|
|
147
|
|
148 notification->in_use = FALSE;
|
|
149 }
|
|
150
|
|
151 /**************************************************************************
|
|
152 * Util
|
|
153 **************************************************************************/
|
|
154
|
|
155 static void
|
|
156 group_error_helper(MsnSession *session, const char *msg, int group_id, int error)
|
|
157 {
|
|
158 GaimAccount *account;
|
|
159 GaimConnection *gc;
|
|
160 char *reason = NULL;
|
|
161 char *title = NULL;
|
|
162
|
|
163 account = session->account;
|
|
164 gc = gaim_account_get_connection(account);
|
|
165
|
|
166 if (error == 224)
|
|
167 {
|
|
168 if (group_id == 0)
|
|
169 {
|
|
170 return;
|
|
171 }
|
|
172 else
|
|
173 {
|
|
174 const char *group_name;
|
|
175 group_name =
|
|
176 msn_userlist_find_group_name(session->userlist,
|
|
177 group_id);
|
|
178 reason = g_strdup_printf(_("%s is not a valid group."),
|
|
179 group_name);
|
|
180 }
|
|
181 }
|
|
182 else
|
|
183 {
|
|
184 reason = g_strdup(_("Unknown error."));
|
|
185 }
|
|
186
|
|
187 title = g_strdup_printf(_("%s on %s (%s)"), msg,
|
|
188 gaim_account_get_username(account),
|
|
189 gaim_account_get_protocol_name(account));
|
|
190 gaim_notify_error(gc, NULL, title, reason);
|
|
191 g_free(title);
|
|
192 g_free(reason);
|
|
193 }
|
|
194
|
|
195 /**************************************************************************
|
|
196 * Login
|
|
197 **************************************************************************/
|
|
198
|
|
199 void
|
|
200 msn_got_login_params(MsnSession *session, const char *login_params)
|
|
201 {
|
|
202 MsnCmdProc *cmdproc;
|
|
203
|
|
204 cmdproc = session->notification->cmdproc;
|
|
205
|
|
206 msn_session_set_login_step(session, MSN_LOGIN_STEP_AUTH_END);
|
|
207
|
|
208 msn_cmdproc_send(cmdproc, "USR", "TWN S %s", login_params);
|
|
209 }
|
|
210
|
|
211 static void
|
|
212 cvr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
213 {
|
|
214 GaimAccount *account;
|
|
215
|
|
216 account = cmdproc->session->account;
|
|
217
|
|
218 msn_cmdproc_send(cmdproc, "USR", "TWN I %s",
|
|
219 gaim_account_get_username(account));
|
|
220 }
|
|
221
|
|
222 static void
|
|
223 usr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
224 {
|
|
225 MsnSession *session;
|
|
226 GaimAccount *account;
|
|
227 GaimConnection *gc;
|
|
228
|
|
229 session = cmdproc->session;
|
|
230 account = session->account;
|
|
231 gc = gaim_account_get_connection(account);
|
|
232
|
|
233 if (!g_ascii_strcasecmp(cmd->params[1], "OK"))
|
|
234 {
|
|
235 /* OK */
|
|
236 const char *friendly = gaim_url_decode(cmd->params[3]);
|
|
237
|
|
238 gaim_connection_set_display_name(gc, friendly);
|
|
239
|
|
240 msn_session_set_login_step(session, MSN_LOGIN_STEP_SYN);
|
|
241
|
|
242 msn_cmdproc_send(cmdproc, "SYN", "%s", "0");
|
|
243 }
|
|
244 else if (!g_ascii_strcasecmp(cmd->params[1], "TWN"))
|
|
245 {
|
|
246 /* Passport authentication */
|
|
247 char **elems, **cur, **tokens;
|
|
248
|
|
249 session->nexus = msn_nexus_new(session);
|
|
250
|
|
251 /* Parse the challenge data. */
|
|
252
|
|
253 elems = g_strsplit(cmd->params[3], ",", 0);
|
|
254
|
|
255 for (cur = elems; *cur != NULL; cur++)
|
|
256 {
|
|
257 tokens = g_strsplit(*cur, "=", 2);
|
|
258 g_hash_table_insert(session->nexus->challenge_data, tokens[0], tokens[1]);
|
|
259 /* Don't free each of the tokens, only the array. */
|
|
260 g_free(tokens);
|
|
261 }
|
|
262
|
|
263 g_strfreev(elems);
|
|
264
|
|
265 msn_session_set_login_step(session, MSN_LOGIN_STEP_AUTH_START);
|
|
266
|
|
267 msn_nexus_connect(session->nexus);
|
|
268 }
|
|
269 }
|
|
270
|
|
271 static void
|
|
272 usr_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
|
|
273 {
|
|
274 MsnErrorType msnerr = 0;
|
|
275
|
|
276 switch (error)
|
|
277 {
|
|
278 case 500:
|
|
279 case 601:
|
|
280 case 910:
|
|
281 case 921:
|
|
282 msnerr = MSN_ERROR_SERV_UNAVAILABLE;
|
|
283 break;
|
|
284 case 911:
|
|
285 msnerr = MSN_ERROR_AUTH;
|
|
286 break;
|
|
287 default:
|
|
288 return;
|
|
289 break;
|
|
290 }
|
|
291
|
|
292 msn_session_set_error(cmdproc->session, msnerr, NULL);
|
|
293 }
|
|
294
|
|
295 static void
|
|
296 ver_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
297 {
|
|
298 MsnSession *session;
|
|
299 GaimAccount *account;
|
|
300 gboolean protocol_supported = FALSE;
|
|
301 char proto_str[8];
|
|
302 size_t i;
|
|
303
|
|
304 session = cmdproc->session;
|
|
305 account = session->account;
|
|
306
|
|
307 g_snprintf(proto_str, sizeof(proto_str), "MSNP%d", session->protocol_ver);
|
|
308
|
|
309 for (i = 1; i < cmd->param_count; i++)
|
|
310 {
|
|
311 if (!strcmp(cmd->params[i], proto_str))
|
|
312 {
|
|
313 protocol_supported = TRUE;
|
|
314 break;
|
|
315 }
|
|
316 }
|
|
317
|
|
318 if (!protocol_supported)
|
|
319 {
|
|
320 msn_session_set_error(session, MSN_ERROR_UNSUPPORTED_PROTOCOL,
|
|
321 NULL);
|
|
322 return;
|
|
323 }
|
|
324
|
|
325 msn_cmdproc_send(cmdproc, "CVR",
|
|
326 "0x0409 winnt 5.1 i386 MSNMSGR 6.0.0602 MSMSGS %s",
|
|
327 gaim_account_get_username(account));
|
|
328 }
|
|
329
|
|
330 /**************************************************************************
|
|
331 * Log out
|
|
332 **************************************************************************/
|
|
333
|
|
334 static void
|
|
335 out_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
336 {
|
|
337 if (!g_ascii_strcasecmp(cmd->params[0], "OTH"))
|
|
338 msn_session_set_error(cmdproc->session, MSN_ERROR_SIGN_OTHER,
|
|
339 NULL);
|
|
340 else if (!g_ascii_strcasecmp(cmd->params[0], "SSD"))
|
|
341 msn_session_set_error(cmdproc->session, MSN_ERROR_SERV_DOWN, NULL);
|
|
342 }
|
|
343
|
|
344 void
|
|
345 msn_notification_close(MsnNotification *notification)
|
|
346 {
|
|
347 g_return_if_fail(notification != NULL);
|
|
348
|
|
349 if (!notification->in_use)
|
|
350 return;
|
|
351
|
|
352 msn_cmdproc_send_quick(notification->cmdproc, "OUT", NULL, NULL);
|
|
353
|
|
354 msn_notification_disconnect(notification);
|
|
355 }
|
|
356
|
|
357 /**************************************************************************
|
|
358 * Messages
|
|
359 **************************************************************************/
|
|
360
|
|
361 static void
|
|
362 msg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload,
|
|
363 size_t len)
|
|
364 {
|
|
365 MsnMessage *msg;
|
|
366
|
|
367 msg = msn_message_new_from_cmd(cmdproc->session, cmd);
|
|
368
|
|
369 msn_message_parse_payload(msg, payload, len);
|
|
370 #ifdef MSN_DEBUG_NS
|
|
371 msn_message_show_readable(msg, "Notification", TRUE);
|
|
372 #endif
|
|
373
|
|
374 msn_cmdproc_process_msg(cmdproc, msg);
|
|
375
|
|
376 msn_message_destroy(msg);
|
|
377 }
|
|
378
|
|
379 static void
|
|
380 msg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
381 {
|
|
382 /* NOTE: cmd is not always cmdproc->last_cmd, sometimes cmd is a queued
|
|
383 * command and we are processing it */
|
|
384
|
|
385 if (cmd->payload == NULL)
|
|
386 {
|
|
387 cmdproc->last_cmd->payload_cb = msg_cmd_post;
|
|
388 cmdproc->servconn->payload_len = atoi(cmd->params[2]);
|
|
389 }
|
|
390 else
|
|
391 {
|
|
392 g_return_if_fail(cmd->payload_cb != NULL);
|
|
393
|
|
394 cmd->payload_cb(cmdproc, cmd, cmd->payload, cmd->payload_len);
|
|
395 }
|
|
396 }
|
|
397
|
|
398 /**************************************************************************
|
|
399 * Challenges
|
|
400 **************************************************************************/
|
|
401
|
|
402 static void
|
|
403 chl_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
404 {
|
|
405 MsnTransaction *trans;
|
|
406 char buf[33];
|
|
407 const char *challenge_resp;
|
|
408 GaimCipher *cipher;
|
|
409 GaimCipherContext *context;
|
|
410 guchar digest[16];
|
|
411 int i;
|
|
412
|
|
413 cipher = gaim_ciphers_find_cipher("md5");
|
|
414 context = gaim_cipher_context_new(cipher, NULL);
|
|
415
|
|
416 gaim_cipher_context_append(context, (const guchar *)cmd->params[1],
|
|
417 strlen(cmd->params[1]));
|
|
418
|
|
419 challenge_resp = "VT6PX?UQTM4WM%YR";
|
|
420
|
|
421 gaim_cipher_context_append(context, (const guchar *)challenge_resp,
|
|
422 strlen(challenge_resp));
|
|
423 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
|
|
424 gaim_cipher_context_destroy(context);
|
|
425
|
|
426 for (i = 0; i < 16; i++)
|
|
427 g_snprintf(buf + (i*2), 3, "%02x", digest[i]);
|
|
428
|
|
429 trans = msn_transaction_new(cmdproc, "QRY", "%s 32", "PROD0038W!61ZTF9");
|
|
430
|
|
431 msn_transaction_set_payload(trans, buf, 32);
|
|
432
|
|
433 msn_cmdproc_send_trans(cmdproc, trans);
|
|
434 }
|
|
435
|
|
436 /**************************************************************************
|
|
437 * Buddy Lists
|
|
438 **************************************************************************/
|
|
439
|
|
440 static void
|
|
441 add_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
442 {
|
|
443 MsnSession *session;
|
|
444 MsnUser *user;
|
|
445 const char *list;
|
|
446 const char *passport;
|
|
447 const char *friendly;
|
|
448 MsnListId list_id;
|
|
449 int group_id;
|
|
450
|
|
451 list = cmd->params[1];
|
|
452 passport = cmd->params[3];
|
|
453 friendly = gaim_url_decode(cmd->params[4]);
|
|
454
|
|
455 session = cmdproc->session;
|
|
456
|
|
457 user = msn_userlist_find_user(session->userlist, passport);
|
|
458
|
|
459 if (user == NULL)
|
|
460 {
|
|
461 user = msn_user_new(session->userlist, passport, friendly);
|
|
462 msn_userlist_add_user(session->userlist, user);
|
|
463 }
|
|
464 else
|
|
465 msn_user_set_friendly_name(user, friendly);
|
|
466
|
|
467 list_id = msn_get_list_id(list);
|
|
468
|
|
469 if (cmd->param_count >= 6)
|
|
470 group_id = atoi(cmd->params[5]);
|
|
471 else
|
|
472 group_id = -1;
|
|
473
|
|
474 msn_got_add_user(session, user, list_id, group_id);
|
|
475 msn_user_update(user);
|
|
476 }
|
|
477
|
|
478 static void
|
|
479 add_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
|
|
480 {
|
|
481 MsnSession *session;
|
|
482 GaimAccount *account;
|
|
483 GaimConnection *gc;
|
|
484 const char *list, *passport;
|
|
485 char *reason = NULL;
|
|
486 char *msg = NULL;
|
|
487 char **params;
|
|
488
|
|
489 session = cmdproc->session;
|
|
490 account = session->account;
|
|
491 gc = gaim_account_get_connection(account);
|
|
492 params = g_strsplit(trans->params, " ", 0);
|
|
493
|
|
494 list = params[0];
|
|
495 passport = params[1];
|
|
496
|
|
497 if (!strcmp(list, "FL"))
|
|
498 msg = g_strdup_printf(_("Unable to add user on %s (%s)"),
|
|
499 gaim_account_get_username(account),
|
|
500 gaim_account_get_protocol_name(account));
|
|
501 else if (!strcmp(list, "BL"))
|
|
502 msg = g_strdup_printf(_("Unable to block user on %s (%s)"),
|
|
503 gaim_account_get_username(account),
|
|
504 gaim_account_get_protocol_name(account));
|
|
505 else if (!strcmp(list, "AL"))
|
|
506 msg = g_strdup_printf(_("Unable to permit user on %s (%s)"),
|
|
507 gaim_account_get_username(account),
|
|
508 gaim_account_get_protocol_name(account));
|
|
509
|
|
510 if (!strcmp(list, "FL"))
|
|
511 {
|
|
512 if (error == 210)
|
|
513 {
|
|
514 reason = g_strdup_printf(_("%s could not be added because "
|
|
515 "your buddy list is full."), passport);
|
|
516 }
|
|
517 }
|
|
518
|
|
519 if (reason == NULL)
|
|
520 {
|
|
521 if (error == 208)
|
|
522 {
|
|
523 reason = g_strdup_printf(_("%s is not a valid passport account."),
|
|
524 passport);
|
|
525 }
|
|
526 else if (error == 500)
|
|
527 {
|
|
528 reason = g_strdup(_("Service Temporarily Unavailable."));
|
|
529 }
|
|
530 else
|
|
531 {
|
|
532 reason = g_strdup(_("Unknown error."));
|
|
533 }
|
|
534 }
|
|
535
|
|
536 if (msg != NULL)
|
|
537 {
|
|
538 gaim_notify_error(gc, NULL, msg, reason);
|
|
539 g_free(msg);
|
|
540 }
|
|
541
|
|
542 if (!strcmp(list, "FL"))
|
|
543 {
|
|
544 GaimBuddy *buddy;
|
|
545
|
|
546 buddy = gaim_find_buddy(account, passport);
|
|
547
|
|
548 if (buddy != NULL)
|
|
549 gaim_blist_remove_buddy(buddy);
|
|
550 }
|
|
551
|
|
552 g_free(reason);
|
|
553
|
|
554 g_strfreev(params);
|
|
555 }
|
|
556
|
|
557 static void
|
|
558 adg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
559 {
|
|
560 MsnSession *session;
|
|
561 gint group_id;
|
|
562 const char *group_name;
|
|
563
|
|
564 session = cmdproc->session;
|
|
565
|
|
566 group_id = atoi(cmd->params[3]);
|
|
567
|
|
568 group_name = gaim_url_decode(cmd->params[2]);
|
|
569
|
|
570 msn_group_new(session->userlist, group_id, group_name);
|
|
571
|
|
572 /* There is a user that must me moved to this group */
|
|
573 if (cmd->trans->data)
|
|
574 {
|
|
575 /* msn_userlist_move_buddy(); */
|
|
576 MsnUserList *userlist = cmdproc->session->userlist;
|
|
577 MsnMoveBuddy *data = cmd->trans->data;
|
|
578
|
|
579 if (data->old_group_name != NULL)
|
|
580 {
|
|
581 msn_userlist_rem_buddy(userlist, data->who, MSN_LIST_FL, data->old_group_name);
|
|
582 g_free(data->old_group_name);
|
|
583 }
|
|
584
|
|
585 msn_userlist_add_buddy(userlist, data->who, MSN_LIST_FL, group_name);
|
|
586 g_free(data->who);
|
|
587
|
|
588 }
|
|
589 }
|
|
590
|
|
591 static void
|
|
592 fln_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
593 {
|
|
594 MsnSlpLink *slplink;
|
|
595 MsnUser *user;
|
|
596
|
|
597 user = msn_userlist_find_user(cmdproc->session->userlist, cmd->params[0]);
|
|
598
|
|
599 user->status = "offline";
|
|
600 msn_user_update(user);
|
|
601
|
|
602 slplink = msn_session_find_slplink(cmdproc->session, cmd->params[0]);
|
|
603
|
|
604 if (slplink != NULL)
|
|
605 msn_slplink_destroy(slplink);
|
|
606
|
|
607 }
|
|
608
|
|
609 static void
|
|
610 iln_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
611 {
|
|
612 MsnSession *session;
|
|
613 GaimAccount *account;
|
|
614 GaimConnection *gc;
|
|
615 MsnUser *user;
|
|
616 MsnObject *msnobj;
|
|
617 const char *state, *passport, *friendly;
|
|
618
|
|
619 session = cmdproc->session;
|
|
620 account = session->account;
|
|
621 gc = gaim_account_get_connection(account);
|
|
622
|
|
623 state = cmd->params[1];
|
|
624 passport = cmd->params[2];
|
|
625 friendly = gaim_url_decode(cmd->params[3]);
|
|
626
|
|
627 user = msn_userlist_find_user(session->userlist, passport);
|
|
628
|
|
629 serv_got_alias(gc, passport, friendly);
|
|
630
|
|
631 msn_user_set_friendly_name(user, friendly);
|
|
632
|
|
633 if (session->protocol_ver >= 9 && cmd->param_count == 6)
|
|
634 {
|
|
635 msnobj = msn_object_new_from_string(gaim_url_decode(cmd->params[5]));
|
|
636 msn_user_set_object(user, msnobj);
|
|
637 }
|
|
638
|
|
639 msn_user_set_state(user, state);
|
|
640 msn_user_update(user);
|
|
641 }
|
|
642
|
|
643 static void
|
|
644 ipg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, size_t len)
|
|
645 {
|
|
646 #if 0
|
|
647 gaim_debug_misc("msn", "Incoming Page: {%s}\n", payload);
|
|
648 #endif
|
|
649 }
|
|
650
|
|
651 static void
|
|
652 ipg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
653 {
|
|
654 cmdproc->servconn->payload_len = atoi(cmd->params[0]);
|
|
655 cmdproc->last_cmd->payload_cb = ipg_cmd_post;
|
|
656 }
|
|
657
|
|
658 static void
|
|
659 nln_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
660 {
|
|
661 MsnSession *session;
|
|
662 GaimAccount *account;
|
|
663 GaimConnection *gc;
|
|
664 MsnUser *user;
|
|
665 MsnObject *msnobj;
|
|
666 int clientid;
|
|
667 const char *state, *passport, *friendly;
|
|
668
|
|
669 session = cmdproc->session;
|
|
670 account = session->account;
|
|
671 gc = gaim_account_get_connection(account);
|
|
672
|
|
673 state = cmd->params[0];
|
|
674 passport = cmd->params[1];
|
|
675 friendly = gaim_url_decode(cmd->params[2]);
|
|
676
|
|
677 user = msn_userlist_find_user(session->userlist, passport);
|
|
678
|
|
679 serv_got_alias(gc, passport, friendly);
|
|
680
|
|
681 msn_user_set_friendly_name(user, friendly);
|
|
682
|
|
683 if (session->protocol_ver >= 9)
|
|
684 {
|
|
685 if (cmd->param_count == 5)
|
|
686 {
|
|
687 msnobj =
|
|
688 msn_object_new_from_string(gaim_url_decode(cmd->params[4]));
|
|
689 msn_user_set_object(user, msnobj);
|
|
690 }
|
|
691 else
|
|
692 {
|
|
693 msn_user_set_object(user, NULL);
|
|
694 }
|
|
695 }
|
|
696
|
|
697 clientid = atoi(cmd->params[3]);
|
|
698 user->mobile = (clientid & MSN_CLIENT_CAP_MSNMOBILE);
|
|
699
|
|
700 msn_user_set_state(user, state);
|
|
701 msn_user_update(user);
|
|
702 }
|
|
703
|
|
704 #if 0
|
|
705 static void
|
|
706 chg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
707 {
|
|
708 char *state = cmd->params[1];
|
|
709 int state_id = 0;
|
|
710
|
|
711 if (!strcmp(state, "NLN"))
|
|
712 state_id = MSN_ONLINE;
|
|
713 else if (!strcmp(state, "BSY"))
|
|
714 state_id = MSN_BUSY;
|
|
715 else if (!strcmp(state, "IDL"))
|
|
716 state_id = MSN_IDLE;
|
|
717 else if (!strcmp(state, "BRB"))
|
|
718 state_id = MSN_BRB;
|
|
719 else if (!strcmp(state, "AWY"))
|
|
720 state_id = MSN_AWAY;
|
|
721 else if (!strcmp(state, "PHN"))
|
|
722 state_id = MSN_PHONE;
|
|
723 else if (!strcmp(state, "LUN"))
|
|
724 state_id = MSN_LUNCH;
|
|
725 else if (!strcmp(state, "HDN"))
|
|
726 state_id = MSN_HIDDEN;
|
|
727
|
|
728 cmdproc->session->state = state_id;
|
|
729 }
|
|
730 #endif
|
|
731
|
|
732
|
|
733 static void
|
|
734 not_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, size_t len)
|
|
735 {
|
|
736 #if 0
|
|
737 MSN_SET_PARAMS("NOT %d\r\n%s", cmdproc->servconn->payload, payload);
|
|
738 gaim_debug_misc("msn", "Notification: {%s}\n", payload);
|
|
739 #endif
|
|
740 }
|
|
741
|
|
742 static void
|
|
743 not_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
744 {
|
|
745 cmdproc->servconn->payload_len = atoi(cmd->params[0]);
|
|
746 cmdproc->last_cmd->payload_cb = not_cmd_post;
|
|
747 }
|
|
748
|
|
749 static void
|
|
750 rea_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
751 {
|
|
752 /* TODO: This might be for us too */
|
|
753
|
|
754 MsnSession *session;
|
|
755 GaimConnection *gc;
|
|
756 const char *friendly;
|
|
757
|
|
758 session = cmdproc->session;
|
|
759 gc = session->account->gc;
|
|
760 friendly = gaim_url_decode(cmd->params[3]);
|
|
761
|
|
762 gaim_connection_set_display_name(gc, friendly);
|
|
763 }
|
|
764
|
|
765 static void
|
|
766 prp_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
767 {
|
|
768 MsnSession *session = cmdproc->session;
|
|
769 const char *type, *value;
|
|
770
|
|
771 g_return_if_fail(cmd->param_count >= 3);
|
|
772
|
|
773 type = cmd->params[2];
|
|
774
|
|
775 if (cmd->param_count == 4)
|
|
776 {
|
|
777 value = cmd->params[3];
|
|
778 if (!strcmp(type, "PHH"))
|
|
779 msn_user_set_home_phone(session->user, gaim_url_decode(value));
|
|
780 else if (!strcmp(type, "PHW"))
|
|
781 msn_user_set_work_phone(session->user, gaim_url_decode(value));
|
|
782 else if (!strcmp(type, "PHM"))
|
|
783 msn_user_set_mobile_phone(session->user, gaim_url_decode(value));
|
|
784 }
|
|
785 else
|
|
786 {
|
|
787 if (!strcmp(type, "PHH"))
|
|
788 msn_user_set_home_phone(session->user, NULL);
|
|
789 else if (!strcmp(type, "PHW"))
|
|
790 msn_user_set_work_phone(session->user, NULL);
|
|
791 else if (!strcmp(type, "PHM"))
|
|
792 msn_user_set_mobile_phone(session->user, NULL);
|
|
793 }
|
|
794 }
|
|
795
|
|
796 static void
|
|
797 reg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
798 {
|
|
799 MsnSession *session;
|
|
800 int group_id;
|
|
801 const char *group_name;
|
|
802
|
|
803 session = cmdproc->session;
|
|
804 group_id = atoi(cmd->params[2]);
|
|
805 group_name = gaim_url_decode(cmd->params[3]);
|
|
806
|
|
807 msn_userlist_rename_group_id(session->userlist, group_id, group_name);
|
|
808 }
|
|
809
|
|
810 static void
|
|
811 reg_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
|
|
812 {
|
|
813 int group_id;
|
|
814 char **params;
|
|
815
|
|
816 params = g_strsplit(trans->params, " ", 0);
|
|
817
|
|
818 group_id = atoi(params[0]);
|
|
819
|
|
820 group_error_helper(cmdproc->session, _("Unable to rename group"), group_id, error);
|
|
821
|
|
822 g_strfreev(params);
|
|
823 }
|
|
824
|
|
825 static void
|
|
826 rem_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
827 {
|
|
828 MsnSession *session;
|
|
829 MsnUser *user;
|
|
830 const char *list;
|
|
831 const char *passport;
|
|
832 MsnListId list_id;
|
|
833 int group_id;
|
|
834
|
|
835 session = cmdproc->session;
|
|
836 list = cmd->params[1];
|
|
837 passport = cmd->params[3];
|
|
838 user = msn_userlist_find_user(session->userlist, passport);
|
|
839
|
|
840 g_return_if_fail(user != NULL);
|
|
841
|
|
842 list_id = msn_get_list_id(list);
|
|
843
|
|
844 if (cmd->param_count == 5)
|
|
845 group_id = atoi(cmd->params[4]);
|
|
846 else
|
|
847 group_id = -1;
|
|
848
|
|
849 msn_got_rem_user(session, user, list_id, group_id);
|
|
850 msn_user_update(user);
|
|
851 }
|
|
852
|
|
853 static void
|
|
854 rmg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
855 {
|
|
856 MsnSession *session;
|
|
857 int group_id;
|
|
858
|
|
859 session = cmdproc->session;
|
|
860 group_id = atoi(cmd->params[2]);
|
|
861
|
|
862 msn_userlist_remove_group_id(session->userlist, group_id);
|
|
863 }
|
|
864
|
|
865 static void
|
|
866 rmg_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
|
|
867 {
|
|
868 int group_id;
|
|
869 char **params;
|
|
870
|
|
871 params = g_strsplit(trans->params, " ", 0);
|
|
872
|
|
873 group_id = atoi(params[0]);
|
|
874
|
|
875 group_error_helper(cmdproc->session, _("Unable to delete group"), group_id, error);
|
|
876
|
|
877 g_strfreev(params);
|
|
878 }
|
|
879
|
|
880 static void
|
|
881 syn_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
882 {
|
|
883 MsnSession *session;
|
|
884 int total_users;
|
|
885
|
|
886 session = cmdproc->session;
|
|
887
|
|
888 if (cmd->param_count == 2)
|
|
889 {
|
|
890 /*
|
|
891 * This can happen if we sent a SYN with an up-to-date
|
|
892 * buddy list revision, but we send 0 to get a full list.
|
|
893 * So, error out.
|
|
894 */
|
|
895
|
|
896 msn_session_set_error(cmdproc->session, MSN_ERROR_BAD_BLIST, NULL);
|
|
897 return;
|
|
898 }
|
|
899
|
|
900 total_users = atoi(cmd->params[2]);
|
|
901
|
|
902 if (total_users == 0)
|
|
903 {
|
|
904 msn_session_finish_login(session);
|
|
905 }
|
|
906 else
|
|
907 {
|
|
908 /* syn_table */
|
|
909 MsnSync *sync;
|
|
910
|
|
911 sync = msn_sync_new(session);
|
|
912 sync->total_users = total_users;
|
|
913 sync->old_cbs_table = cmdproc->cbs_table;
|
|
914
|
|
915 session->sync = sync;
|
|
916 cmdproc->cbs_table = sync->cbs_table;
|
|
917 }
|
|
918 }
|
|
919
|
|
920 /**************************************************************************
|
|
921 * Misc commands
|
|
922 **************************************************************************/
|
|
923
|
|
924 static void
|
|
925 url_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
926 {
|
|
927 MsnSession *session;
|
|
928 GaimAccount *account;
|
|
929 const char *rru;
|
|
930 const char *url;
|
|
931 GaimCipher *cipher;
|
|
932 GaimCipherContext *context;
|
|
933 guchar digest[16];
|
|
934 FILE *fd;
|
|
935 char *buf;
|
|
936 char buf2[3];
|
|
937 char sendbuf[64];
|
|
938 int i;
|
|
939
|
|
940 session = cmdproc->session;
|
|
941 account = session->account;
|
|
942
|
|
943 rru = cmd->params[1];
|
|
944 url = cmd->params[2];
|
|
945
|
|
946 buf = g_strdup_printf("%s%lu%s",
|
|
947 session->passport_info.mspauth,
|
|
948 time(NULL) - session->passport_info.sl,
|
|
949 gaim_connection_get_password(account->gc));
|
|
950
|
|
951 cipher = gaim_ciphers_find_cipher("md5");
|
|
952 context = gaim_cipher_context_new(cipher, NULL);
|
|
953
|
|
954 gaim_cipher_context_append(context, (const guchar *)buf, strlen(buf));
|
|
955 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
|
|
956 gaim_cipher_context_destroy(context);
|
|
957
|
|
958 g_free(buf);
|
|
959
|
|
960 memset(sendbuf, 0, sizeof(sendbuf));
|
|
961
|
|
962 for (i = 0; i < 16; i++)
|
|
963 {
|
|
964 g_snprintf(buf2, sizeof(buf2), "%02x", digest[i]);
|
|
965 strcat(sendbuf, buf2);
|
|
966 }
|
|
967
|
|
968 if (session->passport_info.file != NULL)
|
|
969 {
|
|
970 g_unlink(session->passport_info.file);
|
|
971 g_free(session->passport_info.file);
|
|
972 }
|
|
973
|
|
974 if ((fd = gaim_mkstemp(&session->passport_info.file, FALSE)) == NULL)
|
|
975 {
|
|
976 gaim_debug_error("msn",
|
|
977 "Error opening temp passport file: %s\n",
|
|
978 strerror(errno));
|
|
979 }
|
|
980 else
|
|
981 {
|
|
982 fputs("<html>\n"
|
|
983 "<head>\n"
|
|
984 "<noscript>\n"
|
|
985 "<meta http-equiv=\"Refresh\" content=\"0; "
|
|
986 "url=http://www.hotmail.com\">\n"
|
|
987 "</noscript>\n"
|
|
988 "</head>\n\n",
|
|
989 fd);
|
|
990
|
|
991 fprintf(fd, "<body onload=\"document.pform.submit(); \">\n");
|
|
992 fprintf(fd, "<form name=\"pform\" action=\"%s\" method=\"POST\">\n\n",
|
|
993 url);
|
|
994 fprintf(fd, "<input type=\"hidden\" name=\"mode\" value=\"ttl\">\n");
|
|
995 fprintf(fd, "<input type=\"hidden\" name=\"login\" value=\"%s\">\n",
|
|
996 gaim_account_get_username(account));
|
|
997 fprintf(fd, "<input type=\"hidden\" name=\"username\" value=\"%s\">\n",
|
|
998 gaim_account_get_username(account));
|
|
999 fprintf(fd, "<input type=\"hidden\" name=\"sid\" value=\"%s\">\n",
|
|
1000 session->passport_info.sid);
|
|
1001 fprintf(fd, "<input type=\"hidden\" name=\"kv\" value=\"%s\">\n",
|
|
1002 session->passport_info.kv);
|
|
1003 fprintf(fd, "<input type=\"hidden\" name=\"id\" value=\"2\">\n");
|
|
1004 fprintf(fd, "<input type=\"hidden\" name=\"sl\" value=\"%ld\">\n",
|
|
1005 time(NULL) - session->passport_info.sl);
|
|
1006 fprintf(fd, "<input type=\"hidden\" name=\"rru\" value=\"%s\">\n",
|
|
1007 rru);
|
|
1008 fprintf(fd, "<input type=\"hidden\" name=\"auth\" value=\"%s\">\n",
|
|
1009 session->passport_info.mspauth);
|
|
1010 fprintf(fd, "<input type=\"hidden\" name=\"creds\" value=\"%s\">\n",
|
|
1011 sendbuf); /* TODO Digest me (huh? -- ChipX86) */
|
|
1012 fprintf(fd, "<input type=\"hidden\" name=\"svc\" value=\"mail\">\n");
|
|
1013 fprintf(fd, "<input type=\"hidden\" name=\"js\" value=\"yes\">\n");
|
|
1014 fprintf(fd, "</form></body>\n");
|
|
1015 fprintf(fd, "</html>\n");
|
|
1016
|
|
1017 if (fclose(fd))
|
|
1018 {
|
|
1019 gaim_debug_error("msn",
|
|
1020 "Error closing temp passport file: %s\n",
|
|
1021 strerror(errno));
|
|
1022
|
|
1023 g_unlink(session->passport_info.file);
|
|
1024 g_free(session->passport_info.file);
|
|
1025 session->passport_info.file = NULL;
|
|
1026 }
|
|
1027 #ifdef _WIN32
|
|
1028 else
|
|
1029 {
|
|
1030 /*
|
|
1031 * Renaming file with .html extension, so that the
|
|
1032 * win32 open_url will work.
|
|
1033 */
|
|
1034 char *tmp;
|
|
1035
|
|
1036 if ((tmp =
|
|
1037 g_strdup_printf("%s.html",
|
|
1038 session->passport_info.file)) != NULL)
|
|
1039 {
|
|
1040 if (g_rename(session->passport_info.file,
|
|
1041 tmp) == 0)
|
|
1042 {
|
|
1043 g_free(session->passport_info.file);
|
|
1044 session->passport_info.file = tmp;
|
|
1045 }
|
|
1046 else
|
|
1047 g_free(tmp);
|
|
1048 }
|
|
1049 }
|
|
1050 #endif
|
|
1051 }
|
|
1052 }
|
|
1053 /**************************************************************************
|
|
1054 * Switchboards
|
|
1055 **************************************************************************/
|
|
1056
|
|
1057 static void
|
|
1058 rng_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
1059 {
|
|
1060 MsnSession *session;
|
|
1061 MsnSwitchBoard *swboard;
|
|
1062 const char *session_id;
|
|
1063 char *host;
|
|
1064 int port;
|
|
1065
|
|
1066 session = cmdproc->session;
|
|
1067 session_id = cmd->params[0];
|
|
1068
|
|
1069 msn_parse_socket(cmd->params[1], &host, &port);
|
|
1070
|
|
1071 if (session->http_method)
|
|
1072 port = 80;
|
|
1073
|
|
1074 swboard = msn_switchboard_new(session);
|
|
1075
|
|
1076 msn_switchboard_set_invited(swboard, TRUE);
|
|
1077 msn_switchboard_set_session_id(swboard, cmd->params[0]);
|
|
1078 msn_switchboard_set_auth_key(swboard, cmd->params[3]);
|
|
1079 swboard->im_user = g_strdup(cmd->params[4]);
|
|
1080 /* msn_switchboard_add_user(swboard, cmd->params[4]); */
|
|
1081
|
|
1082 if (!msn_switchboard_connect(swboard, host, port))
|
|
1083 msn_switchboard_destroy(swboard);
|
|
1084
|
|
1085 g_free(host);
|
|
1086 }
|
|
1087
|
|
1088 static void
|
|
1089 xfr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
1090 {
|
|
1091 char *host;
|
|
1092 int port;
|
|
1093
|
|
1094 if (strcmp(cmd->params[1], "SB") && strcmp(cmd->params[1], "NS"))
|
|
1095 {
|
|
1096 /* Maybe we can have a generic bad command error. */
|
|
1097 gaim_debug_error("msn", "Bad XFR command (%s)\n", cmd->params[1]);
|
|
1098 return;
|
|
1099 }
|
|
1100
|
|
1101 msn_parse_socket(cmd->params[2], &host, &port);
|
|
1102
|
|
1103 if (!strcmp(cmd->params[1], "SB"))
|
|
1104 {
|
|
1105 gaim_debug_error("msn", "This shouldn't be handled here.\n");
|
|
1106 }
|
|
1107 else if (!strcmp(cmd->params[1], "NS"))
|
|
1108 {
|
|
1109 MsnSession *session;
|
|
1110
|
|
1111 session = cmdproc->session;
|
|
1112
|
|
1113 msn_session_set_login_step(session, MSN_LOGIN_STEP_TRANSFER);
|
|
1114
|
|
1115 msn_notification_connect(session->notification, host, port);
|
|
1116 }
|
|
1117
|
|
1118 g_free(host);
|
|
1119 }
|
|
1120
|
|
1121 /**************************************************************************
|
|
1122 * Message Types
|
|
1123 **************************************************************************/
|
|
1124
|
|
1125 static void
|
|
1126 profile_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
|
|
1127 {
|
|
1128 MsnSession *session;
|
|
1129 const char *value;
|
|
1130
|
|
1131 session = cmdproc->session;
|
|
1132
|
|
1133 if (strcmp(msg->remote_user, "Hotmail"))
|
|
1134 /* This isn't an official message. */
|
|
1135 return;
|
|
1136
|
|
1137 if ((value = msn_message_get_attr(msg, "kv")) != NULL)
|
|
1138 {
|
|
1139 if (session->passport_info.kv != NULL)
|
|
1140 g_free(session->passport_info.kv);
|
|
1141
|
|
1142 session->passport_info.kv = g_strdup(value);
|
|
1143 }
|
|
1144
|
|
1145 if ((value = msn_message_get_attr(msg, "sid")) != NULL)
|
|
1146 {
|
|
1147 if (session->passport_info.sid != NULL)
|
|
1148 g_free(session->passport_info.sid);
|
|
1149
|
|
1150 session->passport_info.sid = g_strdup(value);
|
|
1151 }
|
|
1152
|
|
1153 if ((value = msn_message_get_attr(msg, "MSPAuth")) != NULL)
|
|
1154 {
|
|
1155 if (session->passport_info.mspauth != NULL)
|
|
1156 g_free(session->passport_info.mspauth);
|
|
1157
|
|
1158 session->passport_info.mspauth = g_strdup(value);
|
|
1159 }
|
|
1160
|
|
1161 if ((value = msn_message_get_attr(msg, "ClientIP")) != NULL)
|
|
1162 {
|
|
1163 if (session->passport_info.client_ip != NULL)
|
|
1164 g_free(session->passport_info.client_ip);
|
|
1165
|
|
1166 session->passport_info.client_ip = g_strdup(value);
|
|
1167 }
|
|
1168
|
|
1169 if ((value = msn_message_get_attr(msg, "ClientPort")) != NULL)
|
|
1170 session->passport_info.client_port = ntohs(atoi(value));
|
|
1171
|
|
1172 if ((value = msn_message_get_attr(msg, "LoginTime")) != NULL)
|
|
1173 session->passport_info.sl = atol(value);
|
|
1174 }
|
|
1175
|
|
1176 static void
|
|
1177 initial_email_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
|
|
1178 {
|
|
1179 MsnSession *session;
|
|
1180 GaimConnection *gc;
|
|
1181 GHashTable *table;
|
|
1182 const char *unread;
|
|
1183
|
|
1184 session = cmdproc->session;
|
|
1185 gc = session->account->gc;
|
|
1186
|
|
1187 if (strcmp(msg->remote_user, "Hotmail"))
|
|
1188 /* This isn't an official message. */
|
|
1189 return;
|
|
1190
|
|
1191 if (session->passport_info.file == NULL)
|
|
1192 {
|
|
1193 MsnTransaction *trans;
|
|
1194 trans = msn_transaction_new(cmdproc, "URL", "%s", "INBOX");
|
|
1195 msn_transaction_queue_cmd(trans, msg->cmd);
|
|
1196
|
|
1197 msn_cmdproc_send_trans(cmdproc, trans);
|
|
1198
|
|
1199 return;
|
|
1200 }
|
|
1201
|
|
1202 if (!gaim_account_get_check_mail(session->account))
|
|
1203 return;
|
|
1204
|
|
1205 table = msn_message_get_hashtable_from_body(msg);
|
|
1206
|
|
1207 unread = g_hash_table_lookup(table, "Inbox-Unread");
|
|
1208
|
|
1209 if (unread != NULL)
|
|
1210 {
|
|
1211 int count = atoi(unread);
|
|
1212
|
|
1213 if (count > 0)
|
|
1214 {
|
|
1215 const char *passport;
|
|
1216 const char *url;
|
|
1217
|
|
1218 passport = msn_user_get_passport(session->user);
|
|
1219 url = session->passport_info.file;
|
|
1220
|
|
1221 gaim_notify_emails(gc, atoi(unread), FALSE, NULL, NULL,
|
|
1222 &passport, &url, NULL, NULL);
|
|
1223 }
|
|
1224 }
|
|
1225
|
|
1226 g_hash_table_destroy(table);
|
|
1227 }
|
|
1228
|
|
1229 static void
|
|
1230 email_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
|
|
1231 {
|
|
1232 MsnSession *session;
|
|
1233 GaimConnection *gc;
|
|
1234 GHashTable *table;
|
|
1235 char *from, *subject, *tmp;
|
|
1236
|
|
1237 session = cmdproc->session;
|
|
1238 gc = session->account->gc;
|
|
1239
|
|
1240 if (strcmp(msg->remote_user, "Hotmail"))
|
|
1241 /* This isn't an official message. */
|
|
1242 return;
|
|
1243
|
|
1244 if (session->passport_info.file == NULL)
|
|
1245 {
|
|
1246 MsnTransaction *trans;
|
|
1247 trans = msn_transaction_new(cmdproc, "URL", "%s", "INBOX");
|
|
1248 msn_transaction_queue_cmd(trans, msg->cmd);
|
|
1249
|
|
1250 msn_cmdproc_send_trans(cmdproc, trans);
|
|
1251
|
|
1252 return;
|
|
1253 }
|
|
1254
|
|
1255 if (!gaim_account_get_check_mail(session->account))
|
|
1256 return;
|
|
1257
|
|
1258 table = msn_message_get_hashtable_from_body(msg);
|
|
1259
|
|
1260 from = subject = NULL;
|
|
1261
|
|
1262 tmp = g_hash_table_lookup(table, "From");
|
|
1263 if (tmp != NULL)
|
|
1264 from = gaim_mime_decode_field(tmp);
|
|
1265
|
|
1266 tmp = g_hash_table_lookup(table, "Subject");
|
|
1267 if (tmp != NULL)
|
|
1268 subject = gaim_mime_decode_field(tmp);
|
|
1269
|
|
1270 gaim_notify_email(gc,
|
|
1271 (subject != NULL ? subject : ""),
|
|
1272 (from != NULL ? from : ""),
|
|
1273 msn_user_get_passport(session->user),
|
|
1274 session->passport_info.file, NULL, NULL);
|
|
1275
|
|
1276 if (from != NULL)
|
|
1277 g_free(from);
|
|
1278
|
|
1279 if (subject != NULL)
|
|
1280 g_free(subject);
|
|
1281
|
|
1282 g_hash_table_destroy(table);
|
|
1283 }
|
|
1284
|
|
1285 static void
|
|
1286 system_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
|
|
1287 {
|
|
1288 GHashTable *table;
|
|
1289 const char *type_s;
|
|
1290
|
|
1291 if (strcmp(msg->remote_user, "Hotmail"))
|
|
1292 /* This isn't an official message. */
|
|
1293 return;
|
|
1294
|
|
1295 table = msn_message_get_hashtable_from_body(msg);
|
|
1296
|
|
1297 if ((type_s = g_hash_table_lookup(table, "Type")) != NULL)
|
|
1298 {
|
|
1299 int type = atoi(type_s);
|
|
1300 char buf[MSN_BUF_LEN];
|
|
1301 int minutes;
|
|
1302
|
|
1303 switch (type)
|
|
1304 {
|
|
1305 case 1:
|
|
1306 minutes = atoi(g_hash_table_lookup(table, "Arg1"));
|
|
1307 g_snprintf(buf, sizeof(buf), ngettext(
|
|
1308 "The MSN server will shut down for maintenance "
|
|
1309 "in %d minute. You will automatically be "
|
|
1310 "signed out at that time. Please finish any "
|
|
1311 "conversations in progress.\n\nAfter the "
|
|
1312 "maintenance has been completed, you will be "
|
|
1313 "able to successfully sign in.",
|
|
1314 "The MSN server will shut down for maintenance "
|
|
1315 "in %d minutes. You will automatically be "
|
|
1316 "signed out at that time. Please finish any "
|
|
1317 "conversations in progress.\n\nAfter the "
|
|
1318 "maintenance has been completed, you will be "
|
|
1319 "able to successfully sign in.", minutes),
|
|
1320 minutes);
|
|
1321 default:
|
|
1322 break;
|
|
1323 }
|
|
1324
|
|
1325 if (*buf != '\0')
|
|
1326 gaim_notify_info(cmdproc->session->account->gc, NULL, buf, NULL);
|
|
1327 }
|
|
1328
|
|
1329 g_hash_table_destroy(table);
|
|
1330 }
|
|
1331
|
|
1332 void
|
|
1333 msn_notification_add_buddy(MsnNotification *notification, const char *list,
|
|
1334 const char *who, const char *store_name,
|
|
1335 int group_id)
|
|
1336 {
|
|
1337 MsnCmdProc *cmdproc;
|
|
1338 cmdproc = notification->servconn->cmdproc;
|
|
1339
|
|
1340 if (group_id < 0 && !strcmp(list, "FL"))
|
|
1341 group_id = 0;
|
|
1342
|
|
1343 if (group_id >= 0)
|
|
1344 {
|
|
1345 msn_cmdproc_send(cmdproc, "ADD", "%s %s %s %d",
|
|
1346 list, who, store_name, group_id);
|
|
1347 }
|
|
1348 else
|
|
1349 {
|
|
1350 msn_cmdproc_send(cmdproc, "ADD", "%s %s %s", list, who, store_name);
|
|
1351 }
|
|
1352 }
|
|
1353
|
|
1354 void
|
|
1355 msn_notification_rem_buddy(MsnNotification *notification, const char *list,
|
|
1356 const char *who, int group_id)
|
|
1357 {
|
|
1358 MsnCmdProc *cmdproc;
|
|
1359 cmdproc = notification->servconn->cmdproc;
|
|
1360
|
|
1361 if (group_id >= 0)
|
|
1362 {
|
|
1363 msn_cmdproc_send(cmdproc, "REM", "%s %s %d", list, who, group_id);
|
|
1364 }
|
|
1365 else
|
|
1366 {
|
|
1367 msn_cmdproc_send(cmdproc, "REM", "%s %s", list, who);
|
|
1368 }
|
|
1369 }
|
|
1370
|
|
1371 /**************************************************************************
|
|
1372 * Init
|
|
1373 **************************************************************************/
|
|
1374
|
|
1375 void
|
|
1376 msn_notification_init(void)
|
|
1377 {
|
|
1378 /* TODO: check prp, blp */
|
|
1379
|
|
1380 cbs_table = msn_table_new();
|
|
1381
|
|
1382 /* Synchronous */
|
|
1383 msn_table_add_cmd(cbs_table, "CHG", "CHG", NULL);
|
|
1384 msn_table_add_cmd(cbs_table, "CHG", "ILN", iln_cmd);
|
|
1385 msn_table_add_cmd(cbs_table, "ADD", "ADD", add_cmd);
|
|
1386 msn_table_add_cmd(cbs_table, "ADD", "ILN", iln_cmd);
|
|
1387 msn_table_add_cmd(cbs_table, "REM", "REM", rem_cmd);
|
|
1388 msn_table_add_cmd(cbs_table, "USR", "USR", usr_cmd);
|
|
1389 msn_table_add_cmd(cbs_table, "USR", "XFR", xfr_cmd);
|
|
1390 msn_table_add_cmd(cbs_table, "SYN", "SYN", syn_cmd);
|
|
1391 msn_table_add_cmd(cbs_table, "CVR", "CVR", cvr_cmd);
|
|
1392 msn_table_add_cmd(cbs_table, "VER", "VER", ver_cmd);
|
|
1393 msn_table_add_cmd(cbs_table, "REA", "REA", rea_cmd);
|
|
1394 msn_table_add_cmd(cbs_table, "PRP", "PRP", prp_cmd);
|
|
1395 /* msn_table_add_cmd(cbs_table, "BLP", "BLP", blp_cmd); */
|
|
1396 msn_table_add_cmd(cbs_table, "BLP", "BLP", NULL);
|
|
1397 msn_table_add_cmd(cbs_table, "REG", "REG", reg_cmd);
|
|
1398 msn_table_add_cmd(cbs_table, "ADG", "ADG", adg_cmd);
|
|
1399 msn_table_add_cmd(cbs_table, "RMG", "RMG", rmg_cmd);
|
|
1400 msn_table_add_cmd(cbs_table, "XFR", "XFR", xfr_cmd);
|
|
1401
|
|
1402 /* Asynchronous */
|
|
1403 msn_table_add_cmd(cbs_table, NULL, "IPG", ipg_cmd);
|
|
1404 msn_table_add_cmd(cbs_table, NULL, "MSG", msg_cmd);
|
|
1405 msn_table_add_cmd(cbs_table, NULL, "NOT", not_cmd);
|
|
1406
|
|
1407 msn_table_add_cmd(cbs_table, NULL, "CHL", chl_cmd);
|
|
1408 msn_table_add_cmd(cbs_table, NULL, "REM", rem_cmd);
|
|
1409 msn_table_add_cmd(cbs_table, NULL, "ADD", add_cmd);
|
|
1410
|
|
1411 msn_table_add_cmd(cbs_table, NULL, "QRY", NULL);
|
|
1412 msn_table_add_cmd(cbs_table, NULL, "QNG", NULL);
|
|
1413 msn_table_add_cmd(cbs_table, NULL, "FLN", fln_cmd);
|
|
1414 msn_table_add_cmd(cbs_table, NULL, "NLN", nln_cmd);
|
|
1415 msn_table_add_cmd(cbs_table, NULL, "ILN", iln_cmd);
|
|
1416 msn_table_add_cmd(cbs_table, NULL, "OUT", out_cmd);
|
|
1417 msn_table_add_cmd(cbs_table, NULL, "RNG", rng_cmd);
|
|
1418
|
|
1419 msn_table_add_cmd(cbs_table, NULL, "URL", url_cmd);
|
|
1420
|
|
1421 msn_table_add_cmd(cbs_table, "fallback", "XFR", xfr_cmd);
|
|
1422
|
|
1423 msn_table_add_error(cbs_table, "ADD", add_error);
|
|
1424 msn_table_add_error(cbs_table, "REG", reg_error);
|
|
1425 msn_table_add_error(cbs_table, "RMG", rmg_error);
|
|
1426 /* msn_table_add_error(cbs_table, "REA", rea_error); */
|
|
1427 msn_table_add_error(cbs_table, "USR", usr_error);
|
|
1428
|
|
1429 msn_table_add_msg_type(cbs_table,
|
|
1430 "text/x-msmsgsprofile",
|
|
1431 profile_msg);
|
|
1432 msn_table_add_msg_type(cbs_table,
|
|
1433 "text/x-msmsgsinitialemailnotification",
|
|
1434 initial_email_msg);
|
|
1435 msn_table_add_msg_type(cbs_table,
|
|
1436 "text/x-msmsgsemailnotification",
|
|
1437 email_msg);
|
|
1438 msn_table_add_msg_type(cbs_table,
|
|
1439 "application/x-msmsgssystemmessage",
|
|
1440 system_msg);
|
|
1441 }
|
|
1442
|
|
1443 void
|
|
1444 msn_notification_end(void)
|
|
1445 {
|
|
1446 msn_table_destroy(cbs_table);
|
|
1447 }
|