diff options
author | Rafael Garcia-Suarez <rgarciasuarez@mandriva.org> | 2004-06-29 06:35:54 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@mandriva.org> | 2004-06-29 06:35:54 +0000 |
commit | e1d903c8ea73f57ca704720dacc747c66a785a32 (patch) | |
tree | 3477e50f7367a1c236ca3fbadd8b30220454355c | |
parent | 1c97c7796ad78713386a3ec76e2f45f2c3456272 (diff) | |
download | urpmi-e1d903c8ea73f57ca704720dacc747c66a785a32.tar urpmi-e1d903c8ea73f57ca704720dacc747c66a785a32.tar.gz urpmi-e1d903c8ea73f57ca704720dacc747c66a785a32.tar.bz2 urpmi-e1d903c8ea73f57ca704720dacc747c66a785a32.tar.xz urpmi-e1d903c8ea73f57ca704720dacc747c66a785a32.zip |
Parsing of the proxy.cfg file: support for per-media proxies
-rw-r--r-- | urpm/download.pm | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/urpm/download.pm b/urpm/download.pm index 41bfa848..4308f9f6 100644 --- a/urpm/download.pm +++ b/urpm/download.pm @@ -5,12 +5,16 @@ use urpm::msg; use urpm::cfg; use Cwd; +#- proxy config file. +our $PROXY_CFG = '/etc/urpmi/proxy.cfg'; +my $proxy_config; + sub basename { local $_ = shift; s|/*\s*$||; s|.*/||; $_ } sub import () { my $c = caller; no strict 'refs'; - foreach my $symbol (qw(get_proxy set_proxy + foreach my $symbol (qw(get_proxy propagate_sync_callback sync_file sync_wget sync_curl sync_rsync sync_ssh )) { @@ -18,30 +22,41 @@ sub import () { } } -sub get_proxy () { - my $proxy = { - http_proxy => undef , - ftp_proxy => undef , - user => undef, - pwd => undef - }; +sub load_proxy_config () { + return if defined $proxy_config; + open my $f, $PROXY_CFG or $proxy_config = {}, return; local $_; - open my $f, $urpm::cfg::PROXY_CFG or return undef; while (<$f>) { chomp; s/#.*$//; s/^\s*//; s/\s*$//; - /^http_proxy\s*=\s*(.*)$/ and $proxy->{http_proxy} = $1, next; - /^ftp_proxy\s*=\s*(.*)$/ and $proxy->{ftp_proxy} = $1, next; - /^proxy_user\s*=\s*(.*):(.*)$/ and do { - $proxy->{user} = $1; - $proxy->{pwd} = $2; + if (/^(?:(.*):\s*)(ftp|http_)proxy\s*=\s*(.*)$/) { + $proxy_config->{$1 || ''}{$2} = $3; + next; + } + if (/^(?:(.*):\s*)proxy_user\s*=\s*(.*)(?::(.*))?$/) { + $proxy_config->{$1 || ''}{user} = $2; + $proxy_config->{$1 || ''}{pwd} = $3 if defined $3; next; - }; - next; + } } close $f; - bless $proxy; } +#- reads and loads the proxy.cfg file ; +#- returns the global proxy settings (without arguments) or the +#- proxy settings for the specified media (with a media name as argument) +sub get_proxy (;$) { + my ($o_media) = @_; $o_media ||= ''; + load_proxy_config(); + return $proxy_config->{$o_media} || { + http_proxy => undef , + ftp_proxy => undef , + user => undef, + pwd => undef + }; +} + +#- set up the environment for proxy usage for the appropriate tool. +#- returns an array of command-line arguments. sub set_proxy { my ($proxy) = @_; my @res; |