You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2010/11/17 01:28:49 UTC
svn commit: r1035878 - in /trafficserver/plugins/header_filter:
header_filter.cc rules.cc rules.h
Author: zwoop
Date: Wed Nov 17 00:28:49 2010
New Revision: 1035878
URL: http://svn.apache.org/viewvc?rev=1035878&view=rev
Log:
TS-521 Updates for the INk to TS migration
Modified:
trafficserver/plugins/header_filter/header_filter.cc
trafficserver/plugins/header_filter/rules.cc
trafficserver/plugins/header_filter/rules.h
Modified: trafficserver/plugins/header_filter/header_filter.cc
URL: http://svn.apache.org/viewvc/trafficserver/plugins/header_filter/header_filter.cc?rev=1035878&r1=1035877&r2=1035878&view=diff
==============================================================================
--- trafficserver/plugins/header_filter/header_filter.cc (original)
+++ trafficserver/plugins/header_filter/header_filter.cc Wed Nov 17 00:28:49 2010
@@ -37,51 +37,51 @@ Rules global;
// Continuation
//
static int
-cont_header_filter(INKCont contp, INKEvent event, void *edata)
+cont_header_filter(TSCont contp, TSEvent event, void *edata)
{
- INKHttpTxn txnp = (INKHttpTxn) edata;
- INKHttpHookID hook = INK_HTTP_LAST_HOOK;
- INKMBuffer reqp;
- INKMLoc hdr_loc;
+ TSHttpTxn txnp = (TSHttpTxn) edata;
+ TSHttpHookID hook = TS_HTTP_LAST_HOOK;
+ TSMBuffer reqp;
+ TSMLoc hdr_loc;
// Get the resources necessary to process this event
switch (event) {
- case INK_EVENT_HTTP_READ_REQUEST_HDR:
- if (INKHttpTxnClientReqGet(txnp, &reqp, &hdr_loc))
- hook = INK_HTTP_READ_REQUEST_HDR_HOOK;
+ case TS_EVENT_HTTP_READ_REQUEST_HDR:
+ if (TSHttpTxnClientReqGet(txnp, &reqp, &hdr_loc))
+ hook = TS_HTTP_READ_REQUEST_HDR_HOOK;
break;
- case INK_EVENT_HTTP_SEND_REQUEST_HDR:
- if (INKHttpTxnServerReqGet(txnp, &reqp, &hdr_loc))
- hook = INK_HTTP_SEND_REQUEST_HDR_HOOK;
+ case TS_EVENT_HTTP_SEND_REQUEST_HDR:
+ if (TSHttpTxnServerReqGet(txnp, &reqp, &hdr_loc))
+ hook = TS_HTTP_SEND_REQUEST_HDR_HOOK;
break;
- case INK_EVENT_HTTP_READ_RESPONSE_HDR:
- if (INKHttpTxnServerRespGet(txnp, &reqp, &hdr_loc))
- hook = INK_HTTP_READ_RESPONSE_HDR_HOOK;
+ case TS_EVENT_HTTP_READ_RESPONSE_HDR:
+ if (TSHttpTxnServerRespGet(txnp, &reqp, &hdr_loc))
+ hook = TS_HTTP_READ_RESPONSE_HDR_HOOK;
break;
- case INK_EVENT_HTTP_SEND_RESPONSE_HDR:
- if (INKHttpTxnClientRespGet(txnp, &reqp, &hdr_loc))
- hook = INK_HTTP_SEND_RESPONSE_HDR_HOOK;
+ case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
+ if (TSHttpTxnClientRespGet(txnp, &reqp, &hdr_loc))
+ hook = TS_HTTP_SEND_RESPONSE_HDR_HOOK;
break;
default:
- INKError("header_rewrite: unknown event for this plugin");
- INKDebug(PLUGIN_NAME, "unknown event for this plugin");
+ TSError("header_rewrite: unknown event for this plugin");
+ TSDebug(PLUGIN_NAME, "unknown event for this plugin");
break;
}
- if (hook != INK_HTTP_LAST_HOOK) {
+ if (hook != TS_HTTP_LAST_HOOK) {
Rules* from_remap;
global.execute(reqp, hdr_loc, hook);
- if (INK_HTTP_READ_REQUEST_HDR_HOOK != hook) { // Don't run the hook handled by remap plugin
- if (INK_SUCCESS == INKHttpTxnGetArg(txnp, 0, (void**)(&from_remap)) && from_remap)
+ if (TS_HTTP_READ_REQUEST_HDR_HOOK != hook) { // Don't run the hook handled by remap plugin
+ if (TS_SUCCESS == TSHttpTxnGetArg(txnp, 0, (void**)(&from_remap)) && from_remap)
from_remap->execute(reqp, hdr_loc, hook);
}
- INKHandleMLocRelease(reqp, INK_NULL_MLOC, hdr_loc);
+ TSHandleMLocRelease(reqp, TS_NULL_MLOC, hdr_loc);
}
- INKHttpTxnReenable(txnp, INK_EVENT_HTTP_CONTINUE);
+ TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
return 0;
}
@@ -90,33 +90,33 @@ cont_header_filter(INKCont contp, INKEve
// Initialize the InkAPI plugin for the global hooks we support.
//
void
-INKPluginInit(int argc, const char *argv[])
+TSPluginInit(int argc, const char *argv[])
{
- INKPluginRegistrationInfo info;
+ TSPluginRegistrationInfo info;
info.plugin_name = const_cast<char*>(PLUGIN_NAME);
info.vendor_name = const_cast<char*>("Apache");
info.support_email = const_cast<char*>("users@trafficserver.apache.org");
- if (!INKPluginRegister(INK_SDK_VERSION_2_0 , &info)) {
- INKError("header_rewrite: plugin registration failed.\n");
+ if (!TSPluginRegister(TS_SDK_VERSION_2_0 , &info)) {
+ TSError("header_rewrite: plugin registration failed.\n");
}
if (argc != 2) {
- INKError("usage: %s <config-file>\n", argv[0] );
+ TSError("usage: %s <config-file>\n", argv[0] );
}
// Parse the rules file
if (global.parse_file(argv[1])) {
- INKCont cont = INKContCreate(cont_header_filter, NULL);
+ TSCont cont = TSContCreate(cont_header_filter, NULL);
- for (int i=INK_HTTP_READ_REQUEST_HDR_HOOK; i < INK_HTTP_LAST_HOOK; ++i) {
- if (global.supported_hook(static_cast<INKHttpHookID>(i))) {
- INKHttpHookAdd(static_cast<INKHttpHookID>(i), cont);
+ for (int i=TS_HTTP_READ_REQUEST_HDR_HOOK; i < TS_HTTP_LAST_HOOK; ++i) {
+ if (global.supported_hook(static_cast<TSHttpHookID>(i))) {
+ TSHttpHookAdd(static_cast<TSHttpHookID>(i), cont);
}
}
} else {
- INKError("header_rewrite: failed to parse configuration file");
+ TSError("header_rewrite: failed to parse configuration file");
}
}
@@ -143,7 +143,7 @@ tsremap_init(TSRemapInterface* api_info,
return -3;
}
- INKDebug(PLUGIN_NAME, "remap plugin is succesfully initialized");
+ TSDebug(PLUGIN_NAME, "remap plugin is succesfully initialized");
return 0; /* success */
}
@@ -152,7 +152,7 @@ int
tsremap_new_instance(int argc, char* argv[], ihandle* ih, char* errbuf, int errbuf_size)
{
if (argc < 3) {
- INKError("Unable to create remap instance, need rules file");
+ TSError("Unable to create remap instance, need rules file");
return -1;
} else {
Rules* conf = new(Rules);
@@ -182,18 +182,18 @@ int
tsremap_remap(ihandle ih, rhandle rh, TSRemapRequestInfo *rri)
{
if (NULL == ih) {
- INKDebug(PLUGIN_NAME, "No Rules configured, falling back to default mapping rule");
+ TSDebug(PLUGIN_NAME, "No Rules configured, falling back to default mapping rule");
return 0;
} else {
Rules* confp = static_cast<Rules*>(ih);
- INKHttpTxn txnp = static_cast<INKHttpTxn>(rh);
- INKMBuffer reqp;
- INKMLoc hdr_loc;
-
- INKHttpTxnSetArg(txnp, 0, static_cast<void*>(ih)); // Save for later hooks
- if (INKHttpTxnClientReqGet(txnp, &reqp, &hdr_loc)) {
- confp->execute(reqp, hdr_loc, INK_HTTP_READ_REQUEST_HDR_HOOK);
- INKHandleMLocRelease(reqp, INK_NULL_MLOC, hdr_loc);
+ TSHttpTxn txnp = static_cast<TSHttpTxn>(rh);
+ TSMBuffer reqp;
+ TSMLoc hdr_loc;
+
+ TSHttpTxnSetArg(txnp, 0, static_cast<void*>(ih)); // Save for later hooks
+ if (TSHttpTxnClientReqGet(txnp, &reqp, &hdr_loc)) {
+ confp->execute(reqp, hdr_loc, TS_HTTP_READ_REQUEST_HDR_HOOK);
+ TSHandleMLocRelease(reqp, TS_NULL_MLOC, hdr_loc);
}
}
Modified: trafficserver/plugins/header_filter/rules.cc
URL: http://svn.apache.org/viewvc/trafficserver/plugins/header_filter/rules.cc?rev=1035878&r1=1035877&r2=1035878&view=diff
==============================================================================
--- trafficserver/plugins/header_filter/rules.cc (original)
+++ trafficserver/plugins/header_filter/rules.cc Wed Nov 17 00:28:49 2010
@@ -39,18 +39,18 @@ RulesEntry::append(RulesEntry* entry)
}
void
-RulesEntry::execute(INKMBuffer& reqp, INKMLoc& hdr_loc)
+RulesEntry::execute(TSMBuffer& reqp, TSMLoc& hdr_loc)
{
- INKMLoc field, tmp;
+ TSMLoc field, tmp;
RulesEntry* n = this;
while (n) {
- field = INKMimeHdrFieldFind(reqp, hdr_loc, n->_header, n->_len);
+ field = TSMimeHdrFieldFind(reqp, hdr_loc, n->_header, n->_len);
while (field) {
- INKDebug(PLUGIN_NAME, "\tDeleting header %.*s", n->_len, n->_header);
- tmp = INKMimeHdrFieldNextDup(reqp, hdr_loc, field);
- INKMimeHdrFieldDestroy(reqp, hdr_loc, field);
- INKHandleMLocRelease(reqp, hdr_loc, field);
+ TSDebug(PLUGIN_NAME, "\tDeleting header %.*s", n->_len, n->_header);
+ tmp = TSMimeHdrFieldNextDup(reqp, hdr_loc, field);
+ TSMimeHdrFieldDestroy(reqp, hdr_loc, field);
+ TSHandleMLocRelease(reqp, hdr_loc, field);
field = tmp;
}
n = n->_next;
@@ -61,20 +61,20 @@ RulesEntry::execute(INKMBuffer& reqp, IN
// Rules class implementations
Rules::~Rules()
{
- INKDebug(PLUGIN_NAME_DBG, "Calling DTOR for Rules");
+ TSDebug(PLUGIN_NAME_DBG, "Calling DTOR for Rules");
- for (int i = 0; i < INK_HTTP_LAST_HOOK; ++i) {
+ for (int i = 0; i < TS_HTTP_LAST_HOOK; ++i) {
if (_entries[i])
delete _entries[i];
}
}
RulesEntry*
-Rules::add_entry(const INKHttpHookID hook, const std::string& s)
+Rules::add_entry(const TSHttpHookID hook, const std::string& s)
{
RulesEntry* e = new(RulesEntry)(s);
- INKAssert(supported_hook(hook));
+ TSAssert(supported_hook(hook));
if (NULL == _entries[hook]) {
_entries[hook] = e;
} else {
@@ -88,16 +88,16 @@ bool
Rules::parse_file(const char* filename)
{
std::ifstream f;
- INKHttpHookID hook = INK_HTTP_READ_REQUEST_HDR_HOOK;
+ TSHttpHookID hook = TS_HTTP_READ_REQUEST_HDR_HOOK;
int lineno = 0;
// TODO: Should we support a 'default' prefix here for the ruless?
f.open(filename, std::ios::in);
if (!f.is_open()) {
- INKError("unable to open %s", filename);
+ TSError("unable to open %s", filename);
return false;
}
- INKDebug(PLUGIN_NAME, "Parsing config file %s", filename);
+ TSDebug(PLUGIN_NAME, "Parsing config file %s", filename);
while (!f.eof()) {
std::string line, word;
std::string::size_type pos1, pos2;
@@ -118,16 +118,16 @@ Rules::parse_file(const char* filename)
word = line.substr(pos1, pos2-pos1);
if (word == "READ_REQUEST_HDR:") {
- hook = INK_HTTP_READ_REQUEST_HDR_HOOK;
+ hook = TS_HTTP_READ_REQUEST_HDR_HOOK;
} else if (word == "SEND_REQUEST_HDR:") {
- hook = INK_HTTP_SEND_REQUEST_HDR_HOOK;
+ hook = TS_HTTP_SEND_REQUEST_HDR_HOOK;
} else if (word == "READ_RESPONSE_HDR:") {
- hook = INK_HTTP_READ_RESPONSE_HDR_HOOK;
+ hook = TS_HTTP_READ_RESPONSE_HDR_HOOK;
} else if (word == "SEND_RESPONSE_HDR:") {
- hook = INK_HTTP_SEND_RESPONSE_HDR_HOOK;
+ hook = TS_HTTP_SEND_RESPONSE_HDR_HOOK;
} else { // Assume it's a header name for everything else
if (!word.empty()) {
- INKDebug(PLUGIN_NAME, "Adding %s to hook %d", word.c_str(), hook);
+ TSDebug(PLUGIN_NAME, "Adding %s to hook %d", word.c_str(), hook);
add_entry(hook, word);
}
}
Modified: trafficserver/plugins/header_filter/rules.h
URL: http://svn.apache.org/viewvc/trafficserver/plugins/header_filter/rules.h?rev=1035878&r1=1035877&r2=1035878&view=diff
==============================================================================
--- trafficserver/plugins/header_filter/rules.h (original)
+++ trafficserver/plugins/header_filter/rules.h Wed Nov 17 00:28:49 2010
@@ -37,22 +37,22 @@ public:
RulesEntry(const std::string& s)
: _header(NULL), _len(0), _next(NULL)
{
- _header = INKstrdup(s.c_str());
+ _header = TSstrdup(s.c_str());
_len = s.length();
- INKDebug(PLUGIN_NAME_DBG, "Calling CTOR for RulesEntry, header is %s", _header);
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for RulesEntry, header is %s", _header);
}
~RulesEntry()
{
- INKDebug(PLUGIN_NAME_DBG, "Calling DTOR for RulesEntry");
+ TSDebug(PLUGIN_NAME_DBG, "Calling DTOR for RulesEntry");
if (_next)
delete _next; // Potentially "deep" recursion, but should be OK.
if (_header)
- INKfree(_header);
+ TSfree(_header);
}
void append(RulesEntry* entry);
- void execute(INKMBuffer& reqp, INKMLoc& hdr_loc); // This is really the meat of the app
+ void execute(TSMBuffer& reqp, TSMLoc& hdr_loc); // This is really the meat of the app
private:
DISALLOW_COPY_AND_ASSIGN(RulesEntry);
@@ -68,34 +68,34 @@ class Rules
public:
Rules()
{
- INKDebug(PLUGIN_NAME_DBG, "Calling CTOR for Rules");
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for Rules");
memset(_entries, 0, sizeof(_entries));
}
virtual ~Rules();
- RulesEntry* add_entry(const INKHttpHookID hook, const std::string& s);
+ RulesEntry* add_entry(const TSHttpHookID hook, const std::string& s);
bool parse_file(const char* filename);
- bool supported_hook(const INKHttpHookID hook)
+ bool supported_hook(const TSHttpHookID hook)
{
- return ((hook == INK_HTTP_READ_REQUEST_HDR_HOOK) ||
- (hook == INK_HTTP_SEND_REQUEST_HDR_HOOK) ||
- (hook == INK_HTTP_READ_RESPONSE_HDR_HOOK) ||
- (hook == INK_HTTP_SEND_RESPONSE_HDR_HOOK));
+ return ((hook == TS_HTTP_READ_REQUEST_HDR_HOOK) ||
+ (hook == TS_HTTP_SEND_REQUEST_HDR_HOOK) ||
+ (hook == TS_HTTP_READ_RESPONSE_HDR_HOOK) ||
+ (hook == TS_HTTP_SEND_RESPONSE_HDR_HOOK));
}
- void execute(INKMBuffer& reqp, INKMLoc& hdr_loc, const INKHttpHookID hook)
+ void execute(TSMBuffer& reqp, TSMLoc& hdr_loc, const TSHttpHookID hook)
{
- INKAssert(supported_hook(hook));
- INKDebug(PLUGIN_NAME, "Executing rules(s) for hook %d", hook);
+ TSAssert(supported_hook(hook));
+ TSDebug(PLUGIN_NAME, "Executing rules(s) for hook %d", hook);
_entries[hook]->execute(reqp, hdr_loc);
}
private:
DISALLOW_COPY_AND_ASSIGN(Rules);
- RulesEntry* _entries[INK_HTTP_LAST_HOOK]; // One possible set of entries for each hook
+ RulesEntry* _entries[TS_HTTP_LAST_HOOK]; // One possible set of entries for each hook
};
} // End of namespace ::HeaderFilter