bnc#431571 : move unique id to private http header
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 22 Oct 2008 12:19:23 +0000 (12:19 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 22 Oct 2008 12:19:23 +0000 (12:19 +0000)
package/libzypp.changes
zypp/media/MediaAria2c.cc
zypp/media/MediaAria2c.h
zypp/media/MediaCurl.cc
zypp/media/MediaCurl.h

index 3cfbd87f56202cf1158f8a6c484c67b8c7df6385..436b524166781856b2c5ffb957317d615eaf607c 100644 (file)
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+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
 
index 6a38de3787bb8b2941b6ee90c5b1ceb1d4111c43..03ed75a44f9b2781d57ae6ba89b94f19e20a75ce 100644 (file)
@@ -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 @@ MediaAria2c::existsAria2cmd()
         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 @@ void MediaAria2c::attachTo (bool next)
    _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));
 
index e6a9a93a2488f180e206ac5ea49d7eeb50974b43..fcbc6292088580fc381e92f808e29000fee177de 100644 (file)
@@ -90,7 +90,8 @@ class MediaAria2c : public MediaHandler {
 
     /** The user agent string */
     static const char *const agentString();   
-    
+    /** anonymous id header used to count unique users */
+    static const char *const anonymousIdHeader();    
 
   private:
 
index 9b41b4a13852e61fc7d76ea7f043b10cfca52d56..85a6f565695c2a02a4f545acfd5f8b1db6a73586 100644 (file)
@@ -185,6 +185,31 @@ namespace zypp {
 
 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 @@ const char *const MediaCurl::agentString()
        "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 @@ void MediaCurl::attachTo (bool next)
       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));
+    }
+
   }
 
 
index ea40610e8a6f1ef7860e96525688b1996fe9624f..6a45a7081d93d70801aa79b56253558ac861ce3c 100644 (file)
@@ -98,6 +98,9 @@ class MediaCurl : public MediaHandler {
     /** 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