git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-cvsimport: add suport for CVS pserver method HTTP/1.x  proxying
@ 2006-11-22 22:26 Inaki Arenaza
       [not found] ` <7v64 d5keke.fsf@assigned-by-dhcp.cox.net>
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Inaki Arenaza @ 2006-11-22 22:26 UTC (permalink / raw)
  To: git; +Cc: I�aki Arenaza

From: =?utf-8?q?I=F1aki_Arenaza?= <iarenuno@eteo.mondragon.edu>

Quoting from the CVS info manual:

......................................................................
     The `gserver' and `pserver' connection methods all accept optional
  method options, specified as part of the METHOD string, like so:

       :METHOD[;OPTION=ARG...]:

     Currently, the only two valid connection options are `proxy', which
  takes a hostname as an argument, and `proxyport', which takes a port
  number as an argument.  These options can be used to connect via an HTTP
  tunnel style web proxy.  For example, to connect pserver via a web proxy
  at www.myproxy.net and port 8000, you would use a method of:

       :pserver;proxy=www.myproxy.net;proxyport=8000:

     *NOTE: The rest of the connection string is required to connect to
  the server as noted in the upcoming sections on password authentication,
  gserver and kserver.  The example above would only modify the METHOD
  portion of the repository name.*

     PROXY must be supplied to connect to a CVS server via a proxy
  server, but PROXYPORT will default to port 8080 if not supplied.
  PROXYPORT may also be set via the CVS_PROXY_PORT environment variable.
......................................................................

This patch adds support for 'proxy' and 'proxyport' connection options
when using the pserver method for the CVS Root.

It has been tested with a Squid 2.5.x proxy server.

Please, CC me as I am not in the list.

Signed-off-by: Iñaki Arenaza <iarenuno@eteo.mondragon.edu>
---
 git-cvsimport.perl |   49 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index b54a948..394f3c3 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -161,8 +161,22 @@ sub new {
 sub conn {
 	my $self = shift;
 	my $repo = $self->{'fullrep'};
-	if($repo =~ s/^:pserver:(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?//) {
-		my($user,$pass,$serv,$port) = ($1,$2,$3,$4);
+	if($repo =~ s/^:pserver(?:([^:]*)):(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?//) {
+		my($param,$user,$pass,$serv,$port) = ($1,$2,$3,$4,$5);
+
+		my($proxyhost,$proxyport);
+		if($param && ($param =~ m/proxy=([^;]+)/)) {
+			$proxyhost = $1;
+			# Default proxyport, if not specified, is 8080.
+			$proxyport = 8080;
+			if($ENV{"CVS_PROXY_PORT"}) {
+				$proxyport = $ENV{"CVS_PROXY_PORT"};
+			}
+			if($param =~ m/proxyport=([^;]+)/){
+				$proxyport = $1;
+			}
+		}
+
 		$user="anonymous" unless defined $user;
 		my $rr2 = "-";
 		unless($port) {
@@ -187,13 +201,38 @@ sub conn {
 		}
 		$pass="A" unless $pass;
 
-		my $s = IO::Socket::INET->new(PeerHost => $serv, PeerPort => $port);
-		die "Socket to $serv: $!\n" unless defined $s;
+		my ($s, $rep);
+		if($proxyhost) {
+
+			# Use a HTTP Proxy. Only works for HTTP proxies that
+			# don't require user authentication
+			#
+			# See: http://www.ietf.org/rfc/rfc2817.txt
+
+			$s = IO::Socket::INET->new(PeerHost => $proxyhost, PeerPort => $proxyport);
+			die "Socket to $proxyhost: $!\n" unless defined $s;
+			$s->write("CONNECT $serv:$port HTTP/1.1\r\nHost: $serv:$port\r\n\r\n")
+	                        or die "Write to $proxyhost: $!\n";
+	                $s->flush();
+
+			$rep = <$s>;
+
+			# The answer should loook like 'HTTP/1.x 2yy ....'
+			if(!($rep =~ m#^HTTP/1\.. 2[0-9][0-9]#)) {
+				die "Proxy connect: $rep\n";
+			}
+			# Skip the empty line of the proxy server output
+			<$s>;
+		} else {
+			my $s = IO::Socket::INET->new(PeerHost => $serv, PeerPort => $port);
+			die "Socket to $serv: $!\n" unless defined $s;
+		}
+
 		$s->write("BEGIN AUTH REQUEST\n$repo\n$user\n$pass\nEND AUTH REQUEST\n")
 			or die "Write to $serv: $!\n";
 		$s->flush();
 
-		my $rep = <$s>;
+		$rep = <$s>;
 
 		if($rep ne "I LOVE YOU\n") {
 			$rep="<unknown>" unless $rep;
-- 
1.4.4


^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2006-11-27 16:27 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-22 22:26 [PATCH] git-cvsimport: add suport for CVS pserver method HTTP/1.x proxying Inaki Arenaza
     [not found] ` <7v64 d5keke.fsf@assigned-by-dhcp.cox.net>
2006-11-23 22:01 ` Junio C Hamano
2006-11-23 22:09   ` Martin Langhoff (CatalystIT)
2006-11-23 23:02     ` Junio C Hamano
2006-11-23 23:20       ` Martin Langhoff (CatalystIT)
2006-11-23 23:52       ` Martin Langhoff
2006-11-24  0:24         ` Junio C Hamano
2006-11-25 12:43           ` Ignacio Arenaza
2006-11-24  1:42         ` Jeff King
2006-11-24  2:54           ` Junio C Hamano
2006-11-24  8:43   ` Ignacio Arenaza
2006-11-24  8:46   ` Ignacio Arenaza
2006-11-24  8:57     ` Junio C Hamano
2006-11-24  9:05       ` Ignacio Arenaza
2006-11-24 11:48         ` Junio C Hamano
2006-11-27 16:27           ` Ignacio Arenaza
2006-11-24 14:57       ` Jeff King
2006-11-24  4:48 ` Christian Couder
2006-11-24  8:41   ` Ignacio Arenaza

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).