Mercurial > pidgin.yaz
comparison src/proxy.c @ 1695:c0ab844d4790
[gaim-migrate @ 1705]
ugh
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 09 Apr 2001 20:53:47 +0000 |
parents | f6cc5cb7faf6 |
children | b4d454e5ee31 |
comparison
equal
deleted
inserted
replaced
1694:bea407767ac1 | 1695:c0ab844d4790 |
---|---|
36 #include <unistd.h> | 36 #include <unistd.h> |
37 #include <gtk/gtk.h> | 37 #include <gtk/gtk.h> |
38 #include "gaim.h" | 38 #include "gaim.h" |
39 #include "proxy.h" | 39 #include "proxy.h" |
40 | 40 |
41 /* this code is borrowed from cvs 1.10 */ | |
42 static int proxy_recv_line(int sock, char **resultp) | |
43 { | |
44 int c; | |
45 char *result; | |
46 size_t input_index = 0; | |
47 size_t result_size = 80; | |
48 | |
49 result = g_malloc(result_size); | |
50 | |
51 while (1) { | |
52 char ch; | |
53 if (recv(sock, &ch, 1, 0) < 0) | |
54 debug_printf("recv() error from proxy server\n"); | |
55 c = ch; | |
56 | |
57 if (c == EOF) { | |
58 g_free(result); | |
59 | |
60 /* It's end of file. */ | |
61 debug_printf("end of file from server\n"); | |
62 } | |
63 | |
64 if (c == '\012') | |
65 break; | |
66 | |
67 result[input_index++] = c; | |
68 while (input_index + 1 >= result_size) { | |
69 result_size *= 2; | |
70 result = (char *)g_realloc(result, result_size); | |
71 } | |
72 } | |
73 | |
74 if (resultp) | |
75 *resultp = result; | |
76 | |
77 /* Terminate it just for kicks, but we *can* deal with embedded NULs. */ | |
78 result[input_index] = '\0'; | |
79 | |
80 if (resultp == NULL) | |
81 g_free(result); | |
82 return input_index; | |
83 } | |
84 | |
85 static int proxy_connect_none(char *host, unsigned short port) | 41 static int proxy_connect_none(char *host, unsigned short port) |
86 { | 42 { |
87 struct sockaddr_in sin; | 43 struct sockaddr_in sin; |
88 struct hostent *hp; | 44 struct hostent *hp; |
89 int fd = -1; | 45 int fd = -1; |
116 { | 72 { |
117 struct hostent *hp; | 73 struct hostent *hp; |
118 struct sockaddr_in sin; | 74 struct sockaddr_in sin; |
119 int fd = -1; | 75 int fd = -1; |
120 char cmd[384]; | 76 char cmd[384]; |
121 char *inputline; | 77 char inputline[8192]; |
78 int nlc = 0; | |
79 int pos = 0; | |
122 | 80 |
123 debug_printf("connecting to %s:%d via %s:%d using HTTP\n", host, port, proxyhost, proxyport); | 81 debug_printf("connecting to %s:%d via %s:%d using HTTP\n", host, port, proxyhost, proxyport); |
124 | 82 |
125 if (!(hp = gethostbyname(proxyhost))) | 83 if (!(hp = gethostbyname(proxyhost))) |
126 return -1; | 84 return -1; |
138 return -1; | 96 return -1; |
139 } | 97 } |
140 | 98 |
141 snprintf(cmd, sizeof(cmd), "CONNECT %s:%d HTTP/1.1\n\r\n\r", host, port); | 99 snprintf(cmd, sizeof(cmd), "CONNECT %s:%d HTTP/1.1\n\r\n\r", host, port); |
142 | 100 |
143 if (send(fd, cmd, strlen(cmd), 0) < 0) | 101 if (send(fd, cmd, strlen(cmd), 0) < 0) { |
144 return -1; | 102 close(fd); |
145 if (proxy_recv_line(fd, &inputline) < 0) | 103 return -1; |
146 return -1; | 104 } |
105 while ((nlc != 2) && (read(fd, &inputline[pos++], 1) == 1)) { | |
106 if (inputline[pos-1] == '\n') | |
107 nlc++; | |
108 else if (inputline[pos-1] != '\r') | |
109 nlc = 0; | |
110 } | |
147 | 111 |
148 if ((memcmp(HTTP_GOODSTRING, inputline, strlen(HTTP_GOODSTRING)) == 0) || | 112 if ((memcmp(HTTP_GOODSTRING, inputline, strlen(HTTP_GOODSTRING)) == 0) || |
149 (memcmp(HTTP_GOODSTRING2, inputline, strlen(HTTP_GOODSTRING2)) == 0)) { | 113 (memcmp(HTTP_GOODSTRING2, inputline, strlen(HTTP_GOODSTRING2)) == 0)) { |
150 while (strlen(inputline) > 1) { | |
151 free(inputline); | |
152 if (proxy_recv_line(fd, &inputline) < 0) | |
153 return -1; | |
154 } | |
155 free(inputline); | |
156 return fd; | 114 return fd; |
157 } | 115 } |
158 | 116 |
159 free(inputline); | |
160 | |
161 close(fd); | 117 close(fd); |
162 | |
163 return -1; | 118 return -1; |
164 } | 119 } |
165 | 120 |
166 static int proxy_connect_socks4(char *host, unsigned short port, | 121 static int proxy_connect_socks4(char *host, unsigned short port, |
167 char *proxyhost, unsigned short proxyport) | 122 char *proxyhost, unsigned short proxyport) |