diff options
Diffstat (limited to 'toxcore/TCP_client.c')
-rw-r--r-- | toxcore/TCP_client.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index aee309ae..61a2ff1e 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c | |||
@@ -38,10 +38,11 @@ | |||
38 | static int connect_sock_to(sock_t sock, IP_Port ip_port, TCP_Proxy_Info *proxy_info) | 38 | static int connect_sock_to(sock_t sock, IP_Port ip_port, TCP_Proxy_Info *proxy_info) |
39 | { | 39 | { |
40 | if (proxy_info->proxy_type != TCP_PROXY_NONE) { | 40 | if (proxy_info->proxy_type != TCP_PROXY_NONE) { |
41 | ip_port =proxy_info->ip_port; | 41 | ip_port = proxy_info->ip_port; |
42 | } | 42 | } |
43 | 43 | ||
44 | struct sockaddr_storage addr = {0}; | 44 | struct sockaddr_storage addr = {0}; |
45 | |||
45 | size_t addrsize; | 46 | size_t addrsize; |
46 | 47 | ||
47 | if (ip_port.ip.family == AF_INET) { | 48 | if (ip_port.ip.family == AF_INET) { |
@@ -77,11 +78,15 @@ static int proxy_http_generate_connection_request(TCP_Client_Connection *TCP_con | |||
77 | char three[] = "\r\n\r\n"; | 78 | char three[] = "\r\n\r\n"; |
78 | 79 | ||
79 | char ip[INET6_ADDRSTRLEN]; | 80 | char ip[INET6_ADDRSTRLEN]; |
81 | |||
80 | if (!ip_parse_addr(&TCP_conn->ip_port.ip, ip, sizeof(ip))) { | 82 | if (!ip_parse_addr(&TCP_conn->ip_port.ip, ip, sizeof(ip))) { |
81 | return 0; | 83 | return 0; |
82 | } | 84 | } |
85 | |||
83 | const uint16_t port = ntohs(TCP_conn->ip_port.port); | 86 | const uint16_t port = ntohs(TCP_conn->ip_port.port); |
84 | const int written = snprintf(TCP_conn->last_packet, MAX_PACKET_SIZE, "%s%s:%hu%s%s:%hu%s", one, ip, port, two, ip, port, three); | 87 | const int written = snprintf((char *)TCP_conn->last_packet, MAX_PACKET_SIZE, "%s%s:%hu%s%s:%hu%s", one, ip, port, two, |
88 | ip, port, three); | ||
89 | |||
85 | if (written < 0) { | 90 | if (written < 0) { |
86 | return 0; | 91 | return 0; |
87 | } | 92 | } |
@@ -107,19 +112,16 @@ static int proxy_http_read_connection_response(TCP_Client_Connection *TCP_conn) | |||
107 | return 0; | 112 | return 0; |
108 | } | 113 | } |
109 | 114 | ||
110 | data[sizeof(data) - 1] = '\0'; | 115 | data[sizeof(data) - 1] = 0; |
111 | 116 | ||
112 | if (strstr(data, success)) { | 117 | if (strstr((char *)data, success)) { |
113 | // drain all data | 118 | // drain all data |
114 | // instead of drainining it byte by byte do it in bigger chunks | 119 | unsigned int data_left = TCP_socket_data_recv_buffer(TCP_conn->sock); |
115 | // decrementing to 1 | 120 | |
116 | size_t step = sizeof(data); | 121 | if (data_left) { |
117 | do { | 122 | uint8_t temp_data[data_left]; |
118 | if (ret <= 0) { | 123 | read_TCP_packet(TCP_conn->sock, temp_data, data_left); |
119 | step = step % 2 == 0 ? step/2 : 1; | 124 | } |
120 | } | ||
121 | ret = read_TCP_packet(TCP_conn->sock, data, step); | ||
122 | } while (ret > 0 || step != 1); | ||
123 | 125 | ||
124 | return 1; | 126 | return 1; |
125 | } | 127 | } |
@@ -606,6 +608,12 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public | |||
606 | 608 | ||
607 | uint8_t family = ip_port.ip.family; | 609 | uint8_t family = ip_port.ip.family; |
608 | 610 | ||
611 | TCP_Proxy_Info default_proxyinfo; | ||
612 | if (proxy_info == NULL) { | ||
613 | default_proxyinfo.proxy_type = TCP_PROXY_NONE; | ||
614 | proxy_info = &default_proxyinfo; | ||
615 | } | ||
616 | |||
609 | if (proxy_info->proxy_type != TCP_PROXY_NONE) { | 617 | if (proxy_info->proxy_type != TCP_PROXY_NONE) { |
610 | family = proxy_info->ip_port.ip.family; | 618 | family = proxy_info->ip_port.ip.family; |
611 | } | 619 | } |
@@ -645,10 +653,12 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public | |||
645 | temp->status = TCP_CLIENT_PROXY_HTTP_CONNECTING; | 653 | temp->status = TCP_CLIENT_PROXY_HTTP_CONNECTING; |
646 | proxy_http_generate_connection_request(temp); | 654 | proxy_http_generate_connection_request(temp); |
647 | break; | 655 | break; |
656 | |||
648 | case TCP_PROXY_SOCKS5: | 657 | case TCP_PROXY_SOCKS5: |
649 | temp->status = TCP_CLIENT_PROXY_SOCKS5_CONNECTING; | 658 | temp->status = TCP_CLIENT_PROXY_SOCKS5_CONNECTING; |
650 | proxy_socks5_generate_handshake(temp); | 659 | proxy_socks5_generate_handshake(temp); |
651 | break; | 660 | break; |
661 | |||
652 | case TCP_PROXY_NONE: | 662 | case TCP_PROXY_NONE: |
653 | temp->status = TCP_CLIENT_CONNECTING; | 663 | temp->status = TCP_CLIENT_CONNECTING; |
654 | 664 | ||
@@ -657,6 +667,7 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public | |||
657 | free(temp); | 667 | free(temp); |
658 | return NULL; | 668 | return NULL; |
659 | } | 669 | } |
670 | |||
660 | break; | 671 | break; |
661 | } | 672 | } |
662 | 673 | ||