22 static bool once __attribute__ ((__unused__)) = ( [] {
23 if ( curl_global_init( CURL_GLOBAL_ALL ) != 0 )
24 WAR <<
"curl global init failed" << std::endl;
29 char *ptr,
size_t len,
void *max_lvl)
35 case CURLINFO_TEXT: lvl = 1; pfx =
"*";
break;
36 case CURLINFO_HEADER_IN: lvl = 2; pfx =
"<";
break;
37 case CURLINFO_HEADER_OUT: lvl = 2; pfx =
">";
break;
40 if( lvl > 0 && max_lvl != NULL && lvl <= *((
long *)max_lvl))
42 std::string msg(ptr, len);
43 std::list<std::string> lines;
44 std::list<std::string>::const_iterator line;
46 for(line = lines.begin(); line != lines.end(); ++line)
48 DBG << pfx <<
" " << *line << std::endl;
58 char * lstart = ptr, * lend = ptr;
60 size_t max = size * nmemb;
64 for (lstart = lend; *lend !=
'\n' && pos < max; ++lend, ++pos);
77 std::string line { lstart, *(lend-1)==
'\r' ? lend-1 : lend };
78 DBG <<
"redirecting to " << line << std::endl;
80 *
reinterpret_cast<std::string *
>( userdata ) = line;
106 if( ! param.empty() )
108 long num = str::strtonum<long>(param);
115 if ( ! param.empty() )
119 if ( ! param.empty() )
135 if( verify.empty() || verify ==
"yes" )
140 else if ( verify ==
"no" )
147 std::vector<std::string> flags;
148 str::split( verify, std::back_inserter(flags),
"," );
149 for (
const auto & flag : flags )
151 if ( flag ==
"host" )
153 else if ( flag ==
"peer" )
162 if( ! ca_path.empty() )
172 if( ! client_cert.empty() )
174 if( !
PathInfo(client_cert).
isFile() || ! client_cert.absolute() )
182 if( ! client_key.empty() )
192 if ( ! param.empty() )
204 if ( ! proxyport.empty() ) {
215 if ( ! param.empty() )
232 DBG <<
"Rethrowing as MediaUnauthorizedException.";
241 if( ! param.empty() && param ==
"no" )
276 if (
const char * envp = getenv(
"ZYPP_MEDIA_CURL_IPRESOLVE" ) )
278 WAR <<
"env set: $ZYPP_MEDIA_CURL_IPRESOLVE='" << envp <<
"'" << std::endl;
279 if ( strcmp( envp,
"4" ) == 0 ) ret = 4;
280 else if ( strcmp( envp,
"6" ) == 0 ) ret = 6;
292 static const std::string
_value(
294 "X-ZYpp-AnonymousId: %s",
306 static const std::string
_value(
308 "X-ZYpp-DistributionFlavor: %s",
320 static const std::string
_value(
322 "ZYpp " LIBZYPP_VERSION_STRING
" (curl %s) %s" 323 , curl_version_info(CURLVERSION_NOW)->version
331 const char char_r,
const std::string & escaped_r ) {
333 pos != std::string::npos; pos = str_r.find( char_r, pos ) ) {
334 str_r.replace( pos, 1, escaped_r );
344 char * tmp = curl_unescape( text_r.c_str(), 0 );
345 std::string ret( tmp );
378 for ( std::string param : {
"proxy",
"proxyport",
"proxyuser",
"proxypass"} )
380 const std::string & value( template_r.
getQueryParam( param ) );
381 if ( ! value.empty() )
std::string getScheme() const
Returns the scheme name of the URL.
void setPassword(const std::string &pass, EEncoding eflag=zypp::url::E_DECODED)
Set the password in the URL authority.
void globalInitCurlOnce()
std::string targetDistribution() const
This is register.target attribute of the installed base product.
size_t log_redirects_curl(char *ptr, size_t size, size_t nmemb, void *userdata)
void setQueryParam(const std::string ¶m, const std::string &value)
Set or add value for the specified query parameter.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
const char * anonymousIdHeader()
initialized only once, this gets the anonymous id from the target, which we pass in the http header ...
zypp::Url propagateQueryParams(zypp::Url url_r, const zypp::Url &template_r)
Flag to request encoded string(s).
int getZYPP_MEDIA_CURL_IPRESOLVE()
#define TRANSFER_TIMEOUT_MAX
Url clearQueryString(const Url &url)
static const ViewOption WITH_SCHEME
Option to include scheme name in the URL string.
static const ViewOption WITH_HOST
Option to include hostname in the URL string.
void setPathParams(const std::string ¶ms)
Set the path parameters.
std::string curlEscapedPath(std::string path_r)
void setUsername(const std::string &user, EEncoding eflag=zypp::url::E_DECODED)
Set the username in the URL authority.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
const char * distributionFlavorHeader()
initialized only once, this gets the distribution flavor from the target, which we pass in the http h...
void setFragment(const std::string &fragment, EEncoding eflag=zypp::url::E_DECODED)
Set the fragment string in the URL.
void curlEscape(std::string &str_r, const char char_r, const std::string &escaped_r)
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \, const Trim trim_r=NO_TRIM)
Split line_r into words.
std::string getQueryParam(const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
std::string trim(const std::string &s, const Trim trim_r)
void fillSettingsFromUrl(const Url &url, media::TransferSettings &s)
Fills the settings structure using options passed on the url for example ?timeout=x&proxy=foo.
std::string curlUnEscape(std::string text_r)
Wrapper class for ::stat/::lstat.
const char * agentString()
initialized only once, this gets the agent string which also includes the curl version ...
void fillSettingsSystemProxy(const Url &url, media::TransferSettings &s)
Reads the system proxy configuration and fills the settings structure proxy information.
std::string anonymousUniqueId() const
anonymous unique id
static const ViewOption WITH_PORT
Option to include port number in the URL string.
Easy-to use interface to the ZYPP dependency resolver.
std::string distributionFlavor() const
This is flavor attribute of the installed base product but does not require the target to be loaded a...
int log_curl(CURL *curl, curl_infotype info, char *ptr, size_t len, void *max_lvl)
std::string getPassword(EEncoding eflag=zypp::url::E_DECODED) const
Returns the password from the URL authority.
const char * c_str() const
#define EXPLICITLY_NO_PROXY
void delQueryParam(const std::string ¶m)
remove the specified query parameter.
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
const std::string & msg() const
Return the message string provided to the ctor.