Blame SOURCES/cvs-1.11.21-proxy.patch

36e843
--- cvs-1.11.21/src/client.h.proxy	2005-08-02 22:46:57.000000000 +0200
36e843
+++ cvs-1.11.21/src/client.h	2005-11-10 10:26:24.000000000 +0100
36e843
@@ -83,6 +83,9 @@
36e843
 #   ifndef CVS_AUTH_PORT
36e843
 #     define CVS_AUTH_PORT 2401
36e843
 #   endif /* CVS_AUTH_PORT */
36e843
+#   ifndef CVS_PROXY_PORT
36e843
+#     define CVS_PROXY_PORT 80
36e843
+#   endif /* CVS_PROXY_PORT */
36e843
 # endif /* (AUTH_CLIENT_SUPPORT) || defined (HAVE_GSSAPI) */
36e843
 
36e843
 # if HAVE_KERBEROS
36e843
--- cvs-1.11.21/src/client.c.proxy	2005-09-22 17:58:46.000000000 +0200
36e843
+++ cvs-1.11.21/src/client.c	2005-11-10 10:26:24.000000000 +0100
36e843
@@ -144,6 +144,7 @@
36e843
 
36e843
 static size_t try_read_from_server PROTO ((char *, size_t));
36e843
 
36e843
+static void proxy_connect PROTO ((cvsroot_t *, int));
36e843
 static void auth_server PROTO ((cvsroot_t *, struct buffer *, struct buffer *,
36e843
 				int, int, struct hostent *));
36e843
 
36e843
@@ -3802,7 +3803,7 @@
36e843
     int port_number;
36e843
     struct sockaddr_in client_sai;
36e843
     struct hostent *hostinfo;
36e843
-    struct buffer *to_server, *from_server;
36e843
+    struct buffer *local_to_server, *local_from_server;
36e843
 
36e843
     sock = socket (AF_INET, SOCK_STREAM, 0);
36e843
     if (sock == -1)
36e843
@@ -3810,7 +3811,17 @@
36e843
 	error (1, 0, "cannot create socket: %s", SOCK_STRERROR (SOCK_ERRNO));
36e843
     }
36e843
     port_number = get_cvs_port_number (root);
36e843
-    hostinfo = init_sockaddr (&client_sai, root->hostname, port_number);
36e843
+
36e843
+    /* if we have a proxy connect to that instead */
36e843
+    if (root->proxy_hostname)
36e843
+    {
36e843
+	hostinfo = init_sockaddr (&client_sai, root->proxy_hostname, root->proxy_port);
36e843
+    }
36e843
+    else
36e843
+    {
36e843
+	hostinfo = init_sockaddr (&client_sai, root->hostname, port_number);
36e843
+    }
36e843
+
36e843
     if (trace)
