aboutsummaryrefslogtreecommitdiffstats
path: root/grpmi/curl_download/curl_download.pm
blob: 7c6ec47286e3c2acfb0c7a77d24f595ae725c0bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package curl_download;

use strict;
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;