Mercurial > pidgin
comparison src/proxy.c @ 2907:28cd1b9d08a1
[gaim-migrate @ 2920]
evidently this broke things.
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Fri, 21 Dec 2001 22:42:41 +0000 |
| parents | 538c58b43eff |
| children | 4790fb1272a1 |
comparison
equal
deleted
inserted
replaced
| 2906:538c58b43eff | 2907:28cd1b9d08a1 |
|---|---|
| 31 #include <string.h> | 31 #include <string.h> |
| 32 #include <sys/types.h> | 32 #include <sys/types.h> |
| 33 #include <sys/socket.h> | 33 #include <sys/socket.h> |
| 34 #include <netdb.h> | 34 #include <netdb.h> |
| 35 #include <netinet/in.h> | 35 #include <netinet/in.h> |
| 36 #include <arpa/inet.h> | |
| 37 #include <unistd.h> | 36 #include <unistd.h> |
| 38 #include <fcntl.h> | 37 #include <fcntl.h> |
| 39 #include <errno.h> | 38 #include <errno.h> |
| 40 #include "gaim.h" | 39 #include "gaim.h" |
| 41 #include "proxy.h" | 40 #include "proxy.h" |
| 117 /* debug_printf("CLOSURE: removing input watcher %d\n", tag); */ | 116 /* debug_printf("CLOSURE: removing input watcher %d\n", tag); */ |
| 118 if (tag > 0) | 117 if (tag > 0) |
| 119 g_source_remove(tag); | 118 g_source_remove(tag); |
| 120 } | 119 } |
| 121 | 120 |
| 122 static struct sockaddr_in *gaim_gethostbyname(char *host) | |
| 123 { | |
| 124 static struct sockaddr_in sin; | |
| 125 | |
| 126 if (!inet_aton(host, &sin.sin_addr)) { | |
| 127 struct hostent *hp; | |
| 128 if (!(hp = gethostbyname(host))) { | |
| 129 return NULL; | |
| 130 } | |
| 131 memset(&sin, 0, sizeof(struct sockaddr_in)); | |
| 132 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); | |
| 133 sin.sin_family = hp->h_addrtype; | |
| 134 } else | |
| 135 sin.sin_family = AF_INET; | |
| 136 | |
| 137 return &sin; | |
| 138 } | |
| 139 | |
| 140 static void no_one_calls(gpointer data, gint source, GaimInputCondition cond) | 121 static void no_one_calls(gpointer data, gint source, GaimInputCondition cond) |
| 141 { | 122 { |
| 142 struct PHB *phb = data; | 123 struct PHB *phb = data; |
| 143 unsigned int len; | 124 unsigned int len; |
| 144 int error = ETIMEDOUT; | 125 int error = ETIMEDOUT; |
| 168 } | 149 } |
| 169 | 150 |
| 170 | 151 |
| 171 static int proxy_connect_none(char *host, unsigned short port, struct PHB *phb) | 152 static int proxy_connect_none(char *host, unsigned short port, struct PHB *phb) |
| 172 { | 153 { |
| 173 struct sockaddr_in *sin; | 154 struct sockaddr_in sin; |
| 155 struct hostent *hp; | |
| 174 int fd = -1; | 156 int fd = -1; |
| 175 | 157 |
| 176 debug_printf("connecting to %s:%d with no proxy\n", host, port); | 158 debug_printf("connecting to %s:%d with no proxy\n", host, port); |
| 177 | 159 |
| 178 if (!(sin = gaim_gethostbyname(host))) { | 160 if (!(hp = gethostbyname(host))) { |
| 179 debug_printf("gethostbyname failed\n"); | 161 debug_printf("gethostbyname failed\n"); |
| 180 g_free(phb); | 162 g_free(phb); |
| 181 return -1; | 163 return -1; |
| 182 } | 164 } |
| 183 | 165 |
| 184 if ((fd = socket(sin->sin_family, SOCK_STREAM, 0)) < 0) { | 166 memset(&sin, 0, sizeof(struct sockaddr_in)); |
| 167 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); | |
| 168 sin.sin_family = hp->h_addrtype; | |
| 169 sin.sin_port = htons(port); | |
| 170 | |
| 171 if ((fd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) { | |
| 185 debug_printf("unable to create socket\n"); | 172 debug_printf("unable to create socket\n"); |
| 186 g_free(phb); | 173 g_free(phb); |
| 187 return -1; | 174 return -1; |
| 188 } | 175 } |
| 189 | 176 |
| 190 fcntl(fd, F_SETFL, O_NONBLOCK); | 177 fcntl(fd, F_SETFL, O_NONBLOCK); |
| 191 if (connect(fd, (struct sockaddr *)sin, sizeof(*sin)) < 0) { | 178 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { |
| 192 if ((errno == EINPROGRESS) || (errno == EINTR)) { | 179 if ((errno == EINPROGRESS) || (errno == EINTR)) { |
| 193 debug_printf("Connect would have blocked\n"); | 180 debug_printf("Connect would have blocked\n"); |
| 194 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, no_one_calls, phb); | 181 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, no_one_calls, phb); |
| 195 } else { | 182 } else { |
| 196 debug_printf("connect failed (errno %d)\n", errno); | 183 debug_printf("connect failed (errno %d)\n", errno); |
| 313 phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, http_canread, phb); | 300 phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, http_canread, phb); |
| 314 } | 301 } |
| 315 | 302 |
| 316 static int proxy_connect_http(char *host, unsigned short port, struct PHB *phb) | 303 static int proxy_connect_http(char *host, unsigned short port, struct PHB *phb) |
| 317 { | 304 { |
| 318 struct sockaddr_in *sin; | 305 struct hostent *hp; |
| 306 struct sockaddr_in sin; | |
| 319 int fd = -1; | 307 int fd = -1; |
| 320 | 308 |
| 321 debug_printf("connecting to %s:%d via %s:%d using HTTP\n", host, port, proxyhost, proxyport); | 309 debug_printf("connecting to %s:%d via %s:%d using HTTP\n", host, port, proxyhost, proxyport); |
| 322 | 310 |
| 323 if (!(sin = gaim_gethostbyname(proxyhost))) { | 311 if (!(hp = gethostbyname(proxyhost))) { |
| 324 g_free(phb); | 312 g_free(phb); |
| 325 return -1; | 313 return -1; |
| 326 } | 314 } |
| 327 | 315 |
| 328 if ((fd = socket(sin->sin_family, SOCK_STREAM, 0)) < 0) { | 316 memset(&sin, 0, sizeof(struct sockaddr_in)); |
| 317 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); | |
| 318 sin.sin_family = hp->h_addrtype; | |
| 319 sin.sin_port = htons(proxyport); | |
| 320 | |
| 321 if ((fd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) { | |
| 329 g_free(phb); | 322 g_free(phb); |
| 330 return -1; | 323 return -1; |
| 331 } | 324 } |
| 332 | 325 |
| 333 phb->host = g_strdup(host); | 326 phb->host = g_strdup(host); |
| 334 phb->port = port; | 327 phb->port = port; |
| 335 | 328 |
| 336 fcntl(fd, F_SETFL, O_NONBLOCK); | 329 fcntl(fd, F_SETFL, O_NONBLOCK); |
| 337 if (connect(fd, (struct sockaddr *)sin, sizeof(*sin)) < 0) { | 330 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { |
| 338 if ((errno == EINPROGRESS) || (errno == EINTR)) { | 331 if ((errno == EINPROGRESS) || (errno == EINTR)) { |
| 339 debug_printf("Connect would have blocked\n"); | 332 debug_printf("Connect would have blocked\n"); |
| 340 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, http_canwrite, phb); | 333 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, http_canwrite, phb); |
| 341 } else { | 334 } else { |
| 342 close(fd); | 335 close(fd); |
| 432 phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, s4_canread, phb); | 425 phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, s4_canread, phb); |
| 433 } | 426 } |
| 434 | 427 |
| 435 static int proxy_connect_socks4(char *host, unsigned short port, struct PHB *phb) | 428 static int proxy_connect_socks4(char *host, unsigned short port, struct PHB *phb) |
| 436 { | 429 { |
| 437 struct sockaddr_in *sin; | 430 struct sockaddr_in sin; |
| 431 struct hostent *hp; | |
| 438 int fd = -1; | 432 int fd = -1; |
| 439 | 433 |
| 440 debug_printf("connecting to %s:%d via %s:%d using SOCKS4\n", host, port, proxyhost, proxyport); | 434 debug_printf("connecting to %s:%d via %s:%d using SOCKS4\n", host, port, proxyhost, proxyport); |
| 441 | 435 |
| 442 if (!(sin = gaim_gethostbyname(proxyhost))) { | 436 if (!(hp = gethostbyname(proxyhost))) { |
| 443 g_free(phb); | 437 g_free(phb); |
| 444 return -1; | 438 return -1; |
| 445 } | 439 } |
| 446 | 440 |
| 447 if ((fd = socket(sin->sin_family, SOCK_STREAM, 0)) < 0) { | 441 memset(&sin, 0, sizeof(struct sockaddr_in)); |
| 442 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); | |
| 443 sin.sin_family = hp->h_addrtype; | |
| 444 sin.sin_port = htons(proxyport); | |
| 445 | |
| 446 if ((fd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) { | |
| 448 g_free(phb); | 447 g_free(phb); |
| 449 return -1; | 448 return -1; |
| 450 } | 449 } |
| 451 | 450 |
| 452 phb->host = g_strdup(host); | 451 phb->host = g_strdup(host); |
| 453 phb->port = port; | 452 phb->port = port; |
| 454 | 453 |
| 455 fcntl(fd, F_SETFL, O_NONBLOCK); | 454 fcntl(fd, F_SETFL, O_NONBLOCK); |
| 456 if (connect(fd, (struct sockaddr *)sin, sizeof(*sin)) < 0) { | 455 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { |
| 457 if ((errno == EINPROGRESS) || (errno == EINTR)) { | 456 if ((errno == EINPROGRESS) || (errno == EINTR)) { |
| 458 debug_printf("Connect would have blocked\n"); | 457 debug_printf("Connect would have blocked\n"); |
| 459 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, s4_canwrite, phb); | 458 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, s4_canwrite, phb); |
| 460 } else { | 459 } else { |
| 461 close(fd); | 460 close(fd); |
| 655 phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, s5_canread, phb); | 654 phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, s5_canread, phb); |
| 656 } | 655 } |
| 657 | 656 |
| 658 static int proxy_connect_socks5(char *host, unsigned short port, struct PHB *phb) | 657 static int proxy_connect_socks5(char *host, unsigned short port, struct PHB *phb) |
| 659 { | 658 { |
| 660 struct sockaddr_in *sin; | |
| 661 int fd = -1; | 659 int fd = -1; |
| 660 struct sockaddr_in sin; | |
| 661 struct hostent *hp; | |
| 662 | 662 |
| 663 debug_printf("connecting to %s:%d via %s:%d using SOCKS5\n", host, port, proxyhost, proxyport); | 663 debug_printf("connecting to %s:%d via %s:%d using SOCKS5\n", host, port, proxyhost, proxyport); |
| 664 | 664 |
| 665 if (!(sin = gaim_gethostbyname(proxyhost))) { | 665 if (!(hp = gethostbyname(proxyhost))) { |
| 666 g_free(phb); | 666 g_free(phb); |
| 667 return -1; | 667 return -1; |
| 668 } | 668 } |
| 669 | 669 |
| 670 if ((fd = socket(sin->sin_family, SOCK_STREAM, 0)) < 0) { | 670 memset(&sin, 0, sizeof(struct sockaddr_in)); |
| 671 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); | |
| 672 sin.sin_family = hp->h_addrtype; | |
| 673 sin.sin_port = htons(proxyport); | |
| 674 | |
| 675 if ((fd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) { | |
| 671 g_free(phb); | 676 g_free(phb); |
| 672 return -1; | 677 return -1; |
| 673 } | 678 } |
| 674 | 679 |
| 675 phb->host = g_strdup(host); | 680 phb->host = g_strdup(host); |
| 676 phb->port = port; | 681 phb->port = port; |
| 677 | 682 |
| 678 fcntl(fd, F_SETFL, O_NONBLOCK); | 683 fcntl(fd, F_SETFL, O_NONBLOCK); |
| 679 if (connect(fd, (struct sockaddr *)sin, sizeof(*sin)) < 0) { | 684 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { |
| 680 if ((errno == EINPROGRESS) || (errno == EINTR)) { | 685 if ((errno == EINPROGRESS) || (errno == EINTR)) { |
| 681 debug_printf("Connect would have blocked\n"); | 686 debug_printf("Connect would have blocked\n"); |
| 682 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, s5_canwrite, phb); | 687 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, s5_canwrite, phb); |
| 683 } else { | 688 } else { |
| 684 close(fd); | 689 close(fd); |
