]> granicus.if.org Git - apache/blobdiff - modules/mappers/mod_rewrite.c
Move the POSIX reg* implementations into the ap_* namespace;
[apache] / modules / mappers / mod_rewrite.c
index 066b0521a6d6fcb3333067c4c883334a26ed28ee..aab63cbe597d92b8d2e59266b2367662609a3651 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright 1999-2004 The Apache Software Foundation
+/* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -93,9 +94,8 @@
 
 #include "mod_rewrite.h"
 
-#if !defined(OS2) && !defined(WIN32) && !defined(BEOS)  && !defined(NETWARE)
+#ifdef AP_NEED_SET_MUTEX_PERMS
 #include "unixd.h"
-#define MOD_REWRITE_SET_MUTEX_PERMS /* XXX Apache should define something */
 #endif
 
 /*
 /* XXX: not used at all. We should do a check somewhere and/or cut the cookie */
 #define MAX_COOKIE_LEN 4096
 
-/* default maximum number of internal redirects */
-#define REWRITE_REDIRECT_LIMIT 10
-
 /* max line length (incl.\n) in text rewrite maps */
 #ifndef REWRITE_MAX_TXT_MAP_LINE
 #define REWRITE_MAX_TXT_MAP_LINE 1024
@@ -248,7 +245,7 @@ typedef enum {
 typedef struct {
     char        *input;   /* Input string of RewriteCond   */
     char        *pattern; /* the RegExp pattern string     */
-    regex_t     *regexp;  /* the precompiled regexp        */
+    ap_regex_t  *regexp;  /* the precompiled regexp        */
     int          flags;   /* Flags which control the match */
     pattern_type ptype;   /* pattern type                  */
 } rewritecond_entry;
@@ -262,7 +259,7 @@ typedef struct data_item {
 typedef struct {
     apr_array_header_t *rewriteconds;/* the corresponding RewriteCond entries */
     char      *pattern;              /* the RegExp pattern string             */
-    regex_t   *regexp;               /* the RegExp pattern compilation        */
+    ap_regex_t *regexp;              /* the RegExp pattern compilation        */
     char      *output;               /* the Substitution string               */
     int        flags;                /* Flags which control the substitution  */
     char      *forced_mimetype;      /* forced MIME type of substitution      */
@@ -285,7 +282,6 @@ typedef struct {
     apr_array_header_t *rewriteconds; /* the RewriteCond entries (temp.)    */
     apr_array_header_t *rewriterules; /* the RewriteRule entries            */
     server_rec   *server;             /* the corresponding server indicator */
-    int          redirect_limit;      /* max number of internal redirects   */
 } rewrite_server_conf;
 
 typedef struct {
@@ -295,14 +291,8 @@ typedef struct {
     apr_array_header_t *rewriterules; /* the RewriteRule entries           */
     char         *directory;          /* the directory where it applies    */
     const char   *baseurl;            /* the base-URL  where it applies    */
-    int          redirect_limit;      /* max. number of internal redirects */
 } rewrite_perdir_conf;
 
-typedef struct {
-    int           redirects;      /* current number of redirects */
-    int           redirect_limit; /* maximum number of redirects */
-} rewrite_request_conf;
-
 /* the (per-child) cache structures.
  */
 typedef struct cache {
@@ -328,7 +318,7 @@ typedef struct {
 typedef struct backrefinfo {
     char *source;
     int nsub;
-    regmatch_t regmatch[AP_MAX_REG_MATCH];
+    ap_regmatch_t regmatch[AP_MAX_REG_MATCH];
 } backrefinfo;
 
 /* single linked list used for
@@ -569,6 +559,19 @@ static unsigned is_absolute_uri(char *uri)
     }
 
     switch (*uri++) {
+    case 'a':
+    case 'A':
+        if (!strncasecmp(uri, "jp://", 5)) {        /* ajp://    */
+          return 6;
+        }
+
+    case 'b':
+    case 'B':
+        if (!strncasecmp(uri, "alancer://", 10)) {   /* balancer:// */
+          return 11;
+        }
+        break;
+
     case 'f':
     case 'F':
         if (!strncasecmp(uri, "tp://", 5)) {        /* ftp://    */
@@ -702,7 +705,9 @@ static void splitout_queryargs(request_rec *r, int qsappend)
     /* don't touch, unless it's an http or mailto URL.
      * See RFC 1738 and RFC 2368.
      */
-    if (   is_absolute_uri(r->filename)
+    if (is_absolute_uri(r->filename)
+        && strncasecmp(r->filename, "ajp", 3)
+        && strncasecmp(r->filename, "balancer", 8)
         && strncasecmp(r->filename, "http", 4)
         && strncasecmp(r->filename, "mailto", 6)) {
         r->args = NULL; /* forget the query that's still flying around */
@@ -746,7 +751,7 @@ static void reduce_uri(request_rec *r)
     char *cp;
     apr_size_t l;
 
-    cp = (char *)ap_http_method(r);
+    cp = (char *)ap_http_scheme(r);
     l  = strlen(cp);
     if (   strlen(r->filename) > l+3
         && strncasecmp(r->filename, cp, l) == 0
@@ -818,7 +823,7 @@ static void fully_qualify_uri(request_rec *r)
                    : apr_psprintf(r->pool, ":%u", port);
 
         r->filename = apr_psprintf(r->pool, "%s://%s%s%s%s",
-                                   ap_http_method(r), thisserver, thisport,
+                                   ap_http_scheme(r), thisserver, thisport,
                                    (*r->filename == '/') ? "" : "/",
                                    r->filename);
     }
@@ -1319,7 +1324,8 @@ static char *lookup_map_program(request_rec *r, apr_file_t *fpin,
     apr_size_t i, nbytes, combined_len = 0;
     apr_status_t rv;
     const char *eol = APR_EOL_STR;
-    int eolc = 0, found_nl = 0;
+    apr_size_t eolc = 0;
+    int found_nl = 0;
     result_list *buflist = NULL, *curbuf = NULL;
 
 #ifndef NO_WRITEV
@@ -2442,7 +2448,7 @@ static apr_status_t rewritelock_create(server_rec *s, apr_pool_t *p)
         return rc;
     }
 
-#ifdef MOD_REWRITE_SET_MUTEX_PERMS
+#ifdef AP_NEED_SET_MUTEX_PERMS
     rc = unixd_set_global_mutex_perms(rewrite_mapr_lock_acquire);
     if (rc != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s,
@@ -2586,7 +2592,6 @@ static void *config_server_create(apr_pool_t *p, server_rec *s)
     a->rewriteconds    = apr_array_make(p, 2, sizeof(rewritecond_entry));
     a->rewriterules    = apr_array_make(p, 2, sizeof(rewriterule_entry));
     a->server          = s;
-    a->redirect_limit  = 0; /* unset (use default) */
 
     return (void *)a;
 }
@@ -2603,9 +2608,6 @@ static void *config_server_merge(apr_pool_t *p, void *basev, void *overridesv)
     a->state   = overrides->state;
     a->options = overrides->options;
     a->server  = overrides->server;
-    a->redirect_limit = overrides->redirect_limit
-                          ? overrides->redirect_limit
-                          : base->redirect_limit;
 
     if (a->options & OPTION_INHERIT) {
         /*
@@ -2659,7 +2661,6 @@ static void *config_perdir_create(apr_pool_t *p, char *path)
     a->baseurl         = NULL;
     a->rewriteconds    = apr_array_make(p, 2, sizeof(rewritecond_entry));
     a->rewriterules    = apr_array_make(p, 2, sizeof(rewriterule_entry));
-    a->redirect_limit  = 0; /* unset (use server config) */
 
     if (path == NULL) {
         a->directory = NULL;
@@ -2690,9 +2691,6 @@ static void *config_perdir_merge(apr_pool_t *p, void *basev, void *overridesv)
     a->options   = overrides->options;
     a->directory = overrides->directory;
     a->baseurl   = overrides->baseurl;
-    a->redirect_limit = overrides->redirect_limit
-                          ? overrides->redirect_limit
-                          : base->redirect_limit;
 
     if (a->options & OPTION_INHERIT) {
         a->rewriteconds = apr_array_append(p, overrides->rewriteconds,
@@ -2729,7 +2727,7 @@ static const char *cmd_rewriteengine(cmd_parms *cmd,
 static const char *cmd_rewriteoptions(cmd_parms *cmd,
                                       void *in_dconf, const char *option)
 {
-    int options = 0, limit = 0;
+    int options = 0;
     char *w;
 
     while (*option) {
@@ -2739,15 +2737,11 @@ static const char *cmd_rewriteoptions(cmd_parms *cmd,
             options |= OPTION_INHERIT;
         }
         else if (!strncasecmp(w, "MaxRedirects=", 13)) {
-            limit = atoi(&w[13]);
-            if (limit <= 0) {
-                return "RewriteOptions: MaxRedirects takes a number greater "
-                       "than zero.";
-            }
-        }
-        else if (!strcasecmp(w, "MaxRedirects")) { /* be nice */
-            return "RewriteOptions: MaxRedirects has the format MaxRedirects"
-                   "=n.";
+            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
+                         "RewriteOptions: MaxRedirects option has been "
+                         "removed in favor of the global "
+                         "LimitInternalRecursion directive and will be "
+                         "ignored.");
         }
         else {
             return apr_pstrcat(cmd->pool, "RewriteOptions: unknown option '",
@@ -2762,13 +2756,11 @@ static const char *cmd_rewriteoptions(cmd_parms *cmd,
                                  &rewrite_module);
 
         conf->options |= options;
-        conf->redirect_limit = limit;
     }
     else {                  /* is per-directory command */
         rewrite_perdir_conf *conf = in_dconf;
 
         conf->options |= options;
-        conf->redirect_limit = limit;
     }
 
     return NULL;
@@ -3054,7 +3046,7 @@ static const char *cmd_rewritecond(cmd_parms *cmd, void *in_dconf,
     char *str = apr_pstrdup(cmd->pool, in_str);
     rewrite_server_conf *sconf;
     rewritecond_entry *newcond;
-    regex_t *regexp;
+    ap_regex_t *regexp;
     char *a1;
     char *a2;
     char *a3;
@@ -3141,8 +3133,8 @@ static const char *cmd_rewritecond(cmd_parms *cmd, void *in_dconf,
 
     if (!newcond->ptype) {
         regexp = ap_pregcomp(cmd->pool, a2,
-                             REG_EXTENDED | ((newcond->flags & CONDFLAG_NOCASE)
-                                             ? REG_ICASE : 0));
+                             AP_REG_EXTENDED | ((newcond->flags & CONDFLAG_NOCASE)
+                                             ? AP_REG_ICASE : 0));
         if (!regexp) {
             return apr_pstrcat(cmd->pool, "RewriteCond: cannot compile regular "
                                "expression '", a2, "'", NULL);
@@ -3382,7 +3374,7 @@ static const char *cmd_rewriterule(cmd_parms *cmd, void *in_dconf,
     char *str = apr_pstrdup(cmd->pool, in_str);
     rewrite_server_conf *sconf;
     rewriterule_entry *newrule;
-    regex_t *regexp;
+    ap_regex_t *regexp;
     char *a1;
     char *a2;
     char *a3;
@@ -3427,9 +3419,9 @@ static const char *cmd_rewriterule(cmd_parms *cmd, void *in_dconf,
         ++a1;
     }
 
-    regexp = ap_pregcomp(cmd->pool, a1, REG_EXTENDED |
+    regexp = ap_pregcomp(cmd->pool, a1, AP_REG_EXTENDED |
                                         ((newrule->flags & RULEFLAG_NOCASE)
-                                         ? REG_ICASE : 0));
+                                         ? AP_REG_ICASE : 0));
     if (!regexp) {
         return apr_pstrcat(cmd->pool,
                            "RewriteRule: cannot compile regular expression '",
@@ -3501,7 +3493,7 @@ static int apply_rewrite_cond(rewritecond_entry *p, rewrite_ctx *ctx)
     char *input = do_expand(p->input, ctx);
     apr_finfo_t sb;
     request_rec *rsub, *r = ctx->r;
-    regmatch_t regmatch[AP_MAX_REG_MATCH];
+    ap_regmatch_t regmatch[AP_MAX_REG_MATCH];
     int rc = 0;
 
     switch (p->ptype) {
@@ -3654,7 +3646,7 @@ static APR_INLINE void force_type_handler(rewriterule_entry *p,
  */
 static int apply_rewrite_rule(rewriterule_entry *p, rewrite_ctx *ctx)
 {
-    regmatch_t regmatch[AP_MAX_REG_MATCH];
+    ap_regmatch_t regmatch[AP_MAX_REG_MATCH];
     apr_array_header_t *rewriteconds;
     rewritecond_entry *conds;
     int i, rc;
@@ -4053,7 +4045,7 @@ static int post_config(apr_pool_t *p,
         return HTTP_INTERNAL_SERVER_ERROR;
     }
 
-#ifdef MOD_REWRITE_SET_MUTEX_PERMS
+#ifdef AP_NEED_SET_MUTEX_PERMS
     rv = unixd_set_global_mutex_perms(rewrite_log_lock);
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
@@ -4209,7 +4201,7 @@ static int hook_uri2file(request_rec *r)
     thisurl = apr_table_get(r->subprocess_env, ENVVAR_SCRIPT_URL);
 
     /* set the variable */
-    var = apr_pstrcat(r->pool, ap_http_method(r), "://", thisserver, thisport,
+    var = apr_pstrcat(r->pool, ap_http_scheme(r), "://", thisserver, thisport,
                       thisurl, NULL);
     apr_table_setn(r->subprocess_env, ENVVAR_SCRIPT_URI, var);
 
@@ -4252,7 +4244,7 @@ static int hook_uri2file(request_rec *r)
             return n;
         }
 
-        flen = strlen(r->filename);
+        flen = r->filename ? strlen(r->filename) : 0;
         if (flen > 6 && strncmp(r->filename, "proxy:", 6) == 0) {
             /* it should be go on as an internal proxy request */
 
@@ -4274,7 +4266,7 @@ static int hook_uri2file(request_rec *r)
                                           r->path_info, NULL);
             }
             if (r->args != NULL &&
-                r->uri != r->unparsed_uri) {
+                r->uri == r->unparsed_uri) {
                 /* see proxy_http:proxy_http_canon() */
                 r->filename = apr_pstrcat(r->pool, r->filename,
                                           "?", r->args, NULL);
@@ -4722,57 +4714,6 @@ static int hook_mimetype(request_rec *r)
     return OK;
 }
 
-/* check whether redirect limit is reached */
-static int is_redirect_limit_exceeded(request_rec *r)
-{
-    request_rec *top = r;
-    rewrite_request_conf *reqc;
-    rewrite_perdir_conf *dconf;
-
-    /* we store it in the top request */
-    while (top->main) {
-        top = top->main;
-    }
-    while (top->prev) {
-        top = top->prev;
-    }
-
-    /* fetch our config */
-    reqc = (rewrite_request_conf *) ap_get_module_config(top->request_config,
-                                                         &rewrite_module);
-
-    /* no config there? create one. */
-    if (!reqc) {
-        rewrite_server_conf *sconf;
-
-        reqc = apr_palloc(top->pool, sizeof(rewrite_request_conf));
-        sconf = ap_get_module_config(r->server->module_config, &rewrite_module);
-
-        reqc->redirects = 0;
-        reqc->redirect_limit = sconf->redirect_limit
-                                 ? sconf->redirect_limit
-                                 : REWRITE_REDIRECT_LIMIT;
-
-        /* associate it with this request */
-        ap_set_module_config(top->request_config, &rewrite_module, reqc);
-    }
-
-    /* allow to change the limit during redirects. */
-    dconf = (rewrite_perdir_conf *)ap_get_module_config(r->per_dir_config,
-                                                        &rewrite_module);
-
-    /* 0 == unset; take server conf ... */
-    if (dconf->redirect_limit) {
-        reqc->redirect_limit = dconf->redirect_limit;
-    }
-
-    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
-                  "mod_rewrite's internal redirect status: %d/%d.",
-                  reqc->redirects, reqc->redirect_limit);
-
-    /* and now give the caller a hint */
-    return (reqc->redirects++ >= reqc->redirect_limit);
-}
 
 /*
  * "content" handler for internal redirects
@@ -4788,15 +4729,6 @@ static int handler_redirect(request_rec *r)
         return DECLINED;
     }
 
-    if (is_redirect_limit_exceeded(r)) {
-        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
-                      "mod_rewrite: maximum number of internal redirects "
-                      "reached. Assuming configuration error. Use "
-                      "'RewriteOptions MaxRedirects' to increase the limit "
-                      "if neccessary.");
-        return HTTP_INTERNAL_SERVER_ERROR;
-    }
-
     /* now do the internal redirect */
     ap_internal_redirect(apr_pstrcat(r->pool, r->filename+9,
                                      r->args ? "?" : NULL, r->args, NULL), r);