SVN: toys/rsget.pl/RSGet/Curl.pm

sparky sparky at pld-linux.org
Sun Apr 11 16:23:04 CEST 2010


Author: sparky
Date: Sun Apr 11 16:23:04 2010
New Revision: 11329

Modified:
   toys/rsget.pl/RSGet/Curl.pm
Log:
- added proxy (http and proxy) support as additional interfaces


Modified: toys/rsget.pl/RSGet/Curl.pm
==============================================================================
--- toys/rsget.pl/RSGet/Curl.pm	(original)
+++ toys/rsget.pl/RSGet/Curl.pm	Sun Apr 11 16:23:04 2010
@@ -88,8 +88,34 @@
 	};
 
 	$curl->setopt( CURLOPT_PRIVATE, $id );
-	$curl->setopt( CURLOPT_INTERFACE, $get_obj->{_outif} )
-		if $get_obj->{_outif};
+
+	if ( $get_obj->{_outif} ) {
+		foreach my $if ( split /;+/, $get_obj->{_outif} ) {
+			if ( $if =~ /^([a-z0-9]+)=(\S+)(:(\d+))?$/ ) {
+				my ($tn, $host, $port) = ($1, $2, $4);
+				my %proxytype = (
+					http => 0, #CURLPROXY_HTTP,
+					http10 => 1, #CURLPROXY_HTTP_1_0,
+					socks4 => 4, #CURLPROXY_SOCKS4,
+					socks4a => 6, #CURLPROXY_SOCKS4a,
+					socks5 => 5, #CURLPROXY_SOCKS5,
+					socks5host => 7, #CURLPROXY_SOCKS5_HOSTNAME,
+				);
+				if ( my $type = $proxytype{ $tn } ) {
+					$curl->setopt( CURLOPT_PROXYTYPE, $type );
+					$curl->setopt( CURLOPT_PROXY, $host );
+					$curl->setopt( CURLOPT_PROXYPORT, $port )
+						if $port;
+				} else {
+					warn "Unrecognized proxy type '$tn' in '$get_obj->{_outif}'\n";
+				}
+			} elsif ( $if =~ /^\S+$/ ) {
+				$curl->setopt( CURLOPT_INTERFACE, $if );
+			} else {
+				warn "Unrecognized interface string '$if' in '$get_obj->{_outif}'\n";
+			}
+		}
+	}
 
 	if ( defined $get_obj->{_cookie} ) {
 		$curl->setopt( CURLOPT_COOKIEJAR, $get_obj->{_cookie} );


More information about the pld-cvs-commit mailing list