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
internal::curlUnEscape
std::string curlUnEscape(std::string text_r)
Definition: CurlHelper.cc:351
internal::ProgressData::url
zypp::Url url
Definition: CurlHelper.h:42
internal::agentString
const char * agentString()
initialized only once, this gets the agent string which also includes the curl version
Definition: CurlHelper.cc:322
zypp::callback::SendReport< zypp::media::DownloadProgressReport >
internal::ProgressData::curl
CURL * curl
Definition: CurlHelper.h:41
internal::ProgressData::_timeStart
time_t _timeStart
Start total stats.
Definition: CurlHelper.h:49
internal::log_curl
int log_curl(CURL *curl, curl_infotype info, char *ptr, size_t len, void *max_lvl)
Definition: CurlHelper.cc:28
internal::fillSettingsSystemProxy
void fillSettingsSystemProxy(const Url &url, media::TransferSettings &s)
Reads the system proxy configuration and fills the settings structure proxy information.
Definition: CurlHelper.cc:258
internal::ProgressData::_drateTotal
double _drateTotal
Download rate so far.
Definition: CurlHelper.h:60
internal::ProgressData::uload
double uload
Definition: CurlHelper.h:81
internal::anonymousIdHeader
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
internal::ProgressData::_dnlLast
double _dnlLast
Bytes downloaded at period start.
Definition: CurlHelper.h:55
zypp::media::TransferSettings
Holds transfer setting.
Definition: TransferSettings.h:25
internal::fillSettingsFromUrl
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
Store and operate with byte count.
Definition: ByteCount.h:31
internal::globalInitCurlOnce
void globalInitCurlOnce()
Definition: CurlHelper.cc:19
internal::env::ZYPP_MEDIA_CURL_IPRESOLVE
int ZYPP_MEDIA_CURL_IPRESOLVE()
Definition: CurlHelper.h:86
internal::ProgressData::dload_period
double dload_period
Definition: CurlHelper.h:71
Url.h
internal::curlEscapedPath
std::string curlEscapedPath(std::string path_r)
Definition: CurlHelper.cc:346
internal::ProgressData::_timeRcv
time_t _timeRcv
Start of no-data timeout.
Definition: CurlHelper.h:51
internal::clearQueryString
Url clearQueryString(const Url &url)
Definition: CurlHelper.cc:358
internal::ProgressData::_timeLast
time_t _timeLast
Start last period(~1sec)
Definition: CurlHelper.h:50
internal::ProgressData::_timeNow
time_t _timeNow
Now.
Definition: CurlHelper.h:52
internal::ProgressData::ltime
time_t ltime
Definition: CurlHelper.h:77
ZYppCallbacks.h
internal::ProgressData::_drateLast
double _drateLast
Download rate in last period.
Definition: CurlHelper.h:61
TransferSettings.h
internal::ProgressData::ProgressData
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
internal::curlEscape
void curlEscape(std::string &str_r, const char char_r, const std::string &escaped_r)
Definition: CurlHelper.cc:338
internal::env::getZYPP_MEDIA_CURL_IPRESOLVE
int getZYPP_MEDIA_CURL_IPRESOLVE()
Definition: CurlHelper.cc:281
internal::ProgressData::timeout
time_t timeout
Definition: CurlHelper.h:43
internal::ProgressData::reportProgress
int reportProgress() const
Definition: CurlHelper.cc:454
internal::ProgressData::_dnlTotal
double _dnlTotal
Bytes to download or 0 if unknown.
Definition: CurlHelper.h:54
internal::ProgressData::dload
double dload
Definition: CurlHelper.h:79
internal::ProgressData::secs
long secs
Definition: CurlHelper.h:73
internal::ProgressData::drate_avg
double drate_avg
Definition: CurlHelper.h:75
internal::propagateQueryParams
zypp::Url propagateQueryParams(zypp::Url url_r, const zypp::Url &template_r)
Definition: CurlHelper.cc:384
internal::ProgressData::report
zypp::callback::SendReport< zypp::media::DownloadProgressReport > * report
Definition: CurlHelper.h:46
internal::distributionFlavorHeader
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
internal::ProgressData::fileSizeExceeded
bool fileSizeExceeded
Definition: CurlHelper.h:45
internal::ProgressData::_dnlNow
double _dnlNow
Bytes downloaded now.
Definition: CurlHelper.h:56
internal
Definition: CurlHelper.cc:17
internal::ProgressData::_dnlPercent
int _dnlPercent
Percent completed or 0 if _dnlTotal is unknown.
Definition: CurlHelper.h:58
internal::ProgressData::_expectedFileSize
zypp::ByteCount _expectedFileSize
Definition: CurlHelper.h:47
internal::ProgressData::updateStats
void updateStats(double dltotal=0.0, double dlnow=0.0)
Definition: CurlHelper.cc:405
zypp::Url
Url manipulation class.
Definition: Url.h:88
internal::log_redirects_curl
size_t log_redirects_curl(char *ptr, size_t size, size_t nmemb, void *userdata)
Definition: CurlHelper.cc:62
internal::ProgressData::drate_period
double drate_period
Definition: CurlHelper.h:69
internal::ProgressData
Definition: CurlHelper.h:36
internal::ProgressData::reached
bool reached
Definition: CurlHelper.h:44