ref: refs/heads/SuSE-Code-11-Branch
commit cccfb2677bdd80dea8e846dd5723a4411d5591ab
Author: Michael Andres
Date: Thu Aug 27 13:19:47 2009 +0200
Log redirections when cURL media backend is used (fate #305320, bnc #522260).
---
zypp/media/MediaCurl.cc | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/zypp/media/MediaCurl.cc b/zypp/media/MediaCurl.cc
index 7fd0160..411a784 100644
--- a/zypp/media/MediaCurl.cc
+++ b/zypp/media/MediaCurl.cc
@@ -111,6 +111,41 @@ namespace
}
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 {
@@ -347,6 +382,8 @@ void MediaCurl::attachTo (bool next)
}
}
+ curl_easy_setopt(_curl, CURLOPT_HEADERFUNCTION, log_redirects_curl);
+
CURLcode ret = curl_easy_setopt( _curl, CURLOPT_ERRORBUFFER, _curlError );
if ( ret != 0 ) {
disconnectFrom();
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org