Mercurial > pidgin
comparison src/proxy.c @ 9729:f44ae9331afc
[gaim-migrate @ 10590]
Use opt_debug less in proxy.c
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sun, 08 Aug 2004 19:01:42 +0000 |
| parents | 51464cbbdc1a |
| children | d9e8d420e9fe |
comparison
equal
deleted
inserted
replaced
| 9728:8be2c406a1f1 | 9729:f44ae9331afc |
|---|---|
| 34 #include "notify.h" | 34 #include "notify.h" |
| 35 #include "prefs.h" | 35 #include "prefs.h" |
| 36 #include "proxy.h" | 36 #include "proxy.h" |
| 37 #include "util.h" | 37 #include "util.h" |
| 38 | 38 |
| 39 #include "gaim.h" | |
| 40 | |
| 39 static GaimProxyInfo *global_proxy_info = NULL; | 41 static GaimProxyInfo *global_proxy_info = NULL; |
| 40 | |
| 41 static int opt_debug = 0; | |
| 42 | 42 |
| 43 struct PHB { | 43 struct PHB { |
| 44 GaimInputFunction func; | 44 GaimInputFunction func; |
| 45 gpointer data; | 45 gpointer data; |
| 46 char *host; | 46 char *host; |
| 416 } | 416 } |
| 417 #endif | 417 #endif |
| 418 } | 418 } |
| 419 | 419 |
| 420 static void | 420 static void |
| 421 gaim_dns_childthread(int child_out, int child_in, dns_params_t *dns_params) | 421 gaim_dns_childthread(int child_out, int child_in, dns_params_t *dns_params, gboolean show_debug) |
| 422 { | 422 { |
| 423 const int zero = 0; | 423 const int zero = 0; |
| 424 int rc; | 424 int rc; |
| 425 #if HAVE_GETADDRINFO | 425 #if HAVE_GETADDRINFO |
| 426 struct addrinfo hints, *res, *tmp; | 426 struct addrinfo hints, *res, *tmp; |
| 446 struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 }; | 446 struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 }; |
| 447 FD_ZERO(&fds); | 447 FD_ZERO(&fds); |
| 448 FD_SET(child_in, &fds); | 448 FD_SET(child_in, &fds); |
| 449 rc = select(child_in + 1, &fds, NULL, NULL, &tv); | 449 rc = select(child_in + 1, &fds, NULL, NULL, &tv); |
| 450 if (!rc) { | 450 if (!rc) { |
| 451 if (opt_debug) | 451 if (show_debug) |
| 452 fprintf(stderr,"dns[%d]: nobody needs me... =(\n", getpid()); | 452 fprintf(stderr,"dns[%d]: nobody needs me... =(\n", getpid()); |
| 453 break; | 453 break; |
| 454 } | 454 } |
| 455 rc = read(child_in, dns_params, sizeof(dns_params_t)); | 455 rc = read(child_in, dns_params, sizeof(dns_params_t)); |
| 456 if (rc < 0) { | 456 if (rc < 0) { |
| 457 perror("read()"); | 457 perror("read()"); |
| 458 break; | 458 break; |
| 459 } | 459 } |
| 460 if (rc==0) { | 460 if (rc==0) { |
| 461 if(opt_debug) | 461 if (show_debug) |
| 462 fprintf(stderr,"dns[%d]: Ops, father has gone, wait for me, wait...!\n", getpid()); | 462 fprintf(stderr,"dns[%d]: Ops, father has gone, wait for me, wait...!\n", getpid()); |
| 463 _exit(0); | 463 _exit(0); |
| 464 } | 464 } |
| 465 if (dns_params->hostname[0] == '\0') { | 465 if (dns_params->hostname[0] == '\0') { |
| 466 fprintf(stderr, "dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params->port); | 466 fprintf(stderr, "dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params->port); |
| 479 * value will not be really used by the C | 479 * value will not be really used by the C |
| 480 * library. | 480 * library. |
| 481 */ | 481 */ |
| 482 hints.ai_socktype = SOCK_STREAM; | 482 hints.ai_socktype = SOCK_STREAM; |
| 483 rc = getaddrinfo(dns_params->hostname, servname, &hints, &res); | 483 rc = getaddrinfo(dns_params->hostname, servname, &hints, &res); |
| 484 if(rc) { | 484 if (rc) { |
| 485 write(child_out, &rc, sizeof(int)); | 485 write(child_out, &rc, sizeof(int)); |
| 486 close(child_out); | 486 close(child_out); |
| 487 if(opt_debug) | 487 if (show_debug) |
| 488 fprintf(stderr,"dns[%d] Error: getaddrinfo returned %d\n", | 488 fprintf(stderr,"dns[%d] Error: getaddrinfo returned %d\n", |
| 489 getpid(), rc); | 489 getpid(), rc); |
| 490 dns_params->hostname[0] = '\0'; | 490 dns_params->hostname[0] = '\0'; |
| 491 continue; | 491 continue; |
| 492 } | 492 } |
| 501 freeaddrinfo(tmp); | 501 freeaddrinfo(tmp); |
| 502 write(child_out, &zero, sizeof(zero)); | 502 write(child_out, &zero, sizeof(zero)); |
| 503 #else | 503 #else |
| 504 if (!inet_aton(hostname, &sin.sin_addr)) { | 504 if (!inet_aton(hostname, &sin.sin_addr)) { |
| 505 struct hostent *hp; | 505 struct hostent *hp; |
| 506 if(!(hp = gethostbyname(dns_params->hostname))) { | 506 if (!(hp = gethostbyname(dns_params->hostname))) { |
| 507 write(child_out, &h_errno, sizeof(int)); | 507 write(child_out, &h_errno, sizeof(int)); |
| 508 close(child_out); | 508 close(child_out); |
| 509 if(opt_debug) | 509 if (show_debug) |
| 510 fprintf(stderr,"DNS Error: %d\n", h_errno); | 510 fprintf(stderr,"DNS Error: %d\n", h_errno); |
| 511 _exit(0); | 511 _exit(0); |
| 512 } | 512 } |
| 513 memset(&sin, 0, sizeof(struct sockaddr_in)); | 513 memset(&sin, 0, sizeof(struct sockaddr_in)); |
| 514 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); | 514 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); |
| 593 | 593 |
| 594 /* Fork! */ | 594 /* Fork! */ |
| 595 req->dns_pid = fork(); | 595 req->dns_pid = fork(); |
| 596 | 596 |
| 597 /* If we are the child process... */ | 597 /* If we are the child process... */ |
| 598 if (req->dns_pid==0) { | 598 if (req->dns_pid == 0) { |
| 599 /* We should not access the parent's side of the pipe, so close them... */ | 599 /* We should not access the parent's side of the pipe, so close them... */ |
| 600 close(child_out[0]); | 600 close(child_out[0]); |
| 601 close(child_in[1]); | 601 close(child_in[1]); |
| 602 | 602 |
| 603 gaim_dns_childthread(child_out[1], child_in[0], &dns_params); | 603 gaim_dns_childthread(child_out[1], child_in[0], &dns_params, opt_debug); |
| 604 /* The thread calls _exit() rather than returning, so we never get here */ | 604 /* The thread calls _exit() rather than returning, so we never get here */ |
| 605 } | 605 } |
| 606 | 606 |
| 607 /* We should not access the child's side of the pipe, so close them... */ | 607 /* We should not access the child's side of the pipe, so close them... */ |
| 608 close(child_out[1]); | 608 close(child_out[1]); |
