libzypp  17.25.2
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 
32 //do not export
33 namespace internal {
34 
36 {
37  ProgressData( CURL *_curl, time_t _timeout = 0, const zypp::Url & _url = zypp::Url(),
38  zypp::ByteCount expectedFileSize_r = 0,
40 
41  CURL *curl;
43  time_t timeout;
44  bool reached;
48 
49  time_t _timeStart = 0;
50  time_t _timeLast = 0;
51  time_t _timeRcv = 0;
52  time_t _timeNow = 0;
53 
54  double _dnlTotal = 0.0;
55  double _dnlLast = 0.0;
56  double _dnlNow = 0.0;
57 
58  int _dnlPercent= 0;
59 
60  double _drateTotal= 0.0;
61  double _drateLast = 0.0;
62 
63  void updateStats( double dltotal = 0.0, double dlnow = 0.0 );
64 
65  int reportProgress() const;
66 
67 
68  // download rate of the last period (cca 1 sec)
69  double drate_period;
70  // bytes downloaded at the start of the last period
71  double dload_period;
72  // seconds from the start of the download
73  long secs;
74  // average download rate
75  double drate_avg;
76  // last time the progress was reported
77  time_t ltime;
78  // bytes downloaded at the moment the progress was last reported
79  double dload;
80  // bytes uploaded at the moment the progress was last reported
81  double uload;
82 };
83 
84 namespace env {
87  {
88  static int _v = getZYPP_MEDIA_CURL_IPRESOLVE();
89  return _v;
90  }
91 }
92 
93 void globalInitCurlOnce();
94 int log_curl(CURL *curl, curl_infotype info, char *ptr, size_t len, void *max_lvl);
95 size_t log_redirects_curl( char *ptr, size_t size, size_t nmemb, void *userdata);
96 
97 
100 
105 const char * anonymousIdHeader();
106 
111 const char * distributionFlavorHeader();
112 
117 const char * agentString();
118 
119 void curlEscape( std::string & str_r, const char char_r, const std::string & escaped_r );
120 std::string curlEscapedPath( std::string path_r );
121 std::string curlUnEscape( std::string text_r );
122 
124 zypp::Url propagateQueryParams( zypp::Url url_r, const zypp::Url & template_r );
125 
126 }
127 
128 
129 
130 
131 #endif
void globalInitCurlOnce()
Definition: CurlHelper.cc:19
size_t log_redirects_curl(char *ptr, size_t size, size_t nmemb, void *userdata)
Definition: CurlHelper.cc:62
const char * anonymousIdHeader()
initialized only once, this gets the anonymous id from the target, which we pass in the http header ...
Definition: CurlHelper.cc:294
zypp::Url propagateQueryParams(zypp::Url url_r, const zypp::Url &template_r)
Definition: CurlHelper.cc:384
int getZYPP_MEDIA_CURL_IPRESOLVE()
Definition: CurlHelper.cc:281
Store and operate with byte count.
Definition: ByteCount.h:30
Holds transfer setting.
int reportProgress() const
Definition: CurlHelper.cc:454
Url clearQueryString(const Url &url)
Definition: CurlHelper.cc:358
std::string curlEscapedPath(std::string path_r)
Definition: CurlHelper.cc:346
time_t _timeNow
Now.
Definition: CurlHelper.h:52
const char * distributionFlavorHeader()
initialized only once, this gets the distribution flavor from the target, which we pass in the http h...
Definition: CurlHelper.cc:308
void curlEscape(std::string &str_r, const char char_r, const std::string &escaped_r)
Definition: CurlHelper.cc:338
double _dnlTotal
Bytes to download or 0 if unknown.
Definition: CurlHelper.h:54
double _dnlLast
Bytes downloaded at period start.
Definition: CurlHelper.h:55
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:110
zypp::ByteCount _expectedFileSize
Definition: CurlHelper.h:47
int _dnlPercent
Percent completed or 0 if _dnlTotal is unknown.
Definition: CurlHelper.h:58
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:395
double _drateLast
Download rate in last period.
Definition: CurlHelper.h:61
std::string curlUnEscape(std::string text_r)
Definition: CurlHelper.cc:351
time_t _timeStart
Start total stats.
Definition: CurlHelper.h:49
double _dnlNow
Bytes downloaded now.
Definition: CurlHelper.h:56
const char * agentString()
initialized only once, this gets the agent string which also includes the curl version ...
Definition: CurlHelper.cc:322
void updateStats(double dltotal=0.0, double dlnow=0.0)
Definition: CurlHelper.cc:405
void fillSettingsSystemProxy(const Url &url, media::TransferSettings &s)
Reads the system proxy configuration and fills the settings structure proxy information.
Definition: CurlHelper.cc:258
double _drateTotal
Download rate so far.
Definition: CurlHelper.h:60
time_t _timeRcv
Start of no-data timeout.
Definition: CurlHelper.h:51
int log_curl(CURL *curl, curl_infotype info, char *ptr, size_t len, void *max_lvl)
Definition: CurlHelper.cc:28
time_t _timeLast
Start last period(~1sec)
Definition: CurlHelper.h:50
Url manipulation class.
Definition: Url.h:87
int ZYPP_MEDIA_CURL_IPRESOLVE()
Definition: CurlHelper.h:86
zypp::callback::SendReport< zypp::media::DownloadProgressReport > * report
Definition: CurlHelper.h:46