mjc         96/10/14 03:51:18

  Modified:    src       mod_rewrite.c mod_rewrite.h
  Log:
  Submitted by: Ralf S. Engelschal <[EMAIL PROTECTED]>
  
  Update of mod_rewrite from version 2.2 to 2.3.5
  
  Revision  Changes    Path
  1.5       +266 -98   apache/src/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /export/home/cvs/apache/src/mod_rewrite.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -C3 -r1.4 -r1.5
  *** mod_rewrite.c     1996/08/23 16:16:52     1.4
  --- mod_rewrite.c     1996/10/14 10:51:15     1.5
  ***************
  *** 1,3 ****
  --- 1,4 ----
  +  
    /* ====================================================================
     * Copyright (c) 1996 The Apache Group.  All rights reserved.
     *
  ***************
  *** 50,56 ****
     *
     */
    
  - /* $Id: mod_rewrite.c,v 1.4 1996/08/23 16:16:52 akosut Exp $ */
    
    /*
    **  mod_rewrite.c -- The Main Module Code
  --- 51,56 ----
  ***************
  *** 61,67 ****
    **  |_| |_| |_|\___/ \__,_|___|_|  \___| \_/\_/ |_|  |_|\__\___|
    **                       |_____|
    **
  ! **  URL Rewriting Module, Version 2.2 (22-08-1996)
    **
    **  This module uses a rule-based rewriting engine (based on a
    **  regular-expression parser) to rewrite requested URLs on the fly. 
  --- 61,67 ----
    **  |_| |_| |_|\___/ \__,_|___|_|  \___| \_/\_/ |_|  |_|\__\___|
    **                       |_____|
    **
  ! **  URL Rewriting Module, Version 2.3.5 (09-10-1996)
    **
    **  This module uses a rule-based rewriting engine (based on a
    **  regular-expression parser) to rewrite requested URLs on the fly. 
  ***************
  *** 99,104 ****
  --- 99,105 ----
    #include <time.h>
    #include <sys/types.h>
    #include <sys/stat.h>
  + #include <netinet/in.h>
    
        /* from the Apache server ... */
    #include "httpd.h"
  ***************
  *** 192,198 ****
    static command_rec command_table[] = {
        { "RewriteEngine",   cmd_rewriteengine,   NULL, OR_FILEINFO, FLAG, 
          "On or Off to enable or disable (default) the whole rewriting engine" 
},
  !     { "RewriteBase",     cmd_rewritebase,     NULL, OR_OPTIONS,  TAKE1, 
          "the base URL of the per-directory context" },
        { "RewriteCond",     cmd_rewritecond,     NULL, OR_FILEINFO, RAW_ARGS, 
          "a input string and a to be applied regexp-pattern" },
  --- 193,201 ----
    static command_rec command_table[] = {
        { "RewriteEngine",   cmd_rewriteengine,   NULL, OR_FILEINFO, FLAG, 
          "On or Off to enable or disable (default) the whole rewriting engine" 
},
  !     { "RewriteOptions",  cmd_rewriteoptions,  NULL, OR_FILEINFO, ITERATE, 
  !       "List of option strings to set" },
  !     { "RewriteBase",     cmd_rewritebase,     NULL, OR_FILEINFO, TAKE1, 
          "the base URL of the per-directory context" },
        { "RewriteCond",     cmd_rewritecond,     NULL, OR_FILEINFO, RAW_ARGS, 
          "a input string and a to be applied regexp-pattern" },
  ***************
  *** 216,221 ****
  --- 219,235 ----
        /* the common cache */
    cache *cachep;
    
  +     /* the txt mapfile parsing stuff */
  + #define MAPFILE_PATTERN "^([^ ]+) +([^ ]+).*$"
  + #ifdef HAS_APACHE_REGEX_LIB
  + #define MAPFILE_OUTPUT "$1,$2"
  + static regex_t   *lookup_map_txtfile_regexp = NULL;
  + static regmatch_t lookup_map_txtfile_regmatch[10];
  + #else
  + #define MAPFILE_OUTPUT "\\1,\\2"
  + static regexp *lookup_map_txtfile_regexp = NULL;
  + #endif
  + 
    
    
    
  ***************
  *** 241,246 ****
  --- 255,261 ----
        a = (rewrite_server_conf *)pcalloc(p, sizeof(rewrite_server_conf));
    
        a->state           = ENGINE_DISABLED;
  +     a->options         = OPTION_NONE;
        a->rewritelogfile  = NULL;
        a->rewritelogfp    = -1;
        a->rewriteloglevel = 1;
  ***************
  *** 260,271 ****
        overrides = (rewrite_server_conf *)overridesv;
    
        a->state           = overrides->state;
  !     a->rewritelogfile  = overrides->rewritelogfile;
  !     a->rewritelogfp    = overrides->rewritelogfp;
        a->rewriteloglevel = overrides->rewriteloglevel;
  !     a->rewritemaps     = append_arrays(p, overrides->rewritemaps,  
base->rewritemaps);
  !     a->rewriteconds    = append_arrays(p, overrides->rewriteconds, 
base->rewriteconds);
  !     a->rewriterules    = append_arrays(p, overrides->rewriterules, 
base->rewriterules);
    
        return (void *)a;
    }
  --- 275,295 ----
        overrides = (rewrite_server_conf *)overridesv;
    
        a->state           = overrides->state;
  !     a->options         = overrides->options;
  !     a->rewritelogfile  = base->rewritelogfile  != NULL ? 
base->rewritelogfile  : overrides->rewritelogfile;
  !     a->rewritelogfp    = base->rewritelogfp    != -1   ? base->rewritelogfp 
   : overrides->rewritelogfp;
        a->rewriteloglevel = overrides->rewriteloglevel;
  ! 
  !     if (a->options & OPTION_INHERIT) {
  !         a->rewritemaps  = append_arrays(p, overrides->rewritemaps,  
base->rewritemaps);
  !         a->rewriteconds = append_arrays(p, overrides->rewriteconds, 
base->rewriteconds);
  !         a->rewriterules = append_arrays(p, overrides->rewriterules, 
base->rewriterules);
  !     }
  !     else {
  !         a->rewritemaps  = overrides->rewritemaps;
  !         a->rewriteconds = overrides->rewriteconds;
  !         a->rewriterules = overrides->rewriterules;
  !     }
    
        return (void *)a;
    }
  ***************
  *** 284,293 ****
        a = (rewrite_perdir_conf *)pcalloc(p, sizeof(rewrite_perdir_conf));
    
        a->state           = ENGINE_DISABLED;
  !     a->rewriteconds    = make_array(p, 2, sizeof(rewritecond_entry));
  !     a->rewriterules    = make_array(p, 2, sizeof(rewriterule_entry));
        a->directory       = pstrdup(p, path);
        a->baseurl         = NULL;
    
        return (void *)a;
    }
  --- 308,318 ----
        a = (rewrite_perdir_conf *)pcalloc(p, sizeof(rewrite_perdir_conf));
    
        a->state           = ENGINE_DISABLED;
  !     a->options         = OPTION_NONE;
        a->directory       = pstrdup(p, path);
        a->baseurl         = NULL;
  +     a->rewriteconds    = make_array(p, 2, sizeof(rewritecond_entry));
  +     a->rewriterules    = make_array(p, 2, sizeof(rewriterule_entry));
    
        return (void *)a;
    }
  ***************
  *** 301,311 ****
        overrides = (rewrite_perdir_conf *)overridesv;
    
        a->state           = overrides->state;
  !     a->rewriteconds    = append_arrays(p, overrides->rewriteconds, 
base->rewriteconds);
  !     a->rewriterules    = append_arrays(p, overrides->rewriterules, 
base->rewriterules);
        a->directory       = overrides->directory;
        a->baseurl         = overrides->baseurl;
    
        return (void *)a;
    }
    
  --- 326,344 ----
        overrides = (rewrite_perdir_conf *)overridesv;
    
        a->state           = overrides->state;
  !     a->options         = overrides->options;
        a->directory       = overrides->directory;
        a->baseurl         = overrides->baseurl;
    
  +     if (a->options & OPTION_INHERIT) {
  +         a->rewriteconds = append_arrays(p, overrides->rewriteconds, 
base->rewriteconds);
  +         a->rewriterules = append_arrays(p, overrides->rewriterules, 
base->rewriterules);
  +     }
  +     else {
  +         a->rewriteconds = overrides->rewriteconds;
  +         a->rewriterules = overrides->rewriterules;
  +     }
  + 
        return (void *)a;
    }
    
  ***************
  *** 329,334 ****
  --- 362,390 ----
        return NULL;
    }
    
  + static char *cmd_rewriteoptions(cmd_parms *cmd, rewrite_perdir_conf *dconf, 
char *option)
  + {
  +     rewrite_server_conf *sconf;
  +     char *err;
  + 
  +     sconf = (rewrite_server_conf 
*)get_module_config(cmd->server->module_config, &rewrite_module);
  +     if (cmd->path == NULL) /* is server command */
  +         err = cmd_rewriteoptions_setoption(cmd->pool, &(sconf->options), 
option);
  +     else                   /* is per-directory command */
  +         err = cmd_rewriteoptions_setoption(cmd->pool, &(dconf->options), 
option);
  + 
  +     return err;
  + }
  + 
  + static char *cmd_rewriteoptions_setoption(pool *p, int *options, char *name)
  + {
  +     if (strcasecmp(name, "inherit") == 0)
  +         *options |= OPTION_INHERIT;
  +     else
  +         return pstrcat(p, "RewriteOptions: unknown option '", name, "'\n", 
NULL);
  +     return NULL;
  + }
  + 
    static char *cmd_rewritelog(cmd_parms *cmd, void *dconf, char *a1)
    {
        rewrite_server_conf *sconf;
  ***************
  *** 360,385 ****
    
        new->name = a1;
        if (strncmp(a2, "txt:", 4) == 0) {
  !         new->file = a2+4;
  !         new->type = MAPTYPE_TXT;
        }
        else if (strncmp(a2, "dbm:", 4) == 0) {
  !         new->file = a2+4;
  !         new->type = MAPTYPE_DBM;
        }
        else if (strncmp(a2, "prg:", 4) == 0) {
  -         new->file = a2+4;
            new->type = MAPTYPE_PRG;
        }
        else {
  !         new->file = a2;
  !         new->type = MAPTYPE_TXT;
        }
        new->fpin  = 0;
        new->fpout = 0;
    
  !     if (stat(new->file, &st) == -1)
  !         return pstrcat(cmd->pool, "RewriteMap: map file or program not 
found:", new->file, NULL);
    
        return NULL;
    }
  --- 416,450 ----
    
        new->name = a1;
        if (strncmp(a2, "txt:", 4) == 0) {
  !         new->type      = MAPTYPE_TXT;
  !         new->datafile  = a2+4;
  !         new->checkfile = a2+4;
        }
        else if (strncmp(a2, "dbm:", 4) == 0) {
  ! #ifdef HAS_NDBM_LIB
  !         new->type      = MAPTYPE_DBM;
  !         new->datafile  = a2+4;
  !         new->checkfile = pstrcat(cmd->pool, a2+4, NDBM_FILE_SUFFIX, NULL);
  ! #else
  !         return pstrdup(cmd->pool, "RewriteMap: cannot use NDBM mapfile, 
because no NDBM support compiled in");
  ! #endif
        }
        else if (strncmp(a2, "prg:", 4) == 0) {
            new->type = MAPTYPE_PRG;
  +         new->datafile = a2+4;
  +         new->checkfile = a2+4;
        }
        else {
  !         new->type      = MAPTYPE_TXT;
  !         new->datafile  = a2;
  !         new->checkfile = a2;
        }
        new->fpin  = 0;
        new->fpout = 0;
    
  !     if (new->checkfile)
  !         if (stat(new->checkfile, &st) == -1)
  !             return pstrcat(cmd->pool, "RewriteMap: map file or program not 
found:", new->checkfile, NULL);
    
        return NULL;
    }
  ***************
  *** 519,527 ****
    static char *cmd_rewritecond_setflag(pool *p, rewritecond_entry *cfg, char 
*key, char *val)
    {
        if (   strcasecmp(key, "nocase") == 0
  !         || strcasecmp(key, "NC") == 0       ) {
            cfg->flags |= CONDFLAG_NOCASE;
        }
        else {
            return pstrcat(p, "RewriteCond: unknown flag '", key, "'\n", NULL);
        }
  --- 584,596 ----
    static char *cmd_rewritecond_setflag(pool *p, rewritecond_entry *cfg, char 
*key, char *val)
    {
        if (   strcasecmp(key, "nocase") == 0
  !         || strcasecmp(key, "NC") == 0    ) {
            cfg->flags |= CONDFLAG_NOCASE;
        }
  +     else if (   strcasecmp(key, "ornext") == 0
  +              || strcasecmp(key, "OR") == 0    ) {
  +         cfg->flags |= CONDFLAG_ORNEXT;
  +     }
        else {
            return pstrcat(p, "RewriteCond: unknown flag '", key, "'\n", NULL);
        }
  ***************
  *** 722,727 ****
  --- 791,805 ----
    
        /* create the lookup cache */
        cachep = init_cache(p);
  + 
  + 
  +     /* precompile a static pattern 
  +        for the txt mapfile parsing */
  + #ifdef HAS_APACHE_REGEX_LIB
  +     lookup_map_txtfile_regexp = pregcomp(p, MAPFILE_PATTERN, REG_EXTENDED);
  + #else
  +     lookup_map_txtfile_regexp = regcomp(MAPFILE_PATTERN);
  + #endif
    }
    
    
  ***************
  *** 1021,1027 ****
                /* make sure the QUERY_STRING and
                   PATH_INFO parts get incorporated */
                r->filename = pstrcat(r->pool, r->filename, 
  !                                            r->path_info ? r->path_info : 
"", 
                                               r->args ? "?" : NULL, r->args, 
                                               NULL);
    
  --- 1099,1107 ----
                /* make sure the QUERY_STRING and
                   PATH_INFO parts get incorporated */
                r->filename = pstrcat(r->pool, r->filename, 
  !                                            /* r->path_info was already
  !                                               appended by the rewriting 
engine
  !                                               because of the per-dir 
context! */
                                               r->args ? "?" : NULL, r->args, 
                                               NULL);
    
  ***************
  *** 1254,1259 ****
  --- 1334,1340 ----
        int rc;
        int prefixstrip;
        int i;
  +     int failed;
        array_header *rewriteconds;
        rewritecond_entry *conds;
        rewritecond_entry *c;
  ***************
  *** 1296,1306 ****
               slow down the rewriting engine!! */
            rewriteconds = p->rewriteconds;
            conds = (rewritecond_entry *)rewriteconds->elts;
            for (i = 0; i < rewriteconds->nelts; i++) {
                c = &conds[i];
  !             if (!apply_rewrite_cond(r, c, perdir))
  !                 return 0; /* if any condition fails this complete rule 
fails */
            }
    
            /* if this is a pure matching rule we return immediately */
            if (strcmp(output, "-") == 0) 
  --- 1377,1413 ----
               slow down the rewriting engine!! */
            rewriteconds = p->rewriteconds;
            conds = (rewritecond_entry *)rewriteconds->elts;
  +         failed = 0;
            for (i = 0; i < rewriteconds->nelts; i++) {
                c = &conds[i];
  !             rc = apply_rewrite_cond(r, c, perdir);
  !             if (c->flags & CONDFLAG_ORNEXT) {
  !                 /* there is a "or" flag */
  !                 if (rc == 0) {
  !                     /* one cond is false, but another can be true... */
  !                     continue;
  !                 }
  !                 else {
  !                     /* one true cond is enough, so skip the other conds
  !                        of the "ornext" chained conds */
  !                     while (   i < rewriteconds->nelts
  !                            && c->flags & CONDFLAG_ORNEXT) {
  !                         i++;
  !                         c = &conds[i];
  !                     }
  !                     continue;
  !                 }
  !             }
  !             else {
  !                 /* no "or" flag, so a single fail means total fail */
  !                 if (rc == 0) { /* failed */
  !                     failed = 1;
  !                     break;
  !                 }
  !             }
            }
  +         if (failed) 
  +             return 0; /* if any condition fails this complete rule fails */
    
            /* if this is a pure matching rule we return immediately */
            if (strcmp(output, "-") == 0) 
  ***************
  *** 1763,1805 ****
            s = &entries[i];
            if (strcmp(s->name, name) == 0) {
                if (s->type == MAPTYPE_TXT) {
  !                 stat(s->file, &st); /* existence was checked at startup! */
  !                 value = get_cache_string(cachep, s->file, CACHEMODE_TS, 
st.st_mtime, key);
                    if (value == NULL) {
                        rewritelog(r, 6, "cache lookup FAILED, forcing new map 
lookup");
  !                     if ((value = lookup_map_txtfile(r, s->file, key)) != 
NULL) {
  !                         rewritelog(r, 5, "map lookup OK: map=%s key=%s -> 
val=%s", s->file, key, value);
  !                         set_cache_string(cachep, s->file, CACHEMODE_TS, 
st.st_mtime, key, value);
                            return value;
                        }
                        else {
  !                         rewritelog(r, 5, "map lookup FAILED: map=%s 
key=%s", s->file, key);
                            return NULL;
                        }
                    }
                    else {
  !                     rewritelog(r, 5, "cache lookup OK: res=%s key=%s -> 
val=%s", s->file, key, value);
                        return value;
                    }
                }
                else if (s->type == MAPTYPE_DBM) {
    #if HAS_NDBM_LIB
  !                 stat(s->file, &st); /* existence was checked at startup! */
  !                 value = get_cache_string(cachep, s->file, CACHEMODE_TS, 
st.st_mtime, key);
                    if (value == NULL) {
                        rewritelog(r, 6, "cache lookup FAILED, forcing new map 
lookup");
  !                     if ((value = lookup_map_dbmfile(r, s->file, key)) != 
NULL) {
  !                         rewritelog(r, 5, "map lookup OK: map=%s key=%s -> 
val=%s", s->file, key, value);
  !                         set_cache_string(cachep, s->file, CACHEMODE_TS, 
st.st_mtime, key, value);
                            return value;
                        }
                        else {
  !                         rewritelog(r, 5, "map lookup FAILED: map=%s 
key=%s", s->file, key);
                            return NULL;
                        }
                    }
                    else {
  !                     rewritelog(r, 5, "cache lookup OK: res=%s key=%s -> 
val=%s", s->file, key, value);
                        return value;
                    }
    #else
  --- 1870,1912 ----
            s = &entries[i];
            if (strcmp(s->name, name) == 0) {
                if (s->type == MAPTYPE_TXT) {
  !                 stat(s->checkfile, &st); /* existence was checked at 
startup! */
  !                 value = get_cache_string(cachep, s->name, CACHEMODE_TS, 
st.st_mtime, key);
                    if (value == NULL) {
                        rewritelog(r, 6, "cache lookup FAILED, forcing new map 
lookup");
  !                     if ((value = lookup_map_txtfile(r, s->datafile, key)) 
!= NULL) {
  !                         rewritelog(r, 5, "map lookup OK: map=%s key=%s[txt] 
-> val=%s", s->name, key, value);
  !                         set_cache_string(cachep, s->name, CACHEMODE_TS, 
st.st_mtime, key, value);
                            return value;
                        }
                        else {
  !                         rewritelog(r, 5, "map lookup FAILED: map=%s[txt] 
key=%s", s->name, key);
                            return NULL;
                        }
                    }
                    else {
  !                     rewritelog(r, 5, "cache lookup OK: map=%s[txt] key=%s 
-> val=%s", s->name, key, value);
                        return value;
                    }
                }
                else if (s->type == MAPTYPE_DBM) {
    #if HAS_NDBM_LIB
  !                 stat(s->checkfile, &st); /* existence was checked at 
startup! */
  !                 value = get_cache_string(cachep, s->name, CACHEMODE_TS, 
st.st_mtime, key);
                    if (value == NULL) {
                        rewritelog(r, 6, "cache lookup FAILED, forcing new map 
lookup");
  !                     if ((value = lookup_map_dbmfile(r, s->datafile, key)) 
!= NULL) {
  !                         rewritelog(r, 5, "map lookup OK: map=%s[dbm] key=%s 
-> val=%s", s->name, key, value);
  !                         set_cache_string(cachep, s->name, CACHEMODE_TS, 
st.st_mtime, key, value);
                            return value;
                        }
                        else {
  !                         rewritelog(r, 5, "map lookup FAILED: map=%s[dbm] 
key=%s", s->name, key);
                            return NULL;
                        }
                    }
                    else {
  !                     rewritelog(r, 5, "cache lookup OK: map=%s[dbm] key=%s 
-> val=%s", s->name, key, value);
                        return value;
                    }
    #else
  ***************
  *** 1808,1818 ****
                }
                else if (s->type == MAPTYPE_PRG) {
                    if ((value = lookup_map_program(r, s->fpin, s->fpout, key)) 
!= NULL) {
  !                     rewritelog(r, 5, "map lookup OK: map=%s key=%s -> 
val=%s", s->file, key, value);
                        return value;
                    }
                    else {
  !                     rewritelog(r, 5, "map lookup FAILED: map=%s key=%s", 
s->file, key);
                    }
                }
            }
  --- 1915,1925 ----
                }
                else if (s->type == MAPTYPE_PRG) {
                    if ((value = lookup_map_program(r, s->fpin, s->fpout, key)) 
!= NULL) {
  !                     rewritelog(r, 5, "map lookup OK: map=%s key=%s -> 
val=%s", s->name, key, value);
                        return value;
                    }
                    else {
  !                     rewritelog(r, 5, "map lookup FAILED: map=%s key=%s", 
s->name, key);
                    }
                }
            }
  ***************
  *** 1820,1839 ****
        return NULL;
    }
    
  - #define PATTERN "^([^ ]+) +([^ ]+).*$"
  - 
  - #ifdef HAS_APACHE_REGEX_LIB
  - 
  - #define OUTPUT "$1,$2"
  - static regex_t   *lookup_map_txtfile_regexp = NULL;
  - static regmatch_t lookup_map_txtfile_regmatch[10];
  - 
  - #else
  - 
  - #define OUTPUT "\\1,\\2"
  - static regexp *lookup_map_txtfile_regexp = NULL;
  - 
  - #endif
    
    static char *lookup_map_txtfile(request_rec *r, char *file, char *key)
    {
  --- 1927,1932 ----
  ***************
  *** 1849,1862 ****
        if ((fp = pfopen(r->pool, file, "r")) == NULL)
            return NULL;
    
  !     if (lookup_map_txtfile_regexp == NULL)
  ! #ifdef HAS_APACHE_REGEX_LIB
  !         lookup_map_txtfile_regexp = pregcomp(r->pool, PATTERN, 
REG_EXTENDED);
  ! #else
  !         lookup_map_txtfile_regexp = regcomp(PATTERN);
  ! #endif
  ! 
  !     strcpy(output,  OUTPUT);
        while (fgets(line, sizeof(line), fp) != NULL) {
            if (line[strlen(line)-1] == '\n')
                line[strlen(line)-1] = '\0';
  --- 1942,1948 ----
        if ((fp = pfopen(r->pool, file, "r")) == NULL)
            return NULL;
    
  !     strcpy(output,  MAPFILE_OUTPUT);
        while (fgets(line, sizeof(line), fp) != NULL) {
            if (line[strlen(line)-1] == '\n')
                line[strlen(line)-1] = '\0';
  ***************
  *** 1895,1901 ****
        static char buf[MAX_STRING_LEN];
    
        dbmkey.dptr  = key;
  !     dbmkey.dsize = strlen(key)+1;
        if ((dbmfp = dbm_open(file, O_RDONLY, 0666)) != NULL) {
            dbmval = dbm_fetch(dbmfp, dbmkey);
            if (dbmval.dptr != NULL) {
  --- 1981,1987 ----
        static char buf[MAX_STRING_LEN];
    
        dbmkey.dptr  = key;
  !     dbmkey.dsize = strlen(key);
        if ((dbmfp = dbm_open(file, O_RDONLY, 0666)) != NULL) {
            dbmval = dbm_fetch(dbmfp, dbmkey);
            if (dbmval.dptr != NULL) {
  ***************
  *** 2038,2044 ****
        else
            sprintf(redir, "/redir#%d", i);
    
  !     sprintf(str3, "%s %s [sid#%x][rid#%x/%s%s] (%d) %s\n", str1, 
current_logtime(r), (unsigned int)(r->server), (unsigned int)r, type, redir, 
level, str2);
    
        write(conf->rewritelogfp, str3, strlen(str3));
    
  --- 2124,2130 ----
        else
            sprintf(redir, "/redir#%d", i);
    
  !     sprintf(str3, "%s %s [%s/sid#%x][rid#%x/%s%s] (%d) %s\n", str1, 
current_logtime(r), r->server->server_hostname, (unsigned int)(r->server), 
(unsigned int)r, type, redir, level, str2);
    
        write(conf->rewritelogfp, str3, strlen(str3));
    
  ***************
  *** 2096,2110 ****
            map = &entries[i];
            if (map->type != MAPTYPE_PRG)
                continue;
  !         if (map->file == NULL    ||
  !             *(map->file) == '\0' ||
                map->fpin > 0        ||
                map->fpout > 0         )
                continue;
  !         fname = server_root_relative(p, map->file);
            fpin = NULL;
            fpout = NULL;
  !         rc = spawn_child(p, rewritemap_program_child, (void *)map->file, 
kill_after_timeout, &fpin, &fpout);
            if (rc == 0 || fpin == NULL || fpout == NULL) {
                fprintf (stderr, "mod_rewrite: could not fork child for 
RewriteMap process\n");
                exit (1);
  --- 2182,2196 ----
            map = &entries[i];
            if (map->type != MAPTYPE_PRG)
                continue;
  !         if (map->datafile == NULL    ||
  !             *(map->datafile) == '\0' ||
                map->fpin > 0        ||
                map->fpout > 0         )
                continue;
  !         fname = server_root_relative(p, map->datafile);
            fpin = NULL;
            fpout = NULL;
  !         rc = spawn_child(p, rewritemap_program_child, (void 
*)map->datafile, kill_after_timeout, &fpin, &fpout);
            if (rc == 0 || fpin == NULL || fpout == NULL) {
                fprintf (stderr, "mod_rewrite: could not fork child for 
RewriteMap process\n");
                exit (1);
  ***************
  *** 2355,2362 ****
        cache *c;
    
        c = (cache *)palloc(p, sizeof(cache));
  !     c->pool = p;
  !     c->lists = make_array(p, 2, sizeof(cachelist));
        return c;
    }
    
  --- 2441,2448 ----
        cache *c;
    
        c = (cache *)palloc(p, sizeof(cache));
  !     c->pool = make_sub_pool(NULL);
  !     c->lists = make_array(c->pool, 2, sizeof(cachelist));
        return c;
    }
    
  ***************
  *** 2396,2416 ****
        cachelist *l;
        cacheentry *e;
        int found_list;
  -     int found_entry;
    
        found_list = 0;
  -     found_entry = 0;
        /* first try to edit an existing entry */
        for (i = 0; i < c->lists->nelts; i++) {
  !         l = (cachelist *)&(c->lists->elts[i]);
            if (strcmp(l->resource, res) == 0) {
                found_list = 1;
  !             for (j = 0; j < l->entries->nelts; i++) {
  !                 e = (cacheentry *)&(l->entries->elts)[j];
                    if (strcmp(e->key, ce->key) == 0) {
                        e->time  = ce->time;
                        e->value = pstrdup(c->pool, ce->value);
  !                     found_entry = 1;
                    }
                }
            }
  --- 2482,2500 ----
        cachelist *l;
        cacheentry *e;
        int found_list;
    
        found_list = 0;
        /* first try to edit an existing entry */
        for (i = 0; i < c->lists->nelts; i++) {
  !         l = &(((cachelist *)c->lists->elts)[i]);
            if (strcmp(l->resource, res) == 0) {
                found_list = 1;
  !             for (j = 0; j < l->entries->nelts; j++) {
  !                 e = &(((cacheentry *)l->entries->elts)[j]);
                    if (strcmp(e->key, ce->key) == 0) {
                        e->time  = ce->time;
                        e->value = pstrdup(c->pool, ce->value);
  !                     return;
                    }
                }
            }
  ***************
  *** 2425,2439 ****
    
        /* create the new entry */
        for (i = 0; i < c->lists->nelts; i++) {
  !         l = (cachelist *)&(c->lists->elts)[i];
            if (strcmp(l->resource, res) == 0) {
                e = push_array(l->entries);
                e->time  = ce->time;
                e->key   = pstrdup(c->pool, ce->key);
                e->value = pstrdup(c->pool, ce->value);
            }
        }
    
        return;
    }
    
  --- 2509,2525 ----
    
        /* create the new entry */
        for (i = 0; i < c->lists->nelts; i++) {
  !         l = &(((cachelist *)c->lists->elts)[i]);
            if (strcmp(l->resource, res) == 0) {
                e = push_array(l->entries);
                e->time  = ce->time;
                e->key   = pstrdup(c->pool, ce->key);
                e->value = pstrdup(c->pool, ce->value);
  +             return;
            }
        }
    
  +     /* not reached, but when it is no problem... */
        return;
    }
    
  ***************
  *** 2445,2454 ****
        cacheentry *e;
    
        for (i = 0; i < c->lists->nelts; i++) {
  !         l = (cachelist *)&(c->lists->elts)[i];
            if (strcmp(l->resource, res) == 0) {
  !             for (j = 0; j < l->entries->nelts; i++) {
  !                 e = (cacheentry *)&(l->entries->elts)[j];
                    if (strcmp(e->key, key) == 0) {
                        return e;
                    }
  --- 2531,2540 ----
        cacheentry *e;
    
        for (i = 0; i < c->lists->nelts; i++) {
  !         l = &(((cachelist *)c->lists->elts)[i]);
            if (strcmp(l->resource, res) == 0) {
  !             for (j = 0; j < l->entries->nelts; j++) {
  !                 e = &(((cacheentry *)l->entries->elts)[j]);
                    if (strcmp(e->key, key) == 0) {
                        return e;
                    }
  ***************
  *** 2623,2660 ****
    {
        char **cppHNLour;
        char **cppHNLtest;
        int i, j;
    
  !     if ((cppHNLour = make_hostname_list(r, r->server->server_hostname)) == 
NULL)
  !         return 0;
  !     if ((cppHNLtest = make_hostname_list(r, testhost)) == NULL)
  !         return 0;
    
  !     for (i = 0; cppHNLtest[i] != NULL; i++) {
  !         for (j = 0; cppHNLour[j] != NULL; j++) {
  !             if (strcmp(cppHNLtest[i], cppHNLour[j]) == 0) {
  !                 return 1;
                }
            }
        }
  !     return 0;
    }
    
  ! static char **make_hostname_list(request_rec *r, char *hostname)
    {
        char **cppHNL;
        struct hostent *hep;
        int i;
    
  !     if ((hep = gethostbyname(hostname)) == NULL)
            return NULL;
  !     for (i = 0; hep->h_aliases[i]; i++)
            ;
  !     cppHNL = (char **)palloc(r->pool, sizeof(char *)*(i+2));
  !     cppHNL[0] = pstrdup(r->pool, hep->h_name);
  !     for (i = 0; hep->h_aliases[i]; i++)
  !         cppHNL[1+i] = pstrdup(r->pool, hep->h_aliases[i]);
  !     cppHNL[1+i] = NULL;
        return cppHNL;
    }
    
  --- 2709,2828 ----
    {
        char **cppHNLour;
        char **cppHNLtest;
  +     char *ourhostname;
  +     char *ourhostip;
  +     char *names;
  +     char *name;
        int i, j;
    
  !     /* we can check:
  !        r->
  !             char *hostname            Host, as set by full URI or Host: 
  !             int hostlen               Length of http://host:port in full 
URI 
  !        r->server->
  !             int is_virtual            0=main, 1=ip-virtual, 2=non-ip-virtual
  !             char *server_hostname     used on compare to r->hostname
  !             inet_ntoa(r->connection->local_addr.sin_addr)
  !                                       used on compare to r->hostname
  !             short port                for redirects
  !             char *path                name of ServerPath
  !             int pathlen               len of ServerPath
  !             char *names               Wildcarded names for ServerAlias 
servers 
  !        under 1.1:
  !        r->server->
  !             struct in_addr host_addr  The bound address, for this server 
  !             short host_port           The bound port, for this server 
  !             char *virthost            The name given in <VirtualHost> 
  !        under 1.2:
  !        r->server->addrs->next...
  !             struct in_addr host_addr  The bound address, for this server
  !             short host_port           The bound port, for this server 
  !             char *virthost            The name given in <VirtualHost> 
  !     */
  ! 
  !     ourhostname = r->server->server_hostname;
  !     ourhostip   = inet_ntoa(r->connection->local_addr.sin_addr);
  ! 
  !     /* just a simple common case */
  !     if (strcmp(testhost, ourhostname) == 0 ||
  !         strcmp(testhost, ourhostip)   == 0   )
  !        return YES;
  ! 
  !     /* now the complicated cases */
  !     if (!r->server->is_virtual) {
  !         /* main servers */
  ! 
  !         /* check for the alternative IP addresses */
  !         if ((cppHNLour = resolv_ipaddr_list(r, ourhostname)) == NULL)
  !             return NO;
  !         if ((cppHNLtest = resolv_ipaddr_list(r, testhost)) == NULL)
  !             return NO;
  !         for (i = 0; cppHNLtest[i] != NULL; i++) {
  !             for (j = 0; cppHNLour[j] != NULL; j++) {
  !                 if (strcmp(cppHNLtest[i], cppHNLour[j]) == 0) {
  !                     return YES;
  !                 }
  !             }
  !         }
  !     }
  !     else if (r->server->is_virtual) {
  !         /* virtual servers */
    
  !         /* check for the virtual-server aliases */
  !         if (r->server->names != NULL && r->server->names[0] != '\0') {
  !             names = r->server->names;
  !             while (*names != '\0') {
  !                 name = getword_conf(r->pool, &names);
  !                 if ((is_matchexp(name) && !strcasecmp_match(testhost, 
name)) ||
  !                     (strcasecmp(testhost, name) == 0)                       
   ) {
  !                     return YES;
  !                 }
                }
            }
        }
  !     return NO;
  ! }
  ! 
  ! static int isaddr(char *host)
  ! {
  !     char *cp;
  ! 
  !     /* Null pointers and empty strings 
  !        are not addresses. */
  !     if (host == NULL)
  !         return NO;
  !     if (*host == '\0')
  !         return NO;
  !     /* Make sure it has only digits and dots. */
  !     for (cp = host; *cp; cp++) {
  !         if (!isdigit(*cp) && *cp != '.')
  !             return NO;
  !     }
  !     /* If it has a trailing dot, 
  !        don't treat it as an address. */
  !     if (*(cp-1) == '.')
  !        return NO;
  !     return YES;
    }
    
  ! static char **resolv_ipaddr_list(request_rec *r, char *name)
    {
        char **cppHNL;
        struct hostent *hep;
        int i;
    
  !     if (isaddr(name)) 
  !         hep = gethostbyaddr(name, sizeof(struct in_addr), AF_INET);
  !     else
  !         hep = gethostbyname(name);
  !     if (hep == NULL)
            return NULL;
  !     for (i = 0; hep->h_addr_list[i]; i++)
            ;
  !     cppHNL = (char **)palloc(r->pool, sizeof(char *)*(i+1));
  !     for (i = 0; hep->h_addr_list[i]; i++)
  !         cppHNL[i] = pstrdup(r->pool, inet_ntoa(*((struct in_addr 
*)(hep->h_addr_list[i]))) );
  !     cppHNL[i] = NULL;
        return cppHNL;
    }
    
  
  
  
  1.6       +55 -17    apache/src/mod_rewrite.h
  
  Index: mod_rewrite.h
  ===================================================================
  RCS file: /export/home/cvs/apache/src/mod_rewrite.h,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -C3 -r1.5 -r1.6
  *** mod_rewrite.h     1996/08/23 16:16:53     1.5
  --- mod_rewrite.h     1996/10/14 10:51:16     1.6
  ***************
  *** 1,3 ****
  --- 1,4 ----
  + 
    /* ====================================================================
     * Copyright (c) 1996 The Apache Group.  All rights reserved.
     *
  ***************
  *** 50,56 ****
     *
     */
    
  - /* $Id: mod_rewrite.h,v 1.5 1996/08/23 16:16:53 akosut Exp $ */
    
    #ifndef _MOD_REWRITE_H
    #define _MOD_REWRITE_H 1
  --- 51,56 ----
  ***************
  *** 64,70 ****
    **  |_| |_| |_|\___/ \__,_|___|_|  \___| \_/\_/ |_|  |_|\__\___|
    **                       |_____|
    **
  ! **  URL Rewriting Module, Version 2.2 (22-08-1996)
    **
    **  This module uses a rule-based rewriting engine (based on a
    **  regular-expression parser) to rewrite requested URLs on the fly. 
  --- 64,70 ----
    **  |_| |_| |_|\___/ \__,_|___|_|  \___| \_/\_/ |_|  |_|\__\___|
    **                       |_____|
    **
  ! **  URL Rewriting Module, Version 2.3.5 (09-10-1996)
    **
    **  This module uses a rule-based rewriting engine (based on a
    **  regular-expression parser) to rewrite requested URLs on the fly. 
  ***************
  *** 96,112 ****
    
    
    
  !    /* try to see under which version we are running */
    #if (MODULE_MAGIC_NUMBER >= 19960725)
    #define HAS_APACHE_REGEX_LIB 1
    #endif
    
  !     /* now we go on and include more of our own stuff ... */
    #ifndef HAS_APACHE_REGEX_LIB
    #include "regexp/regexp.h"
    #endif
    #if HAS_NDBM_LIB
  ! #include <ndbm>
    #endif
    
    
  --- 96,128 ----
    
    
    
  !     /* Check Apache Release */
    #if (MODULE_MAGIC_NUMBER >= 19960725)
  + #define IS_APACHE_12         1
    #define HAS_APACHE_REGEX_LIB 1
    #endif
    
  ! 
  !     /* The RegExp support:
  !        For Apache 1.1.1 we provide our own Spencer V8 library,
  !        for Apache 1.2 and higher there is a Spencer POSIX library
  !        in the distribution */
    #ifndef HAS_APACHE_REGEX_LIB
    #include "regexp/regexp.h"
    #endif
  + 
  + 
  +     /* The NDBM support:
  +        We support only NDBM files. 
  +        But we have to stat the file for the mtime,
  +        so we also need to know the file extension */
    #if HAS_NDBM_LIB
  ! #include <ndbm.h>
  ! #if (__FreeBSD__)
  ! #define NDBM_FILE_SUFFIX ".db"
  ! #else 
  ! #define NDBM_FILE_SUFFIX ".pag"
  ! #endif
    #endif
    
    
  ***************
  *** 128,133 ****
  --- 144,150 ----
    #define CONDFLAG_NONE               1<<0
    #define CONDFLAG_NOCASE             1<<1
    #define CONDFLAG_NOTMATCH           1<<2
  + #define CONDFLAG_ORNEXT             1<<3
    
    #define RULEFLAG_NONE               1<<0
    #define RULEFLAG_FORCEREDIRECT      1<<1
  ***************
  *** 147,154 ****
    #define ENGINE_DISABLED             1<<0
    #define ENGINE_ENABLED              1<<1
    
  ! #define CACHEMODE_TS  1<<0
  ! #define CACHEMODE_TTL 1<<1
    
    
    /*
  --- 164,184 ----
    #define ENGINE_DISABLED             1<<0
    #define ENGINE_ENABLED              1<<1
    
  ! #define OPTION_NONE                 1<<0
  ! #define OPTION_INHERIT              1<<1
  ! 
  ! #define CACHEMODE_TS                1<<0
  ! #define CACHEMODE_TTL               1<<1
  ! 
  ! #ifndef FALSE
  ! #define FALSE 0
  ! #define TRUE  !FALSE
  ! #endif
  ! 
  ! #ifndef NO
  ! #define NO    FALSE
  ! #define YES   TRUE
  ! #endif
    
    
    /*
  ***************
  *** 162,182 ****
    
    typedef struct {
        char *name;                    /* the name of the map */
  !     char *file;                    /* the file of the map */
        int   type;                    /* the type of the map */
        int   fpin;                    /* in  filepointer for program maps */
        int   fpout;                   /* out filepointer for program maps */
    } rewritemap_entry;
    
    typedef struct {
  !     char   *input;                 /* Input string of RewriteCond */
  !     char   *pattern;               /* the RegExp pattern string */
    #ifdef HAS_APACHE_REGEX_LIB
        regex_t *regexp;
    #else
  !     regexp *regexp;                /* the RegExp pattern compilation */
    #endif
  !     int     flags;                 /* Flags which control the match */
    } rewritecond_entry;
    
    typedef struct {
  --- 192,213 ----
    
    typedef struct {
        char *name;                    /* the name of the map */
  !     char *datafile;                /* the file which contains the data of 
the map */
  !     char *checkfile;               /* the file which stays for existence of 
the map */
        int   type;                    /* the type of the map */
        int   fpin;                    /* in  filepointer for program maps */
        int   fpout;                   /* out filepointer for program maps */
    } rewritemap_entry;
    
    typedef struct {
  !     char    *input;                /* Input string of RewriteCond */
  !     char    *pattern;              /* the RegExp pattern string */
    #ifdef HAS_APACHE_REGEX_LIB
        regex_t *regexp;
    #else
  !     regexp  *regexp;               /* the RegExp pattern compilation */
    #endif
  !     int      flags;                /* Flags which control the match */
    } rewritecond_entry;
    
    typedef struct {
  ***************
  *** 199,204 ****
  --- 230,236 ----
    
    typedef struct {
        int           state;           /* the RewriteEngine state */
  +     int           options;         /* the RewriteOption state */
        char         *rewritelogfile;  /* the RewriteLog filename */
        int           rewritelogfp;    /* the RewriteLog open filepointer */
        int           rewriteloglevel; /* the RewriteLog level of verbosity */
  ***************
  *** 213,222 ****
    
    typedef struct {
        int           state;           /* the RewriteEngine state */
        array_header *rewriteconds;    /* the RewriteCond entries (temporary) */
        array_header *rewriterules;    /* the RewriteRule entries */
  !     char *directory;               /* the directory where it applies */
  !     char *baseurl;                 /* the base-URL  where it applies */
    } rewrite_perdir_conf;
    
    
  --- 245,255 ----
    
    typedef struct {
        int           state;           /* the RewriteEngine state */
  +     int           options;         /* the RewriteOption state */
        array_header *rewriteconds;    /* the RewriteCond entries (temporary) */
        array_header *rewriterules;    /* the RewriteRule entries */
  !     char         *directory;       /* the directory where it applies */
  !     char         *baseurl;         /* the base-URL  where it applies */
    } rewrite_perdir_conf;
    
    
  ***************
  *** 229,235 ****
    } cacheentry;
    
    typedef struct cachelist {
  !     char  *resource;
        array_header *entries;
    } cachelist;
    
  --- 262,268 ----
    } cacheentry;
    
    typedef struct cachelist {
  !     char         *resource;
        array_header *entries;
    } cachelist;
    
  ***************
  *** 259,264 ****
  --- 292,299 ----
    
        /* config directive handling */
    static char *cmd_rewriteengine  (cmd_parms *cmd, rewrite_perdir_conf 
*dconf, int flag);
  + static char *cmd_rewriteoptions (cmd_parms *cmd, rewrite_perdir_conf 
*dconf, char *option);
  + static char *cmd_rewriteoptions_setoption(pool *p, int *options, char 
*name);
    static char *cmd_rewritelog     (cmd_parms *cmd, void *dconf, char *a1);
    static char *cmd_rewriteloglevel(cmd_parms *cmd, void *dconf, char *a1);
    static char *cmd_rewritemap     (cmd_parms *cmd, void *dconf, char *a1, 
char *a2);
  ***************
  *** 296,302 ****
        /* DBM hashfile support functions */
    static char *lookup_map(request_rec *r, char *name, char *key);
    static char *lookup_map_txtfile(request_rec *r, char *file, char *key);
  ! #if SUPPORT_DBM_REWRITEMAP
    static char *lookup_map_dbmfile(request_rec *r, char *file, char *key);
    #endif
    static char *lookup_map_program(request_rec *r, int fpin, int fpout, char 
*key);
  --- 331,337 ----
        /* DBM hashfile support functions */
    static char *lookup_map(request_rec *r, char *name, char *key);
    static char *lookup_map_txtfile(request_rec *r, char *file, char *key);
  ! #if HAS_NDBM_LIB
    static char *lookup_map_dbmfile(request_rec *r, char *file, char *key);
    #endif
    static char *lookup_map_program(request_rec *r, int fpin, int fpout, char 
*key);
  ***************
  *** 328,335 ****
    static char  *subst_prefix_path(request_rec *r, char *input, char *match, 
char *subst);
    static int    parseargline(char *str, char **a1, char **a2, char **a3);
    static int    prefix_stat(const char *path, struct stat *sb);
    static int    is_this_our_host(request_rec *r, char *testhost);
  ! static char **make_hostname_list(request_rec *r, char *hostname);
    
    #endif /* _MOD_REWRITE_H */
    
  --- 363,373 ----
    static char  *subst_prefix_path(request_rec *r, char *input, char *match, 
char *subst);
    static int    parseargline(char *str, char **a1, char **a2, char **a3);
    static int    prefix_stat(const char *path, struct stat *sb);
  + 
  +     /* DNS functions */
    static int    is_this_our_host(request_rec *r, char *testhost);
  ! static int    isaddr(char *host);
  ! static char **resolv_ipaddr_list(request_rec *r, char *name);
    
    #endif /* _MOD_REWRITE_H */
    
  
  
  

Reply via email to