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 Wed, 16 Jul 2003 01:04:24 GMT
nd          2003/07/15 18:04:24

  Modified:    modules/mappers mod_rewrite.c
  Log:
  optimization: speed up ruleflag parsing.
  
  Revision  Changes    Path
  1.161     +123 -95   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.160
  retrieving revision 1.161
  diff -u -r1.160 -r1.161
  --- mod_rewrite.c	15 Jul 2003 23:30:40 -0000	1.160
  +++ mod_rewrite.c	16 Jul 2003 01:04:23 -0000	1.161
  @@ -858,110 +858,138 @@
                                              char *key, char *val)
   {
       int status = 0;
  -    int i;
  +    int i = 0;
   
  -    if (   strcasecmp(key, "redirect") == 0
  -        || strcasecmp(key, "R") == 0       ) {
  -        cfg->flags |= RULEFLAG_FORCEREDIRECT;
  -        if (strlen(val) > 0) {
  -            if (strcasecmp(val, "permanent") == 0) {
  -                status = HTTP_MOVED_PERMANENTLY;
  -            }
  -            else if (strcasecmp(val, "temp") == 0) {
  -                status = HTTP_MOVED_TEMPORARILY;
  -            }
  -            else if (strcasecmp(val, "seeother") == 0) {
  -                status = HTTP_SEE_OTHER;
  -            }
  -            else if (apr_isdigit(*val)) {
  -                status = atoi(val);
  -            }
  -            if (!ap_is_HTTP_REDIRECT(status)) {
  -                return "RewriteRule: invalid HTTP response code "
  -                       "for flag 'R'";
  +    switch (*key++) {
  +    case 'c':
  +    case 'C':
  +        if (!*key || !strcasecmp(key, "hain")) {           /* chain */
  +            cfg->flags |= RULEFLAG_CHAIN;
  +        }
  +        else if (((*key == 'O' || *key == 'o') && !key[1])
  +                 || !strcasecmp(key, "ookie")) {           /* cookie */
  +            while (cfg->cookie[i] && i < MAX_COOKIE_FLAGS) {
  +                ++i;
  +            }
  +            if (i < MAX_COOKIE_FLAGS) {
  +                cfg->cookie[i] = apr_pstrdup(p, val);
  +                cfg->cookie[i+1] = NULL;
  +            }
  +            else {
  +                return "RewriteRule: too many cookie flags 'CO'";
               }
  -            cfg->forced_responsecode = status;
           }
  -    }
  -    else if (   strcasecmp(key, "noescape") == 0
  -        || strcasecmp(key, "NE") == 0       ) {
  -        cfg->flags |= RULEFLAG_NOESCAPE;
  -    }
  -    else if (   strcasecmp(key, "last") == 0
  -             || strcasecmp(key, "L") == 0   ) {
  -        cfg->flags |= RULEFLAG_LASTRULE;
  -    }
  -    else if (   strcasecmp(key, "next") == 0
  -             || strcasecmp(key, "N") == 0   ) {
  -        cfg->flags |= RULEFLAG_NEWROUND;
  -    }
  -    else if (   strcasecmp(key, "chain") == 0
  -             || strcasecmp(key, "C") == 0    ) {
  -        cfg->flags |= RULEFLAG_CHAIN;
  -    }
  -    else if (   strcasecmp(key, "type") == 0
  -             || strcasecmp(key, "T") == 0   ) {
  -        cfg->forced_mimetype = apr_pstrdup(p, val);
  -        ap_str_tolower(cfg->forced_mimetype);
  -    }
  -    else if (   strcasecmp(key, "env") == 0
  -             || strcasecmp(key, "E") == 0   ) {
  -        for (i = 0; (cfg->env[i] != NULL) && (i < MAX_ENV_FLAGS); i++)
  -            ;
  -        if (i < MAX_ENV_FLAGS) {
  -            cfg->env[i] = apr_pstrdup(p, val);
  -            cfg->env[i+1] = NULL;
  +        break;
  +    case 'e':
  +    case 'E':
  +        if (!*key || !strcasecmp(key, "nv")) {             /* env */
  +            while (cfg->env[i] && i < MAX_ENV_FLAGS) {
  +                ++i;
  +            }
  +            if (i < MAX_ENV_FLAGS) {
  +                cfg->env[i] = apr_pstrdup(p, val);
  +                cfg->env[i+1] = NULL;
  +            }
  +            else {
  +                return "RewriteRule: too many environment flags 'E'";
  +            }
           }
  -        else {
  -            return "RewriteRule: too many environment flags 'E'";
  +        break;
  +    case 'f':
  +    case 'F':
  +        if (!*key || !strcasecmp(key, "orbidden")) {       /* forbidden */
  +            cfg->flags |= RULEFLAG_FORBIDDEN;
           }
  -    }
  -    else  if ( strcasecmp(key, "cookie") == 0 || strcasecmp(key, "CO") == 0) {
  -        for (i = 0; (cfg->cookie[i] != NULL) && (i < MAX_COOKIE_FLAGS); i++)
  -            ;
  -        if (i < MAX_COOKIE_FLAGS) {
  -            cfg->cookie[i] = apr_pstrdup(p, val);
  -            cfg->cookie[i+1] = NULL;
  +        break;
  +    case 'g':
  +    case 'G':
  +        if (!*key || !strcasecmp(key, "one")) {            /* gone */
  +            cfg->flags |= RULEFLAG_GONE;
           }
  -        else {
  -            return "RewriteRule: too many cookie flags 'CO'";
  +        break;
  +    case 'l':
  +    case 'L':
  +        if (!*key || !strcasecmp(key, "ast")) {            /* last */
  +            cfg->flags |= RULEFLAG_LASTRULE;
           }
  -    }
  -    else if (   strcasecmp(key, "nosubreq") == 0
  -             || strcasecmp(key, "NS") == 0      ) {
  -        cfg->flags |= RULEFLAG_IGNOREONSUBREQ;
  -    }
  -    else if (   strcasecmp(key, "proxy") == 0
  -             || strcasecmp(key, "P") == 0      ) {
  -        cfg->flags |= RULEFLAG_PROXY;
  -    }
  -    else if (   strcasecmp(key, "passthrough") == 0
  -             || strcasecmp(key, "PT") == 0      ) {
  -        cfg->flags |= RULEFLAG_PASSTHROUGH;
  -    }
  -    else if (   strcasecmp(key, "skip") == 0
  -             || strcasecmp(key, "S") == 0   ) {
  -        cfg->skip = atoi(val);
  -    }
  -    else if (   strcasecmp(key, "forbidden") == 0
  -             || strcasecmp(key, "F") == 0   ) {
  -        cfg->flags |= RULEFLAG_FORBIDDEN;
  -    }
  -    else if (   strcasecmp(key, "gone") == 0
  -             || strcasecmp(key, "G") == 0   ) {
  -        cfg->flags |= RULEFLAG_GONE;
  -    }
  -    else if (   strcasecmp(key, "qsappend") == 0
  -             || strcasecmp(key, "QSA") == 0   ) {
  -        cfg->flags |= RULEFLAG_QSAPPEND;
  -    }
  -    else if (   strcasecmp(key, "nocase") == 0
  -             || strcasecmp(key, "NC") == 0    ) {
  -        cfg->flags |= RULEFLAG_NOCASE;
  -    }
  -    else {
  +        break;
  +    case 'n':
  +    case 'N':
  +        if (((*key == 'E' || *key == 'e') && !key[1])
  +            || !strcasecmp(key, "oescape")) {              /* noescape */
  +            cfg->flags |= RULEFLAG_NOESCAPE;
  +        }
  +        else if (!*key || !strcasecmp(key, "ext")) {       /* next */
  +            cfg->flags |= RULEFLAG_NEWROUND;
  +        }
  +        else if (((*key == 'S' || *key == 's') && !key[1])
  +            || !strcasecmp(key, "osubreq")) {              /* nosubreq */
  +            cfg->flags |= RULEFLAG_IGNOREONSUBREQ;
  +        }
  +        else if (((*key == 'C' || *key == 'c') && !key[1])
  +            || !strcasecmp(key, "ocase")) {                /* nocase */
  +            cfg->flags |= RULEFLAG_NOCASE;
  +        }
  +        break;
  +    case 'p':
  +    case 'P':
  +        if (!*key || !strcasecmp(key, "roxy")) {           /* proxy */
  +            cfg->flags |= RULEFLAG_PROXY;
  +        }
  +        else if (((*key == 'T' || *key == 't') && !key[1])
  +            || !strcasecmp(key, "assthrough")) {           /* passthrough */
  +            cfg->flags |= RULEFLAG_PASSTHROUGH;
  +        }
  +        break;
  +    case 'q':
  +    case 'Q':
  +        if (   !strcasecmp(key, "QSA")
  +            || !strcasecmp(key, "qsappend")) {             /* qsappend */
  +            cfg->flags |= RULEFLAG_QSAPPEND;
  +        }
  +        break;
  +    case 'r':
  +    case 'R':
  +        if (!*key || !strcasecmp(key, "edirect")) {        /* redirect */
  +            cfg->flags |= RULEFLAG_FORCEREDIRECT;
  +            if (strlen(val) > 0) {
  +                if (strcasecmp(val, "permanent") == 0) {
  +                    status = HTTP_MOVED_PERMANENTLY;
  +                }
  +                else if (strcasecmp(val, "temp") == 0) {
  +                    status = HTTP_MOVED_TEMPORARILY;
  +                }
  +                else if (strcasecmp(val, "seeother") == 0) {
  +                    status = HTTP_SEE_OTHER;
  +                }
  +                else if (apr_isdigit(*val)) {
  +                    status = atoi(val);
  +                    if (!ap_is_HTTP_REDIRECT(status)) {
  +                        return "RewriteRule: invalid HTTP response code "
  +                               "for flag 'R'";
  +                    }
  +                }
  +                cfg->forced_responsecode = status;
  +            }
  +        }
  +        break;
  +    case 't':
  +    case 'T':
  +        if (!*key || !strcasecmp(key, "ype")) {             /* type */
  +            cfg->forced_mimetype = apr_pstrdup(p, val);
  +            ap_str_tolower(cfg->forced_mimetype);
  +        }
  +        break;
  +    case 's':
  +    case 'S':
  +        if (!*key || !strcasecmp(key, "kip")) {            /* skip */
  +            cfg->skip = atoi(val);
  +        }
  +        break;
  +    default:
           return apr_pstrcat(p, "RewriteRule: unknown flag '", key, "'", NULL);
       }
  +
       return NULL;
   }
   
  
  
  

Mime
View raw message