libzypp 17.28.8
CurlHelper.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* You have been warned!
12*
13*/
14#ifndef ZYPP_MEDIA_CURLHELPER_H_INCLUDED
15#define ZYPP_MEDIA_CURLHELPER_H_INCLUDED
16
17#include <curl/curl.h>
18#include <zypp/Url.h>
20#include <zypp/ZYppCallbacks.h>
21
22#define CONNECT_TIMEOUT 60
23#define TRANSFER_TIMEOUT_MAX 60 * 60
24#define DETECT_DIR_INDEX 0
25
26#define EXPLICITLY_NO_PROXY "_none_"
27
28#undef CURLVERSION_AT_LEAST
29#define CURLVERSION_AT_LEAST(M,N,O) LIBCURL_VERSION_NUM >= ((((M)<<8)+(N))<<8)+(O)
30
31namespace zypp
32{
33 namespace env
34 {
37 {
38 long ret = 0L;
39 if ( char *ptr = ::getenv("ZYPP_MEDIA_CURL_DEBUG"); ptr && *ptr )
40 str::strtonum( ptr, ret );
41 return ret;
42 }
43
46 } // namespace env
47} //namespace zypp
48
49//do not export
50namespace internal {
51
53{
54 ProgressData( CURL *_curl, time_t _timeout = 0, const zypp::Url & _url = zypp::Url(),
55 zypp::ByteCount expectedFileSize_r = 0,
57
58 CURL *curl;
60 time_t timeout;
61 bool reached;
65
66 time_t _timeStart = 0;
67 time_t _timeLast = 0;
68 time_t _timeRcv = 0;
69 time_t _timeNow = 0;
70
71 double _dnlTotal = 0.0;
72 double _dnlLast = 0.0;
73 double _dnlNow = 0.0;
74
75 int _dnlPercent= 0;
76
77 double _drateTotal= 0.0;
78 double _drateLast = 0.0;
79
80 void updateStats( double dltotal = 0.0, double dlnow = 0.0 );
81
82 int reportProgress() const;
83
84
85 // download rate of the last period (cca 1 sec)
87 // bytes downloaded at the start of the last period
89 // seconds from the start of the download
90 long secs;
91 // average download rate
92 double drate_avg;
93 // last time the progress was reported
94 time_t ltime;
95 // bytes downloaded at the moment the progress was last reported
96 double dload;
97 // bytes uploaded at the moment the progress was last reported
98 double uload;
99};
100
101void globalInitCurlOnce();
102int log_curl(CURL *curl, curl_infotype info, char *ptr, size_t len, void *max_lvl);
103size_t log_redirects_curl( char *ptr, size_t size, size_t nmemb, void *userdata);
104
105
108
109// Disable custom headers -- Arachnos
110#ifdef ANONYMOUS_ID
115const char * anonymousIdHeader();
116
121const char * distributionFlavorHeader();
122#endif
123
128const char * agentString();
129
130void curlEscape( std::string & str_r, const char char_r, const std::string & escaped_r );
131std::string curlEscapedPath( std::string path_r );
132std::string curlUnEscape( std::string text_r );
133
135zypp::Url propagateQueryParams( zypp::Url url_r, const zypp::Url & template_r );
136
137}
138
139
140
141
142#endif
Store and operate with byte count.
Definition: ByteCount.h:31
Url manipulation class.
Definition: Url.h:92
Holds transfer setting.
void fillSettingsFromUrl(const Url &url, media::TransferSettings &s)
Fills the settings structure using options passed on the url for example ?timeout=x&proxy=foo.
Definition: CurlHelper.cc:129
size_t log_redirects_curl(char *ptr, size_t size, size_t nmemb, void *userdata)
Definition: CurlHelper.cc:89
void globalInitCurlOnce()
Definition: CurlHelper.cc:46
zypp::Url propagateQueryParams(zypp::Url url_r, const zypp::Url &template_r)
Definition: CurlHelper.cc:393
std::string curlUnEscape(std::string text_r)
Definition: CurlHelper.cc:360
std::string curlEscapedPath(std::string path_r)
Definition: CurlHelper.cc:355
const char * agentString()
initialized only once, this gets the agent string which also includes the curl version
Definition: CurlHelper.cc:331
void fillSettingsSystemProxy(const Url &url, media::TransferSettings &s)
Reads the system proxy configuration and fills the settings structure proxy information.
Definition: CurlHelper.cc:277
Url clearQueryString(const Url &url)
Definition: CurlHelper.cc:367
void curlEscape(std::string &str_r, const char char_r, const std::string &escaped_r)
Definition: CurlHelper.cc:347
int log_curl(CURL *curl, curl_infotype info, char *ptr, size_t len, void *max_lvl)
Definition: CurlHelper.cc:55
int ZYPP_MEDIA_CURL_IPRESOLVE()
4/6 to force IPv4/v6
Definition: CurlHelper.cc:35
long ZYPP_MEDIA_CURL_DEBUG()
Long number for setting CURLOPT_DEBUGDATA.
Definition: CurlHelper.h:36
TInt strtonum(const C_Str &str)
Parsing numbers from string.
Definition: String.h:388
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::ByteCount _expectedFileSize
Definition: CurlHelper.h:64
ProgressData(CURL *_curl, time_t _timeout=0, const zypp::Url &_url=zypp::Url(), zypp::ByteCount expectedFileSize_r=0, zypp::callback::SendReport< zypp::media::DownloadProgressReport > *_report=nullptr)
Definition: CurlHelper.cc:404
void updateStats(double dltotal=0.0, double dlnow=0.0)
Definition: CurlHelper.cc:414
int _dnlPercent
Percent completed or 0 if _dnlTotal is unknown.
Definition: CurlHelper.h:75
time_t _timeRcv
Start of no-data timeout.
Definition: CurlHelper.h:68
time_t _timeLast
Start last period(~1sec)
Definition: CurlHelper.h:67
int reportProgress() const
Definition: CurlHelper.cc:463
double _drateLast
Download rate in last period.
Definition: CurlHelper.h:78
double _dnlTotal
Bytes to download or 0 if unknown.
Definition: CurlHelper.h:71
double _dnlNow
Bytes downloaded now.
Definition: CurlHelper.h:73
double _drateTotal
Download rate so far.
Definition: CurlHelper.h:77
zypp::callback::SendReport< zypp::media::DownloadProgressReport > * report
Definition: CurlHelper.h:63
double _dnlLast
Bytes downloaded at period start.
Definition: CurlHelper.h:72
time_t _timeStart
Start total stats.
Definition: CurlHelper.h:66