comparison src/proxy.c @ 2372:2927c2c26fe6

[gaim-migrate @ 2385] reformatting. nothing else. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 27 Sep 2001 19:17:11 +0000
parents 7973a8348d8b
children 8530d4d72fab
comparison
equal deleted inserted replaced
2371:db02399a9ad7 2372:2927c2c26fe6
41 41
42 #define GAIM_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR) 42 #define GAIM_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
43 #define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) 43 #define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
44 44
45 char proxyhost[128] = { 0 }; 45 char proxyhost[128] = { 0 };
46 int proxyport = 0; 46 int proxyport = 0;
47 int proxytype = 0; 47 int proxytype = 0;
48 char proxyuser[128] = { 0 }; 48 char proxyuser[128] = { 0 };
49 char proxypass[128] = { 0 }; 49 char proxypass[128] = { 0 };
50 50
51 struct PHB { 51 struct PHB {
52 GaimInputFunction func; 52 GaimInputFunction func;
76 gaim_cond |= GAIM_INPUT_READ; 76 gaim_cond |= GAIM_INPUT_READ;
77 if (condition & GAIM_READ_COND) 77 if (condition & GAIM_READ_COND)
78 gaim_cond |= GAIM_INPUT_WRITE; 78 gaim_cond |= GAIM_INPUT_WRITE;
79 79
80 debug_printf("CLOSURE: callback for %d, fd is %d\n", 80 debug_printf("CLOSURE: callback for %d, fd is %d\n",
81 closure->result, g_io_channel_unix_get_fd(source)); 81 closure->result, g_io_channel_unix_get_fd(source));
82 82
83 closure->function(closure->data, g_io_channel_unix_get_fd(source), gaim_cond); 83 closure->function(closure->data, g_io_channel_unix_get_fd(source), gaim_cond);
84 84
85 return TRUE; 85 return TRUE;
86 } 86 }
87 87
88 gint gaim_input_add(gint source, GaimInputCondition condition, 88 gint gaim_input_add(gint source, GaimInputCondition condition, GaimInputFunction function, gpointer data)
89 GaimInputFunction function, gpointer data)
90 { 89 {
91 GaimIOClosure *closure = g_new0(GaimIOClosure, 1); 90 GaimIOClosure *closure = g_new0(GaimIOClosure, 1);
92 GIOChannel *channel; 91 GIOChannel *channel;
93 GIOCondition cond = 0; 92 GIOCondition cond = 0;
94 93
100 if (condition & GAIM_INPUT_WRITE) 99 if (condition & GAIM_INPUT_WRITE)
101 cond |= GAIM_WRITE_COND; 100 cond |= GAIM_WRITE_COND;
102 101
103 channel = g_io_channel_unix_new(source); 102 channel = g_io_channel_unix_new(source);
104 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, 103 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
105 gaim_io_invoke, closure, gaim_io_destroy); 104 gaim_io_invoke, closure, gaim_io_destroy);
106 105
107 debug_printf("CLOSURE: adding input watcher %d for fd %d\n", closure->result, source); 106 debug_printf("CLOSURE: adding input watcher %d for fd %d\n", closure->result, source);
108 107
109 g_io_channel_unref(channel); 108 g_io_channel_unref(channel);
110 return closure->result; 109 return closure->result;
189 close(fd); 188 close(fd);
190 g_free(phb); 189 g_free(phb);
191 return -1; 190 return -1;
192 } 191 }
193 fcntl(fd, F_SETFL, 0); 192 fcntl(fd, F_SETFL, 0);
194 phb->port = fd; /* bleh */ 193 phb->port = fd; /* bleh */
195 g_timeout_add(50, clean_connect, phb); /* we do this because we never 194 g_timeout_add(50, clean_connect, phb); /* we do this because we never
196 want to call our callback 195 want to call our callback
197 before we return. */ 196 before we return. */
198 } 197 }
199 198
200 return fd; 199 return fd;
201 } 200 }
202 201
211 char inputline[8192]; 210 char inputline[8192];
212 211
213 gaim_input_remove(phb->inpa); 212 gaim_input_remove(phb->inpa);
214 213
215 while ((nlc != 2) && (read(source, &inputline[pos++], 1) == 1)) { 214 while ((nlc != 2) && (read(source, &inputline[pos++], 1) == 1)) {
216 if (inputline[pos-1] == '\n') 215 if (inputline[pos - 1] == '\n')
217 nlc++; 216 nlc++;
218 else if (inputline[pos-1] != '\r') 217 else if (inputline[pos - 1] != '\r')
219 nlc = 0; 218 nlc = 0;
220 } 219 }
221 inputline[pos] = '\0'; 220 inputline[pos] = '\0';
222 221
223 debug_printf("Proxy says: %s\n", inputline); 222 debug_printf("Proxy says: %s\n", inputline);
224 223
225 if ((memcmp(HTTP_GOODSTRING , inputline, strlen(HTTP_GOODSTRING )) == 0) || 224 if ((memcmp(HTTP_GOODSTRING, inputline, strlen(HTTP_GOODSTRING)) == 0) ||
226 (memcmp(HTTP_GOODSTRING2, inputline, strlen(HTTP_GOODSTRING2)) == 0)) { 225 (memcmp(HTTP_GOODSTRING2, inputline, strlen(HTTP_GOODSTRING2)) == 0)) {
227 phb->func(phb->data, source, GAIM_INPUT_READ); 226 phb->func(phb->data, source, GAIM_INPUT_READ);
228 g_free(phb->host); 227 g_free(phb->host);
229 g_free(phb); 228 g_free(phb);
230 return; 229 return;
254 g_free(phb); 253 g_free(phb);
255 return; 254 return;
256 } 255 }
257 fcntl(source, F_SETFL, 0); 256 fcntl(source, F_SETFL, 0);
258 257
259 g_snprintf(cmd, sizeof(cmd), "CONNECT %s:%d HTTP/1.1\r\nHost = %s:%d\r\n", phb->host, phb->port, phb->host, phb->port); 258 g_snprintf(cmd, sizeof(cmd), "CONNECT %s:%d HTTP/1.1\r\nHost = %s:%d\r\n", phb->host, phb->port,
259 phb->host, phb->port);
260 if (send(source, cmd, strlen(cmd), 0) < 0) { 260 if (send(source, cmd, strlen(cmd), 0) < 0) {
261 close(source); 261 close(source);
262 phb->func(phb->data, -1, GAIM_INPUT_READ); 262 phb->func(phb->data, -1, GAIM_INPUT_READ);
263 g_free(phb->host); 263 g_free(phb->host);
264 g_free(phb); 264 g_free(phb);
581 return; 581 return;
582 } 582 }
583 583
584 if (buf[1] == 0x02) { 584 if (buf[1] == 0x02) {
585 unsigned int i = strlen(proxyuser), j = strlen(proxypass); 585 unsigned int i = strlen(proxyuser), j = strlen(proxypass);
586 buf[0] = 0x01; /* version 1 */ 586 buf[0] = 0x01; /* version 1 */
587 buf[1] = i; 587 buf[1] = i;
588 memcpy(buf+2, proxyuser, i); 588 memcpy(buf + 2, proxyuser, i);
589 buf[2+i] = j; 589 buf[2 + i] = j;
590 memcpy(buf+2+i+1, proxypass, j); 590 memcpy(buf + 2 + i + 1, proxypass, j);
591 if (write(source, buf, 3+i+j) < 3+i+j) { 591 if (write(source, buf, 3 + i + j) < 3 + i + j) {
592 close(source); 592 close(source);
593 phb->func(phb->data, -1, GAIM_INPUT_READ); 593 phb->func(phb->data, -1, GAIM_INPUT_READ);
594 g_free(phb->host); 594 g_free(phb->host);
595 g_free(phb); 595 g_free(phb);
596 return; 596 return;
713 return -1; 713 return -1;
714 } 714 }
715 715
716 sethostent(1); 716 sethostent(1);
717 717
718 if ((proxytype == PROXY_NONE) || 718 if ((proxytype == PROXY_NONE) || !proxyhost || !proxyhost[0] || !proxyport || (proxyport == -1))
719 !proxyhost || !proxyhost[0] ||
720 !proxyport || (proxyport == -1))
721 return proxy_connect_none(host, port, phb); 719 return proxy_connect_none(host, port, phb);
722 else if (proxytype == PROXY_HTTP) 720 else if (proxytype == PROXY_HTTP)
723 return proxy_connect_http(host, port, phb); 721 return proxy_connect_http(host, port, phb);
724 else if (proxytype == PROXY_SOCKS4) 722 else if (proxytype == PROXY_SOCKS4)
725 return proxy_connect_socks4(host, port, phb); 723 return proxy_connect_socks4(host, port, phb);