}
return 0;
}
+
+ static size_t
+ log_redirects_curl(
+ void *ptr, size_t size, size_t nmemb, void *stream)
+ {
+ // INT << "got header: " << string((char *)ptr, ((char*)ptr) + size*nmemb) << endl;
+
+ char * lstart = (char *)ptr, * lend = (char *)ptr;
+ size_t pos = 0;
+ size_t max = size * nmemb;
+ while (pos + 1 < max)
+ {
+ // get line
+ for (lstart = lend; *lend != '\n' && pos < max; ++lend, ++pos);
+
+ // look for "Location"
+ string line(lstart, lend);
+ if (line.find("Location") != string::npos)
+ {
+ DBG << "redirecting to " << line << endl;
+ return max;
+ }
+
+ // continue with the next line
+ if (pos + 1 < max)
+ {
+ ++lend;
+ ++pos;
+ }
+ else
+ break;
+ }
+
+ return max;
+ }
}
namespace zypp {
if ( url.getScheme() == "ftp" && s.username().empty() )
s.setAnonymousAuth();
}
-
+
if ( url.getScheme() == "https" )
{
s.setVerifyPeerEnabled(false);
}
}
}
-
+
Pathname ca_path = Pathname(url.getQueryParam("ssl_capath")).asString();
if( ! ca_path.empty())
- {
+ {
if( !PathInfo(ca_path).isDir() || !Pathname(ca_path).absolute())
ZYPP_THROW(MediaBadUrlException(url, "Invalid ssl_capath path"));
else
s.setProxy(proxy);
s.setProxyEnabled(true);
}
-}
+}
/**
* Reads the system proxy configuration and fills the settings
if ( s.proxyEnabled() )
s.setProxy(proxy_info.proxy(url.getScheme()));
}
-}
+}
Pathname MediaCurl::_cookieFile = "/var/lib/YaST2/cookies";
ZYPP_THROW(MediaCurlSetOptException(_url, _curlError)); \
} \
}
-
+
MediaCurl::MediaCurl( const Url & url_r,
const Pathname & attach_point_hint_r )
: MediaHandler( url_r, attach_point_hint_r,
}
}
+ curl_easy_setopt(_curl, CURLOPT_HEADERFUNCTION, log_redirects_curl);
+
CURLcode ret = curl_easy_setopt( _curl, CURLOPT_ERRORBUFFER, _curlError );
if ( ret != 0 ) {
disconnectFrom();
// reset settings in case we are re-attaching
_settings.reset();
-
+
// add custom headers
_settings.addHeader(anonymousIdHeader());
_settings.addHeader(distributionFlavorHeader());
disconnectFrom();
ZYPP_RETHROW(e);
}
-
- // if the proxy was not set by url, then look
+
+ // if the proxy was not set by url, then look
if ( _settings.proxy().empty() )
{
// at the system proxy settings
if ( _url.getScheme() == "https" )
{
- if( _settings.verifyPeerEnabled() ||
+ if( _settings.verifyPeerEnabled() ||
_settings.verifyHostEnabled() )
{
- SET_OPTION(CURLOPT_CAPATH, _settings.certificateAuthoritiesPath().c_str());
+ SET_OPTION(CURLOPT_CAPATH, _settings.certificateAuthoritiesPath().c_str());
}
SET_OPTION(CURLOPT_SSL_VERIFYPEER, _settings.verifyPeerEnabled() ? 1L : 0L);
SET_OPTION(CURLOPT_PROXY, _settings.proxy().c_str());
/*---------------------------------------------------------------*
CURLOPT_PROXYUSERPWD: [user name]:[password]
-
+
Url::option(proxyuser and proxypassword) -> CURLOPT_PROXYUSERPWD
If not provided, $HOME/.curlrc is evaluated
*---------------------------------------------------------------*/
-
+
string proxyuserpwd = _settings.proxyUserPassword();
if ( proxyuserpwd.empty() )
SET_OPTION(CURLOPT_PROXYUSERPWD, proxyuserpwd.c_str());
}
}
-
+
/** Speed limits */
if ( _settings.minDownloadSpeed() != 0 )
{
// default to 10 seconds at low speed
SET_OPTION(CURLOPT_LOW_SPEED_TIME, 10);
}
-
+
if ( _settings.maxDownloadSpeed() != 0 )
SET_OPTION(CURLOPT_MAX_RECV_SPEED_LARGE, _settings.maxDownloadSpeed());
it != _settings.headersEnd();
++it )
{
-
+
_customHeaders = curl_slist_append(_customHeaders, it->c_str());
if ( !_customHeaders )
ZYPP_THROW(MediaCurlInitException(_url));
bool timeout_reached ) const
{
Url url(getFileUrl(_url, filename));
-
+
if ( code != 0 )
{
std::string err;
case 401:
{
string auth_hint = getAuthHint();
-
+
DBG << msg << " Login failed (URL: " << url.asString() << ")" << std::endl;
DBG << "MediaUnauthorizedException auth hint: '" << auth_hint << "'" << std::endl;
-
+
ZYPP_THROW(MediaUnauthorizedException(
url, "Login failed.", _curlError, auth_hint
));
}
-
+
case 503: // service temporarily unavailable (bnc #462545)
- ZYPP_THROW(MediaTemporaryProblemException(url));
+ ZYPP_THROW(MediaTemporaryProblemException(url));
case 504: // gateway timeout
- ZYPP_THROW(MediaTimeoutException(url));
+ ZYPP_THROW(MediaTimeoutException(url));
case 403:
- ZYPP_THROW(MediaForbiddenException(url));
+ ZYPP_THROW(MediaForbiddenException(url));
case 404:
ZYPP_THROW(MediaFileNotFoundException(_url, filename));
}
-
+
DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
ZYPP_THROW(MediaCurlException(url, msg, _curlError));
}
err = "Unrecognized error";
break;
}
-
+
// uhm, no 0 code but unknown curl exception
ZYPP_THROW(MediaCurlException(url, err, _curlError));
}
else
{
// actually the code is 0, nothing happened
- }
-}
+ }
+}
///////////////////////////////////////////////////////////////////
ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
}
}
-
+
// if the code is not zero, close the file
if ( ok != 0 )
::fclose(file);
-
+
// as we are not having user interaction, the user can't cancel
// the file existence checking, a callback or timeout return code
// will be always a timeout.
ZYPP_RETHROW(e);
}
}
-
+
#if DETECT_DIR_INDEX
else
if(curlUrl.getScheme() == "http" ||