trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bc...@apache.org
Subject [1/3] git commit: TS-2113 first stab at porting it over to ATS, still more work to be done to the balancer plugin
Date Thu, 05 Sep 2013 00:25:58 GMT
Updated Branches:
  refs/heads/master 1b75d0f0f -> 5ba16cb66


TS-2113 first stab at porting it over to ATS, still more work to be done to the balancer plugin


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/6688e60d
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/6688e60d
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/6688e60d

Branch: refs/heads/master
Commit: 6688e60db8e40129b1668c39d9ead3f908fe3119
Parents: ebe3502
Author: Bryan Call <bcall@apache.org>
Authored: Wed Sep 4 17:19:45 2013 -0700
Committer: Bryan Call <bcall@apache.org>
Committed: Wed Sep 4 17:19:45 2013 -0700

----------------------------------------------------------------------
 plugins/experimental/balancer/balancer.cc | 46 ++++++++++++++------------
 plugins/experimental/balancer/hashkey.h   | 44 +++++++++++-------------
 plugins/experimental/balancer/resources.h | 36 ++++++++++++++------
 3 files changed, 69 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6688e60d/plugins/experimental/balancer/balancer.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/balancer/balancer.cc b/plugins/experimental/balancer/balancer.cc
index adc91ad..8b8a5a1 100644
--- a/plugins/experimental/balancer/balancer.cc
+++ b/plugins/experimental/balancer/balancer.cc
@@ -41,8 +41,8 @@
 
 #include <string>
 
-#include <ts/remap.h>
 #include <ts/ts.h>
+#include <ts/remap.h>
 
 #include "resources.h"
 #include "hashkey.h"
@@ -151,24 +151,25 @@ public:
         if (TSIsDebugTagSet("balancer")) {
           TSDebug("balancer", "Making %s hash ID's using %s", secondary ? "secondary" : "primary",
buf);
         }
