Mercurial > pidgin
comparison src/protocols/msn/msn.c @ 9158:c30d81b4dd22
[gaim-migrate @ 9942]
Patch from Felipe Contreras to sync our MSN prpl with what's in his tree.
He says this may fix a couple bugs, but the important thing is the
restructuring of how MsnMessages work. Lots of style changes and other
stuff as well.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Tue, 01 Jun 2004 06:42:20 +0000 |
parents | 9e5a709c30a8 |
children | 502707ca1836 |
comparison
equal
deleted
inserted
replaced
9157:bd1ea0a717d7 | 9158:c30d81b4dd22 |
---|---|
39 | 39 |
40 #define BUDDY_ALIAS_MAXLEN 387 | 40 #define BUDDY_ALIAS_MAXLEN 387 |
41 | 41 |
42 static GaimPlugin *my_protocol = NULL; | 42 static GaimPlugin *my_protocol = NULL; |
43 | 43 |
44 static const char *msn_normalize(const GaimAccount *account, const char *str); | |
45 | |
46 typedef struct | 44 typedef struct |
47 { | 45 { |
48 GaimConnection *gc; | 46 GaimConnection *gc; |
49 const char *passport; | 47 const char *passport; |
50 | 48 |
55 GaimConnection *gc; | 53 GaimConnection *gc; |
56 char *name; | 54 char *name; |
57 | 55 |
58 } MsnGetInfoData; | 56 } MsnGetInfoData; |
59 | 57 |
58 static const char * | |
59 msn_normalize(const GaimAccount *account, const char *str) | |
60 { | |
61 static char buf[BUF_LEN]; | |
62 char *tmp; | |
63 | |
64 g_return_val_if_fail(str != NULL, NULL); | |
65 | |
66 g_snprintf(buf, sizeof(buf), "%s%s", str, | |
67 (strchr(str, '@') ? "" : "@hotmail.com")); | |
68 | |
69 tmp = g_utf8_strdown(buf, -1); | |
70 strncpy(buf, tmp, sizeof(buf)); | |
71 g_free(tmp); | |
72 | |
73 return buf; | |
74 } | |
75 | |
60 static void | 76 static void |
61 msn_act_id(GaimConnection *gc, const char *entry) | 77 msn_act_id(GaimConnection *gc, const char *entry) |
62 { | 78 { |
63 MsnCmdProc *cmdproc; | 79 MsnCmdProc *cmdproc; |
64 MsnSession *session; | 80 MsnSession *session; |
65 GaimAccount *account; | 81 GaimAccount *account; |
66 char *alias; | 82 const char *alias; |
67 | 83 |
68 session = gc->proto_data; | 84 session = gc->proto_data; |
69 cmdproc = session->notification_conn->cmdproc; | 85 cmdproc = session->notification_conn->cmdproc; |
70 account = gaim_connection_get_account(gc); | 86 account = gaim_connection_get_account(gc); |
71 | 87 |
72 if (entry == NULL || *entry == '\0') | 88 alias = (entry && *entry) ? entry : ""; |
73 alias = g_strdup(""); | |
74 else | |
75 alias = g_strdup(entry); | |
76 | 89 |
77 if (strlen(alias) > BUDDY_ALIAS_MAXLEN) | 90 if (strlen(alias) > BUDDY_ALIAS_MAXLEN) |
78 { | 91 { |
79 gaim_notify_error(gc, NULL, | 92 gaim_notify_error(gc, NULL, |
80 _("Your new MSN friendly name is too long."), NULL); | 93 _("Your new MSN friendly name is too long."), NULL); |
81 | |
82 g_free(alias); | |
83 | 94 |
84 return; | 95 return; |
85 } | 96 } |
86 | 97 |
87 msn_cmdproc_send(cmdproc, "REA", "%s %s", | 98 msn_cmdproc_send(cmdproc, "REA", "%s %s", |
88 gaim_account_get_username(account), | 99 gaim_account_get_username(account), |
89 gaim_url_encode(alias)); | 100 gaim_url_encode(alias)); |
90 | |
91 g_free(alias); | |
92 } | 101 } |
93 | 102 |
94 static void | 103 static void |
95 msn_set_prp(GaimConnection *gc, const char *type, const char *entry) | 104 msn_set_prp(GaimConnection *gc, const char *type, const char *entry) |
96 { | 105 { |
100 session = gc->proto_data; | 109 session = gc->proto_data; |
101 cmdproc = session->notification_conn->cmdproc; | 110 cmdproc = session->notification_conn->cmdproc; |
102 | 111 |
103 if (entry == NULL || *entry == '\0') | 112 if (entry == NULL || *entry == '\0') |
104 { | 113 { |
105 msn_cmdproc_send(cmdproc, "PRP", "%s ", type); | 114 msn_cmdproc_send(cmdproc, "PRP", "%s", type); |
106 } | 115 } |
107 else | 116 else |
108 { | 117 { |
109 msn_cmdproc_send(cmdproc, "PRP", "%s %s", type, | 118 msn_cmdproc_send(cmdproc, "PRP", "%s %s", type, |
110 gaim_url_encode(entry)); | 119 gaim_url_encode(entry)); |
186 /* -- */ | 195 /* -- */ |
187 | 196 |
188 static void | 197 static void |
189 msn_show_set_friendly_name(GaimPluginAction *action) | 198 msn_show_set_friendly_name(GaimPluginAction *action) |
190 { | 199 { |
191 GaimConnection *gc = (GaimConnection *) action->context; | 200 GaimConnection *gc; |
201 | |
202 gc = (GaimConnection *) action->context; | |
203 | |
192 gaim_request_input(gc, NULL, _("Set your friendly name."), | 204 gaim_request_input(gc, NULL, _("Set your friendly name."), |
193 _("This is the name that other MSN buddies will " | 205 _("This is the name that other MSN buddies will " |
194 "see you as."), | 206 "see you as."), |
195 gaim_connection_get_display_name(gc), FALSE, FALSE, NULL, | 207 gaim_connection_get_display_name(gc), FALSE, FALSE, NULL, |
196 _("OK"), G_CALLBACK(msn_act_id), | 208 _("OK"), G_CALLBACK(msn_act_id), |
198 } | 210 } |
199 | 211 |
200 static void | 212 static void |
201 msn_show_set_home_phone(GaimPluginAction *action) | 213 msn_show_set_home_phone(GaimPluginAction *action) |
202 { | 214 { |
203 GaimConnection *gc = (GaimConnection *) action->context; | 215 GaimConnection *gc; |
204 MsnSession *session = gc->proto_data; | 216 MsnSession *session; |
217 | |
218 gc = (GaimConnection *) action->context; | |
219 session = gc->proto_data; | |
205 | 220 |
206 gaim_request_input(gc, NULL, _("Set your home phone number."), NULL, | 221 gaim_request_input(gc, NULL, _("Set your home phone number."), NULL, |
207 msn_user_get_home_phone(session->user), FALSE, FALSE, NULL, | 222 msn_user_get_home_phone(session->user), FALSE, FALSE, NULL, |
208 _("OK"), G_CALLBACK(msn_set_home_phone_cb), | 223 _("OK"), G_CALLBACK(msn_set_home_phone_cb), |
209 _("Cancel"), NULL, gc); | 224 _("Cancel"), NULL, gc); |
210 } | 225 } |
211 | 226 |
212 static void | 227 static void |
213 msn_show_set_work_phone(GaimPluginAction *action) | 228 msn_show_set_work_phone(GaimPluginAction *action) |
214 { | 229 { |
215 GaimConnection *gc = (GaimConnection *) action->context; | 230 GaimConnection *gc; |
216 MsnSession *session = gc->proto_data; | 231 MsnSession *session; |
232 | |
233 gc = (GaimConnection *) action->context; | |
234 session = gc->proto_data; | |
217 | 235 |
218 gaim_request_input(gc, NULL, _("Set your work phone number."), NULL, | 236 gaim_request_input(gc, NULL, _("Set your work phone number."), NULL, |
219 msn_user_get_work_phone(session->user), FALSE, FALSE, NULL, | 237 msn_user_get_work_phone(session->user), FALSE, FALSE, NULL, |
220 _("OK"), G_CALLBACK(msn_set_work_phone_cb), | 238 _("OK"), G_CALLBACK(msn_set_work_phone_cb), |
221 _("Cancel"), NULL, gc); | 239 _("Cancel"), NULL, gc); |
222 } | 240 } |
223 | 241 |
224 static void | 242 static void |
225 msn_show_set_mobile_phone(GaimPluginAction *action) | 243 msn_show_set_mobile_phone(GaimPluginAction *action) |
226 { | 244 { |
227 GaimConnection *gc = (GaimConnection *) action->context; | 245 GaimConnection *gc; |
228 MsnSession *session = gc->proto_data; | 246 MsnSession *session; |
247 | |
248 gc = (GaimConnection *) action->context; | |
249 session = gc->proto_data; | |
229 | 250 |
230 gaim_request_input(gc, NULL, _("Set your mobile phone number."), NULL, | 251 gaim_request_input(gc, NULL, _("Set your mobile phone number."), NULL, |
231 msn_user_get_mobile_phone(session->user), FALSE, FALSE, NULL, | 252 msn_user_get_mobile_phone(session->user), FALSE, FALSE, NULL, |
232 _("OK"), G_CALLBACK(msn_set_mobile_phone_cb), | 253 _("OK"), G_CALLBACK(msn_set_mobile_phone_cb), |
233 _("Cancel"), NULL, gc); | 254 _("Cancel"), NULL, gc); |
234 } | 255 } |
235 | 256 |
236 static void | 257 static void |
237 msn_show_set_mobile_pages(GaimPluginAction *action) | 258 msn_show_set_mobile_pages(GaimPluginAction *action) |
238 { | 259 { |
239 GaimConnection *gc = (GaimConnection *) action->context; | 260 GaimConnection *gc; |
261 | |
262 gc = (GaimConnection *) action->context; | |
263 | |
240 gaim_request_action(gc, NULL, _("Allow MSN Mobile pages?"), | 264 gaim_request_action(gc, NULL, _("Allow MSN Mobile pages?"), |
241 _("Do you want to allow or disallow people on " | 265 _("Do you want to allow or disallow people on " |
242 "your buddy list to send you MSN Mobile pages " | 266 "your buddy list to send you MSN Mobile pages " |
243 "to your cell phone or other mobile device?"), | 267 "to your cell phone or other mobile device?"), |
244 -1, gc, 3, | 268 -1, gc, 3, |
306 session->last_chat_id++; | 330 session->last_chat_id++; |
307 swboard->chat_id = session->last_chat_id; | 331 swboard->chat_id = session->last_chat_id; |
308 swboard->chat = serv_got_joined_chat(gc, swboard->chat_id, "MSN Chat"); | 332 swboard->chat = serv_got_joined_chat(gc, swboard->chat_id, "MSN Chat"); |
309 | 333 |
310 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->chat), | 334 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->chat), |
311 gaim_account_get_username(buddy->account), NULL); | 335 gaim_account_get_username(buddy->account), NULL); |
312 } | 336 } |
313 | 337 |
314 /************************************************************************** | 338 /************************************************************************** |
315 * Protocol Plugin ops | 339 * Protocol Plugin ops |
316 **************************************************************************/ | 340 **************************************************************************/ |
337 else if (away_type == MSN_BUSY || away_type == MSN_PHONE) | 361 else if (away_type == MSN_BUSY || away_type == MSN_PHONE) |
338 emblems[i++] = "occupied"; | 362 emblems[i++] = "occupied"; |
339 else if (away_type != 0) | 363 else if (away_type != 0) |
340 emblems[i++] = "away"; | 364 emblems[i++] = "away"; |
341 | 365 |
342 if (user == NULL) { | 366 if (user == NULL) |
367 { | |
343 emblems[0] = "offline"; | 368 emblems[0] = "offline"; |
344 } | 369 } |
345 else if (user->mobile) | 370 else if (user->mobile) |
346 emblems[i++] = "wireless"; | 371 emblems[i++] = "wireless"; |
347 | 372 |
363 static char * | 388 static char * |
364 msn_tooltip_text(GaimBuddy *b) | 389 msn_tooltip_text(GaimBuddy *b) |
365 { | 390 { |
366 char *text = NULL; | 391 char *text = NULL; |
367 | 392 |
368 if (GAIM_BUDDY_IS_ONLINE(b)) { | 393 if (GAIM_BUDDY_IS_ONLINE(b)) |
394 { | |
369 text = g_strdup_printf("\n<b>%s:</b> %s", _("Status"), | 395 text = g_strdup_printf("\n<b>%s:</b> %s", _("Status"), |
370 msn_away_get_text(MSN_AWAY_TYPE(b->uc))); | 396 msn_away_get_text(MSN_AWAY_TYPE(b->uc))); |
371 } | 397 } |
372 | 398 |
373 return text; | 399 return text; |
394 { | 420 { |
395 GList *m = NULL; | 421 GList *m = NULL; |
396 GaimPluginAction *act; | 422 GaimPluginAction *act; |
397 | 423 |
398 act = gaim_plugin_action_new(_("Set Friendly Name"), | 424 act = gaim_plugin_action_new(_("Set Friendly Name"), |
399 msn_show_set_friendly_name); | 425 msn_show_set_friendly_name); |
400 m = g_list_append(m, act); | 426 m = g_list_append(m, act); |
401 m = g_list_append(m, NULL); | 427 m = g_list_append(m, NULL); |
402 | 428 |
403 act = gaim_plugin_action_new(_("Set Home Phone Number"), | 429 act = gaim_plugin_action_new(_("Set Home Phone Number"), |
404 msn_show_set_home_phone); | 430 msn_show_set_home_phone); |
405 m = g_list_append(m, act); | 431 m = g_list_append(m, act); |
406 | 432 |
407 act = gaim_plugin_action_new(_("Set Work Phone Number"), | 433 act = gaim_plugin_action_new(_("Set Work Phone Number"), |
408 msn_show_set_work_phone); | 434 msn_show_set_work_phone); |
409 m = g_list_append(m, act); | 435 m = g_list_append(m, act); |
433 | 459 |
434 GList *m = NULL; | 460 GList *m = NULL; |
435 GaimBlistNodeAction *act; | 461 GaimBlistNodeAction *act; |
436 | 462 |
437 user = buddy->proto_data; | 463 user = buddy->proto_data; |
464 | |
438 if (user != NULL) | 465 if (user != NULL) |
439 { | 466 { |
440 if (user->mobile) | 467 if (user->mobile) |
441 { | 468 { |
442 act = gaim_blist_node_action_new(_("Send to Mobile"), | 469 act = gaim_blist_node_action_new(_("Send to Mobile"), |
443 show_send_to_mobile_cb, NULL); | 470 show_send_to_mobile_cb, NULL); |
444 m = g_list_append(m, act); | 471 m = g_list_append(m, act); |
445 } | 472 } |
446 } | 473 } |
447 | 474 |
448 if (g_ascii_strcasecmp(buddy->name, gaim_account_get_username(buddy->account))) | 475 if (g_ascii_strcasecmp(buddy->name, |
476 gaim_account_get_username(buddy->account))) | |
449 { | 477 { |
450 act = gaim_blist_node_action_new(_("Initiate Chat"), | 478 act = gaim_blist_node_action_new(_("Initiate Chat"), |
451 initiate_chat_cb, NULL); | 479 initiate_chat_cb, NULL); |
452 m = g_list_append(m, act); | 480 m = g_list_append(m, act); |
453 } | 481 } |
454 | 482 |
455 return m; | 483 return m; |
456 } | 484 } |
457 | |
458 | 485 |
459 static GList * | 486 static GList * |
460 msn_blist_node_menu(GaimBlistNode *node) | 487 msn_blist_node_menu(GaimBlistNode *node) |
461 { | 488 { |
462 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | 489 if(GAIM_BLIST_NODE_IS_BUDDY(node)) |
490 { | |
463 return msn_buddy_menu((GaimBuddy *) node); | 491 return msn_buddy_menu((GaimBuddy *) node); |
464 } else { | 492 } |
493 else | |
494 { | |
465 return NULL; | 495 return NULL; |
466 } | 496 } |
467 } | 497 } |
468 | 498 |
469 | |
470 static void | 499 static void |
471 msn_login(GaimAccount *account) | 500 msn_login(GaimAccount *account) |
472 { | 501 { |
473 GaimConnection *gc; | 502 GaimConnection *gc; |
474 MsnSession *session; | 503 MsnSession *session; |
475 const char *username; | 504 const char *username; |
476 const char *server; | 505 const char *host; |
477 gboolean http_method = FALSE; | 506 gboolean http_method = FALSE; |
478 int port; | 507 int port; |
479 | 508 |
480 gc = gaim_account_get_connection(account); | 509 gc = gaim_account_get_connection(account); |
481 | 510 |
493 { | 522 { |
494 http_method = TRUE; | 523 http_method = TRUE; |
495 | 524 |
496 gaim_debug(GAIM_DEBUG_INFO, "msn", "using http method\n"); | 525 gaim_debug(GAIM_DEBUG_INFO, "msn", "using http method\n"); |
497 | 526 |
498 server = "gateway.messenger.hotmail.com"; | 527 host = "gateway.messenger.hotmail.com"; |
499 port = 80; | 528 port = 80; |
500 } | 529 } |
501 else | 530 else |
502 { | 531 { |
503 server = gaim_account_get_string(account, "server", MSN_SERVER); | 532 host = gaim_account_get_string(account, "server", MSN_SERVER); |
504 port = gaim_account_get_int(account, "port", MSN_PORT); | 533 port = gaim_account_get_int(account, "port", MSN_PORT); |
505 } | 534 } |
506 | 535 |
507 session = msn_session_new(account, server, port); | 536 session = msn_session_new(account, host, port); |
508 session->http_method = http_method; | 537 session->http_method = http_method; |
509 session->prpl = my_protocol; | 538 session->prpl = my_protocol; |
510 | 539 |
511 if (session->http_method) | 540 if (session->http_method) |
512 msn_http_session_init(session); | 541 msn_http_session_init(session); |
549 static int | 578 static int |
550 msn_send_im(GaimConnection *gc, const char *who, const char *message, | 579 msn_send_im(GaimConnection *gc, const char *who, const char *message, |
551 GaimConvImFlags flags) | 580 GaimConvImFlags flags) |
552 { | 581 { |
553 GaimAccount *account; | 582 GaimAccount *account; |
554 MsnSession *session; | |
555 MsnSwitchBoard *swboard; | |
556 | 583 |
557 account = gaim_connection_get_account(gc); | 584 account = gaim_connection_get_account(gc); |
558 session = gc->proto_data; | |
559 swboard = msn_session_find_switch_with_passport(session, who); | |
560 | 585 |
561 if (g_ascii_strcasecmp(who, gaim_account_get_username(account))) | 586 if (g_ascii_strcasecmp(who, gaim_account_get_username(account))) |
562 { | 587 { |
588 MsnSession *session; | |
589 MsnSwitchBoard *swboard; | |
563 MsnMessage *msg; | 590 MsnMessage *msg; |
564 MsnUser *user; | 591 MsnUser *user; |
565 char *msgformat; | 592 char *msgformat; |
566 char *msgtext; | 593 char *msgtext; |
567 | 594 |
595 session = gc->proto_data; | |
596 swboard = msn_session_find_switch_with_passport(session, who); | |
568 user = msn_user_new(session, who, NULL); | 597 user = msn_user_new(session, who, NULL); |
569 | 598 |
570 msn_import_html(message, &msgformat, &msgtext); | 599 msn_import_html(message, &msgformat, &msgtext); |
571 | 600 |
572 msg = msn_message_new(); | 601 msg = msn_message_new_plain(msgtext); |
573 msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat); | 602 msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat); |
574 msn_message_set_body(msg, msgtext); | |
575 | 603 |
576 g_free(msgformat); | 604 g_free(msgformat); |
577 g_free(msgtext); | 605 g_free(msgtext); |
578 | 606 |
579 if (swboard != NULL) | 607 if (swboard != NULL) |
614 { | 642 { |
615 GaimAccount *account; | 643 GaimAccount *account; |
616 MsnSession *session; | 644 MsnSession *session; |
617 MsnSwitchBoard *swboard; | 645 MsnSwitchBoard *swboard; |
618 MsnMessage *msg; | 646 MsnMessage *msg; |
619 MsnUser *user; | |
620 | 647 |
621 account = gaim_connection_get_account(gc); | 648 account = gaim_connection_get_account(gc); |
622 session = gc->proto_data; | 649 session = gc->proto_data; |
623 | 650 |
624 if (!typing) | 651 if (!typing) |
635 swboard = msn_session_find_switch_with_passport(session, who); | 662 swboard = msn_session_find_switch_with_passport(session, who); |
636 | 663 |
637 if (swboard == NULL) | 664 if (swboard == NULL) |
638 return 0; | 665 return 0; |
639 | 666 |
640 user = msn_user_new(session, who, NULL); | |
641 | |
642 msg = msn_message_new(); | 667 msg = msn_message_new(); |
643 msn_message_set_content_type(msg, "text/x-msmsgscontrol"); | 668 msn_message_set_content_type(msg, "text/x-msmsgscontrol"); |
644 msn_message_set_charset(msg, NULL); | |
645 msn_message_set_flag(msg, 'U'); | 669 msn_message_set_flag(msg, 'U'); |
646 msn_message_set_attr(msg, "TypingUser", | 670 msn_message_set_attr(msg, "TypingUser", |
647 gaim_account_get_username(account)); | 671 gaim_account_get_username(account)); |
648 msn_message_set_attr(msg, "User-Agent", NULL); | 672 msn_message_set_bin_data(msg, "\r\n", 2); |
649 msn_message_set_body(msg, "\r\n"); | |
650 | 673 |
651 msn_switchboard_send_msg(swboard, msg); | 674 msn_switchboard_send_msg(swboard, msg); |
652 | 675 |
653 msn_user_destroy(user); | 676 msn_message_destroy(msg); |
654 | 677 |
655 return MSN_TYPING_SEND_TIMEOUT; | 678 return MSN_TYPING_SEND_TIMEOUT; |
656 } | 679 } |
657 | 680 |
658 static void | 681 static void |
659 msn_set_away(GaimConnection *gc, const char *state, const char *msg) | 682 msn_set_away(GaimConnection *gc, const char *state, const char *msg) |
660 { | 683 { |
661 MsnSession *session; | 684 MsnSession *session; |
662 const char *away; | 685 const char *status; |
663 | 686 |
664 session = gc->proto_data; | 687 session = gc->proto_data; |
665 | 688 |
666 if (gc->away != NULL) | 689 if (gc->away != NULL) |
667 { | 690 { |
670 } | 693 } |
671 | 694 |
672 if (msg != NULL) | 695 if (msg != NULL) |
673 { | 696 { |
674 gc->away = g_strdup(""); | 697 gc->away = g_strdup(""); |
675 away = "AWY"; | 698 status = "AWY"; |
676 } | 699 } |
677 else if (state) | 700 else if (state) |
678 { | 701 { |
679 gc->away = g_strdup(""); | 702 gc->away = g_strdup(""); |
680 | 703 |
681 if (!strcmp(state, _("Away From Computer"))) | 704 if (!strcmp(state, _("Away From Computer"))) |
682 away = "AWY"; | 705 status = "AWY"; |
683 else if (!strcmp(state, _("Be Right Back"))) | 706 else if (!strcmp(state, _("Be Right Back"))) |
684 away = "BRB"; | 707 status = "BRB"; |
685 else if (!strcmp(state, _("Busy"))) | 708 else if (!strcmp(state, _("Busy"))) |
686 away = "BSY"; | 709 status = "BSY"; |
687 else if (!strcmp(state, _("On The Phone"))) | 710 else if (!strcmp(state, _("On The Phone"))) |
688 away = "PHN"; | 711 status = "PHN"; |
689 else if (!strcmp(state, _("Out To Lunch"))) | 712 else if (!strcmp(state, _("Out To Lunch"))) |
690 away = "LUN"; | 713 status = "LUN"; |
691 else if (!strcmp(state, _("Hidden"))) | 714 else if (!strcmp(state, _("Hidden"))) |
692 away = "HDN"; | 715 status = "HDN"; |
693 else | 716 else |
694 { | 717 { |
695 g_free(gc->away); | 718 g_free(gc->away); |
696 gc->away = NULL; | 719 gc->away = NULL; |
697 away = "NLN"; | 720 status = "NLN"; |
698 } | 721 } |
699 } | 722 } |
700 else if (gc->is_idle) | 723 else if (gc->is_idle) |
701 away = "IDL"; | 724 status = "IDL"; |
702 else | 725 else |
703 away = "NLN"; | 726 status = "NLN"; |
704 | 727 |
705 msn_session_change_status(session, away); | 728 msn_session_change_status(session, status); |
706 } | 729 } |
707 | 730 |
708 static void | 731 static void |
709 msn_set_idle(GaimConnection *gc, int idle) | 732 msn_set_idle(GaimConnection *gc, int idle) |
710 { | 733 { |
1067 msn_chat_invite(GaimConnection *gc, int id, const char *msg, | 1090 msn_chat_invite(GaimConnection *gc, int id, const char *msg, |
1068 const char *who) | 1091 const char *who) |
1069 { | 1092 { |
1070 MsnSession *session; | 1093 MsnSession *session; |
1071 MsnSwitchBoard *swboard; | 1094 MsnSwitchBoard *swboard; |
1072 | 1095 MsnCmdProc *cmdproc; |
1073 session = gc->proto_data; | 1096 |
1097 session = gc->proto_data; | |
1098 | |
1074 swboard = msn_session_find_switch_with_id(session, id); | 1099 swboard = msn_session_find_switch_with_id(session, id); |
1075 | 1100 g_return_if_fail(swboard != NULL); |
1076 if (swboard == NULL) | 1101 |
1077 return; | 1102 cmdproc = swboard->cmdproc; |
1078 | 1103 |
1079 msn_cmdproc_send(swboard->cmdproc, "CAL", "%s", who); | 1104 msn_cmdproc_send(cmdproc, "CAL", "%s", who); |
1080 } | 1105 } |
1081 | 1106 |
1082 static void | 1107 static void |
1083 msn_chat_leave(GaimConnection *gc, int id) | 1108 msn_chat_leave(GaimConnection *gc, int id) |
1084 { | 1109 { |
1085 GaimAccount *account; | |
1086 MsnSession *session; | 1110 MsnSession *session; |
1087 MsnSwitchBoard *swboard; | 1111 MsnSwitchBoard *swboard; |
1088 | 1112 MsnCmdProc *cmdproc; |
1089 session = gc->proto_data; | 1113 |
1090 account = gaim_connection_get_account(gc); | 1114 session = gc->proto_data; |
1091 swboard = msn_session_find_switch_with_id(session, id); | 1115 swboard = msn_session_find_switch_with_id(session, id); |
1092 | 1116 g_return_if_fail(swboard != NULL); |
1093 if (swboard == NULL) | 1117 |
1094 { | 1118 cmdproc = swboard->servconn->cmdproc; |
1095 serv_got_chat_left(gc, id); | 1119 |
1096 return; | 1120 msn_cmdproc_send_quick(cmdproc, "OUT", NULL, NULL); |
1097 } | |
1098 | |
1099 msn_cmdproc_send_quick(swboard->cmdproc, "OUT", NULL, NULL); | |
1100 msn_switchboard_destroy(swboard); | 1121 msn_switchboard_destroy(swboard); |
1101 | 1122 |
1102 serv_got_chat_left(gc, id); | 1123 /* serv_got_chat_left(gc, id); */ |
1103 } | 1124 } |
1104 | 1125 |
1105 static int | 1126 static int |
1106 msn_chat_send(GaimConnection *gc, int id, const char *message) | 1127 msn_chat_send(GaimConnection *gc, int id, const char *message) |
1107 { | 1128 { |
1119 if (swboard == NULL) | 1140 if (swboard == NULL) |
1120 return -EINVAL; | 1141 return -EINVAL; |
1121 | 1142 |
1122 msn_import_html(message, &msgformat, &msgtext); | 1143 msn_import_html(message, &msgformat, &msgtext); |
1123 | 1144 |
1124 msg = msn_message_new(); | 1145 msg = msn_message_new_plain(msgtext); |
1125 msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat); | 1146 msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat); |
1126 msn_message_set_body(msg, msgtext); | |
1127 | 1147 |
1128 g_free(msgformat); | 1148 g_free(msgformat); |
1129 g_free(msgtext); | 1149 g_free(msgtext); |
1130 | 1150 |
1131 msn_switchboard_send_msg(swboard, msg); | 1151 msn_switchboard_send_msg(swboard, msg); |
1132 | 1152 |
1133 msn_message_destroy(msg); | 1153 msn_message_destroy(msg); |
1134 | 1154 |
1135 serv_got_chat_in(gc, id, gaim_account_get_username(account), | 1155 serv_got_chat_in(gc, id, gaim_account_get_username(account), 0, |
1136 0, message, time(NULL)); | 1156 message, time(NULL)); |
1137 | 1157 |
1138 return 0; | 1158 return 0; |
1139 } | 1159 } |
1140 | 1160 |
1141 static void | 1161 static void |
1208 msn_group_get_id(old_group)); | 1228 msn_group_get_id(old_group)); |
1209 | 1229 |
1210 if (cmdproc->error) | 1230 if (cmdproc->error) |
1211 return; | 1231 return; |
1212 | 1232 |
1233 #if 0 | |
1213 if (msn_users_get_count(msn_group_get_users(old_group)) <= 0) | 1234 if (msn_users_get_count(msn_group_get_users(old_group)) <= 0) |
1214 { | 1235 { |
1215 msn_cmdproc_send(cmdproc, "RMG", "%d", | 1236 msn_cmdproc_send(cmdproc, "RMG", "%d", |
1216 msn_group_get_id(old_group)); | 1237 msn_group_get_id(old_group)); |
1217 } | 1238 } |
1239 #endif | |
1218 } | 1240 } |
1219 } | 1241 } |
1220 | 1242 |
1221 static void | 1243 static void |
1222 msn_rename_group(GaimConnection *gc, const char *old_group_name, | 1244 msn_rename_group(GaimConnection *gc, const char *old_group_name, |
1223 const char *new_group_name, GList *members) | 1245 const char *new_group_name, GList *members) |
1224 { | 1246 { |
1225 MsnSession *session; | 1247 MsnSession *session; |
1226 MsnCmdProc *cmdproc; | 1248 MsnCmdProc *cmdproc; |
1227 MsnGroup *old_group; | 1249 MsnGroup *old_group; |
1250 const char *enc_new_group_name; | |
1228 | 1251 |
1229 session = gc->proto_data; | 1252 session = gc->proto_data; |
1230 cmdproc = session->notification_conn->cmdproc; | 1253 cmdproc = session->notification_conn->cmdproc; |
1254 enc_new_group_name = gaim_url_encode(new_group_name); | |
1231 | 1255 |
1232 if ((old_group = msn_groups_find_with_name(session->groups, | 1256 if ((old_group = msn_groups_find_with_name(session->groups, |
1233 old_group_name)) != NULL) | 1257 old_group_name)) != NULL) |
1234 { | 1258 { |
1235 msn_cmdproc_send(cmdproc, "REG", "%d %s 0", | 1259 msn_cmdproc_send(cmdproc, "REG", "%d %s 0", |
1236 msn_group_get_id(old_group), | 1260 msn_group_get_id(old_group), enc_new_group_name); |
1237 gaim_url_encode(new_group_name)); | |
1238 | 1261 |
1239 if (cmdproc->error) | 1262 if (cmdproc->error) |
1240 return; | 1263 return; |
1241 | 1264 |
1242 msn_group_set_name(old_group, new_group_name); | 1265 msn_group_set_name(old_group, new_group_name); |
1243 } | 1266 } |
1244 else | 1267 else |
1245 { | 1268 { |
1246 msn_cmdproc_send(cmdproc, "ADG", "%s 0", | 1269 msn_cmdproc_send(cmdproc, "ADG", "%s 0", enc_new_group_name); |
1247 gaim_url_encode(new_group_name)); | |
1248 } | 1270 } |
1249 } | 1271 } |
1250 | 1272 |
1251 static void | 1273 static void |
1252 msn_buddy_free(GaimBuddy *b) | 1274 msn_buddy_free(GaimBuddy *b) |
1259 } | 1281 } |
1260 | 1282 |
1261 static void | 1283 static void |
1262 msn_convo_closed(GaimConnection *gc, const char *who) | 1284 msn_convo_closed(GaimConnection *gc, const char *who) |
1263 { | 1285 { |
1264 GaimAccount *account; | |
1265 MsnSession *session; | 1286 MsnSession *session; |
1266 MsnSwitchBoard *swboard; | 1287 MsnSwitchBoard *swboard; |
1267 | 1288 MsnCmdProc *cmdproc; |
1268 account = gaim_connection_get_account(gc); | 1289 |
1269 session = gc->proto_data; | 1290 session = gc->proto_data; |
1291 | |
1270 swboard = msn_session_find_switch_with_passport(session, who); | 1292 swboard = msn_session_find_switch_with_passport(session, who); |
1271 | 1293 g_return_if_fail(swboard != NULL); |
1272 if (swboard != NULL && swboard->chat == NULL) | 1294 |
1273 { | 1295 cmdproc = swboard->servconn->cmdproc; |
1274 msn_cmdproc_send_quick(swboard->cmdproc, "BYE", "%s", | 1296 |
1297 if (swboard->chat == NULL) | |
1298 { | |
1299 GaimAccount *account; | |
1300 | |
1301 account = gaim_connection_get_account(gc); | |
1302 | |
1303 msn_cmdproc_send_quick(cmdproc, "BYE", "%s", | |
1275 gaim_account_get_username(account)); | 1304 gaim_account_get_username(account)); |
1276 | 1305 |
1277 msn_switchboard_destroy(swboard); | 1306 msn_switchboard_destroy(swboard); |
1278 } | 1307 } |
1279 } | 1308 } |
1280 | 1309 |
1281 static const char * | |
1282 msn_normalize(const GaimAccount *account, const char *str) | |
1283 { | |
1284 static char buf[BUF_LEN]; | |
1285 char *tmp; | |
1286 | |
1287 g_return_val_if_fail(str != NULL, NULL); | |
1288 | |
1289 g_snprintf(buf, sizeof(buf), "%s%s", str, | |
1290 (strchr(str, '@') ? "" : "@hotmail.com")); | |
1291 | |
1292 tmp = g_utf8_strdown(buf, -1); | |
1293 strncpy(buf, tmp, sizeof(buf)); | |
1294 g_free(tmp); | |
1295 | |
1296 return buf; | |
1297 } | |
1298 | |
1299 static void | 1310 static void |
1300 msn_set_buddy_icon(GaimConnection *gc, const char *filename) | 1311 msn_set_buddy_icon(GaimConnection *gc, const char *filename) |
1301 { | 1312 { |
1302 MsnSession *session = (MsnSession *)gc->proto_data; | 1313 MsnSession *session; |
1303 MsnUser *user = session->user; | 1314 MsnUser *user; |
1315 | |
1316 session = gc->proto_data; | |
1317 user = session->user; | |
1304 | 1318 |
1305 msn_user_set_buddy_icon(user, filename); | 1319 msn_user_set_buddy_icon(user, filename); |
1306 | 1320 |
1307 msn_session_change_status(session, session->away_state); | 1321 msn_session_change_status(session, session->away_state); |
1308 } | 1322 } |
1339 gaim_debug_info("msn", "In msn_got_info\n"); | 1353 gaim_debug_info("msn", "In msn_got_info\n"); |
1340 | 1354 |
1341 if (url_text == NULL || strcmp(url_text, "") == 0) | 1355 if (url_text == NULL || strcmp(url_text, "") == 0) |
1342 { | 1356 { |
1343 gaim_notify_formatted(info_data->gc, NULL, | 1357 gaim_notify_formatted(info_data->gc, NULL, |
1344 _("Buddy Information"), NULL, | 1358 _("Buddy Information"), NULL, |
1345 _("<html><body><b>Error retrieving profile</b></body></html>"), | 1359 _("<html><body><b>Error retrieving profile</b></body></html>"), |
1346 NULL, NULL); | 1360 NULL, NULL); |
1347 | 1361 |
1348 return; | 1362 return; |
1349 } | 1363 } |
1350 | 1364 |
1351 url_buffer = g_strdup(url_text); | 1365 url_buffer = g_strdup(url_text); |
1409 | 1423 |
1410 if (found) | 1424 if (found) |
1411 has_info = TRUE; | 1425 has_info = TRUE; |
1412 | 1426 |
1413 /* Extract their Age and put it in */ | 1427 /* Extract their Age and put it in */ |
1414 found = gaim_markup_extract_info_field(stripped, stripped_len, s,"\tAge", | 1428 found = gaim_markup_extract_info_field(stripped, stripped_len, s, |
1415 0, "\t", '\n', "Undisclosed", _("Age"), 0, NULL); | 1429 "\tAge", 0, "\t", '\n', "Undisclosed", _("Age"), 0, NULL); |
1416 | 1430 |
1417 if (found) | 1431 if (found) |
1418 has_info = TRUE; | 1432 has_info = TRUE; |
1419 | 1433 |
1420 /* Extract their Gender and put it in */ | 1434 /* Extract their Gender and put it in */ |
1421 found = gaim_markup_extract_info_field(stripped, stripped_len, s,"\tGender", | 1435 found = gaim_markup_extract_info_field(stripped, stripped_len, s, |
1422 6, "\t", '\n', "Undisclosed", _("Gender"), 0, NULL); | 1436 "\tGender", 6, "\t", '\n', "Undisclosed", _("Gender"), 0, |
1437 NULL); | |
1423 | 1438 |
1424 if (found) | 1439 if (found) |
1425 has_info = TRUE; | 1440 has_info = TRUE; |
1426 | 1441 |
1427 /* Extract their MaritalStatus and put it in */ | 1442 /* Extract their MaritalStatus and put it in */ |
1432 if (found) | 1447 if (found) |
1433 has_info = TRUE; | 1448 has_info = TRUE; |
1434 | 1449 |
1435 /* Extract their Location and put it in */ | 1450 /* Extract their Location and put it in */ |
1436 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | 1451 found = gaim_markup_extract_info_field(stripped, stripped_len, s, |
1437 "\tLocation", 0, "\t", '\n', "Undisclosed", _("Location"), | 1452 "\tLocation", 0, "\t", '\n', "Undisclosed", _("Location"), 0, |
1438 0, NULL); | 1453 NULL); |
1439 | 1454 |
1440 if (found) | 1455 if (found) |
1441 has_info = TRUE; | 1456 has_info = TRUE; |
1442 | 1457 |
1443 /* Extract their Occupation and put it in */ | 1458 /* Extract their Occupation and put it in */ |
1492 if (found) | 1507 if (found) |
1493 has_info = TRUE; | 1508 has_info = TRUE; |
1494 | 1509 |
1495 /* Check if they have Favorite Things */ | 1510 /* Check if they have Favorite Things */ |
1496 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | 1511 found = gaim_markup_extract_info_field(stripped, stripped_len, s, |
1497 "Favorite Things", 1, "Hobbies and Interests", '\n', NULL, | 1512 "Favorite Things", 1, "Hobbies and Interests", '\n', NULL, |
1498 _("Favorite Things"), 0, NULL); | 1513 _("Favorite Things"), 0, NULL); |
1499 | 1514 |
1500 if (!found) | 1515 if (!found) |
1501 { | 1516 { |
1502 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | 1517 found = gaim_markup_extract_info_field(stripped, stripped_len, s, |
1503 "Favorite Things", 1, "Favorite Quote", '\n', NULL, | 1518 "Favorite Things", 1, "Favorite Quote", '\n', NULL, |
1505 } | 1520 } |
1506 | 1521 |
1507 if (!found) | 1522 if (!found) |
1508 { | 1523 { |
1509 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | 1524 found = gaim_markup_extract_info_field(stripped, stripped_len, s, |
1510 "Favorite Things", 1, "My Homepage\tTake a look", '\n', NULL, | 1525 "Favorite Things", 1, "My Homepage\tTake a look", '\n', |
1511 _("Favorite Things"), 0, NULL); | 1526 NULL, _("Favorite Things"), 0, NULL); |
1512 } | 1527 } |
1513 | 1528 |
1514 if (!found) | 1529 if (!found) |
1515 { | 1530 { |
1516 gaim_markup_extract_info_field(stripped, stripped_len, s, | 1531 gaim_markup_extract_info_field(stripped, stripped_len, s, |
1558 if (found) | 1573 if (found) |
1559 has_info = TRUE; | 1574 has_info = TRUE; |
1560 | 1575 |
1561 /* Extract the last updated date and put it in */ | 1576 /* Extract the last updated date and put it in */ |
1562 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | 1577 found = gaim_markup_extract_info_field(stripped, stripped_len, s, |
1563 "\tlast updated:", 1, "\n", '\n', NULL, _("Last Updated"), | 1578 "\tlast updated:", 1, "\n", '\n', NULL, _("Last Updated"), 0, |
1564 0, NULL); | 1579 NULL); |
1565 | 1580 |
1566 if (found) | 1581 if (found) |
1567 has_info = TRUE; | 1582 has_info = TRUE; |
1568 | 1583 |
1569 /* If we were able to fetch a homepage url earlier, stick it in there */ | 1584 /* If we were able to fetch a homepage url earlier, stick it in there */ |
1591 else | 1606 else |
1592 { | 1607 { |
1593 char primary[256]; | 1608 char primary[256]; |
1594 | 1609 |
1595 g_snprintf(primary, sizeof(primary), | 1610 g_snprintf(primary, sizeof(primary), |
1596 _("User information for %s unavailable"), info_data->name); | 1611 _("User information for %s unavailable"), |
1612 info_data->name); | |
1597 gaim_notify_error(info_data->gc, NULL, primary, | 1613 gaim_notify_error(info_data->gc, NULL, primary, |
1598 _("The user's profile is empty.")); | 1614 _("The user's profile is empty.")); |
1599 } | 1615 } |
1600 | 1616 |
1601 g_free(stripped); | 1617 g_free(stripped); |
1616 data->name = g_strdup(name); | 1632 data->name = g_strdup(name); |
1617 | 1633 |
1618 url = g_strdup_printf("%s%s", PROFILE_URL, name); | 1634 url = g_strdup_printf("%s%s", PROFILE_URL, name); |
1619 | 1635 |
1620 gaim_url_fetch(url, FALSE, | 1636 gaim_url_fetch(url, FALSE, |
1621 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", TRUE, | 1637 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", |
1622 msn_got_info, data); | 1638 TRUE, msn_got_info, data); |
1623 | 1639 |
1624 g_free(url); | 1640 g_free(url); |
1625 } | 1641 } |
1626 | 1642 |
1627 static gboolean msn_load(GaimPlugin *plugin) | 1643 static gboolean msn_load(GaimPlugin *plugin) |
1766 | 1782 |
1767 option = gaim_account_option_int_new(_("Port"), "port", 1863); | 1783 option = gaim_account_option_int_new(_("Port"), "port", 1863); |
1768 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | 1784 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
1769 option); | 1785 option); |
1770 | 1786 |
1771 option = gaim_account_option_bool_new(_("Use HTTP Method"), "http_method", | 1787 option = gaim_account_option_bool_new(_("Use HTTP Method"), |
1772 FALSE); | 1788 "http_method", FALSE); |
1773 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | 1789 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
1774 option); | 1790 option); |
1775 | 1791 |
1776 my_protocol = plugin; | 1792 my_protocol = plugin; |
1777 | 1793 |