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 Sun, 27 Jul 2003 00:08:21 GMT
nd          2003/07/26 17:08:21

  Modified:    modules/mappers mod_rewrite.c
  Log:
  cleanup lookup_map function.
  - use switch instead of if-else chain
  - collapse txt/rnd code, which is essentially the same
  - make it better readable at all.
  
  Revision  Changes    Path
  1.182     +104 -139  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.181
  retrieving revision 1.182
  diff -u -r1.181 -r1.182
  --- mod_rewrite.c	26 Jul 2003 23:04:18 -0000	1.181
  +++ mod_rewrite.c	27 Jul 2003 00:08:21 -0000	1.182
  @@ -1547,147 +1547,112 @@
           return NULL;
       }
   
  -            if (s->type == MAPTYPE_TXT) {
  -                if ((rv = apr_stat(&st, s->checkfile,
  -                                   APR_FINFO_MIN, r->pool)) != APR_SUCCESS) {
  -                    ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
  -                                  "mod_rewrite: can't access text RewriteMap "
  -                                  "file %s", s->checkfile);
  -                    rewritelog(r, 1, "can't open RewriteMap file, "
  -                               "see error log");
  -                    return NULL;
  -                }
  -                value = get_cache_string(cachep, name, CACHEMODE_TS,
  -                                         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", name, key, value);
  -                        set_cache_string(cachep, name, CACHEMODE_TS,
  -                                         st.mtime, key, value);
  -                        return value;
  -                    }
  -                    else {
  -                        rewritelog(r, 5, "map lookup FAILED: map=%s[txt] "
  -                                   "key=%s", name, key);
  -                        set_cache_string(cachep, name, CACHEMODE_TS,
  -                                         st.mtime, key, "");
  -                        return NULL;
  -                    }
  -                }
  -                else {
  -                    rewritelog(r, 5, "cache lookup OK: map=%s[txt] key=%s "
  -                               "-> val=%s", name, key, value);
  -                    return value[0] != '\0' ? value : NULL;
  -                }
  +    switch (s->type) {
  +    /*
  +     * Text file map (perhaps random)
  +     */
  +    case MAPTYPE_RND:
  +    case MAPTYPE_TXT:
  +        rv = apr_stat(&st, s->checkfile, APR_FINFO_MIN, r->pool);
  +        if (rv != APR_SUCCESS) {
  +            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
  +                          "mod_rewrite: can't access text RewriteMap file %s",
  +                          s->checkfile);
  +            rewritelog(r, 1, "can't open RewriteMap file, see error log");
  +            return NULL;
  +        }
  +
  +        value = get_cache_string(cachep, name, CACHEMODE_TS, st.mtime, key);
  +        if (!value) {
  +            rewritelog(r, 6, "cache lookup FAILED, forcing new map lookup");
  +
  +            value = lookup_map_txtfile(r, s->datafile, key);
  +            if (!value) {
  +                rewritelog(r, 5, "map lookup FAILED: map=%s[txt] key=%s",
  +                           name, key);
  +                set_cache_string(cachep, name, CACHEMODE_TS, st.mtime, key, "");
  +                return NULL;
               }
  -            else if (s->type == MAPTYPE_DBM) {
  -                if ((rv = apr_stat(&st, s->checkfile,
  -                                   APR_FINFO_MIN, r->pool)) != APR_SUCCESS) {
  -                    ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
  -                                  "mod_rewrite: can't access DBM RewriteMap "
  -                                  "file %s", s->checkfile);
  -                    rewritelog(r, 1, "can't open DBM RewriteMap file, "
  -                               "see error log");
  -                    return NULL;
  -                }
  -                value = get_cache_string(cachep, name, CACHEMODE_TS,
  -                                         st.mtime, key);
  -                if (value == NULL) {
  -                    rewritelog(r, 6,
  -                               "cache lookup FAILED, forcing new map lookup");
  -                    if ((value =
  -                         lookup_map_dbmfile(r, s->datafile, s->dbmtype, key)) !=
NULL) {
  -                        rewritelog(r, 5, "map lookup OK: map=%s[dbm] key=%s "
  -                                   "-> val=%s", name, key, value);
  -                        set_cache_string(cachep, name, CACHEMODE_TS,
  -                                         st.mtime, key, value);
  -                        return value;
  -                    }
  -                    else {
  -                        rewritelog(r, 5, "map lookup FAILED: map=%s[dbm] "
  -                                   "key=%s", name, key);
  -                        set_cache_string(cachep, name, CACHEMODE_TS,
  -                                         st.mtime, key, "");
  -                        return NULL;
  -                    }
  -                }
  -                else {
  -                    rewritelog(r, 5, "cache lookup OK: map=%s[dbm] key=%s "
  -                               "-> val=%s", name, key, value);
  -                    return value[0] != '\0' ? value : NULL;
  -                }
  -            }
  -            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",
  -                               name, key, value);
  -                    return value;
  -                }
  -                else {
  -                    rewritelog(r, 5, "map lookup FAILED: map=%s key=%s",
  -                               name, key);
  -                }
  -            }
  -            else if (s->type == MAPTYPE_INT) {
  -                if ((value = s->func(r, key)) != NULL) {
  -                    rewritelog(r, 5, "map lookup OK: map=%s key=%s -> val=%s",
  -                               name, key, value);
  -                    return value;
  -                }
  -                else {
  -                    rewritelog(r, 5, "map lookup FAILED: map=%s key=%s",
  -                               name, key);
  -                }
  -            }
  -            else if (s->type == MAPTYPE_RND) {
  -                if ((rv = apr_stat(&st, s->checkfile,
  -                                   APR_FINFO_MIN, r->pool)) != APR_SUCCESS) {
  -                    ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
  -                                  "mod_rewrite: can't access text RewriteMap "
  -                                  "file %s", s->checkfile);
  -                    rewritelog(r, 1, "can't open RewriteMap file, "
  -                               "see error log");
  -                    return NULL;
  -                }
  -                value = get_cache_string(cachep, name, CACHEMODE_TS,
  -                                         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", name, key, value);
  -                        set_cache_string(cachep, name, CACHEMODE_TS,
  -                                         st.mtime, key, value);
  -                    }
  -                    else {
  -                        rewritelog(r, 5, "map lookup FAILED: map=%s[txt] "
  -                                   "key=%s", name, key);
  -                        set_cache_string(cachep, name, CACHEMODE_TS,
  -                                         st.mtime, key, "");
  -                        return NULL;
  -                    }
  -                }
  -                else {
  -                    rewritelog(r, 5, "cache lookup OK: map=%s[txt] key=%s "
  -                               "-> val=%s", name, key, value);
  -                }
  -                if (value[0] != '\0') {
  -                   value = select_random_value_part(r, value);
  -                   rewritelog(r, 5, "randomly choosen the subvalue `%s'",
  -                              value);
  -                }
  -                else {
  -                    value = NULL;
  -                }
  -                return value;
  +
  +            rewritelog(r, 5, "map lookup OK: map=%s key=%s[txt] -> val=%s",
  +                       name, key, value);
  +            set_cache_string(cachep, name, CACHEMODE_TS, st.mtime, key, value);
  +        }
  +        else {
  +            rewritelog(r, 5, "cache lookup OK: map=%s[txt] key=%s -> val=%s",
  +                       name, key, value);
  +        }
  +
  +        if (s->type == MAPTYPE_RND && *value) {
  +            value = select_random_value_part(r, value);
  +            rewritelog(r, 5, "randomly chosen the subvalue `%s'", value);
  +        }
  +
  +        return *value ? value : NULL;
  +
  +    /*
  +     * DBM file map
  +     */
  +    case MAPTYPE_DBM:
  +        rv = apr_stat(&st, s->checkfile, APR_FINFO_MIN, r->pool);
  +        if (rv != APR_SUCCESS) {
  +            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
  +                          "mod_rewrite: can't access DBM RewriteMap file %s",
  +                          s->checkfile);
  +            rewritelog(r, 1, "can't open DBM RewriteMap file, see error log");
  +            return NULL;
  +        }
  +
  +        value = get_cache_string(cachep, name, CACHEMODE_TS, st.mtime, key);
  +        if (!value) {
  +            rewritelog(r, 6, "cache lookup FAILED, forcing new map lookup");
  +
  +            value = lookup_map_dbmfile(r, s->datafile, s->dbmtype, key);
  +            if (!value) {
  +                rewritelog(r, 5, "map lookup FAILED: map=%s[dbm] key=%s",
  +                           name, key);
  +                set_cache_string(cachep, name, CACHEMODE_TS, st.mtime, key, "");
  +                return NULL;
               }
  +
  +            rewritelog(r, 5, "map lookup OK: map=%s[dbm] key=%s -> val=%s",
  +                       name, key, value);
  +            set_cache_string(cachep, name, CACHEMODE_TS, st.mtime, key, value);
  +            return value;
  +        }
  +
  +        rewritelog(r, 5, "cache lookup OK: map=%s[dbm] key=%s -> val=%s",
  +                   name, key, value);
  +        return *value ? value : NULL;
  +
  +    /*
  +     * Program file map
  +     */
  +    case MAPTYPE_PRG:
  +        value = lookup_map_program(r, s->fpin, s->fpout, key);
  +        if (!value) {
  +            rewritelog(r, 5, "map lookup FAILED: map=%s key=%s", name, key);
  +            return NULL;
  +        }
  +
  +        rewritelog(r, 5, "map lookup OK: map=%s key=%s -> val=%s",
  +                   name, key, value);
  +        return value;
  +
  +    /*
  +     * Internal Map
  +     */
  +    case MAPTYPE_INT:
  +        value = s->func(r, key);
  +        if (!value) {
  +            rewritelog(r, 5, "map lookup FAILED: map=%s key=%s", name, key);
  +            return NULL;
  +        }
  +
  +        rewritelog(r, 5, "map lookup OK: map=%s key=%s -> val=%s",
  +                   name, key, value);
  +        return value;
  +    }
   
       return NULL;
   }
  
  
  

Mime
View raw message