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:51 UTC

svn commit: r1082493 - in /trafficserver/traffic/trunk: example/query_remap/ example/remap/ plugins/conf_remap/ proxy/api/ts/ proxy/hdrs/ proxy/http/ proxy/http/remap/ tools/

Author: zwoop
Date: Thu Mar 17 14:00:51 2011
New Revision: 1082493

URL: http://svn.apache.org/viewvc?rev=1082493&view=rev
Log:
TS-588 Phase one, cleaning up APIs and fixing core code

Modified:
    trafficserver/traffic/trunk/example/query_remap/query_remap.c
    trafficserver/traffic/trunk/example/remap/remap.cc
    trafficserver/traffic/trunk/plugins/conf_remap/conf_remap.cc
    trafficserver/traffic/trunk/proxy/api/ts/remap.h
    trafficserver/traffic/trunk/proxy/hdrs/URL.cc
    trafficserver/traffic/trunk/proxy/http/HttpTransact.cc
    trafficserver/traffic/trunk/proxy/http/HttpTransact.h
    trafficserver/traffic/trunk/proxy/http/remap/RemapPluginInfo.cc
    trafficserver/traffic/trunk/proxy/http/remap/RemapPluginInfo.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/UrlMapping.h
    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=1082493&r1=1082492&r2=1082493&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:51 2011
@@ -21,8 +21,8 @@
   limitations under the License.
 */
 
-#include <ts/remap.h>
 #include <ts/ts.h>
+#include <ts/remap.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdint.h>
@@ -40,7 +40,8 @@ typedef struct _query_remap_info {
 } query_remap_info;
 
 
-int tsremap_init(TSRemapInterface *api_info,char *errbuf,int errbuf_size)
+int
+TSRemapInit(TSRemapInterface *api_info, char *errbuf, int errbuf_size)
 {
   /* Called at TS startup. Nothing needed for this plugin */
   TSDebug(PLUGIN_NAME , "remap plugin initialized");
@@ -48,7 +49,8 @@ int tsremap_init(TSRemapInterface *api_i
 }
 
 
-int tsremap_new_instance(int argc,char *argv[],ihandle *ih,char *errbuf,int errbuf_size)
+int
+TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_size)
 {
   /* Called for each remap rule using this plugin. The parameters are parsed here */
   int i;
@@ -81,14 +83,15 @@ int tsremap_new_instance(int argc,char *
     TSDebug(PLUGIN_NAME, " - Host %d: %s", i, qri->hosts[i]);
   }
 
-  *ih = (ihandle)qri;
+  *ih = (void*)qri;
   TSDebug(PLUGIN_NAME, "created instance %p", *ih);
   return 0;
 }
 
-void tsremap_delete_instance(ihandle ih)
+void
+TSRemapDeleteInstance(void* ih)
 {
-  /* Release instance memory allocated in tsremap_new_instance */
+  /* Release instance memory allocated in TSRemapNewInstance */
   int i;
   TSDebug(PLUGIN_NAME, "deleting instance %p", ih);
 
@@ -107,17 +110,18 @@ void tsremap_delete_instance(ihandle ih)
 }
 
 
