Mercurial > pidgin.yaz
comparison src/protocols/msn/switchboard.c @ 10463:9bed28273ec7
[gaim-migrate @ 11737]
Felipe Contreras fixed the MSN HTTP Method. Yay! Thanks Felipe.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Fri, 31 Dec 2004 16:34:22 +0000 |
parents | 92d4a25fd33c |
children | bcfea6c3d5c9 |
comparison
equal
deleted
inserted
replaced
10462:f7b32dd67bdf | 10463:9bed28273ec7 |
---|---|
40 MsnSwitchBoard * | 40 MsnSwitchBoard * |
41 msn_switchboard_new(MsnSession *session) | 41 msn_switchboard_new(MsnSession *session) |
42 { | 42 { |
43 MsnSwitchBoard *swboard; | 43 MsnSwitchBoard *swboard; |
44 MsnServConn *servconn; | 44 MsnServConn *servconn; |
45 MsnCmdProc *cmdproc; | |
46 | 45 |
47 g_return_val_if_fail(session != NULL, NULL); | 46 g_return_val_if_fail(session != NULL, NULL); |
48 | 47 |
49 swboard = g_new0(MsnSwitchBoard, 1); | 48 swboard = g_new0(MsnSwitchBoard, 1); |
50 | 49 |
51 swboard->session = session; | 50 swboard->session = session; |
52 swboard->servconn = servconn = msn_servconn_new(session, MSN_SERVER_SB); | 51 swboard->servconn = servconn = msn_servconn_new(session, MSN_SERVER_SB); |
53 cmdproc = servconn->cmdproc; | 52 swboard->cmdproc = servconn->cmdproc; |
54 | 53 |
55 swboard->im_queue = g_queue_new(); | 54 swboard->im_queue = g_queue_new(); |
56 swboard->empty = TRUE; | 55 swboard->empty = TRUE; |
57 | 56 |
58 servconn->data = swboard; | 57 swboard->cmdproc->data = swboard; |
58 swboard->cmdproc->cbs_table = cbs_table; | |
59 | 59 |
60 session->switches = g_list_append(session->switches, swboard); | 60 session->switches = g_list_append(session->switches, swboard); |
61 | |
62 cmdproc->cbs_table = cbs_table; | |
63 | 61 |
64 return swboard; | 62 return swboard; |
65 } | 63 } |
66 | 64 |
67 void | 65 void |
86 while ((msg = g_queue_pop_head(swboard->im_queue)) != NULL) | 84 while ((msg = g_queue_pop_head(swboard->im_queue)) != NULL) |
87 { | 85 { |
88 if (swboard->error != MSN_SB_ERROR_NONE) | 86 if (swboard->error != MSN_SB_ERROR_NONE) |
89 { | 87 { |
90 /* The messages could not be sent due to a switchboard error */ | 88 /* The messages could not be sent due to a switchboard error */ |
91 msg_error_helper(swboard->servconn->cmdproc, msg, | 89 msg_error_helper(swboard->cmdproc, msg, |
92 MSN_MSG_ERROR_SB); | 90 MSN_MSG_ERROR_SB); |
93 } | 91 } |
94 msn_message_unref(msg); | 92 msn_message_unref(msg); |
95 } | 93 } |
96 | 94 |
197 MsnCmdProc *cmdproc; | 195 MsnCmdProc *cmdproc; |
198 GaimAccount *account; | 196 GaimAccount *account; |
199 | 197 |
200 g_return_if_fail(swboard != NULL); | 198 g_return_if_fail(swboard != NULL); |
201 | 199 |
202 cmdproc = swboard->servconn->cmdproc; | 200 cmdproc = swboard->cmdproc; |
203 account = swboard->servconn->session->account; | 201 account = cmdproc->session->account; |
204 | 202 |
205 swboard->users = g_list_prepend(swboard->users, g_strdup(user)); | 203 swboard->users = g_list_prepend(swboard->users, g_strdup(user)); |
206 swboard->current_users++; | 204 swboard->current_users++; |
207 swboard->empty = FALSE; | 205 swboard->empty = FALSE; |
208 | 206 |
311 gaim_debug_info("msg", "Error: Unable to call the user %s\n", passport); | 309 gaim_debug_info("msg", "Error: Unable to call the user %s\n", passport); |
312 | 310 |
313 if (swboard->total_users == 0) | 311 if (swboard->total_users == 0) |
314 { | 312 { |
315 swboard->error = reason; | 313 swboard->error = reason; |
316 msn_switchboard_destroy(swboard); | 314 msn_switchboard_close(swboard); |
317 } | 315 } |
318 } | 316 } |
319 | 317 |
320 static void | 318 static void |
321 cal_error_helper(MsnTransaction *trans, int reason) | 319 cal_error_helper(MsnTransaction *trans, int reason) |
344 g_return_if_fail(msg != NULL); | 342 g_return_if_fail(msg != NULL); |
345 | 343 |
346 if ((error != MSN_MSG_ERROR_SB) && (msg->nak_cb != NULL)) | 344 if ((error != MSN_MSG_ERROR_SB) && (msg->nak_cb != NULL)) |
347 msg->nak_cb(msg, msg->ack_data); | 345 msg->nak_cb(msg, msg->ack_data); |
348 | 346 |
349 swboard = cmdproc->servconn->data; | 347 swboard = cmdproc->data; |
350 | 348 |
351 if (msg->type == MSN_MSG_TEXT) | 349 if (msg->type == MSN_MSG_TEXT) |
352 { | 350 { |
353 const char *format; | 351 const char *format; |
354 char *body_str, *body_enc, *pre, *post; | 352 char *body_str, *body_enc, *pre, *post; |
432 static void | 430 static void |
433 ans_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | 431 ans_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) |
434 { | 432 { |
435 MsnSwitchBoard *swboard; | 433 MsnSwitchBoard *swboard; |
436 | 434 |
437 swboard = cmdproc->servconn->data; | 435 swboard = cmdproc->data; |
438 swboard->ready = TRUE; | 436 swboard->ready = TRUE; |
439 } | 437 } |
440 | 438 |
441 static void | 439 static void |
442 bye_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | 440 bye_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) |
443 { | 441 { |
444 MsnSwitchBoard *swboard; | 442 MsnSwitchBoard *swboard; |
445 const char *user; | 443 const char *user; |
446 | 444 |
447 swboard = cmdproc->servconn->data; | 445 swboard = cmdproc->data; |
448 user = cmd->params[0]; | 446 user = cmd->params[0]; |
449 | 447 |
450 if (swboard->conv == NULL) | 448 if (swboard->conv == NULL) |
451 { | 449 { |
452 /* This is a helper switchboard */ | 450 /* This is a helper switchboard */ |
507 GaimConnection *gc; | 505 GaimConnection *gc; |
508 MsnSwitchBoard *swboard; | 506 MsnSwitchBoard *swboard; |
509 | 507 |
510 account = cmdproc->session->account; | 508 account = cmdproc->session->account; |
511 gc = account->gc; | 509 gc = account->gc; |
512 swboard = cmdproc->servconn->data; | 510 swboard = cmdproc->data; |
513 | 511 |
514 swboard->total_users = atoi(cmd->params[2]); | 512 swboard->total_users = atoi(cmd->params[2]); |
515 | 513 |
516 msn_switchboard_add_user(swboard, cmd->params[3]); | 514 msn_switchboard_add_user(swboard, cmd->params[3]); |
517 } | 515 } |
528 passport = cmd->params[0]; | 526 passport = cmd->params[0]; |
529 | 527 |
530 session = cmdproc->session; | 528 session = cmdproc->session; |
531 account = session->account; | 529 account = session->account; |
532 gc = account->gc; | 530 gc = account->gc; |
533 swboard = cmdproc->servconn->data; | 531 swboard = cmdproc->data; |
534 | 532 |
535 msn_switchboard_add_user(swboard, passport); | 533 msn_switchboard_add_user(swboard, passport); |
536 | 534 |
537 msn_switchboard_process_queue(swboard); | 535 msn_switchboard_process_queue(swboard); |
538 | 536 |
539 send_clientcaps(swboard); | 537 if (!session->http_method) |
538 send_clientcaps(swboard); | |
540 | 539 |
541 if (swboard->closed) | 540 if (swboard->closed) |
542 msn_switchboard_close(swboard); | 541 msn_switchboard_close(swboard); |
543 } | 542 } |
544 | 543 |
588 msg = cmd->trans->data; | 587 msg = cmd->trans->data; |
589 | 588 |
590 if (msg->ack_cb != NULL) | 589 if (msg->ack_cb != NULL) |
591 msg->ack_cb(msg, msg->ack_data); | 590 msg->ack_cb(msg, msg->ack_data); |
592 | 591 |
593 swboard = cmdproc->servconn->data; | 592 swboard = cmdproc->data; |
594 swboard->ack_list = g_list_remove(swboard->ack_list, msg); | 593 swboard->ack_list = g_list_remove(swboard->ack_list, msg); |
595 msn_message_unref(msg); | 594 msn_message_unref(msg); |
596 } | 595 } |
597 | 596 |
598 static void | 597 static void |
600 { | 599 { |
601 GaimConnection *gc; | 600 GaimConnection *gc; |
602 MsnSwitchBoard *swboard; | 601 MsnSwitchBoard *swboard; |
603 | 602 |
604 gc = cmdproc->session->account->gc; | 603 gc = cmdproc->session->account->gc; |
605 swboard = cmdproc->servconn->data; | 604 swboard = cmdproc->data; |
606 | 605 |
607 if (swboard->current_users > 1) | 606 if (swboard->current_users > 1) |
608 serv_got_chat_left(gc, swboard->chat_id); | 607 serv_got_chat_left(gc, swboard->chat_id); |
609 | 608 |
610 msn_switchboard_disconnect(swboard); | 609 msn_switchboard_disconnect(swboard); |
613 static void | 612 static void |
614 usr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | 613 usr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) |
615 { | 614 { |
616 MsnSwitchBoard *swboard; | 615 MsnSwitchBoard *swboard; |
617 | 616 |
618 swboard = cmdproc->servconn->data; | 617 swboard = cmdproc->data; |
619 | 618 |
620 #if 0 | 619 #if 0 |
621 GList *l; | 620 GList *l; |
622 | 621 |
623 for (l = swboard->users; l != NULL; l = l->next) | 622 for (l = swboard->users; l != NULL; l = l->next) |
648 size_t body_len; | 647 size_t body_len; |
649 const char *passport; | 648 const char *passport; |
650 const char *value; | 649 const char *value; |
651 | 650 |
652 gc = cmdproc->session->account->gc; | 651 gc = cmdproc->session->account->gc; |
653 swboard = cmdproc->servconn->data; | 652 swboard = cmdproc->data; |
654 | 653 |
655 body = msn_message_get_bin_data(msg, &body_len); | 654 body = msn_message_get_bin_data(msg, &body_len); |
656 body_str = g_strndup(body, body_len); | 655 body_str = g_strndup(body, body_len); |
657 body_enc = gaim_escape_html(body_str); | 656 body_enc = gaim_escape_html(body_str); |
658 g_free(body_str); | 657 g_free(body_str); |
707 MsnSwitchBoard *swboard; | 706 MsnSwitchBoard *swboard; |
708 const char *value; | 707 const char *value; |
709 char *passport; | 708 char *passport; |
710 | 709 |
711 gc = cmdproc->session->account->gc; | 710 gc = cmdproc->session->account->gc; |
712 swboard = cmdproc->servconn->data; | 711 swboard = cmdproc->data; |
713 passport = msg->remote_user; | 712 passport = msg->remote_user; |
714 | 713 |
715 if (swboard->current_users == 1 && | 714 if (swboard->current_users == 1 && |
716 (value = msn_message_get_attr(msg, "TypingUser")) != NULL) | 715 (value = msn_message_get_attr(msg, "TypingUser")) != NULL) |
717 { | 716 { |
796 gsize payload_len; | 795 gsize payload_len; |
797 | 796 |
798 g_return_if_fail(swboard != NULL); | 797 g_return_if_fail(swboard != NULL); |
799 g_return_if_fail(msg != NULL); | 798 g_return_if_fail(msg != NULL); |
800 | 799 |
801 cmdproc = swboard->servconn->cmdproc; | 800 cmdproc = swboard->cmdproc; |
802 | 801 |
803 payload = msn_message_gen_payload(msg, &payload_len); | 802 payload = msn_message_gen_payload(msg, &payload_len); |
804 | 803 |
805 /* msn_message_show_readable(msg, "SB SEND", FALSE); */ | 804 /* msn_message_show_readable(msg, "SB SEND", FALSE); */ |
806 | 805 |
883 cmdproc = servconn->cmdproc; | 882 cmdproc = servconn->cmdproc; |
884 g_return_if_fail(cmdproc != NULL); | 883 g_return_if_fail(cmdproc != NULL); |
885 | 884 |
886 cmdproc->ready = TRUE; | 885 cmdproc->ready = TRUE; |
887 | 886 |
888 account = servconn->session->account; | 887 account = cmdproc->session->account; |
889 swboard = servconn->data; | 888 swboard = cmdproc->data; |
890 g_return_if_fail(swboard != NULL); | 889 g_return_if_fail(swboard != NULL); |
891 | 890 |
892 if (msn_switchboard_is_invited(swboard)) | 891 if (msn_switchboard_is_invited(swboard)) |
893 { | 892 { |
894 swboard->empty = FALSE; | 893 swboard->empty = FALSE; |
908 static void | 907 static void |
909 disconnect_cb(MsnServConn *servconn) | 908 disconnect_cb(MsnServConn *servconn) |
910 { | 909 { |
911 MsnSwitchBoard *swboard; | 910 MsnSwitchBoard *swboard; |
912 | 911 |
913 swboard = servconn->data; | 912 swboard = servconn->cmdproc->data; |
914 g_return_if_fail(swboard != NULL); | 913 g_return_if_fail(swboard != NULL); |
915 | 914 |
916 msn_switchboard_destroy(swboard); | 915 msn_switchboard_destroy(swboard); |
917 } | 916 } |
918 | 917 |
943 { | 942 { |
944 #if 0 | 943 #if 0 |
945 MsnSwitchBoard *swboard; | 944 MsnSwitchBoard *swboard; |
946 const char *user; | 945 const char *user; |
947 | 946 |
948 swboard = cmdproc->servconn->data; | 947 swboard = cmdproc->data; |
949 | 948 |
950 user = cmd->params[0]; | 949 user = cmd->params[0]; |
951 | 950 |
952 msn_switchboard_add_user(swboard, user); | 951 msn_switchboard_add_user(swboard, user); |
953 #endif | 952 #endif |
983 MsnTransaction *trans; | 982 MsnTransaction *trans; |
984 MsnCmdProc *cmdproc; | 983 MsnCmdProc *cmdproc; |
985 | 984 |
986 g_return_if_fail(swboard != NULL); | 985 g_return_if_fail(swboard != NULL); |
987 | 986 |
988 cmdproc = swboard->servconn->cmdproc; | 987 cmdproc = swboard->cmdproc; |
989 | 988 |
990 trans = msn_transaction_new(cmdproc, "CAL", "%s", user); | 989 trans = msn_transaction_new(cmdproc, "CAL", "%s", user); |
991 /* this doesn't do anything, but users seem to think that | 990 /* this doesn't do anything, but users seem to think that |
992 * 'Unhandled command' is some kind of error, so we don't report it */ | 991 * 'Unhandled command' is some kind of error, so we don't report it */ |
993 msn_transaction_add_cb(trans, "CAL", got_cal); | 992 msn_transaction_add_cb(trans, "CAL", got_cal); |
1018 | 1017 |
1019 msn_switchboard_set_auth_key(swboard, cmd->params[4]); | 1018 msn_switchboard_set_auth_key(swboard, cmd->params[4]); |
1020 | 1019 |
1021 msn_parse_socket(cmd->params[2], &host, &port); | 1020 msn_parse_socket(cmd->params[2], &host, &port); |
1022 | 1021 |
1023 if (swboard->session->http_method) | |
1024 { | |
1025 GaimAccount *account; | |
1026 MsnSession *session; | |
1027 MsnServConn *servconn; | |
1028 | |
1029 port = 80; | |
1030 | |
1031 session = swboard->session; | |
1032 servconn = swboard->servconn; | |
1033 account = session->account; | |
1034 | |
1035 swboard->empty = FALSE; | |
1036 | |
1037 servconn->http_data->gateway_host = g_strdup(host); | |
1038 | |
1039 #if 0 | |
1040 servconn->connected = TRUE; | |
1041 servconn->cmdproc->ready = TRUE; | |
1042 #endif | |
1043 | |
1044 if (msn_switchboard_is_invited(swboard)) | |
1045 { | |
1046 msn_cmdproc_send(servconn->cmdproc, "ANS", "%s %s %s", | |
1047 gaim_account_get_username(account), | |
1048 swboard->auth_key, swboard->session_id); | |
1049 } | |
1050 else | |
1051 { | |
1052 msn_cmdproc_send(servconn->cmdproc, "USR", "%s %s", | |
1053 gaim_account_get_username(account), | |
1054 swboard->auth_key); | |
1055 } | |
1056 } | |
1057 | |
1058 msn_switchboard_connect(swboard, host, port); | 1022 msn_switchboard_connect(swboard, host, port); |
1059 | 1023 |
1060 g_free(host); | 1024 g_free(host); |
1061 } | 1025 } |
1062 | 1026 |
1100 | 1064 |
1101 if (g_queue_is_empty(swboard->im_queue)) | 1065 if (g_queue_is_empty(swboard->im_queue)) |
1102 { | 1066 { |
1103 MsnCmdProc *cmdproc; | 1067 MsnCmdProc *cmdproc; |
1104 | 1068 |
1105 cmdproc = swboard->servconn->cmdproc; | 1069 cmdproc = swboard->cmdproc; |
1106 | 1070 |
1107 msn_cmdproc_send_quick(cmdproc, "OUT", NULL, NULL); | 1071 msn_cmdproc_send_quick(cmdproc, "OUT", NULL, NULL); |
1108 | 1072 |
1109 msn_switchboard_destroy(swboard); | 1073 msn_switchboard_destroy(swboard); |
1110 } | 1074 } |