comparison src/proxy.c @ 10309:19974fd2d61d

[gaim-migrate @ 11501] I prefer these functions like nobody's business. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 03 Dec 2004 03:07:47 +0000
parents 2ac21bf20e04
children 61852117568f
comparison
equal deleted inserted replaced
10308:52c2303f60dc 10309:19974fd2d61d
239 char ch; 239 char ch;
240 int rc; 240 int rc;
241 241
242 /* Are you alive? */ 242 /* Are you alive? */
243 if(kill(req->dns_pid, 0) != 0) { 243 if(kill(req->dns_pid, 0) != 0) {
244 gaim_debug(GAIM_DEBUG_WARNING, "dns", 244 gaim_debug_warning("dns",
245 "DNS child %d no longer exists\n", req->dns_pid); 245 "DNS child %d no longer exists\n", req->dns_pid);
246 return -1; 246 return -1;
247 } 247 }
248 248
249 /* Let's contact this lost child! */ 249 /* Let's contact this lost child! */
250 rc = write(req->fd_in, dns_params, sizeof(*dns_params)); 250 rc = write(req->fd_in, dns_params, sizeof(*dns_params));
251 if(rc<0) { 251 if(rc<0) {
252 gaim_debug(GAIM_DEBUG_ERROR, "dns", 252 gaim_debug_error("dns",
253 "Unable to write to DNS child %d: %d\n", 253 "Unable to write to DNS child %d: %d\n",
254 req->dns_pid, strerror(errno)); 254 req->dns_pid, strerror(errno));
255 close(req->fd_in); 255 close(req->fd_in);
256 return -1; 256 return -1;
257 } 257 }
259 g_return_val_if_fail(rc == sizeof(*dns_params), -1); 259 g_return_val_if_fail(rc == sizeof(*dns_params), -1);
260 260
261 /* Did you hear me? (This avoids some race conditions) */ 261 /* Did you hear me? (This avoids some race conditions) */
262 rc = read(req->fd_out, &ch, 1); 262 rc = read(req->fd_out, &ch, 1);
263 if(rc != 1 || ch!='Y') { 263 if(rc != 1 || ch!='Y') {
264 gaim_debug(GAIM_DEBUG_WARNING, "dns", 264 gaim_debug_warning("dns",
265 "DNS child %d not responding. Killing it!\n", 265 "DNS child %d not responding. Killing it!\n",
266 req->dns_pid); 266 req->dns_pid);
267 kill(req->dns_pid, SIGKILL); 267 kill(req->dns_pid, SIGKILL);
268 return -1; 268 return -1;
269 } 269 }
270 270
271 gaim_debug(GAIM_DEBUG_INFO, "dns", 271 gaim_debug_info("dns",
272 "Successfully sent DNS request to child %d\n", req->dns_pid); 272 "Successfully sent DNS request to child %d\n", req->dns_pid);
273 return 0; 273 return 0;
274 } 274 }
275 275
276 static void host_resolved(gpointer data, gint source, GaimInputCondition cond); 276 static void host_resolved(gpointer data, gint source, GaimInputCondition cond);
285 req->host = g_strdup(r->params.hostname); 285 req->host = g_strdup(r->params.hostname);
286 req->port = r->params.port; 286 req->port = r->params.port;
287 req->callback = r->callback; 287 req->callback = r->callback;
288 req->data = r->data; 288 req->data = r->data;
289 289
290 gaim_debug(GAIM_DEBUG_INFO, "dns", 290 gaim_debug_info("dns",
291 "Processing queued DNS query for '%s' with child %d\n", 291 "Processing queued DNS query for '%s' with child %d\n",
292 req->host, req->dns_pid); 292 req->host, req->dns_pid);
293 293
294 if(send_dns_request_to_child(req, &(r->params)) != 0) { 294 if(send_dns_request_to_child(req, &(r->params)) != 0) {
295 req_free(req); 295 req_free(req);
296 req = NULL; 296 req = NULL;
297 297
298 gaim_debug(GAIM_DEBUG_WARNING, "dns", 298 gaim_debug_warning("dns",
299 "Intent of process queued query of '%s' failed, " 299 "Intent of process queued query of '%s' failed, "
300 "requeueing...\n", r->params.hostname); 300 "requeueing...\n", r->params.hostname);
301 g_queue_push_head(queued_requests, r); 301 g_queue_push_head(queued_requests, r);
302 } else { 302 } else {
303 req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); 303 req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req);
318 int rc, err; 318 int rc, err;
319 GSList *hosts = NULL; 319 GSList *hosts = NULL;
320 struct sockaddr *addr = NULL; 320 struct sockaddr *addr = NULL;
321 size_t addrlen; 321 size_t addrlen;
322 322
323 gaim_debug(GAIM_DEBUG_INFO, "dns", "Host '%s' resolved\n", req->host); 323 gaim_debug_info("dns", "Host '%s' resolved\n", req->host);
324 gaim_input_remove(req->inpa); 324 gaim_input_remove(req->inpa);
325 325
326 rc=read(req->fd_out, &err, sizeof(err)); 326 rc=read(req->fd_out, &err, sizeof(err));
327 if((rc==4) && (err!=0)) { 327 if((rc==4) && (err!=0)) {
328 char message[1024]; 328 char message[1024];
331 gai_strerror(err), req->dns_pid); 331 gai_strerror(err), req->dns_pid);
332 #else 332 #else
333 g_snprintf(message, sizeof(message), "DNS error: %d (pid=%d)", 333 g_snprintf(message, sizeof(message), "DNS error: %d (pid=%d)",
334 err, req->dns_pid); 334 err, req->dns_pid);
335 #endif 335 #endif
336 gaim_debug(GAIM_DEBUG_ERROR, "dns", "%s\n", message); 336 gaim_debug_error("dns", "%s\n", message);
337 req->callback(NULL, req->data, message); 337 req->callback(NULL, req->data, message);
338 release_dns_child(req); 338 release_dns_child(req);
339 return; 339 return;
340 } 340 }
341 if(rc>0) { 341 if(rc>0) {
351 } 351 }
352 } 352 }
353 } else if(rc==-1) { 353 } else if(rc==-1) {
354 char message[1024]; 354 char message[1024];
355 g_snprintf(message, sizeof(message), "Error reading from DNS child: %s",strerror(errno)); 355 g_snprintf(message, sizeof(message), "Error reading from DNS child: %s",strerror(errno));
356 gaim_debug(GAIM_DEBUG_ERROR, "dns", "%s\n", message); 356 gaim_debug_error("dns", "%s\n", message);
357 req->callback(NULL, req->data, message); 357 req->callback(NULL, req->data, message);
358 req_free(req); 358 req_free(req);
359 return; 359 return;
360 } else if(rc==0) { 360 } else if(rc==0) {
361 char message[1024]; 361 char message[1024];
362 g_snprintf(message, sizeof(message), "EOF reading from DNS child"); 362 g_snprintf(message, sizeof(message), "EOF reading from DNS child");
363 close(req->fd_out); 363 close(req->fd_out);
364 gaim_debug(GAIM_DEBUG_ERROR, "dns", "%s\n", message); 364 gaim_debug_error("dns", "%s\n", message);
365 req->callback(NULL, req->data, message); 365 req->callback(NULL, req->data, message);
366 req_free(req); 366 req_free(req);
367 return; 367 return;
368 } 368 }
369 369
408 return; 408 return;
409 409
410 e[MIN(n,sizeof(e)-1)] = '\0'; 410 e[MIN(n,sizeof(e)-1)] = '\0';
411 411
412 if(strstr(e,"gdb")) { 412 if(strstr(e,"gdb")) {
413 gaim_debug(GAIM_DEBUG_INFO, "dns", 413 gaim_debug_info("dns",
414 "Debugger detected, performing useless query...\n"); 414 "Debugger detected, performing useless query...\n");
415 gethostbyname("x.x.x.x.x"); 415 gethostbyname("x.x.x.x.x");
416 } 416 }
417 #endif 417 #endif
418 } 418 }
575 r->data = data; 575 r->data = data;
576 if (!queued_requests) 576 if (!queued_requests)
577 queued_requests = g_queue_new(); 577 queued_requests = g_queue_new();
578 g_queue_push_tail(queued_requests, r); 578 g_queue_push_tail(queued_requests, r);
579 579
580 gaim_debug(GAIM_DEBUG_INFO, "dns", 580 gaim_debug_info("dns",
581 "DNS query for '%s' queued\n", dns_params.hostname); 581 "DNS query for '%s' queued\n", dns_params.hostname);
582 582
583 return 0; 583 return 0;
584 } 584 }
585 585
586 /* Create pipes for communicating with the child process */ 586 /* Create pipes for communicating with the child process */
587 if (pipe(child_out) || pipe(child_in)) { 587 if (pipe(child_out) || pipe(child_in)) {
588 gaim_debug(GAIM_DEBUG_ERROR, "dns", 588 gaim_debug_error("dns",
589 "Could not create pipes: %s\n", strerror(errno)); 589 "Could not create pipes: %s\n", strerror(errno));
590 return -1; 590 return -1;
591 } 591 }
592 592
593 req = g_new(pending_dns_request_t, 1); 593 req = g_new(pending_dns_request_t, 1);
609 609
610 /* We should not access the child's side of the pipe, so close them... */ 610 /* We should not access the child's side of the pipe, so close them... */
611 close(child_out[1]); 611 close(child_out[1]);
612 close(child_in[0]); 612 close(child_in[0]);
613 if (req->dns_pid == -1) { 613 if (req->dns_pid == -1) {
614 gaim_debug(GAIM_DEBUG_ERROR, "dns", 614 gaim_debug_error("dns",
615 "Could not create child process for DNS: %s\n", 615 "Could not create child process for DNS: %s\n",
616 strerror(errno)); 616 strerror(errno));
617 g_free(req); 617 g_free(req);
618 return -1; 618 return -1;
619 } 619 }
620 620
621 req->fd_out = child_out[0]; 621 req->fd_out = child_out[0];
622 req->fd_in = child_in[1]; 622 req->fd_in = child_in[1];
623 number_of_dns_children++; 623 number_of_dns_children++;
624 gaim_debug(GAIM_DEBUG_INFO, "dns", 624 gaim_debug_info("dns",
625 "Created new DNS child %d, there are now %d children.\n", 625 "Created new DNS child %d, there are now %d children.\n",
626 req->dns_pid, number_of_dns_children); 626 req->dns_pid, number_of_dns_children);
627 } 627 }
628 628
629 req->host = g_strdup(hostname); 629 req->host = g_strdup(hostname);
742 pending_dns_request_t *req; 742 pending_dns_request_t *req;
743 743
744 if (!inet_aton(hostname, &sin.sin_addr)) { 744 if (!inet_aton(hostname, &sin.sin_addr)) {
745 struct hostent *hp; 745 struct hostent *hp;
746 if(!(hp = gethostbyname(hostname))) { 746 if(!(hp = gethostbyname(hostname))) {
747 gaim_debug(GAIM_DEBUG_ERROR, "dns", 747 gaim_debug_error("dns",
748 "gaim_gethostbyname(\"%s\", %d) failed: %d\n", 748 "gaim_gethostbyname(\"%s\", %d) failed: %d\n",
749 hostname, port, h_errno); 749 hostname, port, h_errno);
750 return -1; 750 return -1;
751 } 751 }
752 memset(&sin, 0, sizeof(struct sockaddr_in)); 752 memset(&sin, 0, sizeof(struct sockaddr_in));
772 { 772 {
773 struct PHB *phb = data; 773 struct PHB *phb = data;
774 unsigned int len; 774 unsigned int len;
775 int error=0, ret; 775 int error=0, ret;
776 776
777 gaim_debug(GAIM_DEBUG_INFO, "proxy", "Connected.\n"); 777 gaim_debug_info("proxy", "Connected.\n");
778 778
779 len = sizeof(error); 779 len = sizeof(error);
780 780
781 /* 781 /*
782 * getsockopt after a non-blocking connect returns -1 if something is 782 * getsockopt after a non-blocking connect returns -1 if something is
795 if (ret < 0 || error != 0) { 795 if (ret < 0 || error != 0) {
796 if(ret!=0) error = errno; 796 if(ret!=0) error = errno;
797 close(source); 797 close(source);
798 gaim_input_remove(phb->inpa); 798 gaim_input_remove(phb->inpa);
799 799
800 gaim_debug(GAIM_DEBUG_ERROR, "proxy", 800 gaim_debug_error("proxy",
801 "getsockopt SO_ERROR check: %s\n", strerror(error)); 801 "getsockopt SO_ERROR check: %s\n", strerror(error));
802 802
803 try_connect(phb); 803 try_connect(phb);
804 return; 804 return;
805 } 805 }
837 static int 837 static int
838 proxy_connect_none(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen) 838 proxy_connect_none(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen)
839 { 839 {
840 int fd = -1; 840 int fd = -1;
841 841
842 gaim_debug(GAIM_DEBUG_INFO, "proxy", 842 gaim_debug_info("proxy",
843 "Connecting to %s:%d with no proxy\n", phb->host, phb->port); 843 "Connecting to %s:%d with no proxy\n", phb->host, phb->port);
844 844
845 if ((fd = socket(addr->sa_family, SOCK_STREAM, 0)) < 0) { 845 if ((fd = socket(addr->sa_family, SOCK_STREAM, 0)) < 0) {
846 gaim_debug(GAIM_DEBUG_ERROR, "proxy", 846 gaim_debug_error("proxy",
847 "Unable to create socket: %s\n", strerror(errno)); 847 "Unable to create socket: %s\n", strerror(errno));
848 return -1; 848 return -1;
849 } 849 }
850 fcntl(fd, F_SETFL, O_NONBLOCK); 850 fcntl(fd, F_SETFL, O_NONBLOCK);
851 #ifndef _WIN32 851 #ifndef _WIN32
852 fcntl(fd, F_SETFD, FD_CLOEXEC); 852 fcntl(fd, F_SETFD, FD_CLOEXEC);
853 #endif 853 #endif
854 854
855 if (connect(fd, (struct sockaddr *)addr, addrlen) < 0) { 855 if (connect(fd, (struct sockaddr *)addr, addrlen) < 0) {
856 if ((errno == EINPROGRESS) || (errno == EINTR)) { 856 if ((errno == EINPROGRESS) || (errno == EINTR)) {
857 gaim_debug(GAIM_DEBUG_WARNING, "proxy", 857 gaim_debug_warning("proxy",
858 "Connect would have blocked.\n"); 858 "Connect would have blocked.\n");
859 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, no_one_calls, phb); 859 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, no_one_calls, phb);
860 } 860 }
861 else { 861 else {
862 gaim_debug(GAIM_DEBUG_ERROR, "proxy", 862 gaim_debug_error("proxy",
863 "Connect failed: %s\n", strerror(errno)); 863 "Connect failed: %s\n", strerror(errno));
864 close(fd); 864 close(fd);
865 return -1; 865 return -1;
866 } 866 }
867 } 867 }
868 else { 868 else {
869 unsigned int len; 869 unsigned int len;
870 int error = ETIMEDOUT; 870 int error = ETIMEDOUT;
871 gaim_debug(GAIM_DEBUG_MISC, "proxy", "Connect didn't block.\n"); 871 gaim_debug_misc("proxy", "Connect didn't block.\n");
872 len = sizeof(error); 872 len = sizeof(error);
873 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { 873 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
874 gaim_debug(GAIM_DEBUG_ERROR, "proxy", "getsockopt failed.\n"); 874 gaim_debug_error("proxy", "getsockopt failed.\n");
875 close(fd); 875 close(fd);
876 return -1; 876 return -1;
877 } 877 }
878 fcntl(fd, F_SETFL, 0); 878 fcntl(fd, F_SETFL, 0);
879 phb->port = fd; /* bleh */ 879 phb->port = fd; /* bleh */
889 #define HTTP_GOODSTRING2 "HTTP/1.1 200" 889 #define HTTP_GOODSTRING2 "HTTP/1.1 200"
890 890
891 static void 891 static void
892 http_complete(struct PHB *phb, gint source) 892 http_complete(struct PHB *phb, gint source)
893 { 893 {
894 gaim_debug(GAIM_DEBUG_INFO, "http proxy", "proxy connection established\n"); 894 gaim_debug_info("http proxy", "proxy connection established\n");
895 if(source < 0) { 895 if(source < 0) {
896 try_connect(phb); 896 try_connect(phb);
897 } else if(!phb->account || phb->account->gc) { 897 } else if(!phb->account || phb->account->gc) {
898 phb->func(phb->data, source, GAIM_INPUT_READ); 898 phb->func(phb->data, source, GAIM_INPUT_READ);
899 g_free(phb->host); 899 g_free(phb->host);
938 } 938 }
939 } 939 }
940 } 940 }
941 941
942 if(error) { 942 if(error) {
943 gaim_debug(GAIM_DEBUG_ERROR, "proxy", 943 gaim_debug_error("proxy",
944 "Unable to parse proxy's response: %s\n", inputline); 944 "Unable to parse proxy's response: %s\n", inputline);
945 close(source); 945 close(source);
946 source=-1; 946 source=-1;
947 } 947 }
948 else if(status!=200) { 948 else if(status!=200) {
949 gaim_debug(GAIM_DEBUG_ERROR, "proxy", 949 gaim_debug_error("proxy",
950 "Proxy server replied with:\n%s\n", p); 950 "Proxy server replied with:\n%s\n", p);
951 close(source); 951 close(source);
952 source = -1; 952 source = -1;
953 953
954 /* XXX: why in the hell are we calling gaim_connection_error() here? */ 954 /* XXX: why in the hell are we calling gaim_connection_error() here? */
976 int request_len = 0; 976 int request_len = 0;
977 struct PHB *phb = data; 977 struct PHB *phb = data;
978 unsigned int len; 978 unsigned int len;
979 int error = ETIMEDOUT; 979 int error = ETIMEDOUT;
980 980
981 gaim_debug(GAIM_DEBUG_INFO, "http proxy", "Connected.\n"); 981 gaim_debug_info("http proxy", "Connected.\n");
982 982
983 if (phb->inpa > 0) 983 if (phb->inpa > 0)
984 gaim_input_remove(phb->inpa); 984 gaim_input_remove(phb->inpa);
985 985
986 len = sizeof(error); 986 len = sizeof(error);
990 990
991 try_connect(phb); 991 try_connect(phb);
992 return; 992 return;
993 } 993 }
994 994
995 gaim_debug(GAIM_DEBUG_INFO, "proxy", "using CONNECT tunnelling for %s:%d\n", phb->host, phb->port); 995 gaim_debug_info("proxy", "using CONNECT tunnelling for %s:%d\n", phb->host, phb->port);
996 request_len = g_snprintf(request, sizeof(request), 996 request_len = g_snprintf(request, sizeof(request),
997 "CONNECT %s:%d HTTP/1.1\r\nHost: %s:%d\r\n", 997 "CONNECT %s:%d HTTP/1.1\r\nHost: %s:%d\r\n",
998 phb->host, phb->port, phb->host, phb->port); 998 phb->host, phb->port, phb->host, phb->port);
999 999
1000 if (gaim_proxy_info_get_username(phb->gpi) != NULL) { 1000 if (gaim_proxy_info_get_username(phb->gpi) != NULL) {
1030 static int 1030 static int
1031 proxy_connect_http(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen) 1031 proxy_connect_http(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen)
1032 { 1032 {
1033 int fd = -1; 1033 int fd = -1;
1034 1034
1035 gaim_debug(GAIM_DEBUG_INFO, "http proxy", 1035 gaim_debug_info("http proxy",
1036 "Connecting to %s:%d via %s:%d using HTTP\n", 1036 "Connecting to %s:%d via %s:%d using HTTP\n",
1037 phb->host, phb->port, 1037 phb->host, phb->port,
1038 gaim_proxy_info_get_host(phb->gpi), 1038 gaim_proxy_info_get_host(phb->gpi),
1039 gaim_proxy_info_get_port(phb->gpi)); 1039 gaim_proxy_info_get_port(phb->gpi));
1040 1040
1047 fcntl(fd, F_SETFD, FD_CLOEXEC); 1047 fcntl(fd, F_SETFD, FD_CLOEXEC);
1048 #endif 1048 #endif
1049 1049
1050 if (connect(fd, addr, addrlen) < 0) { 1050 if (connect(fd, addr, addrlen) < 0) {
1051 if ((errno == EINPROGRESS) || (errno == EINTR)) { 1051 if ((errno == EINPROGRESS) || (errno == EINTR)) {
1052 gaim_debug(GAIM_DEBUG_WARNING, "http proxy", 1052 gaim_debug_warning("http proxy",
1053 "Connect would have blocked.\n"); 1053 "Connect would have blocked.\n");
1054 1054
1055 if (phb->port != 80) { 1055 if (phb->port != 80) {
1056 /* we need to do CONNECT first */ 1056 /* we need to do CONNECT first */
1057 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, 1057 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE,
1066 } 1066 }
1067 else { 1067 else {
1068 unsigned int len; 1068 unsigned int len;
1069 int error = ETIMEDOUT; 1069 int error = ETIMEDOUT;
1070 1070
1071 gaim_debug(GAIM_DEBUG_MISC, "http proxy", 1071 gaim_debug_misc("http proxy",
1072 "Connect didn't block.\n"); 1072 "Connect didn't block.\n");
1073 1073
1074 len = sizeof(error); 1074 len = sizeof(error);
1075 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { 1075 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
1076 close(fd); 1076 close(fd);
1117 struct hostent *hp; 1117 struct hostent *hp;
1118 struct PHB *phb = data; 1118 struct PHB *phb = data;
1119 unsigned int len; 1119 unsigned int len;
1120 int error = ETIMEDOUT; 1120 int error = ETIMEDOUT;
1121 1121
1122 gaim_debug(GAIM_DEBUG_INFO, "s4 proxy", "Connected.\n"); 1122 gaim_debug_info("s4 proxy", "Connected.\n");
1123 1123
1124 if (phb->inpa > 0) 1124 if (phb->inpa > 0)
1125 gaim_input_remove(phb->inpa); 1125 gaim_input_remove(phb->inpa);
1126 1126
1127 len = sizeof(error); 1127 len = sizeof(error);
1165 static int 1165 static int
1166 proxy_connect_socks4(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen) 1166 proxy_connect_socks4(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen)
1167 { 1167 {
1168 int fd = -1; 1168 int fd = -1;
1169 1169
1170 gaim_debug(GAIM_DEBUG_INFO, "socks4 proxy", 1170 gaim_debug_info("socks4 proxy",
1171 "Connecting to %s:%d via %s:%d using SOCKS4\n", 1171 "Connecting to %s:%d via %s:%d using SOCKS4\n",
1172 phb->host, phb->port, 1172 phb->host, phb->port,
1173 gaim_proxy_info_get_host(phb->gpi), 1173 gaim_proxy_info_get_host(phb->gpi),
1174 gaim_proxy_info_get_port(phb->gpi)); 1174 gaim_proxy_info_get_port(phb->gpi));
1175 1175
1181 fcntl(fd, F_SETFD, FD_CLOEXEC); 1181 fcntl(fd, F_SETFD, FD_CLOEXEC);
1182 #endif 1182 #endif
1183 1183
1184 if (connect(fd, addr, addrlen) < 0) { 1184 if (connect(fd, addr, addrlen) < 0) {
1185 if ((errno == EINPROGRESS) || (errno == EINTR)) { 1185 if ((errno == EINPROGRESS) || (errno == EINTR)) {
1186 gaim_debug(GAIM_DEBUG_WARNING, "socks4 proxy", 1186 gaim_debug_warning("socks4 proxy",
1187 "Connect would have blocked.\n"); 1187 "Connect would have blocked.\n");
1188 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, s4_canwrite, phb); 1188 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, s4_canwrite, phb);
1189 } 1189 }
1190 else { 1190 else {
1191 close(fd); 1191 close(fd);
1193 } 1193 }
1194 } else { 1194 } else {
1195 unsigned int len; 1195 unsigned int len;
1196 int error = ETIMEDOUT; 1196 int error = ETIMEDOUT;
1197 1197
1198 gaim_debug(GAIM_DEBUG_MISC, "socks4 proxy", 1198 gaim_debug_misc("socks4 proxy",
1199 "Connect didn't block.\n"); 1199 "Connect didn't block.\n");
1200 1200
1201 len = sizeof(error); 1201 len = sizeof(error);
1202 1202
1203 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { 1203 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
1217 { 1217 {
1218 unsigned char buf[512]; 1218 unsigned char buf[512];
1219 struct PHB *phb = data; 1219 struct PHB *phb = data;
1220 1220
1221 gaim_input_remove(phb->inpa); 1221 gaim_input_remove(phb->inpa);
1222 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", "Able to read again.\n"); 1222 gaim_debug_info("socks5 proxy", "Able to read again.\n");
1223 1223
1224 if (read(source, buf, 4) < 4) { 1224 if (read(source, buf, 4) < 4) {
1225 gaim_debug(GAIM_DEBUG_WARNING, "socks5 proxy", "or not...\n"); 1225 gaim_debug_warning("socks5 proxy", "or not...\n");
1226 close(source); 1226 close(source);
1227 1227
1228 try_connect(phb); 1228 try_connect(phb);
1229 return; 1229 return;
1230 } 1230 }
1231 if ((buf[0] != 0x05) || (buf[1] != 0x00)) { 1231 if ((buf[0] != 0x05) || (buf[1] != 0x00)) {
1232 if ((buf[0] == 0x05) && (buf[1] < 0x09)) 1232 if ((buf[0] == 0x05) && (buf[1] < 0x09))
1233 gaim_debug(GAIM_DEBUG_ERROR, "socks5 proxy", socks5errors[buf[1]]); 1233 gaim_debug_error("socks5 proxy", socks5errors[buf[1]]);
1234 else 1234 else
1235 gaim_debug(GAIM_DEBUG_ERROR, "socks5 proxy", "Bad data.\n"); 1235 gaim_debug_error("socks5 proxy", "Bad data.\n");
1236 close(source); 1236 close(source);
1237 1237
1238 try_connect(phb); 1238 try_connect(phb);
1239 return; 1239 return;
1240 } 1240 }
1299 { 1299 {
1300 unsigned char buf[512]; 1300 unsigned char buf[512];
1301 struct PHB *phb = data; 1301 struct PHB *phb = data;
1302 1302
1303 gaim_input_remove(phb->inpa); 1303 gaim_input_remove(phb->inpa);
1304 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", "Got auth response.\n"); 1304 gaim_debug_info("socks5 proxy", "Got auth response.\n");
1305 1305
1306 if (read(source, buf, 2) < 2) { 1306 if (read(source, buf, 2) < 2) {
1307 close(source); 1307 close(source);
1308 1308
1309 try_connect(phb); 1309 try_connect(phb);
1325 { 1325 {
1326 unsigned char buf[512]; 1326 unsigned char buf[512];
1327 struct PHB *phb = data; 1327 struct PHB *phb = data;
1328 1328
1329 gaim_input_remove(phb->inpa); 1329 gaim_input_remove(phb->inpa);
1330 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", "Able to read.\n"); 1330 gaim_debug_info("socks5 proxy", "Able to read.\n");
1331 1331
1332 if (read(source, buf, 2) < 2) { 1332 if (read(source, buf, 2) < 2) {
1333 close(source); 1333 close(source);
1334 1334
1335 try_connect(phb); 1335 try_connect(phb);
1376 int i; 1376 int i;
1377 struct PHB *phb = data; 1377 struct PHB *phb = data;
1378 unsigned int len; 1378 unsigned int len;
1379 int error = ETIMEDOUT; 1379 int error = ETIMEDOUT;
1380 1380
1381 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", "Connected.\n"); 1381 gaim_debug_info("socks5 proxy", "Connected.\n");
1382 1382
1383 if (phb->inpa > 0) 1383 if (phb->inpa > 0)
1384 gaim_input_remove(phb->inpa); 1384 gaim_input_remove(phb->inpa);
1385 1385
1386 len = sizeof(error); 1386 len = sizeof(error);
1406 buf[2] = 0x00; 1406 buf[2] = 0x00;
1407 i = 3; 1407 i = 3;
1408 } 1408 }
1409 1409
1410 if (write(source, buf, i) < i) { 1410 if (write(source, buf, i) < i) {
1411 gaim_debug(GAIM_DEBUG_ERROR, "socks5 proxy", "Unable to write\n"); 1411 gaim_debug_error("socks5 proxy", "Unable to write\n");
1412 close(source); 1412 close(source);
1413 1413
1414 try_connect(phb); 1414 try_connect(phb);
1415 return; 1415 return;
1416 } 1416 }
1421 static int 1421 static int
1422 proxy_connect_socks5(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen) 1422 proxy_connect_socks5(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen)
1423 { 1423 {
1424 int fd = -1; 1424 int fd = -1;
1425 1425
1426 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", 1426 gaim_debug_info("socks5 proxy",
1427 "Connecting to %s:%d via %s:%d using SOCKS5\n", 1427 "Connecting to %s:%d via %s:%d using SOCKS5\n",
1428 phb->host, phb->port, 1428 phb->host, phb->port,
1429 gaim_proxy_info_get_host(phb->gpi), 1429 gaim_proxy_info_get_host(phb->gpi),
1430 gaim_proxy_info_get_port(phb->gpi)); 1430 gaim_proxy_info_get_port(phb->gpi));
1431 1431
1437 fcntl(fd, F_SETFD, FD_CLOEXEC); 1437 fcntl(fd, F_SETFD, FD_CLOEXEC);
1438 #endif 1438 #endif
1439 1439
1440 if (connect(fd, addr, addrlen) < 0) { 1440 if (connect(fd, addr, addrlen) < 0) {
1441 if ((errno == EINPROGRESS) || (errno == EINTR)) { 1441 if ((errno == EINPROGRESS) || (errno == EINTR)) {
1442 gaim_debug(GAIM_DEBUG_WARNING, "socks5 proxy", 1442 gaim_debug_warning("socks5 proxy",
1443 "Connect would have blocked.\n"); 1443 "Connect would have blocked.\n");
1444 1444
1445 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, s5_canwrite, phb); 1445 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, s5_canwrite, phb);
1446 } 1446 }
1447 else { 1447 else {
1451 } 1451 }
1452 else { 1452 else {
1453 unsigned int len; 1453 unsigned int len;
1454 int error = ETIMEDOUT; 1454 int error = ETIMEDOUT;
1455 1455
1456 gaim_debug(GAIM_DEBUG_MISC, "socks5 proxy", 1456 gaim_debug_misc("socks5 proxy",
1457 "Connect didn't block.\n"); 1457 "Connect didn't block.\n");
1458 1458
1459 len = sizeof(error); 1459 len = sizeof(error);
1460 1460
1461 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { 1461 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {