Github user shinrich commented on a diff in the pull request:

    https://github.com/apache/trafficserver/pull/1111#discussion_r83489086
  
    --- Diff: plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc 
---
    @@ -265,49 +307,69 @@ collapsed_cont(TSCont contp, TSEvent event, void 
*edata)
       return TS_SUCCESS;
     }
     
    -TSReturnCode
    -TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* 
errbuf_size */)
    -{
    -  TSDebug(DEBUG_TAG, "plugin is succesfully initialized");
    -  return TS_SUCCESS;
    -}
    -
    -TSReturnCode
    -TSRemapNewInstance(int argc, char *argv[], void ** /* ih */, char * /* 
errbuf */, int /* errbuf_size */)
    +void
    +process_args(int argc, const char **argv)
     {
       // basic argv processing..
    -  for (int i = 2; i < argc; ++i) {
    +  for (int i = 1; i < argc; ++i) {
         if (strncmp(argv[i], "--delay=", 8) == 0) {
           OPEN_WRITE_FAIL_REQ_DELAY_TIMEOUT = atoi((char *)(argv[i] + 8));
         } else if (strncmp(argv[i], "--retries=", 10) == 0) {
           OPEN_WRITE_FAIL_MAX_REQ_DELAY_RETRIES = atoi((char *)(argv[i] + 10));
         }
       }
    -
    -  return TS_SUCCESS;
     }
     
    -TSRemapStatus
    -TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
    +/*
    + * Initialize globally
    + */
    +void
    +TSPluginInit(int argc, const char *argv[])
     {
    +  TSPluginRegistrationInfo info;
    +
    +  info.plugin_name   = (char *)DEBUG_TAG;
    +  info.vendor_name   = (char *)"Apache Software Foundation";
    +  info.support_email = (char *)"d...@trafficserver.apache.org";
    +
    +  if (TS_SUCCESS != TSPluginRegister(&info)) {
    +    TSError("[%s] Plugin registration failed.", DEBUG_TAG);
    +  }
    +
    +  process_args(argc, argv);
    +
       TSCont cont = TSContCreate(collapsed_cont, TSMutexCreate());
     
    -  RequestData *req_data = new RequestData();
    +  TSDebug(DEBUG_TAG, "Global Initialized");
    +  // Set up the per transaction state in the READ_REQUEST event
    +  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont);
     
    -  req_data->txnp     = rh;
    -  req_data->wl_retry = 0;
    +  global_init = true;
    +}
     
    -  int url_len = 0;
    -  char *url   = TSHttpTxnEffectiveUrlStringGet(rh, &url_len);
    -  req_data->req_url.assign(url, url_len);
    +TSReturnCode
    +TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* 
errbuf_size */)
    +{
    +  if (global_init) {
    +    TSError("Cannot initialize %s as both global and remap plugin", 
DEBUG_TAG);
    +    return TS_ERROR;
    +  } else {
    +    TSDebug(DEBUG_TAG, "plugin is succesfully initialized for remap");
    +    return TS_SUCCESS;
    +  }
    +}
     
    -  TSfree(url);
    -  TSContDataSet(cont, req_data);
    +TSReturnCode
    +TSRemapNewInstance(int argc, char *argv[], void ** /* ih */, char * /* 
errbuf */, int /* errbuf_size */)
    +{
    +  process_args(argc, const_cast<const char **>(argv + 1));
    --- End diff --
    
    Updated new version that decrements argc appropriately.  Verified that it 
is correct in the remap case.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to