11 class CurlException
{};
12 class TimeoutException
: public CurlException
{};
13 class UnsupportedProtocolException
: public CurlException
{};
14 class MalformedUrlException
: public CurlException
{};
15 class ConnectErrorException
: public CurlException
{};
16 class AccessDeniedException
: public CurlException
{};
17 class DoesNotExistException
: public CurlException
{};
23 SetConnectTimeout(20);
25 char templ
[] = "/tmp/curl_downloadXXXXXX";
26 close(mkstemp(templ
)); // ReneR: Hack alert!
30 void SetConnectTimeout (int value
) {connect_timeout
= value
;}
31 void SetMaxTime (int value
) {max_time
= value
;}
33 void Download (const std::string
& url
) {
39 void Download (std::string url
, unsigned int start
, unsigned int end
) {
41 params
<< " -r " << start
<< "-" << end
<< " " << url
;
45 std::string
GetCommand () {return params
.str();}
47 void SetFile (const std::string
& name
) {filename
= name
;}
49 std::auto_ptr
<std::ifstream
> OpenFile () {
50 std::auto_ptr
<std::ifstream
> r (new std::ifstream());
51 r
->open(filename
.c_str());
55 void RemoveFile () {unlink (filename
.c_str());}
60 std::string cmd
= GetCommand();
61 size_t it
= cmd
.find("&");
62 while (it
!= std::string::npos
) {
63 cmd
.replace(it
, it
, "\\");
64 it
= cmd
.find("&", it
+ 2);
67 int ret
= system(cmd
.c_str());
71 throw UnsupportedProtocolException();
75 throw MalformedUrlException();
80 throw ConnectErrorException();
84 throw AccessDeniedException();
86 throw DoesNotExistException();
88 throw TimeoutException();
90 throw CurlException();
94 void GenParamString () {
95 std::string
empty("");
96 params
.rdbuf()->str(empty
);
97 params
<< "curl -A T2-updater --disable-epsv --location -f -o " << filename
;
98 if (connect_timeout
> 0)
99 params
<< " --connect-timeout " << connect_timeout
;
101 params
<< " --max-time " << max_time
;
106 std::string filename
;
108 std::stringstream params
;