Author: dmacvicar Date: Wed Oct 22 14:19:23 2008 New Revision: 11444 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11444&view=rev Log: bnc#431571 : move unique id to private http header Modified: trunk/libzypp/package/libzypp.changes trunk/libzypp/zypp/media/MediaAria2c.cc trunk/libzypp/zypp/media/MediaAria2c.h trunk/libzypp/zypp/media/MediaCurl.cc trunk/libzypp/zypp/media/MediaCurl.h Modified: trunk/libzypp/package/libzypp.changes URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/package/libzypp.changes?rev=11444&r1=11443&r2=11444&view=diff ============================================================================== --- trunk/libzypp/package/libzypp.changes (original) +++ trunk/libzypp/package/libzypp.changes Wed Oct 22 14:19:23 2008 @@ -1,4 +1,10 @@ ------------------------------------------------------------------- +Wed Oct 22 14:16:33 CEST 2008 - dmacvicar@suse.de + +- move anonymous unique id to a private http header + X-ZYpp-AnonymousUniqueId (bnc#431571 ) + +------------------------------------------------------------------- Wed Oct 22 12:58:35 CEST 2008 - ma@suse.de - Adapt to satsolver-0.12 API. Modified: trunk/libzypp/zypp/media/MediaAria2c.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaAria2c.cc?rev=11444&r1=11443&r2=11444&view=diff ============================================================================== --- trunk/libzypp/zypp/media/MediaAria2c.cc (original) +++ trunk/libzypp/zypp/media/MediaAria2c.cc Wed Oct 22 14:19:23 2008 @@ -22,6 +22,9 @@ #include "zypp/base/Gettext.h" #include "zypp/ZYppCallbacks.h" +#include "zypp/Target.h" +#include "zypp/ZYppFactory.h" + #include "zypp/media/MediaAria2c.h" #include "zypp/media/proxyinfo/ProxyInfos.h" #include "zypp/media/ProxyInfo.h" @@ -76,13 +79,60 @@ return false; } +const char *const MediaAria2c::anonymousIdHeader() +{ + // we need to add the release and identifier to the + // agent string. + // The target could be not initialized, and then this information + // is not available. + Target_Ptr target; + // FIXME this has to go away as soon as the target + // does not throw when not initialized. + try { + target = zypp::getZYpp()->target(); + } + catch ( const Exception &e ) + { + // nothing to do + } + + static const std::string _value( + str::form( + "X-ZYpp-AnonymousUniqueId: %s", + target ? target->anonymousUniqueId().c_str() : "" ) + ); + return _value.c_str(); +} + const char *const MediaAria2c::agentString() { - static const std::string _value( str::form( "ZYpp %s (with %s)", VERSION, MediaAria2c::_aria2cVersion.c_str() )); - return _value.c_str(); - + // we need to add the release and identifier to the + // agent string. + // The target could be not initialized, and then this information + // is not available. + Target_Ptr target; + // FIXME this has to go away as soon as the target + // does not throw when not initialized. + try { + target = zypp::getZYpp()->target(); + } + catch ( const Exception &e ) + { + // nothing to do + } + + static const std::string _value( + str::form( + "ZYpp %s (aria2c %s) %s" + , VERSION + , MediaAria2c::_aria2cVersion.c_str() + , target ? target->targetDistribution().c_str() : "" + ) + ); + return _value.c_str(); } + MediaAria2c::MediaAria2c( const Url & url_r, const Pathname & attach_point_hint_r ) : MediaHandler( url_r, attach_point_hint_r, @@ -128,6 +178,10 @@ _args.push_back("--follow-metalink=mem"); _args.push_back("--check-integrity=true"); + // add the anonymous id. + _args.push_back(str::form("--header=\"%s\"", anonymousIdHeader() )); + + if ( next ) ZYPP_THROW(MediaNotSupportedException(_url)); Modified: trunk/libzypp/zypp/media/MediaAria2c.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaAria2c.h?rev=11444&r1=11443&r2=11444&view=diff ============================================================================== --- trunk/libzypp/zypp/media/MediaAria2c.h (original) +++ trunk/libzypp/zypp/media/MediaAria2c.h Wed Oct 22 14:19:23 2008 @@ -90,7 +90,8 @@ /** The user agent string */ static const char *const agentString(); - + /** anonymous id header used to count unique users */ + static const char *const anonymousIdHeader(); private: Modified: trunk/libzypp/zypp/media/MediaCurl.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaCurl.cc?rev=11444&r1=11443&r2=11444&view=diff ============================================================================== --- trunk/libzypp/zypp/media/MediaCurl.cc (original) +++ trunk/libzypp/zypp/media/MediaCurl.cc Wed Oct 22 14:19:23 2008 @@ -185,6 +185,31 @@ Pathname MediaCurl::_cookieFile = "/var/lib/YaST2/cookies"; +const char *const MediaCurl::anonymousIdHeader() +{ + // we need to add the release and identifier to the + // agent string. + // The target could be not initialized, and then this information + // is not available. + Target_Ptr target; + // FIXME this has to go away as soon as the target + // does not throw when not initialized. + try { + target = zypp::getZYpp()->target(); + } + catch ( const Exception &e ) + { + // nothing to do + } + + static const std::string _value( + str::form( + "X-ZYpp-AnonymousUniqueId: %s", + target ? target->anonymousUniqueId().c_str() : "" ) + ); + return _value.c_str(); +} + const char *const MediaCurl::agentString() { // we need to add the release and identifier to the @@ -207,11 +232,7 @@ "ZYpp %s (curl %s) %s" , VERSION , curl_version_info(CURLVERSION_NOW)->version - , target ? - str::form( " - %s on '%s'" - , target->anonymousUniqueId().c_str() - , target->targetDistribution().c_str() - ).c_str() : "" + , target ? target->targetDistribution().c_str() : "" ) ); return _value.c_str(); @@ -470,6 +491,18 @@ disconnectFrom(); ZYPP_THROW(MediaCurlSetOptException(_url, _curlError)); } + + // now add the anonymous id header + curl_slist *chunk = NULL; + chunk = curl_slist_append(chunk, anonymousIdHeader()); + ret = curl_easy_setopt ( _curl, CURLOPT_HTTPHEADER, chunk ); + curl_slist_free_all(chunk); + + if ( ret != 0) { + disconnectFrom(); + ZYPP_THROW(MediaCurlSetOptException(_url, _curlError)); + } + } Modified: trunk/libzypp/zypp/media/MediaCurl.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaCurl.h?rev=11444&r1=11443&r2=11444&view=diff ============================================================================== --- trunk/libzypp/zypp/media/MediaCurl.h (original) +++ trunk/libzypp/zypp/media/MediaCurl.h Wed Oct 22 14:19:23 2008 @@ -98,6 +98,9 @@ /** The user agent string */ static const char *const agentString(); + /** anonymous id header used to count unique users */ + static const char *const anonymousIdHeader(); + private: /** * Return a comma separated list of available authentication methods -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org