aboutsummaryrefslogtreecommitdiffstats
path: root/grpmi
diff options
context:
space:
mode:
Diffstat (limited to 'grpmi')
-rw-r--r--grpmi/curl_download/curl_download.pm27
-rw-r--r--grpmi/curl_download/curl_download.xs11
-rwxr-xr-xgrpmi/grpmi.pl5
3 files changed, 34 insertions, 9 deletions
diff --git a/grpmi/curl_download/curl_download.pm b/grpmi/curl_download/curl_download.pm
index 329a05c2..7c6ec472 100644
--- a/grpmi/curl_download/curl_download.pm
+++ b/grpmi/curl_download/curl_download.pm
@@ -1,14 +1,39 @@
package curl_download;
use strict;
-use vars qw($VERSION @ISA);
+use vars qw($VERSION @ISA @EXPORT);
+use MDK::Common;
require DynaLoader;
@ISA = qw(DynaLoader);
+@EXPORT = qw(download readproxy writeproxy);
$VERSION = '1.0';
bootstrap curl_download $VERSION;
+sub readproxy {
+ my ($proxy, $proxy_user);
+ foreach (cat_('/etc/urpmi/proxy.cfg')) {
+ /^http_proxy\s*=\s*(.*)$/ and $proxy = $1;
+ /^ftp_proxy\s*=\s*(.*)$/ and $proxy = $1;
+ /^proxy_user\s*=\s*(.*)$/ and $proxy_user = $1;
+ }
+ ($proxy, $proxy_user);
+}
+
+sub writeproxy {
+ my ($proxy, $proxy_user) = @_;
+ output("/etc/urpmi/proxy.cfg",
+ if_($proxy, "http_proxy=$proxy\n"),
+ if_($proxy_user, "proxy_user=$proxy_user\n"));
+}
+
+sub download {
+ my ($url, $location, $downloadprogress_callback) = @_;
+
+ download_real($url, $location, $downloadprogress_callback, readproxy());
+}
+
1;
diff --git a/grpmi/curl_download/curl_download.xs b/grpmi/curl_download/curl_download.xs
index ab200d6f..2297555d 100644
--- a/grpmi/curl_download/curl_download.xs
+++ b/grpmi/curl_download/curl_download.xs
@@ -71,7 +71,7 @@ int my_progress_func(void *ptr, double td, double dd, double tu, double du)
return 0;
}
-char * download_url_real(char * url, char * location, char * proxy)
+char * download_url_real(char * url, char * location, char * proxy, char * proxy_user)
{
CURL *curl;
CURLcode rescurl = CURL_LAST;
@@ -108,6 +108,8 @@ char * download_url_real(char * url, char * location, char * proxy)
if (proxy && strcmp(proxy, ""))
curl_easy_setopt(curl, CURLOPT_PROXY, proxy);
+ if (proxy_user && strcmp(proxy_user, ""))
+ curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, proxy_user);
rescurl = curl_easy_perform(curl);
@@ -269,14 +271,15 @@ MODULE = curl_download PACKAGE = curl_download
PROTOTYPES : DISABLE
char *
-download(url, location, proxy, downloadprogress_callback)
+download_real(url, location, downloadprogress_callback, proxy, proxy_user)
char * url
char * location
- char * proxy
SV * downloadprogress_callback
+ char * proxy
+ char * proxy_user
CODE:
downloadprogress_callback_sv = downloadprogress_callback;
- RETVAL = download_url_real(url, location, proxy);
+ RETVAL = download_url_real(url, location, proxy, proxy_user);
OUTPUT:
RETVAL
diff --git a/grpmi/grpmi.pl b/grpmi/grpmi.pl
index ea9c165b..b76f23a3 100755
--- a/grpmi/grpmi.pl
+++ b/grpmi/grpmi.pl
@@ -81,8 +81,6 @@ my $exitstatus = -1;
# -=-=-=---=-=-=---=-=-=-- download potential URL's, and verify signatures -=-=-=---=-=-=--
-my $proxy;
-/http_proxy = (http:[^:]+:\d+)/ and $proxy = $1 foreach cat_("$ENV{HOME}/.wgetrc");
my $cache_location = '/var/cache/urpmi/rpms';
my $url_regexp = '^http://|^https://|^ftp://';
my $nb_downloads = int(grep { m,$url_regexp, } @ARGV);
@@ -93,8 +91,7 @@ for (my $i=0; $i<@ARGV; $i++) {
$download_progress++;
$label->set(_("Downloading package `%s' (%s/%s)...", basename($ARGV[$i]), $download_progress, $nb_downloads));
select(undef, undef, undef, 0.1); $mainw->flush; #- hackish :-(
- my $res = curl_download::download($ARGV[$i], $cache_location, $proxy,
- sub { $_[0] and $progressbar->update($_[1]/$_[0]); $mainw->flush });
+ my $res = curl_download::download($ARGV[$i], $cache_location, sub { $_[0] and $progressbar->update($_[1]/$_[0]); $mainw->flush });
my $url = $ARGV[$i];
$ARGV[$i] = "$cache_location/" . basename($ARGV[$i]);
if ($res) {