You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jw...@apache.org on 2002/06/03 09:47:53 UTC

cvs commit: apr-util/uri apr_uri.c

jwoolley    2002/06/03 00:47:53

  Modified:    include  apr_uri.h
               uri      apr_uri.c
  Log:
  style police
  
  Revision  Changes    Path
  1.11      +22 -14    apr-util/include/apr_uri.h
  
  Index: apr_uri.h
  ===================================================================
  RCS file: /home/cvs/apr-util/include/apr_uri.h,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -d -u -r1.10 -r1.11
  --- apr_uri.h	13 Mar 2002 20:40:48 -0000	1.10
  +++ apr_uri.h	3 Jun 2002 07:47:53 -0000	1.11
  @@ -101,14 +101,22 @@
   #define APR_URI_TIP_DEFAULT_PORT       3372
   #define APR_URI_SIP_DEFAULT_PORT       5060
   
  -/* Flags passed to unparse_uri_components(): */
  -#define APR_URI_UNP_OMITSITEPART	(1U<<0)	/* suppress "scheme://user@site:port" */
  -#define	APR_URI_UNP_OMITUSER		(1U<<1)	/* Just omit user */
  -#define	APR_URI_UNP_OMITPASSWORD	(1U<<2)	/* Just omit password */
  -#define	APR_URI_UNP_OMITUSERINFO	(APR_URI_UNP_OMITUSER|APR_URI_UNP_OMITPASSWORD)	/* omit "user:password@" part */
  -#define	APR_URI_UNP_REVEALPASSWORD	(1U<<3)	/* Show plain text password (default: show XXXXXXXX) */
  -#define APR_URI_UNP_OMITPATHINFO	(1U<<4)	/* Show "scheme://user@site:port" only */
  -#define APR_URI_UNP_OMITQUERY	        (1U<<5)	/* Omit the "?queryarg" from the path */
  +/** Flags passed to unparse_uri_components(): */
  +/** suppress "scheme://user@site:port" */
  +#define APR_URI_UNP_OMITSITEPART    (1U<<0)
  +/** Just omit user */
  +#define APR_URI_UNP_OMITUSER        (1U<<1)
  +/** Just omit password */
  +#define APR_URI_UNP_OMITPASSWORD    (1U<<2)
  +/** omit "user:password@" part */
  +#define APR_URI_UNP_OMITUSERINFO    (APR_URI_UNP_OMITUSER | \
  +                                     APR_URI_UNP_OMITPASSWORD)
  +/** Show plain text password (default: show XXXXXXXX) */
  +#define APR_URI_UNP_REVEALPASSWORD  (1U<<3)
  +/** Show "scheme://user@site:port" only */
  +#define APR_URI_UNP_OMITPATHINFO    (1U<<4)
  +/** Omit the "?queryarg" from the path */
  +#define APR_URI_UNP_OMITQUERY       (1U<<5)
   
   typedef struct apr_uri_t apr_uri_t;
   
  @@ -178,8 +186,8 @@
    * @return The uri as a string
    */
   APU_DECLARE(char *) apr_uri_unparse(apr_pool_t *p, 
  -                                               const apr_uri_t *uptr,
  -                                               unsigned flags);
  +                                    const apr_uri_t *uptr,
  +                                    unsigned flags);
   
   /**
    * Parse a given URI, fill in all supplied fields of a apr_uri_t
  @@ -191,7 +199,7 @@
    * @return An HTTP status code
    */
   APU_DECLARE(int) apr_uri_parse(apr_pool_t *p, const char *uri, 
  -                                          apr_uri_t *uptr);
  +                               apr_uri_t *uptr);
   
   /**
    * Special case for CONNECT parsing: it comes with the hostinfo part only
  @@ -201,12 +209,12 @@
    * @return An HTTP status code
    */
   APU_DECLARE(int) apr_uri_parse_hostinfo(apr_pool_t *p, 
  -                                                   const char *hostinfo, 
  -                                                   apr_uri_t *uptr);
  +                                        const char *hostinfo, 
  +                                        apr_uri_t *uptr);
   
   /** @} */
   #ifdef __cplusplus
   }
   #endif
   
  -#endif /*APR_URI_H*/
  +#endif /* APR_URI_H */
  
  
  
  1.13      +135 -122  apr-util/uri/apr_uri.c
  
  Index: apr_uri.c
  ===================================================================
  RCS file: /home/cvs/apr-util/uri/apr_uri.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -d -u -r1.12 -r1.13
  --- apr_uri.c	13 Mar 2002 20:40:49 -0000	1.12
  +++ apr_uri.c	3 Jun 2002 07:47:53 -0000	1.13
  @@ -112,9 +112,11 @@
   {
       schemes_t *scheme;
   
  -    for (scheme = schemes; scheme->name != NULL; ++scheme)
  -	if (strcasecmp(scheme_str, scheme->name) == 0)
  -	    return scheme->default_port;
  +    for (scheme = schemes; scheme->name != NULL; ++scheme) {
  +        if (strcasecmp(scheme_str, scheme->name) == 0) {
  +            return scheme->default_port;
  +        }
  +    }
   
       return 0;
   }
  @@ -123,55 +125,66 @@
    * Optionally suppress the password for security reasons.
    */
   APU_DECLARE(char *) apr_uri_unparse(apr_pool_t *p, 
  -                                               const apr_uri_t *uptr, 
  -                                               unsigned flags)
  +                                    const apr_uri_t *uptr, 
  +                                    unsigned flags)
   {
       char *ret = "";
   
       /* If suppressing the site part, omit both user name & scheme://hostname */
       if (!(flags & APR_URI_UNP_OMITSITEPART)) {
   
  -	/* Construct a "user:password@" string, honoring the passed APR_URI_UNP_ flags: */
  -	if (uptr->user||uptr->password)
  -	    ret = apr_pstrcat (p,
  -			(uptr->user     && !(flags & APR_URI_UNP_OMITUSER)) ? uptr->user : "",
  -			(uptr->password && !(flags & APR_URI_UNP_OMITPASSWORD)) ? ":" : "",
  -			(uptr->password && !(flags & APR_URI_UNP_OMITPASSWORD))
  -			   ? ((flags & APR_URI_UNP_REVEALPASSWORD) ? uptr->password : "XXXXXXXX")
  -			   : "",
  -            ((uptr->user     && !(flags & APR_URI_UNP_OMITUSER)) ||
  -             (uptr->password && !(flags & APR_URI_UNP_OMITPASSWORD))) ? "@" : "", 
  -            NULL);
  +        /* Construct a "user:password@" string, honoring the passed
  +         * APR_URI_UNP_ flags: */
  +        if (uptr->user || uptr->password) {
  +            ret = apr_pstrcat(p,
  +                      (uptr->user     && !(flags & APR_URI_UNP_OMITUSER))
  +                          ? uptr->user : "",
  +                      (uptr->password && !(flags & APR_URI_UNP_OMITPASSWORD))
  +                          ? ":" : "",
  +                      (uptr->password && !(flags & APR_URI_UNP_OMITPASSWORD))
  +                          ? ((flags & APR_URI_UNP_REVEALPASSWORD)
  +                              ? uptr->password : "XXXXXXXX")
  +                          : "",
  +                      ((uptr->user     && !(flags & APR_URI_UNP_OMITUSER)) ||
  +                       (uptr->password && !(flags & APR_URI_UNP_OMITPASSWORD)))
  +                          ? "@" : "", 
  +                      NULL);
  +        }
   
  -	/* Construct scheme://site string */
  -	if (uptr->hostname) {
  -	    int is_default_port;
  +        /* Construct scheme://site string */
  +        if (uptr->hostname) {
  +            int is_default_port;
   
  -	    is_default_port =
  -		(uptr->port_str == NULL ||
  -		 uptr->port == 0 ||
  -		 uptr->port == apr_uri_default_port_for_scheme(uptr->scheme));
  +            is_default_port =
  +                (uptr->port_str == NULL ||
  +                 uptr->port == 0 ||
  +                 uptr->port == apr_uri_default_port_for_scheme(uptr->scheme));
   
  -	    ret = apr_pstrcat (p,
  -			uptr->scheme, "://", ret, 
  -			uptr->hostname ? uptr->hostname : "",
  -			is_default_port ? "" : ":",
  -			is_default_port ? "" : uptr->port_str,
  -			NULL);
  -	}
  +            ret = apr_pstrcat(p,
  +                      uptr->scheme, "://", ret, 
  +                      uptr->hostname ? uptr->hostname : "",
  +                      is_default_port ? "" : ":",
  +                      is_default_port ? "" : uptr->port_str,
  +                      NULL);
  +        }
       }
   
       /* Should we suppress all path info? */
       if (!(flags & APR_URI_UNP_OMITPATHINFO)) {
  -	/* Append path, query and fragment strings: */
  -	ret = apr_pstrcat (p,
  -		ret,
  -		uptr->path ? uptr->path : "",
  -		(uptr->query    && !(flags & APR_URI_UNP_OMITQUERY)) ? "?" : "",
  -		(uptr->query    && !(flags & APR_URI_UNP_OMITQUERY)) ? uptr->query : "",
  -		(uptr->fragment && !(flags & APR_URI_UNP_OMITQUERY)) ? "#" : NULL,
  -		(uptr->fragment && !(flags & APR_URI_UNP_OMITQUERY)) ? uptr->fragment : NULL,
  -		NULL);
  +        /* Append path, query and fragment strings: */
  +        ret = apr_pstrcat(p,
  +                          ret,
  +                          (uptr->path)
  +                              ? uptr->path : "",
  +                          (uptr->query    && !(flags & APR_URI_UNP_OMITQUERY))
  +                              ? "?" : "",
  +                          (uptr->query    && !(flags & APR_URI_UNP_OMITQUERY))
  +                              ? uptr->query : "",
  +                          (uptr->fragment && !(flags & APR_URI_UNP_OMITQUERY))
  +                              ? "#" : NULL,
  +                          (uptr->fragment && !(flags & APR_URI_UNP_OMITQUERY))
  +                              ? uptr->fragment : NULL,
  +                          NULL);
       }
       return ret;
   }
  @@ -187,27 +200,27 @@
    * compares for NUL for free -- it's just another delimiter.
    */
   
  -#define T_COLON		0x01	/* ':' */
  -#define T_SLASH		0x02	/* '/' */
  -#define T_QUESTION	0x04	/* '?' */
  -#define T_HASH		0x08	/* '#' */
  -#define T_NUL		0x80	/* '\0' */
  +#define T_COLON           0x01        /* ':' */
  +#define T_SLASH           0x02        /* '/' */
  +#define T_QUESTION        0x04        /* '?' */
  +#define T_HASH            0x08        /* '#' */
  +#define T_NUL             0x80        /* '\0' */
   
   /* the uri_delims.h file is autogenerated by gen_uri_delims.c */
   #include "uri_delims.h"
   
   /* it works like this:
       if (uri_delims[ch] & NOTEND_foobar) {
  -	then we're not at a delimiter for foobar
  +        then we're not at a delimiter for foobar
       }
   */
   
   /* Note that we optimize the scheme scanning here, we cheat and let the
    * compiler know that it doesn't have to do the & masking.
    */
  -#define NOTEND_SCHEME	(0xff)
  -#define NOTEND_HOSTINFO	(T_SLASH | T_QUESTION | T_HASH | T_NUL)
  -#define NOTEND_PATH	(T_QUESTION | T_HASH | T_NUL)
  +#define NOTEND_SCHEME     (0xff)
  +#define NOTEND_HOSTINFO   (T_SLASH | T_QUESTION | T_HASH | T_NUL)
  +#define NOTEND_PATH       (T_QUESTION | T_HASH | T_NUL)
   
   /* parse_uri_components():
    * Parse a given URI, fill in all supplied fields of a uri_components
  @@ -218,7 +231,7 @@
    *  - none on any of the r->* fields
    */
   APU_DECLARE(int) apr_uri_parse(apr_pool_t *p, const char *uri, 
  -                                          apr_uri_t *uptr)
  +                               apr_uri_t *uptr)
   {
       const char *s;
       const char *s1;
  @@ -238,53 +251,53 @@
        */
       if (uri[0] == '/') {
   deal_with_path:
  -	/* we expect uri to point to first character of path ... remember
  -	 * that the path could be empty -- http://foobar?query for example
  -	 */
  -	s = uri;
  -	while ((uri_delims[*(unsigned char *)s] & NOTEND_PATH) == 0) {
  -	    ++s;
  -	}
  -	if (s != uri) {
  -	    uptr->path = apr_pstrmemdup(p, uri, s - uri);
  -	}
  -	if (*s == 0) {
  -	    return APR_SUCCESS;
  -	}
  -	if (*s == '?') {
  -	    ++s;
  -	    s1 = strchr(s, '#');
  -	    if (s1) {
  -		uptr->fragment = apr_pstrdup(p, s1 + 1);
  -		uptr->query = apr_pstrmemdup(p, s, s1 - s);
  -	    }
  -	    else {
  -		uptr->query = apr_pstrdup(p, s);
  -	    }
  -	    return APR_SUCCESS;
  -	}
  -	/* otherwise it's a fragment */
  -	uptr->fragment = apr_pstrdup(p, s + 1);
  -	return APR_SUCCESS;
  +        /* we expect uri to point to first character of path ... remember
  +         * that the path could be empty -- http://foobar?query for example
  +         */
  +        s = uri;
  +        while ((uri_delims[*(unsigned char *)s] & NOTEND_PATH) == 0) {
  +            ++s;
  +        }
  +        if (s != uri) {
  +            uptr->path = apr_pstrmemdup(p, uri, s - uri);
  +        }
  +        if (*s == 0) {
  +            return APR_SUCCESS;
  +        }
  +        if (*s == '?') {
  +            ++s;
  +            s1 = strchr(s, '#');
  +            if (s1) {
  +                uptr->fragment = apr_pstrdup(p, s1 + 1);
  +                uptr->query = apr_pstrmemdup(p, s, s1 - s);
  +            }
  +            else {
  +                uptr->query = apr_pstrdup(p, s);
  +            }
  +            return APR_SUCCESS;
  +        }
  +        /* otherwise it's a fragment */
  +        uptr->fragment = apr_pstrdup(p, s + 1);
  +        return APR_SUCCESS;
       }
   
       /* find the scheme: */
       s = uri;
       while ((uri_delims[*(unsigned char *)s] & NOTEND_SCHEME) == 0) {
  -	++s;
  +        ++s;
       }
       /* scheme must be non-empty and followed by :// */
       if (s == uri || s[0] != ':' || s[1] != '/' || s[2] != '/') {
  -	goto deal_with_path;	/* backwards predicted taken! */
  +        goto deal_with_path;        /* backwards predicted taken! */
       }
   
       uptr->scheme = apr_pstrmemdup(p, uri, s - uri);
       s += 3;
       hostinfo = s;
       while ((uri_delims[*(unsigned char *)s] & NOTEND_HOSTINFO) == 0) {
  -	++s;
  +        ++s;
       }
  -    uri = s;	/* whatever follows hostinfo is start of uri */
  +    uri = s;        /* whatever follows hostinfo is start of uri */
       uptr->hostinfo = apr_pstrmemdup(p, hostinfo, uri - hostinfo);
   
       /* If there's a username:password@host:port, the @ we want is the last @...
  @@ -293,45 +306,45 @@
        * &hostinfo[-1] < &hostinfo[0] ... and this loop is valid C.
        */
       do {
  -	--s;
  +        --s;
       } while (s >= hostinfo && *s != '@');
       if (s < hostinfo) {
  -	/* again we want the common case to be fall through */
  +        /* again we want the common case to be fall through */
   deal_with_host:
  -	/* We expect hostinfo to point to the first character of
  -	 * the hostname.  If there's a port it is the first colon.
  -	 */
  -	s = memchr(hostinfo, ':', uri - hostinfo);
  -	if (s == NULL) {
  -	    /* we expect the common case to have no port */
  -	    uptr->hostname = apr_pstrmemdup(p, hostinfo, uri - hostinfo);
  -	    goto deal_with_path;
  -	}
  -	uptr->hostname = apr_pstrmemdup(p, hostinfo, s - hostinfo);
  -	++s;
  -	uptr->port_str = apr_pstrmemdup(p, s, uri - s);
  -	if (uri != s) {
  -	    port = strtol(uptr->port_str, &endstr, 10);
  -	    uptr->port = port;
  -	    if (*endstr == '\0') {
  -		goto deal_with_path;
  -	    }
  -	    /* Invalid characters after ':' found */
  -	    return APR_EGENERAL;
  -	}
  -	uptr->port = apr_uri_default_port_for_scheme(uptr->scheme);
  -	goto deal_with_path;
  +        /* We expect hostinfo to point to the first character of
  +         * the hostname.  If there's a port it is the first colon.
  +         */
  +        s = memchr(hostinfo, ':', uri - hostinfo);
  +        if (s == NULL) {
  +            /* we expect the common case to have no port */
  +            uptr->hostname = apr_pstrmemdup(p, hostinfo, uri - hostinfo);
  +            goto deal_with_path;
  +        }
  +        uptr->hostname = apr_pstrmemdup(p, hostinfo, s - hostinfo);
  +        ++s;
  +        uptr->port_str = apr_pstrmemdup(p, s, uri - s);
  +        if (uri != s) {
  +            port = strtol(uptr->port_str, &endstr, 10);
  +            uptr->port = port;
  +            if (*endstr == '\0') {
  +                goto deal_with_path;
  +            }
  +            /* Invalid characters after ':' found */
  +            return APR_EGENERAL;
  +        }
  +        uptr->port = apr_uri_default_port_for_scheme(uptr->scheme);
  +        goto deal_with_path;
       }
   
       /* first colon delimits username:password */
       s1 = memchr(hostinfo, ':', s - hostinfo);
       if (s1) {
  -	uptr->user = apr_pstrmemdup(p, hostinfo, s1 - hostinfo);
  -	++s1;
  -	uptr->password = apr_pstrmemdup(p, s1, s - s1);
  +        uptr->user = apr_pstrmemdup(p, hostinfo, s1 - hostinfo);
  +        ++s1;
  +        uptr->password = apr_pstrmemdup(p, s1, s - s1);
       }
       else {
  -	uptr->user = apr_pstrmemdup(p, hostinfo, s - hostinfo);
  +        uptr->user = apr_pstrmemdup(p, hostinfo, s - hostinfo);
       }
       hostinfo = s + 1;
       goto deal_with_host;
  @@ -343,8 +356,8 @@
    * for the format of the "CONNECT host:port HTTP/1.0" request
    */
   APU_DECLARE(int) apr_uri_parse_hostinfo(apr_pool_t *p, 
  -                                                   const char *hostinfo, 
  -                                                   apr_uri_t *uptr)
  +                                        const char *hostinfo, 
  +                                        apr_uri_t *uptr)
   {
       const char *s;
       char *endstr;
  @@ -352,7 +365,7 @@
       /* Initialize the structure. parse_uri() and parse_uri_components()
        * can be called more than once per request.
        */
  -    memset (uptr, '\0', sizeof(*uptr));
  +    memset(uptr, '\0', sizeof(*uptr));
       uptr->is_initialized = 1;
       uptr->hostinfo = apr_pstrdup(p, hostinfo);
   
  @@ -361,17 +374,17 @@
        */
       s = strchr(hostinfo, ':');
       if (s == NULL) {
  -	return APR_EGENERAL;
  +        return APR_EGENERAL;
       }
       uptr->hostname = apr_pstrndup(p, hostinfo, s - hostinfo);
       ++s;
       uptr->port_str = apr_pstrdup(p, s);
       if (*s != '\0') {
  -	uptr->port = (unsigned short) strtol(uptr->port_str, &endstr, 10);
  -	if (*endstr == '\0') {
  -	    return APR_SUCCESS;
  -	}
  -	/* Invalid characters after ':' found */
  +        uptr->port = (unsigned short) strtol(uptr->port_str, &endstr, 10);
  +        if (*endstr == '\0') {
  +            return APR_SUCCESS;
  +        }
  +        /* Invalid characters after ':' found */
       }
       return APR_EGENERAL;
   }