Lines Matching refs:sx

163 static void socksstate(struct socks_state *sx, struct Curl_easy *data,  in socksstate()  argument
170 enum connect_t oldstate = sx->state; in socksstate()
200 sx->state = state; in socksstate()
205 socks_statename[oldstate], socks_statename[sx->state], in socksstate()
211 struct socks_state *sx, in socks_state_send() argument
219 nwritten = Curl_conn_cf_send(cf->next, data, (char *)sx->outp, in socks_state_send()
220 sx->outstanding, FALSE, &result); in socks_state_send()
234 DEBUGASSERT(sx->outstanding >= nwritten); in socks_state_send()
236 sx->outstanding -= nwritten; in socks_state_send()
237 sx->outp += nwritten; in socks_state_send()
242 struct socks_state *sx, in socks_state_recv() argument
250 nread = Curl_conn_cf_recv(cf->next, data, (char *)sx->outp, in socks_state_recv()
251 sx->outstanding, &result); in socks_state_recv()
266 DEBUGASSERT(sx->outstanding >= nread); in socks_state_recv()
267 sx->outstanding -= nread; in socks_state_recv()
268 sx->outp += nread; in socks_state_recv()
284 struct socks_state *sx, in do_SOCKS4() argument
290 unsigned char *socksreq = sx->buffer; in do_SOCKS4()
295 switch(sx->state) { in do_SOCKS4()
301 protocol4a ? "a" : "", sx->hostname, sx->remote_port); in do_SOCKS4()
304 sx->hostname, sx->remote_port); in do_SOCKS4()
319 socksreq[2] = (unsigned char)((sx->remote_port >> 8) & 0xff); /* MSB */ in do_SOCKS4()
320 socksreq[3] = (unsigned char)(sx->remote_port & 0xff); /* LSB */ in do_SOCKS4()
325 Curl_resolv(data, sx->hostname, sx->remote_port, TRUE, &dns); in do_SOCKS4()
330 sxstate(sx, data, CONNECT_RESOLVING); in do_SOCKS4()
331 infof(data, "SOCKS4 non-blocking resolve of %s", sx->hostname); in do_SOCKS4()
334 sxstate(sx, data, CONNECT_RESOLVED); in do_SOCKS4()
339 sxstate(sx, data, CONNECT_REQ_INIT); in do_SOCKS4()
344 dns = Curl_fetch_addr(data, sx->hostname, conn->primary.remote_port); in do_SOCKS4()
351 infof(data, "Hostname '%s' was found", sx->hostname); in do_SOCKS4()
352 sxstate(sx, data, CONNECT_RESOLVED); in do_SOCKS4()
394 failf(data, "SOCKS4 connection to %s not supported", sx->hostname); in do_SOCKS4()
398 sx->hostname); in do_SOCKS4()
410 if(sx->proxy_user) { in do_SOCKS4()
411 size_t plen = strlen(sx->proxy_user); in do_SOCKS4()
420 memcpy(socksreq + 8, sx->proxy_user, plen + 1); in do_SOCKS4()
438 hostnamelen = strlen(sx->hostname) + 1; /* length including NUL */ in do_SOCKS4()
440 (packetsize + hostnamelen < sizeof(sx->buffer))) in do_SOCKS4()
441 strcpy((char *)socksreq + packetsize, sx->hostname); in do_SOCKS4()
448 sx->outp = socksreq; in do_SOCKS4()
449 DEBUGASSERT(packetsize <= sizeof(sx->buffer)); in do_SOCKS4()
450 sx->outstanding = packetsize; in do_SOCKS4()
451 sxstate(sx, data, CONNECT_REQ_SENDING); in do_SOCKS4()
456 presult = socks_state_send(cf, sx, data, CURLPX_SEND_CONNECT, in do_SOCKS4()
460 else if(sx->outstanding) { in do_SOCKS4()
465 sx->outstanding = 8; /* receive data size */ in do_SOCKS4()
466 sx->outp = socksreq; in do_SOCKS4()
467 sxstate(sx, data, CONNECT_SOCKS_READ); in do_SOCKS4()
472 presult = socks_state_recv(cf, sx, data, CURLPX_RECV_CONNECT, in do_SOCKS4()
476 else if(sx->outstanding) { in do_SOCKS4()
480 sxstate(sx, data, CONNECT_DONE); in do_SOCKS4()
561 struct socks_state *sx, in do_SOCKS5() argument
581 unsigned char *socksreq = sx->buffer; in do_SOCKS5()
587 const size_t hostname_len = strlen(sx->hostname); in do_SOCKS5()
594 switch(sx->state) { in do_SOCKS5()
598 sx->hostname, sx->remote_port); in do_SOCKS5()
613 sx->proxy_user = NULL; in do_SOCKS5()
625 if(sx->proxy_user) in do_SOCKS5()
630 sx->outp = socksreq; in do_SOCKS5()
631 DEBUGASSERT(idx <= sizeof(sx->buffer)); in do_SOCKS5()
632 sx->outstanding = idx; in do_SOCKS5()
633 presult = socks_state_send(cf, sx, data, CURLPX_SEND_CONNECT, in do_SOCKS5()
637 else if(sx->outstanding) { in do_SOCKS5()
641 sxstate(sx, data, CONNECT_SOCKS_READ); in do_SOCKS5()
644 presult = socks_state_send(cf, sx, data, CURLPX_SEND_CONNECT, in do_SOCKS5()
648 else if(sx->outstanding) { in do_SOCKS5()
655 sx->outstanding = 2; /* expect two bytes */ in do_SOCKS5()
656 sx->outp = socksreq; /* store it here */ in do_SOCKS5()
659 presult = socks_state_recv(cf, sx, data, CURLPX_RECV_CONNECT, in do_SOCKS5()
663 else if(sx->outstanding) { in do_SOCKS5()
673 sxstate(sx, data, CONNECT_REQ_INIT); in do_SOCKS5()
678 sxstate(sx, data, CONNECT_AUTH_INIT); in do_SOCKS5()
683 sxstate(sx, data, CONNECT_GSSAPI_INIT); in do_SOCKS5()
719 if(sx->proxy_user && sx->proxy_password) { in do_SOCKS5()
720 proxy_user_len = strlen(sx->proxy_user); in do_SOCKS5()
721 proxy_password_len = strlen(sx->proxy_password); in do_SOCKS5()
738 if(sx->proxy_user && proxy_user_len) { in do_SOCKS5()
744 memcpy(socksreq + len, sx->proxy_user, proxy_user_len); in do_SOCKS5()
748 if(sx->proxy_password && proxy_password_len) { in do_SOCKS5()
754 memcpy(socksreq + len, sx->proxy_password, proxy_password_len); in do_SOCKS5()
757 sxstate(sx, data, CONNECT_AUTH_SEND); in do_SOCKS5()
758 DEBUGASSERT(len <= sizeof(sx->buffer)); in do_SOCKS5()
759 sx->outstanding = len; in do_SOCKS5()
760 sx->outp = socksreq; in do_SOCKS5()
764 presult = socks_state_send(cf, sx, data, CURLPX_SEND_AUTH, in do_SOCKS5()
768 else if(sx->outstanding) { in do_SOCKS5()
772 sx->outp = socksreq; in do_SOCKS5()
773 sx->outstanding = 2; in do_SOCKS5()
774 sxstate(sx, data, CONNECT_AUTH_READ); in do_SOCKS5()
777 presult = socks_state_recv(cf, sx, data, CURLPX_RECV_AUTH, in do_SOCKS5()
781 else if(sx->outstanding) { in do_SOCKS5()
793 sxstate(sx, data, CONNECT_REQ_INIT); in do_SOCKS5()
798 enum resolve_t rc = Curl_resolv(data, sx->hostname, sx->remote_port, in do_SOCKS5()
805 sxstate(sx, data, CONNECT_RESOLVING); in do_SOCKS5()
808 sxstate(sx, data, CONNECT_RESOLVED); in do_SOCKS5()
815 dns = Curl_fetch_addr(data, sx->hostname, sx->remote_port); in do_SOCKS5()
822 infof(data, "SOCKS5: hostname '%s' found", sx->hostname); in do_SOCKS5()
852 sx->hostname); in do_SOCKS5()
873 sx->remote_port); in do_SOCKS5()
888 sx->remote_port); in do_SOCKS5()
915 if(1 != Curl_inet_pton(AF_INET6, sx->hostname, ip6)) in do_SOCKS5()
923 if(1 == Curl_inet_pton(AF_INET, sx->hostname, ip4)) { in do_SOCKS5()
931 memcpy(&socksreq[len], sx->hostname, hostname_len); /* w/o NULL */ in do_SOCKS5()
935 sx->hostname, sx->remote_port); in do_SOCKS5()
942 socksreq[len++] = (unsigned char)((sx->remote_port >> 8) & 0xff); in do_SOCKS5()
944 socksreq[len++] = (unsigned char)(sx->remote_port & 0xff); in do_SOCKS5()
952 sx->outp = socksreq; in do_SOCKS5()
953 DEBUGASSERT(len <= sizeof(sx->buffer)); in do_SOCKS5()
954 sx->outstanding = len; in do_SOCKS5()
955 sxstate(sx, data, CONNECT_REQ_SENDING); in do_SOCKS5()
958 presult = socks_state_send(cf, sx, data, CURLPX_SEND_REQUEST, in do_SOCKS5()
962 else if(sx->outstanding) { in do_SOCKS5()
972 sx->outstanding = 10; /* minimum packet size is 10 */ in do_SOCKS5()
973 sx->outp = socksreq; in do_SOCKS5()
974 sxstate(sx, data, CONNECT_REQ_READ); in do_SOCKS5()
977 presult = socks_state_recv(cf, sx, data, CURLPX_RECV_REQACK, in do_SOCKS5()
981 else if(sx->outstanding) { in do_SOCKS5()
994 sx->hostname, (unsigned char)socksreq[1]); in do_SOCKS5()
1053 DEBUGASSERT(len <= sizeof(sx->buffer)); in do_SOCKS5()
1054 sx->outstanding = len - 10; /* get the rest */ in do_SOCKS5()
1055 sx->outp = &socksreq[10]; in do_SOCKS5()
1056 sxstate(sx, data, CONNECT_REQ_READ_MORE); in do_SOCKS5()
1059 sxstate(sx, data, CONNECT_DONE); in do_SOCKS5()
1067 presult = socks_state_recv(cf, sx, data, CURLPX_RECV_ADDRESS, in do_SOCKS5()
1071 else if(sx->outstanding) { in do_SOCKS5()
1075 sxstate(sx, data, CONNECT_DONE); in do_SOCKS5()
1136 struct socks_state *sx = cf->ctx; in socks_proxy_cf_connect() local
1147 if(!sx) { in socks_proxy_cf_connect()
1148 sx = calloc(1, sizeof(*sx)); in socks_proxy_cf_connect()
1149 if(!sx) in socks_proxy_cf_connect()
1151 cf->ctx = sx; in socks_proxy_cf_connect()
1154 if(sx->state == CONNECT_INIT) { in socks_proxy_cf_connect()
1158 sxstate(sx, data, CONNECT_SOCKS_INIT); in socks_proxy_cf_connect()
1159 sx->hostname = in socks_proxy_cf_connect()
1166 sx->remote_port = in socks_proxy_cf_connect()
1171 sx->proxy_user = conn->socks_proxy.user; in socks_proxy_cf_connect()
1172 sx->proxy_password = conn->socks_proxy.passwd; in socks_proxy_cf_connect()
1175 result = connect_SOCKS(cf, sx, data); in socks_proxy_cf_connect()
1176 if(!result && sx->state == CONNECT_DONE) { in socks_proxy_cf_connect()
1190 struct socks_state *sx = cf->ctx; in socks_cf_adjust_pollset() local
1192 if(!cf->connected && sx) { in socks_cf_adjust_pollset()
1196 switch(sx->state) { in socks_cf_adjust_pollset()