libzypp  17.28.5
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 
31 namespace zypp
32 {
33  namespace env
34  {
36  inline long ZYPP_MEDIA_CURL_DEBUG()
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
50 namespace 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)
86  double drate_period;
87  // bytes downloaded at the start of the last period
88  double dload_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 
101 void globalInitCurlOnce();
102 int log_curl(CURL *curl, curl_infotype info, char *ptr, size_t len, void *max_lvl);
103 size_t log_redirects_curl( char *ptr, size_t size, size_t nmemb, void *userdata);
104 
105 
108 
113 const char * anonymousIdHeader();
114 
119 const char * distributionFlavorHeader();
120 
125 const char * agentString();
126 
127 void curlEscape( std::string & str_r, const char char_r, const std::string & escaped_r );
128 std::string curlEscapedPath( std::string path_r );
129 std::string curlUnEscape( std::string text_r );
130 
132 zypp::Url propagateQueryParams( zypp::Url url_r, const zypp::Url & template_r );
133 
134 }
135 
136 
137 
138 
139 #endif
void globalInitCurlOnce()
Definition: CurlHelper.cc:46
size_t log_redirects_curl(char *ptr, size_t size, size_t nmemb, void *userdata)
Definition: CurlHelper.cc:89
const char * anonymousIdHeader()
initialized only once, this gets the anonymous id from the target, which we pass in the http header ...
Definition: CurlHelper.cc:300
zypp::Url propagateQueryParams(zypp::Url url_r, const zypp::Url &template_r)
Definition: CurlHelper.cc:390
Store and operate with byte count.
Definition: ByteCount.h:30
Holds transfer setting.
int reportProgress() const
Definition: CurlHelper.cc:460
Url clearQueryString(const Url &url)
Definition: CurlHelper.cc:364
std::string curlEscapedPath(std::string path_r)
Definition: CurlHelper.cc:352
time_t _timeNow
Now.
Definition: CurlHelper.h:69
const char * distributionFlavorHeader()
initialized only once, this gets the distribution flavor from the target, which we pass in the http h...
Definition: CurlHelper.cc:314
int ZYPP_MEDIA_CURL_IPRESOLVE()
4/6 to force IPv4/v6
Definition: CurlHelper.cc:35
void curlEscape(std::string &str_r, const char char_r, const std::string &escaped_r)
Definition: CurlHelper.cc:344
double _dnlTotal
Bytes to download or 0 if unknown.
Definition: CurlHelper.h:71
double _dnlLast
Bytes downloaded at period start.
Definition: CurlHelper.h:72
TInt strtonum(const C_Str &str)
Parsing numbers from string.
Definition: String.h:388
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
zypp::ByteCount _expectedFileSize
Definition: CurlHelper.h:64
int _dnlPercent
Percent completed or 0 if _dnlTotal is unknown.
Definition: CurlHelper.h:75
long ZYPP_MEDIA_CURL_DEBUG()
Long number for setting CURLOPT_DEBUGDATA.
Definition: CurlHelper.h:36
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:401
double _drateLast
Download rate in last period.
Definition: CurlHelper.h:78
std::string curlUnEscape(std::string text_r)
Definition: CurlHelper.cc:357
time_t _timeStart
Start total stats.
Definition: CurlHelper.h:66
double _dnlNow
Bytes downloaded now.
Definition: CurlHelper.h:73
const char * agentString()
initialized only once, this gets the agent string which also includes the curl version ...
Definition: CurlHelper.cc:328
void updateStats(double dltotal=0.0, double dlnow=0.0)
Definition: CurlHelper.cc:411
void fillSettingsSystemProxy(const Url &url, media::TransferSettings &s)
Reads the system proxy configuration and fills the settings structure proxy information.
Definition: CurlHelper.cc:277
double _drateTotal
Download rate so far.
Definition: CurlHelper.h:77
time_t _timeRcv
Start of no-data timeout.
Definition: CurlHelper.h:68
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
int log_curl(CURL *curl, curl_infotype info, char *ptr, size_t len, void *max_lvl)
Definition: CurlHelper.cc:55
time_t _timeLast
Start last period(~1sec)
Definition: CurlHelper.h:67
Url manipulation class.
Definition: Url.h:91
zypp::callback::SendReport< zypp::media::DownloadProgressReport > * report
Definition: CurlHelper.h:63