comparison src/protocols/msn/msn.c @ 8808:bbd8cdaf0ad5

[gaim-migrate @ 9570] A massive patch by shx to reorganize MSN some more and add command processor support. This allows us to do cool things like produce more detailed error messages. For example, the Invalid Username dialog now shows the username of the invalid user. I modified the aforementioned dialog so it'll look a little nicer looking, and also mention the account this happened on. It also removes the user from your blist, as there's no point to keeping the user on there. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sun, 25 Apr 2004 22:02:06 +0000
parents d7b8eb1f0a18
children 9a62b8e3b23b
comparison
equal deleted inserted replaced
8807:482fc53c969d 8808:bbd8cdaf0ad5
31 #include "state.h" 31 #include "state.h"
32 #include "utils.h" 32 #include "utils.h"
33 #include "multi.h" 33 #include "multi.h"
34 #include "util.h" 34 #include "util.h"
35 35
36 #include "notification.h"
37 #include "switchboard.h"
38
36 #define BUDDY_ALIAS_MAXLEN 387 39 #define BUDDY_ALIAS_MAXLEN 387
37 40
38 static GaimPlugin *my_protocol = NULL; 41 static GaimPlugin *my_protocol = NULL;
39 42
40 static const char *msn_normalize(const GaimAccount *account, const char *str); 43 static const char *msn_normalize(const GaimAccount *account, const char *str);
54 } MsnGetInfoData; 57 } MsnGetInfoData;
55 58
56 static void 59 static void
57 msn_act_id(GaimConnection *gc, const char *entry) 60 msn_act_id(GaimConnection *gc, const char *entry)
58 { 61 {
59 MsnSession *session = gc->proto_data; 62 MsnCmdProc *cmdproc;
60 GaimAccount *account = gaim_connection_get_account(gc); 63 MsnSession *session;
61 char outparams[MSN_BUF_LEN]; 64 GaimAccount *account;
62 char *alias; 65 char *alias;
66
67 session = gc->proto_data;
68 cmdproc = session->notification_conn->cmdproc;
69 account = gaim_connection_get_account(gc);
63 70
64 if (entry == NULL || *entry == '\0') 71 if (entry == NULL || *entry == '\0')
65 alias = g_strdup(""); 72 alias = g_strdup("");
66 else 73 else
67 alias = g_strdup(entry); 74 alias = g_strdup(entry);
71 gaim_notify_error(gc, NULL, 78 gaim_notify_error(gc, NULL,
72 _("Your new MSN friendly name is too long."), NULL); 79 _("Your new MSN friendly name is too long."), NULL);
73 return; 80 return;
74 } 81 }
75 82
76 g_snprintf(outparams, sizeof(outparams), "%s %s", 83 msn_cmdproc_send(cmdproc, "REA", "%s %s",
77 gaim_account_get_username(account), gaim_url_encode(alias)); 84 gaim_account_get_username(account),
85 gaim_url_encode(alias));
78 86
79 g_free(alias); 87 g_free(alias);
80
81 if (!msn_servconn_send_command(session->notification_conn,
82 "REA", outparams)) {
83
84 gaim_connection_error(gc, _("Write error"));
85 return;
86 }
87 } 88 }
88 89
89 static void 90 static void
90 msn_set_prp(GaimConnection *gc, const char *type, const char *entry) 91 msn_set_prp(GaimConnection *gc, const char *type, const char *entry)
91 { 92 {
92 MsnSession *session = gc->proto_data; 93 MsnCmdProc *cmdproc;
93 char outparams[MSN_BUF_LEN]; 94 MsnSession *session;
95
96 session = gc->proto_data;
97 cmdproc = session->notification_conn->cmdproc;
94 98
95 if (entry == NULL || *entry == '\0') 99 if (entry == NULL || *entry == '\0')
96 g_snprintf(outparams, sizeof(outparams), "%s ", type); 100 {
101 msn_cmdproc_send(cmdproc, "PRP", "%s ", type);
102 }
97 else 103 else
98 g_snprintf(outparams, sizeof(outparams), "%s %s", type, 104 {
99 gaim_url_encode(entry)); 105 msn_cmdproc_send(cmdproc, "PRP", "%s %s", type,
100 106 gaim_url_encode(entry));
101 if (!msn_servconn_send_command(session->notification_conn,
102 "PRP", outparams)) {
103
104 gaim_connection_error(gc, _("Write error"));
105 return;
106 } 107 }
107 } 108 }
108 109
109 static void 110 static void
110 msn_set_home_phone_cb(GaimConnection *gc, const char *entry) 111 msn_set_home_phone_cb(GaimConnection *gc, const char *entry)
135 { 136 {
136 msn_set_prp(gc, "MOB", "N"); 137 msn_set_prp(gc, "MOB", "N");
137 } 138 }
138 139
139 static void 140 static void
140 send_to_mobile_cb(MsnMobileData *data, const char *entry) 141 send_to_mobile(GaimConnection *gc, const char *who, const char *entry)
141 { 142 {
142 MsnSession *session; 143 MsnSession *session;
143 MsnServConn *servconn; 144 MsnServConn *servconn;
145 MsnCmdProc *cmdproc;
146 MsnTransaction *trans;
144 MsnPage *page; 147 MsnPage *page;
145 char *buf;
146 char *payload; 148 char *payload;
147 size_t len;
148 size_t payload_len; 149 size_t payload_len;
149 150
150 session = data->gc->proto_data; 151 session = gc->proto_data;
151 servconn = session->notification_conn; 152 servconn = session->notification_conn;
153 cmdproc = servconn->cmdproc;
152 154
153 page = msn_page_new(); 155 page = msn_page_new();
154 msn_page_set_body(page, entry); 156 msn_page_set_body(page, entry);
155 buf = g_strdup_printf("PGD %d %s 1 %d\r\n", ++session->trId, 157
156 data->passport, page->size); 158 trans = msn_transaction_new("PGD", "%s 1 %d", who, page->size);
157
158 len = strlen(buf);
159 159
160 payload = msn_page_gen_payload(page, &payload_len); 160 payload = msn_page_gen_payload(page, &payload_len);
161 161
162 if (payload != NULL) 162 msn_transaction_set_payload(trans, payload, payload_len);
163 {
164 buf = g_realloc(buf, len + payload_len + 1);
165 memcpy(buf + len, payload, payload_len);
166 len += payload_len;
167 buf[len] = 0;
168 }
169 163
170 msn_page_destroy(page); 164 msn_page_destroy(page);
171 165
172 if (!msn_servconn_write(servconn, buf, len)) 166 msn_cmdproc_send_trans(cmdproc, trans);
173 { 167 }
174 gaim_connection_error(data->gc, _("Write error")); 168
175 } 169 static void
176 170 send_to_mobile_cb(MsnMobileData *data, const char *entry)
177 g_free(buf); 171 {
172 send_to_mobile(data->gc, data->passport, entry);
173 g_free(data);
178 } 174 }
179 175
180 static void 176 static void
181 close_mobile_page_cb(MsnMobileData *data, const char *entry) 177 close_mobile_page_cb(MsnMobileData *data, const char *entry)
182 { 178 {
244 240
245 static void 241 static void
246 show_send_to_mobile_cb(GaimConnection *gc, const char *passport) 242 show_send_to_mobile_cb(GaimConnection *gc, const char *passport)
247 { 243 {
248 MsnUser *user; 244 MsnUser *user;
249 MsnSession *session = gc->proto_data; 245 MsnSession *session;
250 MsnMobileData *data; 246 MsnMobileData *data;
251 247
248 session = gc->proto_data;
252 user = msn_users_find_with_passport(session->users, passport); 249 user = msn_users_find_with_passport(session->users, passport);
253 250
254 data = g_new0(MsnMobileData, 1); 251 data = g_new0(MsnMobileData, 1);
255 data->gc = gc; 252 data->gc = gc;
256 data->passport = passport; 253 data->passport = passport;
263 } 260 }
264 261
265 static void 262 static void
266 initiate_chat_cb(GaimConnection *gc, const char *passport) 263 initiate_chat_cb(GaimConnection *gc, const char *passport)
267 { 264 {
268 GaimAccount *account = gaim_connection_get_account(gc); 265 GaimAccount *account;
269 MsnSession *session = gc->proto_data; 266 MsnSession *session;
267 MsnCmdProc *cmdproc;
270 MsnSwitchBoard *swboard; 268 MsnSwitchBoard *swboard;
271 MsnUser *user; 269 MsnUser *user;
272 270
273 if ((swboard = msn_session_open_switchboard(session)) == NULL) { 271 account = gaim_connection_get_account(gc);
274 gaim_connection_error(gc, _("Write error")); 272 session = gc->proto_data;
275 273 cmdproc = session->notification_conn->cmdproc;
274
275 if ((swboard = msn_session_open_switchboard(session)) == NULL)
276 return; 276 return;
277 }
278 277
279 user = msn_user_new(session, passport, NULL); 278 user = msn_user_new(session, passport, NULL);
280 279
281 msn_switchboard_set_user(swboard, user); 280 msn_switchboard_set_user(swboard, user);
282 281
420 } 419 }
421 420
422 static GList * 421 static GList *
423 msn_buddy_menu(GaimConnection *gc, const char *who) 422 msn_buddy_menu(GaimConnection *gc, const char *who)
424 { 423 {
425 GaimAccount *account = gaim_connection_get_account(gc); 424 GaimAccount *account;
426 MsnUser *user; 425 MsnUser *user;
427 struct proto_buddy_menu *pbm; 426 struct proto_buddy_menu *pbm;
428 GaimBuddy *b; 427 GaimBuddy *b;
429 GList *m = NULL; 428 GList *m = NULL;
430 429
431 b = gaim_find_buddy(gc->account, who); 430 account = gaim_connection_get_account(gc);
431 b = gaim_find_buddy(account, who);
432 432
433 g_return_val_if_fail(b != NULL, NULL); 433 g_return_val_if_fail(b != NULL, NULL);
434 434
435 user = b->proto_data; 435 user = b->proto_data;
436 436
437 if (user != NULL) { 437 if (user != NULL)
438 if (user->mobile) { 438 {
439 if (user->mobile)
440 {
439 pbm = g_new0(struct proto_buddy_menu, 1); 441 pbm = g_new0(struct proto_buddy_menu, 1);
440 pbm->label = _("Send to Mobile"); 442 pbm->label = _("Send to Mobile");
441 pbm->callback = show_send_to_mobile_cb; 443 pbm->callback = show_send_to_mobile_cb;
442 pbm->gc = gc; 444 pbm->gc = gc;
443 m = g_list_append(m, pbm); 445 m = g_list_append(m, pbm);
444 } 446 }
445 } 447 }
446 448
447 if (g_ascii_strcasecmp(who, gaim_account_get_username(account))) { 449 if (g_ascii_strcasecmp(who, gaim_account_get_username(account)))
450 {
448 pbm = g_new0(struct proto_buddy_menu, 1); 451 pbm = g_new0(struct proto_buddy_menu, 1);
449 pbm->label = _("Initiate Chat"); 452 pbm->label = _("Initiate Chat");
450 pbm->callback = initiate_chat_cb; 453 pbm->callback = initiate_chat_cb;
451 pbm->gc = gc; 454 pbm->gc = gc;
452 m = g_list_append(m, pbm); 455 m = g_list_append(m, pbm);
508 username = msn_normalize(account, gaim_account_get_username(account)); 511 username = msn_normalize(account, gaim_account_get_username(account));
509 512
510 if (strcmp(username, gaim_account_get_username(account))) 513 if (strcmp(username, gaim_account_get_username(account)))
511 gaim_account_set_username(account, username); 514 gaim_account_set_username(account, username);
512 515
513 if (!msn_session_connect(session)) { 516 if (!msn_session_connect(session))
517 {
514 gaim_connection_error(gc, _("Unable to connect.")); 518 gaim_connection_error(gc, _("Unable to connect."));
515 519
516 return; 520 return;
517 } 521 }
518 } 522 }
535 539
536 static int 540 static int
537 msn_send_im(GaimConnection *gc, const char *who, const char *message, 541 msn_send_im(GaimConnection *gc, const char *who, const char *message,
538 GaimConvImFlags flags) 542 GaimConvImFlags flags)
539 { 543 {
540 GaimAccount *account = gaim_connection_get_account(gc); 544 GaimAccount *account;
541 MsnSession *session = gc->proto_data; 545 MsnSession *session;
542 MsnSwitchBoard *swboard; 546 MsnSwitchBoard *swboard;
543 547
548 account = gaim_connection_get_account(gc);
549 session = gc->proto_data;
544 swboard = msn_session_find_switch_with_passport(session, who); 550 swboard = msn_session_find_switch_with_passport(session, who);
545 551
546 if (g_ascii_strcasecmp(who, gaim_account_get_username(account))) { 552 if (g_ascii_strcasecmp(who, gaim_account_get_username(account)))
553 {
547 MsnMessage *msg; 554 MsnMessage *msg;
548 MsnUser *user; 555 MsnUser *user;
549 char *msgformat; 556 char *msgformat;
550 char *msgtext; 557 char *msgtext;
551 558
558 msn_message_set_body(msg, msgtext); 565 msn_message_set_body(msg, msgtext);
559 566
560 g_free(msgformat); 567 g_free(msgformat);
561 g_free(msgtext); 568 g_free(msgtext);
562 569
563 if (swboard != NULL) { 570 if (swboard != NULL)
564 if (!msn_switchboard_send_msg(swboard, msg)) 571 {
565 msn_switchboard_destroy(swboard); 572 msn_switchboard_send_msg(swboard, msg);
566 } 573 }
567 else { 574 else
568 if ((swboard = msn_session_open_switchboard(session)) == NULL) { 575 {
576 if ((swboard = msn_session_open_switchboard(session)) == NULL)
577 {
569 msn_message_destroy(msg); 578 msn_message_destroy(msg);
570
571 gaim_connection_error(gc, _("Write error"));
572 579
573 return 1; 580 return 1;
574 } 581 }
575 582
576 msn_switchboard_set_user(swboard, user); 583 msn_switchboard_set_user(swboard, user);
578 } 585 }
579 586
580 msn_user_destroy(user); 587 msn_user_destroy(user);
581 msn_message_destroy(msg); 588 msn_message_destroy(msg);
582 } 589 }
583 else { 590 else
591 {
584 /* 592 /*
585 * In MSN, you can't send messages to yourself, so 593 * In MSN, you can't send messages to yourself, so
586 * we'll fake like we received it ;) 594 * we'll fake like we received it ;)
587 */ 595 */
588 gchar *fakemsg = gaim_escape_html(message); 596 gchar *fakemsg = gaim_escape_html(message);
596 } 604 }
597 605
598 static int 606 static int
599 msn_send_typing(GaimConnection *gc, const char *who, int typing) 607 msn_send_typing(GaimConnection *gc, const char *who, int typing)
600 { 608 {
601 GaimAccount *account = gaim_connection_get_account(gc); 609 GaimAccount *account;
602 MsnSession *session = gc->proto_data; 610 MsnSession *session;
603 MsnSwitchBoard *swboard; 611 MsnSwitchBoard *swboard;
604 MsnMessage *msg; 612 MsnMessage *msg;
605 MsnUser *user; 613 MsnUser *user;
606 614
615 account = gaim_connection_get_account(gc);
616 session = gc->proto_data;
617
607 if (!typing) 618 if (!typing)
608 return 0; 619 return 0;
609 620
610 if (!g_ascii_strcasecmp(who, gaim_account_get_username(account))) { 621 if (!g_ascii_strcasecmp(who, gaim_account_get_username(account)))
622 {
611 /* We'll just fake it, since we're sending to ourself. */ 623 /* We'll just fake it, since we're sending to ourself. */
612 serv_got_typing(gc, who, MSN_TYPING_RECV_TIMEOUT, GAIM_TYPING); 624 serv_got_typing(gc, who, MSN_TYPING_RECV_TIMEOUT, GAIM_TYPING);
613 625
614 return MSN_TYPING_SEND_TIMEOUT; 626 return MSN_TYPING_SEND_TIMEOUT;
615 } 627 }
628 msn_message_set_attr(msg, "TypingUser", 640 msn_message_set_attr(msg, "TypingUser",
629 gaim_account_get_username(account)); 641 gaim_account_get_username(account));
630 msn_message_set_attr(msg, "User-Agent", NULL); 642 msn_message_set_attr(msg, "User-Agent", NULL);
631 msn_message_set_body(msg, "\r\n"); 643 msn_message_set_body(msg, "\r\n");
632 644
633 if (!msn_switchboard_send_msg(swboard, msg)) 645 msn_switchboard_send_msg(swboard, msg);
634 msn_switchboard_destroy(swboard);
635 646
636 msn_user_destroy(user); 647 msn_user_destroy(user);
637 648
638 return MSN_TYPING_SEND_TIMEOUT; 649 return MSN_TYPING_SEND_TIMEOUT;
639 } 650 }
640 651
641 static void 652 static void
642 msn_set_away(GaimConnection *gc, const char *state, const char *msg) 653 msn_set_away(GaimConnection *gc, const char *state, const char *msg)
643 { 654 {
644 MsnSession *session = gc->proto_data; 655 MsnSession *session;
645 const char *away; 656 const char *away;
657
658 session = gc->proto_data;
646 659
647 if (gc->away != NULL) 660 if (gc->away != NULL)
648 { 661 {
649 g_free(gc->away); 662 g_free(gc->away);
650 gc->away = NULL; 663 gc->away = NULL;
687 } 700 }
688 701
689 static void 702 static void
690 msn_set_idle(GaimConnection *gc, int idle) 703 msn_set_idle(GaimConnection *gc, int idle)
691 { 704 {
692 MsnSession *session = gc->proto_data; 705 MsnSession *session;
706
707 session = gc->proto_data;
693 708
694 if (gc->away != NULL) 709 if (gc->away != NULL)
695 return; 710 return;
696 711
697 msn_session_change_status(session, (idle ? "IDL" : "NLN")); 712 msn_session_change_status(session, (idle ? "IDL" : "NLN"));
698 } 713 }
699 714
700 static void 715 static void
701 msn_add_buddy(GaimConnection *gc, const char *name, GaimGroup *group) 716 msn_add_buddy(GaimConnection *gc, const char *name, GaimGroup *group)
702 { 717 {
703 MsnSession *session = gc->proto_data; 718 MsnSession *session;
719 MsnCmdProc *cmdproc;
704 MsnGroup *msn_group = NULL; 720 MsnGroup *msn_group = NULL;
705 const char *who; 721 const char *who;
706 char outparams[MSN_BUF_LEN];
707 GSList *l; 722 GSList *l;
708 723
724 session = gc->proto_data;
725 cmdproc = session->notification_conn->cmdproc;
709 who = msn_normalize(gc->account, name); 726 who = msn_normalize(gc->account, name);
710 727
711 if (strchr(who, ' ')) { 728 if (strchr(who, ' '))
729 {
712 /* This is a broken blist entry. */ 730 /* This is a broken blist entry. */
713 return; 731 return;
714 } 732 }
715 733
716 for (l = session->lists.forward; l != NULL; l = l->next) { 734 for (l = session->lists.forward; l != NULL; l = l->next)
735 {
717 MsnUser *user = l->data; 736 MsnUser *user = l->data;
718 737
719 if (!gaim_utf8_strcasecmp(who, msn_user_get_passport(user))) 738 if (!gaim_utf8_strcasecmp(who, msn_user_get_passport(user)))
720 break; 739 break;
721 } 740 }
726 if (group != NULL) 745 if (group != NULL)
727 msn_group = msn_groups_find_with_name(session->groups, group->name); 746 msn_group = msn_groups_find_with_name(session->groups, group->name);
728 747
729 if (msn_group != NULL) 748 if (msn_group != NULL)
730 { 749 {
731 g_snprintf(outparams, sizeof(outparams), 750 msn_cmdproc_send(cmdproc, "ADD", "FL %s %s %d", who, who,
732 "FL %s %s %d", who, who, msn_group_get_id(msn_group)); 751 msn_group_get_id(msn_group));
733 } 752 }
734 else 753 else
735 { 754 {
736 g_snprintf(outparams, sizeof(outparams), 755 msn_cmdproc_send(cmdproc, "ADD", "FL %s %s", who, who);
737 "FL %s %s", who, who);
738 }
739
740 if (!msn_servconn_send_command(session->notification_conn,
741 "ADD", outparams))
742 {
743 gaim_connection_error(gc, _("Write error"));
744 return;
745 } 756 }
746 } 757 }
747 758
748 static void 759 static void
749 msn_rem_buddy(GaimConnection *gc, const char *who, const char *group_name) 760 msn_rem_buddy(GaimConnection *gc, const char *who, const char *group_name)
750 { 761 {
751 MsnSession *session = gc->proto_data; 762 MsnSession *session;
752 char outparams[MSN_BUF_LEN]; 763 MsnCmdProc *cmdproc;
753 MsnGroup *group; 764 MsnGroup *group;
765
766 session = gc->proto_data;
767 cmdproc = session->notification_conn->cmdproc;
754 768
755 if (strchr(who, ' ')) 769 if (strchr(who, ' '))
756 { 770 {
757 /* This is a broken blist entry. */ 771 /* This is a broken blist entry. */
758 return; 772 return;
759 } 773 }
760 774
761 group = msn_groups_find_with_name(session->groups, group_name); 775 group = msn_groups_find_with_name(session->groups, group_name);
762 776
763 if (group == NULL) 777 if (group == NULL)
764 g_snprintf(outparams, sizeof(outparams), "FL %s", who); 778 {
779 msn_cmdproc_send(cmdproc, "REM", "FL %s", who);
780 }
765 else 781 else
766 g_snprintf(outparams, sizeof(outparams), "FL %s %d", who, 782 {
767 msn_group_get_id(group)); 783 msn_cmdproc_send(cmdproc, "REM", "FL %s %d", who,
768 784 msn_group_get_id(group));
769 if (!msn_servconn_send_command(session->notification_conn,
770 "REM", outparams)) {
771
772 gaim_connection_error(gc, _("Write error"));
773 return;
774 } 785 }
775 } 786 }
776 787
777 static void 788 static void
778 msn_add_permit(GaimConnection *gc, const char *who) 789 msn_add_permit(GaimConnection *gc, const char *who)
779 { 790 {
780 MsnSession *session = gc->proto_data; 791 MsnSession *session;
781 char buf[MSN_BUF_LEN]; 792 MsnCmdProc *cmdproc;
782 793
783 if (!strchr(who, '@')) { 794 session = gc->proto_data;
795 cmdproc = session->notification_conn->cmdproc;
796
797 if (!strchr(who, '@'))
798 {
799 char buf[MSN_BUF_LEN];
800
784 g_snprintf(buf, sizeof(buf), 801 g_snprintf(buf, sizeof(buf),
785 _("An MSN screen name must be in the form \"user@server.com\". " 802 _("An MSN screen name must be in the form \"user@server.com\". "
786 "Perhaps you meant %s@hotmail.com. No changes were made " 803 "Perhaps you meant %s@hotmail.com. No changes were made "
787 "to your allow list."), who); 804 "to your allow list."), who);
788 805
789 gaim_notify_error(gc, NULL, _("Invalid MSN screen name"), buf); 806 gaim_notify_error(gc, NULL, _("Invalid MSN screen name"), buf);
790 gaim_privacy_permit_remove(gc->account, who, TRUE); 807 gaim_privacy_permit_remove(gc->account, who, TRUE);
791 808
792 return; 809 return;
793 } 810 }
794 811
795 if (g_slist_find_custom(gc->account->deny, who, (GCompareFunc)strcmp)) { 812 if (g_slist_find_custom(gc->account->deny, who, (GCompareFunc)strcmp))
796 gaim_debug(GAIM_DEBUG_INFO, "msn", "Moving %s from BL to AL\n", who); 813 {
814 gaim_debug_info("msn", "Moving %s from BL to AL\n", who);
797 gaim_privacy_deny_remove(gc->account, who, TRUE); 815 gaim_privacy_deny_remove(gc->account, who, TRUE);
798 816
799 g_snprintf(buf, sizeof(buf), "BL %s", who); 817 msn_cmdproc_send(cmdproc, "REM", "BL %s", who);
800 818
801 if (!msn_servconn_send_command(session->notification_conn, 819 if (cmdproc->error)
802 "REM", buf)) {
803
804 gaim_connection_error(gc, _("Write error"));
805 return; 820 return;
806 } 821 }
807 } 822
808 823 msn_cmdproc_send(cmdproc, "ADD", "AL %s %s", who, who);
809 g_snprintf(buf, sizeof(buf), "AL %s %s", who, who); 824 }
810 825
811 if (!msn_servconn_send_command(session->notification_conn, "ADD", buf)) { 826 static void
812 gaim_connection_error(gc, _("Write error")); 827 msn_add_deny(GaimConnection *gc, const char *who)
828 {
829 MsnCmdProc *cmdproc;
830 MsnSession *session;
831
832 session = gc->proto_data;
833 cmdproc = session->notification_conn->cmdproc;
834
835 if (!strchr(who, '@'))
836 {
837 char buf[MSN_BUF_LEN];
838 g_snprintf(buf, sizeof(buf),
839 _("An MSN screen name must be in the form \"user@server.com\". "
840 "Perhaps you meant %s@hotmail.com. No changes were made "
841 "to your block list."), who);
842
843 gaim_notify_error(gc, NULL, _("Invalid MSN screen name"), buf);
844
845 gaim_privacy_deny_remove(gc->account, who, TRUE);
846
813 return; 847 return;
814 } 848 }
815 } 849
816 850 if (g_slist_find_custom(gc->account->permit, who, (GCompareFunc)strcmp))
817 static void 851 {
818 msn_add_deny(GaimConnection *gc, const char *who)
819 {
820 MsnSession *session = gc->proto_data;
821 char buf[MSN_BUF_LEN];
822
823 if (!strchr(who, '@')) {
824 g_snprintf(buf, sizeof(buf),
825 _("An MSN screen name must be in the form \"user@server.com\". "
826 "Perhaps you meant %s@hotmail.com. No changes were made "
827 "to your block list."), who);
828
829 gaim_notify_error(gc, NULL, _("Invalid MSN screen name"), buf);
830
831 gaim_privacy_deny_remove(gc->account, who, TRUE);
832
833 return;
834 }
835
836 if (g_slist_find_custom(gc->account->permit, who, (GCompareFunc)strcmp)) {
837 gaim_debug(GAIM_DEBUG_INFO, "msn", "Moving %s from AL to BL\n", who); 852 gaim_debug(GAIM_DEBUG_INFO, "msn", "Moving %s from AL to BL\n", who);
838 gaim_privacy_permit_remove(gc->account, who, TRUE); 853 gaim_privacy_permit_remove(gc->account, who, TRUE);
839 854
840 g_snprintf(buf, sizeof(buf), "AL %s", who); 855 msn_cmdproc_send(cmdproc, "REM", "AL %s", who);
841 856
842 if (!msn_servconn_send_command(session->notification_conn, 857 if (cmdproc->error)
843 "REM", buf)) {
844
845 gaim_connection_error(gc, _("Write error"));
846 return; 858 return;
847 } 859 }
848 } 860
849 861 msn_cmdproc_send(cmdproc, "ADD", "BL %s %s", who, who);
850 g_snprintf(buf, sizeof(buf), "BL %s %s", who, who); 862 }
851 863
852 if (!msn_servconn_send_command(session->notification_conn, "ADD", buf)) { 864 static void
853 gaim_connection_error(gc, _("Write error")); 865 msn_rem_permit(GaimConnection *gc, const char *who)
866 {
867 MsnSession *session;
868 MsnCmdProc *cmdproc;
869
870 session = gc->proto_data;
871 cmdproc = session->notification_conn->cmdproc;
872
873 msn_cmdproc_send(cmdproc, "REM", "AL %s", who);
874
875 if (cmdproc->error)
854 return; 876 return;
855 } 877
856 } 878 gaim_privacy_deny_add(gc->account, who, TRUE);
857 879
858 static void 880 msn_cmdproc_send(cmdproc, "ADD", "BL %s %s", who, who);
859 msn_rem_permit(GaimConnection *gc, const char *who) 881 }
860 { 882
861 MsnSession *session = gc->proto_data; 883 static void
862 char buf[MSN_BUF_LEN]; 884 msn_rem_deny(GaimConnection *gc, const char *who)
863 885 {
864 g_snprintf(buf, sizeof(buf), "AL %s", who); 886 MsnSession *session;
865 887 MsnCmdProc *cmdproc;
866 if (!msn_servconn_send_command(session->notification_conn, "REM", buf)) { 888
867 gaim_connection_error(gc, _("Write error")); 889 session = gc->proto_data;
890 cmdproc = session->notification_conn->cmdproc;
891
892 msn_cmdproc_send(cmdproc, "REM", "BL %s", who);
893
894 if (cmdproc->error)
868 return; 895 return;
869 } 896
870 897 gaim_privacy_permit_add(gc->account, who, TRUE);
871 gaim_privacy_deny_add(gc->account, who, TRUE); 898
872 899 msn_cmdproc_send(cmdproc, "ADD", "AL %s %s", who, who);
873 g_snprintf(buf, sizeof(buf), "BL %s %s", who, who); 900 }
874 901
875 if (!msn_servconn_send_command(session->notification_conn, "ADD", buf)) { 902 static void
876 gaim_connection_error(gc, _("Write error")); 903 msn_set_permit_deny(GaimConnection *gc)
904 {
905 GaimAccount *account;
906 MsnSession *session;
907 MsnCmdProc *cmdproc;
908 GSList *s, *t = NULL;
909
910 account = gaim_connection_get_account(gc);
911 session = gc->proto_data;
912 cmdproc = session->notification_conn->cmdproc;
913
914 if (account->perm_deny == GAIM_PRIVACY_ALLOW_ALL ||
915 account->perm_deny == GAIM_PRIVACY_DENY_USERS)
916 {
917 msn_cmdproc_send(cmdproc, "BLP", "%s", "AL");
918 }
919 else
920 {
921 msn_cmdproc_send(cmdproc, "BLP", "%s", "BL");
922 }
923
924 if (cmdproc->error)
877 return; 925 return;
878 }
879 }
880
881 static void
882 msn_rem_deny(GaimConnection *gc, const char *who)
883 {
884 MsnSession *session = gc->proto_data;
885 char buf[MSN_BUF_LEN];
886
887 g_snprintf(buf, sizeof(buf), "BL %s", who);
888
889 if (!msn_servconn_send_command(session->notification_conn, "REM", buf))
890 {
891 gaim_connection_error(gc, _("Write error"));
892 return;
893 }
894
895 gaim_privacy_permit_add(gc->account, who, TRUE);
896
897 g_snprintf(buf, sizeof(buf), "AL %s %s", who, who);
898
899 if (!msn_servconn_send_command(session->notification_conn, "ADD", buf))
900 {
901 gaim_connection_error(gc, _("Write error"));
902 return;
903 }
904 }
905
906 static void
907 msn_set_permit_deny(GaimConnection *gc)
908 {
909 GaimAccount *account = gaim_connection_get_account(gc);
910 MsnSession *session = gc->proto_data;
911 char buf[MSN_BUF_LEN];
912 GSList *s, *t = NULL;
913
914 if (account->perm_deny == GAIM_PRIVACY_ALLOW_ALL ||
915 account->perm_deny == GAIM_PRIVACY_DENY_USERS) {
916
917 strcpy(buf, "AL");
918 }
919 else
920 strcpy(buf, "BL");
921
922 if (!msn_servconn_send_command(session->notification_conn, "BLP", buf)) {
923 gaim_connection_error(gc, _("Write error"));
924 return;
925 }
926 926
927 /* 927 /*
928 * This is safe because we'll always come here after we've gotten 928 * This is safe because we'll always come here after we've gotten
929 * the list off the server, and data is never removed. So if the 929 * the list off the server, and data is never removed. So if the
930 * lengths are equal we don't know about anyone locally and so 930 * lengths are equal we don't know about anyone locally and so
931 * there's no sense in going through them all. 931 * there's no sense in going through them all.
932 */ 932 */
933 if (g_slist_length(gc->account->permit) == 933 if (g_slist_length(gc->account->permit) ==
934 g_slist_length(session->lists.allow)) { 934 g_slist_length(session->lists.allow))
935 935 {
936 g_slist_free(session->lists.allow); 936 g_slist_free(session->lists.allow);
937 session->lists.allow = NULL; 937 session->lists.allow = NULL;
938 } 938 }
939 939
940 if (g_slist_length(gc->account->deny) == 940 if (g_slist_length(gc->account->deny) ==
941 g_slist_length(session->lists.block)) { 941 g_slist_length(session->lists.block))
942 942 {
943 g_slist_free(session->lists.block); 943 g_slist_free(session->lists.block);
944 session->lists.block = NULL; 944 session->lists.block = NULL;
945 } 945 }
946 946
947 if (session->lists.allow == NULL && session->lists.block == NULL) 947 if (session->lists.allow == NULL && session->lists.block == NULL)
948 return; 948 return;
949 949
950 if (session->lists.allow != NULL) { 950 if (session->lists.allow != NULL)
951 951 {
952 for (s = g_slist_nth(gc->account->permit, 952 for (s = g_slist_nth(gc->account->permit,
953 g_slist_length(session->lists.allow)); 953 g_slist_length(session->lists.allow));
954 s != NULL; 954 s != NULL;
955 s = s->next) { 955 s = s->next)
956 956 {
957 char *who = s->data; 957 char *who = s->data;
958 958
959 if (!strchr(who, '@')) { 959 if (!strchr(who, '@'))
960 {
960 t = g_slist_append(t, who); 961 t = g_slist_append(t, who);
961 continue; 962 continue;
962 } 963 }
963 964
964 if (g_slist_find(session->lists.block, who)) { 965 if (g_slist_find(session->lists.block, who))
966 {
965 t = g_slist_append(t, who); 967 t = g_slist_append(t, who);
966 continue; 968 continue;
967 } 969 }
968 970
969 g_snprintf(buf, sizeof(buf), "AL %s %s", who, who); 971 msn_cmdproc_send(cmdproc, "ADD", "AL %s %s", who, who);
970 972
971 if (!msn_servconn_send_command(session->notification_conn, 973 if (cmdproc->error)
972 "ADD", buf)) {
973 gaim_connection_error(gc, _("Write error"));
974 return; 974 return;
975 }
976 } 975 }
977 976
978 for (; t != NULL; t = t->next) 977 for (; t != NULL; t = t->next)
979 gaim_privacy_permit_remove(gc->account, t->data, TRUE); 978 gaim_privacy_permit_remove(gc->account, t->data, TRUE);
980 979
984 t = NULL; 983 t = NULL;
985 g_slist_free(session->lists.allow); 984 g_slist_free(session->lists.allow);
986 session->lists.allow = NULL; 985 session->lists.allow = NULL;
987 } 986 }
988 987
989 if (session->lists.block) { 988 if (session->lists.block)
989 {
990 for (s = g_slist_nth(gc->account->deny, 990 for (s = g_slist_nth(gc->account->deny,
991 g_slist_length(session->lists.block)); 991 g_slist_length(session->lists.block));
992 s != NULL; 992 s != NULL;
993 s = s->next) { 993 s = s->next)
994 994 {
995 char *who = s->data; 995 char *who = s->data;
996 996
997 if (!strchr(who, '@')) { 997 if (!strchr(who, '@'))
998 {
998 t = g_slist_append(t, who); 999 t = g_slist_append(t, who);
999 continue; 1000 continue;
1000 } 1001 }
1001 1002
1002 if (g_slist_find(session->lists.block, who)) { 1003 if (g_slist_find(session->lists.block, who))
1004 {
1003 t = g_slist_append(t, who); 1005 t = g_slist_append(t, who);
1004 continue; 1006 continue;
1005 } 1007 }
1006 1008
1007 g_snprintf(buf, sizeof(buf), "BL %s %s", who, who); 1009 msn_cmdproc_send(cmdproc, "ADD", "BL %s %s", who, who);
1008 1010
1009 if (!msn_servconn_send_command(session->notification_conn, 1011 if (cmdproc->error)
1010 "ADD", buf)) {
1011 gaim_connection_error(gc, _("Write error"));
1012 return; 1012 return;
1013 }
1014 } 1013 }
1015 1014
1016 for (; t != NULL; t = t->next) 1015 for (; t != NULL; t = t->next)
1017 gaim_privacy_deny_remove(gc->account, t->data, TRUE); 1016 gaim_privacy_deny_remove(gc->account, t->data, TRUE);
1018 1017
1026 1025
1027 static void 1026 static void
1028 msn_chat_invite(GaimConnection *gc, int id, const char *msg, 1027 msn_chat_invite(GaimConnection *gc, int id, const char *msg,
1029 const char *who) 1028 const char *who)
1030 { 1029 {
1031 MsnSession *session = gc->proto_data; 1030 MsnSession *session;
1032 MsnSwitchBoard *swboard = msn_session_find_switch_with_id(session, id); 1031 MsnSwitchBoard *swboard;
1032
1033 session = gc->proto_data;
1034 swboard = msn_session_find_switch_with_id(session, id);
1033 1035
1034 if (swboard == NULL) 1036 if (swboard == NULL)
1035 return; 1037 return;
1036 1038
1037 if (!msn_switchboard_send_command(swboard, "CAL", who)) 1039 msn_cmdproc_send(swboard->cmdproc, "CAL", "%s", who);
1038 msn_switchboard_destroy(swboard);
1039 } 1040 }
1040 1041
1041 static void 1042 static void
1042 msn_chat_leave(GaimConnection *gc, int id) 1043 msn_chat_leave(GaimConnection *gc, int id)
1043 { 1044 {
1044 MsnSession *session = gc->proto_data; 1045 GaimAccount *account;
1045 MsnSwitchBoard *swboard = msn_session_find_switch_with_id(session, id); 1046 MsnSession *session;
1046 char buf[6]; 1047 MsnSwitchBoard *swboard;
1047 1048
1048 if (swboard == NULL) { 1049 session = gc->proto_data;
1050 account = gaim_connection_get_account(gc);
1051 swboard = msn_session_find_switch_with_id(session, id);
1052
1053 if (swboard == NULL)
1054 {
1049 serv_got_chat_left(gc, id); 1055 serv_got_chat_left(gc, id);
1050 return; 1056 return;
1051 } 1057 }
1052 1058
1053 strcpy(buf, "OUT\r\n"); 1059 msn_cmdproc_send_quick(swboard->cmdproc, "OUT", NULL, NULL);
1054 1060 msn_switchboard_destroy(swboard);
1055 if (!msn_servconn_write(swboard->servconn, buf, strlen(buf)))
1056 msn_switchboard_destroy(swboard);
1057 1061
1058 serv_got_chat_left(gc, id); 1062 serv_got_chat_left(gc, id);
1059 } 1063 }
1060 1064
1061 static int 1065 static int
1062 msn_chat_send(GaimConnection *gc, int id, const char *message) 1066 msn_chat_send(GaimConnection *gc, int id, const char *message)
1063 { 1067 {
1064 GaimAccount *account = gaim_connection_get_account(gc); 1068 GaimAccount *account;
1065 MsnSession *session = gc->proto_data; 1069 MsnSession *session;
1066 MsnSwitchBoard *swboard = msn_session_find_switch_with_id(session, id); 1070 MsnSwitchBoard *swboard;
1067 MsnMessage *msg; 1071 MsnMessage *msg;
1068 char *send, *recv; 1072 char *send, *recv;
1073
1074 account = gaim_connection_get_account(gc);
1075 session = gc->proto_data;
1076 swboard = msn_session_find_switch_with_id(session, id);
1069 1077
1070 if (swboard == NULL) 1078 if (swboard == NULL)
1071 return -EINVAL; 1079 return -EINVAL;
1072 1080
1073 send = gaim_str_add_cr(message); 1081 send = gaim_str_add_cr(message);
1077 "FN=MS%20Sans%20Serif; EF=; CO=0; PF=0"); 1085 "FN=MS%20Sans%20Serif; EF=; CO=0; PF=0");
1078 msn_message_set_body(msg, send); 1086 msn_message_set_body(msg, send);
1079 1087
1080 g_free(send); 1088 g_free(send);
1081 1089
1082 if (!msn_switchboard_send_msg(swboard, msg)) { 1090 msn_switchboard_send_msg(swboard, msg);
1083 msn_switchboard_destroy(swboard);
1084
1085 msn_message_destroy(msg);
1086
1087 return 0;
1088 }
1089 1091
1090 msn_message_destroy(msg); 1092 msn_message_destroy(msg);
1091 1093
1092 recv = gaim_escape_html(message); 1094 recv = gaim_escape_html(message);
1093 serv_got_chat_in(gc, id, gaim_account_get_username(account), 1095 serv_got_chat_in(gc, id, gaim_account_get_username(account),
1098 } 1100 }
1099 1101
1100 static void 1102 static void
1101 msn_keepalive(GaimConnection *gc) 1103 msn_keepalive(GaimConnection *gc)
1102 { 1104 {
1103 MsnSession *session = gc->proto_data; 1105 MsnSession *session;
1104 char buf[MSN_BUF_LEN]; 1106 MsnCmdProc *cmdproc;
1107
1108 session = gc->proto_data;
1109 cmdproc = session->notification_conn->cmdproc;
1105 1110
1106 if (!session->http_method) 1111 if (!session->http_method)
1107 { 1112 msn_cmdproc_send_quick(cmdproc, "PNG", NULL, NULL);
1108 g_snprintf(buf, sizeof(buf), "PNG\r\n");
1109
1110 if (msn_servconn_write(session->notification_conn,
1111 buf, strlen(buf)) < 0) {
1112
1113 gaim_connection_error(gc, _("Write error"));
1114 return;
1115 }
1116 }
1117 } 1113 }
1118 1114
1119 static void 1115 static void
1120 msn_group_buddy(GaimConnection *gc, const char *who, 1116 msn_group_buddy(GaimConnection *gc, const char *who,
1121 const char *old_group_name, const char *new_group_name) 1117 const char *old_group_name, const char *new_group_name)
1122 { 1118 {
1123 MsnSession *session = gc->proto_data; 1119 MsnSession *session;
1120 MsnCmdProc *cmdproc;
1124 MsnGroup *old_group, *new_group; 1121 MsnGroup *old_group, *new_group;
1125 MsnUser *user; 1122 MsnUser *user;
1126 const char *friendly; 1123 const char *friendly;
1127 char outparams[MSN_BUF_LEN]; 1124
1128 1125 session = gc->proto_data;
1126 cmdproc = session->notification_conn->cmdproc;
1129 old_group = msn_groups_find_with_name(session->groups, old_group_name); 1127 old_group = msn_groups_find_with_name(session->groups, old_group_name);
1130 new_group = msn_groups_find_with_name(session->groups, new_group_name); 1128 new_group = msn_groups_find_with_name(session->groups, new_group_name);
1131 1129
1132 user = msn_users_find_with_passport(session->users, who); 1130 user = msn_users_find_with_passport(session->users, who);
1133 1131
1135 friendly = msn_user_get_passport(user); 1133 friendly = msn_user_get_passport(user);
1136 1134
1137 if (old_group != NULL) 1135 if (old_group != NULL)
1138 msn_user_remove_group_id(user, msn_group_get_id(old_group)); 1136 msn_user_remove_group_id(user, msn_group_get_id(old_group));
1139 1137
1140 if (new_group == NULL) { 1138 if (new_group == NULL)
1141 g_snprintf(outparams, sizeof(outparams), "%s 0", 1139 {
1142 gaim_url_encode(new_group_name)); 1140 msn_cmdproc_send(cmdproc, "ADG", "%s 0",
1143 1141 gaim_url_encode(new_group_name));
1144 if (!msn_servconn_send_command(session->notification_conn, 1142
1145 "ADG", outparams)) { 1143 if (cmdproc->error)
1146 gaim_connection_error(gc, _("Write error"));
1147 return; 1144 return;
1148 }
1149 1145
1150 /* I hate this. So much. */ 1146 /* I hate this. So much. */
1151 session->moving_buddy = TRUE; 1147 session->moving_buddy = TRUE;
1152 session->dest_group_name = g_strdup(new_group_name); 1148 session->dest_group_name = g_strdup(new_group_name);
1153 session->old_group = old_group; 1149 session->old_group = old_group;
1155 session->moving_user = 1151 session->moving_user =
1156 msn_users_find_with_passport(session->users, who); 1152 msn_users_find_with_passport(session->users, who);
1157 1153
1158 msn_user_ref(session->moving_user); 1154 msn_user_ref(session->moving_user);
1159 } 1155 }
1160 else { 1156 else
1161 g_snprintf(outparams, sizeof(outparams), "FL %s %s %d", 1157 {
1162 who, gaim_url_encode(friendly), 1158 msn_cmdproc_send(cmdproc, "ADD", "FL %s %s %d",
1163 msn_group_get_id(new_group)); 1159 who, gaim_url_encode(friendly),
1164 1160 msn_group_get_id(new_group));
1165 if (!msn_servconn_send_command(session->notification_conn, 1161
1166 "ADD", outparams)) { 1162 if (cmdproc->error)
1167 gaim_connection_error(gc, _("Write error"));
1168 return; 1163 return;
1169 } 1164 }
1170 } 1165
1171 1166 if (old_group != NULL)
1172 if (old_group != NULL) { 1167 {
1173 g_snprintf(outparams, sizeof(outparams), "FL %s %d", 1168 msn_cmdproc_send(cmdproc, "REM", "AL %s %s", who,
1174 who, msn_group_get_id(old_group)); 1169 msn_group_get_id(old_group));
1175 1170
1176 if (!msn_servconn_send_command(session->notification_conn, 1171 if (cmdproc->error)
1177 "REM", outparams)) {
1178 gaim_connection_error(gc, _("Write error"));
1179 return; 1172 return;
1180 } 1173
1181 1174 if (msn_users_get_count(msn_group_get_users(old_group)) <= 0)
1182 if (msn_users_get_count(msn_group_get_users(old_group)) <= 0) { 1175 {
1183 g_snprintf(outparams, sizeof(outparams), "%d", 1176 msn_cmdproc_send(cmdproc, "RMG", "%d",
1184 msn_group_get_id(old_group)); 1177 msn_group_get_id(old_group));
1185
1186 if (!msn_servconn_send_command(session->notification_conn,
1187 "RMG", outparams)) {
1188
1189 gaim_connection_error(gc, _("Write error"));
1190 return;
1191 }
1192 } 1178 }
1193 } 1179 }
1194 } 1180 }
1195 1181
1196 static void 1182 static void
1197 msn_rename_group(GaimConnection *gc, const char *old_group_name, 1183 msn_rename_group(GaimConnection *gc, const char *old_group_name,
1198 const char *new_group_name, GList *members) 1184 const char *new_group_name, GList *members)
1199 { 1185 {
1200 MsnSession *session = gc->proto_data; 1186 MsnSession *session;
1201 char outparams[MSN_BUF_LEN]; 1187 MsnCmdProc *cmdproc;
1202 MsnGroup *old_group; 1188 MsnGroup *old_group;
1203 1189
1190 session = gc->proto_data;
1191 cmdproc = session->notification_conn->cmdproc;
1192
1204 if ((old_group = msn_groups_find_with_name(session->groups, 1193 if ((old_group = msn_groups_find_with_name(session->groups,
1205 old_group_name)) != NULL) { 1194 old_group_name)) != NULL)
1206 1195 {
1207 g_snprintf(outparams, sizeof(outparams), "%d %s 0", 1196 msn_cmdproc_send(cmdproc, "REG", "%d %s 0",
1208 msn_group_get_id(old_group), 1197 msn_group_get_id(old_group),
1209 gaim_url_encode(new_group_name)); 1198 gaim_url_encode(new_group_name));
1210 1199
1211 if (!msn_servconn_send_command(session->notification_conn, 1200 if (cmdproc->error)
1212 "REG", outparams)) {
1213 gaim_connection_error(gc, _("Write error"));
1214 return; 1201 return;
1215 }
1216 1202
1217 msn_group_set_name(old_group, new_group_name); 1203 msn_group_set_name(old_group, new_group_name);
1218 } 1204 }
1219 else { 1205 else
1220 g_snprintf(outparams, sizeof(outparams), "%s 0", 1206 {
1221 gaim_url_encode(new_group_name)); 1207 msn_cmdproc_send(cmdproc, "ADG", "%s 0",
1222 1208 gaim_url_encode(new_group_name));
1223 if (!msn_servconn_send_command(session->notification_conn,
1224 "ADG", outparams)) {
1225 gaim_connection_error(gc, _("Write error"));
1226 return;
1227 }
1228 } 1209 }
1229 } 1210 }
1230 1211
1231 static void 1212 static void
1232 msn_buddy_free(GaimBuddy *b) 1213 msn_buddy_free(GaimBuddy *b)
1233 { 1214 {
1234 if (b->proto_data != NULL) { 1215 if (b->proto_data != NULL)
1216 {
1235 msn_user_destroy(b->proto_data); 1217 msn_user_destroy(b->proto_data);
1236 b->proto_data = NULL; 1218 b->proto_data = NULL;
1237 } 1219 }
1238 } 1220 }
1239 1221
1240 static void 1222 static void
1241 msn_convo_closed(GaimConnection *gc, const char *who) 1223 msn_convo_closed(GaimConnection *gc, const char *who)
1242 { 1224 {
1243 GaimAccount *account = gaim_connection_get_account(gc); 1225 GaimAccount *account;
1244 MsnSession *session = gc->proto_data; 1226 MsnSession *session;
1245 MsnSwitchBoard *swboard; 1227 MsnSwitchBoard *swboard;
1246 1228
1229 account = gaim_connection_get_account(gc);
1230 session = gc->proto_data;
1247 swboard = msn_session_find_switch_with_passport(session, who); 1231 swboard = msn_session_find_switch_with_passport(session, who);
1248 1232
1249 if (swboard != NULL && swboard->chat == NULL) { 1233 if (swboard != NULL && swboard->chat == NULL)
1250 char sendbuf[256]; 1234 {
1251 1235 msn_cmdproc_send_quick(swboard->cmdproc, "BYE", "%s",
1252 g_snprintf(sendbuf, sizeof(sendbuf), "BYE %s\r\n", 1236 gaim_account_get_username(account));
1253 gaim_account_get_username(account));
1254
1255 msn_servconn_write(swboard->servconn, sendbuf, strlen(sendbuf));
1256 1237
1257 msn_switchboard_destroy(swboard); 1238 msn_switchboard_destroy(swboard);
1258 } 1239 }
1259 } 1240 }
1260 1241
1288 } 1269 }
1289 1270
1290 static void 1271 static void
1291 msn_remove_group(GaimConnection *gc, const char *name) 1272 msn_remove_group(GaimConnection *gc, const char *name)
1292 { 1273 {
1293 MsnSession *session = (MsnSession *)gc->proto_data; 1274 MsnSession *session;
1275 MsnCmdProc *cmdproc;
1294 MsnGroup *group; 1276 MsnGroup *group;
1295 1277
1278 session = gc->proto_data;
1279 cmdproc = session->notification_conn->cmdproc;
1280
1296 if ((group = msn_groups_find_with_name(session->groups, name)) != NULL) 1281 if ((group = msn_groups_find_with_name(session->groups, name)) != NULL)
1297 { 1282 {
1298 char outparams[MSN_BUF_LEN]; 1283 msn_cmdproc_send(cmdproc, "RMG", "%d", msn_group_get_id(group));
1299
1300 g_snprintf(outparams, sizeof(outparams), "%d",
1301 msn_group_get_id(group));
1302
1303 if (!msn_servconn_send_command(session->notification_conn,
1304 "RMG", outparams))
1305 {
1306 gaim_connection_error(gc, _("Write error"));
1307
1308 return;
1309 }
1310 } 1284 }
1311 } 1285 }
1312 1286
1313 static void 1287 static void
1314 msn_got_info(void *data, const char *url_text, size_t len) 1288 msn_got_info(void *data, const char *url_text, size_t len)
1609 msn_got_info, data); 1583 msn_got_info, data);
1610 1584
1611 g_free(url); 1585 g_free(url);
1612 } 1586 }
1613 1587
1588 static gboolean msn_load(GaimPlugin *plugin)
1589 {
1590 msn_notification_init();
1591 msn_switchboard_init();
1592
1593 return TRUE;
1594 }
1595
1596 static gboolean msn_unload(GaimPlugin *plugin)
1597 {
1598 msn_notification_end();
1599 msn_switchboard_end();
1600
1601 return TRUE;
1602 }
1603
1614 static GaimPluginPrefFrame * 1604 static GaimPluginPrefFrame *
1615 get_plugin_pref_frame(GaimPlugin *plugin) { 1605 get_plugin_pref_frame(GaimPlugin *plugin) {
1616 GaimPluginPrefFrame *frame; 1606 GaimPluginPrefFrame *frame;
1617 GaimPluginPref *ppref; 1607 GaimPluginPref *ppref;
1618 1608
1718 /** description */ 1708 /** description */
1719 N_("MSN Protocol Plugin"), 1709 N_("MSN Protocol Plugin"),
1720 "Christian Hammond <chipx86@gnupdate.org>", /**< author */ 1710 "Christian Hammond <chipx86@gnupdate.org>", /**< author */
1721 GAIM_WEBSITE, /**< homepage */ 1711 GAIM_WEBSITE, /**< homepage */
1722 1712
1723 NULL, /**< load */ 1713 msn_load, /**< load */
1724 NULL, /**< unload */ 1714 msn_unload, /**< unload */
1725 NULL, /**< destroy */ 1715 NULL, /**< destroy */
1726 1716
1727 NULL, /**< ui_info */ 1717 NULL, /**< ui_info */
1728 &prpl_info, /**< extra_info */ 1718 &prpl_info, /**< extra_info */
1729 &prefs_info /**< prefs_info */ 1719 &prefs_info /**< prefs_info */
1730 }; 1720 };
1731 1721
1732 static void 1722 static void
1733 init_plugin(GaimPlugin *plugin) 1723 init_plugin(GaimPlugin *plugin)
1734 { 1724 {