-int tsremap_remap(ihandle ih, rhandle rh, TSRemapRequestInfo *rri)
+int
+TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
 {
   int hostidx = -1;
   query_remap_info *qri = (query_remap_info*)ih;
 
   if (!qri) {
-    TSError(PLUGIN_NAME "NULL ihandle");
+    TSError(PLUGIN_NAME "NULL private data");
     return 0;
   }
 
-  TSDebug(PLUGIN_NAME, "tsremap_remap request: %.*s", rri->orig_url_size, rri->orig_url);
+  TSDebug(PLUGIN_NAME, "TSRemapDoRemap request: %.*s", rri->orig_url_size, rri->orig_url);
 
   if (rri && rri->request_query && rri->request_query_size > 0) {
     char *q, *key;

Modified: trafficserver/traffic/trunk/example/remap/remap.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/example/remap/remap.cc?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/example/remap/remap.cc (original)
+++ trafficserver/traffic/trunk/example/remap/remap.cc Thu Mar 17 14:00:51 2011
@@ -41,8 +41,8 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 
-#include <ts/remap.h>
 #include <ts/ts.h>
+#include <ts/remap.h>
 
 #if __GNUC__ >= 3
 #ifndef likely
@@ -83,11 +83,10 @@ pthread_mutex_t
 
 /* ----------------------- remap_entry::remap_entry ------------------------ */
 remap_entry::remap_entry(int _argc, char *_argv[]):
-next(NULL),
-argc(0),
-argv(NULL)
+  next(NULL), argc(0), argv(NULL)
 {
   int i;
+
   if (_argc > 0 && _argv && (argv = (char **) malloc(sizeof(char *) * (_argc + 1))) != 0) {
     argc = _argc;
     for (i = 0; i < argc; i++)
@@ -100,6 +99,7 @@ argv(NULL)
 remap_entry::~remap_entry()
 {
   int i;
+
   if (argc && argv) {
     for (i = 0; i < argc; i++) {
       if (argv[i])
@@ -189,29 +189,29 @@ TSPluginInit(int argc, const char *argv[
 
 // Plugin initialization code. Called immediately after dlopen() Only once!
 // Can perform internal initialization. For example, pthread_.... initialization.
-/* ------------------------- tsremap_init ---------------------------------- */
+/* ------------------------- TSRemapInit ---------------------------------- */
 int
-tsremap_init(TSRemapInterface * api_info, char *errbuf, int errbuf_size)
+TSRemapInit(TSRemapInterface * api_info, char *errbuf, int errbuf_size)
 {
-  fprintf(stderr, "Remap Plugin: tsremap_init()\n");
+  fprintf(stderr, "Remap Plugin: TSRemapInit()\n");
 
   if (!plugin_init_counter) {
     if (unlikely(!api_info)) {
-      return store_my_error_message(-1, errbuf, errbuf_size, "[tsremap_init] - Invalid TSRemapInterface argument");
+      return store_my_error_message(-1, errbuf, errbuf_size, "[TSRemapInit] - Invalid TSRemapInterface argument");
     }
     if (unlikely(api_info->size < sizeof(TSRemapInterface))) {
       return store_my_error_message(-2, errbuf, errbuf_size,
-                                    "[tsremap_init] - Incorrect size of TSRemapInterface structure %d. Should be at least %d bytes",
+                                    "[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,
-                                    "[tsremap_init] - Incorrect API version %d.%d",
+                                    "[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, "[tsremap_init] - Mutex initialization error");
+      return store_my_error_message(-4, errbuf, errbuf_size, "[TSRemapInit] - Mutex initialization error");
     }
     plugin_init_counter++;
   }
@@ -220,11 +220,11 @@ tsremap_init(TSRemapInterface * api_info
 
 // Plugin shutdown
 // Optional function.
-/* -------------------------- tsremap_done --------------------------------- */
+/* -------------------------- TSRemapDone --------------------------------- */
 int
-tsremap_done(void)
+TSRemapDone(void)
 {
-  fprintf(stderr, "Remap Plugin: tsremap_done()\n");
+  fprintf(stderr, "Remap Plugin: TSRemapDone()\n");
   /* do nothing */
 
   return 0;
@@ -233,48 +233,48 @@ tsremap_done(void)
 
 // Plugin new instance for new remapping rule.
 // This function can be called multiple times (depends on remap.config)
-/* ------------------------ tsremap_new_instance --------------------------- */
+/* ------------------------ TSRemapNewInstance --------------------------- */
 int
-tsremap_new_instance(int argc, char *argv[], ihandle * ih, char *errbuf, int errbuf_size)
+TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_size)
 {
   remap_entry *ri;
   int i;
 
 
-  fprintf(stderr, "Remap Plugin: tsremap_new_instance()\n");
+  fprintf(stderr, "Remap Plugin: TSRemapNewInstance()\n");
 
   if (argc < 2) {
     return store_my_error_message(-1, errbuf, errbuf_size,
-                                  "[tsremap_new_instance] - Incorrect number of arguments - %d", argc);
+                                  "[TSRemapNewInstance] - Incorrect number of arguments - %d", argc);
   }
   if (!argv || !ih) {
-    return store_my_error_message(-2, errbuf, errbuf_size, "[tsremap_new_instance] - Invalid argument(s)");
+    return store_my_error_message(-2, errbuf, errbuf_size, "[TSRemapNewInstance] - Invalid argument(s)");
   }
   // print all arguments for this particular remapping
   for (i = 0; i < argc; i++) {
-    fprintf(stderr, "[tsremap_new_instance] - argv[%d] = \"%s\"\n", i, argv[i]);
+    fprintf(stderr, "[TSRemapNewInstance] - argv[%d] = \"%s\"\n", i, argv[i]);
   }
 
   ri = new remap_entry(argc, argv);
 
   if (!ri) {
-    return store_my_error_message(-3, errbuf, errbuf_size, "[tsremap_new_instance] - Can't create remap_entry class");
+    return store_my_error_message(-3, errbuf, errbuf_size, "[TSRemapNewInstance] - Can't create remap_entry class");
   }
 
   remap_entry::add_to_list(ri);
 
-  *ih = (ihandle) ri;
+  *ih = (void*) ri;
 
   return 0;
 }
 
-/* ---------------------- tsremap_delete_instance -------------------------- */
+/* ---------------------- TSRemapDeleteInstance -------------------------- */
 void
-tsremap_delete_instance(ihandle ih)
+TSRemapDeleteInstance(void* ih)
 {
   remap_entry *ri = (remap_entry *) ih;
 
-  fprintf(stderr, "Remap Plugin: tsremap_delete_instance()\n");
+  fprintf(stderr, "Remap Plugin: TSRemapDeleteInstance()\n");
 
   remap_entry::remove_from_list(ri);
 
@@ -284,11 +284,10 @@ tsremap_delete_instance(ihandle ih)
 static volatile unsigned long processing_counter = 0;   // sequential counter
 static int arg_index = 0;
 
-/* -------------------------- tsremap_remap -------------------------------- */
+/* -------------------------- TSRemapDoRemap -------------------------------- */
 int
-tsremap_remap(ihandle ih, rhandle rh, TSRemapRequestInfo * rri)
+TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo * rri)
 {
-  char *p;
   TSMBuffer cbuf;
   TSMLoc chdr;
   TSMLoc cfield;
@@ -296,32 +295,32 @@ tsremap_remap(ihandle ih, rhandle rh, TS
   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: tsremap_remap()\n");
+  fprintf(stderr, "Remap Plugin: TSRemapDoRemap()\n");
 
   if (!ri || !rri)
     return 0;                   /* TS must remap this request */
-  p = (char *) &rri->client_ip;
-  fprintf(stderr, "[tsremap_remap] Client IP: %d.%d.%d.%d\n", (int) p[0], (int) p[1], (int) p[2], (int) p[3]);
-  fprintf(stderr, "[tsremap_remap] From: \"%s\"  To: \"%s\"\n", ri->argv[0], ri->argv[1]);
-  fprintf(stderr, "[tsremap_remap] OrigURL: \"");
+  /* 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]);
+  */
+  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[tsremap_remap] Request Host(%d): \"", rri->request_host_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[tsremap_remap] Remap To Host: \"");
+  fprintf(stderr, "\"\n[TSRemapDoRemap] Remap To Host: \"");
   my_print_ascii_string(rri->remap_to_host, rri->remap_to_host_size);
-  fprintf(stderr, "\"\n[tsremap_remap] Remap From Host: \"");
+  fprintf(stderr, "\"\n[TSRemapDoRemap] Remap From Host: \"");
   my_print_ascii_string(rri->remap_from_host, rri->remap_from_host_size);
-  fprintf(stderr, "\"\n[tsremap_remap] Request Port: %d\n", rri->request_port);
-  fprintf(stderr, "[tsremap_remap] Remap From Port: %d\n", rri->remap_from_port);
-  fprintf(stderr, "[tsremap_remap] Remap To Port: %d\n", rri->remap_to_port);
-  fprintf(stderr, "[tsremap_remap] Request Path: \"");
+  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[tsremap_remap] Remap From Path: \"");
+  fprintf(stderr, "\"\n[TSRemapDoRemap] Remap From Path: \"");
   my_print_ascii_string(rri->remap_from_path, rri->remap_from_path_size);
-  fprintf(stderr, "\"\n[tsremap_remap] Remap To Path: \"");
+  fprintf(stderr, "\"\n[TSRemapDoRemap] Remap To Path: \"");
   my_print_ascii_string(rri->remap_to_path, rri->remap_to_path_size);
-  fprintf(stderr, "\"\n[tsremap_remap] Request cookie: \"");
-  my_print_ascii_string(rri->request_cookie, rri->request_cookie_size);
   fprintf(stderr, "\"\n");
 
 
@@ -344,7 +343,7 @@ tsremap_remap(ihandle ih, rhandle rh, TS
   }
   // 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, "[tsremap_remap] Save processing counter %lu inside request processing block\n", _processing_counter);
+    fprintf(stderr, "[TSRemapDoRemap] Save processing counter %lu inside request processing block\n", _processing_counter);
     TSHttpTxnArgSet((TSHttpTxn) rh, arg_index, (void *) _processing_counter); // save counter
   }
   // How to cancel request processing and return error message to the client
@@ -380,15 +379,15 @@ tsremap_remap(ihandle ih, rhandle rh, TS
   return retcode;
 }
 
-/* ----------------------- tsremap_os_response ----------------------------- */
+/* ----------------------- TSRemapOSResponse ----------------------------- */
 void
-tsremap_os_response(ihandle ih, rhandle rh, int os_response_type)
+TSRemapOSResponse(void* ih, TSHttpTxn rh, int os_response_type)
 {
   int request_id = -1;
-  void *data = TSHttpTxnArgGet((TSHttpTxn) rh, arg_index);  // read counter (we store it in tsremap_remap function call)
+  void *data = TSHttpTxnArgGet((TSHttpTxn) rh, arg_index);  // read counter (we store it in TSRemapDoRemap function call)
 
   if (data)
     request_id = *((int*)data);
-  fprintf(stderr, "[tsremap_os_response] Read processing counter %d from request processing block\n", request_id);
-  fprintf(stderr, "[tsremap_os_response] OS response status: %d\n", os_response_type);
+  fprintf(stderr, "[TSRemapOSResponse] Read processing counter %d from request processing block\n", request_id);
+  fprintf(stderr, "[TSRemapOSResponse] OS response status: %d\n", os_response_type);
 }

Modified: trafficserver/traffic/trunk/plugins/conf_remap/conf_remap.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/plugins/conf_remap/conf_remap.cc?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/plugins/conf_remap/conf_remap.cc (original)
+++ trafficserver/traffic/trunk/plugins/conf_remap/conf_remap.cc Thu Mar 17 14:00:51 2011
@@ -175,46 +175,46 @@ RemapConfigs::parse_file(const char* fn)
 ///////////////////////////////////////////////////////////////////////////////
 // Initialize the plugin as a remap plugin.
 //
-int
-tsremap_init(TSRemapInterface* api_info, char *errbuf, int errbuf_size)
+TSReturnCode
+TSRemapInit(TSRemapInterface* api_info, char *errbuf, int errbuf_size)
 {
   if (!api_info) {
-    strncpy(errbuf, "[tsremap_init] - Invalid TSRemapInterface argument", errbuf_size - 1);
-    return -1;
+    strncpy(errbuf, "[TSRemapInit] - Invalid TSRemapInterface argument", errbuf_size - 1);
+    return TS_ERROR;
   }
 
   if (api_info->size < sizeof(TSRemapInterface)) {
-    strncpy(errbuf, "[tsremap_init] - Incorrect size of TSRemapInterface structure", errbuf_size - 1);
-    return -2;
+    strncpy(errbuf, "[TSRemapInit] - Incorrect size of TSRemapInterface structure", errbuf_size - 1);
+    return TS_ERROR;
   }
 
   TSDebug(PLUGIN_NAME, "remap plugin is succesfully initialized");
-  return 0;                     /* success */
+  return TS_SUCCESS;                     /* success */
 }
 
 
-int
-tsremap_new_instance(int argc, char* argv[], ihandle* ih, char* errbuf, int errbuf_size)
+TSReturnCode
+TSRemapNewInstance(int argc, char* argv[], void** ih, char* errbuf, int errbuf_size)
 {
   if (argc < 3) {
     TSError("Unable to create remap instance, need configuration file");
-    return -1;
+    return TS_ERROR;
   } else {
     RemapConfigs* conf = new(RemapConfigs);
 
     if (conf->parse_file(argv[2])) {
-      *ih = static_cast<ihandle>(conf);
+      *ih = static_cast<void*>(conf);
     } else {
       *ih = NULL;
       delete conf;
     }
   }
 
-  return 0;
+  return TS_SUCCESS;
 }
 
 void
-tsremap_delete_instance(ihandle ih)
+TSRemapDeleteInstance(void* ih)
 {
   RemapConfigs* conf = static_cast<RemapConfigs*>(ih);
 
@@ -230,8 +230,8 @@ tsremap_delete_instance(ihandle ih)
 ///////////////////////////////////////////////////////////////////////////////
 // Main entry point when used as a remap plugin.
 //
-int
-tsremap_remap(ihandle ih, rhandle rh, TSRemapRequestInfo *rri)
+TSRemapStatus
+TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
 {
   if (NULL != ih) {
     RemapConfigs* conf = static_cast<RemapConfigs*>(ih);
@@ -253,7 +253,7 @@ tsremap_remap(ihandle ih, rhandle rh, TS
     }
   }
 
-  return 0; // This plugin never rewrites anything.
+  return TSREMAP_NO_REMAP; // This plugin never rewrites anything.
 }
 
 

Modified: trafficserver/traffic/trunk/proxy/api/ts/remap.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/api/ts/remap.h?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/api/ts/remap.h (original)
+++ trafficserver/traffic/trunk/proxy/api/ts/remap.h Thu Mar 17 14:00:51 2011
@@ -21,9 +21,6 @@
   limitations under the License.
  */
 
-/* ------------------------------------------------------------------------- */
-/* -                               RemapAPI.h                              - */
-/* ------------------------------------------------------------------------- */
 #ifndef H_REMAPAPI_H
 #define H_REMAPAPI_H
 
@@ -32,55 +29,16 @@ extern "C"
 {
 #endif                          /* __cplusplus */
 
-#define TSREMAP_VMAJOR   2      /* major version number */
+#define TSREMAP_VMAJOR   3      /* major version number */
 #define TSREMAP_VMINOR   0      /* minor version number */
 #define TSREMAP_VERSION ((TSREMAP_VMAJOR << 16)|TSREMAP_VMINOR)
 
-  typedef int tsremap_interface(int cmd, ...);
-
   typedef struct _tsremap_api_info
   {
     unsigned long size;         /* in: sizeof(struct _tsremap_api_info) */
     unsigned long tsremap_version;      /* in: TS supported version ((major << 16) | minor) */
-    tsremap_interface *fp_tsremap_interface;    /* in: TS interface function pointer */
   } TSRemapInterface;
 
-  typedef TSRemapInterface TSREMAP_INTERFACE;   /* This is deprecated. */
-
-  typedef void *base_handle;
-  typedef base_handle ihandle;  /* plugin instance handle (per unique remap rule) */
-  typedef base_handle rhandle;  /* request handle */
-
-
-  /* Plugin initialization - called first.
-     Mandatory interface function.
-     Return: 0 - success
-             != 0 - error, errbuf can include error message from plugin
-  */
-  int tsremap_init(TSRemapInterface * api_info, char *errbuf, int errbuf_size);
-  typedef int _tsremap_init(TSRemapInterface * api_info, char *errbuf, int errbuf_size);
-#define TSREMAP_FUNCNAME_INIT "tsremap_init"
-
-
-  /* Plugin shutdown
-     Optional function. */
-  int tsremap_done(void);
-  typedef int _tsremap_done(void);
-#define TSREMAP_FUNCNAME_DONE "tsremap_done"
-
-  /* Plugin new instance. Create new plugin processing entry for unique remap record.
-     First two arguments in argv vector are - fromURL and toURL from remap record.
-     Please keep in mind that fromURL and toURL will be converted to canonical view.
-     Return: != 0 - instance creation error
-                0 - success
-  */
-  int tsremap_new_instance(int argc, char *argv[], ihandle * ih, char *errbuf, int errbuf_size);
-  typedef int _tsremap_new_instance(int argc, char *argv[], ihandle * ih, char *errbuf, int errbuf_size);
-#define TSREMAP_FUNCNAME_NEW_INSTANCE "tsremap_new_instance"
-
-  void tsremap_delete_instance(ihandle);
-  typedef void _tsremap_delete_instance(ihandle);
-#define TSREMAP_FUNCNAME_DELETE_INSTANCE "tsremap_delete_instance"
 
 #define TSREMAP_RRI_MAX_HOST_SIZE    256
 #define TSREMAP_RRI_MAX_PATH_SIZE    (1024*2)
@@ -88,53 +46,49 @@ extern "C"
 
   typedef struct _tm_remap_request_info
   {
-    /* the following fields are read only */
-    unsigned long size;         /* sizeof(TSRemapRequestInfo) */
+    /* these URLs mloc's are read only, use normal ts/ts.h APIs for accesing  */
+    TSMLoc mapFromUrl;
+    TSMLoc mapToUrl;
+    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 */
+    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) */
+    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) */
+    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) */
+    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 */
+    const char* request_path;   /* request path */
     int request_path_size;      /* request path size */
 
-    const char *remap_from_path;        /* fromURL path (from remap rule string) */
+    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) */
+    const char* remap_to_path;  /* toURL path (from remap rule string) */
     int remap_to_path_size;     /* toURL path size */
 
-    const char *request_cookie; /* request cookie string */
-    int request_cookie_size;    /* request cookie string size */
-
-    const char *request_query;  /* request query string */
+    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 */
+    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) */
+    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) */
+    const char* to_scheme;      /* The "to" scheme (e.g. HTTP) */
     int to_scheme_len;          /* The len of the "to" scheme */
 
-    unsigned int client_ip;     /* The client IP is an unsigned network (big-endian) 32-bit number. */
-    /* Each of the dotted components is a byte, so: */
-    /* 0x25364758 = 0x25.0x36.0x47.0x58 = 37.54.71.88 in decimal. */
-
     /* 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) */
@@ -153,25 +107,63 @@ extern "C"
     /*   -1 (default) -> Don't modify scheme */
   } 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 */
+  } TSRemapStatus;
+
+
+
+  /* ----------------------------------------------------------------------------------
+     These are the entry points a plugin can implement. Note that TSRemapInit() and
+     TSRemapDoRemap() are both required.
+     ----------------------------------------------------------------------------------
+  */
+
+  /* Plugin initialization - called first.
+     Mandatory interface function.
+     Return: TS_SUCCESS
+             TS_ERROR - error, errbuf can include error message from plugin
+  */
+  TSReturnCode TSRemapInit(TSRemapInterface* api_info, char* errbuf, int errbuf_size);
+
+
   /* Remap new request
-     Return: != 0 - request was remapped, TS must look at new_... fields in TSRemapRequestInfo
-             == 0 - request was not processed. TS must perform default remap
-     Note: rhandle == TSHttpTxn (see ts/ts.h for more details)
-     Remap API plugin can use InkAPI function calls inside tsremap_remap()
+     Mandatory interface function.
+     Remap API plugin can/should use SDK API function calls inside this function!
+     return: TSREMAP_NO_REMAP - No remaping was done, continue with next in chain
+             TSREMAP_DID_REMAP - Remapping was done, continue with next in chain
+             TSREMAP_NO_REMAP_STOP - No remapping was done, and stop plugin chain evaluation
+             TSREMAP_DID_REMAP_STOP -  Remapping was done, but stop plugin chain evaluation
   */
-  int tsremap_remap(ihandle ih, rhandle rh, TSRemapRequestInfo * rri);
-  typedef int _tsremap_remap(ihandle ih, rhandle rh, TSRemapRequestInfo * rri);
-#define TSREMAP_FUNCNAME_REMAP "tsremap_remap"
+  TSRemapStatus TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo* rri);
+
+
+  /* Plugin shutdown, called when plugin is unloaded.
+     Optional function. */
+  void TSRemapDone(void);
+
+
+  /* Plugin new instance. Create new plugin processing entry for unique remap record.
+     First two arguments in argv vector are - fromURL and toURL from remap record.
+     Please keep in mind that fromURL and toURL will be converted to canonical view.
+     Return: TS_SUCESS
+             TS_ERROR - instance creation error
+  */
+  TSReturnCode TSRemapNewInstance(int argc, char* argv[], void** ih, char* errbuf, int errbuf_size);
+  void TSRemapDeleteInstance(void*);
+
 
   /* Check response code from Origin Server
-     Return: none
-     Note: rhandle == TSHttpTxn (see ts/ts.h for more details)
      os_response_type -> TSServerState
-     Remap API plugin can use InkAPI function calls inside tsremap_remap()
+     Remap API plugin can use InkAPI function calls inside TSRemapDoRemap()
+     Return: none
   */
-  void tsremap_os_response(ihandle ih, rhandle rh, int os_response_type);
-  typedef void _tsremap_os_response(ihandle ih, rhandle rh, int os_response_type);
-#define TSREMAP_FUNCNAME_OS_RESPONSE "tsremap_os_response"
+  void TSRemapOSResponse(void* ih, TSHttpTxn rh, int os_response_type);
 
 #ifdef __cplusplus
 }

Modified: trafficserver/traffic/trunk/proxy/hdrs/URL.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/hdrs/URL.cc?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/hdrs/URL.cc (original)
+++ trafficserver/traffic/trunk/proxy/hdrs/URL.cc Thu Mar 17 14:00:51 2011
@@ -199,7 +199,7 @@ url_create(HdrHeap * heap)
   url->m_url_type = URL_TYPE_NONE;
   url->m_scheme_wks_idx = -1;
   url_clear_string_ref(url);
-  return (url);
+  return url;
 }
 
 /*-------------------------------------------------------------------------
@@ -221,7 +221,7 @@ url_copy(URLImpl * s_url, HdrHeap * s_he
 {
   URLImpl *d_url = url_create(d_heap);
   url_copy_onto(s_url, s_heap, d_url, d_heap, inherit_strs);
-  return (d_url);
+  return d_url;
 }
 
 /*-------------------------------------------------------------------------
@@ -389,7 +389,7 @@ url_scheme_set(HdrHeap * heap, URLImpl *
   else
     url->m_url_type = URL_TYPE_HTTP;
 
-  return (scheme_wks);          // tokenized string or NULL if not well known
+  return scheme_wks;          // tokenized string or NULL if not well known
 }
 
 /*-------------------------------------------------------------------------
@@ -645,7 +645,7 @@ url_scheme_get(URLImpl * url, int *lengt
     str = url->m_ptr_scheme;
     *length = url->m_len_scheme;
   }
-  return (str);
+  return str;
 }
 
 /*-------------------------------------------------------------------------
@@ -655,7 +655,7 @@ const char *
 url_user_get(URLImpl * url, int *length)
 {
   *length = url->m_len_user;
-  return (url->m_ptr_user);
+  return url->m_ptr_user;
 }
 
 /*-------------------------------------------------------------------------
@@ -665,7 +665,7 @@ const char *
 url_password_get(URLImpl * url, int *length)
 {
   *length = url->m_len_password;
-  return (url->m_ptr_password);
+  return url->m_ptr_password;
 }
 
 /*-------------------------------------------------------------------------
@@ -675,7 +675,7 @@ const char *
 url_host_get(URLImpl * url, int *length)
 {
   *length = url->m_len_host;
-  return (url->m_ptr_host);
+  return url->m_ptr_host;
 }
 
 /*-------------------------------------------------------------------------
@@ -684,7 +684,7 @@ url_host_get(URLImpl * url, int *length)
 int
 url_port_get(URLImpl * url)
 {
-  return (url->m_port);
+  return url->m_port;
 }
 
 /*-------------------------------------------------------------------------
@@ -694,7 +694,7 @@ const char *
 url_path_get(URLImpl * url, int *length)
 {
   *length = url->m_len_path;
-  return (url->m_ptr_path);
+  return url->m_ptr_path;
 }
 
 /*-------------------------------------------------------------------------
@@ -704,7 +704,7 @@ const char *
 url_params_get(URLImpl * url, int *length)
 {
   *length = url->m_len_params;
-  return (url->m_ptr_params);
+  return url->m_ptr_params;
 }
 
 /*-------------------------------------------------------------------------
@@ -714,7 +714,7 @@ const char *
 url_query_get(URLImpl * url, int *length)
 {
   *length = url->m_len_query;
-  return (url->m_ptr_query);
+  return url->m_ptr_query;
 }
 
 /*-------------------------------------------------------------------------
@@ -724,7 +724,7 @@ const char *
 url_fragment_get(URLImpl * url, int *length)
 {
   *length = url->m_len_fragment;
-  return (url->m_ptr_fragment);
+  return url->m_ptr_fragment;
 }
 
 /*-------------------------------------------------------------------------
@@ -733,7 +733,7 @@ url_fragment_get(URLImpl * url, int *len
 int
 url_type_get(URLImpl * url)
 {
-  return (url->m_type_code);
+  return url->m_type_code;
 }
 
 /*-------------------------------------------------------------------------
@@ -786,7 +786,7 @@ url_length_get(URLImpl * url)
   if (url->m_ptr_fragment)
     length += url->m_len_fragment + 1;        // +1 for "/"
 
-  return (length);
+  return length;
 }
 
 /*-------------------------------------------------------------------------
@@ -869,7 +869,7 @@ url_to_string(URLImpl * url, Arena * are
 
   ink_release_assert(idx == len);
 
-  return (str);
+  return str;
 }
 
 /*-------------------------------------------------------------------------
@@ -1027,7 +1027,7 @@ url_unescapify(Arena * arena, const char
   unescape_str(t, e, str, str + length, s);
   *t = '\0';
 
-  return (buffer);
+  return buffer;
 }
 
 /*-------------------------------------------------------------------------
@@ -1583,7 +1583,7 @@ url_print(URLImpl * url, char *buf_start
                        buf_start, buf_length, buf_index_inout, buf_chars_to_skip_inout));
   }
 
-  return (1);
+  return 1;
 
 #undef TRY
 }

Modified: trafficserver/traffic/trunk/proxy/http/HttpTransact.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpTransact.cc?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpTransact.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpTransact.cc Thu Mar 17 14:00:51 2011
@@ -3507,13 +3507,10 @@ HttpTransact::handle_response_from_serve
   HTTP_RELEASE_ASSERT(s->current.server == &s->server_info);
   int max_connect_retries = 0;
 
-  s->server_info.state = s->current.state;
-
   // plugin call
-  if (s->fp_tsremap_os_response)        // && s->current.state != CONNECTION_ALIVE)
-  {
-    s->fp_tsremap_os_response(s->remap_plugin_instance, (rhandle) (s->state_machine), s->current.state);
-  }
+  s->server_info.state = s->current.state;
+  if (s->fp_tsremap_os_response)
+    s->fp_tsremap_os_response(s->remap_plugin_instance, reinterpret_cast<TSHttpTxn>(s->state_machine), s->current.state);
 
   switch (s->current.state) {
   case CONNECTION_ALIVE:

Modified: trafficserver/traffic/trunk/proxy/http/HttpTransact.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpTransact.h?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpTransact.h (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpTransact.h Thu Mar 17 14:00:51 2011
@@ -997,8 +997,8 @@ public:
     bool acl_filtering_performed;
 
     // INK API/Remap API plugin interface
-    _tsremap_os_response *fp_tsremap_os_response;
-    ihandle remap_plugin_instance;
+    remap_plugin_info::_tsremap_os_response *fp_tsremap_os_response;
+    void* remap_plugin_instance;
     HTTPStatus http_return_code;
     int return_xbuf_size;
     bool return_xbuf_plain;

Modified: trafficserver/traffic/trunk/proxy/http/remap/RemapPluginInfo.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/RemapPluginInfo.cc?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/RemapPluginInfo.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/RemapPluginInfo.cc Thu Mar 17 14:00:51 2011
@@ -23,27 +23,14 @@
 
 #include "RemapPluginInfo.h"
 
-// Globals
-pthread_mutex_t remap_plugin_info::global_list_mutex;
-remap_plugin_info_init instance_of_remap_plugin_info_init;
-
-
-// Initialization
-remap_plugin_info_init::remap_plugin_info_init()
-{
-  pthread_mutex_init(&remap_plugin_info::global_list_mutex, 0);
-}
-
-
 remap_plugin_info::remap_plugin_info(char *_path)
   :  next(0), path(NULL), path_size(0), dlh(NULL), fp_tsremap_init(NULL), fp_tsremap_done(NULL), fptsremap_new_instance(NULL),
-     fp_tsremap_delete_instance(NULL), fp_tsremap_remap(NULL), fp_tsremap_os_response(NULL) 
+     fp_tsremap_delete_instance(NULL), fp_tsremap_do_remap(NULL), fp_tsremap_os_response(NULL) 
 {
   // coverity did not see xfree
   // coverity[ctor_dtor_leak]
-  if (_path && likely((path = xstrdup(_path)) > 0)) {
+  if (_path && likely((path = xstrdup(_path)) > 0))
     path_size = strlen(path);
-  }
 }
 
 remap_plugin_info::~remap_plugin_info()

Modified: trafficserver/traffic/trunk/proxy/http/remap/RemapPluginInfo.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/RemapPluginInfo.h?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/RemapPluginInfo.h (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/RemapPluginInfo.h Thu Mar 17 14:00:51 2011
@@ -24,6 +24,7 @@
 #if !defined (_REMAPPLUGININFO_h_)
 #define _REMAPPLUGININFO_h_
 #include "libts.h"
+#include "api/ts/ts.h"
 #include "api/ts/remap.h"
 
 // Remap inline options
@@ -37,6 +38,13 @@
 #define REMAP_OPTFLG_INVERT           0x80000000        /* "invert" the rule (for src_ip at least) */
 #define REMAP_OPTFLG_ALL_FILTERS (REMAP_OPTFLG_METHOD|REMAP_OPTFLG_SRC_IP|REMAP_OPTFLG_ACTION)
 
+#define TSREMAP_FUNCNAME_INIT "TSRemapInit"
+#define TSREMAP_FUNCNAME_DONE "TSRemapDone"
+#define TSREMAP_FUNCNAME_NEW_INSTANCE "TSRemapNewInstance"
+#define TSREMAP_FUNCNAME_DELETE_INSTANCE "TSRemapDeleteInstance"
+#define TSREMAP_FUNCNAME_DO_REMAP "TSRemapDoRemap"
+#define TSREMAP_FUNCNAME_OS_RESPONSE "TSRemapOSResponse"
+
 class url_mapping;
 
 /**
@@ -45,9 +53,12 @@ class url_mapping;
 class remap_plugin_info
 {
 public:
-  static pthread_mutex_t global_list_mutex;
-
-  Link<remap_plugin_info *>link;   //so i can queue these up
+  typedef TSReturnCode _tsremap_init(TSRemapInterface* api_info, char* errbuf, int errbuf_size);
+  typedef void _tsremap_done(void);
+  typedef TSReturnCode _tsremap_new_instance(int argc, char* argv[], void** ih, char* errbuf, int errbuf_size);
+  typedef void _tsremap_delete_instance(void*);
+  typedef TSRemapStatus _tsremap_do_remap(void* ih, TSHttpTxn rh, TSRemapRequestInfo* rri);
+  typedef void _tsremap_os_response(void* ih, TSHttpTxn rh, int os_response_type);
 
   remap_plugin_info *next;
   char *path;
@@ -57,7 +68,7 @@ public:
   _tsremap_done *fp_tsremap_done;
   _tsremap_new_instance *fptsremap_new_instance;
   _tsremap_delete_instance *fp_tsremap_delete_instance;
-  _tsremap_remap *fp_tsremap_remap;
+  _tsremap_do_remap *fp_tsremap_do_remap;
   _tsremap_os_response *fp_tsremap_os_response;
 
   remap_plugin_info(char *_path);
@@ -70,16 +81,6 @@ public:
 
 
 /**
- *
-**/
-class remap_plugin_info_init
-{
-public:
-  remap_plugin_info_init();
-};
-
-
-/**
  * struct host_hdr_info;
  * Used to store info about host header
 **/

Modified: trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.cc?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.cc Thu Mar 17 14:00:51 2011
@@ -25,11 +25,11 @@
 
 ClassAllocator<RemapPlugins> pluginAllocator("RemapPluginsAlloc");
 
-int
+TSRemapStatus
 RemapPlugins::run_plugin(remap_plugin_info* plugin, char *origURLBuf, int origURLBufSize,
                          bool* plugin_modified_host, bool* plugin_modified_port, bool* plugin_modified_path)
 {
-  int plugin_retcode;
+  TSRemapStatus plugin_retcode;
   bool do_x_proto_check = true;
   TSRemapRequestInfo rri;
   int requestPort = 0;
@@ -37,6 +37,11 @@ RemapPlugins::run_plugin(remap_plugin_in
   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();
@@ -71,7 +76,6 @@ RemapPlugins::run_plugin(remap_plugin_in
   // Get request matrix parameters
   rri.request_matrix = _request_url->params_get(&rri.request_matrix_size);
 
-  rri.size = sizeof(rri);
   rri.orig_url = origURLBuf;
   rri.orig_url_size = origURLBufSize;
 
@@ -88,18 +92,7 @@ RemapPlugins::run_plugin(remap_plugin_in
   // Get request Host
   rri.request_host = _request_url->host_get(&rri.request_host_size);
 
-  // Copy client IP address
-  rri.client_ip = _s ? _s->client_info.ip : 0;
-
-  // Get Cookie header
-  if (_request_header->presence(MIME_PRESENCE_COOKIE)) {
-    rri.request_cookie = _request_header->value_get(MIME_FIELD_COOKIE, MIME_LEN_COOKIE, &rri.request_cookie_size);
-  } else {
-    rri.request_cookie = NULL;
-    rri.request_cookie_size = 0;
-  }
-
-  ihandle *ih = map->get_instance(plugin);
+  void* ih = map->get_instance(_cur);
 
   ink_debug_assert(ih);
 
@@ -109,19 +102,20 @@ RemapPlugins::run_plugin(remap_plugin_in
     _s->remap_plugin_instance = ih;
   }
 
-  plugin_retcode = plugin->fp_tsremap_remap(*ih, _s ? (rhandle) (_s->state_machine) : NULL, &rri);
+  plugin_retcode = plugin->fp_tsremap_do_remap(ih, _s ? reinterpret_cast<TSHttpTxn>(_s->state_machine) : NULL, &rri);
 
   // First step after plugin remap must be "redirect url" check
-  if ( /*_s->remap_redirect && */ plugin_retcode && rri.redirect_url_size > 0) {
+  // 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 1;
+    return plugin_retcode;
   }
 
-  if (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);
@@ -195,7 +189,6 @@ RemapPlugins::run_plugin(remap_plugin_in
   }
 
   return plugin_retcode;
-
 }
 
 /**
@@ -219,7 +212,7 @@ RemapPlugins::run_single_remap()
   bool plugin_modified_port = false;
   bool plugin_modified_path = false;
 
-  int plugin_retcode = 1;
+  TSRemapStatus plugin_retcode = TSREMAP_DID_REMAP;
 
   char *origURLBuf = NULL;
   int origURLBufSize;
@@ -266,9 +259,8 @@ RemapPlugins::run_single_remap()
 
   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, origURLBuf, origURLBufSize, &plugin_modified_host, &plugin_modified_port,
+                                &plugin_modified_path);
   } else if (_cur > 0) {
     _cur++;
     Debug("url_rewrite",
@@ -278,7 +270,7 @@ RemapPlugins::run_single_remap()
     return 1;
   }
 
-  if ((!plugin && _cur == 0) || plugin_retcode == 0) {
+  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");

Modified: trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.h?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.h (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/RemapPlugins.h Thu Mar 17 14:00:51 2011
@@ -31,13 +31,12 @@
 #include "libts.h"
 #include "I_EventSystem.h"
 #include "RemapProcessor.h"
+#include "api/ts/ts.h"
 #include "api/ts/remap.h"
 #include "RemapPluginInfo.h"
 #include "HttpTransact.h"
 #include "ReverseProxy.h"
 
-static const unsigned int MAX_REMAP_PLUGIN_CHAIN = 10;
-
 /**
  * A class that represents a queue of plugins to run
 **/
@@ -58,7 +57,7 @@ struct RemapPlugins: public Continuation
 
   int run_remap(int, Event *);
   int run_single_remap();
-  int run_plugin(remap_plugin_info *, char *, int, bool *, bool *, bool *);
+  TSRemapStatus run_plugin(remap_plugin_info *, char *, int, bool *, bool *, bool *);
 
   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=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/UrlMapping.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/UrlMapping.cc Thu Mar 17 14:00:51 2011
@@ -30,18 +30,26 @@ url_mapping::url_mapping(int rank /* = 0
   : from_path_len(0), fromURL(), homePageRedirect(false), unique(false), default_redirect_url(false),
     optional_referer(false), negative_referer(false), wildcard_from_scheme(false),
     tag(NULL), filter_redirect_url(NULL), referer_list(0),
-    redir_chunk_list(0), filter(NULL), _plugin_count(0), _cur_instance_count(0), _rank(rank), _default_to_url()
+    redir_chunk_list(0), filter(NULL), _plugin_count(0), _rank(rank), _default_to_url()
 {
+  memset(_plugin_list, 0, sizeof(_plugin_list));
+  memset(_instance_data, 0, sizeof(_instance_data));
 }
 
 
 /**
  *
 **/
-bool url_mapping::add_plugin(remap_plugin_info * i)
+bool
+url_mapping::add_plugin(remap_plugin_info* i, void* ih)
 {
-  _plugin_list.push_back(i);
+  if (_plugin_count >= MAX_REMAP_PLUGIN_CHAIN)
+    return false;
+
+  _plugin_list[_plugin_count] = i;
+  _instance_data[_plugin_count] = ih;
   _plugin_count++;
+
   return true;
 }
 
@@ -49,92 +57,27 @@ bool url_mapping::add_plugin(remap_plugi
 /**
  *
 **/
-remap_plugin_info *
-url_mapping::get_plugin(unsigned int index)
+remap_plugin_info*
+url_mapping::get_plugin(unsigned int index) const
 {
   Debug("url_rewrite", "get_plugin says we have %d plugins and asking for plugin %d", _plugin_count, index);
-  if (_plugin_count == 0)
-    return NULL;
-
-  remap_plugin_info *plugin = NULL;
-
-  if (unlikely(index > _plugin_count)) {
+  if ((_plugin_count == 0) || unlikely(index > _plugin_count))
     return NULL;
-  }
 
-  std::deque<remap_plugin_info *>::iterator i;
-  unsigned int j = 0;
-
-  for (i = _plugin_list.begin(); i != _plugin_list.end(); i++) {
-    if (j == index) {
-      plugin = *i;
-      return plugin;
-    }
-    j++;
-  }
-
-  Debug("url_rewrite", "url_mapping::get_plugin could not find requested plugin");
-  return NULL;
+  return _plugin_list[_plugin_count];
 }
 
-
-/**
- *
-**/
-bool url_mapping::set_instance(remap_plugin_info * p, ihandle * h)
-{
-  Debug("url_rewrite", "Adding handle: %x to instance map for plugin: %x (%s) [cur:%d]", h, p, p->path, _cur_instance_count);
-  _instance_map[p] = h;
-  return true;
-}
-
-
-/**
- *
-**/
-ihandle *
-url_mapping::get_instance(remap_plugin_info * p)
-{
-  Debug("url_rewrite", "Requesting instance handle for plugin: %x [%s]", p, p->path);
-  ihandle *h = _instance_map[p];
-
-  Debug("url_rewrite", "Found instance handle: %x for plugin: %x [%s]", h, p, p->path);
-  return h;
-}
-
-/**
- *
-**/
-ihandle *
-url_mapping::get_another_instance(remap_plugin_info * p)
-{
-  ihandle *ih = NEW(new ihandle);
-
-  _cur_instance_count++;
-  if (_cur_instance_count >= 15) {
-    Error("Cant have more than 15 remap handles!");
-    Debug("url_rewrite", "Cant have more than 15 remap handles!");
-    abort();
-  }
-  set_instance(p, ih);
-  return ih;
-}
-
-
 /**
  *
 **/
 void
-url_mapping::delete_instance(remap_plugin_info * p)
+url_mapping::delete_instance(unsigned int index)
 {
-  Debug("url_rewrite", "Deleting instance handle and plugin for %x [%s]", p, p->path);
-  _cur_instance_count--;
-  ihandle *ih = get_instance(p);
-
-  if (ih && p && p->fp_tsremap_delete_instance) {
-    p->fp_tsremap_delete_instance(*ih);
-    delete ih;
-  }
+  void *ih = get_instance(index);
+  remap_plugin_info* p = get_plugin(index);
+
+  if (ih && p && p->fp_tsremap_delete_instance)
+    p->fp_tsremap_delete_instance(ih);
 }
 
 
@@ -150,28 +93,26 @@ url_mapping::~url_mapping()
   if (tag) {
     tag = (char *) xfree_null(tag);
   }
+
   if (filter_redirect_url) {
     filter_redirect_url = (char *) xfree_null(filter_redirect_url);
   }
+
   while ((r = referer_list) != 0) {
     referer_list = r->next;
     delete r;
   }
+
   while ((rc = redir_chunk_list) != 0) {
     redir_chunk_list = rc->next;
     delete rc;
   }
 
-  //iterate all plugins and delete them
-  std::deque<remap_plugin_info *>::iterator i;
-  remap_plugin_info *plugin = NULL;
-
-  for (i = _plugin_list.begin(); i != _plugin_list.end(); i++) {
-    plugin = *i;
-    if (plugin)
-      delete_instance(plugin);
-  }
+  // Delete all instance data
+  for (unsigned int i = 0; i < _plugin_count; ++i)
+    delete_instance(i);
 
+  // Delete filters
   while ((afr = filter) != NULL) {
     filter = afr->next;
     delete afr;
@@ -229,7 +170,7 @@ redirect_tag_str::parse_format_redirect_
 /**
  *
 **/
-referer_info::referer_info(char *_ref, bool * error_flag, char *errmsgbuf, int errmsgbuf_size):next(0), referer(0), referer_size(0), any(false), negative(false),
+referer_info::referer_info(char *_ref, bool *error_flag, char *errmsgbuf, int errmsgbuf_size):next(0), referer(0), referer_size(0), any(false), negative(false),
 regx_valid(false)
 {
   const char *error;

Modified: trafficserver/traffic/trunk/proxy/http/remap/UrlMapping.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/UrlMapping.h?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/UrlMapping.h (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/UrlMapping.h Thu Mar 17 14:00:51 2011
@@ -25,8 +25,6 @@
 #define _URL_MAPPING_H_
 
 #include "AclFiltering.h"
-#include <deque>
-#include <map>
 #include "Main.h"
 #include "Error.h"
 #include "URL.h"
@@ -38,6 +36,9 @@
 #include <pcre.h>
 #endif
 
+static const unsigned int MAX_REMAP_PLUGIN_CHAIN = 10;
+
+
 /**
  * Used to store http referer strings (and/or regexp)
 **/
@@ -89,12 +90,11 @@ public:
   url_mapping(int rank = 0);
   ~url_mapping();
 
-  bool add_plugin(remap_plugin_info *);
-  remap_plugin_info *get_plugin(unsigned int);
+  bool add_plugin(remap_plugin_info *i, void* ih);
+  remap_plugin_info *get_plugin(unsigned int) const;
 
-  ihandle *get_instance(remap_plugin_info *);
-  ihandle *get_another_instance(remap_plugin_info * p);
-  void delete_instance(remap_plugin_info * p);
+  void* get_instance(unsigned int index) const { return _instance_data[index]; };
+  void delete_instance(unsigned int index);
 
   int from_path_len;
   URL fromURL;
@@ -115,10 +115,8 @@ public:
   int getRank() const { return _rank; };
 
 private:
-  bool set_instance(remap_plugin_info *, ihandle *);
-  std::deque<remap_plugin_info *>_plugin_list;
-  std::map<remap_plugin_info *, ihandle *>_instance_map;
-  int _cur_instance_count;
+  remap_plugin_info* _plugin_list[MAX_REMAP_PLUGIN_CHAIN];
+  void* _instance_data[MAX_REMAP_PLUGIN_CHAIN];
   int _rank;
   URL _default_to_url;
 

Modified: trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc Thu Mar 17 14:00:51 2011
@@ -1686,12 +1686,12 @@ UrlRewrite::load_remap_plugin(char *argv
       snprintf(errbuf, errbufsize, "Can't load plugin \"%s\" - %s", c, err ? err : "Unknown dlopen() error");
       return -4;
     }
-    pi->fp_tsremap_init = (_tsremap_init *) dlsym(pi->dlh, TSREMAP_FUNCNAME_INIT);
-    pi->fp_tsremap_done = (_tsremap_done *) dlsym(pi->dlh, TSREMAP_FUNCNAME_DONE);
-    pi->fptsremap_new_instance = (_tsremap_new_instance *) dlsym(pi->dlh, TSREMAP_FUNCNAME_NEW_INSTANCE);
-    pi->fp_tsremap_delete_instance = (_tsremap_delete_instance *) dlsym(pi->dlh, TSREMAP_FUNCNAME_DELETE_INSTANCE);
-    pi->fp_tsremap_remap = (_tsremap_remap *) dlsym(pi->dlh, TSREMAP_FUNCNAME_REMAP);
-    pi->fp_tsremap_os_response = (_tsremap_os_response *) dlsym(pi->dlh, TSREMAP_FUNCNAME_OS_RESPONSE);
+    pi->fp_tsremap_init = (remap_plugin_info::_tsremap_init *) dlsym(pi->dlh, TSREMAP_FUNCNAME_INIT);
+    pi->fp_tsremap_done = (remap_plugin_info::_tsremap_done *) dlsym(pi->dlh, TSREMAP_FUNCNAME_DONE);
+    pi->fptsremap_new_instance = (remap_plugin_info::_tsremap_new_instance *) dlsym(pi->dlh, TSREMAP_FUNCNAME_NEW_INSTANCE);
+    pi->fp_tsremap_delete_instance = (remap_plugin_info::_tsremap_delete_instance *) dlsym(pi->dlh, TSREMAP_FUNCNAME_DELETE_INSTANCE);
+    pi->fp_tsremap_do_remap = (remap_plugin_info::_tsremap_do_remap *) dlsym(pi->dlh, TSREMAP_FUNCNAME_DO_REMAP);
+    pi->fp_tsremap_os_response = (remap_plugin_info::_tsremap_os_response *) dlsym(pi->dlh, TSREMAP_FUNCNAME_OS_RESPONSE);
 
     if (!pi->fp_tsremap_init) {
       snprintf(errbuf, errbufsize, "Can't find \"%s\" function in remap plugin \"%s\"", TSREMAP_FUNCNAME_INIT, c);
@@ -1700,8 +1700,8 @@ UrlRewrite::load_remap_plugin(char *argv
       snprintf(errbuf, errbufsize, "Can't find \"%s\" function in remap plugin \"%s\"",
                    TSREMAP_FUNCNAME_NEW_INSTANCE, c);
       retcode = -11;
-    } else if (!pi->fp_tsremap_remap) {
-      snprintf(errbuf, errbufsize, "Can't find \"%s\" function in remap plugin \"%s\"", TSREMAP_FUNCNAME_REMAP, c);
+    } else if (!pi->fp_tsremap_do_remap) {
+      snprintf(errbuf, errbufsize, "Can't find \"%s\" function in remap plugin \"%s\"", TSREMAP_FUNCNAME_DO_REMAP, c);
       retcode = -12;
     }
     if (retcode) {
@@ -1714,9 +1714,8 @@ UrlRewrite::load_remap_plugin(char *argv
     memset(&ri, 0, sizeof(ri));
     ri.size = sizeof(ri);
     ri.tsremap_version = TSREMAP_VERSION;
-    ri.fp_tsremap_interface = NULL;     /* we don't need it now */
 
-    if ((retcode = pi->fp_tsremap_init(&ri, tmpbuf, sizeof(tmpbuf) - 1)) != 0) {
+    if (pi->fp_tsremap_init(&ri, tmpbuf, sizeof(tmpbuf) - 1) != TS_SUCCESS) {
       Error("Failed to initialize plugin %s (non-zero retval) ... bailing out", pi->path);
       exit(-1);                 //see my comment re: exit() about 60 lines down
     }
@@ -1770,16 +1769,19 @@ UrlRewrite::load_remap_plugin(char *argv
     Debug("url_rewrite", "Argument %d: %s", k, parv[k]);
   }
 
-  ihandle *ih = mp->get_another_instance(pi);
+  void* ih;
+
   Debug("remap_plugin", "creating new plugin instance");
-  retcode = pi->fptsremap_new_instance(parc, parv, ih, tmpbuf, sizeof(tmpbuf) - 1);
+  TSReturnCode res = pi->fptsremap_new_instance(parc, parv, &ih, tmpbuf, sizeof(tmpbuf) - 1);
+
   Debug("remap_plugin", "done creating new plugin instance");
 
   xfree(parv[0]);               // fromURL
   xfree(parv[1]);               // toURL
 
-  if (retcode != 0) {
-    mp->delete_instance(pi);
+  if (res != TS_SUCCESS) {
+    // TODO: This is such serious failure, no reason to try to delete the instance.
+    // mp->delete_instance(pi);
     snprintf(errbuf, errbufsize, "Can't create new remap instance for plugin \"%s\" - %s", c,
                  tmpbuf[0] ? tmpbuf : "Unknown plugin error");
     Error("Failed to create new instance for plugin %s (non-zero retval)... bailing out", pi->path);
@@ -1796,7 +1798,7 @@ UrlRewrite::load_remap_plugin(char *argv
     return -6;
   }
 
-  mp->add_plugin(pi);
+  mp->add_plugin(pi, ih);
 
   return 0;
 }

Modified: trafficserver/traffic/trunk/tools/apichecker.pl
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/tools/apichecker.pl?rev=1082493&r1=1082492&r2=1082493&view=diff
==============================================================================
--- trafficserver/traffic/trunk/tools/apichecker.pl (original)
+++ trafficserver/traffic/trunk/tools/apichecker.pl Thu Mar 17 14:00:51 2011
@@ -75,6 +75,7 @@ sub ink2ts {
   return $ret;
 }
 
+# ts/ts.h warnings
 my $W_TSRETURNCODE = "returns TSReturnCode, check for == TS_SUCCESS (and not 0|1)";
 my $W_RETURN_DIRECT = "returns the value directly, it can not fail (don't check for TS_ERROR)";
 my $W_TSPARSERESULT = "returns TSParseResult, do not check for e.g. TS_ERROR";
@@ -90,9 +91,23 @@ my $W_TIME_T = "returns the time_t direc
 my $W_NOT_NULL_LEN = "the length parameter can no longer be a NULL pointer";
 my $W_TSCACHEKEY = "returns a TSCacheKey directly";
 my $W_TSAIOCALLBACK = "uses the new TSAIOCallback data type";
+my $W_DEPRECATED = "is deprecated, do not use (ever!)";
 my $W_NO_NULL_LENGTH = "1";
 my $W_NO_ERROR_PTR = "2";
-
+my $W_RENAMED = "3";
+# ts/remap.h warnings
+my $W_IHANDLE = "is deprecated, use a plain void* instead";
+my $W_TSREMAPSTATUS = "returns TSRemapStatus, return appropriate message";
+
+my %RENAMED = (
+  "tsremap_init" => "TSRemapInit",
+  "tsremap_done" => "TSRemapDone",
+  "tsremap_new_instance" => "TSRemapNewInstance",
+  "tsremap_delete_instance" => "TSRemapDeleteInstance",
+  "tsremap_remap" => "TSRemapDoRemap",
+  "tsremap_os_response" => "TSRemapOSResponse",
+  "rhandle" => "TSHttpTXN",
+);
 
 my %TWO_2_THREE = (
   "TSPluginRegister" => [$W_TSRETURNCODE],
@@ -228,12 +243,39 @@ my %TWO_2_THREE = (
   "TS_ERROR_PTR" => [$W_NO_ERROR_PTR],
   "TSAIOBufGet" => [$W_TSAIOCALLBACK],
   "TSAIONBytesGet" => [$W_TSAIOCALLBACK],
+  # Remap API changes
+  "TSREMAP_INTERFACE" => [$W_DEPRECATED],
+  "tsremap_interface" => [$W_DEPRECATED],
+  "fp_tsremap_interface" => [$W_DEPRECATED],
+  "TSREMAP_FUNCNAME_INIT" => [$W_DEPRECATED],
+  "TSREMAP_FUNCNAME_DONE" => [$W_DEPRECATED],
+  "TSREMAP_FUNCNAME_NEW_INSTANCE" => [$W_DEPRECATED],
+  "TSREMAP_FUNCNAME_DELETE_INSTANCE" => [$W_DEPRECATED],
+  "TSREMAP_FUNCNAME_REMAP" => [$W_DEPRECATED],
+  "TSREMAP_FUNCNAME_OS_RESPONSE" => [$W_DEPRECATED],
+  "base_handle" => [$W_DEPRECATED],
+  "ihandle" => [$W_IHANDLE],
+  "rhandle" => [$W_RENAMED],
+  "tsremap_init" => [$W_RENAMED, $W_TSRETURNCODE],
+  "tsremap_done" =>  [$W_RENAMED],
+  "tsremap_new_instance" =>  [$W_RENAMED, $W_TSRETURNCODE],
+  "tsremap_delete_instance" =>  [$W_RENAMED],
+  "tsremap_remap" =>  [$W_RENAMED, $W_TSREMAPSTATUS],
+  "tsremap_os_response" => [$W_RENAMED],
 );
 
 
 #
 # Warning messages related to SDK v2 to v3 migration
 #
+sub header_write {
+  my $do_it = shift;
+  my $tok = shift;
+
+  print "--> $tok() <--\n" if $do_it;
+  return 0;
+}
+
 sub two2three {
   my $tokens = shift || return;
   my $line = shift || return;
@@ -241,18 +283,25 @@ sub two2three {
 
   return 0 if $line =~ /TSDebug/;
   foreach my $tok (@{$tokens}) {
+    my $hdr_write = 1;
     my $warns = $TWO_2_THREE{$tok};
     next unless $warns;
 
     foreach my $w (@{$warns}) {
       if ($w eq $W_NO_NULL_LENGTH) {
-        print "--> $tok() <--\n";
-        print "    + The length output parameter can not be NULL\n" if $line =~ /NULL/;
+        if ($line =~ /NULL/) {
+          print "    + The length output parameter can not be NULL\n";
+          $hdr_write = header_write($hdr_write, $tok);
+        }
       } elsif ($w eq $W_NO_ERROR_PTR) {
-        print "--> TS_ERROR_PTR <--\n";
+        $hdr_write = header_write($hdr_write, "TS_ERROR_PTR");
         print "    + no APIs can return TS_ERROR_PTR, you should not compare it\n";
+      } elsif ($w eq $W_RENAMED) {
+        $hdr_write = header_write($hdr_write, $tok);
+        print "    + is renamed to $RENAMED{$tok}\n";
       } else {
-        print "--> $tok() <--\n    + $w\n";
+        $hdr_write = header_write($hdr_write, $tok);
+        print "    + $w\n";
       }
     }
     $ret = 1;