httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n.@apache.org
Subject cvs commit: httpd-2.0/modules/mappers mod_rewrite.c
Date Tue, 19 Aug 2003 00:36:59 GMT
nd          2003/08/18 17:36:59

  Modified:    .        CHANGES
               modules/mappers mod_rewrite.c
  Log:
  Fix LA-U and LA-F lookups in directory context. Previously
  the current rewrite state was just used as lookup path, which lead to
  strange and often useless results.
  
  Related to PR 8493.
  
  Revision  Changes    Path
  1.1255    +4 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.1254
  retrieving revision 1.1255
  diff -u -r1.1254 -r1.1255
  --- CHANGES	15 Aug 2003 02:25:40 -0000	1.1254
  +++ CHANGES	19 Aug 2003 00:36:58 -0000	1.1255
  @@ -2,6 +2,10 @@
   
     [Remove entries to the current 2.0 section below, when backported]
   
  +  *) mod_rewrite: Fix LA-U and LA-F lookups in directory context. Previously
  +     the current rewrite state was just used as lookup path, which lead to
  +     strange and often useless results. Related to PR 8493.  [André Malo]
  +
     *) Change Listen directive to bind to all addresses when a hostname is
        not specified.  [Justin Erenkrantz]
   
  
  
  
  1.227     +51 -9     httpd-2.0/modules/mappers/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_rewrite.c,v
  retrieving revision 1.226
  retrieving revision 1.227
  diff -u -r1.226 -r1.227
  --- mod_rewrite.c	18 Aug 2003 21:57:45 -0000	1.226
  +++ mod_rewrite.c	19 Aug 2003 00:36:58 -0000	1.227
  @@ -1584,6 +1584,25 @@
   }
   
   /*
  + * lookahead helper function
  + * Determine the correct URI path in perdir context
  + */
  +static APR_INLINE const char *la_u(exp_ctx *ctx)
  +{
  +    rewrite_perdir_conf *conf;
  +
  +    if (*ctx->uri == '/') {
  +        return ctx->uri;
  +    }
  +
  +    conf = ap_get_module_config(ctx->r->per_dir_config, &rewrite_module);
  +
  +    return apr_pstrcat(ctx->r->pool, conf->baseurl
  +                                     ? conf->baseurl : conf->directory,
  +                       ctx->uri, NULL);
  +}
  +
  +/*
    * generic variable lookup
    */
   static char *lookup_variable(char *var, exp_ctx *ctx)
  @@ -1616,34 +1635,57 @@
       else if (var[4] == ':') {
           if (var[5]) {
               request_rec *rr;
  +            const char *path;
   
               if (!strncasecmp(var, "HTTP", 4)) {
                   result = lookup_header(r, var+5);
               }
               else if (!strncasecmp(var, "LA-U", 4)) {
  -                if (r->filename && subreq_ok(r)) {
  -                    rr = ap_sub_req_lookup_uri(ctx->uri, r, NULL);
  +                if (ctx->uri && subreq_ok(r)) {
  +                    path = ctx->perdir ? la_u(ctx) : ctx->uri;
  +                    rr = ap_sub_req_lookup_uri(path, r, NULL);
                       ctx->r = rr;
                       result = apr_pstrdup(r->pool, lookup_variable(var+5, ctx));
                       ctx->r = r;
                       ap_destroy_sub_req(rr);
   
  -                    rewritelog((r, 5, NULL,"lookahead: path=%s var=%s -> val=%s",
  -                                r->filename, var+5, result));
  +                    rewritelog((r, 5, ctx->perdir, "lookahead: path=%s var=%s "
  +                                "-> val=%s", path, var+5, result));
   
                       return (char *)result;
                   }
               }
               else if (!strncasecmp(var, "LA-F", 4)) {
  -                if (r->filename && subreq_ok(r)) {
  -                    rr = ap_sub_req_lookup_file(ctx->uri, r, NULL);
  +                if (ctx->uri && subreq_ok(r)) {
  +                    path = ctx->uri;
  +                    if (ctx->perdir && *path == '/') {
  +                        /* sigh, the user wants a file based subrequest, but
  +                         * we can't do one, since we don't know what the file
  +                         * path is! In this case behave like LA-U.
  +                         */
  +                        rr = ap_sub_req_lookup_uri(path, r, NULL);
  +                    }
  +                    else {
  +                        if (ctx->perdir) {
  +                            rewrite_perdir_conf *conf;
  +
  +                            conf = ap_get_module_config(r->per_dir_config,
  +                                                        &rewrite_module);
  +
  +                            path = apr_pstrcat(r->pool, conf->directory, path,
  +                                               NULL);
  +                        }
  +
  +                        rr = ap_sub_req_lookup_file(path, r, NULL);
  +                    }
  +
                       ctx->r = rr;
                       result = apr_pstrdup(r->pool, lookup_variable(var+5, ctx));
                       ctx->r = r;
                       ap_destroy_sub_req(rr);
   
  -                    rewritelog((r, 5, NULL,"lookahead: path=%s var=%s -> val=%s",
  -                                r->filename, var+5, result));
  +                    rewritelog((r, 5, ctx->perdir, "lookahead: path=%s var=%s "
  +                                "-> val=%s", path, var+5, result));
   
                       return (char *)result;
                   }
  @@ -1668,7 +1710,7 @@
                   result = apr_psprintf(r->pool, "%04d%02d%02d%02d%02d%02d",
                                         tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
                                         tm.tm_hour, tm.tm_min, tm.tm_sec);
  -                rewritelog((r, 1, NULL, "RESULT='%s'", result));
  +                rewritelog((r, 1, ctx->perdir, "RESULT='%s'", result));
                   return (char *)result;
               }
               break;
  
  
  

Mime
View raw message