Author: manjesh
Date: Wed Jun  2 23:27:50 2010
New Revision: 950820

URL: http://svn.apache.org/viewvc?rev=950820&view=rev
Log:
TS-384: creating transaction specific 'to URL' in case of regex remap match

Full list of changes:
1) Added UrlMappingContainer to control access to 'toURL' of url mappings
2) Regex remap code creates new toURL on rule match and sets in container
3) Removed some unnecessary (no code breaks) code to reduce maintainance 
overhead

Modified:
    trafficserver/traffic/trunk/proxy/http2/HttpTransact.h
    trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.cc
    trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.h
    trafficserver/traffic/trunk/proxy/http2/remap/RemapProcessor.cc
    trafficserver/traffic/trunk/proxy/http2/remap/UrlMapping.cc
    trafficserver/traffic/trunk/proxy/http2/remap/UrlMapping.h
    trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc
    trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.h

Modified: trafficserver/traffic/trunk/proxy/http2/HttpTransact.h
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/HttpTransact.h?rev=950820&r1=950819&r2=950820&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/HttpTransact.h (original)
+++ trafficserver/traffic/trunk/proxy/http2/HttpTransact.h Wed Jun  2 23:27:50 
2010
@@ -41,6 +41,7 @@
 //#include "HttpAuthParams.h"
 #include "api/ts/remap.h"
 #include "RemapPluginInfo.h"
+#include "UrlMapping.h"
 
 
 #ifdef USE_NCA
@@ -1072,7 +1073,7 @@ public:
                                 /**
                                 * Remap plugin processor support
                                **/
-    url_mapping *url_map;
+    UrlMappingContainer url_map;
     host_hdr_info hh_info;
 
     //
@@ -1389,7 +1390,7 @@ api_lock_url(LOCK_URL_FIRST),
 saved_update_next_action(STATE_MACHINE_ACTION_UNDEFINED),
 saved_update_cache_action(CACHE_DO_UNDEFINED),
 stale_icp_lookup(false),
-url_map(NULL),
+url_map(),
 pCongestionEntry(NULL),
 congest_saved_next_action(STATE_MACHINE_ACTION_UNDEFINED),
 congestion_control_crat(0),
@@ -1516,6 +1517,7 @@ HttpTransact::State::destroy()
     cache_resp_hdr_heap_handle->m_sdk_alloc.free_all();
   }
 
+  url_map.clear();
   arena.reset();
 
   return;

Modified: trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.cc?rev=950820&r1=950819&r2=950820&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.cc (original)
+++ trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.cc Wed Jun  2 
23:27:50 2010
@@ -36,9 +36,9 @@ RemapPlugins::~RemapPlugins()
 }
 
 void
-RemapPlugins::setMap(url_mapping * m)
+RemapPlugins::setMap(UrlMappingContainer * m)
 {
-  _map = m;
+  _map_container = m;
 }
 
 void
@@ -75,10 +75,11 @@ RemapPlugins::run_plugin(remap_plugin_in
   const char *requestPath;
   int requestPathLen;
   int requestPort = 0;
-  URL *map_from = &_map->fromURL;
+  url_mapping *map = _map_container->getMapping();
+  URL *map_from = &(map->fromURL);
   const char *fromPath;
   int fromPathLen;
-  URL *map_to = &_map->toURL;
+  URL *map_to = _map_container->getToURL();
 
   const char *toHost;
   const char *toPath;
@@ -165,7 +166,7 @@ RemapPlugins::run_plugin(remap_plugin_in
     rri.request_cookie_size = 0;
   }
 
-  ihandle *ih = _map->get_instance(plugin);
+  ihandle *ih = map->get_instance(plugin);
 
   ink_debug_assert(ih);
 
@@ -291,10 +292,11 @@ RemapPlugins::run_single_remap()
   const char *requestPath;
   int requestPathLen;
   int requestPort;
-  URL *map_from = &_map->fromURL;
+  url_mapping *map = _map_container->getMapping();
+  URL *map_from = &(map->fromURL);
   const char *fromPath;
   int fromPathLen;
-  URL *map_to = &_map->toURL;
+  URL *map_to = _map_container->getToURL();
 
   const char *fromHost;
   int fromHostLen;
@@ -311,9 +313,9 @@ RemapPlugins::run_single_remap()
   int retcode = 0;              // 0 - no redirect, !=0 - redirected
 
   if (_cur == 0 && _s) {        // it is important - we must copy 
"no_negative_cache" flag before possible plugin call [only do this on our first 
iteration of this function]
-    _s->no_negative_cache = _map->no_negative_cache;
-    _s->pristine_host_hdr = _map->pristine_host_hdr;
-    _s->remap_chunking_enabled = _map->chunking_enabled;
+    _s->no_negative_cache = map->no_negative_cache;
+    _s->pristine_host_hdr = map->pristine_host_hdr;
+    _s->remap_chunking_enabled = map->chunking_enabled;
   }
 
   requestPath = _request_url->path_get(&requestPathLen);
@@ -345,7 +347,7 @@ RemapPlugins::run_single_remap()
     debug_on = true;
 
   if (_request_header)
-    plugin = _map->get_plugin(_cur);    //get the nth plugin in our list of 
plugins
+    plugin = map->get_plugin(_cur);    //get the nth plugin in our list of 
plugins
 
   if (plugin || debug_on) {
     origURLBuf = _request_url->string_get(NULL);
@@ -354,7 +356,7 @@ RemapPlugins::run_single_remap()
   }
 
   if (plugin) {
-    Debug("url_rewrite", "Remapping rule id: %d matched; running it now", 
_map->map_id);
+    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);
@@ -392,13 +394,13 @@ RemapPlugins::run_single_remap()
   }
 
   if (_cur > 0 && !plugin_modified_host && !plugin_modified_port && 
!plugin_modified_path &&
-      (_cur + 1) < _map->_plugin_count) {
+      (_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
   }
 
-  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
+  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;
   }
 