36e843
     {
36e843
 	fprintf (stderr, " -> Connecting to %s(%s):%d\n",
36e843
@@ -3820,29 +3831,41 @@
36e843
     if (connect (sock, (struct sockaddr *) &client_sai, sizeof (client_sai))
36e843
 	< 0)
36e843
 	error (1, 0, "connect to %s(%s):%d failed: %s",
36e843
-	       root->hostname,
36e843
+	       root->proxy_hostname ? root->proxy_hostname : root->hostname,
36e843
 	       inet_ntoa (client_sai.sin_addr),
36e843
-	       port_number, SOCK_STRERROR (SOCK_ERRNO));
36e843
+	       root->proxy_hostname ? root->proxy_port : port_number,
36e843
+	       SOCK_STRERROR (SOCK_ERRNO));
36e843
 
36e843
-    make_bufs_from_fds (sock, sock, 0, &to_server, &from_server, 1);
36e843
+    make_bufs_from_fds (sock, sock, 0, &local_to_server, &local_from_server, 1);
36e843
 
36e843
-    auth_server (root, to_server, from_server, verify_only, do_gssapi, hostinfo);
36e843
+    if (root->proxy_hostname)
36e843
+    {
36e843
+    	// REALLY ugly hack to allow proxy_connect() to use send_to_server().
36e843
+    	// The proper fix would be to remove the global to_server & from_server
36e843
+    	// variables, and instead let send_to_server() etc. take the target
36e843
+    	// server struct as a paramter.
36e843
+	to_server = local_to_server;
36e843
+	from_server = local_from_server;
36e843
+	proxy_connect (root, port_number);
36e843
+    }
36e843
+
36e843
+    auth_server (root, local_to_server, local_from_server, verify_only, do_gssapi, hostinfo);
36e843
 
36e843
     if (verify_only)
36e843
     {
36e843
 	int status;
36e843
 
36e843
-	status = buf_shutdown (to_server);
36e843
+	status = buf_shutdown (local_to_server);
36e843
 	if (status != 0)
36e843
 	    error (0, status, "shutting down buffer to server");
36e843
-	buf_free (to_server);
36e843
-	to_server = NULL;
36e843
+	buf_free (local_to_server);
36e843
+	local_to_server = NULL;
36e843
 
36e843
-	status = buf_shutdown (from_server);
36e843
+	status = buf_shutdown (local_from_server);
36e843
 	if (status != 0)
36e843
 	    error (0, status, "shutting down buffer from server");
36e843
-	buf_free (from_server);
36e843
-	from_server = NULL;
36e843
+	buf_free (local_from_server);
36e843
+	local_from_server = NULL;
36e843
 
36e843
 	/* Don't need to set server_started = 0 since we don't set it to 1
36e843
 	 * until returning from this call.
36e843
@@ -3850,8 +3873,8 @@
36e843
     }
36e843
     else
36e843
     {
36e843
-	*to_server_p = to_server;
36e843
-	*from_server_p = from_server;
36e843
+	*to_server_p = local_to_server;
36e843
+	*from_server_p = local_from_server;
36e843
     }
36e843
 
36e843
     return;
36e843
@@ -3860,6 +3883,46 @@
36e843
 
36e843
 
36e843
 static void
36e843
+proxy_connect (root, port_number)
36e843
+    cvsroot_t *root;
36e843
+    int port_number;
36e843
+{
36e843
+#define CONNECT_STRING "CONNECT %s:%d HTTP/1.0\r\n\r\n"
36e843
+    /* Send a "CONNECT" command to proxy: */
36e843
+    char* read_buf;
36e843
+    int codenum, count;
36e843
+    
36e843
+    /* 4 characters for port covered by the length of %s & %d */
36e843
+    char* write_buf = xmalloc (strlen (CONNECT_STRING) + strlen (root->hostname) + 20 + 1);
36e843
+    int len = sprintf (write_buf, CONNECT_STRING, root->hostname, port_number);
36e843
+    send_to_server (write_buf, len);
36e843
+    
36e843
+    /* Wait for HTTP status code, bail out if you don't get back a 2xx code.*/
36e843
+    count = read_line (&read_buf);
36e843
+    sscanf (read_buf, "%s %d", write_buf, &codenum);
36e843
+    
36e843
+    if ((codenum / 100) != 2)
36e843
+	error (1, 0, "proxy server %s:%d does not support http tunnelling",
36e843
+	       root->proxy_hostname, root->proxy_port);
36e843
+    free (read_buf);
36e843
+    free (write_buf);
36e843
+    
36e843
+    /* Skip through remaining part of MIME header, recv_line
36e843
+       consumes the trailing \n */
36e843
+    while(read_line (&read_buf) > 0)
36e843
+    {
36e843
+	if (read_buf[0] == '\r' || read_buf[0] == 0)
36e843
+	{
36e843
+	    free (read_buf);
36e843
+	    break;
36e843
+	}
36e843
+	free (read_buf);
36e843
+    }
36e843
+}
36e843
+
36e843
+
36e843
+
36e843
+static void
36e843
 auth_server (root, lto_server, lfrom_server, verify_only, do_gssapi, hostinfo)
36e843
     cvsroot_t *root;
36e843
     struct buffer *lto_server;
36e843
--- cvs-1.11.21/src/root.c.proxy	2005-09-04 02:26:43.000000000 +0200
36e843
+++ cvs-1.11.21/src/root.c	2005-11-10 10:26:24.000000000 +0100
36e843
@@ -298,7 +298,7 @@
36e843
     newroot->port = 0;
36e843
     newroot->directory = NULL;
36e843
     newroot->proxy_hostname = NULL;
36e843
-    newroot->proxy_port = 0;
36e843
+    newroot->proxy_port = CVS_PROXY_PORT;
36e843
 #endif /* CLIENT_SUPPORT */
36e843
 
36e843
     return newroot;
36e843
@@ -371,6 +371,7 @@
36e843
     char *cvsroot_copy, *p, *q;		/* temporary pointers for parsing */
36e843
 #ifdef CLIENT_SUPPORT
36e843
     int check_hostname, no_port, no_password;
36e843
+    const char *env_var;
36e843
 #endif /* CLIENT_SUPPORT */
36e843
 
36e843
     assert (root_in);
36e843
@@ -406,6 +407,31 @@
36e843
 	cvsroot_copy = ++p;
36e843
 
36e843
 #ifdef CLIENT_SUPPORT
36e843
+	/* Determine proxy */
36e843
+	env_var = getenv("CVS_PROXY");
36e843
+/*
36e843
+	if (!env_var)
36e843
+	  	env_var = getenv("HTTP_PROXY");
36e843
+	if (!env_var)
36e843
+	  	env_var = getenv("http_proxy");
36e843
+*/
36e843
+	/* Check if a proxy was specified, and if it is a HTTP proxy */
36e843
+	if (env_var && !memcmp(env_var, "http://", 7))
36e843
+	{
36e843
+	    char *port_str;
36e843
+
36e843
+	    /* Try to parse the proxy data */
36e843
+	    env_var += 7;
36e843
+	    /* TODO - parse username/password data, too */
36e843
+	    port_str = strchr(env_var, ':');
36e843
+	    if (port_str)
36e843
+	    {
36e843
+		*port_str++ = 0;
36e843
+		newroot->proxy_port = atoi(port_str);
36e843
+		newroot->proxy_hostname = xstrdup(env_var);
36e843
+	    }
36e843
+	}
36e843
+
36e843
 	/* Look for method options, for instance, proxy, proxyport.
36e843
 	 * We don't handle these, but we like to try and warn the user that
36e843
 	 * they are being ignored.