annotate src/proxy.c @ 710:efd72a117875

[gaim-migrate @ 720] yay, icq-style aliasing. joy. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 17 Aug 2000 13:07:52 +0000
parents 9e51c1a4abba
children b1b77b39a1fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 * gaim
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * (at your option) any later version.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * GNU General Public License for more details.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22 /* this is a little piece of code to handle proxy connection */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
23 /* it is intended to : 1st handle http proxy, using the CONNECT command
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
24 , 2nd provide an easy way to add socks support */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
25
349
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
26 #ifdef HAVE_CONFIG_H
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
27 #include "../config.h"
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
28 #endif
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
29 #include <stdio.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
30 #include <stdlib.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
31 #include <string.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
32 #include <sys/types.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
33 #include <sys/socket.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
34 #include <netdb.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
35 #include <netinet/in.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
36 #include <gtk/gtk.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
37 #include "gaim.h"
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
38 #include "proxy.h"
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
39
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
40
210
ec0686b3b03f [gaim-migrate @ 220]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 79
diff changeset
41 /* static int proxy_inited=0; */
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
42 int proxy_type = 0;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
43 char proxy_host[256];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
44 int proxy_port = 3128;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
45 char *proxy_realhost = NULL;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
46
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
47 /* this code is borrowed from cvs 1.10 */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
48 static int
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
49 proxy_recv_line (int sock, char **resultp)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
50 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
51 int c;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
52 char *result;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
53 size_t input_index = 0;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
54 size_t result_size = 80;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
55
79
bfdc427b936d [gaim-migrate @ 89]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
56 result = g_malloc (result_size);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
57
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
58 while (1)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
59 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
60 char ch;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
61 if (recv (sock, &ch, 1, 0) < 0)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
62 fprintf (stderr, "recv() error from proxy server\n");
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
63 c = ch;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
64
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
65 if (c == EOF)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
66 {
79
bfdc427b936d [gaim-migrate @ 89]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
67 g_free (result);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
68
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
69 /* It's end of file. */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
70 fprintf(stderr, "end of file from server\n");
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
71 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
72
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
73 if (c == '\012')
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
74 break;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
75
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
76 result[input_index++] = c;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
77 while (input_index + 1 >= result_size)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
78 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
79 result_size *= 2;
79
bfdc427b936d [gaim-migrate @ 89]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
80 result = (char *) g_realloc (result, result_size);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
81 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
82 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
83
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
84 if (resultp)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
85 *resultp = result;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
86
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
87 /* Terminate it just for kicks, but we *can* deal with embedded NULs. */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
88 result[input_index] = '\0';
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
89
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
90 if (resultp == NULL)
79
bfdc427b936d [gaim-migrate @ 89]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
91 g_free (result);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
92 return input_index;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
93 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
94
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
95
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
96 struct hostent *proxy_gethostbyname(char *host)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
97 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
98
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
99 if (proxy_type == PROXY_NONE)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
100 return (gethostbyname(host));
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
101
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
102 if (proxy_realhost != NULL)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
103 g_free(proxy_realhost);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
104
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
105 /* we keep the real host name for the Connect command */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
106 proxy_realhost = (char *) strdup(host);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
107
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
108 return (gethostbyname(proxy_host));
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
109
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
110 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
111
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
112
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
113 int proxy_connect(int sockfd, struct sockaddr *serv_addr, int
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
114 addrlen )
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
115 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
116 struct sockaddr_in name;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
117 int ret;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
118
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
119 switch (proxy_type) {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
120 case PROXY_NONE:
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
121 /* normal use */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
122 return (connect(sockfd,serv_addr,addrlen));
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
123 break;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
124 case PROXY_HTTP: /* Http proxy */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
125 /* do the tunneling */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
126 /* step one : connect to proxy */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
127 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
128 struct hostent *hostinfo;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
129 unsigned short shortport = proxy_port;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
130
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
131 memset (&name, 0, sizeof (name));
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
132 name.sin_family = AF_INET;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
133 name.sin_port = htons (shortport);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
134 hostinfo = gethostbyname (proxy_host);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
135 if (hostinfo == NULL) {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
136 fprintf (stderr, "Unknown host %s.\n", proxy_host);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
137 return (-1);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
138 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
139 name.sin_addr = *(struct in_addr *) hostinfo->h_addr;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
140 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
141 sprintf(debug_buff,"Trying to connect ...\n");
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
142 debug_print(debug_buff);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
143 if ((ret = connect(sockfd,(struct sockaddr *)&name,sizeof(name)))<0)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
144 return(ret);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
145
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
146 /* step two : do proxy tunneling init */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
147 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
148 char cmd[80];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
149 char *inputline;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
150 unsigned short realport=ntohs(((struct sockaddr_in *)serv_addr)->sin_port);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
151 sprintf(cmd,"CONNECT %s:%d HTTP/1.1\n\r\n\r",proxy_realhost,realport);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
152 sprintf(debug_buff,"<%s>\n",cmd);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
153 debug_print(debug_buff);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
154 if (send(sockfd,cmd,strlen(cmd),0)<0)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
155 return(-1);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
156 if (proxy_recv_line(sockfd,&inputline) < 0) {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
157 return(-1);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
158 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
159 sprintf(debug_buff,"<%s>\n",inputline);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
160 debug_print(debug_buff);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
161 if (memcmp("HTTP/1.0 200 Connection established",inputline,35))
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
162 if (memcmp("HTTP/1.1 200 Connection established",inputline,35)) {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
163 free(inputline);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
164 return(-1);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
165 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
166
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
167 while (strlen(inputline)>1) {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
168 free(inputline);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
169 if (proxy_recv_line(sockfd,&inputline) < 0) {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
170 return(-1);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
171 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
172 sprintf(debug_buff,"<%s>\n",inputline);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
173 debug_print(debug_buff);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
174 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
175 free(inputline);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
176 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
177
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
178 return ret;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
179 break;
664
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
180 case PROXY_SOCKS4:
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
181 /* code shamelessly stolen from everybuddy */
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
182 {
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
183 struct sockaddr_in sa;
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
184 unsigned char packet[12];
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
185 struct hostent *hp;
234
985635758c33 [gaim-migrate @ 244]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 210
diff changeset
186
664
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
187 debug_print("connecting with socks4.\n");
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
188
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
189 if (!(hp = gethostbyname(proxy_host)))
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
190 return -1;
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
191
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
192 bzero(&sa, sizeof(sa));
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
193 sa.sin_family = AF_INET;
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
194 sa.sin_port = htons(proxy_port);
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
195 bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length);
253
5b28ef2b550e [gaim-migrate @ 263]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 234
diff changeset
196
664
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
197 if (connect(sockfd, (struct sockaddr *) &sa, sizeof (sa)) != -1) {
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
198 unsigned short realport = htons(((struct sockaddr_in *)serv_addr)->sin_port);
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
199
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
200 if (!(hp = gethostbyname(proxy_realhost)))
253
5b28ef2b550e [gaim-migrate @ 263]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 234
diff changeset
201 return -1;
664
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
202 packet[0] = 4;
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
203 packet[1] = 1;
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
204 packet[2] = (((unsigned short) realport) >> 8);
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
205 packet[3] = (((unsigned short) realport) & 0xff);
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
206 packet[4] = (unsigned char) (hp->h_addr_list[0])[0];
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
207 packet[5] = (unsigned char) (hp->h_addr_list[0])[1];
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
208 packet[6] = (unsigned char) (hp->h_addr_list[0])[2];
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
209 packet[7] = (unsigned char) (hp->h_addr_list[0])[3];
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
210 packet[8] = 0;
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
211 if (write(sockfd, packet, 9) == 9) {
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
212 bzero(packet, sizeof(packet));
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
213 if (read(sockfd, packet, 9) >= 4 && packet[1] == 90)
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
214 return 0;
253
5b28ef2b550e [gaim-migrate @ 263]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 234
diff changeset
215 }
664
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
216 close(sockfd);
253
5b28ef2b550e [gaim-migrate @ 263]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 234
diff changeset
217 }
664
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
218 return -1;
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
219 }
5cb19972df52 [gaim-migrate @ 674]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
220 break;
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 253
diff changeset
221 case PROXY_SOCKS5:
670
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
222 {
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
223 struct sockaddr_in sin;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
224 struct hostent *hostinfo;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
225 char buff[11];
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
226
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
227 sethostent(0);
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
228 hostinfo = gethostbyname(proxy_host);
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
229 if (!hostinfo) return -1;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
230
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
231 sin.sin_addr.s_addr = atol(hostinfo->h_addr);
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
232 sin.sin_family = AF_INET;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
233 sin.sin_port = htons(proxy_port);
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
234
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
235 if (connect(sockfd, (struct sockaddr *)&sin, sizeof(sin)) < 0)
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
236 return -1;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
237
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
238 buff[0] = 5;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
239 buff[1] = 1;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
240 buff[2] = 0;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
241
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
242 write(sockfd, buff, 3);
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
243 read(sockfd, buff, 2);
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
244
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
245 if (buff[1]) return -1;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
246
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
247 hostinfo = gethostbyname(proxy_realhost);
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
248 if (!hostinfo) return -1;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
249
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
250 buff[0] = 5;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
251 buff[1] = 1;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
252 buff[2] = 0;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
253 buff[3] = 1;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
254 buff[4] = (unsigned char) (hostinfo->h_addr_list[0])[0];
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
255 buff[5] = (unsigned char) (hostinfo->h_addr_list[0])[1];
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
256 buff[6] = (unsigned char) (hostinfo->h_addr_list[0])[2];
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
257 buff[7] = (unsigned char) (hostinfo->h_addr_list[0])[3];
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
258 memcpy(buff+8, &((struct sockaddr_in *)serv_addr)->sin_port, 2);
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
259
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
260 write(sockfd, buff, 10);
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
261 read(sockfd, buff, 10);
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
262
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
263 if (buff[1]) return -1;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
264
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
265 return 0;
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
266 }
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 253
diff changeset
267 break;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
268 default:
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
269 fprintf(stderr,"Unknown proxy type : %d.\n",proxy_type);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
270 break;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
271 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
272 return(-1);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
273 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
274