comparison src/protocols/msn/msn.c @ 5564:187c740f2a4e

[gaim-migrate @ 5966] Committing what I have so far. Some new functions, and msn is almost done. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Fri, 30 May 2003 18:04:45 +0000
parents bf2a7a7b739d
children cc9ddec20010
comparison
equal deleted inserted replaced
5563:9eb5b13fd412 5564:187c740f2a4e
35 35
36 static char *msn_normalize(const char *str); 36 static char *msn_normalize(const char *str);
37 37
38 typedef struct 38 typedef struct
39 { 39 {
40 struct gaim_connection *gc; 40 GaimConnection *gc;
41 const char *passport; 41 const char *passport;
42 42
43 } MsnMobileData; 43 } MsnMobileData;
44 44
45 static void 45 static void
46 msn_act_id(struct gaim_connection *gc, const char *entry) 46 msn_act_id(GaimConnection *gc, const char *entry)
47 { 47 {
48 MsnSession *session = gc->proto_data; 48 MsnSession *session = gc->proto_data;
49 GaimAccount *account = gaim_connection_get_account(gc);
49 char outparams[MSN_BUF_LEN]; 50 char outparams[MSN_BUF_LEN];
50 char *alias; 51 char *alias;
51 52
52 if (entry == NULL || *entry == '\0') 53 if (entry == NULL || *entry == '\0')
53 alias = g_strdup(""); 54 alias = g_strdup("");
59 _("Your new MSN friendly name is too long."), NULL); 60 _("Your new MSN friendly name is too long."), NULL);
60 return; 61 return;
61 } 62 }
62 63
63 g_snprintf(outparams, sizeof(outparams), "%s %s", 64 g_snprintf(outparams, sizeof(outparams), "%s %s",
64 gc->username, msn_url_encode(alias)); 65 gaim_account_get_username(account), msn_url_encode(alias));
65 66
66 g_free(alias); 67 g_free(alias);
67 68
68 if (!msn_servconn_send_command(session->notification_conn, 69 if (!msn_servconn_send_command(session->notification_conn,
69 "REA", outparams)) { 70 "REA", outparams)) {
70 71
71 hide_login_progress(gc, _("Write error")); 72 gaim_connection_error(gc, _("Write error"));
72 signoff(gc); 73 return;
73 } 74 }
74 } 75 }
75 76
76 static void 77 static void
77 msn_set_prp(struct gaim_connection *gc, const char *type, const char *entry) 78 msn_set_prp(GaimConnection *gc, const char *type, const char *entry)
78 { 79 {
79 MsnSession *session = gc->proto_data; 80 MsnSession *session = gc->proto_data;
80 char outparams[MSN_BUF_LEN]; 81 char outparams[MSN_BUF_LEN];
81 82
82 if (entry == NULL || *entry == '\0') 83 if (entry == NULL || *entry == '\0')
85 g_snprintf(outparams, sizeof(outparams), "%s %s", type, entry); 86 g_snprintf(outparams, sizeof(outparams), "%s %s", type, entry);
86 87
87 if (!msn_servconn_send_command(session->notification_conn, 88 if (!msn_servconn_send_command(session->notification_conn,
88 "PRP", outparams)) { 89 "PRP", outparams)) {
89 90
90 hide_login_progress(gc, _("Write error")); 91 gaim_connection_error(gc, _("Write error"));
91 signoff(gc); 92 return;
92 } 93 }
93 } 94 }
94 95
95 static void 96 static void
96 msn_set_home_phone_cb(struct gaim_connection *gc, const char *entry) 97 msn_set_home_phone_cb(GaimConnection *gc, const char *entry)
97 { 98 {
98 msn_set_prp(gc, "PHH", entry); 99 msn_set_prp(gc, "PHH", entry);
99 } 100 }
100 101
101 static void 102 static void
102 msn_set_work_phone_cb(struct gaim_connection *gc, const char *entry) 103 msn_set_work_phone_cb(GaimConnection *gc, const char *entry)
103 { 104 {
104 msn_set_prp(gc, "PHW", entry); 105 msn_set_prp(gc, "PHW", entry);
105 } 106 }
106 107
107 static void 108 static void
108 msn_set_mobile_phone_cb(struct gaim_connection *gc, const char *entry) 109 msn_set_mobile_phone_cb(GaimConnection *gc, const char *entry)
109 { 110 {
110 msn_set_prp(gc, "PHM", entry); 111 msn_set_prp(gc, "PHM", entry);
111 } 112 }
112 113
113 static void 114 static void
114 __enable_msn_pages_cb(struct gaim_connection *gc) 115 __enable_msn_pages_cb(GaimConnection *gc)
115 { 116 {
116 msn_set_prp(gc, "MOB", "Y"); 117 msn_set_prp(gc, "MOB", "Y");
117 } 118 }
118 119
119 static void 120 static void
120 __disable_msn_pages_cb(struct gaim_connection *gc) 121 __disable_msn_pages_cb(GaimConnection *gc)
121 { 122 {
122 msn_set_prp(gc, "MOB", "N"); 123 msn_set_prp(gc, "MOB", "N");
123 } 124 }
124 125
125 static void 126 static void
143 msn_user_destroy(user); 144 msn_user_destroy(user);
144 msn_page_destroy(page); 145 msn_page_destroy(page);
145 146
146 if (!msn_servconn_write(servconn, page_str, strlen(page_str))) { 147 if (!msn_servconn_write(servconn, page_str, strlen(page_str))) {
147 148
148 hide_login_progress(data->gc, _("Write error")); 149 gaim_connection_error(data->gc, _("Write error"));
149 signoff(data->gc);
150 } 150 }
151 151
152 g_free(page_str); 152 g_free(page_str);
153 } 153 }
154 154
159 } 159 }
160 160
161 /* -- */ 161 /* -- */
162 162
163 static void 163 static void
164 msn_show_set_friendly_name(struct gaim_connection *gc) 164 msn_show_set_friendly_name(GaimConnection *gc)
165 { 165 {
166 gaim_request_input(gc, NULL, _("Set your friendly name."), 166 gaim_request_input(gc, NULL, _("Set your friendly name."),
167 _("This is the name that other MSN buddies will " 167 _("This is the name that other MSN buddies will "
168 "see you as."), 168 "see you as."),
169 gc->displayname, FALSE, 169 gaim_connection_get_display_name(gc), FALSE,
170 _("OK"), G_CALLBACK(msn_act_id), 170 _("OK"), G_CALLBACK(msn_act_id),
171 _("Cancel"), NULL, gc); 171 _("Cancel"), NULL, gc);
172 } 172 }
173 173
174 static void 174 static void
175 msn_show_set_home_phone(struct gaim_connection *gc) 175 msn_show_set_home_phone(GaimConnection *gc)
176 { 176 {
177 MsnSession *session = gc->proto_data; 177 MsnSession *session = gc->proto_data;
178 178
179 gaim_request_input(gc, NULL, _("Set your home phone number."), NULL, 179 gaim_request_input(gc, NULL, _("Set your home phone number."), NULL,
180 msn_user_get_home_phone(session->user), FALSE, 180 msn_user_get_home_phone(session->user), FALSE,
181 _("OK"), G_CALLBACK(msn_set_home_phone_cb), 181 _("OK"), G_CALLBACK(msn_set_home_phone_cb),
182 _("Cancel"), NULL, gc); 182 _("Cancel"), NULL, gc);
183 } 183 }
184 184
185 static void 185 static void
186 msn_show_set_work_phone(struct gaim_connection *gc) 186 msn_show_set_work_phone(GaimConnection *gc)
187 { 187 {
188 MsnSession *session = gc->proto_data; 188 MsnSession *session = gc->proto_data;
189 189
190 gaim_request_input(gc, NULL, _("Set your work phone number."), NULL, 190 gaim_request_input(gc, NULL, _("Set your work phone number."), NULL,
191 msn_user_get_work_phone(session->user), FALSE, 191 msn_user_get_work_phone(session->user), FALSE,
192 _("OK"), G_CALLBACK(msn_set_work_phone_cb), 192 _("OK"), G_CALLBACK(msn_set_work_phone_cb),
193 _("Cancel"), NULL, gc); 193 _("Cancel"), NULL, gc);
194 } 194 }
195 195
196 static void 196 static void
197 msn_show_set_mobile_phone(struct gaim_connection *gc) 197 msn_show_set_mobile_phone(GaimConnection *gc)
198 { 198 {
199 MsnSession *session = gc->proto_data; 199 MsnSession *session = gc->proto_data;
200 200
201 gaim_request_input(gc, NULL, _("Set your mobile phone number."), NULL, 201 gaim_request_input(gc, NULL, _("Set your mobile phone number."), NULL,
202 msn_user_get_mobile_phone(session->user), FALSE, 202 msn_user_get_mobile_phone(session->user), FALSE,
203 _("OK"), G_CALLBACK(msn_set_mobile_phone_cb), 203 _("OK"), G_CALLBACK(msn_set_mobile_phone_cb),
204 _("Cancel"), NULL, gc); 204 _("Cancel"), NULL, gc);
205 } 205 }
206 206
207 static void 207 static void
208 msn_show_set_mobile_pages(struct gaim_connection *gc) 208 msn_show_set_mobile_pages(GaimConnection *gc)
209 { 209 {
210 gaim_request_action(gc, NULL, _("Allow MSN Mobile pages?"), 210 gaim_request_action(gc, NULL, _("Allow MSN Mobile pages?"),
211 _("Do you want to allow or disallow people on " 211 _("Do you want to allow or disallow people on "
212 "your buddy list to send you MSN Mobile pages " 212 "your buddy list to send you MSN Mobile pages "
213 "to your cell phone or other mobile device?"), 213 "to your cell phone or other mobile device?"),
216 _("Disallow"), G_CALLBACK(__disable_msn_pages_cb), 216 _("Disallow"), G_CALLBACK(__disable_msn_pages_cb),
217 _("Cancel"), NULL); 217 _("Cancel"), NULL);
218 } 218 }
219 219
220 static void 220 static void
221 __show_send_to_mobile_cb(struct gaim_connection *gc, const char *passport) 221 __show_send_to_mobile_cb(GaimConnection *gc, const char *passport)
222 { 222 {
223 MsnUser *user; 223 MsnUser *user;
224 MsnSession *session = gc->proto_data; 224 MsnSession *session = gc->proto_data;
225 MsnMobileData *data; 225 MsnMobileData *data;
226 226
241 /************************************************************************** 241 /**************************************************************************
242 * Protocol Plugin ops 242 * Protocol Plugin ops
243 **************************************************************************/ 243 **************************************************************************/
244 244
245 static const char * 245 static const char *
246 msn_list_icon(struct gaim_account *a, struct buddy *b) 246 msn_list_icon(GaimAccount *a, struct buddy *b)
247 { 247 {
248 return "msn"; 248 return "msn";
249 } 249 }
250 250
251 static void 251 static void
302 302
303 return text; 303 return text;
304 } 304 }
305 305
306 static GList * 306 static GList *
307 msn_away_states(struct gaim_connection *gc) 307 msn_away_states(GaimConnection *gc)
308 { 308 {
309 GList *m = NULL; 309 GList *m = NULL;
310 310
311 m = g_list_append(m, _("Available")); 311 m = g_list_append(m, _("Available"));
312 m = g_list_append(m, _("Away From Computer")); 312 m = g_list_append(m, _("Away From Computer"));
318 318
319 return m; 319 return m;
320 } 320 }
321 321
322 static GList * 322 static GList *
323 msn_actions(struct gaim_connection *gc) 323 msn_actions(GaimConnection *gc)
324 { 324 {
325 GList *m = NULL; 325 GList *m = NULL;
326 struct proto_actions_menu *pam; 326 struct proto_actions_menu *pam;
327 327
328 pam = g_new0(struct proto_actions_menu, 1); 328 pam = g_new0(struct proto_actions_menu, 1);
369 369
370 return m; 370 return m;
371 } 371 }
372 372
373 static GList * 373 static GList *
374 msn_buddy_menu(struct gaim_connection *gc, const char *who) 374 msn_buddy_menu(GaimConnection *gc, const char *who)
375 { 375 {
376 MsnUser *user; 376 MsnUser *user;
377 struct proto_buddy_menu *pbm; 377 struct proto_buddy_menu *pbm;
378 struct buddy *b; 378 struct buddy *b;
379 GList *m = NULL; 379 GList *m = NULL;
393 393
394 return m; 394 return m;
395 } 395 }
396 396
397 static void 397 static void
398 msn_login(struct gaim_account *account) 398 msn_login(GaimAccount *account)
399 { 399 {
400 struct gaim_connection *gc; 400 GaimConnection *gc;
401 MsnSession *session; 401 MsnSession *session;
402 const char *username;
402 const char *server; 403 const char *server;
403 int port; 404 int port;
404 405
405 server = (*account->proto_opt[USEROPT_MSNSERVER] 406 server = gaim_account_get_string(account, "server", MSN_SERVER);
406 ? account->proto_opt[USEROPT_MSNSERVER] 407 port = gaim_account_get_int(account, "port", MSN_PORT);
407 : MSN_SERVER); 408
408 port = (*account->proto_opt[USEROPT_MSNPORT] 409 gc = gaim_account_get_connection(account);
409 ? atoi(account->proto_opt[USEROPT_MSNPORT])
410 : MSN_PORT);
411
412
413 gc = new_gaim_conn(account);
414 410
415 session = msn_session_new(account, server, port); 411 session = msn_session_new(account, server, port);
416 session->prpl = my_protocol; 412 session->prpl = my_protocol;
417 413
418 gc->proto_data = session; 414 gc->proto_data = session;
419 415
420 set_login_progress(gc, 1, _("Connecting")); 416 gaim_connection_update_progress(gc, _("Connecting"), 0, MSN_CONNECT_STEPS);
421 417
422 g_snprintf(gc->username, sizeof(gc->username), "%s", 418 /* Hmm, I don't like this. */
423 msn_normalize(gc->username)); 419 username = msn_normalize(gaim_account_get_username(account));
420
421 if (strcmp(username, gaim_account_get_username(account)))
422 gaim_account_set_username(account, username);
424 423
425 if (!msn_session_connect(session)) { 424 if (!msn_session_connect(session)) {
426 hide_login_progress(gc, _("Unable to connect")); 425 gaim_connection_error(gc, _("Unable to connect"));
427 signoff(gc); 426
428 } 427 return;
429 } 428 }
430 429 }
431 static void 430
432 msn_close(struct gaim_connection *gc) 431 static void
432 msn_close(GaimConnection *gc)
433 { 433 {
434 MsnSession *session = gc->proto_data; 434 MsnSession *session = gc->proto_data;
435 435
436 msn_session_destroy(session); 436 msn_session_destroy(session);
437 437
438 gc->proto_data = NULL; 438 gc->proto_data = NULL;
439 } 439 }
440 440
441 static int 441 static int
442 msn_send_im(struct gaim_connection *gc, const char *who, const char *message, 442 msn_send_im(GaimConnection *gc, const char *who, const char *message,
443 int len, int flags) 443 int len, int flags)
444 { 444 {
445 GaimAccount *account = gaim_connection_get_account(gc);
445 MsnSession *session = gc->proto_data; 446 MsnSession *session = gc->proto_data;
446 MsnSwitchBoard *swboard; 447 MsnSwitchBoard *swboard;
447 448
448 swboard = msn_session_find_switch_with_passport(session, who); 449 swboard = msn_session_find_switch_with_passport(session, who);
449 450
450 if (g_ascii_strcasecmp(who, gc->username)) { 451 if (g_ascii_strcasecmp(who, gaim_account_get_username(account))) {
451 MsnMessage *msg; 452 MsnMessage *msg;
452 MsnUser *user; 453 MsnUser *user;
453 454
454 user = msn_user_new(session, who, NULL); 455 user = msn_user_new(session, who, NULL);
455 456
465 } 466 }
466 else { 467 else {
467 if ((swboard = msn_session_open_switchboard(session)) == NULL) { 468 if ((swboard = msn_session_open_switchboard(session)) == NULL) {
468 msn_message_destroy(msg); 469 msn_message_destroy(msg);
469 470
470 hide_login_progress(gc, _("Write error")); 471 gaim_connection_error(gc, _("Write error"));
471 signoff(gc);
472 472
473 return 1; 473 return 1;
474 } 474 }
475 475
476 msn_switchboard_set_user(swboard, user); 476 msn_switchboard_set_user(swboard, user);
492 492
493 return 1; 493 return 1;
494 } 494 }
495 495
496 static int 496 static int
497 msn_send_typing(struct gaim_connection *gc, char *who, int typing) 497 msn_send_typing(GaimConnection *gc, char *who, int typing)
498 { 498 {
499 GaimAccount *account = gaim_connection_get_account(gc);
499 MsnSession *session = gc->proto_data; 500 MsnSession *session = gc->proto_data;
500 MsnSwitchBoard *swboard; 501 MsnSwitchBoard *swboard;
501 MsnMessage *msg; 502 MsnMessage *msg;
502 MsnUser *user; 503 MsnUser *user;
503 504
504 if (!typing) 505 if (!typing)
505 return 0; 506 return 0;
506 507
507 if (!g_ascii_strcasecmp(who, gc->username)) { 508 if (!g_ascii_strcasecmp(who, gaim_account_get_username(account))) {
508 /* We'll just fake it, since we're sending to ourself. */ 509 /* We'll just fake it, since we're sending to ourself. */
509 serv_got_typing(gc, who, MSN_TYPING_RECV_TIMEOUT, TYPING); 510 serv_got_typing(gc, who, MSN_TYPING_RECV_TIMEOUT, TYPING);
510 511
511 return MSN_TYPING_SEND_TIMEOUT; 512 return MSN_TYPING_SEND_TIMEOUT;
512 } 513 }
521 msg = msn_message_new(); 522 msg = msn_message_new();
522 msn_message_set_content_type(msg, "text/x-msmsgscontrol"); 523 msn_message_set_content_type(msg, "text/x-msmsgscontrol");
523 msn_message_set_receiver(msg, user); 524 msn_message_set_receiver(msg, user);
524 msn_message_set_charset(msg, NULL); 525 msn_message_set_charset(msg, NULL);
525 msn_message_set_flag(msg, 'U'); 526 msn_message_set_flag(msg, 'U');
526 msn_message_set_attr(msg, "TypingUser", gc->username); 527 msn_message_set_attr(msg, "TypingUser",
528 gaim_account_get_username(account));
527 msn_message_set_attr(msg, "User-Agent", NULL); 529 msn_message_set_attr(msg, "User-Agent", NULL);
528 msn_message_set_body(msg, "\r\n"); 530 msn_message_set_body(msg, "\r\n");
529 531
530 if (!msn_switchboard_send_msg(swboard, msg)) 532 if (!msn_switchboard_send_msg(swboard, msg))
531 msn_switchboard_destroy(swboard); 533 msn_switchboard_destroy(swboard);
534 536
535 return MSN_TYPING_SEND_TIMEOUT; 537 return MSN_TYPING_SEND_TIMEOUT;
536 } 538 }
537 539
538 static void 540 static void
539 msn_set_away(struct gaim_connection *gc, char *state, char *msg) 541 msn_set_away(GaimConnection *gc, char *state, char *msg)
540 { 542 {
541 MsnSession *session = gc->proto_data; 543 MsnSession *session = gc->proto_data;
542 const char *away; 544 const char *away;
543 545
544 if (gc->away != NULL) { 546 if (gc->away != NULL) {
575 away = "IDL"; 577 away = "IDL";
576 else 578 else
577 away = "NLN"; 579 away = "NLN";
578 580
579 if (!msn_servconn_send_command(session->notification_conn, "CHG", away)) { 581 if (!msn_servconn_send_command(session->notification_conn, "CHG", away)) {
580 hide_login_progress(gc, _("Write error")); 582 gaim_connection_error(gc, _("Write error"));
581 signoff(gc); 583 return;
582 } 584 }
583 } 585 }
584 586
585 static void 587 static void
586 msn_set_idle(struct gaim_connection *gc, int idle) 588 msn_set_idle(GaimConnection *gc, int idle)
587 { 589 {
588 MsnSession *session = gc->proto_data; 590 MsnSession *session = gc->proto_data;
589 591
590 if (gc->away != NULL) 592 if (gc->away != NULL)
591 return; 593 return;
592 594
593 if (!msn_servconn_send_command(session->notification_conn, "CHG", 595 if (!msn_servconn_send_command(session->notification_conn, "CHG",
594 (idle ? "IDL" : "NLN"))) { 596 (idle ? "IDL" : "NLN"))) {
595 597
596 hide_login_progress(gc, _("Write error")); 598 gaim_connection_error(gc, _("Write error"));
597 signoff(gc); 599 return;
598 } 600 }
599 } 601 }
600 602
601 static void 603 static void
602 msn_add_buddy(struct gaim_connection *gc, const char *name) 604 msn_add_buddy(GaimConnection *gc, const char *name)
603 { 605 {
604 MsnSession *session = gc->proto_data; 606 MsnSession *session = gc->proto_data;
605 char *who; 607 char *who;
606 char outparams[MSN_BUF_LEN]; 608 char outparams[MSN_BUF_LEN];
607 GSList *l; 609 GSList *l;
626 g_snprintf(outparams, sizeof(outparams), 628 g_snprintf(outparams, sizeof(outparams),
627 "FL %s %s", who, who); 629 "FL %s %s", who, who);
628 630
629 if (!msn_servconn_send_command(session->notification_conn, 631 if (!msn_servconn_send_command(session->notification_conn,
630 "ADD", outparams)) { 632 "ADD", outparams)) {
631 hide_login_progress(gc, _("Write error")); 633 gaim_connection_error(gc, _("Write error"));
632 signoff(gc); 634 return;
633 } 635 }
634 } 636 }
635 637
636 static void 638 static void
637 msn_rem_buddy(struct gaim_connection *gc, char *who, char *group) 639 msn_rem_buddy(GaimConnection *gc, char *who, char *group)
638 { 640 {
639 MsnSession *session = gc->proto_data; 641 MsnSession *session = gc->proto_data;
640 char outparams[MSN_BUF_LEN]; 642 char outparams[MSN_BUF_LEN];
641 643
642 g_snprintf(outparams, sizeof(outparams), "FL %s", who); 644 g_snprintf(outparams, sizeof(outparams), "FL %s", who);
643 645
644 if (!msn_servconn_send_command(session->notification_conn, 646 if (!msn_servconn_send_command(session->notification_conn,
645 "REM", outparams)) { 647 "REM", outparams)) {
646 648
647 hide_login_progress(gc, _("Write error")); 649 gaim_connection_error(gc, _("Write error"));
648 signoff(gc); 650 return;
649 } 651 }
650 } 652 }
651 653
652 static void 654 static void
653 msn_add_permit(struct gaim_connection *gc, const char *who) 655 msn_add_permit(GaimConnection *gc, const char *who)
654 { 656 {
655 MsnSession *session = gc->proto_data; 657 MsnSession *session = gc->proto_data;
656 char buf[MSN_BUF_LEN]; 658 char buf[MSN_BUF_LEN];
657 659
658 if (!strchr(who, '@')) { 660 if (!strchr(who, '@')) {
674 g_snprintf(buf, sizeof(buf), "BL %s", who); 676 g_snprintf(buf, sizeof(buf), "BL %s", who);
675 677
676 if (!msn_servconn_send_command(session->notification_conn, 678 if (!msn_servconn_send_command(session->notification_conn,
677 "REM", buf)) { 679 "REM", buf)) {
678 680
679 hide_login_progress(gc, _("Write error")); 681 gaim_connection_error(gc, _("Write error"));
680 signoff(gc);
681 return; 682 return;
682 } 683 }
683 } 684 }
684 685
685 g_snprintf(buf, sizeof(buf), "AL %s %s", who, who); 686 g_snprintf(buf, sizeof(buf), "AL %s %s", who, who);
686 687
687 if (!msn_servconn_send_command(session->notification_conn, "ADD", buf)) { 688 if (!msn_servconn_send_command(session->notification_conn, "ADD", buf)) {
688 hide_login_progress(gc, _("Write error")); 689 gaim_connection_error(gc, _("Write error"));
689 signoff(gc); 690 return;
690 } 691 }
691 } 692 }
692 693
693 static void 694 static void
694 msn_add_deny(struct gaim_connection *gc, const char *who) 695 msn_add_deny(GaimConnection *gc, const char *who)
695 { 696 {
696 MsnSession *session = gc->proto_data; 697 MsnSession *session = gc->proto_data;
697 char buf[MSN_BUF_LEN]; 698 char buf[MSN_BUF_LEN];
698 699
699 if (!strchr(who, '@')) { 700 if (!strchr(who, '@')) {
716 g_snprintf(buf, sizeof(buf), "AL %s", who); 717 g_snprintf(buf, sizeof(buf), "AL %s", who);
717 718
718 if (!msn_servconn_send_command(session->notification_conn, 719 if (!msn_servconn_send_command(session->notification_conn,
719 "REM", buf)) { 720 "REM", buf)) {
720 721
721 hide_login_progress(gc, _("Write error")); 722 gaim_connection_error(gc, _("Write error"));
722 signoff(gc);
723 return; 723 return;
724 } 724 }
725 } 725 }
726 726
727 g_snprintf(buf, sizeof(buf), "BL %s %s", who, who); 727 g_snprintf(buf, sizeof(buf), "BL %s %s", who, who);
728 728
729 if (!msn_servconn_send_command(session->notification_conn, "ADD", buf)) { 729 if (!msn_servconn_send_command(session->notification_conn, "ADD", buf)) {
730 hide_login_progress(gc, _("Write error")); 730 gaim_connection_error(gc, _("Write error"));
731 signoff(gc); 731 return;
732 return; 732 }
733 } 733 }
734 } 734
735 735 static void
736 static void 736 msn_rem_permit(GaimConnection *gc, const char *who)
737 msn_rem_permit(struct gaim_connection *gc, const char *who)
738 { 737 {
739 MsnSession *session = gc->proto_data; 738 MsnSession *session = gc->proto_data;
740 char buf[MSN_BUF_LEN]; 739 char buf[MSN_BUF_LEN];
741 740
742 g_snprintf(buf, sizeof(buf), "AL %s", who); 741 g_snprintf(buf, sizeof(buf), "AL %s", who);
743 742
744 if (!msn_servconn_send_command(session->notification_conn, "REM", buf)) { 743 if (!msn_servconn_send_command(session->notification_conn, "REM", buf)) {
745 hide_login_progress(gc, _("Write error")); 744 gaim_connection_error(gc, _("Write error"));
746 signoff(gc);
747 return; 745 return;
748 } 746 }
749 747
750 gaim_privacy_deny_add(gc->account, who); 748 gaim_privacy_deny_add(gc->account, who);
751 749
752 g_snprintf(buf, sizeof(buf), "BL %s %s", who, who); 750 g_snprintf(buf, sizeof(buf), "BL %s %s", who, who);
753 751
754 if (!msn_servconn_send_command(session->notification_conn, "ADD", buf)) { 752 if (!msn_servconn_send_command(session->notification_conn, "ADD", buf)) {
755 hide_login_progress(gc, _("Write error")); 753 gaim_connection_error(gc, _("Write error"));
756 signoff(gc); 754 return;
757 return; 755 }
758 } 756 }
759 } 757
760 758 static void
761 static void 759 msn_rem_deny(GaimConnection *gc, const char *who)
762 msn_rem_deny(struct gaim_connection *gc, const char *who)
763 { 760 {
764 MsnSession *session = gc->proto_data; 761 MsnSession *session = gc->proto_data;
765 char buf[MSN_BUF_LEN]; 762 char buf[MSN_BUF_LEN];
766 763
767 g_snprintf(buf, sizeof(buf), "BL %s", who); 764 g_snprintf(buf, sizeof(buf), "BL %s", who);
768 765
769 if (!msn_servconn_send_command(session->notification_conn, "REM", buf)) { 766 if (!msn_servconn_send_command(session->notification_conn, "REM", buf)) {
770 hide_login_progress(gc, _("Write error")); 767 gaim_connection_error(gc, _("Write error"));
771 signoff(gc);
772 return; 768 return;
773 } 769 }
774 770
775 gaim_privacy_permit_add(gc->account, who); 771 gaim_privacy_permit_add(gc->account, who);
776 772
777 g_snprintf(buf, sizeof(buf), "AL %s %s", who, who); 773 g_snprintf(buf, sizeof(buf), "AL %s %s", who, who);
778 774
779 if (!msn_servconn_send_command(session->notification_conn, "ADD", buf)) { 775 if (!msn_servconn_send_command(session->notification_conn, "ADD", buf)) {
780 hide_login_progress(gc, _("Write error")); 776 gaim_connection_error(gc, _("Write error"));
781 signoff(gc); 777 return;
782 return; 778 }
783 } 779 }
784 } 780
785 781 static void
786 static void 782 msn_set_permit_deny(GaimConnection *gc)
787 msn_set_permit_deny(struct gaim_connection *gc) 783 {
788 { 784 GaimAccount *account = gaim_connection_get_account(gc);
789 MsnSession *session = gc->proto_data; 785 MsnSession *session = gc->proto_data;
790 char buf[MSN_BUF_LEN]; 786 char buf[MSN_BUF_LEN];
791 GSList *s, *t = NULL; 787 GSList *s, *t = NULL;
792 788
793 if (gc->account->permdeny == PERMIT_ALL || 789 if (account->perm_deny == PERMIT_ALL ||
794 gc->account->permdeny == DENY_SOME) { 790 account->perm_deny == DENY_SOME) {
795 791
796 strcpy(buf, "AL"); 792 strcpy(buf, "AL");
797 } 793 }
798 else 794 else
799 strcpy(buf, "BL"); 795 strcpy(buf, "BL");
800 796
801 if (!msn_servconn_send_command(session->notification_conn, "BLP", buf)) { 797 if (!msn_servconn_send_command(session->notification_conn, "BLP", buf)) {
802 hide_login_progress(gc, _("Write error")); 798 gaim_connection_error(gc, _("Write error"));
803 signoff(gc);
804 return; 799 return;
805 } 800 }
806 801
807 /* 802 /*
808 * This is safe because we'll always come here after we've gotten 803 * This is safe because we'll always come here after we've gotten
848 843
849 g_snprintf(buf, sizeof(buf), "AL %s %s", who, who); 844 g_snprintf(buf, sizeof(buf), "AL %s %s", who, who);
850 845
851 if (!msn_servconn_send_command(session->notification_conn, 846 if (!msn_servconn_send_command(session->notification_conn,
852 "ADD", buf)) { 847 "ADD", buf)) {
853 hide_login_progress(gc, _("Write error")); 848 gaim_connection_error(gc, _("Write error"));
854 signoff(gc);
855 return; 849 return;
856 } 850 }
857 } 851 }
858 852
859 for (; t != NULL; t = t->next) 853 for (; t != NULL; t = t->next)
887 881
888 g_snprintf(buf, sizeof(buf), "BL %s %s", who, who); 882 g_snprintf(buf, sizeof(buf), "BL %s %s", who, who);
889 883
890 if (!msn_servconn_send_command(session->notification_conn, 884 if (!msn_servconn_send_command(session->notification_conn,
891 "ADD", buf)) { 885 "ADD", buf)) {
892 hide_login_progress(gc, _("Write error")); 886 gaim_connection_error(gc, _("Write error"));
893 signoff(gc);
894 return; 887 return;
895 } 888 }
896 } 889 }
897 890
898 for (; t != NULL; t = t->next) 891 for (; t != NULL; t = t->next)
905 session->lists.block = NULL; 898 session->lists.block = NULL;
906 } 899 }
907 } 900 }
908 901
909 static void 902 static void
910 msn_chat_invite(struct gaim_connection *gc, int id, const char *msg, 903 msn_chat_invite(GaimConnection *gc, int id, const char *msg,
911 const char *who) 904 const char *who)
912 { 905 {
913 MsnSession *session = gc->proto_data; 906 MsnSession *session = gc->proto_data;
914 MsnSwitchBoard *swboard = msn_session_find_switch_with_id(session, id); 907 MsnSwitchBoard *swboard = msn_session_find_switch_with_id(session, id);
915 908
919 if (!msn_switchboard_send_command(swboard, "CAL", who)) 912 if (!msn_switchboard_send_command(swboard, "CAL", who))
920 msn_switchboard_destroy(swboard); 913 msn_switchboard_destroy(swboard);
921 } 914 }
922 915
923 static void 916 static void
924 msn_chat_leave(struct gaim_connection *gc, int id) 917 msn_chat_leave(GaimConnection *gc, int id)
925 { 918 {
926 MsnSession *session = gc->proto_data; 919 MsnSession *session = gc->proto_data;
927 MsnSwitchBoard *swboard = msn_session_find_switch_with_id(session, id); 920 MsnSwitchBoard *swboard = msn_session_find_switch_with_id(session, id);
928 char buf[6]; 921 char buf[6];
929 922
935 if (!msn_servconn_write(swboard->servconn, buf, strlen(buf))) 928 if (!msn_servconn_write(swboard->servconn, buf, strlen(buf)))
936 msn_switchboard_destroy(swboard); 929 msn_switchboard_destroy(swboard);
937 } 930 }
938 931
939 static int 932 static int
940 msn_chat_send(struct gaim_connection *gc, int id, char *message) 933 msn_chat_send(GaimConnection *gc, int id, char *message)
941 { 934 {
935 GaimAccount *account = gaim_connection_get_account(gc);
942 MsnSession *session = gc->proto_data; 936 MsnSession *session = gc->proto_data;
943 MsnSwitchBoard *swboard = msn_session_find_switch_with_id(session, id); 937 MsnSwitchBoard *swboard = msn_session_find_switch_with_id(session, id);
944 MsnMessage *msg; 938 MsnMessage *msg;
945 char *send; 939 char *send;
946 940
963 return 0; 957 return 0;
964 } 958 }
965 959
966 msn_message_destroy(msg); 960 msn_message_destroy(msg);
967 961
968 serv_got_chat_in(gc, id, gc->username, 0, message, time(NULL)); 962 serv_got_chat_in(gc, id, (char *)gaim_account_get_username(account),
963 0, message, time(NULL));
969 964
970 return 0; 965 return 0;
971 } 966 }
972 967
973 static void 968 static void
974 msn_keepalive(struct gaim_connection *gc) 969 msn_keepalive(GaimConnection *gc)
975 { 970 {
976 MsnSession *session = gc->proto_data; 971 MsnSession *session = gc->proto_data;
977 char buf[MSN_BUF_LEN]; 972 char buf[MSN_BUF_LEN];
978 973
979 g_snprintf(buf, sizeof(buf), "PNG\r\n"); 974 g_snprintf(buf, sizeof(buf), "PNG\r\n");
980 975
981 if (msn_servconn_write(session->notification_conn, 976 if (msn_servconn_write(session->notification_conn,
982 buf, strlen(buf)) < 0) { 977 buf, strlen(buf)) < 0) {
983 978
984 hide_login_progress(gc, _("Write error")); 979 gaim_connection_error(gc, _("Write error"));
985 signoff(gc); 980 return;
986 return; 981 }
987 } 982 }
988 } 983
989 984 static void
990 static void 985 msn_group_buddy(GaimConnection *gc, const char *who,
991 msn_group_buddy(struct gaim_connection *gc, const char *who,
992 const char *old_group_name, const char *new_group_name) 986 const char *old_group_name, const char *new_group_name)
993 { 987 {
994 MsnSession *session = gc->proto_data; 988 MsnSession *session = gc->proto_data;
995 char outparams[MSN_BUF_LEN]; 989 char outparams[MSN_BUF_LEN];
996 MsnGroup *old_group, *new_group; 990 MsnGroup *old_group, *new_group;
1004 g_snprintf(outparams, sizeof(outparams), "%s 0", 998 g_snprintf(outparams, sizeof(outparams), "%s 0",
1005 msn_url_encode(new_group_name)); 999 msn_url_encode(new_group_name));
1006 1000
1007 if (!msn_servconn_send_command(session->notification_conn, 1001 if (!msn_servconn_send_command(session->notification_conn,
1008 "ADG", outparams)) { 1002 "ADG", outparams)) {
1009 hide_login_progress(gc, _("Write error")); 1003 gaim_connection_error(gc, _("Write error"));
1010 signoff(gc);
1011 return; 1004 return;
1012 } 1005 }
1013 1006
1014 /* I hate this. So much. */ 1007 /* I hate this. So much. */
1015 session->moving_buddy = TRUE; 1008 session->moving_buddy = TRUE;
1025 g_snprintf(outparams, sizeof(outparams), "FL %s %s %d", 1018 g_snprintf(outparams, sizeof(outparams), "FL %s %s %d",
1026 who, who, msn_group_get_id(new_group)); 1019 who, who, msn_group_get_id(new_group));
1027 1020
1028 if (!msn_servconn_send_command(session->notification_conn, 1021 if (!msn_servconn_send_command(session->notification_conn,
1029 "ADD", outparams)) { 1022 "ADD", outparams)) {
1030 hide_login_progress(gc, _("Write error")); 1023 gaim_connection_error(gc, _("Write error"));
1031 signoff(gc);
1032 return; 1024 return;
1033 } 1025 }
1034 } 1026 }
1035 1027
1036 if (old_group != NULL) { 1028 if (old_group != NULL) {
1037 g_snprintf(outparams, sizeof(outparams), "FL %s %d", 1029 g_snprintf(outparams, sizeof(outparams), "FL %s %d",
1038 who, msn_group_get_id(old_group)); 1030 who, msn_group_get_id(old_group));
1039 1031
1040 if (!msn_servconn_send_command(session->notification_conn, 1032 if (!msn_servconn_send_command(session->notification_conn,
1041 "REM", outparams)) { 1033 "REM", outparams)) {
1042 hide_login_progress(gc, _("Write error")); 1034 gaim_connection_error(gc, _("Write error"));
1043 signoff(gc);
1044 return; 1035 return;
1045 } 1036 }
1046 1037
1047 if (msn_users_get_count(msn_group_get_users(old_group)) <= 0) { 1038 if (msn_users_get_count(msn_group_get_users(old_group)) <= 0) {
1048 g_snprintf(outparams, sizeof(outparams), "%d", 1039 g_snprintf(outparams, sizeof(outparams), "%d",
1049 msn_group_get_id(old_group)); 1040 msn_group_get_id(old_group));
1050 1041
1051 if (!msn_servconn_send_command(session->notification_conn, 1042 if (!msn_servconn_send_command(session->notification_conn,
1052 "RMG", outparams)) { 1043 "RMG", outparams)) {
1053 1044
1054 hide_login_progress(gc, _("Write error")); 1045 gaim_connection_error(gc, _("Write error"));
1055 signoff(gc);
1056 return; 1046 return;
1057 } 1047 }
1058 } 1048 }
1059 } 1049 }
1060 } 1050 }
1061 1051
1062 static void 1052 static void
1063 msn_rename_group(struct gaim_connection *gc, const char *old_group_name, 1053 msn_rename_group(GaimConnection *gc, const char *old_group_name,
1064 const char *new_group_name, GList *members) 1054 const char *new_group_name, GList *members)
1065 { 1055 {
1066 MsnSession *session = gc->proto_data; 1056 MsnSession *session = gc->proto_data;
1067 char outparams[MSN_BUF_LEN]; 1057 char outparams[MSN_BUF_LEN];
1068 MsnGroup *old_group; 1058 MsnGroup *old_group;
1074 msn_group_get_id(old_group), 1064 msn_group_get_id(old_group),
1075 msn_url_encode(new_group_name)); 1065 msn_url_encode(new_group_name));
1076 1066
1077 if (!msn_servconn_send_command(session->notification_conn, 1067 if (!msn_servconn_send_command(session->notification_conn,
1078 "REG", outparams)) { 1068 "REG", outparams)) {
1079 hide_login_progress(gc, _("Write error")); 1069 gaim_connection_error(gc, _("Write error"));
1080 signoff(gc);
1081 return; 1070 return;
1082 } 1071 }
1083 1072
1084 msn_group_set_name(old_group, new_group_name); 1073 msn_group_set_name(old_group, new_group_name);
1085 } 1074 }
1087 g_snprintf(outparams, sizeof(outparams), "%s 0", 1076 g_snprintf(outparams, sizeof(outparams), "%s 0",
1088 msn_url_encode(new_group_name)); 1077 msn_url_encode(new_group_name));
1089 1078
1090 if (!msn_servconn_send_command(session->notification_conn, 1079 if (!msn_servconn_send_command(session->notification_conn,
1091 "ADG", outparams)) { 1080 "ADG", outparams)) {
1092 hide_login_progress(gc, _("Write error")); 1081 gaim_connection_error(gc, _("Write error"));
1093 signoff(gc);
1094 return; 1082 return;
1095 } 1083 }
1096 } 1084 }
1097 } 1085 }
1098 1086
1104 b->proto_data = NULL; 1092 b->proto_data = NULL;
1105 } 1093 }
1106 } 1094 }
1107 1095
1108 static void 1096 static void
1109 msn_convo_closed(struct gaim_connection *gc, char *who) 1097 msn_convo_closed(GaimConnection *gc, char *who)
1110 { 1098 {
1099 GaimAccount *account = gaim_connection_get_account(gc);
1111 MsnSession *session = gc->proto_data; 1100 MsnSession *session = gc->proto_data;
1112 MsnSwitchBoard *swboard; 1101 MsnSwitchBoard *swboard;
1113 1102
1114 swboard = msn_session_find_switch_with_passport(session, who); 1103 swboard = msn_session_find_switch_with_passport(session, who);
1115 1104
1116 if (swboard != NULL) { 1105 if (swboard != NULL) {
1117 char sendbuf[256]; 1106 char sendbuf[256];
1118 1107
1119 g_snprintf(sendbuf, sizeof(sendbuf), "BYE %s\r\n", gc->username); 1108 g_snprintf(sendbuf, sizeof(sendbuf), "BYE %s\r\n",
1109 gaim_account_get_username(account));
1120 1110
1121 msn_servconn_write(swboard->servconn, sendbuf, strlen(sendbuf)); 1111 msn_servconn_write(swboard->servconn, sendbuf, strlen(sendbuf));
1122 1112
1123 msn_switchboard_destroy(swboard); 1113 msn_switchboard_destroy(swboard);
1124 } 1114 }