*/
#include <iostream>
+#include <list>
#include "zypp/base/Logger.h"
#include "zypp/ExternalProgram.h"
{
zypp::thread::callOnce(g_InitOnceFlag, _do_init_once);
}
+
+ int log_curl(CURL *curl, curl_infotype info,
+ char *ptr, size_t len, void *max_lvl)
+ {
+ std::string pfx(" ");
+ long lvl = 0;
+ switch( info)
+ {
+ case CURLINFO_TEXT: lvl = 1; pfx = "*"; break;
+ case CURLINFO_HEADER_IN: lvl = 2; pfx = "<"; break;
+ case CURLINFO_HEADER_OUT: lvl = 2; pfx = ">"; break;
+ default: break;
+ }
+ if( lvl > 0 && max_lvl != NULL && lvl <= *((long *)max_lvl))
+ {
+ std::string msg(ptr, len);
+ std::list<std::string> lines;
+ std::list<std::string>::const_iterator line;
+ zypp::str::split(msg, std::back_inserter(lines), "\r\n");
+ for(line = lines.begin(); line != lines.end(); ++line)
+ {
+ DBG << pfx << " " << *line << endl;
+ }
+ }
+ return 0;
+ }
}
namespace zypp {
_curl( NULL )
{
_curlError[0] = '\0';
+ _curlDebug = 0L;
MIL << "MediaCurl::MediaCurl(" << url_r << ", " << attach_point_hint_r << ")" << endl;
ZYPP_THROW(MediaCurlInitException(_url));
}
+ {
+ char *ptr = getenv("ZYPP_MEDIA_CURL_DEBUG");
+ _curlDebug = (ptr && *ptr) ? str::strtonum<long>( ptr) : 0L;
+ if( _curlDebug > 0)
+ {
+ curl_easy_setopt( _curl, CURLOPT_VERBOSE, 1);
+ curl_easy_setopt( _curl, CURLOPT_DEBUGFUNCTION, log_curl);
+ curl_easy_setopt( _curl, CURLOPT_DEBUGDATA, &_curlDebug);
+ }
+ }
+
CURLcode ret = curl_easy_setopt( _curl, CURLOPT_ERRORBUFFER, _curlError );
if ( ret != 0 ) {
disconnectFrom();
// little data, that works with broken servers, and
// works for ftp as well, because retrieving only headers
// ftp will return always OK code ?
- ret = curl_easy_setopt( _curl, CURLOPT_RANGE, "0-100" );
+ ret = curl_easy_setopt( _curl, CURLOPT_RANGE, "0-1" );
if ( ret != 0 ) {
ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
}
if ( !file ) {
::fclose(file);
ERR << "fopen failed for /dev/null" << endl;
+ curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
+ if ( ret != 0 ) {
+ ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
+ }
ZYPP_THROW(MediaWriteException("/dev/null"));
}
ret = curl_easy_setopt( _curl, CURLOPT_WRITEDATA, file );
if ( ret != 0 ) {
::fclose(file);
- ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
+ std::string err( _curlError);
+ curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
+ if ( ret != 0 ) {
+ ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
+ }
+ ZYPP_THROW(MediaCurlSetOptException(url, err));
}
// Set callback and perform.
//ProgressData progressData(_xfer_timeout, url, &report);
CURLcode ok = curl_easy_perform( _curl );
MIL << "perform code: " << ok << " [ " << curl_easy_strerror(ok) << " ]" << endl;
+
+ ret = curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
+ if ( ret != 0 ) {
+ ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
+ }
+
return ( ok == CURLE_OK );
//if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, NULL ) != 0 ) {
// WAR << "Can't unset CURLOPT_PROGRESSDATA: " << _curlError << endl;;