Author: zwoop
Date: Tue Oct 12 01:49:15 2010
New Revision: 1021588
URL: http://svn.apache.org/viewvc?rev=1021588&view=rev
Log:
TS-434 UrlRewrite cleanup.
More cleanup, for now, disable an obscure feature to allow
us to clean out UrlRewrite.cc. We should fix this later, using
the new remap processor.
Modified:
trafficserver/traffic/trunk/contrib/perl/AdminClient/lib/Apache/TS/AdminClient.pm
trafficserver/traffic/trunk/proxy/ReverseProxy.cc
trafficserver/traffic/trunk/proxy/http2/remap/RemapProcessor.cc
trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc
trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.h
Modified:
trafficserver/traffic/trunk/contrib/perl/AdminClient/lib/Apache/TS/AdminClient.pm
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/contrib/perl/AdminClient/lib/Apache/TS/AdminClient.pm?rev=1021588&r1=1021587&r2=1021588&view=diff
==============================================================================
---
trafficserver/traffic/trunk/contrib/perl/AdminClient/lib/Apache/TS/AdminClient.pm
(original)
+++
trafficserver/traffic/trunk/contrib/perl/AdminClient/lib/Apache/TS/AdminClient.pm
Tue Oct 12 01:49:15 2010
@@ -713,7 +713,6 @@ The Apache Traffic Server Administration
proxy.config.url_remap.filename
proxy.config.url_remap.pristine_host_hdr
proxy.config.url_remap.remap_required
- proxy.config.url_remap.url_remap_mode
proxy.config.user_name
proxy.config.username.cache.enabled
proxy.config.username.cache.filename
Modified: trafficserver/traffic/trunk/proxy/ReverseProxy.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ReverseProxy.cc?rev=1021588&r1=1021587&r2=1021588&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ReverseProxy.cc (original)
+++ trafficserver/traffic/trunk/proxy/ReverseProxy.cc Tue Oct 12 01:49:15 2010
@@ -90,11 +90,16 @@ init_reverse_proxy()
return 0;
}
+// TODO: This function needs to be rewritten (or replaced) with something that
uses the new
+// Remap Processor properly. Right now, we effectively don't support "remap"
rules on a few
+// odd ball configs, for example if you use the "CONNECT" method, or if you set
+// set proxy.config.url_remap.url_remap_mode to "2" (which is a completely
undocumented "feature").
bool
request_url_remap(HttpTransact::State * s, HTTPHdr * request_header, char
**redirect_url, char **orig_url, char *tag,
unsigned int filter_mask)
{
- return rewrite_table ? rewrite_table->Remap(s, request_header, redirect_url,
orig_url, tag, filter_mask) : false;
+ return false;
+ // return rewrite_table ? rewrite_table->Remap(s, request_header,
redirect_url, orig_url, tag, filter_mask) : false;
}
Modified: trafficserver/traffic/trunk/proxy/http2/remap/RemapProcessor.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/remap/RemapProcessor.cc?rev=1021588&r1=1021587&r2=1021588&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/remap/RemapProcessor.cc (original)
+++ trafficserver/traffic/trunk/proxy/http2/remap/RemapProcessor.cc Tue Oct 12
01:49:15 2010
@@ -56,7 +56,6 @@ RemapProcessor::setup_for_remap(HttpTran
bool proxy_request = false;
s->reverse_proxy = rewrite_table->reverse_proxy;
-
s->url_map.set(s->hdr_info.client_request.m_heap);
ink_assert(redirect_url != NULL);
Modified: trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc?rev=1021588&r1=1021587&r2=1021588&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc (original)
+++ trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc Tue Oct 12
01:49:15 2010
@@ -37,9 +37,6 @@
#include "ink_string.h"
-//
-// Moved from util.cc...
-//
unsigned long
check_remap_option(char *argv[], int argc, unsigned long findmode = 0, int
*_ret_idx = NULL, char **argptr = NULL)
{
@@ -496,7 +493,9 @@ process_filter_opt(url_mapping * mp, BUI
return errStr;
}
-
+//
+// CTOR / DTOR for the UrlRewrite class.
+//
UrlRewrite::UrlRewrite(const char *file_var_in)
: nohost_rules(0), reverse_proxy(0), pristine_host_hdr(0),
backdoor_enabled(0),
mgmt_autoconf_port(0), default_to_pac(0), default_to_pac_port(0),
file_var(NULL), ts_name(NULL),
@@ -759,191 +758,6 @@ UrlRewrite::_tableLookup(InkHashTable *
return um;
}
-/**
- Modifies the requestUrl to reflect the mapping defined by mapPtr. It is
- assumed that mapPtr to points to a mapping that matched the requestURL.
-
-*/
-int
-UrlRewrite::DoRemap(HttpTransact::State * s, HTTPHdr * request_header,
UrlMappingContainer &mapping_container,
- URL * request_url, char **redirect, host_hdr_info * hh_ptr)
-{
- // Plugin trackers.
- remap_plugin_info *plugin = NULL;
- // int plugin_retcode = 0;
- bool plugin_modified_host = false;
- bool plugin_modified_port = false;
- bool plugin_modified_path = false;
-
- char origURLBuf[1024 * 4];
- int origURLBufSize;
-
- const char *requestPath;
- int requestPathLen;
-
- url_mapping *mapPtr = mapping_container.getMapping();
- URL *map_from = &mapPtr->fromURL;
- int fromPathLen;
-
- URL *map_to = mapping_container.getToURL();
- const char *toHost;
- const char *toPath;
- int toPathLen;
- int toHostLen;
-
- int redirect_host_len;
-
- // Debugging vars
- bool debug_on = false;
-
- int retcode = 0; // 0 - no redirect, !=0 - redirected
-
- if (s) { // it is important - we must copy
"no_negative_cache" flag before possible plugin call
- s->no_negative_cache = mapPtr->no_negative_cache;
- s->pristine_host_hdr = mapPtr->pristine_host_hdr;
- s->remap_chunking_enabled = mapPtr->chunking_enabled;
- }
-
- requestPath = request_url->path_get(&requestPathLen);
- map_from->path_get(&fromPathLen);
-
- toHost = map_to->host_get(&toHostLen);
- toPath = map_to->path_get(&toPathLen);
-
- if (redirect)
- *redirect = NULL;
-
- if (is_debug_tag_set("url_rewrite"))
- debug_on = true;
-
- Debug("url_rewrite", "Remapping rule id: %d matched", mapPtr->map_id);
-
- if (request_header)
- plugin = mapPtr->get_plugin(0);
-
- if (plugin || debug_on)
- request_url->string_get_buf(origURLBuf, sizeof(origURLBuf),
&origURLBufSize);
-
- // 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)
- request_url->port_set(map_to->port_get_raw());
-
- // 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];
- char *newPath;
- char *newPathAlloc = NULL;
- int newPathLen = 0;
- int newPathLenNeed = (requestPathLen - fromPathLen) + toPathLen + 512;
-
- if (newPathLenNeed > TSREMAP_RRI_MAX_PATH_SIZE) {
- newPath = (newPathAlloc = (char *) xmalloc(newPathLenNeed));
- if (debug_on)
- memset(newPath, 0, newPathLenNeed);
- } else {
- newPath = &newPathTmp[0];
- if (debug_on)
- memset(newPath, 0, TSREMAP_RRI_MAX_PATH_SIZE);
- }
-
- *newPath = 0;
-
- // Purify load run with QT in a reverse proxy indicated
- // a UMR/ABR/MSE in the line where we do a *newPath == '/' and the strncpy
- // that follows it. The problem occurs if
- // requestPathLen,fromPathLen,toPathLen are all 0; in this case, we never
- // initialize newPath, but still de-ref it in *newPath == '/' comparison.
- // The memset fixes that problem.
-
- if (toPath) {
- memcpy(newPath, toPath, toPathLen);
- newPathLen += toPathLen;
- }
- // We might need to insert a trailing slash in the new portion of the path
- // if more will be added and none is present and one will be needed.
- if (!fromPathLen && requestPathLen && toPathLen && *(newPath + newPathLen
- 1) != '/') {
- *(newPath + newPathLen) = '/';
- newPathLen++;
- }
-
- if (requestPath) {
- //avoid adding another trailing slash if the requestPath already had one
and so does the toPath
- if (requestPathLen < fromPathLen) {
- if (toPathLen && requestPath[requestPathLen - 1] == '/' &&
toPath[toPathLen - 1] == '/') {
- fromPathLen++;
- }
- } else {
- if (toPathLen && requestPath[fromPathLen] == '/' && toPath[toPathLen -
1] == '/') {
- fromPathLen++;
- }
- }
- // 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);
- }
- }
- // We need to remove the leading slash in newPath if one is
- // present.
- if (*newPath == '/') {
- memmove(newPath, newPath + 1, --newPathLen);
- }
-
- request_url->path_set(newPath, newPathLen);
-
- if (mapPtr->homePageRedirect && fromPathLen == requestPathLen && redirect)
{
- URL redirect_url;
- redirect_url.create(NULL);
- redirect_url.copy(request_url);
-
- ink_assert(fromPathLen > 0);
-
- // Extra byte for trailing '/' in redirect
- if (newPathLen > 0 && newPath[newPathLen - 1] != '/') {
- newPath[newPathLen] = '/';
- newPath[++newPathLen] = '\0';
- redirect_url.path_set(newPath, newPathLen);
- }
- // If we have host header information,
- // put it back into redirect URL
- //
- if (hh_ptr != NULL) {
- redirect_url.host_set(hh_ptr->request_host, hh_ptr->host_len);
- if (redirect_url.port_get() != hh_ptr->request_port)
- redirect_url.port_set(hh_ptr->request_port);
- }
- // If request came in without a host, send back
- // the redirect with the name the proxy is known by
- if (redirect_url.host_get(&redirect_host_len) == NULL)
- redirect_url.host_set(ts_name, strlen(ts_name));
-
- if ((*redirect = redirect_url.string_get(NULL)) != NULL)
- retcode = strlen(*redirect);
-
- if (debug_on)
- Debug("url_rewrite", "Redirected %s to %.*s", origURLBuf, retcode,
*redirect);
-
- redirect_url.destroy();
- } else {
- if (debug_on)
- Debug("url_rewrite", "Remapped %s to %.*s via remap.config",
origURLBuf, newPathLen, newPath);
- }
-
-
- if (unlikely(newPathAlloc))
- xfree(newPathAlloc);
- }
-
- return retcode;
-}
-
/** Perform fast ACL filtering. */
void
@@ -997,434 +811,6 @@ UrlRewrite::PerformACLFiltering(HttpTran
}
}
-
-bool
-UrlRewrite::Remap(HttpTransact::State * s, HTTPHdr * request_header,
- char **redirect_url, char **orig_url, char *tag, unsigned
int filter_mask)
-{
- URL *request_url = NULL;
- bool mapping_found;
-
- // Vars for building a new host header
- //
- // Host buf length is a static buffer
- // size is MAXDNAME (max hostname length) + 12 for
- // port length, one for the ':' and one
- // for the string terminator
- //
- const int host_buf_len = MAXDNAME + 12 + 1 + 1;
- char host_hdr_buf[host_buf_len], tmp_referer_buf[4096],
tmp_redirect_buf[4096], tmp_buf[2048], *c;
- const char *remapped_host, *request_url_host;
- int remapped_host_len, request_url_host_len, remapped_port, tmp;
- int from_len;
- bool remap_found = false;
- bool proxy_request = false;
- host_hdr_info *hh_ptr = NULL;
- host_hdr_info hh_info;
- referer_info *ri;
-
- ink_assert(redirect_url != NULL);
-
- if (unlikely(num_rules_forward == 0)) {
- ink_assert(forward_mappings.empty());
- return false;
- }
-
- Debug("url_rewrite", "Starting ::Remap()");
-
- // Since are called before request validity checking
- // occurs, make sure that we have both a valid request
- // header and a valid URL
- //
- if (unlikely(!request_header || (request_url = request_header->url_get()) ==
NULL || !request_url->valid())) {
- return false;
- }
-
- request_url_host = request_url->host_get(&request_url_host_len);
- if (request_url_host_len > 0 || reverse_proxy == 0) { // Proxy request. Use
the information from the URL on the
- // request line. (Note: we prefer the information in
- // the request URL since some user-agents send broken
- // host headers.)
- proxy_request = true;
- mapping_found = forwardMappingLookup(request_url, request_url->port_get(),
request_url_host,
- request_url_host_len, s->url_map,
tag);
- } else { // Server request. Use the host header to
figure out where
- // it goes
- int host_len, host_hdr_len;
- const char *host_hdr = request_header->value_get(MIME_FIELD_HOST,
MIME_LEN_HOST, &host_hdr_len);
- if (!host_hdr) {
- host_hdr = "";
- host_hdr_len = 0;
- }
- char *tmpc = (char *) memchr(host_hdr, ':', host_hdr_len);
- int request_port;
-
- if (tmpc == NULL) {
- host_len = host_hdr_len;
- // Get the default port from URL structure
- request_port = request_url->port_get();
- } else {
- host_len = tmpc - host_hdr;
- request_port = ink_atoi(tmpc + 1, host_hdr_len - host_len);
-
- // If atoi fails, try the default for the
- // protocol
- if (request_port == 0) {
- request_port = request_url->port_get();
- }
- }
-
- mapping_found = forwardMappingLookup(request_url, request_port, host_hdr,
host_len, s->url_map, tag);
-
- // Save this information for passing to DoRemap
- hh_info.host_len = host_len;
- hh_info.request_host = host_hdr;
- hh_info.request_port = request_port;
- hh_ptr = &hh_info;
-
- // If no rules match, check empty host rules since
- // they function as default rules for server requests
- if (!mapping_found && nohost_rules && *host_hdr != '\0') {
- mapping_found = forwardMappingLookup(request_url, 0, "", 0, s->url_map,
tag);
- }
- }
-
- if (mapping_found) { // Make a copy of the original URL. It is
up to the callee to free this [which is t_state->unmapped_request_url freed
inside HttpTransact::State::destroy()]
- if (orig_url) { // We need to insert the host so that we have
an accurate URL
- if (proxy_request == false) {
- request_url->host_set(hh_info.request_host, hh_info.host_len);
-
- // Only set the port if we need to so default ports
- // do show up in URLs
- if (request_url->port_get() != hh_info.request_port) {
- request_url->port_set(hh_info.request_port);
- }
- }
- *orig_url = request_url->string_get_ref(NULL);
- }
- // Perform the actual URL rewrite
- if (unlikely(DoRemap(s, request_header, s->url_map, request_url,
redirect_url, hh_ptr) &&
- *redirect_url != NULL)) {
- return false; // There is a redirect, return now
- }
- // Do fast ACL filtering (it is safe to check map here)
- url_mapping *map = s->url_map.getMapping();
- PerformACLFiltering(s, map);
-
- //printf("****************** PerformACLFiltering = %s
************\n",s->client_connection_enabled ? "ENABLED" : "DISABLED");
-
- // vl: Check referer filtering rules
- if ((filter_mask & URL_REMAP_FILTER_REFERER) != 0 && (ri =
map->referer_list) != 0) {
- const char *referer_hdr = 0;
- int referer_len = 0;
- bool enabled_flag = map->optional_referer ? true : false;
-
- if (request_header->presence(MIME_PRESENCE_REFERER) &&
- (referer_hdr = request_header->value_get(MIME_FIELD_REFERER,
MIME_LEN_REFERER, &referer_len)) != NULL) {
- if (referer_len >= (int) sizeof(tmp_referer_buf))
- referer_len = (int) (sizeof(tmp_referer_buf) - 1);
- memcpy(tmp_referer_buf, referer_hdr, referer_len);
- tmp_referer_buf[referer_len] = 0;
- for (enabled_flag = false; ri; ri = ri->next) {
- if (ri->any) {
- enabled_flag = true;
- if (!map->negative_referer)
- break;
- } else if (ri->regx_valid && (pcre_exec(ri->regx, NULL,
tmp_referer_buf, referer_len, 0, 0, NULL, 0) != -1)) {
- enabled_flag = ri->negative ? false : true;
- break;
- }
- }
- }
-
- if (!enabled_flag) {
- if (!map->default_redirect_url) {
- if ((filter_mask & URL_REMAP_FILTER_REDIRECT_FMT) != 0 &&
map->redir_chunk_list) {
- redirect_tag_str *rc;
-
- tmp_redirect_buf[(tmp = 0)] = 0;
- for (rc = map->redir_chunk_list; rc; rc = rc->next) {
- c = 0;
- switch (rc->type) {
- case 's':
- c = rc->chunk_str;
- break;
- case 'r':
- c = (referer_len && referer_hdr) ? &tmp_referer_buf[0] : 0;
- break;
- case 'f':
- case 't':
- remapped_host =
- (rc->type == 'f') ? map->fromURL.string_get_buf(tmp_buf,
(int) sizeof(tmp_buf),
- &from_len) :
((s->url_map).getToURL())->string_get_buf(tmp_buf, (int)
-
sizeof
-
(tmp_buf),
-
&from_len);
- if (remapped_host && from_len > 0)
- c = &tmp_buf[0];
- break;
- case 'o':
- c = *orig_url;
- break;
- };
- if (c && tmp < (int) (sizeof(tmp_redirect_buf) - 1)) {
- tmp += snprintf(&tmp_redirect_buf[tmp],
sizeof(tmp_redirect_buf) - tmp, "%s", c);
- }
- }
- tmp_redirect_buf[sizeof(tmp_redirect_buf) - 1] = 0;
- *redirect_url = xstrdup(tmp_redirect_buf);
- }
- } else
- *redirect_url = xstrdup(http_default_redirect_url);
-
- if (*redirect_url == NULL) {
- *redirect_url = xstrdup(map->filter_redirect_url ?
map->filter_redirect_url : http_default_redirect_url);
- }
-
- return false;
- }
- }
-
- remap_found = true;
-
- // We also need to rewrite the "Host:" header if it exists and
- // pristine host hdr is not enabled
- int host_len;
- const char *host_hdr = request_header->value_get(MIME_FIELD_HOST,
- MIME_LEN_HOST, &host_len);
-
- if (host_hdr != NULL &&
- ((pristine_host_hdr <= 0 && s->pristine_host_hdr <= 0) ||
- (pristine_host_hdr > 0 && s->pristine_host_hdr == 0))) {
- remapped_host = request_url->host_get(&remapped_host_len);
- remapped_port = request_url->port_get_raw();
-
- // Debug code to print out old host header. This was easier before
- // the header conversion. Now we have to copy to gain null
- // termination for the Debug() call
- if (is_debug_tag_set("url_rewrite")) {
- int old_host_hdr_len;
- char *old_host_hdr = (char *)
request_header->value_get(MIME_FIELD_HOST,
- MIME_LEN_HOST,
-
&old_host_hdr_len);
-
- if (old_host_hdr) {
- old_host_hdr = xstrndup(old_host_hdr, old_host_hdr_len);
- Debug("url_rewrite", "Host Header before rewrite %s", old_host_hdr);
- xfree(old_host_hdr);
- }
- }
- //
- // Create the new host header field being careful that our
- // temporary buffer has adequate length
- //
- if (host_buf_len > remapped_host_len) {
- tmp = remapped_host_len;
- memcpy(host_hdr_buf, remapped_host, remapped_host_len);
- if (remapped_port) {
- tmp += snprintf(host_hdr_buf + remapped_host_len, host_buf_len -
remapped_host_len - 1,
- ":%d", remapped_port);
- }
- } else {
- tmp = host_buf_len;
- }
-
- // It is possible that the hostname is too long. If it is punt,
- // and remove the host header. If it is too long the HostDB
- // won't be able to resolve it and the request will not go
- // through
- if (tmp >= host_buf_len) {
- request_header->field_delete(MIME_FIELD_HOST, MIME_LEN_HOST);
- Debug("url_rewrite", "Host Header too long after rewrite");
- } else {
- Debug("url_rewrite", "Host Header after rewrite %s", host_hdr_buf);
- request_header->value_set(MIME_FIELD_HOST, MIME_LEN_HOST,
host_hdr_buf, tmp);
- }
- }
- }
-
- return remap_found;
-}
-
-/**
- Determines if a redirect is to occur and if so, figures out what the
- redirect is. This was plaguiarized from UrlRewrite::Remap. redirect_url
- ought to point to the new, mapped URL when the function exists.
-
-*/
-mapping_type UrlRewrite::Remap_redirect(HTTPHdr * request_header, char
**redirect_url, char **orig_url, char *tag)
-{
- URL *
- request_url;
- mapping_type
- mappingType;
- const char *
- host = NULL;
- char
- tmp_buf[2048];
- int
- host_len = 0, request_port = 0;
- bool
- prt,
- trt; // existence of permanent and temporary
redirect tables, respectively
-
- // Host header for DoRemap
- host_hdr_info *
- hh_ptr = NULL;
- host_hdr_info
- hh_info;
-
- ink_assert(redirect_url != NULL);
-
- if (redirect_url == NULL) {
- Debug("url_rewrite", "redirect_url is invalid. UrlRewrite::Remap_redirect
bailing out.");
- return NONE;
- }
-
- *redirect_url = NULL;
-
- prt = (num_rules_redirect_permanent != 0);
- trt = (num_rules_redirect_temporary != 0);
-
- if (prt + trt == 0)
- return NONE;
-
- // Since are called before request validity checking
- // occurs, make sure that we have both a valid request
- // header and a valid URL
- //
- if (request_header == NULL) {
- Debug("url_rewrite", "request_header was invalid.
UrlRewrite::Remap_redirect bailing out.");
- return NONE;
- }
- request_url = request_header->url_get();
- if (!request_url->valid()) {
- Debug("url_rewrite", "request_url was invalid. UrlRewrite::Remap_redirect
bailing out.");
- return NONE;
- }
-
- if (is_debug_tag_set("url_rewrite")) {
- request_url->string_get_buf(tmp_buf, (int) sizeof(tmp_buf));
- Debug("url_rewrite", "%s request in remap_redirect", tmp_buf);
- }
- // You can find information about forward rules, etc. in the remap.config
file
- // Debug("url_rewrite", "Forward Rules: #%d", num_rules_forward);
- // Debug("url_rewrite", "Reverse Rules: #%d", num_rules_reverse);
- // Debug("url_rewrite", "Permanent Redirect Rules: #%d",
num_rules_redirect_permanent);
- // Debug("url_rewrite", "Temporary Redirect Rules: #%d",
num_rules_redirect_temporary);
-
- host = request_url->host_get(&host_len);
- request_port = request_url->port_get();
-
- if (host_len == 0 && reverse_proxy != 0) { // Server request. Use the
host header to figure out where
- // it goes. Host header parsing is same as in ::Remap
- int
- host_hdr_len;
- const char *
- host_hdr = request_header->value_get(MIME_FIELD_HOST, MIME_LEN_HOST,
&host_hdr_len);
-
- if (!host_hdr) {
- host_hdr = "";
- host_hdr_len = 0;
- }
-
- const char *
- tmp = (const char *) memchr(host_hdr, ':', host_hdr_len);
-
- if (tmp == NULL) {
- host_len = host_hdr_len;
- } else {
- host_len = tmp - host_hdr;
- request_port = ink_atoi(tmp + 1, host_hdr_len - host_len);
-
- // If atoi fails, try the default for the
- // protocol
- if (request_port == 0) {
- request_port = request_url->port_get();
- }
- }
-
- host = host_hdr;
-
- memset(&hh_info, 0, sizeof(hh_info));
- // Save this information for passing to DoRemap
- hh_info.host_len = host_len;
- hh_info.request_host = host_hdr;
- hh_info.request_port = request_port;
- hh_ptr = &hh_info;
- }
- // Temporary Redirects have precedence over Permanent Redirects
- // the rationale behind this is that network administrators might
- // want quick redirects and not want to worry about all the existing
- // permanent rules
- mappingType = NONE;
- UrlMappingContainer redirect_mapping(request_header->m_heap);
- if (trt) {
- if (temporaryRedirectLookup(request_url, request_port, host, host_len,
redirect_mapping, tag)) {
- mappingType = TEMPORARY_REDIRECT;
- }
- }
- if ((mappingType == NONE) && prt) {
- if (permanentRedirectLookup(request_url, request_port, host, host_len,
redirect_mapping, tag)) {
- mappingType = PERMANENT_REDIRECT;
- }
- }
-
- if (mappingType != NONE) {
- *orig_url = NULL;
-
- // Make a copy of the request url so that we can munge it
- // for the redirect
- URL
- rurl;
- rurl.create(NULL);
- rurl.copy(request_url);
-
- // Perform the actual URL rewrite
- if (!DoRemap(NULL, NULL, redirect_mapping, &rurl, redirect_url, hh_ptr)) {
- *redirect_url = rurl.string_get(NULL);
- } else { // vl: Do nothing because of "redirect_url"
was created inside DoRemap!
- // There is potential memory leack was here (in the original version)
- /* nope */ ;
- }
- rurl.destroy();
-
- ink_assert((mappingType == PERMANENT_REDIRECT) || (mappingType ==
TEMPORARY_REDIRECT));
- Debug("url_rewrite", "New URL: %s", *redirect_url);
- return mappingType;
- }
- ink_assert(mappingType == NONE);
- return NONE;
-}
-
-/**
- Takes off any trailing slashes on the path of a URL. We need to this in
- order to normalize our URLs for reverse proxy.
-
-*/
-void
-UrlRewrite::RemoveTrailingSlash(URL * url)
-{
- ink_assert(url != NULL);
- Debug("url_rewrite", "Removing trailing slash!");
- int path_length;
- const char *orig_path = url->path_get(&path_length);
- char *new_path;
-
- if (orig_path != NULL) {
- if (path_length > 0 && orig_path[path_length - 1] == '/') {
- if (path_length == 1) {
- url->path_set("", 0);
- } else {
- new_path = xstrndup(orig_path, path_length);
- new_path[path_length - 1] = '\0';
- url->path_set(new_path, path_length - 1);
- xfree(new_path);
- }
- }
- }
-}
-
/**
Returns the length of the URL.
@@ -1797,13 +1183,6 @@ UrlRewrite::BuildTable()
// been removed.
- /*
- commenting these out
- */
- // RemoveTrailingSlash(&new_mapping->toURL);
- // RemoveTrailingSlash(&new_mapping->fromURL);
-
-
if (unlikely(fromHostLen >= (int) sizeof(fromHost_lower_buf))) {
if (unlikely((fromHost_lower = (fromHost_lower_ptr = (char *)
xmalloc(fromHostLen + 1))) == NULL)) {
fromHost_lower = &fromHost_lower_buf[0];
@@ -2132,7 +1511,7 @@ UrlRewrite::load_remap_plugin(char *argv
int *plugin_found_at)
{
*plugin_found_at = 0;
- const char *plugin_default_path = "/home/trafficserver/libexec/yts/";
+ const char *plugin_default_path = "/usr/local/libexec/trafficserver/";
TSREMAP_INTERFACE ri;
struct stat stat_buf;
remap_plugin_info *pi;
@@ -2482,12 +1861,11 @@ UrlRewrite::_regexMappingLookup(RegexMap
mapping_container.set(reg_map.url_map);
- char buf[MAX_URL_STR_SIZE];
+ char buf[TSREMAP_RRI_MAX_REDIRECT_URL];
int buf_len;
// Expand substitutions in the host field from the stored template
- buf_len = _expandSubstitutions(matches_info, reg_map, request_host,
- buf, MAX_URL_STR_SIZE);
+ buf_len = _expandSubstitutions(matches_info, reg_map, request_host, buf,
TSREMAP_RRI_MAX_REDIRECT_URL);
URL *expanded_url = mapping_container.createNewToURL();
expanded_url->copy(&((reg_map.url_map)->_default_to_url));
expanded_url->host_set(buf, buf_len);
@@ -2512,6 +1890,7 @@ void
UrlRewrite::_destroyList(RegexMappingList &mappings)
{
RegexMappingList::iterator list_iter;
+
for (list_iter = mappings.begin(); list_iter != mappings.end(); ++list_iter)
{
RegexMapping ®_map = *list_iter; // handy reference
delete reg_map.url_map;
Modified: trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.h
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.h?rev=1021588&r1=1021587&r2=1021588&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.h (original)
+++ trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.h Tue Oct 12
01:49:15 2010
@@ -73,9 +73,6 @@ public:
UrlRewrite(const char *file_var_in);
~UrlRewrite();
int BuildTable();
- bool Remap(HttpTransact::State * s, HTTPHdr * request_header, char
**redirect_url, char **orig_url,
- char *tag = NULL, unsigned int filter_mask =
URL_REMAP_FILTER_NONE);
- mapping_type Remap_redirect(HTTPHdr * request_header, char **redirect_url,
char **orig_url, char *tag = NULL);
void SetReverseFlag(int flag);
void SetPristineFlag(int flag);
void Print();
@@ -111,10 +108,7 @@ public:
{
InkHashTable *hash_lookup;
RegexMappingList regex_list;
- bool empty()
- {
- return ((hash_lookup == NULL) && (regex_list.size() == 0));
- }
+ bool empty() { return ((hash_lookup == NULL) && (regex_list.size() == 0));
}
};
void PerformACLFiltering(HttpTransact::State * s, url_mapping * mapping);
@@ -157,12 +151,9 @@ public:
return _mappingLookup(temporary_redirects, request_url, request_port,
request_host, request_host_len,
mapping_container, tag);
}
- int DoRemap(HttpTransact::State * s, HTTPHdr * request_header,
UrlMappingContainer &mapping_container,
- URL * request_url, char **redirect = NULL, host_hdr_info *
hh_ptr = NULL);
+
int UrlWhack(char *toWhack, int *origLength);
- void RemoveTrailingSlash(URL * url);
- // Moved this from util, since we need to associate the remap_plugin_info
list with the url rewrite map.
int load_remap_plugin(char *argv[], int argc, url_mapping * mp, char
*errbuf, int errbufsize, int jump_to_argc,
int *plugin_found_at);
@@ -188,24 +179,20 @@ public:
remap_plugin_info *remap_pi_list;
private:
- bool _mappingLookup(MappingsStore &mappings, URL *request_url,
- int request_port, const char *request_host, int
request_host_len,
- UrlMappingContainer &mapping_container, char *tag);
- url_mapping *_tableLookup(InkHashTable * h_table, URL * request_url,
- int request_port, char *request_host, int
request_host_len, char *tag);
- bool _regexMappingLookup(RegexMappingList ®ex_mappings,
- URL * request_url, int request_port, const char
*request_host,
+ bool _mappingLookup(MappingsStore &mappings, URL *request_url, int
request_port, const char *request_host,
+ int request_host_len, UrlMappingContainer
&mapping_container, char *tag);
+ url_mapping *_tableLookup(InkHashTable * h_table, URL * request_url, int
request_port, char *request_host,
+ int request_host_len, char *tag);
+ bool _regexMappingLookup(RegexMappingList ®ex_mappings, URL *
request_url, int request_port, const char *request_host,
int request_host_len, char *tag, int rank_ceiling,
UrlMappingContainer &mapping_container);
- int _expandSubstitutions(int *matches_info, const RegexMapping ®_map,
- const char *matched_string, char *dest_buf, int
dest_buf_size);
+ int _expandSubstitutions(int *matches_info, const RegexMapping ®_map,
const char *matched_string, char *dest_buf,
+ int dest_buf_size);
bool _processRegexMappingConfig(const char *from_host_lower, url_mapping
*new_mapping, RegexMapping ®_map);
void _destroyTable(InkHashTable *h_table);
void _destroyList(RegexMappingList ®exes);
- inline bool _addToStore(MappingsStore &store, url_mapping *new_mapping,
RegexMapping ®_map,
- char *src_host, bool is_cur_mapping_regex, int
&count);
-
- static const int MAX_URL_STR_SIZE = 1024;
+ inline bool _addToStore(MappingsStore &store, url_mapping *new_mapping,
RegexMapping ®_map, char *src_host,
+ bool is_cur_mapping_regex, int &count);
};
#endif