httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@locus.apache.org
Subject cvs commit: apache-1.3/src/modules/standard mod_rewrite.c mod_rewrite.h
Date Fri, 22 Sep 2000 20:43:58 GMT
fanf        00/09/22 13:43:56

  Modified:    src/modules/standard mod_rewrite.c mod_rewrite.h
  Log:
  Replace five instances of some similar code with calls to a function.
  This doesn't change any behaviour, just improves the code quality.
  
  Revision  Changes    Path
  1.161     +30 -55    apache-1.3/src/modules/standard/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v
  retrieving revision 1.160
  retrieving revision 1.161
  diff -u -u -r1.160 -r1.161
  --- mod_rewrite.c	2000/09/22 20:34:36	1.160
  +++ mod_rewrite.c	2000/09/22 20:43:54	1.161
  @@ -1130,20 +1130,7 @@
                          r->filename);
               return OK;
           }
  -        else if (  (strlen(r->filename) > 7 &&
  -                    strncasecmp(r->filename, "http://",   7) == 0)
  -                || (strlen(r->filename) > 8 &&
  -                    strncasecmp(r->filename, "https://",  8) == 0)
  -                || (strlen(r->filename) > 9 &&
  -                    strncasecmp(r->filename, "gopher://", 9) == 0)
  -                || (strlen(r->filename) > 6 &&
  -                    strncasecmp(r->filename, "ftp://",    6) == 0)
  -                || (strlen(r->filename) > 5 &&
  -                    strncasecmp(r->filename, "ldap:",     5) == 0)
  -                || (strlen(r->filename) > 5 &&
  -                    strncasecmp(r->filename, "news:",     5) == 0)
  -                || (strlen(r->filename) > 7 &&
  -                    strncasecmp(r->filename, "mailto:",   7) == 0)) {
  +        else if (is_absolute_uri(r->filename)) {
               /* it was finally rewritten to a remote URL */
   
               /* skip 'scheme:' */
  @@ -1394,20 +1381,7 @@
                          "%s [OK]", dconf->directory, r->filename);
               return OK;
           }
  -        else if (  (strlen(r->filename) > 7 &&
  -                    strncasecmp(r->filename, "http://",   7) == 0)
  -                || (strlen(r->filename) > 8 &&
  -                    strncasecmp(r->filename, "https://",  8) == 0)
  -                || (strlen(r->filename) > 9 &&
  -                    strncasecmp(r->filename, "gopher://", 9) == 0)
  -                || (strlen(r->filename) > 6 &&
  -                    strncasecmp(r->filename, "ftp://",    6) == 0)
  -                || (strlen(r->filename) > 5 &&
  -                    strncasecmp(r->filename, "ldap:",     5) == 0)
  -                || (strlen(r->filename) > 5 &&
  -                    strncasecmp(r->filename, "news:",     5) == 0)
  -                || (strlen(r->filename) > 7 &&
  -                    strncasecmp(r->filename, "mailto:",   7) == 0)) {
  +        else if (is_absolute_uri(r->filename)) {
               /* it was finally rewritten to a remote URL */
   
               /* because we are in a per-dir context
  @@ -1975,16 +1949,8 @@
        *   location, i.e. if it's not starting with either a slash
        *   or a fully qualified URL scheme.
        */
  -    i = strlen(r->filename);
  -    if (   prefixstrip
  -        && !(   r->filename[0] == '/'
  -             || (   (i > 7 && strncasecmp(r->filename, "http://",   7) ==
0)
  -                 || (i > 8 && strncasecmp(r->filename, "https://",  8) ==
0)
  -                 || (i > 9 && strncasecmp(r->filename, "gopher://", 9) ==
0)
  -                 || (i > 6 && strncasecmp(r->filename, "ftp://",    6) ==
0)
  -                 || (i > 5 && strncasecmp(r->filename, "ldap:",     5) ==
0)
  -                 || (i > 5 && strncasecmp(r->filename, "news:",     5) ==
0)
  -                 || (i > 7 && strncasecmp(r->filename, "mailto:",   7) ==
0)))) {
  +    if (prefixstrip && r->filename[0] != '/'
  +	&& !is_absolute_uri(r->filename)) {
           rewritelog(r, 3, "[per-dir %s] add per-dir prefix: %s -> %s%s",
                      perdir, r->filename, perdir, r->filename);
           r->filename = ap_pstrcat(r->pool, perdir, r->filename, NULL);
  @@ -2048,14 +2014,7 @@
        *  redirection (`RewriteRule .. <scheme>://...') then
        *  directly force an external HTTP redirect.
        */
  -    i = strlen(r->filename);
  -    if (   (i > 7 && strncasecmp(r->filename, "http://",   7) == 0)
  -        || (i > 8 && strncasecmp(r->filename, "https://",  8) == 0)
  -        || (i > 9 && strncasecmp(r->filename, "gopher://", 9) == 0)
  -        || (i > 6 && strncasecmp(r->filename, "ftp://",    6) == 0)
  -        || (i > 5 && strncasecmp(r->filename, "ldap:",     5) == 0)
  -        || (i > 5 && strncasecmp(r->filename, "news:",     5) == 0)
  -        || (i > 7 && strncasecmp(r->filename, "mailto:",   7) == 0) ) {
  +    if (is_absolute_uri(r->filename)) {
           if (perdir == NULL) {
               rewritelog(r, 2,
                          "implicitly forcing redirect (rc=%d) with %s",
  @@ -2529,20 +2488,12 @@
   
   static void fully_qualify_uri(request_rec *r)
   {
  -    int i;
       char buf[32];
       const char *thisserver;
       char *thisport;
       int port;
   
  -    i = strlen(r->filename);
  -    if (!(   (i > 7 && strncasecmp(r->filename, "http://",   7) == 0)
  -          || (i > 8 && strncasecmp(r->filename, "https://",  8) == 0)
  -          || (i > 9 && strncasecmp(r->filename, "gopher://", 9) == 0)
  -          || (i > 6 && strncasecmp(r->filename, "ftp://",    6) == 0)
  -          || (i > 5 && strncasecmp(r->filename, "ldap:",     5) == 0)
  -          || (i > 5 && strncasecmp(r->filename, "news:",     5) == 0)
  -          || (i > 7 && strncasecmp(r->filename, "mailto:",   7) == 0))) {
  +    if (!is_absolute_uri(r->filename)) {
   
           thisserver = ap_get_server_name(r);
           port = ap_get_server_port(r);
  @@ -2566,6 +2517,30 @@
           }
       }
       return;
  +}
  +
  +
  +/*
  +**
  +**  return non-zero if the URI is absolute (includes a scheme etc.)
  +**
  +*/
  +
  +static int is_absolute_uri(char *uri)
  +{
  +    int i = strlen(uri);
  +    if (   (i > 7 && strncasecmp(uri, "http://",   7) == 0)
  +        || (i > 8 && strncasecmp(uri, "https://",  8) == 0)
  +        || (i > 9 && strncasecmp(uri, "gopher://", 9) == 0)
  +        || (i > 6 && strncasecmp(uri, "ftp://",    6) == 0)
  +        || (i > 5 && strncasecmp(uri, "ldap:",     5) == 0)
  +        || (i > 5 && strncasecmp(uri, "news:",     5) == 0)
  +        || (i > 7 && strncasecmp(uri, "mailto:",   7) == 0) ) {
  +	return 1;
  +    }
  +    else {
  +	return 0;
  +    }
   }
   
   
  
  
  
  1.70      +1 -0      apache-1.3/src/modules/standard/mod_rewrite.h
  
  Index: mod_rewrite.h
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.h,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -u -r1.69 -r1.70
  --- mod_rewrite.h	2000/09/22 20:34:36	1.69
  +++ mod_rewrite.h	2000/09/22 20:43:55	1.70
  @@ -429,6 +429,7 @@
   static void  splitout_queryargs(request_rec *r, int qsappend);
   static void  fully_qualify_uri(request_rec *r);
   static void  reduce_uri(request_rec *r);
  +static int   is_absolute_uri(char *uri);
   static char *expand_tildepaths(request_rec *r, char *uri);
   
       /* rewrite map support functions */
  
  
  

Mime
View raw message