You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by br...@apache.org on 2013/06/22 01:06:26 UTC
[2/3] TS-1968: Promote header_rewrite from experimental
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/experimental/header_rewrite/operators.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/header_rewrite/operators.h b/plugins/experimental/header_rewrite/operators.h
deleted file mode 100644
index f43858f..0000000
--- a/plugins/experimental/header_rewrite/operators.h
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- 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.
-*/
-//////////////////////////////////////////////////////////////////////////////////////////////
-//
-// Implement the classes for the various types of hash keys we support.
-//
-#ifndef __OPERATORS_H__
-#define __OPERATORS_H__ 1
-
-#include <string>
-#include <ts/ts.h>
-
-#include "operator.h"
-#include "resources.h"
-#include "value.h"
-
-
-///////////////////////////////////////////////////////////////////////////////
-// Operator declarations.
-//
-class OperatorRMHeader : public Operator
-{
-public:
- OperatorRMHeader()
- : _header("")
- {
- TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for OperatorRMHeader");
- }
- void initialize(Parser& p);
-
-protected:
- void exec(const Resources& res) const;
-
-private:
- DISALLOW_COPY_AND_ASSIGN(OperatorRMHeader);
-
- std::string _header;
-};
-
-
-class OperatorSetStatus : public Operator
-{
-public:
- OperatorSetStatus()
- : _reason(NULL), _reason_len(0)
- {
- TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for OperatorSetStatus");
- }
- void initialize(Parser& p);
-
-protected:
- void initialize_hooks();
- void exec(const Resources& res) const;
-
-private:
- DISALLOW_COPY_AND_ASSIGN(OperatorSetStatus);
-
- Value _status;
- const char* _reason;
- int _reason_len;
-};
-
-
-class OperatorSetStatusReason : public Operator
-{
-public:
- OperatorSetStatusReason()
- {
- TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for OperatorSetStatusReason");
- }
- void initialize(Parser& p);
-
-protected:
- void initialize_hooks();
- void exec(const Resources& res) const;
-
-private:
- DISALLOW_COPY_AND_ASSIGN(OperatorSetStatusReason);
-
- Value _reason;
-};
-
-
-class OperatorAddHeader : public Operator
-{
-public:
- OperatorAddHeader()
- : _header("")
- {
- TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for OperatorAddHeader");
- }
- void initialize(Parser& p);
-
-protected:
- void exec(const Resources& res) const;
-
-private:
- DISALLOW_COPY_AND_ASSIGN(OperatorAddHeader);
-
- std::string _header;
- Value _value;
-};
-
-
-class OperatorSetDestination : public Operator
-{
-public:
- OperatorSetDestination()
- : _url_qual(URL_QUAL_NONE)
- {
- TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for OperatorSetDestination");
- }
- void initialize(Parser& p);
-
-protected:
- void exec(const Resources& res) const;
-
-private:
- DISALLOW_COPY_AND_ASSIGN(OperatorSetDestination);
-
- UrlQualifiers _url_qual;
- Value _value;
-};
-
-
-class OperatorSetRedirect : public Operator
-{
-public:
- OperatorSetRedirect()
- {
- TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for OperatorSetRedirect");
- }
- void initialize(Parser& p);
-
-protected:
- void exec(const Resources& res) const;
-
-private:
- DISALLOW_COPY_AND_ASSIGN(OperatorSetRedirect);
-
- Value _status;
- Value _location;
-};
-
-
-class OperatorNoOp : public Operator
-{
-public:
- OperatorNoOp()
- {
- TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for OperatorNoOp");
- }
-
-protected:
- void exec(const Resources& /* res ATS_UNUSED */) const { };
-
-private:
- DISALLOW_COPY_AND_ASSIGN(OperatorNoOp);
-};
-
-
-class OperatorSetTimeoutOut : public Operator
-{
-public:
- OperatorSetTimeoutOut()
- : _type(TO_OUT_UNDEFINED)
- {
- TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for OperatorSetTimeoutOut");
- }
- void initialize(Parser& p);
-
-protected:
- void exec(const Resources& res) const;
-
-private:
- DISALLOW_COPY_AND_ASSIGN(OperatorSetTimeoutOut);
-
- enum TimeoutOutType {
- TO_OUT_UNDEFINED,
- TO_OUT_ACTIVE,
- TO_OUT_INACTIVE,
- TO_OUT_CONNECT,
- TO_OUT_DNS
- };
-
- TimeoutOutType _type;
- Value _timeout;
-};
-
-
-#endif // __OPERATORS_H
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/experimental/header_rewrite/parser.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/header_rewrite/parser.cc b/plugins/experimental/header_rewrite/parser.cc
deleted file mode 100644
index f354422..0000000
--- a/plugins/experimental/header_rewrite/parser.cc
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- 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.
-*/
-//////////////////////////////////////////////////////////////////////////////////////////////
-// parser.cc: implementation of the config parser
-//
-//
-#include <utility>
-#include <boost/tokenizer.hpp>
-
-#include <ts/ts.h>
-
-#include "parser.h"
-
-// Tokenizer separators
-static boost::escaped_list_separator<char> token_sep('\\', ' ', '\"');
-static boost::char_separator<char> comma_sep(",");
-
-
-// This is the core "parser", parsing rule sets
-void
-Parser::preprocess(std::vector<std::string>& tokens)
-{
- // Special case for "conditional" values
- if (tokens[0].substr(0, 2) == "%{") {
- _cond = true;
- } else if (tokens[0] == "cond") {
- _cond = true;
- tokens.erase(tokens.begin());
- }
-
- // Is it a condition or operator?
- if (_cond) {
- if ((tokens[0].substr(0, 2) == "%{") && (tokens[0][tokens[0].size() - 1] == '}')) {
- std::string s = tokens[0].substr(2, tokens[0].size() - 3);
-
- _op = s;
- if (tokens.size() > 1)
- _arg = tokens[1];
- else
- _arg = "";
- } else {
- TSError("header_rewrite: conditions must be embraced in %%{}");
- return;
- }
- } else {
- // Operator has no qualifiers, but could take an optional second argumetn
- _op = tokens[0];
- if (tokens.size() > 1) {
- _arg = tokens[1];
- if (tokens.size() > 2)
- _val = tokens[2];
- else
- _val = "";
- } else {
- _arg = "";
- _val = "";
- }
- }
-
- // The last token might be the "flags" section
- if (tokens.size() > 0) {
- std::string m = tokens[tokens.size() - 1];
-
- if (!m.empty() && (m[0] == '[')) {
- if (m[m.size() - 1] == ']') {
- m = m.substr(1, m.size() - 2);
- if (m.find_first_of(',') != std::string::npos) {
- boost::tokenizer<boost::char_separator<char> > mods(m, comma_sep);
- std::copy(mods.begin(), mods.end(), std::back_inserter(_mods));
- } else {
- _mods.push_back(m);
- }
- } else {
- // Syntax error
- TSError("header_rewrite: mods have to be embraced in []");
- return;
- }
- }
- }
-}
-
-
-Parser::Parser(const std::string& line) :
- _cond(false), _empty(false)
-{
- TSDebug("header_rewrite_dbg", "Calling CTOR for Parser");
-
- if (line[0] == '#') {
- _empty = true;
- } else {
- boost::tokenizer<boost::escaped_list_separator<char> > elem(line, token_sep);
- std::vector<std::string> tokens;
-
- for (boost::tokenizer<boost::escaped_list_separator<char> >::iterator it = elem.begin(); it != elem.end(); it++) {
- // Skip "empty" tokens (tokenizer is a little brain dead IMO)
- if ((*it) != "")
- tokens.push_back(*it);
- }
-
- if (tokens.empty()) {
- _empty = true;
- } else {
- preprocess(tokens);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/experimental/header_rewrite/parser.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/header_rewrite/parser.h b/plugins/experimental/header_rewrite/parser.h
deleted file mode 100644
index 0417fff..0000000
--- a/plugins/experimental/header_rewrite/parser.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- 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.
-*/
-//////////////////////////////////////////////////////////////////////////////////////////////
-//
-// Interface for the config line parser
-//
-#ifndef __PARSER_H__
-#define __PARSER_H__ 1
-
-#include <string>
-#include <vector>
-#include <algorithm>
-
-#include "lulu.h"
-
-
-///////////////////////////////////////////////////////////////////////////////
-//
-class Parser
-{
-public:
- explicit Parser(const std::string& line);
-
- bool empty() const { return _empty; }
- bool is_cond() const { return _cond; }
-
- bool cond_op_is(const std::string s) const { return _cond && (_op == s); }
- bool oper_op_is(const std::string s) const { return !_cond && (_op == s); }
-
- const std::string& get_op() const { return _op; }
- std::string& get_arg() { return _arg; }
- const std::string& get_value() const { return _val; }
-
- bool mod_exist(const std::string m) const {
- return (std::find(_mods.begin(), _mods.end(), m) != _mods.end());
- }
-
-private:
- void preprocess(std::vector<std::string>& tokens);
- DISALLOW_COPY_AND_ASSIGN(Parser);
-
- bool _cond;
- bool _empty;
- std::vector<std::string> _mods;
- std::string _op;
- std::string _arg;
- std::string _val;
-};
-
-
-#endif // __PARSER_H
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/experimental/header_rewrite/regex_helper.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/header_rewrite/regex_helper.cc b/plugins/experimental/header_rewrite/regex_helper.cc
deleted file mode 100644
index 4bfdb23..0000000
--- a/plugins/experimental/header_rewrite/regex_helper.cc
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- 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.
-*/
-#include "regex_helper.h"
-
-bool
-regexHelper::setRegexMatch(const std::string& s)
-{
-
- const char* errorComp = NULL;
- const char* errorStudy = NULL;
- int erroffset;
-
- regexString = s;
- regex = pcre_compile(regexString.c_str(), 0, &errorComp, &erroffset, NULL);
-
- if (regex == NULL)
- {
- return false;
- }
- regexExtra = pcre_study(regex, 0, &errorStudy);
- if ((regexExtra == NULL) && (errorStudy != 0))
- {
- return false;
- }
- if (pcre_fullinfo(regex, regexExtra, PCRE_INFO_CAPTURECOUNT, ®exCcount) != 0)
- return false;
- return true;
- }
-
-const std::string&
-regexHelper::getRegexString() const
-{
- return regexString;
-}
-
-int
-regexHelper::getRegexCcount() const
-{
- return regexCcount;
-}
-
-int
-regexHelper::regexMatch(const char* str, int len, int ovector[]) const {
- return pcre_exec(regex, // the compiled pattern
- regexExtra, // Extra data from study (maybe)
- str, // the subject std::string
- len, // the length of the subject
- 0, // start at offset 0 in the subject
- 0, // default options
- ovector, // output vector for substring information
- OVECCOUNT); // number of elements in the output vector
- };
-
-
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/experimental/header_rewrite/regex_helper.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/header_rewrite/regex_helper.h b/plugins/experimental/header_rewrite/regex_helper.h
deleted file mode 100644
index 5d5099a..0000000
--- a/plugins/experimental/header_rewrite/regex_helper.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- 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.
-*/
-#ifndef REGEX_HELPER_H
-#define REGEX_HELPER_H
-
-#include <pcre.h>
-
-#include <string>
-
-
-const int OVECCOUNT = 30; // We support $1 - $9 only, and this needs to be 3x that
-
-class regexHelper{
-public:
- regexHelper():
- regex(NULL),regexExtra(NULL),regexCcount(0)
- {
-
- }
-
- ~regexHelper()
- {
- if (regex)
- pcre_free(regex);
-
- if (regexExtra)
- pcre_free(regexExtra);
- }
-
-
-
-bool setRegexMatch(const std::string &s);
-const std::string& getRegexString() const;
-int getRegexCcount() const;
-int regexMatch(const char*,int,int ovector[]) const;
-
-private:
- pcre* regex;
- pcre_extra* regexExtra;
- std::string regexString;
- int regexCcount;
-
-};
-
-
-#endif
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/experimental/header_rewrite/resources.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/header_rewrite/resources.cc b/plugins/experimental/header_rewrite/resources.cc
deleted file mode 100644
index c33dfbf..0000000
--- a/plugins/experimental/header_rewrite/resources.cc
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- 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.
-*/
-//////////////////////////////////////////////////////////////////////////////////////////////
-// resources.cc: Implementation of the resources class.
-//
-//
-#include <ts/ts.h>
-
-#include "resources.h"
-#include "lulu.h"
-
-void
-Resources::gather(const ResourceIDs ids, TSHttpHookID hook)
-{
- TSDebug(PLUGIN_NAME, "Building resource structure for hook (%d)", hook);
-
- // If we need the client request headers, make sure it's also available in the client vars.
- if (ids & RSRC_CLIENT_REQUEST_HEADERS) {
- TSDebug(PLUGIN_NAME, "\tAdding TXN client request header buffers");
- if (TSHttpTxnClientReqGet(txnp, &client_bufp, &client_hdr_loc) != TS_SUCCESS) {
- TSDebug(PLUGIN_NAME, "could not gather bufp/hdr_loc for request");
- return;
- }
- }
-
- switch (hook) {
- case TS_HTTP_READ_RESPONSE_HDR_HOOK:
- // Read response headers from server
- if (ids & RSRC_SERVER_RESPONSE_HEADERS) {
- TSDebug(PLUGIN_NAME, "\tAdding TXN server response header buffers");
- if (TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
- TSDebug(PLUGIN_NAME, "could not gather bufp/hdr_loc for response");
- return;
- }
- }
- if (ids & RSRC_RESPONSE_STATUS) {
- TSDebug(PLUGIN_NAME, "\tAdding TXN server response status resource");
- resp_status = TSHttpHdrStatusGet(bufp, hdr_loc);
- }
- break;
-
- case TS_HTTP_SEND_REQUEST_HDR_HOOK:
- // Read request headers to server
- if (ids & RSRC_SERVER_REQUEST_HEADERS) {
- TSDebug(PLUGIN_NAME, "\tAdding TXN server request header buffers");
- if (!TSHttpTxnServerReqGet(txnp, &bufp, &hdr_loc)) {
- TSDebug(PLUGIN_NAME, "could not gather bufp/hdr_loc for request");
- return;
- }
- }
- break;
-
- case TS_HTTP_READ_REQUEST_HDR_HOOK:
- case TS_HTTP_READ_REQUEST_PRE_REMAP_HOOK:
- // Read request from client
- if (ids & RSRC_CLIENT_REQUEST_HEADERS) {
- bufp = client_bufp;
- hdr_loc = client_hdr_loc;
- }
- break;
-
- case TS_HTTP_SEND_RESPONSE_HDR_HOOK:
- // Send response headers to client
- if (ids & RSRC_CLIENT_RESPONSE_HEADERS) {
- TSDebug(PLUGIN_NAME, "\tAdding TXN client response header buffers");
- if (TSHttpTxnClientRespGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
- TSDebug(PLUGIN_NAME, "could not gather bufp/hdr_loc for request");
- return;
- }
- if (ids & RSRC_RESPONSE_STATUS) {
- TSDebug(PLUGIN_NAME, "\tAdding TXN client esponse status resource");
- resp_status = TSHttpHdrStatusGet(bufp, hdr_loc);
- }
- }
- break;
-
- case TS_REMAP_PSEUDO_HOOK:
- // Pseudo-hook for a remap instance
- if (client_bufp && client_hdr_loc) {
- TSDebug(PLUGIN_NAME, "\tAdding TXN client request header buffers for remap instance");
- bufp = client_bufp;
- hdr_loc = client_hdr_loc;
- }
- break;
-
-
- default:
- break;
- }
-
- _ready = true;
-}
-
-void
-Resources::destroy()
-{
- if (bufp) {
- if (hdr_loc)
- TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
- }
-
- if (client_bufp && (client_bufp != bufp)) {
- if (client_hdr_loc && (client_hdr_loc != hdr_loc)) // TODO: Is this check really necessary?
- TSHandleMLocRelease(client_bufp, TS_NULL_MLOC, client_hdr_loc);
- }
-
- _ready = false;
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/experimental/header_rewrite/resources.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/header_rewrite/resources.h b/plugins/experimental/header_rewrite/resources.h
deleted file mode 100644
index d2ce9f5..0000000
--- a/plugins/experimental/header_rewrite/resources.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- 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.
-*/
-//////////////////////////////////////////////////////////////////////////////////////////////
-//
-// Implement the classes for the various types of hash keys we support.
-//
-#ifndef __RESOURCES_H__
-#define __RESOURCES_H__ 1
-
-#include <string>
-#include <ts/ts.h>
-#include <ts/remap.h>
-
-#include "lulu.h"
-
-
-#define TS_REMAP_PSEUDO_HOOK TS_HTTP_LAST_HOOK // Ugly, but use the "last hook" for remap instances.
-
-enum ResourceIDs {
- RSRC_NONE = 0,
- RSRC_SERVER_RESPONSE_HEADERS = 1,
- RSRC_SERVER_REQUEST_HEADERS = 2,
- RSRC_CLIENT_REQUEST_HEADERS = 4,
- RSRC_CLIENT_RESPONSE_HEADERS = 8,
- RSRC_RESPONSE_STATUS = 16,
-};
-
-
-///////////////////////////////////////////////////////////////////////////////
-// Resources holds the minimum resources required to process a request.
-//
-class Resources
-{
-public:
- explicit Resources(TSHttpTxn txnptr, TSCont contptr)
- : txnp(txnptr), contp(contptr), bufp(NULL), hdr_loc(NULL), client_bufp(NULL), client_hdr_loc(NULL),
- resp_status(TS_HTTP_STATUS_NONE), _rri(NULL), changed_url(false), _ready(false)
- {
- TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for Resources (InkAPI)");
- }
-
- Resources(TSHttpTxn txnptr, TSRemapRequestInfo *rri) :
- txnp(txnptr), contp(NULL),
- bufp(NULL), hdr_loc(NULL), client_bufp(NULL), client_hdr_loc(NULL), resp_status(TS_HTTP_STATUS_NONE),
- _rri(rri), _ready(false)
- {
- TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for Resources (RemapAPI)");
- TSDebug(PLUGIN_NAME, "rri: %p", _rri);
- }
-
- ~Resources() { destroy(); }
-
- void gather(const ResourceIDs ids, TSHttpHookID hook);
- bool ready() const { return _ready; }
-
- TSHttpTxn txnp;
- TSCont contp;
- TSMBuffer bufp;
- TSMLoc hdr_loc;
- TSMBuffer client_bufp;
- TSMLoc client_hdr_loc;
- TSHttpStatus resp_status;
- TSRemapRequestInfo *_rri;
- bool changed_url;
-
-private:
- void destroy();
- DISALLOW_COPY_AND_ASSIGN(Resources);
-
- bool _ready;
-};
-
-
-#endif // __RESOURCES_H
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/experimental/header_rewrite/ruleset.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/header_rewrite/ruleset.cc b/plugins/experimental/header_rewrite/ruleset.cc
deleted file mode 100644
index 9b2d688..0000000
--- a/plugins/experimental/header_rewrite/ruleset.cc
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- 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.
-*/
-//////////////////////////////////////////////////////////////////////////////////////////////
-// ruleset.cc: implementation of the ruleset class
-//
-//
-#include <string>
-
-#include "ruleset.h"
-#include "factory.h"
-
-
-///////////////////////////////////////////////////////////////////////////////
-// Class implementation (no reason to have these inline)
-//
-void
-RuleSet::append(RuleSet* rule) {
- RuleSet* tmp = this;
-
- TSReleaseAssert(rule->next == NULL);
-
- while (tmp->next)
- tmp = tmp->next;
- tmp->next = rule;
-}
-
-
-void
-RuleSet::add_condition(Parser& p) {
- Condition* c = condition_factory(p.get_op());
-
- if (NULL != c) {
- TSDebug(PLUGIN_NAME, "Adding condition: %%{%s} with arg: %s\n", p.get_op().c_str(), p.get_arg().c_str());
- c->initialize(p);
- if (!c->set_hook(_hook)) {
- TSError("header_rewrite: can't use this condition in this hook");
- return;
- }
- if (NULL == _cond) {
- _cond = c;
- } else {
- _cond->append(c);
- }
-
- // Update some ruleset state based on this new condition
- _last |= c->last();
- _ids = static_cast<ResourceIDs>(_ids | _cond->get_resource_ids());
- }
-}
-
-
-void
-RuleSet::add_operator(Parser& p) {
- Operator* o = operator_factory(p.get_op());
-
- if (NULL != o) {
- // TODO: This should be extended to show both the "argument" and the "value" (if both are used)
- TSDebug(PLUGIN_NAME, "Adding operator: %s(%s)\n", p.get_op().c_str(), p.get_arg().c_str());
- o->initialize(p);
- if (!o->set_hook(_hook)) {
- TSError("header_rewrite: can't use this operator in this hook");
- return;
- }
- if (NULL == _oper) {
- _oper = o;
- } else {
- _oper->append(o);
- }
-
- // Update some ruleset state based on this new operator
- _opermods = static_cast<OperModifiers>(_opermods | _oper->get_oper_modifiers());
- _ids = static_cast<ResourceIDs>(_ids | _oper->get_resource_ids());
- }
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/experimental/header_rewrite/ruleset.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/header_rewrite/ruleset.h b/plugins/experimental/header_rewrite/ruleset.h
deleted file mode 100644
index b530b7f..0000000
--- a/plugins/experimental/header_rewrite/ruleset.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- 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.
-*/
-//////////////////////////////////////////////////////////////////////////////////////////////
-//
-// Implement the classes for the various types of hash keys we support.
-//
-#ifndef __RULESET_H__
-#define __RULESET_H__ 1
-
-#include <string>
-
-#include "matcher.h"
-#include "factory.h"
-#include "resources.h"
-#include "parser.h"
-
-
-///////////////////////////////////////////////////////////////////////////////
-// Class holding one ruleset. A ruleset is one (or more) pre-conditions, and
-// one (or more) operators.
-//
-class RuleSet
-{
-public:
- RuleSet()
- : next(NULL), _cond(NULL), _oper(NULL), _hook(TS_HTTP_READ_RESPONSE_HDR_HOOK), _ids(RSRC_NONE),
- _opermods(OPER_NONE), _last(false)
- { };
-
- // No reason to inline these
- void append(RuleSet* rule);
-
- void add_condition(Parser& p);
- void add_operator(Parser& p);
- bool has_operator() const { return NULL != _oper; }
- bool has_condition() const { return NULL != _cond; }
-
- void set_hook(TSHttpHookID hook) { _hook = hook; }
- const TSHttpHookID get_hook() const { return _hook; }
-
- // Inline
- const ResourceIDs get_all_resource_ids() const {
- return _ids;
- }
-
- bool eval(const Resources& res) const {
- if (NULL == _cond) {
- return true;
- } else {
- return _cond->do_eval(res);
- }
- }
-
- bool last() const {
- return _last;
- }
-
- OperModifiers exec(const Resources& res) const {
- _oper->do_exec(res);
- return _opermods;
- }
-
- RuleSet* next; // Linked list
-
-private:
- DISALLOW_COPY_AND_ASSIGN(RuleSet);
-
- Condition* _cond; // First pre-condition (linked list)
- Operator* _oper; // First operator (linked list)
- TSHttpHookID _hook; // Which hook is this rule for
-
- // State values (updated when conds / operators are added)
- ResourceIDs _ids;
- OperModifiers _opermods;
- bool _last;
-};
-
-
-#endif // __RULESET_H
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/experimental/header_rewrite/statement.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/header_rewrite/statement.cc b/plugins/experimental/header_rewrite/statement.cc
deleted file mode 100644
index a9053ff..0000000
--- a/plugins/experimental/header_rewrite/statement.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- 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.
-*/
-//////////////////////////////////////////////////////////////////////////////////////////////
-// statement.cc: Implementation of the statement base class.
-//
-//
-
-#include <ts/ts.h>
-
-#include "statement.h"
-
-void
-Statement::append(Statement* stmt)
-{
- Statement* tmp = this;
-
- TSReleaseAssert(stmt->_next == NULL);
- while (tmp->_next)
- tmp = tmp->_next;
- tmp->_next = stmt;
-}
-
-
-const ResourceIDs
-Statement::get_resource_ids() const
-{
- const Statement* stmt = this;
- ResourceIDs ids = RSRC_NONE;
-
- while (stmt) {
- ids = static_cast<ResourceIDs>(ids | stmt->_rsrc);
- stmt = stmt->_next;
- }
-
- return ids;
-}
-
-
-bool
-Statement::set_hook(TSHttpHookID hook) {
- bool ret = std::find(_allowed_hooks.begin(), _allowed_hooks.end(), hook) != _allowed_hooks.end();
-
- if (ret)
- _hook = hook;
-
- return ret;
-}
-
-
-// This should be overridden for any Statement which only supports some hooks
-void
-Statement::initialize_hooks() {
- add_allowed_hook(TS_HTTP_READ_RESPONSE_HDR_HOOK);
- add_allowed_hook(TS_HTTP_READ_REQUEST_PRE_REMAP_HOOK);
- add_allowed_hook(TS_HTTP_READ_REQUEST_HDR_HOOK);
- add_allowed_hook(TS_HTTP_SEND_REQUEST_HDR_HOOK);
- add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK);
- add_allowed_hook(TS_REMAP_PSEUDO_HOOK);
-}
-
-
-// Parse URL qualifiers
-UrlQualifiers
-Statement::parse_url_qualifier(const std::string& q) {
- UrlQualifiers qual = URL_QUAL_NONE;
-
- if (q == "HOST")
- qual = URL_QUAL_HOST;
- else if (q == "PORT")
- qual = URL_QUAL_PORT;
- else if (q == "PATH")
- qual = URL_QUAL_PATH;
- else if (q == "QUERY")
- qual = URL_QUAL_QUERY;
- else if (q == "MATRIX")
- qual = URL_QUAL_MATRIX;
- else if (q == "SCHEME")
- qual = URL_QUAL_SCHEME;
- else if (q == "URL")
- qual = URL_QUAL_URL;
-
- return qual;
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/experimental/header_rewrite/statement.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/header_rewrite/statement.h b/plugins/experimental/header_rewrite/statement.h
deleted file mode 100644
index 15fdf11..0000000
--- a/plugins/experimental/header_rewrite/statement.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- 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.
-*/
-//////////////////////////////////////////////////////////////////////////////////////////////
-//
-// Base class for all Conditions and Operations. We share the "linked" list, and the
-// resource management / requirements.
-//
-#ifndef __STATEMENT_H__
-#define __STATEMENT_H__ 1
-
-#include <string>
-#include <vector>
-#include <ts/ts.h>
-
-#include "resources.h"
-#include "parser.h"
-#include "lulu.h"
-
-
-// URL data (both client and server)
-enum UrlQualifiers {
- URL_QUAL_NONE,
- URL_QUAL_HOST,
- URL_QUAL_PORT,
- URL_QUAL_PATH,
- URL_QUAL_QUERY,
- URL_QUAL_MATRIX,
- URL_QUAL_SCHEME,
- URL_QUAL_URL
-};
-
-
-class Statement
-{
- public:
- Statement()
- : _next(NULL), _pdata(NULL), _rsrc(RSRC_NONE), _initialized(false), _hook(TS_HTTP_READ_RESPONSE_HDR_HOOK)
- {
- TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for Statement");
- }
-
- virtual ~Statement() {
- TSDebug(PLUGIN_NAME_DBG, "Calling DTOR for Statement");
- free_pdata();
- }
-
- // Private data
- void set_pdata(void* pdata) { _pdata = pdata; }
- void* get_pdata() const { return(_pdata); }
- virtual void free_pdata() { TSfree(_pdata); _pdata = NULL; }
-
- // Which hook are we adding this statement to?
- bool set_hook(TSHttpHookID hook);
- const TSHttpHookID get_hook() const { return _hook; }
-
- // Which hooks are this "statement" applicable for? Used during parsing only.
- void add_allowed_hook(const TSHttpHookID hook) { _allowed_hooks.push_back(hook); }
-
- // Linked list.
- void append(Statement* stmt);
-
- const ResourceIDs get_resource_ids() const;
-
- virtual void initialize(Parser&) { // Parser &p
- TSReleaseAssert(_initialized == false);
- initialize_hooks();
- _initialized = true;
- }
- bool initialized() const { return _initialized; }
-
- protected:
- virtual void initialize_hooks();
-
- UrlQualifiers parse_url_qualifier(const std::string& q);
- void require_resources(const ResourceIDs ids) { _rsrc = static_cast<ResourceIDs>(_rsrc | ids); }
-
- Statement* _next; // Linked list
-
-private:
- DISALLOW_COPY_AND_ASSIGN(Statement);
-
- void* _pdata;
- ResourceIDs _rsrc;
- bool _initialized;
- std::vector<TSHttpHookID> _allowed_hooks;
- TSHttpHookID _hook;
-};
-
-
-#endif // __STATEMENT_H
-
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/experimental/header_rewrite/value.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/header_rewrite/value.h b/plugins/experimental/header_rewrite/value.h
deleted file mode 100644
index 0c318fc..0000000
--- a/plugins/experimental/header_rewrite/value.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- 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.
-*/
-//////////////////////////////////////////////////////////////////////////////////////////////
-// Public interface for creating all values.
-//
-//
-#ifndef __VALUE_H__
-#define __VALUE_H__ 1
-
-#include <string>
-#include <ts/ts.h>
-
-#include "resources.h"
-#include "statement.h"
-#include "condition.h"
-#include "factory.h"
-#include "parser.h"
-
-
-///////////////////////////////////////////////////////////////////////////////
-// Base class for all Values (this is also the interface).
-//
-// TODO: This is very incomplete, we need to support linked lists of these,
-// which evaluate each component and create a "joined" final string.
-//
-class Value : Statement
-{
-public:
- Value()
- : _value(""), _int_value(-1), _cond_val(NULL)
- {
- TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for Value");
- };
-
- void
- set_value(const std::string& val)
- {
- _value = val;
- if (_value.substr(0,2) == "%{") {
- Parser parser(_value);
-
- _cond_val = condition_factory(parser.get_op());
- if (_cond_val) {
- _cond_val->initialize(parser);
- }
- }
- _int_value = strtol(_value.c_str(), NULL, 10);
- }
-
- void
- append_value(std::string& s, const Resources& res) const {
- if (_cond_val) {
- _cond_val->append_value(s, res);
- } else {
- s += _value;
- }
- }
-
- const std::string& get_value() const { return _value; }
- int get_int_value() const { return _int_value; }
-
- bool empty() const { return _value.empty(); }
-
-private:
- DISALLOW_COPY_AND_ASSIGN(Value);
-
- std::string _value;
- int _int_value;
- Condition* _cond_val;
-};
-
-
-#endif // __VALUE_H
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/header_rewrite/Examples/Force-close
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/Examples/Force-close b/plugins/header_rewrite/Examples/Force-close
new file mode 100644
index 0000000..cd8fbaf
--- /dev/null
+++ b/plugins/header_rewrite/Examples/Force-close
@@ -0,0 +1,21 @@
+#
+# 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.
+
+cond %{READ_REQUEST_HDR_HOOK} [AND]
+cond %{ACCESS:/url/local/www/html/status.html} [NOT,OR]
+cond %{RANDOM:1000} =42
+add-header Connection "close"
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/header_rewrite/Examples/Regression
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/Examples/Regression b/plugins/header_rewrite/Examples/Regression
new file mode 100644
index 0000000..dc1c0f8
--- /dev/null
+++ b/plugins/header_rewrite/Examples/Regression
@@ -0,0 +1,32 @@
+#
+# 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.
+
+cond %{STATUS} =201
+set-status 999
+set-status-reason "YDoDed again ..."
+
+cond %{READ_REQUEST_HDR_HOOK}
+rm-header Set-Cookie
+rm-header WWW-Authenticate
+rm-header Connection
+add-header Connection "close"
+
+cond %{RANDOM:10} =4
+set-status 789
+
+cond %{ACCESS:/tmp/foobar} [NOT]
+set-status 666
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/header_rewrite/Examples/YCS-EC
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/Examples/YCS-EC b/plugins/header_rewrite/Examples/YCS-EC
new file mode 100644
index 0000000..80b6703
--- /dev/null
+++ b/plugins/header_rewrite/Examples/YCS-EC
@@ -0,0 +1,36 @@
+#
+# 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.
+
+# The default hook is INK_HTTP_READ_RESPONSE_HDR_HOOK, so need to specify that
+# Remove any cookie/authentication headers from the origin server response
+rm-header Set-Cookie
+rm-header WWW-Authenticate
+
+# This technically violates RFC 2616, but allows us to calculate proper age / freshness
+# in YTS, even when the origin (*caugh* wikimedia) shows odd Date and Age responses.
+rm-header Date
+rm-header Age
+
+# If the origin responds with an HTTP status in the 400 range, normalize to a 404
+cond %{STATUS} >399 [AND]
+cond %{STATUS} <499
+set-status 404
+
+# Don't send these headers to the Origin server
+cond %{SEND_REQUEST_HDR_HOOK}
+rm-header Cache-Control
+rm-header Pragma
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/header_rewrite/Makefile.am
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/Makefile.am b/plugins/header_rewrite/Makefile.am
new file mode 100644
index 0000000..bef7840
--- /dev/null
+++ b/plugins/header_rewrite/Makefile.am
@@ -0,0 +1,39 @@
+# 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.
+
+include $(top_srcdir)/build/plugins.mk
+
+if BUILD_HAVE_BOOST
+
+AM_CPPFLAGS += $(BOOST_CPPFLAGS)
+
+pkglib_LTLIBRARIES = header_rewrite.la
+header_rewrite_la_SOURCES = \
+ condition.cc \
+ conditions.cc \
+ factory.cc \
+ header_rewrite.cc \
+ matcher.cc \
+ operator.cc \
+ operators.cc \
+ parser.cc \
+ regex_helper.cc \
+ resources.cc \
+ ruleset.cc \
+ statement.cc
+header_rewrite_la_LDFLAGS = $(BOOST_LDFLAGS) $(TS_PLUGIN_LDFLAGS)
+
+endif
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/header_rewrite/README
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/README b/plugins/header_rewrite/README
new file mode 100644
index 0000000..df8165f
--- /dev/null
+++ b/plugins/header_rewrite/README
@@ -0,0 +1,171 @@
+Apache Traffic Server Rewrite Header Plugin
+This is a plugin for ATS (Apache Traffic Server), that allows you to
+perform various header "rewrite" rules (operations) on a request or
+response. Currently, only one operation is supported, since we had to get
+this rolling asap.
+
+Note that currently only static string "values" are supported. We'll add
+advanced features to allow for expansions in a future release.
+
+
+Operations
+----------
+
+ rm-header header-name [flags]
+ add-header header "string" [flags]
+ set-status status-code [flags]
+ set-status-reason reason-string [flags]
+ no-op [flags]
+
+
+The following operator(s) currently only works when instantiating the
+plugin as a remap plugin:
+
+ set-destination [qual] value
+
+Where qual is one of the support URL qualifiers
+
+ HOST
+ PORT
+ PATH
+ QUERY
+
+For example (as a remap rule):
+
+ cond %{HEADER:X-Mobile} = "foo"
+ set-destination HOST foo.mobile.bar.com [L]
+
+
+
+Operation flags
+---------------
+ [L] Last rule, do not continue
+
+
+Conditions
+----------
+
+ cond %{STATUS} operand [flags]
+ cond %{RANDOM:nn} operand [flags]
+ cond %{ACCESS:file} [flags]
+ cond %{TRUE} [flags]
+ cond %{FALSE} [flags]
+ cond %{HEADER:header-name} [flags]
+
+
+These conditions have to be first in a ruleset, and you can only have one:
+
+ cond %{READ_RESPONSE_HDR_HOOK} (this is the default hook)
+ cond %{READ_REQUEST_HDR_HOOK}
+ cond %{SEND_REQUEST_HDR_HOOK}
+ cond %{SEND_RESPONSE_HDR_HOOK}
+
+
+Condition flags
+---------------
+ [AND] AND with next condition (default)
+ [OR] OR with next condition
+ [NOT] Invert this condition
+
+
+Operands to conditions
+----------------------
+ =val Lexically equal
+ <val Lexically less then
+ >val Lexically greater then
+
+
+
+RELEASES
+--------
+Version 2.0.0 (6/8/12, bcall)
+-- Ported to ATS
+
+Version 1.7.3 (12/01/11,sambani)
+-- changed mdbm locks to mutex
+
+Version 1.7.2 (10/18/11,cdoshi)
+-- check for url redirect length
+
+Version 1.7.1 (10/18/11,cdoshi)
+-- use size_t instead of unsigned
+
+Version 1.7.0 (10/17/11,cdoshi)
+ - Support for %{PATH}
+
+Version 1.6.9 (10,17,11,cdoshi)
+ - Support for PATH condition
+
+Version 1.6.8 (10/17/11,cdoshi)
+ - Replace the INKHttpHdrStatusSet with INKHttptxnSetHttpRetStatus
+
+Version 1.6.7 (07/21/11, bcall)
+ - [bug 4699620] - Removed some extra printf()'s
+
+Version 1.6.6 (cdoshi)
+ - when Host adder is added setHostChange will be called
+
+Version 1.6.5 (cdoshi)
+ - fix QSA for set-destination
+
+Version 1.6.4 (cdoshi)
+ - support QSA for set-destination
+
+Version 1.6.3 (cdoshi)
+ - support the query,fix the remap stuff
+
+Version 1.6.2 (cdoshi)
+ - Support for regex matcher
+
+Version 1.6.1 (09/15/10, leif)
+ - [bug 3985913]
+
+Version 1.6.0 (07/14/10, leif)
+ - Added support for the timeout-out operator.
+ - Added support for the set-redirect operator.
+ - Added support for INK_HTTP_READ_REQUEST_PRE_REMAP_HOOK (this means we
+ now require YTS 1.18.1 or later).
+
+Version 1.5.0 (06/02/10, leif)
+ - Add support for running as a remap plugin.
+ - Add support for set-destination operator (this currently only works in
+ a remap plugin).
+
+Version 1.4.1 (02/09/10, leif)
+ - Cleanup of error messages.
+ - Changed name from MDBM to DBM.
+
+Version 1.4 (01/20/10, leif)
+ - Added support for CLIENT-HEADER condition.
+ - Cleanup in flags handling and features.
+ - Support MDBM as a condition.
+
+Version 1.3.1 (12/22/09, leif)
+ - Fixed package to support MDBM v2.x and v3.x.
+
+Version 1.3 (12/22/09, leif)
+ - Refactored to allow conditions to be used as values.
+ - Added condition for HEADER.
+ - Added condition for MDBM lookups.
+ - Fixed consistency problems on HOOK names.
+
+Version 1.2 (10/28/09, leif)
+ - Added support for SEND_RESPONSE_HDR_HOOK.
+
+Version 1.1 (10/08/09, leif)
+ - Added support for SEND_REQUEST_HDR_HOOK.
+
+Version 1.0 (9/24/09, leif)
+ - Added support for two hooks.
+ - Added "add-header". Remember to "rm-header" the header first if you
+ want to assure there's only one version.
+ - Added support for %{RANDOM:NN} condition
+ - Added support for %{ACCESS:file} condition
+ - Lots of more code cleanup.
+
+Version 0.2 (7/24/09, leif)
+ - Added support for some basic conditions.
+ - Added support for setting the return status code and reason.
+
+Version 0.1 (7/13/09, leif)
+ - Initial version.
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/header_rewrite/TODO
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/TODO b/plugins/header_rewrite/TODO
new file mode 100644
index 0000000..d71e1d4
--- /dev/null
+++ b/plugins/header_rewrite/TODO
@@ -0,0 +1,29 @@
+* Add a new base class for extracting values (extractor)
+* Implement extractors for various values
+* Make the statement base class virtual inherited
+* In conditions / values, we can get the value by using the << or >> operator
+* Mark which conditions and operators work in what hooks
+* Better debugging on conditions.
+* Add descriptions to conditions and operators.
+* Support configurable timeouts
+* Support "super-conditions", or nested conditions (if (A) if (b) else if (c) )
+
+
+Conditions to add
+
+%{REQUEST-HEADER:<hdr>}
+%{RESPONSE-HEADER:<hdr>}
+
+%{CLIENT-URL}
+%{CLIENT-URL:HOST}
+%{CLIENT-URL:PORT}
+%{CLIENT-URL:PATH}
+%{CLIENT-URL:QUERY}
+%{CLIENT-URL:PARAMS}
+
+%{SERVER-URL}
+%{SERVER-URL:HOST}
+%{SERVER-URL:PORT}
+%{SERVER-URL:PATH}
+%{SERVER-URL:QUERY}
+%{SERVER-URL:PARAMS}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/header_rewrite/condition.cc
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/condition.cc b/plugins/header_rewrite/condition.cc
new file mode 100644
index 0000000..5180962
--- /dev/null
+++ b/plugins/header_rewrite/condition.cc
@@ -0,0 +1,80 @@
+/*
+ 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.
+*/
+//////////////////////////////////////////////////////////////////////////////////////////////
+// condition.cc: Implementation of the condition base class
+//
+//
+#include <ts/ts.h>
+#include <string>
+
+#include "condition.h"
+
+
+static MatcherOps
+parse_matcher_op(std::string& arg)
+{
+ switch (arg[0]) {
+ case '=':
+ arg.erase(0,1);
+ return MATCH_EQUAL;
+ break;
+ case '<':
+ arg.erase(0,1);
+ return MATCH_LESS_THEN;
+ break;
+ case '>':
+ arg.erase(0,1);
+ return MATCH_GREATER_THEN;
+ break;
+ case '/':
+ arg.erase(0,1);
+ arg.erase(arg.length() -1 , arg.length());
+ return MATCH_REGULAR_EXPRESSION;
+ break;
+ default:
+ return MATCH_EQUAL;
+ break;
+ }
+}
+
+
+void
+Condition::initialize(Parser& p)
+{
+ Statement::initialize(p);
+
+ if (p.mod_exist("OR")) {
+ if (p.mod_exist("AND")) {
+ TSError("header_rewrite: Can't have both AND and OR in mods");
+ } else {
+ _mods = static_cast<CondModifiers>(_mods | COND_OR);
+ }
+ } else if (p.mod_exist("AND")) {
+ _mods = static_cast<CondModifiers>(_mods | COND_AND);
+ }
+
+ if (p.mod_exist("NOT")) {
+ _mods = static_cast<CondModifiers>(_mods | COND_NOT);
+ }
+
+ if (p.mod_exist("L")) {
+ _mods = static_cast<CondModifiers>(_mods | COND_LAST);
+ }
+
+ _cond_op = parse_matcher_op(p.get_arg());
+}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/header_rewrite/condition.h
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/condition.h b/plugins/header_rewrite/condition.h
new file mode 100644
index 0000000..e832a87
--- /dev/null
+++ b/plugins/header_rewrite/condition.h
@@ -0,0 +1,115 @@
+/*
+ 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.
+*/
+//////////////////////////////////////////////////////////////////////////////////////////////
+//
+// Implement the classes for the various types of hash keys we support.
+//
+#ifndef __CONDITION_H__
+#define __CONDITION_H__ 1
+
+#include <string>
+#include <ts/ts.h>
+
+#include "resources.h"
+#include "statement.h"
+#include "matcher.h"
+#include "parser.h"
+
+
+// Condition modifiers
+enum CondModifiers {
+ COND_NONE = 0,
+ COND_OR = 1,
+ COND_AND = 2,
+ COND_NOT = 4,
+ COND_NOCASE = 8,
+ COND_LAST = 16,
+ COND_CHAIN = 32
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Base class for all Conditions (this is also the interface)
+//
+class Condition : public Statement
+{
+public:
+ Condition()
+ : _qualifier(""), _cond_op(MATCH_EQUAL), _matcher(NULL), _mods(COND_NONE)
+ {
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for Condition");
+ }
+
+ // Inline this, it's critical for speed (and only used twice)
+ bool do_eval(const Resources& res)
+ {
+ bool rt = eval(res);
+
+ if (_mods & COND_NOT)
+ rt = !rt;
+
+ if (_next) {
+ if (_mods & COND_OR) {
+ return rt || (static_cast<Condition*>(_next)->do_eval(res));
+ } else { // AND is the default
+ // Short circuit if we're an AND and the first condition is FALSE.
+ if (rt)
+ return static_cast<Condition*>(_next)->do_eval(res);
+ else
+ return false;
+ }
+ } else {
+ return rt;
+ }
+
+ return false; // Shouldn't happen.
+ }
+
+ bool last() const {
+ return _mods & COND_LAST;
+ }
+
+ // Setters
+ virtual void set_qualifier(const std::string& q) { _qualifier = q; }
+
+ // Some getters
+ const Matcher* get_matcher() const { return _matcher; }
+ const MatcherOps get_cond_op() const { return _cond_op; }
+ const std::string get_qualifier() const { return _qualifier; }
+
+ // Virtual methods, has to be implemented by each conditional;
+ virtual void initialize(Parser& p);
+ virtual void append_value(std::string& s, const Resources& res) = 0;
+
+protected:
+ // Evaluate the condition
+ virtual bool eval(const Resources& res) = 0;
+
+ std::string _qualifier;
+ MatcherOps _cond_op;
+ Matcher* _matcher;
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(Condition);
+
+ CondModifiers _mods;
+};
+
+
+#endif // __CONDITION_H
+
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/header_rewrite/conditions.cc
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc
new file mode 100644
index 0000000..84ad1f0
--- /dev/null
+++ b/plugins/header_rewrite/conditions.cc
@@ -0,0 +1,376 @@
+/*
+ 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.
+*/
+//////////////////////////////////////////////////////////////////////////////////////////////
+// conditions.cc: Implementation of the condition classes
+//
+//
+#include <unistd.h>
+#include <ts/ts.h>
+
+#include "conditions.h"
+#include "lulu.h"
+
+#include <sys/time.h>
+
+
+// ConditionStatus
+void
+ConditionStatus::initialize(Parser& p)
+{
+ Condition::initialize(p);
+
+ Matchers<TSHttpStatus>* match = new Matchers<TSHttpStatus>(_cond_op);
+
+ match->set(static_cast<TSHttpStatus>(strtol(p.get_arg().c_str(), NULL, 10)));
+ _matcher = match;
+
+ require_resources(RSRC_SERVER_RESPONSE_HEADERS);
+ require_resources(RSRC_CLIENT_RESPONSE_HEADERS);
+ require_resources(RSRC_RESPONSE_STATUS);
+}
+
+
+void
+ConditionStatus::initialize_hooks() {
+ add_allowed_hook(TS_HTTP_READ_RESPONSE_HDR_HOOK);
+ add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK);
+}
+
+
+bool
+ConditionStatus::eval(const Resources& res) {
+ TSDebug(PLUGIN_NAME, "Evaluating STATUS()"); // TODO: It'd be nice to get the args here ...
+ return static_cast<const Matchers<TSHttpStatus>*>(_matcher)->test(res.resp_status);
+}
+
+
+void
+ConditionStatus::append_value(std::string& s, const Resources& res) {
+ s += boost::lexical_cast<std::string>(res.resp_status);
+ TSDebug(PLUGIN_NAME, "Appending STATUS(%d) to evaluation value -> %s", res.resp_status, s.c_str());
+}
+
+
+// ConditionRandom: random 0 to (N-1)
+void
+ConditionRandom::initialize(Parser& p)
+{
+ struct timeval tv;
+
+ Condition::initialize(p);
+
+ gettimeofday(&tv, NULL);
+
+ Matchers<unsigned int>* match = new Matchers<unsigned int>(_cond_op);
+ _seed = getpid()* tv.tv_usec;
+ _max = strtol(_qualifier.c_str(), NULL, 10);
+
+ match->set(static_cast<unsigned int>(strtol(p.get_arg().c_str(), NULL, 10)));
+ _matcher = match;
+}
+
+
+bool
+ConditionRandom::eval(const Resources& /* res ATS_UNUSED */) {
+ TSDebug(PLUGIN_NAME, "Evaluating RANDOM(%d)", _max);
+ return static_cast<const Matchers<unsigned int>*>(_matcher)->test(rand_r(&_seed) % _max);
+}
+
+
+void
+ConditionRandom::append_value(std::string& s, const Resources& /* res ATS_UNUSED */)
+{
+ s += boost::lexical_cast<std::string>(rand_r(&_seed) % _max);
+ TSDebug(PLUGIN_NAME, "Appending RANDOM(%d) to evaluation value -> %s", _max, s.c_str());
+}
+
+
+// ConditionAccess: access(file)
+void
+ConditionAccess::initialize(Parser& p)
+{
+ struct timeval tv;
+
+ Condition::initialize(p);
+
+ gettimeofday(&tv, NULL);
+
+ _next = tv.tv_sec + 2;
+ _last = !access(_qualifier.c_str(), R_OK);
+}
+
+
+void
+ConditionAccess::append_value(std::string& s, const Resources& res)
+{
+ if (eval(res)) {
+ s += "OK";
+ } else {
+ s += "NOT OK";
+ }
+}
+
+
+bool
+ConditionAccess::eval(const Resources& /* res ATS_UNUSED */)
+{
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+
+ TSDebug(PLUGIN_NAME, "Evaluating ACCESS(%s)", _qualifier.c_str());
+ if (tv.tv_sec > _next) {
+ // There is a small "race" here, where we could end up calling access() a few times extra. I think
+ // that is OK, and not worth protecting with a lock.
+ bool check = !access(_qualifier.c_str(), R_OK);
+
+ tv.tv_sec += 2;
+ mb();
+ _next = tv.tv_sec; // I hope this is an atomic "set"...
+ _last = check; // This sure ought to be
+ }
+
+ return _last;
+}
+
+
+// ConditionHeader: request or response header
+void
+ConditionHeader::initialize(Parser& p)
+{
+ Condition::initialize(p);
+
+ Matchers<std::string>* match = new Matchers<std::string>(_cond_op);
+ match->set(p.get_arg());
+
+ _matcher = match;
+
+ require_resources(RSRC_CLIENT_REQUEST_HEADERS);
+ require_resources(RSRC_CLIENT_RESPONSE_HEADERS);
+ require_resources(RSRC_SERVER_REQUEST_HEADERS);
+ require_resources(RSRC_SERVER_RESPONSE_HEADERS);
+}
+
+
+void
+ConditionHeader::append_value(std::string& s, const Resources& res)
+{
+ TSMBuffer bufp;
+ TSMLoc hdr_loc;
+ TSMLoc field_loc;
+ const char* value;
+ int len;
+
+ if (_client) {
+ bufp = res.client_bufp;
+ hdr_loc = res.client_hdr_loc;
+ } else {
+ bufp = res.bufp;
+ hdr_loc = res.hdr_loc;
+ }
+
+ if (bufp && hdr_loc) {
+ field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, _qualifier.c_str(), _qualifier.size());
+ TSDebug(PLUGIN_NAME, "Getting Header: %s, field_loc: %p", _qualifier.c_str(), field_loc);
+ if (field_loc != NULL) {
+ value = TSMimeHdrFieldValueStringGet(res.bufp, res.hdr_loc, field_loc, 0, &len);
+ TSDebug(PLUGIN_NAME, "Appending HEADER(%s) to evaluation value -> %.*s", _qualifier.c_str(), len, value);
+ s.append(value, len);
+ TSHandleMLocRelease(res.bufp, res.hdr_loc, field_loc);
+ }
+ }
+}
+
+
+bool
+ConditionHeader::eval(const Resources& res)
+{
+ std::string s;
+
+ append_value(s, res);
+ bool rval = static_cast<const Matchers<std::string>*>(_matcher)->test(s);
+ TSDebug(PLUGIN_NAME, "Evaluating HEADER(): %s - rval: %d", s.c_str(), rval);
+ return rval;
+}
+
+// ConditionPath
+void
+ConditionPath::initialize(Parser& p)
+{
+ Condition::initialize(p);
+
+ Matchers<std::string>* match = new Matchers<std::string>(_cond_op);
+ match->set(p.get_arg());
+
+ _matcher = match;
+}
+
+void
+ConditionPath::append_value(std::string& s, const Resources& res)
+{
+ int path_len = 0;
+ const char *path = TSUrlPathGet(res._rri->requestBufp, res._rri->requestUrl, &path_len);
+ TSDebug(PLUGIN_NAME, "Appending PATH to evaluation value: %.*s", path_len, path);
+ s.append(path, path_len);
+}
+
+bool
+ConditionPath::eval(const Resources& res)
+{
+ std::string s;
+
+ if (NULL == res._rri) {
+ TSDebug(PLUGIN_NAME, "PATH requires remap initialization! Evaluating to false!");
+ return false;
+ }
+ append_value(s, res);
+ TSDebug(PLUGIN_NAME, "Evaluating PATH");
+
+ return static_cast<const Matchers<std::string>*>(_matcher)->test(s);
+}
+
+// ConditionQuery
+void
+ConditionQuery::initialize(Parser& p)
+{
+ Condition::initialize(p);
+
+ Matchers<std::string>* match = new Matchers<std::string>(_cond_op);
+ match->set(p.get_arg());
+ _matcher = match;
+
+}
+
+void
+ConditionQuery::append_value(std::string& s, const Resources& res)
+{
+ int query_len = 0;
+ const char *query = TSUrlHttpQueryGet(res._rri->requestBufp, res._rri->requestUrl, &query_len);
+ TSDebug(PLUGIN_NAME, "Appending QUERY to evaluation value: %.*s", query_len, query);
+ s.append(query, query_len);
+}
+
+bool
+ConditionQuery::eval(const Resources& res)
+{
+ std::string s;
+
+ if (NULL == res._rri) {
+ TSDebug(PLUGIN_NAME, "QUERY requires remap initialization! Evaluating to false!");
+ return false;
+ }
+ append_value(s, res);
+ TSDebug(PLUGIN_NAME, "Evaluating QUERY - %s", s.c_str());
+ return static_cast<const Matchers<std::string>*>(_matcher)->test(s);
+}
+
+
+// ConditionUrl: request or response header. TODO: This is not finished, at all!!!
+void
+ConditionUrl::initialize(Parser& /* p ATS_UNUSED */)
+{
+}
+
+
+void
+ConditionUrl::set_qualifier(const std::string& q) {
+ Condition::set_qualifier(q);
+
+ _url_qual = parse_url_qualifier(q);
+}
+
+
+void
+ConditionUrl::append_value(std::string& /* s ATS_UNUSED */, const Resources& /* res ATS_UNUSED */)
+{
+}
+
+
+bool
+ConditionUrl::eval(const Resources& /* res ATS_UNUSED */)
+{
+ bool ret = false;
+
+ return ret;
+}
+
+
+// ConditionDBM: do a lookup against a DBM
+void
+ConditionDBM::initialize(Parser& p)
+{
+ Condition::initialize(p);
+
+ Matchers<std::string>* match = new Matchers<std::string>(_cond_op);
+ match->set(p.get_arg());
+ _matcher = match;
+
+ std::string::size_type pos = _qualifier.find_first_of(',');
+
+ if (pos != std::string::npos) {
+ _file = _qualifier.substr(0, pos);
+ //_dbm = mdbm_open(_file.c_str(), O_RDONLY, 0, 0, 0);
+ // if (NULL != _dbm) {
+ // TSDebug(PLUGIN_NAME, "Opened DBM file %s\n", _file.c_str());
+ // _key.set_value(_qualifier.substr(pos + 1));
+ // } else {
+ // TSError("Failed to open DBM file: %s", _file.c_str());
+ // }
+ } else {
+ TSError("Malformed DBM condition");
+ }
+}
+
+
+void
+ConditionDBM::append_value(std::string& /* s ATS_UNUSED */, const Resources& /* res ATS_UNUSED */)
+{
+ // std::string key;
+
+ // if (!_dbm)
+ // return;
+
+ // _key.append_value(key, res);
+ // if (key.size() > 0) {
+ // datum k, v;
+
+ // TSDebug(PLUGIN_NAME, "Looking up DBM(\"%s\")", key.c_str());
+ // k.dptr = const_cast<char*>(key.c_str());
+ // k.dsize = key.size();
+
+ // TSMutexLock(_mutex);
+ // //v = mdbm_fetch(_dbm, k);
+ // TSMutexUnlock(_mutex);
+ // if (v.dsize > 0) {
+ // TSDebug(PLUGIN_NAME, "Appending DBM(%.*s) to evaluation value -> %.*s", k.dsize, k.dptr, v.dsize, v.dptr);
+ // s.append(v.dptr, v.dsize);
+ // }
+ // }
+}
+
+
+bool
+ConditionDBM::eval(const Resources& res)
+{
+ std::string s;
+
+ append_value(s, res);
+ TSDebug(PLUGIN_NAME, "Evaluating DBM(%s, \"%s\")", _file.c_str(), s.c_str());
+
+ return static_cast<const Matchers<std::string>*>(_matcher)->test(s);
+}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/header_rewrite/conditions.h
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/conditions.h b/plugins/header_rewrite/conditions.h
new file mode 100644
index 0000000..904533d
--- /dev/null
+++ b/plugins/header_rewrite/conditions.h
@@ -0,0 +1,284 @@
+/*
+ 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.
+*/
+//////////////////////////////////////////////////////////////////////////////////////////////
+//
+// Declarations for all conditionals / conditional values we support.
+//
+#ifndef __CONDITIONS_H__
+#define __CONDITIONS_H__ 1
+
+#include <string>
+#include <ts/ts.h>
+#include <boost/lexical_cast.hpp>
+
+#include "condition.h"
+#include "matcher.h"
+#include "value.h"
+#include "lulu.h"
+//#include <mdbm.h>
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Condition declarations.
+//
+
+// Always true
+class ConditionTrue : public Condition
+{
+public:
+ ConditionTrue()
+ {
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionTrue");
+ }
+
+ void append_value(std::string& s, const Resources& /* res ATS_UNUSED */) { s += "TRUE"; }
+
+protected:
+ bool eval(const Resources& /* res ATS_UNUSED */) {
+ TSDebug(PLUGIN_NAME, "Evaluating TRUE()");
+ return true;
+ }
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ConditionTrue);
+};
+
+
+// Always false
+class ConditionFalse : public Condition
+{
+public:
+ ConditionFalse()
+ {
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionFalse");
+ }
+ void append_value(std::string& s, const Resources& /* res ATS_UNUSED */) { s += "FALSE"; }
+
+protected:
+ bool eval(const Resources& /* res ATS_UNUSED */) {
+ TSDebug(PLUGIN_NAME, "Evaluating FALSE()");
+ return false;
+ }
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ConditionFalse);
+};
+
+
+// Check the HTTP return status
+class ConditionStatus : public Condition
+{
+public:
+ ConditionStatus()
+ {
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionStatus");
+ }
+ void initialize(Parser& p);
+ void append_value(std::string& s, const Resources& res);
+
+protected:
+ bool eval(const Resources& res);
+ void initialize_hooks(); // Return status only valid in certain hooks
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ConditionStatus);
+};
+
+
+// Random 0 to (N-1)
+class ConditionRandom : public Condition
+{
+public:
+ ConditionRandom()
+ : _seed(0), _max(0)
+ {
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionRandom");
+ }
+ void initialize(Parser& p);
+ void append_value(std::string& s, const Resources& res);
+
+protected:
+ bool eval(const Resources& res);
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ConditionRandom);
+
+ unsigned int _seed;
+ unsigned int _max;
+};
+
+
+// access(file)
+class ConditionAccess : public Condition
+{
+public:
+ ConditionAccess()
+ : _next(0), _last(false)
+ {
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionAccess");
+ }
+ void initialize(Parser& p);
+ void append_value(std::string& s, const Resources& res);
+
+protected:
+ bool eval(const Resources& res);
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ConditionAccess);
+
+ time_t _next;
+ bool _last;
+};
+
+
+// header
+class ConditionHeader : public Condition
+{
+public:
+ explicit ConditionHeader(bool client = false)
+ : _client(client)
+ {
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionHeader, client %d", client);
+ };
+
+ void initialize(Parser& p);
+ void append_value(std::string& s, const Resources& res);
+
+protected:
+ bool eval(const Resources& res);
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ConditionHeader);
+
+ bool _client;
+};
+
+// path
+class ConditionPath : public Condition
+{
+public:
+ explicit ConditionPath()
+ {
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionPath");
+ };
+
+ void initialize(Parser& p);
+ void append_value(std::string& s, const Resources& res);
+
+protected:
+ bool eval(const Resources& res);
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ConditionPath);
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+class ConditionQuery : public Condition
+{
+public:
+ explicit ConditionQuery()
+ {
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionQuery");
+ };
+
+ void initialize(Parser& p);
+ void append_value(std::string& s, const Resources& res);
+
+protected:
+ bool eval(const Resources& res);
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ConditionQuery);
+
+};
+
+
+// url
+class ConditionUrl : public Condition
+{
+public:
+ explicit ConditionUrl(bool client = false)
+ : _url_qual(URL_QUAL_NONE), _client(client)
+ {
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionUrl");
+ };
+
+ void initialize(Parser& p);
+ void set_qualifier(const std::string& q);
+ void append_value(std::string& s, const Resources& res);
+
+protected:
+ bool eval(const Resources& res);
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ConditionUrl);
+
+ UrlQualifiers _url_qual;
+ bool _client;
+};
+
+
+// DBM lookups
+class ConditionDBM : public Condition
+{
+public:
+ ConditionDBM()
+ :
+ //_dbm(NULL),
+ _file("")
+ {
+ _mutex = TSMutexCreate();
+ TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionDBM");
+ }
+
+ ~ConditionDBM() {
+ // if (_dbm) {
+ // mdbm_close(_dbm);
+ // _dbm = NULL;
+ // }
+ }
+
+ void initialize(Parser& p);
+ void append_value(std::string& s, const Resources& res);
+
+protected:
+ bool eval(const Resources& res);
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ConditionDBM);
+
+ //MDBM* _dbm;
+ std::string _file;
+ Value _key;
+ TSMutex _mutex;
+};
+
+#endif // __CONDITIONS_H
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/header_rewrite/factory.cc
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/factory.cc b/plugins/header_rewrite/factory.cc
new file mode 100644
index 0000000..d20fa40
--- /dev/null
+++ b/plugins/header_rewrite/factory.cc
@@ -0,0 +1,109 @@
+/*
+ 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.
+*/
+//////////////////////////////////////////////////////////////////////////////////////////////
+// factory.cc: Factory functions for operators, conditions and condition variables.
+//
+//
+#include <string>
+
+#include "operators.h"
+#include "conditions.h"
+
+
+///////////////////////////////////////////////////////////////////////////////
+// "Factory" functions, processing the parsed lines
+//
+Operator*
+operator_factory(const std::string& op)
+{
+ Operator* o = NULL;
+
+ if (op == "rm-header") {
+ o = new OperatorRMHeader();
+ } else if (op == "add-header") {
+ o = new OperatorAddHeader();
+ } else if (op == "set-status") {
+ o = new OperatorSetStatus();
+ } else if (op == "set-status-reason") {
+ o = new OperatorSetStatusReason();
+ } else if (op == "set-destination") {
+ o = new OperatorSetDestination();
+ } else if (op == "set-redirect") {
+ o = new OperatorSetRedirect();
+ } else if (op == "timeout-out") {
+ o = new OperatorSetTimeoutOut();
+ } else if (op == "no-op") {
+ o = new OperatorNoOp();
+ } else {
+ TSError("header_rewrite: unknown operator in header_rewrite: %s", op.c_str());
+ return NULL;
+ }
+
+ return o;
+}
+
+
+Condition*
+condition_factory(const std::string& cond)
+{
+ Condition* c = NULL;
+ std::string c_name, c_qual;
+ std::string::size_type pos = cond.find_first_of(':');
+
+ if (pos != std::string::npos) {
+ c_name = cond.substr(0, pos);
+ c_qual = cond.substr(pos + 1);
+ } else {
+ c_name = cond;
+ c_qual = "";
+ }
+
+ if (c_name == "TRUE") {
+ c = new ConditionTrue();
+ } else if (c_name == "FALSE") {
+ c = new ConditionFalse();
+ } else if (c_name == "STATUS") {
+ c = new ConditionStatus();
+ } else if (c_name == "RANDOM") {
+ c = new ConditionRandom();
+ } else if (c_name == "ACCESS") {
+ c = new ConditionAccess();
+ } else if (c_name == "HEADER") { // This condition adapts to the hook
+ c = new ConditionHeader();
+ }else if (c_name == "PATH"){
+ c= new ConditionPath();
+ } else if (c_name == "CLIENT-HEADER") {
+ c = new ConditionHeader(true);
+ } else if (c_name == "QUERY") {
+ c = new ConditionQuery();
+ } else if (c_name == "URL") { // This condition adapts to the hook
+ c = new ConditionUrl();
+ } else if (c_name == "CLIENT-URL") {
+ c = new ConditionUrl(true);
+ } else if (c_name == "DBM") {
+ c = new ConditionDBM();
+ } else {
+ TSError("header_rewrite: unknown condition in header_rewrite: %s",c_name.c_str());
+ return NULL;
+ }
+
+ if (c_qual != "")
+ c->set_qualifier(c_qual);
+
+ return c;
+}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9d6707b4/plugins/header_rewrite/factory.h
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/factory.h b/plugins/header_rewrite/factory.h
new file mode 100644
index 0000000..d10280a
--- /dev/null
+++ b/plugins/header_rewrite/factory.h
@@ -0,0 +1,34 @@
+/*
+ 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.
+*/
+//////////////////////////////////////////////////////////////////////////////////////////////
+//
+// Implement the classes for the various types of hash keys we support.
+//
+#ifndef __FACTORY_H__
+#define __FACTORY_H__ 1
+
+#include <string>
+
+#include "operator.h"
+#include "condition.h"
+
+Operator* operator_factory(const std::string& op);
+Condition* condition_factory(const std::string& cond);
+
+
+#endif