-        ycrMD5_r(buf, key_len, id);
+        //MD5(buf, key_len, id);
       } else {
         if (secondary) {
           // Secondary ID defaults to IP (if none of the specified hashes computes)
           char buf[4];
 
-          *buf = resr.getRRI()->client_ip; // ToDo: this only works for IPv4
+          
+          //*buf = resr.getRRI()->client_ip; // ToDo: this only works for IPv4
 
           TSDebug("balancer", "Making secondary hash ID's using IP (default) = %s", buf);
-          ycrMD5_r(buf, key_len, id);
+          //MD5(buf, key_len, id);
         } else {
           // Primary ID defaults to URL (if none of the specified hashes computes)
-          char buf[resr.getRRI()->orig_url_size + 1];
+          char buf[resr._urlSize + 1];
 
-          memcpy(buf, resr.getRRI()->orig_url, resr.getRRI()->orig_url_size);
-          buf[resr.getRRI()->orig_url_size] = '\0';
+          memcpy(buf, resr._urlString, resr._urlSize);
+          buf[resr._urlSize] = '\0';
           TSDebug("balancer", "Making primary hash ID's using URL (default) = %s", buf);
-          ycrMD5_r(buf, key_len, id);
+          //MD5(buf, key_len, id);
         }
       }
     } else {
@@ -190,14 +191,14 @@ private:
 // Initialize the plugin.
 //
 int
-tsremap_init(TSREMAP_INTERFACE *api_info, char *errbuf, int errbuf_size)
+tsremap_init(TSRemapInterface *api_info, char *errbuf, int errbuf_size)
 {
   if (!api_info) {
     strncpy(errbuf, "[tsremap_init] - Invalid TSREMAP_INTERFACE argument", errbuf_size -
1);
     return -1;
   }
 
-  if (api_info->size < sizeof(TSREMAP_INTERFACE)) {
+  if (api_info->size < sizeof(TSRemapInterface)) {
     strncpy(errbuf, "[tsremap_init] - Incorrect size of TSREMAP_INTERFACE structure", errbuf_size
- 1);
     return -2;
   }
@@ -216,16 +217,19 @@ tsremap_init(TSREMAP_INTERFACE *api_info, char *errbuf, int errbuf_size)
 ///////////////////////////////////////////////////////////////////////////////
 // One instance per remap.config invocation.
 //
-int
-tsremap_new_instance(int argc, char *argv[], ihandle *ih, char *errbuf, int errbuf_size)
+TSReturnCode
+TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_size)
 {
+  (void) errbuf;
+  (void) errbuf_size;
+
   BalancerInstance* ri = new BalancerInstance;
 
-  *ih = static_cast<ihandle>(ri);
+  *ih = static_cast<void*>(ri);
 
   if (ri == NULL) {
     TSError("Unable to create remap instance");
-    return -5;
+    return TS_ERROR;
   }
 
   for (int ix=2; ix < argc; ++ix) {
@@ -310,13 +314,13 @@ tsremap_new_instance(int argc, char *argv[], ihandle *ih, char *errbuf,
int errb
     }
   }
 
-  return 0;
+  return TS_SUCCESS;
 }
 
 void
-tsremap_delete_instance(ihandle ih)
+tsremap_delete_instance(void** ih)
 {
-  BalancerInstance* ri = static_cast<BalancerInstance*>(ih);
+  BalancerInstance* ri = static_cast<BalancerInstance*>(*ih);
 
   delete ri;
 }
@@ -325,8 +329,8 @@ tsremap_delete_instance(ihandle ih)
 ///////////////////////////////////////////////////////////////////////////////
 // This is the main "entry" point for the plugin, called for every request.
 //
-int
-tsremap_remap(ihandle ih, rhandle rh, REMAP_REQUEST_INFO *rri)
+TSRemapStatus
+TSRemapDoRemap(void** ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
 {
   BalancerInstance* balancer;
   int error = 0;
@@ -338,9 +342,9 @@ tsremap_remap(ihandle ih, rhandle rh, REMAP_REQUEST_INFO *rri)
 
   if (NULL == ih) {
     TSDebug("balancer", "Falling back to default URL on remap without rules");
-    return 0;
+    return TSREMAP_NO_REMAP;
   }
-  balancer = static_cast<BalancerInstance*>(ih);
+  balancer = static_cast<BalancerInstance*>(*ih);
 
   // Get the rotation name to use.
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6688e60d/plugins/experimental/balancer/hashkey.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/balancer/hashkey.h b/plugins/experimental/balancer/hashkey.h
index 856c84f..9cec9fd 100644
--- a/plugins/experimental/balancer/hashkey.h
+++ b/plugins/experimental/balancer/hashkey.h
@@ -56,6 +56,9 @@ public:
   virtual int key(const void** data, Resources& resr) const = 0;
 
   virtual void free_key(const void* data, int len, Resources& resr) const {
+    (void) data;
+    (void) len;
+    (void) resr;
     // No-op by default
   }
 
@@ -86,8 +89,9 @@ class URLHashKey : public HashKey
  public:
   int
   key(const void** data, Resources& resr) const {
-    *data = resr.getRRI()->orig_url;
-    return resr.getRRI()->orig_url_size;
+    int size;
+    *data = resr.getUrl(&size);
+    return size;
   }
 };
 
@@ -100,8 +104,9 @@ class PathHashKey : public HashKey
  public:
   int
   key(const void** data, Resources& resr) const {
-    *data = resr.getRRI()->request_path;
-    return resr.getRRI()->request_path_size;
+    int size;
+    *data = TSUrlPathGet(resr._rri->requestBufp, resr._rri->requestUrl, &size);
+    return size;
   }
 };
 
@@ -152,9 +157,9 @@ class CookieHashKey : public HashKey
         const char* cookie;
 
         if (_sub) {
-          cookie = // TODO - get sub cookie
+          cookie = NULL; // TODO - get sub cookie
         } else {
-          cookie = // TODO - get full cookie
+          cookie = NULL; // TODO - get full cookie
         }
         if (cookie) {
           *data = cookie;
@@ -162,9 +167,9 @@ class CookieHashKey : public HashKey
         }
       }
     } else {
-      if (resr.getRRI()->request_cookie_size > 0) {
-        *data = resr.getRRI()->request_cookie;
-        return resr.getRRI()->request_cookie_size;
+      if (resr._cookie_size > 0) {
+        *data = resr._cookie;
+        return resr._cookie_size;
       }
     }
 
@@ -189,8 +194,10 @@ class IPHashKey : public HashKey
  public:
   int
   key(const void** data, Resources& resr) const {
-    *data = &(resr.getRRI()->client_ip);
-    return 4; // ToDo: This only works with IPV4, obviously
+    const struct sockaddr *addr = TSHttpTxnClientAddrGet(resr._txnp);
+    (void) addr;
+    *data = NULL; // TODO set the right pointer
+    return 4; // TODO set the right size
   }
 };
 
