You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficserver.apache.org by "James Peach (JIRA)" <ji...@apache.org> on 2013/08/01 00:09:48 UTC

[jira] [Commented] (TS-2008) Cache control with multiple suffixes

    [ https://issues.apache.org/jira/browse/TS-2008?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13725768#comment-13725768 ] 

James Peach commented on TS-2008:
---------------------------------

That's a more promising approach. There's 2 problems with it; (1) it parses the string and allocates memory on the fast checking path (2) it's not extensible to other tags where multiple values could make sense

I spent some time looking at this but was not able to get a complete change finished. I think that the right way to approach this is to implement a new MultiTextMod() class. This should split the configured string in it's set() method. MultiTextMod can then be used as a base class for SuffixMod or any other control class where comma-separated values are appropriate.

MultiTextMod would look a bit like this:

{code}
struct MultiTextMod : public ControlBase::Modifier {

  MultiTextMod();
  ~MultiTextMod();

  // Copy the value to the MultiTextMod buffer.
  void set(const char * value);

  // Calls name() which the subclass must provide.
  virtual void print(FILE* f) const;

  bool multimatch(const char * val, size_t len) const;
};

MultiTextMod::MultiTextMod() {}
MultiTextMod::~MultiTextMod() {
}

void MultiTextMod::print(FILE* f) const {
  fprintf(f, "%s=XXX ", this->name());
}

void MultiTextMod::set(const char * value) {
  // XXX  split the string and store it, possibly as a Vec<ts:Buffer>
}

bool MultiTextMod::multimatch(const char * val, size_t len) const {
  // XXX match the given string against the stored list
}

{code}
                
> Cache control with multiple suffixes
> ------------------------------------
>
>                 Key: TS-2008
>                 URL: https://issues.apache.org/jira/browse/TS-2008
>             Project: Traffic Server
>          Issue Type: New Feature
>          Components: Cache, HTTP
>    Affects Versions: 3.3.4
>            Reporter: bettydramit
>            Assignee: James Peach
>             Fix For: 3.5.0
>
>         Attachments: ControlMatcher.patch, ts-2008.patch
>
>
> if you want to control on ver many suffix in cache.config: jpeg js ... you need to specify:
> dest_domain=www.test.com suffix=jpeg ttl-in-cache=1m
> dest_domain=www.test.com suffix=js ttl-in-cache=1m
> ...
> and we can change to :
> dest_domain=www.test.com suffix=jpeg,js,css,html ttl-in-cache=1m
> by this patch:
> {code}
> diff -Nur ts-3.3.1/proxy/ControlMatcher.cc ts-3.3.1-new/proxy/ControlMatcher.cc
> --- ts-3.3.1/proxy/ControlMatcher.cc    2013-03-10 03:44:28.000000000 +0800
> +++ ts-3.3.1-new/proxy/ControlMatcher.cc        2013-07-08 22:42:31.568980245 +0800
> @@ -44,7 +44,7 @@
>  #include "P_Cache.h"
>  #include "P_SplitDNS.h"
>  #include "congest/Congestion.h"
> -
> +#include <string>
>  /****************************************************************
>   *   Place all template instantiations at the bottom of the file
>   ****************************************************************/
> @@ -815,6 +815,63 @@
>    if (file_buf == NULL) {
>      return 1;
>    }
> +  /* add by reggie */
> +  if(strcmp("[CacheControl]",matcher_name) == 0){
> +       Debug("reggie-suffix","file_string is begin" );
> +       char *strbuffern = NULL;
> +       char *strfile_buf = file_buf, *tmpvalue = NULL;
> +       char *cp_line[64];
> +       int in = 0;
> +       char buffer1[128] = {0};
> +       char *outer_ptr=NULL;
> +       std::string file_string;
> +       while((strbuffern = strtok_r(strfile_buf,"\n",&outer_ptr)) != NULL){
> +               Debug("reggie-suffix","strbuffern  is %s",strbuffern);
> +               if(*strbuffern == '#'){
> +                       Debug("reggie-suffix","# is %s ",strbuffern);
> +                       strfile_buf = NULL; 
> +                       continue;
> +               }
> +               if((strchr(strbuffern,',')) != NULL){
> +                       in = 0;
> +                       while((cp_line[in]=strtok(strbuffern," "))!=NULL) {
> +                               strbuffern = NULL;
> +                               in++;
> +                       }
> +                       if((strchr(cp_line[1],'=') != NULL) && (strstr(cp_line[1],"suffix"))){
> +                               if((cp_line[in] = strtok(cp_line[1],"=")) != NULL)
> +                                       tmpvalue = strtok(NULL,"=");
> +                               while((cp_line[in] = strtok(tmpvalue,",")) != NULL){
> +                                       in++;
> +                                       tmpvalue = NULL;
> +                               } 
> +                       }
> +                       for(int nk = 3; nk < in ;nk++){
> +                               //nbuf_len = strlen(cp_line[0]) + strlen(cp_line[2]) +strlen(cp_line[nk]) + 9;
> +                               //snprintf(buffer1,nbuf_len,"%s suffix=%s %s\n",cp_line[0],cp_line[nk],cp_line[2]);
> +                               sprintf(buffer1,"%s suffix=%s %s\n",cp_line[0],cp_line[nk],cp_line[2]);
> +                               file_string.append(buffer1);
> +                       }
> +               }
> +               else{
> +                       file_string.append(strbuffern);
> +                       file_string += "\n";
> +               }
> +               strfile_buf = NULL;
> +       }
> +      //file_string.erase(file_string.end()-1);
> +       Debug("reggie_suffix","file_string is %s ",file_string.c_str());
> +       ats_free(file_buf);
> +       file_buf = (char*) ats_malloc(file_string.size()+1);
> +       if(strcpy(file_buf,file_string.c_str()) == NULL){
> +               ats_free(file_buf);
> +               return 2;
> +       }
> +       ret = BuildTableFromString(file_buf);
> +       ats_free(file_buf);
> +       return ret;
> +  }
> +         /*end by reggie */
>  
>    ret = BuildTableFromString(file_buf);
>    ats_free(file_buf);
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira