You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by fa...@locus.apache.org on 2000/09/22 22:23:21 UTC

cvs commit: apache-1.3/src/modules/standard mod_rewrite.c mod_rewrite.h

fanf        00/09/22 13:23:20

  Modified:    src/modules/standard mod_rewrite.c mod_rewrite.h
  Log:
  Replace four instances of some broken code with calls to a function
  containing the same broken code. This is just a cosmetic improvement
  in preparation for fixing the code.
  
  Revision  Changes    Path
  1.159     +47 -50    apache-1.3/src/modules/standard/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v
  retrieving revision 1.158
  retrieving revision 1.159
  diff -u -u -r1.158 -r1.159
  --- mod_rewrite.c	2000/07/14 20:01:55	1.158
  +++ mod_rewrite.c	2000/09/22 20:23:15	1.159
  @@ -1745,7 +1745,6 @@
       char *output;
       const char *vary;
       char newuri[MAX_STRING_LEN];
  -    char env[MAX_STRING_LEN];
       regex_t *regexp;
       regmatch_t regmatch[MAX_NMATCH];
       backrefinfo *briRR = NULL;
  @@ -1913,20 +1912,7 @@
        *  (`RewriteRule <pat> - [E=...]')
        */
       if (strcmp(output, "-") == 0) {
  -        for (i = 0; p->env[i] != NULL; i++) {
  -            /*  1. take the string  */
  -            ap_cpystrn(env, p->env[i], sizeof(env));
  -            /*  2. expand $N (i.e. backrefs to RewriteRule pattern)  */
  -            expand_backref_inbuffer(r->pool, env, sizeof(env), briRR, '$');
  -            /*  3. expand %N (i.e. backrefs to latest RewriteCond pattern)  */
  -            expand_backref_inbuffer(r->pool, env, sizeof(env), briRC, '%');
  -            /*  4. expand %{...} (i.e. variables) */
  -            expand_variables_inbuffer(r, env, sizeof(env));
  -            /*  5. expand ${...} (RewriteMap lookups)  */
  -            expand_map_lookups(r, env, sizeof(env));
  -            /*  and add the variable to Apache's structures  */
  -            add_env_variable(r, env);
  -        }
  +	do_expand_env(r, p->env, briRR, briRC);
           if (p->forced_mimetype != NULL) {
               if (perdir == NULL) {
                   /* In the per-server context we can force the MIME-type
  @@ -1961,17 +1947,7 @@
        *  that there is something to replace, so we create the
        *  substitution URL string in `newuri'.
        */
  -    /*  1. take the output string  */
  -    ap_cpystrn(newuri, output, sizeof(newuri));
  -    /*  2. expand $N (i.e. backrefs to RewriteRule pattern)  */
  -    expand_backref_inbuffer(r->pool, newuri, sizeof(newuri), briRR, '$');
  -    /*  3. expand %N (i.e. backrefs to latest RewriteCond pattern)  */
  -    expand_backref_inbuffer(r->pool, newuri, sizeof(newuri), briRC, '%');
  -    /*  4. expand %{...} (i.e. variables) */
  -    expand_variables_inbuffer(r, newuri, sizeof(newuri));
  -    /*  5. expand ${...} (RewriteMap lookups)  */
  -    expand_map_lookups(r, newuri, sizeof(newuri));
  -    /*  and log the result... */
  +    do_expand(r, output, newuri, sizeof(newuri), briRR, briRC);
       if (perdir == NULL) {
           rewritelog(r, 2, "rewrite %s -> %s", uri, newuri);
       }
  @@ -1983,20 +1959,7 @@
        *  Additionally do expansion for the environment variable
        *  strings (`RewriteRule .. .. [E=<string>]').
        */
  -    for (i = 0; p->env[i] != NULL; i++) {
  -        /*  1. take the string  */
  -        ap_cpystrn(env, p->env[i], sizeof(env));
  -        /*  2. expand $N (i.e. backrefs to RewriteRule pattern)  */
  -        expand_backref_inbuffer(r->pool, env, sizeof(env), briRR, '$');
  -        /*  3. expand %N (i.e. backrefs to latest RewriteCond pattern)  */
  -        expand_backref_inbuffer(r->pool, env, sizeof(env), briRC, '%');
  -        /*  4. expand %{...} (i.e. variables) */
  -        expand_variables_inbuffer(r, env, sizeof(env));
  -        /*  5. expand ${...} (RewriteMap lookups)  */
  -        expand_map_lookups(r, env, sizeof(env));
  -        /*  and add the variable to Apache's structures  */
  -        add_env_variable(r, env);
  -    }
  +    do_expand_env(r, p->env, briRR, briRC);
   
       /*
        *  Now replace API's knowledge of the current URI:
  @@ -2163,16 +2126,7 @@
        *   Construct the string we match against
        */
   
  -    /*  1. take the string  */
  -    ap_cpystrn(input, p->input, sizeof(input));
  -    /*  2. expand $N (i.e. backrefs to RewriteRule pattern)  */
  -    expand_backref_inbuffer(r->pool, input, sizeof(input), briRR, '$');
  -    /*  3. expand %N (i.e. backrefs to latest RewriteCond pattern)  */
  -    expand_backref_inbuffer(r->pool, input, sizeof(input), briRC, '%');
  -    /*  4. expand %{...} (i.e. variables) */
  -    expand_variables_inbuffer(r, input, sizeof(input));
  -    /*  5. expand ${...} (RewriteMap lookups)  */
  -    expand_map_lookups(r, input, sizeof(input));
  +    do_expand(r, p->input, input, sizeof(input), briRR, briRC);
   
       /*
        *   Apply the patterns
  @@ -2313,6 +2267,49 @@
   ** |                                                       |
   ** +-------------------------------------------------------+
   */
  +
  +
  +/*
  +**
  +**  perform all the expansions on the input string
  +**  leaving the result in the supplied buffer
  +**
  +*/
  +
  +static void do_expand(request_rec *r, char *input, char *buffer, int nbuf,
  +		       backrefinfo *briRR, backrefinfo *briRC)
  +{
  +    /*  1. take the string  */
  +    ap_cpystrn(buffer, input, nbuf);
  +    /*  2. expand $N (i.e. backrefs to RewriteRule pattern)  */
  +    expand_backref_inbuffer(r->pool, buffer, nbuf, briRR, '$');
  +    /*  3. expand %N (i.e. backrefs to latest RewriteCond pattern)  */
  +    expand_backref_inbuffer(r->pool, buffer, nbuf, briRC, '%');
  +    /*  4. expand %{...} (i.e. variables) */
  +    expand_variables_inbuffer(r, buffer, nbuf);
  +    /*  5. expand ${...} (RewriteMap lookups)  */
  +    expand_map_lookups(r, buffer, nbuf);
  +}
  +
  +
  +/*
  +**
  +**  perform all the expansions on the environment variables
  +**
  +*/
  +
  +static void do_expand_env(request_rec *r, char *env[],
  +			  backrefinfo *briRR, backrefinfo *briRC)
  +{
  +    int i;
  +    char buf[MAX_STRING_LEN];
  +
  +    for (i = 0; env[i] != NULL; i++) {
  +	do_expand(r, env[i], buf, sizeof(buf), briRR, briRC);
  +	add_env_variable(r, buf);
  +    }
  +}
  +
   
   /*
   **
  
  
  
  1.68      +5 -0      apache-1.3/src/modules/standard/mod_rewrite.h
  
  Index: mod_rewrite.h
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.h,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -u -r1.67 -r1.68
  --- mod_rewrite.h	2000/09/14 11:54:14	1.67
  +++ mod_rewrite.h	2000/09/22 20:23:15	1.68
  @@ -420,6 +420,11 @@
                                 char *perdir, backrefinfo *briRR,
                                 backrefinfo *briRC);
   
  +static void do_expand(request_rec *r, char *input, char *buffer, int nbuf,
  +		       backrefinfo *briRR, backrefinfo *briRC);
  +static void do_expand_env(request_rec *r, char *env[],
  +			  backrefinfo *briRR, backrefinfo *briRC);
  +
       /* URI transformation function */
   static void  splitout_queryargs(request_rec *r, int qsappend);
   static void  fully_qualify_uri(request_rec *r);