httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruediger Pluem <rpl...@apache.org>
Subject Re: svn commit: r833738 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_log_config.xml modules/loggers/mod_log_config.c
Date Sun, 08 Nov 2009 01:45:22 GMT


On 11/07/2009 08:19 PM, sf@apache.org wrote:
> Author: sf
> Date: Sat Nov  7 19:19:10 2009
> New Revision: 833738
> 
> URL: http://svn.apache.org/viewvc?rev=833738&view=rev
> Log:
> mod_log_config: Make ${cookie}C correctly match whole cookie names
> instead of substrings.
> 
> PR: 28037
> Submitted by: Dan Franklin <dan dan-franklin.com>, Stefan Fritsch
> 
> Modified:
>     httpd/httpd/trunk/CHANGES
>     httpd/httpd/trunk/docs/manual/mod/mod_log_config.xml
>     httpd/httpd/trunk/modules/loggers/mod_log_config.c
> 

> Modified: httpd/httpd/trunk/modules/loggers/mod_log_config.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/loggers/mod_log_config.c?rev=833738&r1=833737&r2=833738&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/loggers/mod_log_config.c (original)
> +++ httpd/httpd/trunk/modules/loggers/mod_log_config.c Sat Nov  7 19:19:10 2009
> @@ -497,19 +497,42 @@
>  static const char *log_cookie(request_rec *r, char *a)
>  {
>      const char *cookies;
> -    const char *start_cookie;
> +
> +    /*
> +     * This supports Netscape version 0 cookies while being tolerant to
> +     * some properties of RFC2109/2965 version 1 cookies:
> +     * - case-insensitive match of cookie names
> +     * - white space around the '='
> +     * It does not support the following version 1 features:
> +     * - quoted strings as cookie values
> +     * - commas to separate cookies
> +     */
>  
>      if ((cookies = apr_table_get(r->headers_in, "Cookie"))) {
> -        if ((start_cookie = ap_strstr_c(cookies,a))) {
> -            char *cookie, *end_cookie;
> -            start_cookie += strlen(a) + 1; /* cookie_name + '=' */
> -            cookie = apr_pstrdup(r->pool, start_cookie);
> -            /* kill everything in cookie after ';' */
> -            end_cookie = strchr(cookie, ';');
> -            if (end_cookie) {
> -                *end_cookie = '\0';
> -            }
> -            return ap_escape_logitem(r->pool, cookie);
> +        const char *cookie;
> +        const char *cookie_end;
> +        const char *cp;
> +        int a_len = strlen(a);
> +        /*
> +         * Loop over semicolon-separated cookies.
> +         */
> +        for (cookie = cookies; *cookie != '\0'; cookie = cookie_end + strspn(cookie_end,
"; \t")) {
> +            /* Loop invariant: "cookie" always points to start of cookie name */
> +
> +            /* Set cookie_end to ';' that ends this cookie, or '\0' at EOS */
> +            cookie_end = cookie + strcspn(cookie, ";");
> +
> +            cp = cookie + a_len;
> +            if (cp >= cookie_end)
> +                continue;
> +            cp += strspn(cp, " \t");
> +            if (*cp == '=' && !strncasecmp(cookie, a, a_len)) {
> +                char *cookie_value;
> +                cp++;  /* Move past '=' */
> +                cp += strspn(cp, " \t");  /* Move past WS */
> +                cookie_value = apr_pstrmemdup(r->pool, cp, cookie_end - cp);
> +                return ap_escape_logitem(r->pool, cookie_value);
> +             }

Just a random thought: Wouldn't it be possible to simply things even further with apr_strtok?

Regards

R├╝diger


Mime
View raw message