@@ -482,7 +484,7 @@ RemapPlugins::run_single_remap()
 
     _request_url->path_set(newPath, newPathLen);
 
-    if (_map->homePageRedirect && fromPathLen == requestPathLen && 
_s->remap_redirect) {
+    if (map->homePageRedirect && fromPathLen == requestPathLen && 
_s->remap_redirect) {
       URL redirect_url;
       redirect_url.create(NULL);
       redirect_url.copy(_request_url);
@@ -537,7 +539,7 @@ done:
 
   _cur++;                       //important
 
-  if (_cur >= _map->_plugin_count) {
+  if (_cur >= map->_plugin_count) {
     //normally, we would callback into this function but we dont have anything 
more to do!
     Debug("url_rewrite", "we exhausted all available plugins");
     return 1;

Modified: trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.h
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.h?rev=950820&r1=950819&r2=950820&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.h (original)
+++ trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.h Wed Jun  2 
23:27:50 2010
@@ -42,7 +42,7 @@
 struct RemapPlugins:Continuation
 {
   unsigned int _cur;
-  url_mapping *_map;
+  UrlMappingContainer *_map_container;
   URL *_request_url;
   HTTPHdr *_request_header;
     HttpTransact::State * _s;
@@ -53,7 +53,7 @@ struct RemapPlugins:Continuation
 
   int run_remap(int, Event *);
   int run_single_remap();
-  void setMap(url_mapping *);
+  void setMap(UrlMappingContainer *);
   void setRequestUrl(URL *);
   void setRequestHeader(HTTPHdr *);
   int run_plugin(remap_plugin_info *, char *, int, bool *, bool *, bool *);

Modified: trafficserver/traffic/trunk/proxy/http2/remap/RemapProcessor.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/remap/RemapProcessor.cc?rev=950820&r1=950819&r2=950820&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/remap/RemapProcessor.cc (original)
+++ trafficserver/traffic/trunk/proxy/http2/remap/RemapProcessor.cc Wed Jun  2 
23:27:50 2010
@@ -45,7 +45,7 @@ RemapProcessor::setup_for_remap(HttpTran
 {
   Debug("url_rewrite", "setting up for remap: %x", s);
   URL *request_url = NULL;
-  url_mapping *map = NULL;
+  bool mapping_found = false;
   HTTPHdr *request_header = &s->hdr_info.client_request;
   char **redirect_url = &s->remap_redirect;
   char **orig_url = &s->unmapped_request_url;
@@ -56,6 +56,8 @@ RemapProcessor::setup_for_remap(HttpTran
 
   s->reverse_proxy = rewrite_table->reverse_proxy;
 
+  s->url_map.set(s->hdr_info.client_request.m_heap);
+
   ink_assert(redirect_url != NULL);
 
   if (unlikely(rewrite_table->num_rules_forward == 0)) {
@@ -78,9 +80,9 @@ RemapProcessor::setup_for_remap(HttpTran
     //  the request URL since some user-agents send broken
     //  host headers.)
     proxy_request = true;
-    map =
+    mapping_found =
       rewrite_table->forwardMappingLookup(request_url, 
request_url->port_get(), request_url_host,
-                                          request_url_host_len, tag);
+                                          request_url_host_len, s->url_map, 
tag);
   } else {
     // Server request.  Use the host header to figure out where
     // it goes
@@ -109,7 +111,8 @@ RemapProcessor::setup_for_remap(HttpTran
     }
 
     Debug("url_rewrite", "[lookup] attempting normal lookup");
-    map = rewrite_table->forwardMappingLookup(request_url, request_port, 
host_hdr, host_len, tag);
+    mapping_found = rewrite_table->forwardMappingLookup(request_url, 
request_port, host_hdr, host_len,
+                                                        s->url_map, tag);
 
     // Save this information for later
     s->hh_info.host_len = host_len;
@@ -118,12 +121,12 @@ RemapProcessor::setup_for_remap(HttpTran
 
     // If no rules match, check empty host rules since
     //   they function as default rules for server requests
-    if (map == NULL && rewrite_table->nohost_rules && *host_hdr != '\0') {
+    if (!mapping_found && rewrite_table->nohost_rules && *host_hdr != '\0') {
       Debug("url_rewrite", "[lookup] nothing matched");
-      map = rewrite_table->forwardMappingLookup(request_url, 0, "", 0, tag);
+      mapping_found = rewrite_table->forwardMappingLookup(request_url, 0, "", 
0, s->url_map, tag);
     }
 
-    if (map && orig_url) {
+    if (mapping_found && orig_url) {
       // We need to insert the host so that we have an accurate URL
       if (proxy_request == false) {
         request_url->host_set(s->hh_info.request_host, s->hh_info.host_len);
@@ -144,13 +147,11 @@ RemapProcessor::setup_for_remap(HttpTran
     // }
   }
 
-  if (!map) {
-    Debug("url_rewrite", "RemapProcessor::setup_for_remap had map as NULL");
+  if (!mapping_found) {
+    Debug("url_rewrite", "RemapProcessor::setup_for_remap did not find a 
mapping");
   }
 
-  s->url_map = map;
-
-  return (map != NULL);
+  return mapping_found;
 }
 
 bool
@@ -169,7 +170,7 @@ RemapProcessor::finish_remap(HttpTransac
   bool remap_found = false;
   referer_info *ri;
 
-  map = s->url_map;
+  map = s->url_map.getMapping();
   if (!map) {
     return false;
   }
@@ -218,7 +219,7 @@ RemapProcessor::finish_remap(HttpTransac
             case 't':
               remapped_host =
                 (rc->type == 'f') ? map->fromURL.string_get_buf(tmp_buf, (int) 
sizeof(tmp_buf),
-                                                                &from_len) : 
map->toURL.string_get_buf(tmp_buf, (int)
+                                                                &from_len) : 
((s->url_map).getToURL())->string_get_buf(tmp_buf, (int)
                                                                                
                        sizeof(tmp_buf),
                                                                                
                        &from_len);
               if (remapped_host && from_len > 0) {
@@ -312,7 +313,7 @@ RemapProcessor::perform_remap(Continuati
   Debug("url_rewrite", "Beginning RemapProcessor::perform_remap");
   HTTPHdr *request_header = &s->hdr_info.client_request;
   URL *request_url = request_header->url_get();
-  url_mapping *map = s->url_map;
+  url_mapping *map = s->url_map.getMapping();
   host_hdr_info *hh_info = &(s->hh_info);
 
   if (!map) {
@@ -328,7 +329,7 @@ RemapProcessor::perform_remap(Continuati
 
   RemapPlugins *plugins = pluginAllocator.alloc();
 
-  plugins->setMap(map);
+  plugins->setMap(&(s->url_map));
   plugins->setRequestUrl(request_url);
   plugins->setRequestHeader(request_header);
   plugins->setState(s);

Modified: trafficserver/traffic/trunk/proxy/http2/remap/UrlMapping.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/remap/UrlMapping.cc?rev=950820&r1=950819&r2=950820&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/remap/UrlMapping.cc (original)
+++ trafficserver/traffic/trunk/proxy/http2/remap/UrlMapping.cc Wed Jun  2 
23:27:50 2010
@@ -27,10 +27,10 @@
  *
 **/
 url_mapping::url_mapping(int rank /* = 0 */)
-  : from_path_len(0), fromURL(), toURL(), homePageRedirect(false), 
unique(false), default_redirect_url(false),
+  : from_path_len(0), fromURL(), homePageRedirect(false), unique(false), 
default_redirect_url(false),
     optional_referer(false), negative_referer(false), 
no_negative_cache(false), wildcard_from_scheme(false),
     pristine_host_hdr(-1), chunking_enabled(-1), tag(NULL), 
filter_redirect_url(NULL), referer_list(0),
-    redir_chunk_list(0), filter(NULL), _plugin_count(0), 
_cur_instance_count(0), _rank(rank)
+    redir_chunk_list(0), filter(NULL), _plugin_count(0), 
_cur_instance_count(0), _rank(rank), _default_to_url()
 { /* nop */ ;
 }
 
@@ -176,68 +176,9 @@ url_mapping::~url_mapping()
 
   // Destroy the URLs
   fromURL.destroy();
-  toURL.destroy();
+  _default_to_url.destroy();
 }
 
-
-/**
- *
-**/
-url_mapping_ext::url_mapping_ext(url_mapping * mapping)
-:m_mapping(mapping)
-{
-}
-
-
-/**
- *
-**/
-url_mapping_ext::~url_mapping_ext()
-{
-  // free nothing -- there is a reference in the hash table
-}
-
-
-/**
- *
-**/
-const char *
-url_mapping_ext::getToHost(int *lenp)
-{
-  return m_mapping ? (const char *) m_mapping->toURL.host_get(lenp) : NULL;
-}
-
-
-/**
- *
-**/
-const char *
-url_mapping_ext::getToPath(int *lenp)
-{
-  return m_mapping ? m_mapping->toURL.path_get(lenp) : NULL;
-}
-
-
-/**
- *
-**/
-URL *
-url_mapping_ext::getFromURL()
-{
-  return m_mapping ? &m_mapping->fromURL : NULL;
-}
-
-
-/**
- *
-**/
-URL *
-url_mapping_ext::getToURL()
-{
-  return m_mapping ? &m_mapping->toURL : NULL;
-}
-
-
 /**
  *
 **/

Modified: trafficserver/traffic/trunk/proxy/http2/remap/UrlMapping.h
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/remap/UrlMapping.h?rev=950820&r1=950819&r2=950820&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/remap/UrlMapping.h (original)
+++ trafficserver/traffic/trunk/proxy/http2/remap/UrlMapping.h Wed Jun  2 
23:27:50 2010
@@ -31,7 +31,6 @@
 #include "Error.h"
 #include "URL.h"
 #include "RemapPluginInfo.h"
-#include "HttpTransact.h"
 
 #ifdef HAVE_PCRE_PCRE_H
 #include <pcre/pcre.h>
@@ -82,22 +81,6 @@ public:
 };
 
 /**
- *
-**/
-class url_mapping_ext
-{
-public:
-  url_mapping_ext(url_mapping *);
-  virtual ~ url_mapping_ext();
-  const char *getToHost(int *lenp = NULL);
-  const char *getToPath(int *lenp = NULL);
-  URL *getFromURL();
-  URL *getToURL();
-private:
-    url_mapping * m_mapping;
-};
-
-/**
  * Used to store the mapping for class UrlRewrite
 **/
 class url_mapping
@@ -115,7 +98,6 @@ public:
 
   int from_path_len;
   URL fromURL;
-  URL toURL;
   bool homePageRedirect;
   bool unique;                  // INKqa11970 - unique mapping
   bool default_redirect_url;
@@ -141,7 +123,71 @@ private:
     std::map<remap_plugin_info *, ihandle *>_instance_map;
   int _cur_instance_count;
   int _rank;
+  URL _default_to_url;
+
+  friend class UrlRewrite;
+  friend class UrlMappingContainer;
 };
 
 
+class UrlMappingContainer {
+
+public:
+
+  UrlMappingContainer() : _mapping(NULL), _toURLPtr(NULL), _heap(NULL) { };
+
+  UrlMappingContainer(url_mapping *m) : _heap(NULL) { set(m); };
+
+  UrlMappingContainer(HdrHeap *heap) : _mapping(NULL), _toURLPtr(NULL), 
_heap(heap) { };
+  
+  URL *getToURL() const { return _toURLPtr; };
+
+  url_mapping *getMapping() const { return _mapping; };
+
+  void set(url_mapping *m) { 
+    deleteToURL();
+    _mapping = m;
+    _toURLPtr = m ? &(m->_default_to_url) : NULL;
+  }
+
+  void set(HdrHeap *heap) {
+    _heap = heap;
+  }
+
+  URL *createNewToURL() {
+    ink_assert(_heap != NULL);
+    deleteToURL();
+    _toURL.create(_heap);
+    _toURLPtr = &_toURL;
+    return _toURLPtr; 
+  }
+
+  void deleteToURL() {
+    if (_toURLPtr == &_toURL) {
+      _toURL.clear();
+    }
+  }
+
+  void clear() {
+    deleteToURL();
+    _mapping = NULL;
+    _toURLPtr = NULL;
+    _heap = NULL;
+  }
+
+  ~UrlMappingContainer() { deleteToURL(); };
+
+private:
+
+  url_mapping *_mapping;
+  URL *_toURLPtr;
+  URL _toURL;
+  HdrHeap *_heap;
+  
+  // non-copyable, non-assignable
+  UrlMappingContainer(const UrlMappingContainer &orig);
+  UrlMappingContainer &operator =(const UrlMappingContainer &rhs);
+
+};
+
 #endif

Modified: trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc?rev=950820&r1=950819&r2=950820&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc (original)
+++ trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc Wed Jun  2 
23:27:50 2010
@@ -142,11 +142,11 @@ check_remap_option(char *argv[], int arg
 
 */
 void
-SetHomePageRedirectFlag(url_mapping * new_mapping)
+SetHomePageRedirectFlag(url_mapping * new_mapping, URL &new_to_url)
 {
   int fromLen, toLen;
   const char *from_path = new_mapping->fromURL.path_get(&fromLen);
-  const char *to_path = new_mapping->toURL.path_get(&toLen);
+  const char *to_path = new_to_url.path_get(&toLen);
 
   new_mapping->homePageRedirect = (from_path && !to_path) ? true : false;
 }
@@ -620,12 +620,12 @@ UrlRewrite::SetupPacMapping()
   mapping->fromURL.parse(from_url, strlen(from_url));
 
   state = error = 0;
-  mapping->toURL.create(NULL);
-  mapping->toURL.parse(local_url, strlen(local_url));
+  mapping->_default_to_url.create(NULL);
+  mapping->_default_to_url.parse(local_url, strlen(local_url));
 
   pac_generator_port = (default_to_pac_port < 0) ? mgmt_autoconf_port : 
default_to_pac_port;
 
-  mapping->toURL.port_set(pac_generator_port);
+  mapping->_default_to_url.port_set(pac_generator_port);
 
   return mapping;
 }
@@ -650,8 +650,8 @@ UrlRewrite::SetupBackdoorMapping()
   mapping->fromURL.parse(from_url, sizeof(from_url) - 1);
   mapping->fromURL.scheme_set(URL_SCHEME_HTTP, URL_LEN_HTTP);
 
-  mapping->toURL.create(NULL);
-  mapping->toURL.parse(to_url, sizeof(to_url) - 1);
+  mapping->_default_to_url.create(NULL);
+  mapping->_default_to_url.parse(to_url, sizeof(to_url) - 1);
 
   return mapping;
 }
@@ -729,7 +729,7 @@ UrlRewrite::PrintTable(InkHashTable * h_
          mapping_iter != mappings.end(); ++mapping_iter) {
       um = *mapping_iter;
       um->fromURL.string_get_buf(from_url_buf, (int) sizeof(from_url_buf));
-      um->toURL.string_get_buf(to_url_buf, (int) sizeof(to_url_buf));
+      um->_default_to_url.string_get_buf(to_url_buf, (int) sizeof(to_url_buf));
       printf("\t %s %s=> %s %s <%s> [plugins %s enabled; running with %d 
plugins]\n", from_url_buf,
              um->unique ? "(unique)" : "", to_url_buf,
              um->homePageRedirect ? "(R)" : "", um->tag ? um->tag : "",
@@ -768,8 +768,8 @@ UrlRewrite::_tableLookup(InkHashTable * 
 
 */
 int
-UrlRewrite::DoRemap(HttpTransact::State * s, HTTPHdr * request_header, 
url_mapping * mapPtr, URL * request_url,
-                    char **redirect, host_hdr_info * hh_ptr)
+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;
@@ -785,11 +785,12 @@ UrlRewrite::DoRemap(HttpTransact::State 
   int requestPathLen;
   int requestPort;
 
+  url_mapping *mapPtr = mapping_container.getMapping();
   URL *map_from = &mapPtr->fromURL;
   const char *fromPath;
   int fromPathLen;
 
-  URL *map_to = &mapPtr->toURL;
+  URL *map_to = mapping_container.getToURL();
   const char *toHost;
   const char *toPath;
   int toPathLen;
@@ -967,8 +968,6 @@ bool UrlRewrite::ReverseMap(HTTPHdr * re
   int
     host_len;
 
-  url_mapping *
-    map;
   char *
     new_loc_hdr;
   int
@@ -990,15 +989,15 @@ bool UrlRewrite::ReverseMap(HTTPHdr * re
   location_url.parse(location_hdr, loc_length);
 
   host = location_url.host_get(&host_len);
-  map = reverseMappingLookup(&location_url, location_url.port_get(), host, 
host_len, tag);
-
-  if (map != NULL) {            /* HDR FIX ME
+  UrlMappingContainer reverse_mapping(response_header->m_heap);
+  if (reverseMappingLookup(&location_url, location_url.port_get(), host, 
host_len, reverse_mapping, tag)) {
+                                /* HDR FIX ME
                                    Debug("url_rewrite", "Location header 
before rewrite: %s",
                                    
response_header->value_get(MIME_FIELD_LOCATION));
                                  */
 
     remap_found = true;
-    DoRemap(NULL, NULL, map, &location_url);
+    DoRemap(NULL, NULL, reverse_mapping, &location_url);
 
     new_loc_hdr = location_url.string_get(NULL, &new_loc_length);
     response_header->value_set(MIME_FIELD_LOCATION, MIME_LEN_LOCATION, 
new_loc_hdr, new_loc_length);
@@ -1072,7 +1071,7 @@ bool
                     char **redirect_url, char **orig_url, char *tag, unsigned 
int filter_mask)
 {
   URL *request_url = NULL;
-  url_mapping *map = NULL;
+  bool mapping_found;
 
   // Vars for building a new host header
   //
@@ -1112,7 +1111,8 @@ bool
     //  the request URL since some user-agents send broken
     //  host headers.)
     proxy_request = true;
-    map = forwardMappingLookup(request_url, request_url->port_get(), 
request_url_host, request_url_host_len, tag);
+    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;
@@ -1139,7 +1139,7 @@ bool
       }
     }
 
-    map = forwardMappingLookup(request_url, request_port, host_hdr, host_len, 
tag);
+    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;
@@ -1149,12 +1149,12 @@ bool
 
     // If no rules match, check empty host rules since
     //   they function as default rules for server requests
-    if (map == NULL && nohost_rules && *host_hdr != '\0') {
-      map = forwardMappingLookup(request_url, 0, "", 0, tag);
+    if (!mapping_found && nohost_rules && *host_hdr != '\0') {
+      mapping_found = forwardMappingLookup(request_url, 0, "", 0, s->url_map, 
tag);
     }
   }
 
-  if (map) {                    // 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 (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);
@@ -1168,10 +1168,12 @@ bool
       *orig_url = request_url->string_get_ref(NULL);
     }
     // Perform the actual URL rewrite
-    if (unlikely(DoRemap(s, request_header, map, request_url, redirect_url, 
hh_ptr) && *redirect_url != NULL)) {
+    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");
@@ -1219,7 +1221,7 @@ bool
               case 't':
                 remapped_host =
                   (rc->type == 'f') ? map->fromURL.string_get_buf(tmp_buf, 
(int) sizeof(tmp_buf),
-                                                                  &from_len) : 
map->toURL.string_get_buf(tmp_buf, (int)
+                                                                  &from_len) : 
((s->url_map).getToURL())->string_get_buf(tmp_buf, (int)
                                                                                
                          sizeof
                                                                                
                          (tmp_buf),
                                                                                
                          &from_len);
@@ -1319,10 +1321,8 @@ mapping_type UrlRewrite::Remap_redirect(
 {
   URL *
     request_url;
-  url_mapping *
-    permanent_redirect = NULL, *temporary_redirect = NULL, *map = NULL;
   mapping_type
-    mappingType = NONE;
+    mappingType;
   const char *
     host = NULL;
   char
@@ -1422,21 +1422,20 @@ mapping_type UrlRewrite::Remap_redirect(
   // the rationale behind this is that network administrators might
   // want quick redirects and not want to worry about all the existing
   // permanent rules
-  if (prt) {
-    permanent_redirect = permanentRedirectLookup(request_url, request_port, 
host, host_len, tag);
-  }
+  mappingType = NONE;
+  UrlMappingContainer redirect_mapping(request_header->m_heap);
   if (trt) {
-    temporary_redirect = temporaryRedirectLookup(request_url, request_port, 
host, host_len, tag);
+    if (temporaryRedirectLookup(request_url, request_port, host, host_len, 
redirect_mapping, tag)) {
+      mappingType = TEMPORARY_REDIRECT;
+    }
   }
-  if (temporary_redirect != NULL) {
-    mappingType = TEMPORARY_REDIRECT;
-    map = temporary_redirect;
-  } else if (permanent_redirect != NULL) {
-    mappingType = PERMANENT_REDIRECT;
-    map = permanent_redirect;
+  if ((mappingType == NONE) && prt) {
+    if (permanentRedirectLookup(request_url, request_port, host, host_len, 
redirect_mapping, tag)) {
+      mappingType = PERMANENT_REDIRECT;
+    }
   }
 
-  if (map != NULL) {
+  if (mappingType != NONE) {
     *orig_url = NULL;
 
     // Make a copy of the request url so that we can munge it
@@ -1447,7 +1446,7 @@ mapping_type UrlRewrite::Remap_redirect(
     rurl.copy(request_url);
 
     // Perform the actual URL rewrite
-    if (!DoRemap(NULL, NULL, map, &rurl, redirect_url, hh_ptr)) {
+    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)
@@ -1757,8 +1756,8 @@ UrlRewrite::BuildTable()
     map_to_start = map_to;
     tmp = map_to;
 
-    new_mapping->toURL.create(NULL);
-    rparse = new_mapping->toURL.parse_no_path_component_breakdown(tmp, length);
+    new_mapping->_default_to_url.create(NULL);
+    rparse = 
new_mapping->_default_to_url.parse_no_path_component_breakdown(tmp, length);
     map_to_start[origLength] = '\0';    // Unwhack
 
     if (rparse != PARSE_DONE) {
@@ -1774,7 +1773,7 @@ UrlRewrite::BuildTable()
       fromScheme = new_mapping->fromURL.scheme_get(&fromSchemeLen);
       new_mapping->wildcard_from_scheme = true;
     }
-    toScheme = new_mapping->toURL.scheme_get(&toSchemeLen);
+    toScheme = new_mapping->_default_to_url.scheme_get(&toSchemeLen);
 
     // Include support for HTTPS scheme
     // includes support for FILE scheme
@@ -1851,7 +1850,7 @@ UrlRewrite::BuildTable()
       }
     }
 
-    toHost = new_mapping->toURL.host_get(&toHostLen);
+    toHost = new_mapping->_default_to_url.host_get(&toHostLen);
     if (toHost == NULL || toHostLen <= 0) {
       errStr = "The remap destinations require a hostname";
       goto MAP_ERROR;
@@ -1906,7 +1905,8 @@ UrlRewrite::BuildTable()
     case FORWARD_MAP_REFERER:
       if ((add_result = _addToStore(forward_mappings, new_mapping, reg_map, 
fromHost_lower,
                                     is_cur_mapping_regex, num_rules_forward)) 
== true) {
-        SetHomePageRedirectFlag(new_mapping);   // @todo: is this applicable 
to regex mapping too?
+        // @todo: is this applicable to regex mapping too?
+        SetHomePageRedirectFlag(new_mapping, new_mapping->_default_to_url);
       }
       break;
     case REVERSE_MAP:
@@ -1961,15 +1961,15 @@ UrlRewrite::BuildTable()
             u_mapping->fromURL.create(NULL);
             u_mapping->fromURL.copy(&new_mapping->fromURL);
             u_mapping->fromURL.host_set(ipv4_name, strlen(ipv4_name));
-            u_mapping->toURL.create(NULL);
-            u_mapping->toURL.copy(&new_mapping->toURL);
+            u_mapping->_default_to_url.create(NULL);
+            u_mapping->_default_to_url.copy(&new_mapping->_default_to_url);
             if (bti.paramv[3] != NULL)
               u_mapping->tag = xstrdup(&(bti.paramv[3][0]));
             if (!TableInsert(forward_mappings.hash_lookup, u_mapping, 
ipv4_name)) {
               goto MAP_WARNING;
             }
             num_rules_forward++;
-            SetHomePageRedirectFlag(u_mapping);
+            SetHomePageRedirectFlag(u_mapping, u_mapping->_default_to_url);
           }
         }
       }
@@ -2003,15 +2003,15 @@ UrlRewrite::BuildTable()
             u_mapping->fromURL.create(NULL);
             u_mapping->fromURL.copy(&new_mapping->fromURL);
             u_mapping->fromURL.host_set(ipv4_name, strlen(ipv4_name));
-            u_mapping->toURL.create(NULL);
-            u_mapping->toURL.copy(&new_mapping->toURL);
+            u_mapping->_default_to_url.create(NULL);
+            u_mapping->_default_to_url.copy(&new_mapping->_default_to_url);
             if (bti.paramv[3] != NULL)
               u_mapping->tag = xstrdup(&(bti.paramv[3][0]));
             if (!TableInsert(forward_mappings.hash_lookup, u_mapping, 
ipv4_name)) {
               goto MAP_WARNING;
             }
             num_rules_forward++;
-            SetHomePageRedirectFlag(u_mapping);
+            SetHomePageRedirectFlag(u_mapping, u_mapping->_default_to_url);
           }
         }
       }
@@ -2037,9 +2037,9 @@ UrlRewrite::BuildTable()
             u_mapping = NEW(new url_mapping);
             u_mapping->fromURL.create(NULL);
             u_mapping->fromURL.copy(&new_mapping->fromURL);
-            u_mapping->toURL.create(NULL);
-            u_mapping->toURL.copy(&new_mapping->toURL);
-            u_mapping->toURL.host_set(ipv4_name, strlen(ipv4_name));
+            u_mapping->_default_to_url.create(NULL);
+            u_mapping->_default_to_url.copy(&new_mapping->_default_to_url);
+            u_mapping->_default_to_url.host_set(ipv4_name, strlen(ipv4_name));
             if (bti.paramv[3] != NULL)
               u_mapping->tag = xstrdup(&(bti.paramv[3][0]));
             if (!TableInsert(reverse_mappings.hash_lookup, u_mapping, 
fromHost_lower)) {
@@ -2195,35 +2195,6 @@ UrlRewrite::TableInsert(InkHashTable * h
   return true;
 }
 
-url_mapping_ext *
-UrlRewrite::forwardTableLookupExt(URL * request_url, int request_port, char 
*request_host, int host_len,
-                                  char *tag)
-{
-  if (forward_mappings.hash_lookup) {
-    url_mapping *m = _tableLookup(forward_mappings.hash_lookup, request_url, 
request_port,
-                                  request_host, host_len, tag);
-
-    return NEW(new url_mapping_ext(m));
-  }
-  return NULL;
-}
-
-
-url_mapping_ext *
-UrlRewrite::reverseTableLookupExt(URL * request_url, int request_port, char 
*request_host, int host_len,
-                                  char *tag)
-{
-  if (reverse_mappings.hash_lookup) {
-    url_mapping *m = _tableLookup(reverse_mappings.hash_lookup, request_url, 
request_port,
-                                  request_host, host_len, tag);
-
-    return NEW(new url_mapping_ext(m));
-  }
-  return NULL;
-}
-
-
-
 int
 UrlRewrite::load_remap_plugin(char *argv[], int argc, url_mapping * mp, char 
*errbuf, int errbufsize, int jump_to_argc,
                               int *plugin_found_at)
@@ -2359,7 +2330,7 @@ UrlRewrite::load_remap_plugin(char *argv
   parv[parc++] = xstrdup(err);
   xfree(err);
 
-  if ((err = mp->toURL.string_get(NULL)) == NULL) {
+  if ((err = mp->_default_to_url.string_get(NULL)) == NULL) {
     snprintf(errbuf, errbufsize, "Can't load toURL from URL class");
     return -6;
   }
@@ -2431,16 +2402,17 @@ UrlRewrite::load_remap_plugin(char *argv
 
      Returns highest-ranked mapping on success, NULL on failure
 */
-url_mapping *
+bool
 UrlRewrite::_mappingLookup(MappingsStore &mappings, URL *request_url,
-                           int request_port, const char *request_host, int 
request_host_len, char *tag)
+                           int request_port, const char *request_host, int 
request_host_len,
+                           UrlMappingContainer &mapping_container, char *tag)
 {
   char request_host_lower[TSREMAP_RRI_MAX_HOST_SIZE];
 
   if (!request_host || !request_url ||
       (request_host_len < 0) || (request_host_len >= 
TSREMAP_RRI_MAX_HOST_SIZE)) {
     Debug("url_rewrite", "Invalid arguments!");
-    return NULL;
+    return false;
   }
 
   // lowercase
@@ -2449,20 +2421,22 @@ UrlRewrite::_mappingLookup(MappingsStore
   }
   request_host_lower[request_host_len] = 0;
 
+  bool retval = false;
   int rank_ceiling = -1;
   url_mapping *mapping = _tableLookup(mappings.hash_lookup, request_url, 
request_port, request_host_lower,
                                       request_host_len, tag);
   if (mapping != NULL) {
     rank_ceiling = mapping->getRank();
     Debug("url_rewrite", "Found 'simple' mapping with rank %d", rank_ceiling);
+    mapping_container.set(mapping);
+    retval = true;
   }
-  url_mapping *regex_mapping = _regexMappingLookup(mappings.regex_list, 
request_url, request_port,
-                                                   request_host_lower, 
request_host_len, tag, rank_ceiling);
-  if (regex_mapping) {
-    mapping = regex_mapping;
-    Debug("url_rewrite", "Using regex mapping with rank %d", 
mapping->getRank());
+  if (_regexMappingLookup(mappings.regex_list, request_url, request_port, 
request_host_lower, request_host_len,
+                          tag, rank_ceiling, mapping_container)) {
+    Debug("url_rewrite", "Using regex mapping with rank %d", 
(mapping_container.getMapping())->getRank());
+    retval = true;
   }
-  return mapping;
+  return retval;
 }
 
 // does not null terminate return string
@@ -2514,11 +2488,12 @@ UrlRewrite::_expandSubstitutions(int *ma
   return 0;
 }
 
-url_mapping *
+bool
 UrlRewrite::_regexMappingLookup(RegexMappingList &regex_mappings, URL 
*request_url, int request_port,
-                                const char *request_host, int 
request_host_len, char *tag, int rank_ceiling)
+                                const char *request_host, int 
request_host_len, char *tag, int rank_ceiling,
+                                UrlMappingContainer &mapping_container)
 {
-  url_mapping *retval = NULL;
+  bool retval = false;
   RegexMappingList::iterator list_iter;
 
   if (rank_ceiling == -1) { // we will now look at all regex mappings
@@ -2572,17 +2547,21 @@ UrlRewrite::_regexMappingLookup(RegexMap
       Debug("url_rewrite_regex", "Request URL host [%.*s] matched regex in 
mapping of rank %d "
             "with %d possible substitutions", request_host_len, request_host, 
reg_map_rank, match_result);
 
+      mapping_container.set(reg_map.url_map);
+
       char buf[MAX_URL_STR_SIZE];
       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);
-      reg_map.url_map->toURL.host_set(buf, buf_len);
+      URL *expanded_url = mapping_container.createNewToURL();
+      expanded_url->copy(&((reg_map.url_map)->_default_to_url));
+      expanded_url->host_set(buf, buf_len);
 
       Debug("url_rewrite_regex", "Expanded toURL to [%.*s]",
-            reg_map.url_map->toURL.length_get(), 
reg_map.url_map->toURL.string_get_ref());
-      retval = reg_map.url_map;
+            expanded_url->length_get(), expanded_url->string_get_ref());
+      retval = true;
       break;
     } else if (match_result == PCRE_ERROR_NOMATCH) {
       Debug("url_rewrite_regex", "Request URL host [%.*s] did NOT match regex 
in mapping of rank %d",
@@ -2664,7 +2643,7 @@ UrlRewrite::_processRegexMappingConfig(c
     goto lFail;
   }
 
-  to_host = new_mapping->toURL.host_get(&to_host_len);
+  to_host = new_mapping->_default_to_url.host_get(&to_host_len);
   for (int i = 0; i < (to_host_len - 1); ++i) {
     if (to_host[i] == '$') {
       if (substitution_count > MAX_REGEX_SUBS) {
@@ -2686,9 +2665,8 @@ UrlRewrite::_processRegexMappingConfig(c
 
   // so the regex itself is stored in fromURL.host; string to match
   // will be in the request; string to use for substitutions will be
-  // in this buffer and finally the substituted string will be stored
-  // in toURL.host on every successful regex match
-  str = new_mapping->toURL.host_get(&str_index); // reusing str and str_index
+  // in this buffer
+  str = new_mapping->_default_to_url.host_get(&str_index); // reusing str and 
str_index
   reg_map.to_url_host_template_len = str_index;
   reg_map.to_url_host_template = static_cast<char *>(ink_malloc(str_index));
   memcpy(reg_map.to_url_host_template, str, str_index);

Modified: trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.h
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.h?rev=950820&r1=950819&r2=950820&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.h (original)
+++ trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.h Wed Jun  2 
23:27:50 2010
@@ -26,6 +26,7 @@
 
 #include "StringHash.h"
 #include "UrlMapping.h"
+#include "HttpTransact.h"
 
 #ifdef HAVE_PCRE_PCRE_H
 #include <pcre/pcre.h>
@@ -89,10 +90,6 @@ public:
   void SetReverseFlag(int flag);
   void SetPristineFlag(int flag);
   void Print();
-  url_mapping_ext *forwardTableLookupExt(URL * request_url,
-                                         int request_port, char *request_host, 
int host_len, char *tag = 0);
-  url_mapping_ext *reverseTableLookupExt(URL * request_url,
-                                         int request_port, char *request_host, 
int host_len, char *tag = 0);
 //  private:
 
   static const int MAX_REGEX_SUBS = 10;
@@ -147,27 +144,31 @@ public:
   MappingsStore permanent_redirects;
   MappingsStore temporary_redirects;
 
-  url_mapping *forwardMappingLookup(URL *request_url, int request_port, const 
char *request_host,
-                                    int request_host_len, char *tag = NULL)
+  bool forwardMappingLookup(URL *request_url, int request_port, const char 
*request_host,
+                            int request_host_len, UrlMappingContainer 
&mapping_container, char *tag = NULL)
   {
-    return _mappingLookup(forward_mappings, request_url, request_port, 
request_host, request_host_len, tag);
+    return _mappingLookup(forward_mappings, request_url, request_port, 
request_host, request_host_len,
+                          mapping_container, tag);
   }
-  url_mapping *reverseMappingLookup(URL *request_url, int request_port, const 
char *request_host,
-                                    int request_host_len, char *tag = NULL)
+  bool reverseMappingLookup(URL *request_url, int request_port, const char 
*request_host,
+                            int request_host_len, UrlMappingContainer 
&mapping_container, char *tag = NULL)
   {
-    return _mappingLookup(reverse_mappings, request_url, request_port, 
request_host, request_host_len, tag);
+    return _mappingLookup(reverse_mappings, request_url, request_port, 
request_host, request_host_len,
+                          mapping_container, tag);
   }
-  url_mapping *permanentRedirectLookup(URL *request_url, int request_port, 
const char *request_host,
-                                       int request_host_len, char *tag = NULL)
+  bool permanentRedirectLookup(URL *request_url, int request_port, const char 
*request_host,
+                               int request_host_len, UrlMappingContainer 
&mapping_container, char *tag = NULL)
   {
-    return _mappingLookup(permanent_redirects, request_url, request_port, 
request_host, request_host_len, tag);
+    return _mappingLookup(permanent_redirects, request_url, request_port, 
request_host, request_host_len,
+                          mapping_container, tag);
   }
-  url_mapping *temporaryRedirectLookup(URL *request_url, int request_port, 
const char *request_host,
-                                       int request_host_len, char *tag = NULL)
+  bool temporaryRedirectLookup(URL *request_url, int request_port, const char 
*request_host,
+                               int request_host_len, UrlMappingContainer 
&mapping_container, char *tag = NULL)
   {
-    return _mappingLookup(temporary_redirects, request_url, request_port, 
request_host, request_host_len, tag);
+    return _mappingLookup(temporary_redirects, request_url, request_port, 
request_host, request_host_len,
+                          mapping_container, tag);
   }
-  int DoRemap(HttpTransact::State * s, HTTPHdr * request_header, url_mapping * 
mapPtr,
+  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);
@@ -198,13 +199,15 @@ public:
   remap_plugin_info *remap_pi_list;
 
 private:
-  url_mapping *_mappingLookup(MappingsStore &mappings, URL *request_url,
-                              int request_port, const char *request_host, int 
request_host_len, char *tag);
+  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);
-  url_mapping *_regexMappingLookup(RegexMappingList &regex_mappings,
-                                   URL * request_url, int request_port, const 
char *request_host,
-                                   int request_host_len, char *tag, int 
rank_ceiling);
+  bool _regexMappingLookup(RegexMappingList &regex_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 &reg_map,
                            const char *matched_string, char *dest_buf, int 
dest_buf_size);
   bool _processRegexMappingConfig(const char *from_host_lower, url_mapping 
*new_mapping, RegexMapping &reg_map);


Reply via email to