@@ -217,17 +224,12 @@ class HeaderHashKey : public HashKey
     TSMBuffer bufp = resr.getBufp();
     TSMLoc hdrLoc = resr.getHdrLoc();
     TSMLoc fieldLoc;
-    const char* val;
     int len = -1;
 
     // Note that hdrLoc is freed as part of the Resources dtor, and we free the "string"
value
     // in the free_key() implementation (after we're done with it).
     if (bufp && hdrLoc && (fieldLoc = TSMimeHdrFieldFind(bufp, hdrLoc, _header,
_header_len))) {
-      if (TS_ERROR != TSMimeHdrFieldValueStringGet(bufp, hdrLoc, fieldLoc, 0, &val, &len))
{
-        *data = val;
-      } else {
-        *data = NULL;
-      }
+      *data = TSMimeHdrFieldValueStringGet(bufp, hdrLoc, fieldLoc, 0, &len);
       TSHandleMLocRelease(bufp, hdrLoc, fieldLoc);
     } else {
       *data = NULL;
@@ -236,14 +238,6 @@ class HeaderHashKey : public HashKey
     return len;
   }
 
-  void free_key(const void* data, int len, Resources& resr) const {
-    TSMBuffer bufp = resr.getBufp();
-    TSMLoc hdrLoc = resr.getHdrLoc();
-
-    if (bufp && hdrLoc)
-      TSHandleStringRelease(bufp, hdrLoc, (const char*)data);
-  }
-
  private:
   const char* _header;
   int _header_len;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6688e60d/plugins/experimental/balancer/resources.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/balancer/resources.h b/plugins/experimental/balancer/resources.h
index 6188951..531278b 100644
--- a/plugins/experimental/balancer/resources.h
+++ b/plugins/experimental/balancer/resources.h
@@ -31,7 +31,7 @@
 
 #include <ts/remap.h>
 #include <ts/ts.h>
-
+#include <string.h>
 
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -41,7 +41,7 @@ class Resources
 {
 public:
   Resources(TSHttpTxn txnp, TSRemapRequestInfo *rri) :
-    _txnp(txnp), _rri(rri), _jar(NULL), _bufp(NULL), _hdrLoc(NULL)
+    _rri(rri), _txnp(txnp), _jar(NULL), _bufp(NULL), _hdrLoc(NULL), _urlString(NULL)
   { }
 
   ~Resources() {
@@ -54,24 +54,28 @@ public:
       TSDebug("balancer", "Destroying the cookie jar");
       // TODO - destroy cookies
     }
+
+    if (_urlString) {
+      TSfree(_urlString);
+    }
   }
 
   const TSHttpTxn getTxnp() const { return _txnp; }
     
   const TSRemapRequestInfo* getRRI() const { return _rri; }
 
-  const cookiejar_t
+  const char*
   getJar() {
     if (_jar)
       return _jar;
 
     // Setup the cookie jar for all processing
-    if (_rri->request_cookie_size > 0) {
-      char cookie_hdr[_rri->request_cookie_size + 1];
+    if (_cookie_size > 0) {
+      char cookie_hdr[_cookie_size + 1];
 
-      memcpy(cookie_hdr, _rri->request_cookie, _rri->request_cookie_size);
-      cookie_hdr[_rri->request_cookie_size] = '\0';
-      _jar = // TODO - create cookies
+      memcpy(cookie_hdr, _cookie, _cookie_size);
+      cookie_hdr[_cookie_size] = '\0';
+      _jar = NULL; // TODO - create cookies
       TSDebug("balancer", "Creating the cookie jar");
     }
 
@@ -99,12 +103,22 @@ public:
     return _hdrLoc;
   }
 
-private:
-  TSHttpTxn _txnp;
+  char* getUrl(int *size) {
+    _urlString = TSUrlStringGet(_rri->requestBufp, _rri->requestUrl, size);
+    _urlSize = *size;
+    return _urlString;
+  }
+
+public:
   TSRemapRequestInfo* _rri;
-  cookiejar_t _jar;
+  TSHttpTxn _txnp;
+  size_t _cookie_size;
+  char* _cookie;
+  char* _jar;
   TSMBuffer _bufp;
   TSMLoc _hdrLoc;
+  int _urlSize;
+  char* _urlString;
 };
 
 


Mime
View raw message