comparison src/protocols/msn/switchboard.c @ 10403:e5455f1dc9b6

[gaim-migrate @ 11648] This is "Yet another MSN fix" from Felipe, it actually turned into "Several MSN fixes", see bug 1088651 for the details. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Thu, 23 Dec 2004 20:13:54 +0000
parents 38256d3e8324
children 6be6da69d603
comparison
equal deleted inserted replaced
10402:3d2dd0ed368d 10403:e5455f1dc9b6
89 { 89 {
90 /* The messages could not be sent due to a switchboard error */ 90 /* The messages could not be sent due to a switchboard error */
91 msg_error_helper(swboard->servconn->cmdproc, msg, 91 msg_error_helper(swboard->servconn->cmdproc, msg,
92 MSN_MSG_ERROR_SB); 92 MSN_MSG_ERROR_SB);
93 } 93 }
94 msn_message_destroy(msg); 94 msn_message_unref(msg);
95 } 95 }
96 96
97 g_queue_free(swboard->im_queue); 97 g_queue_free(swboard->im_queue);
98
99 for (l = swboard->ack_list; l != NULL; l = l->next)
100 msn_message_unref(l->data);
98 101
99 if (swboard->im_user != NULL) 102 if (swboard->im_user != NULL)
100 g_free(swboard->im_user); 103 g_free(swboard->im_user);
101 104
102 if (swboard->auth_key != NULL) 105 if (swboard->auth_key != NULL)
331 } 334 }
332 335
333 static void 336 static void
334 msg_error_helper(MsnCmdProc *cmdproc, MsnMessage *msg, MsnMsgErrorType error) 337 msg_error_helper(MsnCmdProc *cmdproc, MsnMessage *msg, MsnMsgErrorType error)
335 { 338 {
339 MsnSwitchBoard *swboard;
340
336 g_return_if_fail(cmdproc != NULL); 341 g_return_if_fail(cmdproc != NULL);
337 g_return_if_fail(msg != NULL); 342 g_return_if_fail(msg != NULL);
338 343
339 if (msg->nak_cb != NULL) 344 if ((error != MSN_MSG_ERROR_SB) && (msg->nak_cb != NULL))
340 msg->nak_cb(msg, msg->ack_data); 345 msg->nak_cb(msg, msg->ack_data);
341 346
347 swboard = cmdproc->servconn->data;
348
342 if (msg->type == MSN_MSG_TEXT) 349 if (msg->type == MSN_MSG_TEXT)
343 { 350 {
344 MsnSwitchBoard *swboard;
345 const char *format; 351 const char *format;
346 char *body_str, *body_enc, *pre, *post; 352 char *body_str, *body_enc, *pre, *post;
347 char *str_reason; 353 char *str_reason;
348
349 swboard = cmdproc->servconn->data;
350 354
351 #if 0 355 #if 0
352 if (swboard->conv == NULL) 356 if (swboard->conv == NULL)
353 { 357 {
354 if (msg->ack_ref) 358 if (msg->ack_ref)
355 msn_message_unref(msg); 359 msn_message_unref(msg);
356 360
357 return; 361 return;
358 } 362 }
359 #endif 363 #endif
360 364
401 body_str = g_strdup_printf("%s%s%s", pre, body_enc, post); 405 body_str = g_strdup_printf("%s%s%s", pre, body_enc, post);
402 g_free(body_enc); 406 g_free(body_enc);
403 g_free(pre); 407 g_free(pre);
404 g_free(post); 408 g_free(post);
405 409
406 msn_switchboard_report_user(cmdproc->servconn->data, 410 msn_switchboard_report_user(swboard, GAIM_MESSAGE_ERROR,
407 GAIM_MESSAGE_ERROR, str_reason); 411 str_reason);
408 msn_switchboard_report_user(cmdproc->servconn->data, 412 msn_switchboard_report_user(swboard, GAIM_MESSAGE_RAW,
409 GAIM_MESSAGE_RAW, body_str); 413 body_str);
410 414
411 g_free(body_str); 415 g_free(body_str);
412 } 416 }
413 417
414 if (msg->ack_ref) 418 /* If a timeout occures we will want the msg around just in case we
419 * receive the ACK after the timeout. */
420 if (msg->ack_ref && error != MSN_MSG_ERROR_TIMEOUT)
421 {
422 swboard->ack_list = g_list_remove(swboard->ack_list, msg);
415 msn_message_unref(msg); 423 msn_message_unref(msg);
424 }
416 } 425 }
417 426
418 /************************************************************************** 427 /**************************************************************************
419 * Switchboard Commands 428 * Switchboard Commands
420 **************************************************************************/ 429 **************************************************************************/
524 msn_switchboard_add_user(swboard, passport); 533 msn_switchboard_add_user(swboard, passport);
525 534
526 msn_switchboard_process_queue(swboard); 535 msn_switchboard_process_queue(swboard);
527 536
528 send_clientcaps(swboard); 537 send_clientcaps(swboard);
538
539 if (swboard->closed)
540 msn_switchboard_close(swboard);
529 } 541 }
530 542
531 static void 543 static void
532 msg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, size_t len) 544 msg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, size_t len)
533 { 545 {
566 } 578 }
567 579
568 static void 580 static void
569 ack_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) 581 ack_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
570 { 582 {
583 MsnSwitchBoard *swboard;
571 MsnMessage *msg; 584 MsnMessage *msg;
572 585
573 msg = cmd->trans->data; 586 msg = cmd->trans->data;
574 587
575 if (msg->ack_cb != NULL) 588 if (msg->ack_cb != NULL)
576 msg->ack_cb(msg, msg->ack_data); 589 msg->ack_cb(msg, msg->ack_data);
577 590
591 swboard = cmdproc->servconn->data;
592 swboard->ack_list = g_list_remove(swboard->ack_list, msg);
578 msn_message_unref(msg); 593 msn_message_unref(msg);
579 } 594 }
580 595
581 static void 596 static void
582 out_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) 597 out_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
795 810
796 if (msg->type == MSN_MSG_TEXT) 811 if (msg->type == MSN_MSG_TEXT)
797 { 812 {
798 msg->ack_ref = TRUE; 813 msg->ack_ref = TRUE;
799 msn_message_ref(msg); 814 msn_message_ref(msg);
815 swboard->ack_list = g_list_append(swboard->ack_list, msg);
800 msn_transaction_set_timeout_cb(trans, msg_timeout); 816 msn_transaction_set_timeout_cb(trans, msg_timeout);
801 } 817 }
802 else if (msg->type == MSN_MSG_SLP) 818 else if (msg->type == MSN_MSG_SLP)
803 { 819 {
804 msg->ack_ref = TRUE; 820 msg->ack_ref = TRUE;
805 msn_message_ref(msg); 821 msn_message_ref(msg);
822 swboard->ack_list = g_list_append(swboard->ack_list, msg);
806 msn_transaction_set_timeout_cb(trans, msg_timeout); 823 msn_transaction_set_timeout_cb(trans, msg_timeout);
807 #if 0 824 #if 0
808 if (msg->ack_cb != NULL) 825 if (msg->ack_cb != NULL)
809 { 826 {
810 msn_transaction_add_cb(trans, "ACK", msg_ack); 827 msn_transaction_add_cb(trans, "ACK", msg_ack);
918 } 935 }
919 936
920 /************************************************************************** 937 /**************************************************************************
921 * Call stuff 938 * Call stuff
922 **************************************************************************/ 939 **************************************************************************/
940 static void
941 got_cal(MsnCmdProc *cmdproc, MsnCommand *cmd)
942 {
923 #if 0 943 #if 0
924 static void
925 got_cal(MsnCmdProc *cmdproc, MsnCommand *cmd)
926 {
927 MsnSwitchBoard *swboard; 944 MsnSwitchBoard *swboard;
928 const char *user; 945 const char *user;
929 946
930 swboard = cmdproc->servconn->data; 947 swboard = cmdproc->servconn->data;
931 948
932 user = cmd->params[0]; 949 user = cmd->params[0];
933 950
934 msn_switchboard_add_user(swboard, user); 951 msn_switchboard_add_user(swboard, user);
935 }
936 #endif 952 #endif
953 }
937 954
938 static void 955 static void
939 cal_timeout(MsnCmdProc *cmdproc, MsnTransaction *trans) 956 cal_timeout(MsnCmdProc *cmdproc, MsnTransaction *trans)
940 { 957 {
941 cal_error_helper(trans, MSN_SB_ERROR_UNKNOWN); 958 cal_error_helper(trans, MSN_SB_ERROR_UNKNOWN);
961 g_return_if_fail(swboard != NULL); 978 g_return_if_fail(swboard != NULL);
962 979
963 cmdproc = swboard->servconn->cmdproc; 980 cmdproc = swboard->servconn->cmdproc;
964 981
965 trans = msn_transaction_new(cmdproc, "CAL", "%s", user); 982 trans = msn_transaction_new(cmdproc, "CAL", "%s", user);
966 /* msn_transaction_add_cb(trans, "CAL", got_cal); */ 983 /* this doesn't do anything, but users seem to think that
984 * 'Unhandled command' is some kind of error, so we don't report it */
985 msn_transaction_add_cb(trans, "CAL", got_cal);
967 986
968 msn_transaction_set_data(trans, swboard); 987 msn_transaction_set_data(trans, swboard);
969 msn_transaction_set_timeout_cb(trans, cal_timeout); 988 msn_transaction_set_timeout_cb(trans, cal_timeout);
970 989
971 if (swboard->ready) 990 if (swboard->ready)
982 { 1001 {
983 MsnSwitchBoard *swboard; 1002 MsnSwitchBoard *swboard;
984 char *host; 1003 char *host;
985 int port; 1004 int port;
986 swboard = cmd->trans->data; 1005 swboard = cmd->trans->data;
1006
1007 if (g_list_find(cmdproc->session->switches, swboard) == NULL)
1008 /* The conversation window was closed. */
1009 return;
987 1010
988 msn_switchboard_set_auth_key(swboard, cmd->params[4]); 1011 msn_switchboard_set_auth_key(swboard, cmd->params[4]);
989 1012
990 msn_parse_socket(cmd->params[2], &host, &port); 1013 msn_parse_socket(cmd->params[2], &host, &port);
991 1014
1053 1076
1054 cmdproc = swboard->session->notification->cmdproc; 1077 cmdproc = swboard->session->notification->cmdproc;
1055 1078
1056 trans = msn_transaction_new(cmdproc, "XFR", "%s", "SB"); 1079 trans = msn_transaction_new(cmdproc, "XFR", "%s", "SB");
1057 msn_transaction_add_cb(trans, "XFR", got_swboard); 1080 msn_transaction_add_cb(trans, "XFR", got_swboard);
1081
1058 msn_transaction_set_data(trans, swboard); 1082 msn_transaction_set_data(trans, swboard);
1059 msn_transaction_set_error_cb(trans, xfr_error); 1083 msn_transaction_set_error_cb(trans, xfr_error);
1060 1084
1061 msn_cmdproc_send_trans(cmdproc, trans); 1085 msn_cmdproc_send_trans(cmdproc, trans);
1086 }
1087
1088 void
1089 msn_switchboard_close(MsnSwitchBoard *swboard)
1090 {
1091 g_return_if_fail(swboard != NULL);
1092
1093 if (g_queue_is_empty(swboard->im_queue))
1094 {
1095 MsnCmdProc *cmdproc;
1096
1097 cmdproc = swboard->servconn->cmdproc;
1098
1099 msn_cmdproc_send_quick(cmdproc, "OUT", NULL, NULL);
1100
1101 msn_switchboard_destroy(swboard);
1102 }
1103 else
1104 swboard->closed = TRUE;
1062 } 1105 }
1063 1106
1064 /************************************************************************** 1107 /**************************************************************************
1065 * Init stuff 1108 * Init stuff
1066 **************************************************************************/ 1109 **************************************************************************/