You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ig...@apache.org on 2011/12/08 22:14:40 UTC
svn commit: r1212127 - in /trafficserver/plugins/trunk/balancer: Makefile
balancer.cc hashkey.h resources.h
Author: igalic
Date: Thu Dec 8 21:14:40 2011
New Revision: 1212127
URL: http://svn.apache.org/viewvc?rev=1212127&view=rev
Log:
Add a licensed Makefile
run a rudimentary s/INK/TS/g
n.b.: This still doesn't work.
I have no idea what a cookiejar_t is.
Added:
trafficserver/plugins/trunk/balancer/Makefile
Modified:
trafficserver/plugins/trunk/balancer/balancer.cc
trafficserver/plugins/trunk/balancer/hashkey.h
trafficserver/plugins/trunk/balancer/resources.h
Added: trafficserver/plugins/trunk/balancer/Makefile
URL: http://svn.apache.org/viewvc/trafficserver/plugins/trunk/balancer/Makefile?rev=1212127&view=auto
==============================================================================
--- trafficserver/plugins/trunk/balancer/Makefile (added)
+++ trafficserver/plugins/trunk/balancer/Makefile Thu Dec 8 21:14:40 2011
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+TSXS?=tsxs
+
+all: balancer.cc
+ $(TSXS) -v -C $? -o balancer.so
+
+install:
+ $(TSXS) -i -o balancer.so
+
+clean:
+ rm -f *.lo *.so
Modified: trafficserver/plugins/trunk/balancer/balancer.cc
URL: http://svn.apache.org/viewvc/trafficserver/plugins/trunk/balancer/balancer.cc?rev=1212127&r1=1212126&r2=1212127&view=diff
==============================================================================
--- trafficserver/plugins/trunk/balancer/balancer.cc (original)
+++ trafficserver/plugins/trunk/balancer/balancer.cc Thu Dec 8 21:14:40 2011
@@ -41,8 +41,8 @@
#include <string>
-#include <RemapAPI.h>
-#include <InkAPI.h>
+#include <ts/remap.h>
+#include <ts/ts.h>
#include "resources.h"
#include "hashkey.h"
@@ -79,7 +79,7 @@ public:
_first_hash = tmp;
}
if (_rotation)
- INKfree(_rotation);
+ TSfree(_rotation);
};
// Some simple setters and getters
@@ -89,10 +89,10 @@ public:
char* rotation() const { return _rotation; };
void set_rotation(const std::string& rot) {
if (rot.size() > 255) {
- INKError("Rotation name is too long");
+ TSError("Rotation name is too long");
return;
}
- _rotation = INKstrdup(rot.c_str());
+ _rotation = TSstrdup(rot.c_str());
}
int bucket_hosts() const { return _bucket_hosts; };
@@ -148,8 +148,8 @@ public:
hk = hk->next;
}
*p = '\0';
- if (INKIsDebugTagSet("balancer")) {
- INKDebug("balancer", "Making %s hash ID's using %s", secondary ? "secondary" : "primary", buf);
+ if (TSIsDebugTagSet("balancer")) {
+ TSDebug("balancer", "Making %s hash ID's using %s", secondary ? "secondary" : "primary", buf);
}
ycrMD5_r(buf, key_len, id);
} else {
@@ -159,7 +159,7 @@ public:
*buf = resr.getRRI()->client_ip; // ToDo: this only works for IPv4
- INKDebug("balancer", "Making secondary hash ID's using IP (default) = %s", buf);
+ TSDebug("balancer", "Making secondary hash ID's using IP (default) = %s", buf);
ycrMD5_r(buf, key_len, id);
} else {
// Primary ID defaults to URL (if none of the specified hashes computes)
@@ -167,7 +167,7 @@ public:
memcpy(buf, resr.getRRI()->orig_url, resr.getRRI()->orig_url_size);
buf[resr.getRRI()->orig_url_size] = '\0';
- INKDebug("balancer", "Making primary hash ID's using URL (default) = %s", buf);
+ TSDebug("balancer", "Making primary hash ID's using URL (default) = %s", buf);
ycrMD5_r(buf, key_len, id);
}
}
@@ -208,7 +208,7 @@ tsremap_init(TSREMAP_INTERFACE *api_info
return -3;
}
- INKDebug("balancer", "plugin is succesfully initialized");
+ TSDebug("balancer", "plugin is succesfully initialized");
return 0;
}
@@ -224,7 +224,7 @@ tsremap_new_instance(int argc, char *arg
*ih = static_cast<ihandle>(ri);
if (ri == NULL) {
- INKError("Unable to create remap instance");
+ TSError("Unable to create remap instance");
return -5;
}
@@ -238,7 +238,7 @@ tsremap_new_instance(int argc, char *arg
std::string::size_type sep = arg.find_first_of(":");
if (sep == std::string::npos) {
- INKError("Malformed options in balancer: %s", argv[ix]);
+ TSError("Malformed options in balancer: %s", argv[ix]);
} else {
std::string arg_val = arg.substr(sep + 1, std::string::npos);
@@ -253,7 +253,7 @@ tsremap_new_instance(int argc, char *arg
URLHashKey* hk = new URLHashKey();
if (NULL == hk) {
- INKError("Couldn't create balancer URL hash key");
+ TSError("Couldn't create balancer URL hash key");
} else {
ri->append_hash(hk, secondary);
}
@@ -261,7 +261,7 @@ tsremap_new_instance(int argc, char *arg
PathHashKey* hk = new PathHashKey();
if (NULL == hk) {
- INKError("Couldn't create balancer path hash key");
+ TSError("Couldn't create balancer path hash key");
} else {
ri->append_hash(hk, secondary);
}
@@ -269,7 +269,7 @@ tsremap_new_instance(int argc, char *arg
IPHashKey* hk = new IPHashKey();
if (NULL == hk) {
- INKError("Couldn't create balancer IP hash key");
+ TSError("Couldn't create balancer IP hash key");
} else {
ri->append_hash(hk, secondary);
}
@@ -278,7 +278,7 @@ tsremap_new_instance(int argc, char *arg
std::string::size_type sep2 = arg_val.find_first_of("/");
if (sep2 == std::string::npos) {
- INKError("Malformed hash options in balancer: %s", argv[ix]);
+ TSError("Malformed hash options in balancer: %s", argv[ix]);
} else {
std::string arg_val2 = arg_val.substr(sep2 + 1, std::string::npos);
@@ -286,7 +286,7 @@ tsremap_new_instance(int argc, char *arg
CookieHashKey* hk = new CookieHashKey(arg_val2);
if (NULL == hk) {
- INKError("Couldn't create balancer cookie hash key");
+ TSError("Couldn't create balancer cookie hash key");
} else {
ri->append_hash(hk, secondary);
}
@@ -294,17 +294,17 @@ tsremap_new_instance(int argc, char *arg
HeaderHashKey* hk = new HeaderHashKey(arg_val2);
if (NULL == hk) {
- INKError("Couldn't create balancer header hash key");
+ TSError("Couldn't create balancer header hash key");
} else {
ri->append_hash(hk, secondary);
}
} else {
- INKError("Unknown balancer hash option: %s", argv[ix]);
+ TSError("Unknown balancer hash option: %s", argv[ix]);
}
}
}
} else {
- INKError("Unknown balancer option: %s", argv[ix]);
+ TSError("Unknown balancer option: %s", argv[ix]);
}
}
}
@@ -337,7 +337,7 @@ tsremap_remap(ihandle ih, rhandle rh, RE
char *rot;
if (NULL == ih) {
- INKDebug("balancer", "Falling back to default URL on remap without rules");
+ TSDebug("balancer", "Falling back to default URL on remap without rules");
return 0;
}
balancer = static_cast<BalancerInstance*>(ih);
@@ -367,7 +367,7 @@ tsremap_remap(ihandle ih, rhandle rh, RE
if (balancer->has_primary_hash()) {
char id1[MD5_DIGEST_LENGTH+1];
- Resources resr((INKHttpTxn)rh, rri);
+ Resources resr((TSHttpTxn)rh, rri);
balancer_info.num_bucket_hosts = balancer->bucket_hosts();
@@ -382,33 +382,33 @@ tsremap_remap(ihandle ih, rhandle rh, RE
balancer_info.secondary_id = id2;
balancer_info.secondary_id_len = MD5_DIGEST_LENGTH;
- INKDebug("balancer", "Calling balancer_lookup(\"%s\") with primary and secondary hash", rot);
+ TSDebug("balancer", "Calling balancer_lookup(\"%s\") with primary and secondary hash", rot);
res = balancer_lookup(rot, &balancer_info);
} else {
- INKDebug("balancer", "Calling balancer_lookup(\"%s\") with primary hash", rot);
+ TSDebug("balancer", "Calling balancer_lookup(\"%s\") with primary hash", rot);
res = balancer_lookup(rot, &balancer_info);
}
} else {
- INKDebug("balancer", "Calling balancer_lookup(\"%s\") without hash", rot);
+ TSDebug("balancer", "Calling balancer_lookup(\"%s\") without hash", rot);
res = balancer_lookup(rot, &balancer_info);
}
// Check (and use) the balancer lookup results
if (!res) {
- INKDebug("balancer", "BALANCER has no data for %s, using To-URL (error is %d)", rot, balancer_error);
+ TSDebug("balancer", "BALANCER has no data for %s, using To-URL (error is %d)", rot, balancer_error);
return 0;
} else {
if ((balancer_port > 0) && (balancer_port != rri->remap_to_port)) {
rri->new_port = balancer_port;
- INKDebug("balancer", "Changing request to port %d", balancer_port);
+ TSDebug("balancer", "Changing request to port %d", balancer_port);
}
if (balancer->host_ip()) {
unsigned char *ip = (unsigned char*)res->h_addr;
rri->new_host_size = snprintf(rri->new_host, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
- INKDebug("balancer", "Setting real-host IP to %.*s (IP for %s)", rri->new_host_size, rri->new_host, res->h_name);
+ TSDebug("balancer", "Setting real-host IP to %.*s (IP for %s)", rri->new_host_size, rri->new_host, res->h_name);
} else {
- INKDebug("balancer", "Setting real-host to %s", res->h_name);
+ TSDebug("balancer", "Setting real-host to %s", res->h_name);
rri->new_host_size = strlen(res->h_name);
if (rri->new_host_size > TSREMAP_RRI_MAX_HOST_SIZE)
rri->new_host_size = TSREMAP_RRI_MAX_HOST_SIZE;
Modified: trafficserver/plugins/trunk/balancer/hashkey.h
URL: http://svn.apache.org/viewvc/trafficserver/plugins/trunk/balancer/hashkey.h?rev=1212127&r1=1212126&r2=1212127&view=diff
==============================================================================
--- trafficserver/plugins/trunk/balancer/hashkey.h (original)
+++ trafficserver/plugins/trunk/balancer/hashkey.h Thu Dec 8 21:14:40 2011
@@ -31,8 +31,8 @@
#include <string>
-#include <RemapAPI.h>
-#include <InkAPI.h>
+#include <ts/remap.h>
+#include <ts/ts.h>
#include "resources.h"
@@ -60,7 +60,7 @@ public:
}
void append(HashKey* hash) {
- INKReleaseAssert(hash->next == NULL);
+ TSReleaseAssert(hash->next == NULL);
if (NULL == next) {
next = hash;
@@ -120,18 +120,18 @@ class CookieHashKey : public HashKey
std::string tmp;
tmp = cookie.substr(0, dot);
- _main = INKstrdup(tmp.c_str());
+ _main = TSstrdup(tmp.c_str());
_main_len = dot;
tmp = cookie.substr(dot + 1);
if (tmp.size() > 0) {
- _sub = INKstrdup(tmp.c_str());
+ _sub = TSstrdup(tmp.c_str());
_sub_len = cookie.size() - dot - 1;
} else {
_sub = NULL;
_sub_len = 1;
}
} else {
- _main = INKstrdup(cookie.c_str());
+ _main = TSstrdup(cookie.c_str());
_main_len = cookie.size();
_sub = NULL;
_sub_len = 0;
@@ -140,9 +140,9 @@ class CookieHashKey : public HashKey
~CookieHashKey() {
if (_main)
- INKfree(const_cast<char*>(_main));
+ TSfree(const_cast<char*>(_main));
if (_sub)
- INKfree(const_cast<char*>(_sub));
+ TSfree(const_cast<char*>(_sub));
}
int
@@ -203,32 +203,32 @@ class HeaderHashKey : public HashKey
{
public:
HeaderHashKey(const std::string header) {
- _header = INKstrdup(header.c_str());
+ _header = TSstrdup(header.c_str());
_header_len = header.size();
}
~HeaderHashKey() {
if (_header)
- INKfree(const_cast<char*>(_header));
+ TSfree(const_cast<char*>(_header));
}
int
key(const void** data, Resources& resr) const {
- INKMBuffer bufp = resr.getBufp();
- INKMLoc hdrLoc = resr.getHdrLoc();
- INKMLoc fieldLoc;
+ 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 = INKMimeHdrFieldFind(bufp, hdrLoc, _header, _header_len))) {
- if (INK_ERROR != INKMimeHdrFieldValueStringGet(bufp, hdrLoc, fieldLoc, 0, &val, &len)) {
+ 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;
}
- INKHandleMLocRelease(bufp, hdrLoc, fieldLoc);
+ TSHandleMLocRelease(bufp, hdrLoc, fieldLoc);
} else {
*data = NULL;
}
@@ -237,11 +237,11 @@ class HeaderHashKey : public HashKey
}
void free_key(const void* data, int len, Resources& resr) const {
- INKMBuffer bufp = resr.getBufp();
- INKMLoc hdrLoc = resr.getHdrLoc();
+ TSMBuffer bufp = resr.getBufp();
+ TSMLoc hdrLoc = resr.getHdrLoc();
if (bufp && hdrLoc)
- INKHandleStringRelease(bufp, hdrLoc, (const char*)data);
+ TSHandleStringRelease(bufp, hdrLoc, (const char*)data);
}
private:
Modified: trafficserver/plugins/trunk/balancer/resources.h
URL: http://svn.apache.org/viewvc/trafficserver/plugins/trunk/balancer/resources.h?rev=1212127&r1=1212126&r2=1212127&view=diff
==============================================================================
--- trafficserver/plugins/trunk/balancer/resources.h (original)
+++ trafficserver/plugins/trunk/balancer/resources.h Thu Dec 8 21:14:40 2011
@@ -29,8 +29,8 @@
#define __RESOURCES_H__ 1
-#include <RemapAPI.h>
-#include <InkAPI.h>
+#include <ts/remap.h>
+#include <ts/ts.h>
@@ -40,23 +40,23 @@
class Resources
{
public:
- Resources(INKHttpTxn txnp, TSRemapRequestInfo *rri) :
+ Resources(TSHttpTxn txnp, TSRemapRequestInfo *rri) :
_txnp(txnp), _rri(rri), _jar(NULL), _bufp(NULL), _hdrLoc(NULL)
{ }
~Resources() {
if (_hdrLoc) {
- INKDebug("balancer", "Releasing the client request headers");
- INKHandleMLocRelease(_bufp, INK_NULL_MLOC, _hdrLoc);
+ TSDebug("balancer", "Releasing the client request headers");
+ TSHandleMLocRelease(_bufp, TS_NULL_MLOC, _hdrLoc);
}
if (_jar) {
- INKDebug("balancer", "Destroying the cookie jar");
+ TSDebug("balancer", "Destroying the cookie jar");
// TODO - destroy cookies
}
}
- const INKHttpTxn getTxnp() const { return _txnp; }
+ const TSHttpTxn getTxnp() const { return _txnp; }
const TSRemapRequestInfo* getRRI() const { return _rri; }
@@ -72,18 +72,18 @@ public:
memcpy(cookie_hdr, _rri->request_cookie, _rri->request_cookie_size);
cookie_hdr[_rri->request_cookie_size] = '\0';
_jar = // TODO - create cookies
- INKDebug("balancer", "Creating the cookie jar");
+ TSDebug("balancer", "Creating the cookie jar");
}
return _jar;
}
- const INKMBuffer
+ const TSMBuffer
getBufp() {
if (_bufp) {
return _bufp;
} else {
- if (!_txnp || !INKHttpTxnClientReqGet(_txnp, &_bufp, &_hdrLoc)) {
+ if (!_txnp || !TSHttpTxnClientReqGet(_txnp, &_bufp, &_hdrLoc)) {
_bufp = NULL;
_hdrLoc = NULL;
}
@@ -91,7 +91,7 @@ public:
}
}
- const INKMLoc
+ const TSMLoc
getHdrLoc() {
if (!_bufp || !_hdrLoc)
(void)getBufp();
@@ -100,11 +100,11 @@ public:
}
private:
- INKHttpTxn _txnp;
+ TSHttpTxn _txnp;
TSRemapRequestInfo* _rri;
cookiejar_t _jar;
- INKMBuffer _bufp;
- INKMLoc _hdrLoc;
+ TSMBuffer _bufp;
+ TSMLoc _hdrLoc;
};