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 2011/03/17 15:00:57 UTC
svn commit: r1082494 - in /trafficserver/traffic/trunk: example/query_remap/
example/remap/ mgmt/ proxy/ proxy/api/ts/ proxy/config/ proxy/http/
proxy/http/remap/ tools/
Author: zwoop
Date: Thu Mar 17 14:00:57 2011
New Revision: 1082494
URL: http://svn.apache.org/viewvc?rev=1082494&view=rev
Log:
TS-588 Phase two, change the RRI struct to be less insane
Modified:
trafficserver/traffic/trunk/example/query_remap/query_remap.c
trafficserver/traffic/trunk/example/remap/remap.cc
trafficserver/traffic/trunk/mgmt/RecordsConfig.cc
trafficserver/traffic/trunk/proxy/ReverseProxy.cc
trafficserver/traffic/trunk/proxy/api/ts/remap.h
trafficserver/traffic/trunk/proxy/config/records.config.in
trafficserver/traffic/trunk/proxy/http/HttpTransact.cc
trafficserver/traffic/trunk/proxy/http/remap/AclFiltering.cc
trafficserver/traffic/trunk/proxy/http/remap/AclFiltering.h
trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.cc
trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.h
trafficserver/traffic/trunk/proxy/http/remap/UrlMapping.cc
trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc
trafficserver/traffic/trunk/tools/apichecker.pl
Modified: trafficserver/traffic/trunk/example/query_remap/query_remap.c
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/example/query_remap/query_remap.c?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/example/query_remap/query_remap.c (original)
+++ trafficserver/traffic/trunk/example/query_remap/query_remap.c Thu Mar 17 14:00:57 2011
@@ -110,27 +110,28 @@ TSRemapDeleteInstance(void* ih)
}
-int
+TSRemapStatus
TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
{
int hostidx = -1;
query_remap_info *qri = (query_remap_info*)ih;
- if (!qri) {
- TSError(PLUGIN_NAME "NULL private data");
- return 0;
+ if (!qri || !rri) {
+ TSError(PLUGIN_NAME "NULL private data or RRI");
+ return TSREMAP_NO_REMAP;
}
- TSDebug(PLUGIN_NAME, "TSRemapDoRemap request: %.*s", rri->orig_url_size, rri->orig_url);
-
- if (rri && rri->request_query && rri->request_query_size > 0) {
+ int req_query_len;
+ const char* req_query = TSUrlHttpQueryGet(rri->requestBufp, rri->requestUrl, &req_query_len);
+
+ if (req_query && req_query_len > 0) {
char *q, *key;
char *s = NULL;
/* make a copy of the query, as it is read only */
- q = (char*) TSmalloc(rri->request_query_size+1);
- strncpy(q, rri->request_query, rri->request_query_size);
- q[rri->request_query_size] = '\0';
+ q = (char*) TSmalloc(req_query_len+1);
+ strncpy(q, req_query, req_query_len);
+ q[req_query_len] = '\0';
/* parse query parameters */
for (key = strtok_r(q, "&", &s); key != NULL;) {
@@ -150,22 +151,22 @@ TSRemapDoRemap(void* ih, TSHttpTxn rh, T
TSfree(q);
if (hostidx >= 0) {
- rri->new_host_size = strlen(qri->hosts[hostidx]);
- if (rri->new_host_size <= TSREMAP_RRI_MAX_HOST_SIZE) {
- /* copy the chosen host into rri */
- memcpy(rri->new_host, qri->hosts[hostidx], rri->new_host_size);
-
- TSDebug(PLUGIN_NAME, "host changed from [%.*s] to [%.*s]",
- rri->request_host_size, rri->request_host,
- rri->new_host_size, rri->new_host);
- return 1; /* host has been modified */
+ int req_host_len;
+ /* TODO: Perhaps use TSIsDebugTagSet() before calling TSUrlHostGet()... */
+ const char* req_host = TSUrlHostGet(rri->requestBufp, rri->requestUrl, &req_host_len);
+
+ if (TSUrlHostSet(rri->requestBufp, rri->requestUrl, qri->hosts[hostidx], strlen(qri->hosts[hostidx])) != TS_SUCCESS) {
+ TSDebug(PLUGIN_NAME, "Failed to modify the Host in request URL");
+ return TSREMAP_NO_REMAP;
}
+ TSDebug(PLUGIN_NAME, "host changed from [%.*s] to [%s]", req_host_len, req_host, qri->hosts[hostidx]);
+ return TSREMAP_DID_REMAP; /* host has been modified */
}
}
/* the request was not modified, TS will use the toURL from the remap rule */
TSDebug(PLUGIN_NAME, "request not modified");
- return 0;
+ return TSREMAP_NO_REMAP;
}
Modified: trafficserver/traffic/trunk/example/remap/remap.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/example/remap/remap.cc?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/example/remap/remap.cc (original)
+++ trafficserver/traffic/trunk/example/remap/remap.cc Thu Mar 17 14:00:57 2011
@@ -70,8 +70,8 @@ public:
char **argv;
remap_entry(int _argc, char *_argv[]);
~remap_entry();
- static void add_to_list(remap_entry * re);
- static void remove_from_list(remap_entry * re);
+ static void add_to_list(remap_entry *re);
+ static void remove_from_list(remap_entry *re);
};
static int plugin_init_counter = 0; /* remap plugin initialization counter */
@@ -111,7 +111,7 @@ remap_entry::~remap_entry()
/* --------------------- remap_entry::add_to_list -------------------------- */
void
-remap_entry::add_to_list(remap_entry * re)
+remap_entry::add_to_list(remap_entry *re)
{
if (likely(re && plugin_init_counter)) {
pthread_mutex_lock(&mutex);
@@ -123,7 +123,7 @@ remap_entry::add_to_list(remap_entry * r
/* ------------------ remap_entry::remove_from_list ------------------------ */
void
-remap_entry::remove_from_list(remap_entry * re)
+remap_entry::remove_from_list(remap_entry *re)
{
remap_entry **rre;
if (likely(re && plugin_init_counter)) {
@@ -139,8 +139,8 @@ remap_entry::remove_from_list(remap_entr
}
/* ----------------------- store_my_error_message -------------------------- */
-static int
-store_my_error_message(int retcode, char *err_msg_buf, int buf_size, const char *fmt, ...)
+static TSReturnCode
+store_my_error_message(TSReturnCode retcode, char *err_msg_buf, int buf_size, const char *fmt, ...)
{
if (likely(err_msg_buf && buf_size > 0 && fmt)) {
va_list ap;
@@ -153,26 +153,6 @@ store_my_error_message(int retcode, char
return retcode; /* error code here */
}
-/* -------------------------- my_print_ascii_string ------------------------ */
-static void
-my_print_ascii_string(const char *str, int str_size)
-{
- char buf[1024];
- int i, j;
-
- if (str) {
- for (i = 0; i < str_size;) {
- if ((j = (str_size - i)) >= (int) sizeof(buf))
- j = (int) (sizeof(buf) - 1);
- memcpy(buf, str, j);
- buf[j] = 0;
- fprintf(stderr, "%s", buf);
- str += j;
- i += j;
- }
- }
-}
-
void
TSPluginInit(int argc, const char *argv[])
{
@@ -190,51 +170,48 @@ TSPluginInit(int argc, const char *argv[
// Plugin initialization code. Called immediately after dlopen() Only once!
// Can perform internal initialization. For example, pthread_.... initialization.
/* ------------------------- TSRemapInit ---------------------------------- */
-int
-TSRemapInit(TSRemapInterface * api_info, char *errbuf, int errbuf_size)
+TSReturnCode
+TSRemapInit(TSRemapInterface *api_info, char *errbuf, int errbuf_size)
{
fprintf(stderr, "Remap Plugin: TSRemapInit()\n");
if (!plugin_init_counter) {
if (unlikely(!api_info)) {
- return store_my_error_message(-1, errbuf, errbuf_size, "[TSRemapInit] - Invalid TSRemapInterface argument");
+ return store_my_error_message(TS_ERROR, errbuf, errbuf_size, "[TSRemapInit] - Invalid TSRemapInterface argument");
}
if (unlikely(api_info->size < sizeof(TSRemapInterface))) {
- return store_my_error_message(-2, errbuf, errbuf_size,
+ return store_my_error_message(TS_ERROR, errbuf, errbuf_size,
"[TSRemapInit] - Incorrect size of TSRemapInterface structure %d. Should be at least %d bytes",
(int) api_info->size, (int) sizeof(TSRemapInterface));
}
if (unlikely(api_info->tsremap_version < TSREMAP_VERSION)) {
- return store_my_error_message(-3, errbuf, errbuf_size,
+ return store_my_error_message(TS_ERROR, errbuf, errbuf_size,
"[TSRemapInit] - Incorrect API version %d.%d",
(api_info->tsremap_version >> 16), (api_info->tsremap_version & 0xffff));
}
if (pthread_mutex_init(&remap_plugin_global_mutex, 0) || pthread_mutex_init(&remap_entry::mutex, 0)) { /* pthread_mutex_init - always returns 0. :) - impossible error */
- return store_my_error_message(-4, errbuf, errbuf_size, "[TSRemapInit] - Mutex initialization error");
+ return store_my_error_message(TS_ERROR, errbuf, errbuf_size, "[TSRemapInit] - Mutex initialization error");
}
plugin_init_counter++;
}
- return 0; /* success */
+ return TS_SUCCESS; /* success */
}
// Plugin shutdown
// Optional function.
/* -------------------------- TSRemapDone --------------------------------- */
-int
+void
TSRemapDone(void)
{
fprintf(stderr, "Remap Plugin: TSRemapDone()\n");
- /* do nothing */
-
- return 0;
}
// Plugin new instance for new remapping rule.
// This function can be called multiple times (depends on remap.config)
/* ------------------------ TSRemapNewInstance --------------------------- */
-int
+TSReturnCode
TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_size)
{
remap_entry *ri;
@@ -244,11 +221,11 @@ TSRemapNewInstance(int argc, char *argv[
fprintf(stderr, "Remap Plugin: TSRemapNewInstance()\n");
if (argc < 2) {
- return store_my_error_message(-1, errbuf, errbuf_size,
+ return store_my_error_message(TS_ERROR, errbuf, errbuf_size,
"[TSRemapNewInstance] - Incorrect number of arguments - %d", argc);
}
if (!argv || !ih) {
- return store_my_error_message(-2, errbuf, errbuf_size, "[TSRemapNewInstance] - Invalid argument(s)");
+ return store_my_error_message(TS_ERROR, errbuf, errbuf_size, "[TSRemapNewInstance] - Invalid argument(s)");
}
// print all arguments for this particular remapping
for (i = 0; i < argc; i++) {
@@ -258,14 +235,14 @@ TSRemapNewInstance(int argc, char *argv[
ri = new remap_entry(argc, argv);
if (!ri) {
- return store_my_error_message(-3, errbuf, errbuf_size, "[TSRemapNewInstance] - Can't create remap_entry class");
+ return store_my_error_message(TS_ERROR, errbuf, errbuf_size, "[TSRemapNewInstance] - Can't create remap_entry class");
}
remap_entry::add_to_list(ri);
*ih = (void*) ri;
- return 0;
+ return TS_SUCCESS;
}
/* ---------------------- TSRemapDeleteInstance -------------------------- */
@@ -285,62 +262,59 @@ static volatile unsigned long processing
static int arg_index = 0;
/* -------------------------- TSRemapDoRemap -------------------------------- */
-int
-TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo * rri)
+TSRemapStatus
+TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
{
- TSMBuffer cbuf;
- TSMLoc chdr;
+ const char* temp;
+ const char* temp2;
+ int len, len2, port;
TSMLoc cfield;
- int retcode = 0; // TS must perform actual remapping
unsigned long _processing_counter = ++processing_counter; // one more function call (in real life use mutex to protect this counter)
remap_entry *ri = (remap_entry *) ih;
fprintf(stderr, "Remap Plugin: TSRemapDoRemap()\n");
if (!ri || !rri)
- return 0; /* TS must remap this request */
- /* TODO: This should be rewritten to use appropriate APIs from ts/ts.h
- char *p = (char *) &rri->client_ip;
- fprintf(stderr, "[TSRemapDoRemap] Client IP: %d.%d.%d.%d\n", (int) p[0], (int) p[1], (int) p[2], (int) p[3]);
- */
+ return TSREMAP_NO_REMAP; /* TS must remap this request */
+
fprintf(stderr, "[TSRemapDoRemap] From: \"%s\" To: \"%s\"\n", ri->argv[0], ri->argv[1]);
- fprintf(stderr, "[TSRemapDoRemap] OrigURL: \"");
- my_print_ascii_string(rri->orig_url, rri->orig_url_size);
- fprintf(stderr, "\"\n[TSRemapDoRemap] Request Host(%d): \"", rri->request_host_size);
- my_print_ascii_string(rri->request_host, rri->request_host_size);
- fprintf(stderr, "\"\n[TSRemapDoRemap] Remap To Host: \"");
- my_print_ascii_string(rri->remap_to_host, rri->remap_to_host_size);
- fprintf(stderr, "\"\n[TSRemapDoRemap] Remap From Host: \"");
- my_print_ascii_string(rri->remap_from_host, rri->remap_from_host_size);
- fprintf(stderr, "\"\n[TSRemapDoRemap] Request Port: %d\n", rri->request_port);
- fprintf(stderr, "[TSRemapDoRemap] Remap From Port: %d\n", rri->remap_from_port);
- fprintf(stderr, "[TSRemapDoRemap] Remap To Port: %d\n", rri->remap_to_port);
- fprintf(stderr, "[TSRemapDoRemap] Request Path: \"");
- my_print_ascii_string(rri->request_path, rri->request_path_size);
- fprintf(stderr, "\"\n[TSRemapDoRemap] Remap From Path: \"");
- my_print_ascii_string(rri->remap_from_path, rri->remap_from_path_size);
- fprintf(stderr, "\"\n[TSRemapDoRemap] Remap To Path: \"");
- my_print_ascii_string(rri->remap_to_path, rri->remap_to_path_size);
- fprintf(stderr, "\"\n");
+ temp = TSUrlHostGet(rri->requestBufp, rri->requestUrl, &len);
+ fprintf(stderr, "[TSRemapDoRemap] Request Host(%d): \"%.*s\"\n", len, len, temp);
+
+ temp = TSUrlHostGet(rri->requestBufp, rri->mapToUrl, &len);
+ fprintf(stderr, "[TSRemapDoRemap] Remap To Host: \"%.*s\"\n", len, temp);
+
+ temp = TSUrlHostGet(rri->requestBufp, rri->mapFromUrl, &len);
+ fprintf(stderr, "[TSRemapDoRemap] Remap From Host: \"%.*s\"\n", len, temp);
+
+ fprintf(stderr, "[TSRemapDoRemap] Request Port: %d\n", TSUrlPortGet(rri->requestBufp, rri->requestUrl));
+ fprintf(stderr, "[TSRemapDoRemap] Remap From Port: %d\n", TSUrlPortGet(rri->requestBufp, rri->mapFromUrl));
+ fprintf(stderr, "[TSRemapDoRemap] Remap To Port: %d\n", TSUrlPortGet(rri->requestBufp, rri->mapToUrl));
+ temp = TSUrlPathGet(rri->requestBufp, rri->requestUrl, &len);
+ fprintf(stderr, "[TSRemapDoRemap] Request Path: \"%.*s\"\n", len, temp);
+
+ temp = TSUrlPathGet(rri->requestBufp, rri->mapFromUrl, &len);
+ fprintf(stderr, "[TSRemapDoRemap] Remap From Path: \"%.*s\"\n", len, temp);
+
+ temp = TSUrlPathGet(rri->requestBufp, rri->mapToUrl, &len);
+ fprintf(stderr, "[TSRemapDoRemap] Remap To Path: \"%.*s\"\n", len, temp);
// InkAPI usage case
- if (TSHttpTxnClientReqGet((TSHttpTxn) rh, &cbuf, &chdr) == TS_SUCCESS) {
- const char *value;
- if ((cfield = TSMimeHdrFieldFind(cbuf, chdr, TS_MIME_FIELD_DATE, -1)) != TS_NULL_MLOC) {
- fprintf(stderr, "We have \"Date\" header in request\n");
- value = TSMimeHdrFieldValueStringGet(cbuf, chdr, cfield, 0, NULL);
- fprintf(stderr, "Header value: %s\n", value);
- }
- if ((cfield = TSMimeHdrFieldFind(cbuf, chdr, "MyHeader", sizeof("MyHeader") - 1)) != TS_NULL_MLOC) {
- fprintf(stderr, "We have \"MyHeader\" header in request\n");
- value = TSMimeHdrFieldValueStringGet(cbuf, chdr, cfield, 0, NULL);
- fprintf(stderr, "Header value: %s\n", value);
- }
- TSHandleMLocRelease(cbuf, chdr, cfield);
- TSHandleMLocRelease(cbuf, TS_NULL_MLOC, chdr);
+ const char *value;
+
+ if ((cfield = TSMimeHdrFieldFind(rri->requestBufp, rri->requestHdrp, TS_MIME_FIELD_DATE, -1)) != TS_NULL_MLOC) {
+ fprintf(stderr, "We have \"Date\" header in request\n");
+ value = TSMimeHdrFieldValueStringGet(rri->requestBufp, rri->requestHdrp, cfield, 0, NULL);
+ fprintf(stderr, "Header value: %s\n", value);
+ }
+ if ((cfield = TSMimeHdrFieldFind(rri->requestBufp, rri->requestHdrp, "MyHeader", sizeof("MyHeader") - 1)) != TS_NULL_MLOC) {
+ fprintf(stderr, "We have \"MyHeader\" header in request\n");
+ value = TSMimeHdrFieldValueStringGet(rri->requestBufp, rri->requestHdrp, cfield, 0, NULL);
+ fprintf(stderr, "Header value: %s\n", value);
}
+
// How to store plugin private arguments inside Traffic Server request processing block.
if (TSHttpArgIndexReserve("remap_example", "Example remap plugin", &arg_index) == TS_SUCCESS) {
fprintf(stderr, "[TSRemapDoRemap] Save processing counter %lu inside request processing block\n", _processing_counter);
@@ -360,23 +334,32 @@ TSRemapDoRemap(void* ih, TSHttpTxn rh, T
}
// hardcoded case for remapping
// You need to check host and port if you are using the same plugin for multiple remapping rules
- if (rri->request_host_size == 10 &&
- !memcmp("flickr.com", rri->request_host, 10) &&
- rri->request_port == 80 && rri->request_path_size >= 3 && !memcmp("47/", rri->request_path, 3)) {
- rri->new_port = rri->remap_to_port; /* set new port */
+ temp = TSUrlHostGet(rri->requestBufp, rri->requestUrl, &len);
+ temp2 = TSUrlPathGet(rri->requestBufp, rri->requestUrl, &len2);
+ port = TSUrlPortGet(rri->requestBufp, rri->requestUrl);
+
+ if (len == 10 && !memcmp("flickr.com", temp, 10) && port == 80 && len2 >= 3 && !memcmp("47/", temp2, 3)) {
+ char new_path[8192];
+
+ // Ugly, but so is the rest of this "example"
+ if (len2 + 7 >= 8192)
+ return TSREMAP_NO_REMAP;
+
+ if (TSUrlPortSet(rri->requestBufp, rri->mapToUrl, TSUrlPortGet(rri->requestBufp, rri->mapToUrl)) != TS_SUCCESS)
+ return TSREMAP_NO_REMAP;
- strcpy(rri->new_host, "foo.bar.com"); /* set new host name */
- rri->new_host_size = strlen(rri->new_host);
+ if (TSUrlHostSet(rri->requestBufp, rri->requestUrl, "foo.bar.com", 11) != TS_SUCCESS)
+ return TSREMAP_NO_REMAP;
- memcpy(rri->new_path, "47_copy", 7);
- memcpy(&rri->new_path[7], &rri->request_path[2], rri->request_path_size - 2);
- rri->new_path_size = rri->request_path_size + 5;
- rri->new_path[rri->new_path_size] = 0;
+ memcpy(new_path, "47_copy", 7);
+ memcpy(&new_path[7], &temp2[2], len2 - 2);
- retcode = 7; // 0x1 - host, 0x2 - host, 0x4 - path
+ if (TSUrlPathSet(rri->requestBufp, rri->requestUrl, new_path, len2 + 5) == TS_SUCCESS)
+ return TSREMAP_DID_REMAP;
}
- return retcode;
+ // Failure ...
+ return TSREMAP_NO_REMAP;
}
/* ----------------------- TSRemapOSResponse ----------------------------- */
Modified: trafficserver/traffic/trunk/mgmt/RecordsConfig.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/mgmt/RecordsConfig.cc?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/mgmt/RecordsConfig.cc (original)
+++ trafficserver/traffic/trunk/mgmt/RecordsConfig.cc Thu Mar 17 14:00:57 2011
@@ -129,7 +129,7 @@ RecordElement RecordsConfig[] = {
,
{RECT_CONFIG, "proxy.config.accept_threads", RECD_INT, "0", RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-1]", RECA_READ_ONLY}
,
- {RECT_CONFIG, "proxy.config.task_threads", RECD_INT, "0", RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-99999]", RECA_READ_ONLY}
+ {RECT_CONFIG, "proxy.config.task_threads", RECD_INT, "2", RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-99999]", RECA_READ_ONLY}
,
{RECT_CONFIG, "proxy.config.thread.default.stacksize", RECD_INT, "1048576", RECU_RESTART_TS, RR_NULL, RECC_INT, "[131072-104857600]", RECA_READ_ONLY}
,
Modified: trafficserver/traffic/trunk/proxy/ReverseProxy.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ReverseProxy.cc?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ReverseProxy.cc (original)
+++ trafficserver/traffic/trunk/proxy/ReverseProxy.cc Thu Mar 17 14:00:57 2011
@@ -136,11 +136,13 @@ struct UR_UpdateContinuation: public Con
{
NOWARN_UNUSED(etype);
NOWARN_UNUSED(data);
+
reloadUrlRewrite();
delete this;
- return EVENT_DONE;
+ return EVENT_DONE;
}
- UR_UpdateContinuation(ProxyMutex * m):Continuation(m)
+ UR_UpdateContinuation(ProxyMutex * m)
+ : Continuation(m)
{
SET_HANDLER((UR_UpdContHandler) & UR_UpdateContinuation::file_update_handler);
}
@@ -157,10 +159,10 @@ struct UR_FreerContinuation: public Cont
{
NOWARN_UNUSED(event);
NOWARN_UNUSED(e);
- Debug("url_rewrite", "Deleting old table");
+ Debug("url_rewrite", "Deleting old remap.config table");
delete p;
delete this;
- return EVENT_DONE;
+ return EVENT_DONE;
}
UR_FreerContinuation(UrlRewrite * ap):Continuation(new_ProxyMutex()), p(ap)
{
@@ -179,9 +181,10 @@ reloadUrlRewrite()
{
UrlRewrite *newTable;
- Debug("url_rewrite", "remap.config updated, reloading");
- eventProcessor.schedule_in(new UR_FreerContinuation(rewrite_table), URL_REWRITE_TIMEOUT, ET_CACHE);
+ Debug("url_rewrite", "remap.config updated, reloading...");
+ eventProcessor.schedule_in(new UR_FreerContinuation(rewrite_table), URL_REWRITE_TIMEOUT, ET_TASK);
newTable = new UrlRewrite("proxy.config.url_remap.filename");
+ Debug("url_rewrite", "remap.config done reloading!");
ink_atomic_swap_ptr(&rewrite_table, newTable);
}
@@ -196,19 +199,23 @@ url_rewrite_CB(const char *name, RecData
case REVERSE_CHANGED:
rewrite_table->SetReverseFlag(data.rec_int);
break;
+
case TSNAME_CHANGED:
case DEFAULT_TO_PAC_CHANGED:
case DEFAULT_TO_PAC_PORT_CHANGED:
case FILE_CHANGED:
case HTTP_DEFAULT_REDIRECT_CHANGED:
- eventProcessor.schedule_imm(NEW(new UR_UpdateContinuation(reconfig_mutex)), ET_CACHE);
+ eventProcessor.schedule_imm(NEW(new UR_UpdateContinuation(reconfig_mutex)), ET_TASK);
break;
+
case AC_PORT_CHANGED:
// The AutoConf port does not current change on manager except at restart
break;
+
case URL_REMAP_MODE_CHANGED:
// You need to restart TS.
break;
+
default:
ink_assert(0);
break;
Modified: trafficserver/traffic/trunk/proxy/api/ts/remap.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/api/ts/remap.h?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/api/ts/remap.h (original)
+++ trafficserver/traffic/trunk/proxy/api/ts/remap.h Thu Mar 17 14:00:57 2011
@@ -40,80 +40,42 @@ extern "C"
} TSRemapInterface;
-#define TSREMAP_RRI_MAX_HOST_SIZE 256
-#define TSREMAP_RRI_MAX_PATH_SIZE (1024*2)
-#define TSREMAP_RRI_MAX_REDIRECT_URL (1024*2)
-
typedef struct _tm_remap_request_info
{
- /* these URLs mloc's are read only, use normal ts/ts.h APIs for accesing */
+ /* Important: You should *not* release these buf pointers or TSMLocs from your plugin! */
+
+ /* these URL mloc's are read only, use normal ts/ts.h APIs for accesing */
TSMLoc mapFromUrl;
TSMLoc mapToUrl;
+
+ /* the request URL mloc and buffer pointers are read-write. You can read and modify the
+ requestUrl using normal ts/ts.h APIs, which is how you change the destination URL. */
TSMLoc requestUrl;
- /* the following fields are read only */
- int request_port; /* request port number */
- int remap_from_port; /* fromURL port number (from remap rule string) */
- int remap_to_port; /* toURL port number (from remap rule string) */
-
- const char* orig_url; /* request URL */
- int orig_url_size; /* request URL size */
-
- const char* request_host; /* request host string (without '\0' at the end of the string) */
- int request_host_size; /* request host string size */
-
- const char* remap_from_host; /* fromURL host (from remap rule string) */
- int remap_from_host_size; /* fromURL host size */
-
- const char* remap_to_host; /* toURL host (from remap rule string) */
- int remap_to_host_size; /* toURL host size */
-
- const char* request_path; /* request path */
- int request_path_size; /* request path size */
-
- const char* remap_from_path; /* fromURL path (from remap rule string) */
- int remap_from_path_size; /* fromURL path size */
-
- const char* remap_to_path; /* toURL path (from remap rule string) */
- int remap_to_path_size; /* toURL path size */
-
- const char* request_query; /* request query string */
- int request_query_size; /* request query string size. A negative size means remove it completely. */
-
- const char* request_matrix; /* request matrix string */
- int request_matrix_size; /* request matrix string size. A negative size means remove it completely. */
-
- const char* from_scheme; /* The "from" scheme (e.g. HTTP) */
- int from_scheme_len; /* The len of the "from" scheme */
-
- const char* to_scheme; /* The "to" scheme (e.g. HTTP) */
- int to_scheme_len; /* The len of the "to" scheme */
-
- /* plugin can change the following fields */
- char new_host[TSREMAP_RRI_MAX_HOST_SIZE]; /* new host string */
- int new_host_size; /* new host string size (if 0 - do not change request host) */
- int new_port; /* new port number (0 - do not change request port) */
- char new_path[TSREMAP_RRI_MAX_PATH_SIZE]; /* new path string */
- int new_path_size; /* new path string size (0 - do not change request path) */
- char new_query[TSREMAP_RRI_MAX_PATH_SIZE]; /* new query string */
- int new_query_size; /* new query string size (0 - do not change request query) */
- char new_matrix[TSREMAP_RRI_MAX_PATH_SIZE]; /* new matrix parameter string */
- int new_matrix_size; /* new matrix parameter string size (0 - do not change matrix parameters) */
- char redirect_url[TSREMAP_RRI_MAX_REDIRECT_URL]; /* redirect url (to redirect/reject request) */
- int redirect_url_size; /* redirect url size (0 - empty redirect url string) */
- int require_ssl; /* Require the toScheme to become SSL (e.g. HTTPS). */
- /* 0 -> Disable SSL if toScheme is SSL */
- /* 1 -> Enable SSL if toScheme is not SSL */
- /* -1 (default) -> Don't modify scheme */
+ /* requestBufp and requestHdrp are the equivalent of calling TSHttpTxnClientReqGet(). */
+ TSMBuffer requestBufp;
+ TSMLoc requestHdrp;
+
+ /* 0 - don't redirect, 1 - use the (new)request URL as a redirect */
+ int redirect;
} TSRemapRequestInfo;
+
/* This is the type returned by the TSRemapDoRemap() callback */
typedef enum
{
TSREMAP_NO_REMAP = 0, /* No remaping was done, continue with next in chain */
TSREMAP_DID_REMAP = 1, /* Remapping was done, continue with next in chain */
TSREMAP_NO_REMAP_STOP = 2, /* No remapping was done, and stop plugin chain evaluation */
- TSREMAP_DID_REMAP_STOP = 3 /* Remapping was done, but stop plugin chain evaluation */
+ TSREMAP_DID_REMAP_STOP = 3, /* Remapping was done, but stop plugin chain evaluation */
+
+ /* In the future, the following error codes can also be used:
+ -400 to -499
+ -500 to -599
+ ....
+ This would allow a plugin to generate an error page. Right now,
+ setting the return code to any negative number is equivalent to TSREMAP_NO_REMAP */
+ TSREMAP_ERROR = -1 /* Some error, that should generate an error page */
} TSRemapStatus;
Modified: trafficserver/traffic/trunk/proxy/config/records.config.in
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/config/records.config.in?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/config/records.config.in (original)
+++ trafficserver/traffic/trunk/proxy/config/records.config.in Thu Mar 17 14:00:57 2011
@@ -613,7 +613,7 @@ CONFIG proxy.config.dump_mem_info_freque
CONFIG proxy.config.http.slow.log.threshold INT 0
##############################################################################
#
-# Tasks
+# Thread pool for "misc" tasks, plugins etc. 2 is a good minimum.
#
##############################################################################
-CONFIG proxy.config.task_threads INT 1
+CONFIG proxy.config.task_threads INT 2
Modified: trafficserver/traffic/trunk/proxy/http/HttpTransact.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpTransact.cc?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpTransact.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpTransact.cc Thu Mar 17 14:00:57 2011
@@ -8004,9 +8004,8 @@ HttpTransact::build_response(State* s, H
// If the response is prohibited from containing a body,
// we know the content length is trustable for keep-alive
- if (is_response_body_precluded(status_code, s->method)) {
+ if (is_response_body_precluded(status_code, s->method))
s->hdr_info.trust_response_cl = true;
- }
handle_response_keep_alive_headers(s, outgoing_version, outgoing_response);
@@ -8021,9 +8020,8 @@ HttpTransact::build_response(State* s, H
// process reverse mappings on the location header
HTTPStatus outgoing_status = outgoing_response->status_get();
- if ((outgoing_status != 200) && (((outgoing_status >= 300) && (outgoing_status < 400)) || (outgoing_status == 201))) {
+ if ((outgoing_status != 200) && (((outgoing_status >= 300) && (outgoing_status < 400)) || (outgoing_status == 201)))
response_url_remap(outgoing_response);
- }
if (s->http_config_param->enable_http_stats) {
if (s->hdr_info.server_response.valid() && s->http_config_param->wuts_enabled) {
Modified: trafficserver/traffic/trunk/proxy/http/remap/AclFiltering.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/AclFiltering.cc?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/AclFiltering.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/AclFiltering.cc Thu Mar 17 14:00:57 2011
@@ -111,7 +111,7 @@ acl_filter_rule::print(void)
}
acl_filter_rule *
-acl_filter_rule::find_byname(acl_filter_rule * list, const char *_name)
+acl_filter_rule::find_byname(acl_filter_rule *list, const char *_name)
{
int _name_size = 0;
acl_filter_rule *rp = 0;
@@ -125,7 +125,7 @@ acl_filter_rule::find_byname(acl_filter_
}
void
-acl_filter_rule::delete_byname(acl_filter_rule ** rpp, const char *_name)
+acl_filter_rule::delete_byname(acl_filter_rule **rpp, const char *_name)
{
int _name_size = 0;
acl_filter_rule *rp;
@@ -141,7 +141,7 @@ acl_filter_rule::delete_byname(acl_filte
}
void
-acl_filter_rule::requeue_in_active_list(acl_filter_rule ** list, acl_filter_rule * rp)
+acl_filter_rule::requeue_in_active_list(acl_filter_rule **list, acl_filter_rule *rp)
{
if (likely(list && rp)) {
if (rp->active_queue_flag == 0) {
@@ -163,7 +163,7 @@ acl_filter_rule::requeue_in_active_list(
}
void
-acl_filter_rule::requeue_in_passive_list(acl_filter_rule ** list, acl_filter_rule * rp)
+acl_filter_rule::requeue_in_passive_list(acl_filter_rule **list, acl_filter_rule *rp)
{
if (likely(list && rp)) {
if (rp->active_queue_flag) {
Modified: trafficserver/traffic/trunk/proxy/http/remap/AclFiltering.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/AclFiltering.h?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/AclFiltering.h (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/AclFiltering.h Thu Mar 17 14:00:57 2011
@@ -57,7 +57,7 @@ private:
void reset(void);
public:
- acl_filter_rule * next;
+ acl_filter_rule *next;
int filter_name_size; // size of optional filter name
char *filter_name; // optional filter name
unsigned int allow_flag:1, // action allow deny
@@ -83,10 +83,10 @@ public:
int add_argv(int _argc, char *_argv[]);
void print(void);
- static acl_filter_rule *find_byname(acl_filter_rule * list, const char *name);
- static void delete_byname(acl_filter_rule ** list, const char *name);
- static void requeue_in_active_list(acl_filter_rule ** list, acl_filter_rule * rp);
- static void requeue_in_passive_list(acl_filter_rule ** list, acl_filter_rule * rp);
+ static acl_filter_rule *find_byname(acl_filter_rule *list, const char *name);
+ static void delete_byname(acl_filter_rule **list, const char *name);
+ static void requeue_in_active_list(acl_filter_rule **list, acl_filter_rule *rp);
+ static void requeue_in_passive_list(acl_filter_rule **list, acl_filter_rule *rp);
};
#endif
Modified: trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.cc?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.cc Thu Mar 17 14:00:57 2011
@@ -26,32 +26,31 @@
ClassAllocator<RemapPlugins> pluginAllocator("RemapPluginsAlloc");
TSRemapStatus
-RemapPlugins::run_plugin(remap_plugin_info* plugin, char *origURLBuf, int origURLBufSize,
- bool* plugin_modified_host, bool* plugin_modified_port, bool* plugin_modified_path)
+RemapPlugins::run_plugin(remap_plugin_info* plugin)
{
TSRemapStatus plugin_retcode;
- bool do_x_proto_check = true;
TSRemapRequestInfo rri;
- int requestPort = 0;
url_mapping *map = _map_container->getMapping();
URL *map_from = &(map->fromURL);
URL *map_to = _map_container->getToURL();
- // Read-only
- rri.mapFromUrl = reinterpret_cast<TSMLoc>(map_from);
- rri.mapToUrl = reinterpret_cast<TSMLoc>(map_to);
- rri.requestUrl = reinterpret_cast<TSMLoc>(_request_url);
-
- // The "to" part of the RRI struct always stays the same.
- rri.remap_to_host = map_to->host_get(&rri.remap_to_host_size);
- rri.remap_to_port = map_to->port_get();
- rri.remap_to_path = map_to->path_get(&rri.remap_to_path_size);
- rri.to_scheme = map_to->scheme_get(&rri.to_scheme_len);
+ // This is the equivalent of TSHttpTxnClientReqGet(), which every remap plugin would
+ // have to call.
+ rri.requestBufp = reinterpret_cast<TSMBuffer>(_request_header);
+ rri.requestHdrp = reinterpret_cast<TSMLoc>(_request_header->m_http);
+
+ // Read-only URL's (TSMLoc's to the SDK)
+ rri.mapFromUrl = reinterpret_cast<TSMLoc>(map_from->m_url_impl);
+ rri.mapToUrl = reinterpret_cast<TSMLoc>(map_to->m_url_impl);
+ rri.requestUrl = reinterpret_cast<TSMLoc>(_request_url->m_url_impl);
+
+ rri.redirect = 0;
// These are made to reflect the "defaults" that will be used in
// the case where the plugins don't modify them. It's semi-weird
// that the "from" and "to" URLs changes when chaining happens, but
// it is necessary to get predictable behavior.
+#if 0
if (_cur == 0) {
rri.remap_from_host = map_from->host_get(&rri.remap_from_host_size);
rri.remap_from_port = map_from->port_get();
@@ -63,39 +62,10 @@ RemapPlugins::run_plugin(remap_plugin_in
rri.remap_from_path = _request_url->path_get(&rri.remap_from_path_size);
rri.from_scheme = _request_url->scheme_get(&rri.from_scheme_len);
}
-
- // Get request port
- rri.request_port = _request_url->port_get();
-
- // Set request path
- rri.request_path = _request_url->path_get(&rri.request_path_size);
-
- // Get request query
- rri.request_query = _request_url->query_get(&rri.request_query_size);
-
- // Get request matrix parameters
- rri.request_matrix = _request_url->params_get(&rri.request_matrix_size);
-
- rri.orig_url = origURLBuf;
- rri.orig_url_size = origURLBufSize;
-
- rri.require_ssl = -1; // By default, the plugin will not modify the to_scheme
-
- // Used to see if plugin changed anything.
- rri.new_port = 0;
- rri.new_host_size = 0;
- rri.new_path_size = 0;
- rri.redirect_url_size = 0;
- rri.new_query_size = 0;
- rri.new_matrix_size = 0;
-
- // Get request Host
- rri.request_host = _request_url->host_get(&rri.request_host_size);
+#endif
void* ih = map->get_instance(_cur);
- ink_debug_assert(ih);
-
// Prepare State for the future
if (_s && _cur == 0) {
_s->fp_tsremap_os_response = plugin->fp_tsremap_os_response;
@@ -103,90 +73,13 @@ RemapPlugins::run_plugin(remap_plugin_in
}
plugin_retcode = plugin->fp_tsremap_do_remap(ih, _s ? reinterpret_cast<TSHttpTxn>(_s->state_machine) : NULL, &rri);
+ // TODO: Deal with negative return codes here
+ if (plugin_retcode < 0)
+ plugin_retcode = TSREMAP_NO_REMAP;
// First step after plugin remap must be "redirect url" check
- // if ( /*_s->remap_redirect && */ plugin_retcode && rri.redirect_url_size > 0) {
- if ((TSREMAP_DID_REMAP == plugin_retcode || TSREMAP_DID_REMAP_STOP == plugin_retcode) && rri.redirect_url_size > 0) {
- if (rri.redirect_url[0]) {
- _s->remap_redirect = xstrndup(rri.redirect_url, rri.redirect_url_size);
- } else {
- _s->remap_redirect = xstrdup("http://www.apache.org");
- }
- return plugin_retcode;
- }
-
- if (TSREMAP_DID_REMAP == plugin_retcode || TSREMAP_DID_REMAP_STOP == plugin_retcode) {
- // Modify the host
- if (rri.new_host_size > 0) {
- _request_url->host_set(rri.new_host, rri.new_host_size);
- *plugin_modified_host = true;
- }
- // Modify the port, but only if it's different than the request port
- if (rri.new_port != 0) {
- if (requestPort != rri.new_port) {
- _request_url->port_set(rri.new_port);
- }
- *plugin_modified_port = true;
- }
- // Modify the path
- if (rri.new_path_size != 0) {
- if (rri.new_path_size < 0)
- _request_url->path_set(NULL, 0);
- else
- _request_url->path_set(rri.new_path, rri.new_path_size);
- *plugin_modified_path = true;
- }
- // Update the query string. This has a special case, where a negative
- // size value means to remove the query string entirely.
- if (rri.new_query_size != 0) {
- if (rri.new_query_size < 0)
- _request_url->query_set(NULL, 0);
- else
- _request_url->query_set(rri.new_query, rri.new_query_size);
- }
- // Update the matrix parameter string. This has a special case, where a negative
- // size value means to remove the matrix parameter string entirely.
- if (rri.new_matrix_size != 0) {
- if (rri.new_matrix_size < 0)
- _request_url->params_set(NULL, 0);
- else
- _request_url->params_set(rri.new_matrix, rri.new_matrix_size);
- }
- // If require_ssl is set, make sure our toScheme is SSL'ified. It's done this way
- // to avoid dealing with weirness (say, a plugin trying to modify the "toScheme"
- // from FTP to HTTPS).
- if (rri.require_ssl != -1) {
- // TODO add other protocols here if/when necessary
- if (rri.require_ssl == 1) // Plugin wish to turn on SSL (if not already set)
- {
- if ((rri.to_scheme_len == URL_LEN_HTTP) && (rri.to_scheme == URL_SCHEME_HTTP)) {
- _request_url->scheme_set(URL_SCHEME_HTTPS, URL_LEN_HTTPS);
- do_x_proto_check = false;
- Debug("url_rewrite", "Plugin changed protocol from HTTP to HTTPS");
- }
- } else // Plugin wish to turn off SSL (if already set)
- {
- if ((rri.to_scheme_len == URL_LEN_HTTPS) && (rri.to_scheme == URL_SCHEME_HTTPS)) {
- _request_url->scheme_set(URL_SCHEME_HTTP, URL_LEN_HTTP);
- do_x_proto_check = false;
- Debug("url_rewrite", "Plugin changed protocol from HTTPS to HTTP");
- }
- }
- }
- // Check to see if this a cross protocol mapping
- // If so we need to create a new URL since the URL*
- // we get from the request_hdr really points to a subclass
- // of URL that is specific to the protocol
- //
- if (do_x_proto_check && (rri.from_scheme != rri.to_scheme)) {
- _request_url->scheme_set(rri.to_scheme, rri.to_scheme_len);
- if (is_debug_tag_set("url_rewrite")) {
- char tmp_buf[2048];
- Debug("url_rewrite", "Cross protocol mapping to %s in plugin",
- _request_url->string_get_buf(tmp_buf, (int) sizeof(tmp_buf)));
- }
- }
- }
+ if ((TSREMAP_DID_REMAP == plugin_retcode || TSREMAP_DID_REMAP_STOP == plugin_retcode) && rri.redirect)
+ _s->remap_redirect = _request_url->string_get(NULL);
return plugin_retcode;
}
@@ -207,26 +100,14 @@ RemapPlugins::run_single_remap()
Debug("url_rewrite", "Running single remap rule for the %d%s time", _cur, _cur == 1 ? "st" : _cur == 2 ? "nd" : _cur == 3 ? "rd" : "th");
remap_plugin_info *plugin = NULL;
+ TSRemapStatus plugin_retcode = TSREMAP_NO_REMAP;
- bool plugin_modified_host = false;
- bool plugin_modified_port = false;
- bool plugin_modified_path = false;
-
- TSRemapStatus plugin_retcode = TSREMAP_DID_REMAP;
-
- char *origURLBuf = NULL;
- int origURLBufSize;
const char *requestPath;
int requestPathLen;
url_mapping *map = _map_container->getMapping();
URL *map_from = &(map->fromURL);
- int fromPathLen;
URL *map_to = _map_container->getToURL();
- const char *toHost;
- const char *toPath;
- int toPathLen;
- int toHostLen;
int redirect_host_len;
// Debugging vars
@@ -234,104 +115,70 @@ RemapPlugins::run_single_remap()
int retcode = 0; // 0 - no redirect, !=0 - redirected
requestPath = _request_url->path_get(&requestPathLen);
-
- toHost = map_to->host_get(&toHostLen);
- toPath = map_to->path_get(&toPathLen);
-
- // after the first plugin has run, we need to use these in order to "chain" them and previous changes are all in _request_url,
- // in case we need to copy values from previous plugin or from the remap rule.
- if (_cur == 0) {
- map_from->path_get(&fromPathLen);
- } else {
- _request_url->path_get(&fromPathLen);
- }
-
debug_on = is_debug_tag_set("url_rewrite");
if (_request_header)
plugin = map->get_plugin(_cur); //get the nth plugin in our list of plugins
- if (plugin || debug_on) {
- origURLBuf = _request_url->string_get(NULL);
- origURLBufSize = strlen(origURLBuf);
- Debug("url_rewrite", "Original request URL is : %s", origURLBuf);
- }
-
if (plugin) {
Debug("url_rewrite", "Remapping rule id: %d matched; running it now", map->map_id);
- plugin_retcode = run_plugin(plugin, origURLBuf, origURLBufSize, &plugin_modified_host, &plugin_modified_port,
- &plugin_modified_path);
+ plugin_retcode = run_plugin(plugin);
} else if (_cur > 0) {
_cur++;
- Debug("url_rewrite",
- "Called into run_single_remap, but there wasnt a plugin available for us to run. Completing all remap processing immediately");
- if (origURLBuf)
- xfree(origURLBuf);
+ Debug("url_rewrite", "There wasn't a plugin available for us to run. Completing all remap processing immediately");
return 1;
}
- if ((!plugin && _cur == 0) || (TSREMAP_NO_REMAP == plugin_retcode || TSREMAP_NO_REMAP_STOP == plugin_retcode)) {
- // Handle cross protocol mapping when there are no remap plugin(s)
- // or if plugin did not make any modifications.
- Debug("url_rewrite", "no plugins available for this request");
- int to_len, from_len;
- const char *to_scheme = map_to->scheme_get(&to_len);
-
- if (to_scheme != map_from->scheme_get(&from_len)) {
- _request_url->scheme_set(to_scheme, to_len);
- if (is_debug_tag_set("url_rewrite")) {
- char tmp_buf[2048];
- Debug("url_rewrite", "Cross protocol mapping to %s",
- _request_url->string_get_buf(tmp_buf, (int) sizeof(tmp_buf)));
- }
- }
- }
+ if (_s->remap_redirect) //if redirect was set, we need to use that.
+ return 1;
- if (origURLBuf)
- xfree(origURLBuf);
+ // skip the !plugin_modified_* stuff if we are on our 2nd plugin (or greater) and there's no more plugins
+ if (_cur > 0 && (_cur + 1) >= map->_plugin_count)
+ goto done;
- if (_s->remap_redirect) { //if redirect was set, we need to use that.
- return 1;
- }
+ if (TSREMAP_NO_REMAP == plugin_retcode || TSREMAP_NO_REMAP_STOP == plugin_retcode) {
+ if (_cur > 0 ) {
+ //plugin didn't do anything for us, but maybe another will down the chain so lets assume there is something more for us to process
+ ++_cur;
+ Debug("url_rewrite", "Plugin didn't change anything, but we'll try the next one right now");
+ return 0;
+ }
- if (_cur > 0 && !plugin_modified_host && !plugin_modified_port && !plugin_modified_path &&
- (_cur + 1) < map->_plugin_count) {
- _cur++;
- Debug("url_rewrite", "Plugin didn't change anything, but we'll try the next one right now");
- return 0; //plugin didn't do anything for us, but maybe another will down the chain so lets assume there is something more for us to process
- }
+ Debug("url_rewrite", "plugin did not change host, port or path, copying from mapping rule");
+
+ int fromPathLen;
+ const char *toHost;
+ const char *toPath;
+ int toPathLen;
+ int toHostLen;
- if (_cur > 0 && (_cur + 1) >= map->_plugin_count) { //skip the !plugin_modified_* stuff if we are on our 2nd plugin (or greater) and there's no more plugins
- goto done;
- }
+ map_from->path_get(&fromPathLen);
+ toHost = map_to->host_get(&toHostLen);
+ toPath = map_to->path_get(&toPathLen);
- if (!plugin_modified_host && !plugin_modified_port && !plugin_modified_path) {
- Debug("url_rewrite", "plugin did not change host, port or path");
- }
- // Fall back to "remap" maps if plugin didn't change things already
- if (!plugin_modified_host) {
_request_url->host_set(toHost, toHostLen);
- }
- if (!plugin_modified_port) { // Only explicitly set the port if it's not the canonicalized port
int to_port = map_to->port_get_raw();
if (to_port != _request_url->port_get_raw())
_request_url->port_set(to_port);
- }
- // Extra byte is potentially needed for prefix path '/'.
- // Added an extra 3 so that TS wouldn't crash in the field.
- // Allocate a large buffer to avoid problems.
- // Need to figure out why we need the 3 bytes or 512 bytes.
- if (!plugin_modified_path) {
- char newPathTmp[TSREMAP_RRI_MAX_PATH_SIZE];
+ int to_scheme_len, from_scheme_len;
+ const char *to_scheme = map_to->scheme_get(&to_scheme_len);
+
+ if (to_scheme != map_from->scheme_get(&from_scheme_len))
+ _request_url->scheme_set(to_scheme, to_scheme_len);
+
+ // Extra byte is potentially needed for prefix path '/'.
+ // Added an extra 3 so that TS wouldn't crash in the field.
+ // Allocate a large buffer to avoid problems.
+ char newPathTmp[2048];
char *newPath;
char *newPathAlloc = NULL;
- int newPathLen = 0;
- int newPathLenNeed = (requestPathLen - fromPathLen) + toPathLen + 512;
+ unsigned int newPathLen = 0;
+ unsigned int newPathLenNeed = (requestPathLen - fromPathLen) + toPathLen + 8; // 3 + some padding
- if (newPathLenNeed > TSREMAP_RRI_MAX_PATH_SIZE) {
+ if (newPathLenNeed > sizeof(newPathTmp)) {
newPath = (newPathAlloc = (char *) xmalloc(newPathLenNeed));
if (debug_on) {
memset(newPath, 0, newPathLenNeed);
@@ -339,7 +186,7 @@ RemapPlugins::run_single_remap()
} else {
newPath = &newPathTmp[0];
if (debug_on) {
- memset(newPath, 0, TSREMAP_RRI_MAX_PATH_SIZE);
+ memset(newPath, 0, sizeof(newPathTmp));
}
}
@@ -375,7 +222,6 @@ RemapPlugins::run_single_remap()
}
// copy the end of the path past what has been mapped
if ((requestPathLen - fromPathLen) > 0) {
- // strncpy(newPath + newPathLen, requestPath + fromPathLen, requestPathLen - fromPathLen);
memcpy(newPath + newPathLen, requestPath + fromPathLen, requestPathLen - fromPathLen);
newPathLen += (requestPathLen - fromPathLen);
}
@@ -388,8 +234,9 @@ RemapPlugins::run_single_remap()
_request_url->path_set(newPath, newPathLen);
- if (map->homePageRedirect && fromPathLen == requestPathLen && _s->remap_redirect) {
+ if (map->homePageRedirect && fromPathLen == requestPathLen) {
URL redirect_url;
+
redirect_url.create(NULL);
redirect_url.copy(_request_url);
@@ -427,9 +274,8 @@ RemapPlugins::run_single_remap()
done:
if (_cur > MAX_REMAP_PLUGIN_CHAIN) {
- Error("Are you serious?! Called run_single_remap more than 10 times. Stopping this remapping insanity now");
- Debug("url_rewrite",
- "Are you serious?! Called run_single_remap more than 10 times. Stopping this remapping insanity now");
+ Error("Called run_single_remap more than 10 times. Stopping this remapping insanity now");
+ Debug("url_rewrite", "Called run_single_remap more than 10 times. Stopping this remapping insanity now");
return 1;
}
@@ -442,6 +288,7 @@ done:
return 0;
}
+ return 1;
ink_debug_assert(!"not reached");
}
@@ -455,12 +302,9 @@ RemapPlugins::run_remap(int event, Event
int ret = 0;
- //EThread* t = mutex->thread_holding;
-
/* make sure we weren't cancelled */
if (action.cancelled) {
mutex.clear();
- //THREAD_FREE(this, pluginAllocator, t);
pluginAllocator.free(this); //ugly
return EVENT_DONE;
}
@@ -469,12 +313,12 @@ RemapPlugins::run_remap(int event, Event
case EVENT_IMMEDIATE:
Debug("url_rewrite", "handling immediate event inside RemapPlugins::run_remap");
ret = run_single_remap();
- /**
- * If ret !=0 then we are done with this processor and we call back into the SM;
- * otherwise, we call this function again immediately (which really isn't immediate)
- * thru the eventProcessor, thus forcing another run of run_single_remap() which will
- * then operate on _request_url, etc performing additional remaps (mainly another plugin run)
- **/
+ /**
+ * If ret !=0 then we are done with this processor and we call back into the SM;
+ * otherwise, we call this function again immediately (which really isn't immediate)
+ * thru the eventProcessor, thus forcing another run of run_single_remap() which will
+ * then operate on _request_url, etc performing additional remaps (mainly another plugin run)
+ **/
if (ret) {
action.continuation->handleEvent(EVENT_REMAP_COMPLETE, NULL);
mutex.clear();
@@ -495,5 +339,4 @@ RemapPlugins::run_remap(int event, Event
break;
};
return EVENT_DONE;
-
}
Modified: trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.h?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.h (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.h Thu Mar 17 14:00:57 2011
@@ -55,9 +55,9 @@ struct RemapPlugins: public Continuation
void setRequestHeader(HTTPHdr* h) { _request_header = h; }
void setHostHeaderInfo(host_hdr_info* h) { _hh_ptr = h; }
- int run_remap(int, Event *);
+ int run_remap(int event, Event* e);
int run_single_remap();
- TSRemapStatus run_plugin(remap_plugin_info *, char *, int, bool *, bool *, bool *);
+ TSRemapStatus run_plugin(remap_plugin_info* plugin);
Action action;
Modified: trafficserver/traffic/trunk/proxy/http/remap/UrlMapping.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/UrlMapping.cc?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/UrlMapping.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/UrlMapping.cc Thu Mar 17 14:00:57 2011
@@ -64,7 +64,7 @@ url_mapping::get_plugin(unsigned int ind
if ((_plugin_count == 0) || unlikely(index > _plugin_count))
return NULL;
- return _plugin_list[_plugin_count];
+ return _plugin_list[index];
}
/**
Modified: trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc Thu Mar 17 14:00:57 2011
@@ -119,7 +119,7 @@ check_remap_option(char *argv[], int arg
*/
void
-SetHomePageRedirectFlag(url_mapping * new_mapping, URL &new_to_url)
+SetHomePageRedirectFlag(url_mapping *new_mapping, URL &new_to_url)
{
int fromLen, toLen;
const char *from_path = new_mapping->fromURL.path_get(&fromLen);
@@ -360,7 +360,7 @@ validate_filter_args(acl_filter_rule **
static const char *
-parse_directive(BUILD_TABLE_INFO * bti, char *errbuf, int errbufsize)
+parse_directive(BUILD_TABLE_INFO *bti, char *errbuf, int errbufsize)
{
bool flg;
char *directive = NULL;
@@ -395,8 +395,7 @@ parse_directive(BUILD_TABLE_INFO * bti,
flg = ((rp = acl_filter_rule::find_byname(bti->rules_list, (const char *) bti->paramv[1])) == NULL) ? true : false;
// coverity[alloc_arg]
if ((cstr = validate_filter_args(&rp, bti->argv, bti->argc, errbuf, errbufsize)) == NULL && rp) {
- if (flg) // new filter - add to list
- {
+ if (flg) { // new filter - add to list
Debug("url_rewrite", "[parse_directive] new rule \"%s\" was created", bti->paramv[1]);
for (rpp = &bti->rules_list; *rpp; rpp = &((*rpp)->next));
(*rpp = rp)->name(bti->paramv[1]);
@@ -447,7 +446,7 @@ parse_directive(BUILD_TABLE_INFO * bti,
static const char *
-process_filter_opt(url_mapping * mp, BUILD_TABLE_INFO * bti, char *errStrBuf, int errStrBufSize)
+process_filter_opt(url_mapping *mp, BUILD_TABLE_INFO *bti, char *errStrBuf, int errStrBufSize)
{
acl_filter_rule *rp, **rpp;
const char *errStr = NULL;
@@ -623,7 +622,7 @@ UrlRewrite::SetupBackdoorMapping()
/** Deallocated a hash table and all the url_mappings in it. */
void
-UrlRewrite::_destroyTable(InkHashTable * h_table)
+UrlRewrite::_destroyTable(InkHashTable *h_table)
{
InkHashTableEntry *ht_entry;
InkHashTableIteratorState ht_iter;
@@ -678,7 +677,7 @@ UrlRewrite::Print()
/** Debugging method. */
void
-UrlRewrite::PrintTable(InkHashTable * h_table)
+UrlRewrite::PrintTable(InkHashTable *h_table)
{
InkHashTableEntry *ht_entry;
InkHashTableIteratorState ht_iter;
@@ -711,7 +710,7 @@ UrlRewrite::PrintTable(InkHashTable * h_
*/
url_mapping *
-UrlRewrite::_tableLookup(InkHashTable * h_table, URL * request_url,
+UrlRewrite::_tableLookup(InkHashTable *h_table, URL *request_url,
int request_port, char *request_host, int request_host_len)
{
UrlMappingPathIndex *ht_entry;
@@ -850,7 +849,7 @@ UrlRewrite::ReverseMap(HTTPHdr *response
/** Perform fast ACL filtering. */
void
-UrlRewrite::PerformACLFiltering(HttpTransact::State *s, url_mapping * map)
+UrlRewrite::PerformACLFiltering(HttpTransact::State *s, url_mapping *map)
{
if (unlikely(!s || s->acl_filtering_performed || !s->client_connection_enabled))
return;
@@ -1576,7 +1575,7 @@ UrlRewrite::BuildTable()
*/
bool
-UrlRewrite::TableInsert(InkHashTable * h_table, url_mapping * mapping, const char *src_host)
+UrlRewrite::TableInsert(InkHashTable *h_table, url_mapping *mapping, const char *src_host)
{
char src_host_tmp_buf[1];
UrlMappingPathIndex *ht_contents;
@@ -1605,7 +1604,7 @@ UrlRewrite::TableInsert(InkHashTable * h
}
int
-UrlRewrite::load_remap_plugin(char *argv[], int argc, url_mapping * mp, char *errbuf, int errbufsize, int jump_to_argc,
+UrlRewrite::load_remap_plugin(char *argv[], int argc, url_mapping *mp, char *errbuf, int errbufsize, int jump_to_argc,
int *plugin_found_at)
{
TSRemapInterface ri;
@@ -1814,10 +1813,10 @@ UrlRewrite::_mappingLookup(MappingsStore
int request_port, const char *request_host, int request_host_len,
UrlMappingContainer &mapping_container)
{
- char request_host_lower[TSREMAP_RRI_MAX_HOST_SIZE];
+ char request_host_lower[256];
if (!request_host || !request_url ||
- (request_host_len < 0) || (request_host_len >= TSREMAP_RRI_MAX_HOST_SIZE)) {
+ (request_host_len < 0) || (request_host_len >= 256)) {
Debug("url_rewrite", "Invalid arguments!");
return false;
}
@@ -1956,11 +1955,11 @@ UrlRewrite::_regexMappingLookup(RegexMap
mapping_container.set(reg_map.url_map);
- char buf[TSREMAP_RRI_MAX_REDIRECT_URL];
+ char buf[4096];
int buf_len;
// Expand substitutions in the host field from the stored template
- buf_len = _expandSubstitutions(matches_info, reg_map, request_host, buf, TSREMAP_RRI_MAX_REDIRECT_URL);
+ buf_len = _expandSubstitutions(matches_info, reg_map, request_host, buf, sizeof(buf));
URL *expanded_url = mapping_container.createNewToURL();
expanded_url->copy(&((reg_map.url_map)->_default_to_url));
expanded_url->host_set(buf, buf_len);
Modified: trafficserver/traffic/trunk/tools/apichecker.pl
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/tools/apichecker.pl?rev=1082494&r1=1082493&r2=1082494&view=diff
==============================================================================
--- trafficserver/traffic/trunk/tools/apichecker.pl (original)
+++ trafficserver/traffic/trunk/tools/apichecker.pl Thu Mar 17 14:00:57 2011
@@ -106,7 +106,7 @@ my %RENAMED = (
"tsremap_delete_instance" => "TSRemapDeleteInstance",
"tsremap_remap" => "TSRemapDoRemap",
"tsremap_os_response" => "TSRemapOSResponse",
- "rhandle" => "TSHttpTXN",
+ "rhandle" => "TSHttpTxn",
);
my %TWO_2_THREE = (
@@ -262,6 +262,29 @@ my %TWO_2_THREE = (
"tsremap_delete_instance" => [$W_RENAMED],
"tsremap_remap" => [$W_RENAMED, $W_TSREMAPSTATUS],
"tsremap_os_response" => [$W_RENAMED],
+ "orig_url" => [$W_DEPRECATED],
+ "orig_url_size" => [$W_DEPRECATED],
+ "request_port" => [$W_DEPRECATED],
+ "remap_from_port" => [$W_DEPRECATED],
+ "remap_to_port" => [$W_DEPRECATED],
+ "request_host" => [$W_DEPRECATED],
+ "remap_from_host" => [$W_DEPRECATED],
+ "remap_to_host" => [$W_DEPRECATED],
+ "request_path" => [$W_DEPRECATED],
+ "remap_from_path" => [$W_DEPRECATED],
+ "remap_to_path" => [$W_DEPRECATED],
+ "request_cookie" => [$W_DEPRECATED],
+ "request_matrix" => [$W_DEPRECATED],
+ "from_scheme" => [$W_DEPRECATED],
+ "to_scheme" => [$W_DEPRECATED],
+ "request_query" => [$W_DEPRECATED],
+ "new_host" => [$W_DEPRECATED],
+ "new_port" => [$W_DEPRECATED],
+ "new_path" => [$W_DEPRECATED],
+ "new_query" => [$W_DEPRECATED],
+ "new_matrix" => [$W_DEPRECATED],
+ "redirect_url" => [$W_DEPRECATED],
+ "require_ssl" => [$W_DEPRECATED],
);
@@ -272,7 +295,7 @@ sub header_write {
my $do_it = shift;
my $tok = shift;
- print "--> $tok() <--\n" if $do_it;
+ print "--> $tok <--\n" if $do_it;
return 0;
}
@@ -292,19 +315,22 @@ sub two2three {
if ($line =~ /NULL/) {
print " + The length output parameter can not be NULL\n";
$hdr_write = header_write($hdr_write, $tok);
+ $ret = 1;
}
} elsif ($w eq $W_NO_ERROR_PTR) {
$hdr_write = header_write($hdr_write, "TS_ERROR_PTR");
print " + no APIs can return TS_ERROR_PTR, you should not compare it\n";
+ $ret = 1;
} elsif ($w eq $W_RENAMED) {
$hdr_write = header_write($hdr_write, $tok);
print " + is renamed to $RENAMED{$tok}\n";
+ $ret = 1;
} else {
$hdr_write = header_write($hdr_write, $tok);
print " + $w\n";
+ $ret = 1;
}
}
- $ret = 1;
}
return $ret;
@@ -324,7 +350,7 @@ sub process {
}
while (<FILE>) {
- my @tokens = split(/[^a-zA-Z0-9_]/);
+ my @tokens = split(/[^a-zA-Z0-9_\.]/);
if (ink2ts(\@tokens, $_) || two2three(\@tokens, $_)) {
print "$file:$line:$_\n";