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)
31 if ( max_lvl ==
nullptr )
34 long maxlvl = *((
long *)max_lvl);
39 case CURLINFO_TEXT:
if ( maxlvl < 1 )
return 0; pfx =
'*';
break;
40 case CURLINFO_HEADER_IN:
if ( maxlvl < 2 )
return 0; pfx =
'<';
break;
41 case CURLINFO_HEADER_OUT:
if ( maxlvl < 2 )
return 0; pfx =
'>';
break;
46 std::vector<std::string> lines;
47 str::split( std::string(ptr,len), std::back_inserter(lines),
"\r\n" );
48 for(
const auto & line : lines )
52 if ( pos == std::string::npos )
54 DBG << pfx <<
" " << line.substr( 0, pos ) <<
" <credentials removed>" << std::endl;
57 DBG << pfx <<
" " << line << std::endl;
66 char * lstart = ptr, * lend = ptr;
68 size_t max = size * nmemb;
72 for (lstart = lend; *lend !=
'\n' && pos < max; ++lend, ++pos);
85 std::string line { lstart, *(lend-1)==
'\r' ? lend-1 : lend };
86 DBG <<
"redirecting to " << line << std::endl;
88 *
reinterpret_cast<std::string *
>( userdata ) = line;
114 if( ! param.empty() )
116 long num = str::strtonum<long>(param);
123 if ( ! param.empty() )
127 if ( ! param.empty() )
143 if( verify.empty() || verify ==
"yes" )
148 else if ( verify ==
"no" )
155 std::vector<std::string> flags;
156 str::split( verify, std::back_inserter(flags),
"," );
157 for (
const auto & flag : flags )
159 if ( flag ==
"host" )
161 else if ( flag ==
"peer" )
170 if( ! ca_path.empty() )
180 if( ! client_cert.empty() )
182 if( !
PathInfo(client_cert).
isFile() || ! client_cert.absolute() )
190 if( ! client_key.empty() )
200 if ( ! param.empty() )
212 if ( ! proxyport.empty() ) {
223 if ( ! param.empty() )
240 DBG <<
"Rethrowing as MediaUnauthorizedException.";
249 if( ! param.empty() && param ==
"no" )
284 if (
const char * envp = getenv(
"ZYPP_MEDIA_CURL_IPRESOLVE" ) )
286 WAR <<
"env set: $ZYPP_MEDIA_CURL_IPRESOLVE='" << envp <<
"'" << std::endl;
287 if ( strcmp( envp,
"4" ) == 0 ) ret = 4;
288 else if ( strcmp( envp,
"6" ) == 0 ) ret = 6;
300 static const std::string
_value(
302 "X-ZYpp-AnonymousId: %s",
314 static const std::string
_value(
316 "X-ZYpp-DistributionFlavor: %s",
328 static const std::string
_value(
330 "ZYpp " LIBZYPP_VERSION_STRING
" (curl %s) %s" 331 , curl_version_info(CURLVERSION_NOW)->version
339 const char char_r,
const std::string & escaped_r ) {
341 pos != std::string::npos; pos = str_r.find( char_r, pos ) ) {
342 str_r.replace( pos, 1, escaped_r );
352 char * tmp = curl_unescape( text_r.c_str(), 0 );
353 std::string ret( tmp );
386 for ( std::string param : {
"proxy",
"proxyport",
"proxyuser",
"proxypass"} )
388 const std::string & value( template_r.
getQueryParam( param ) );
389 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)
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
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.