Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/si.c @ 32795:fb5b5f6cf111
Jabber: Use file-transfer accessor functions
author | andrew.victor@mxit.com |
---|---|
date | Sun, 30 Oct 2011 15:52:45 +0000 |
parents | 2ec94166be43 |
children | 4a34689eeb33 |
comparison
equal
deleted
inserted
replaced
32794:1f56d5102483 | 32795:fb5b5f6cf111 |
---|---|
391 jsx->rxlen += len; | 391 jsx->rxlen += len; |
392 | 392 |
393 if (jsx->rxlen < jsx->rxmaxlen) | 393 if (jsx->rxlen < jsx->rxmaxlen) |
394 return; | 394 return; |
395 | 395 |
396 purple_input_remove(xfer->watcher); | 396 purple_input_remove(purple_xfer_get_watcher(xfer)); |
397 xfer->watcher = 0; | 397 purple_xfer_set_watcher(xfer, 0); |
398 g_free(jsx->rxqueue); | 398 g_free(jsx->rxqueue); |
399 jsx->rxqueue = NULL; | 399 jsx->rxqueue = NULL; |
400 | 400 |
401 /* Before actually starting sending the file, we need to wait until the | 401 /* Before actually starting sending the file, we need to wait until the |
402 * recipient sends the IQ result with <streamhost-used/> | 402 * recipient sends the IQ result with <streamhost-used/> |
460 | 460 |
461 /* Have we not read all of DST.ADDR and the following 2-byte port number? */ | 461 /* Have we not read all of DST.ADDR and the following 2-byte port number? */ |
462 if(jsx->rxlen - 5 < jsx->rxqueue[4] + 2) | 462 if(jsx->rxlen - 5 < jsx->rxqueue[4] + 2) |
463 return; | 463 return; |
464 | 464 |
465 purple_input_remove(xfer->watcher); | 465 purple_input_remove(purple_xfer_get_watcher(xfer)); |
466 xfer->watcher = 0; | 466 purple_xfer_set_watcher(xfer, 0); |
467 | 467 |
468 dstaddr = g_strdup_printf("%s%s@%s/%s%s", jsx->stream_id, | 468 dstaddr = g_strdup_printf("%s%s@%s/%s%s", jsx->stream_id, |
469 jsx->js->user->node, jsx->js->user->domain, | 469 jsx->js->user->node, jsx->js->user->domain, |
470 jsx->js->user->resource, purple_xfer_get_remote_user(xfer)); | 470 jsx->js->user->resource, purple_xfer_get_remote_user(xfer)); |
471 | 471 |
506 jsx->rxqueue[4] = strlen(host); | 506 jsx->rxqueue[4] = strlen(host); |
507 memcpy(jsx->rxqueue + 5, host, strlen(host)); | 507 memcpy(jsx->rxqueue + 5, host, strlen(host)); |
508 jsx->rxqueue[5+strlen(host)] = 0x00; | 508 jsx->rxqueue[5+strlen(host)] = 0x00; |
509 jsx->rxqueue[6+strlen(host)] = 0x00; | 509 jsx->rxqueue[6+strlen(host)] = 0x00; |
510 | 510 |
511 xfer->watcher = purple_input_add(source, PURPLE_INPUT_WRITE, | 511 purple_xfer_set_watcher(xfer, purple_input_add(source, PURPLE_INPUT_WRITE, |
512 jabber_si_xfer_bytestreams_send_read_again_resp_cb, xfer); | 512 jabber_si_xfer_bytestreams_send_read_again_resp_cb, xfer)); |
513 jabber_si_xfer_bytestreams_send_read_again_resp_cb(xfer, source, | 513 jabber_si_xfer_bytestreams_send_read_again_resp_cb(xfer, source, |
514 PURPLE_INPUT_WRITE); | 514 PURPLE_INPUT_WRITE); |
515 } | 515 } |
516 | 516 |
517 static void | 517 static void |
537 if (jsx->rxlen < jsx->rxmaxlen) | 537 if (jsx->rxlen < jsx->rxmaxlen) |
538 return; | 538 return; |
539 | 539 |
540 /* If we sent a "Success", wait for a response, otherwise give up and cancel */ | 540 /* If we sent a "Success", wait for a response, otherwise give up and cancel */ |
541 if (jsx->rxqueue[1] == 0x00) { | 541 if (jsx->rxqueue[1] == 0x00) { |
542 purple_input_remove(xfer->watcher); | 542 purple_input_remove(purple_xfer_get_watcher(xfer)); |
543 xfer->watcher = purple_input_add(source, PURPLE_INPUT_READ, | 543 purple_xfer_set_watcher(xfer, purple_input_add(source, PURPLE_INPUT_READ, |
544 jabber_si_xfer_bytestreams_send_read_again_cb, xfer); | 544 jabber_si_xfer_bytestreams_send_read_again_cb, xfer)); |
545 g_free(jsx->rxqueue); | 545 g_free(jsx->rxqueue); |
546 jsx->rxqueue = NULL; | 546 jsx->rxqueue = NULL; |
547 jsx->rxlen = 0; | 547 jsx->rxlen = 0; |
548 } else { | 548 } else { |
549 close(source); | 549 close(source); |
561 int len; | 561 int len; |
562 char buffer[256]; | 562 char buffer[256]; |
563 | 563 |
564 purple_debug_info("jabber", "in jabber_si_xfer_bytestreams_send_read_cb\n"); | 564 purple_debug_info("jabber", "in jabber_si_xfer_bytestreams_send_read_cb\n"); |
565 | 565 |
566 xfer->fd = source; | 566 purple_xfer_set_fd(xfer, source); |
567 | 567 |
568 /** Try to read the SOCKS5 header */ | 568 /** Try to read the SOCKS5 header */ |
569 if(jsx->rxlen < 2) { | 569 if(jsx->rxlen < 2) { |
570 purple_debug_info("jabber", "reading those first two bytes\n"); | 570 purple_debug_info("jabber", "reading those first two bytes\n"); |
571 len = read(source, buffer, 2 - jsx->rxlen); | 571 len = read(source, buffer, 2 - jsx->rxlen); |
617 jsx->rxlen = 0; | 617 jsx->rxlen = 0; |
618 jsx->rxmaxlen = 2; | 618 jsx->rxmaxlen = 2; |
619 jsx->rxqueue = g_malloc(jsx->rxmaxlen); | 619 jsx->rxqueue = g_malloc(jsx->rxmaxlen); |
620 jsx->rxqueue[0] = 0x05; | 620 jsx->rxqueue[0] = 0x05; |
621 jsx->rxqueue[1] = 0x00; | 621 jsx->rxqueue[1] = 0x00; |
622 purple_input_remove(xfer->watcher); | 622 purple_input_remove(purple_xfer_get_watcher(xfer)); |
623 xfer->watcher = purple_input_add(source, PURPLE_INPUT_WRITE, | 623 purple_xfer_set_watcher(xfer, purple_input_add(source, PURPLE_INPUT_WRITE, |
624 jabber_si_xfer_bytestreams_send_read_response_cb, | 624 jabber_si_xfer_bytestreams_send_read_response_cb, |
625 xfer); | 625 xfer)); |
626 jabber_si_xfer_bytestreams_send_read_response_cb(xfer, | 626 jabber_si_xfer_bytestreams_send_read_response_cb(xfer, |
627 source, PURPLE_INPUT_WRITE); | 627 source, PURPLE_INPUT_WRITE); |
628 jsx->rxqueue = NULL; | 628 jsx->rxqueue = NULL; |
629 jsx->rxlen = 0; | 629 jsx->rxlen = 0; |
630 return; | 630 return; |
635 jsx->rxlen = 0; | 635 jsx->rxlen = 0; |
636 jsx->rxmaxlen = 2; | 636 jsx->rxmaxlen = 2; |
637 jsx->rxqueue = g_malloc(jsx->rxmaxlen); | 637 jsx->rxqueue = g_malloc(jsx->rxmaxlen); |
638 jsx->rxqueue[0] = 0x05; | 638 jsx->rxqueue[0] = 0x05; |
639 jsx->rxqueue[1] = 0xFF; | 639 jsx->rxqueue[1] = 0xFF; |
640 purple_input_remove(xfer->watcher); | 640 purple_input_remove(purple_xfer_get_watcher(xfer)); |
641 xfer->watcher = purple_input_add(source, PURPLE_INPUT_WRITE, | 641 purple_xfer_set_watcher(xfer, purple_input_add(source, PURPLE_INPUT_WRITE, |
642 jabber_si_xfer_bytestreams_send_read_response_cb, xfer); | 642 jabber_si_xfer_bytestreams_send_read_response_cb, xfer)); |
643 jabber_si_xfer_bytestreams_send_read_response_cb(xfer, | 643 jabber_si_xfer_bytestreams_send_read_response_cb(xfer, |
644 source, PURPLE_INPUT_WRITE); | 644 source, PURPLE_INPUT_WRITE); |
645 } | 645 } |
646 | 646 |
647 static gint | 647 static gint |
672 purple_debug_warning("jabber", "accept: %s\n", g_strerror(errno)); | 672 purple_debug_warning("jabber", "accept: %s\n", g_strerror(errno)); |
673 /* Don't cancel the ft - allow it to fall to the next streamhost.*/ | 673 /* Don't cancel the ft - allow it to fall to the next streamhost.*/ |
674 return; | 674 return; |
675 } | 675 } |
676 | 676 |
677 purple_input_remove(xfer->watcher); | 677 purple_input_remove(purple_xfer_get_watcher(xfer)); |
678 close(source); | 678 close(source); |
679 jsx->local_streamhost_fd = -1; | 679 jsx->local_streamhost_fd = -1; |
680 | 680 |
681 flags = fcntl(acceptfd, F_GETFL); | 681 flags = fcntl(acceptfd, F_GETFL); |
682 fcntl(acceptfd, F_SETFL, flags | O_NONBLOCK); | 682 fcntl(acceptfd, F_SETFL, flags | O_NONBLOCK); |
683 #ifndef _WIN32 | 683 #ifndef _WIN32 |
684 fcntl(acceptfd, F_SETFD, FD_CLOEXEC); | 684 fcntl(acceptfd, F_SETFD, FD_CLOEXEC); |
685 #endif | 685 #endif |
686 | 686 |
687 xfer->watcher = purple_input_add(acceptfd, PURPLE_INPUT_READ, | 687 purple_xfer_set_watcher(xfer, purple_input_add(acceptfd, PURPLE_INPUT_READ, |
688 jabber_si_xfer_bytestreams_send_read_cb, xfer); | 688 jabber_si_xfer_bytestreams_send_read_cb, xfer)); |
689 } | 689 } |
690 | 690 |
691 static void | 691 static void |
692 jabber_si_connect_proxy_cb(JabberStream *js, const char *from, | 692 jabber_si_connect_proxy_cb(JabberStream *js, const char *from, |
693 JabberIqType type, const char *id, | 693 JabberIqType type, const char *id, |
759 { | 759 { |
760 gchar *my_jid = g_strdup_printf("%s@%s/%s", jsx->js->user->node, | 760 gchar *my_jid = g_strdup_printf("%s@%s/%s", jsx->js->user->node, |
761 jsx->js->user->domain, jsx->js->user->resource); | 761 jsx->js->user->domain, jsx->js->user->resource); |
762 if (!strcmp(jid, my_jid)) { | 762 if (!strcmp(jid, my_jid)) { |
763 purple_debug_info("jabber", "Got local SOCKS5 streamhost-used.\n"); | 763 purple_debug_info("jabber", "Got local SOCKS5 streamhost-used.\n"); |
764 purple_xfer_start(xfer, xfer->fd, NULL, -1); | 764 purple_xfer_start(xfer, purple_xfer_get_fd(xfer), NULL, -1); |
765 } else { | 765 } else { |
766 /* if available, try to revert to IBB... */ | 766 /* if available, try to revert to IBB... */ |
767 if (jsx->stream_method & STREAM_METHOD_IBB) { | 767 if (jsx->stream_method & STREAM_METHOD_IBB) { |
768 purple_debug_info("jabber", | 768 purple_debug_info("jabber", |
769 "jabber_si_connect_proxy_cb: trying to revert to IBB\n"); | 769 "jabber_si_connect_proxy_cb: trying to revert to IBB\n"); |
783 g_free(my_jid); | 783 g_free(my_jid); |
784 return; | 784 return; |
785 } | 785 } |
786 | 786 |
787 /* Clean up the local streamhost - it isn't going to be used.*/ | 787 /* Clean up the local streamhost - it isn't going to be used.*/ |
788 if (xfer->watcher > 0) { | 788 if (purple_xfer_get_watcher(xfer) > 0) { |
789 purple_input_remove(xfer->watcher); | 789 purple_input_remove(purple_xfer_get_watcher(xfer)); |
790 xfer->watcher = 0; | 790 purple_xfer_set_watcher(xfer, 0); |
791 } | 791 } |
792 if (jsx->local_streamhost_fd >= 0) { | 792 if (jsx->local_streamhost_fd >= 0) { |
793 close(jsx->local_streamhost_fd); | 793 close(jsx->local_streamhost_fd); |
794 jsx->local_streamhost_fd = -1; | 794 jsx->local_streamhost_fd = -1; |
795 } | 795 } |
843 | 843 |
844 jsx->local_streamhost_fd = sock; | 844 jsx->local_streamhost_fd = sock; |
845 | 845 |
846 jid = g_strdup_printf("%s@%s/%s", jsx->js->user->node, | 846 jid = g_strdup_printf("%s@%s/%s", jsx->js->user->node, |
847 jsx->js->user->domain, jsx->js->user->resource); | 847 jsx->js->user->domain, jsx->js->user->resource); |
848 xfer->local_port = purple_network_get_port_from_fd(sock); | 848 purple_xfer_set_local_port(xfer, purple_network_get_port_from_fd(sock)); |
849 g_snprintf(port, sizeof(port), "%hu", purple_xfer_get_local_port(xfer)); | 849 g_snprintf(port, sizeof(port), "%hu", purple_xfer_get_local_port(xfer)); |
850 | 850 |
851 public_ip = purple_network_get_my_ip(jsx->js->fd); | 851 public_ip = purple_network_get_my_ip(jsx->js->fd); |
852 | 852 |
853 /* Include the localhost's IPs (for in-network transfers) */ | 853 /* Include the localhost's IPs (for in-network transfers) */ |
874 } | 874 } |
875 | 875 |
876 g_free(jid); | 876 g_free(jid); |
877 | 877 |
878 /* The listener for the local proxy */ | 878 /* The listener for the local proxy */ |
879 xfer->watcher = purple_input_add(sock, PURPLE_INPUT_READ, | 879 purple_xfer_set_watcher(xfer, purple_input_add(sock, PURPLE_INPUT_READ, |
880 jabber_si_xfer_bytestreams_send_connected_cb, xfer); | 880 jabber_si_xfer_bytestreams_send_connected_cb, xfer)); |
881 } | 881 } |
882 | 882 |
883 for (tmp = jsx->js->bs_proxies; tmp; tmp = tmp->next) { | 883 for (tmp = jsx->js->bs_proxies; tmp; tmp = tmp->next) { |
884 sh = tmp->data; | 884 sh = tmp->data; |
885 | 885 |
1302 purple_network_listen_cancel(jsx->listen_data); | 1302 purple_network_listen_cancel(jsx->listen_data); |
1303 if (jsx->iq_id != NULL) | 1303 if (jsx->iq_id != NULL) |
1304 jabber_iq_remove_callback_by_id(js, jsx->iq_id); | 1304 jabber_iq_remove_callback_by_id(js, jsx->iq_id); |
1305 if (jsx->local_streamhost_fd >= 0) | 1305 if (jsx->local_streamhost_fd >= 0) |
1306 close(jsx->local_streamhost_fd); | 1306 close(jsx->local_streamhost_fd); |
1307 if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND && xfer->fd >= 0) { | 1307 if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND && purple_xfer_get_fd(xfer) >= 0) { |
1308 purple_debug_info("jabber", "remove port mapping\n"); | 1308 purple_debug_info("jabber", "remove port mapping\n"); |
1309 purple_network_remove_port_mapping(xfer->fd); | 1309 purple_network_remove_port_mapping(purple_xfer_get_fd(xfer)); |
1310 } | 1310 } |
1311 if (jsx->connect_timeout > 0) | 1311 if (jsx->connect_timeout > 0) |
1312 purple_timeout_remove(jsx->connect_timeout); | 1312 purple_timeout_remove(jsx->connect_timeout); |
1313 if (jsx->ibb_timeout_handle > 0) | 1313 if (jsx->ibb_timeout_handle > 0) |
1314 purple_timeout_remove(jsx->ibb_timeout_handle); | 1314 purple_timeout_remove(jsx->ibb_timeout_handle); |