On 11/09/2009 11:00 AM, [email protected] wrote:
> Author: sf
> Date: Mon Nov 9 09:59:53 2009
> New Revision: 834006
>
> URL: http://svn.apache.org/viewvc?rev=834006&view=rev
> Log:
> Simplify code by using apr_strtok
>
> Modified:
> 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=834006&r1=834005&r2=834006&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/loggers/mod_log_config.c (original)
> +++ httpd/httpd/trunk/modules/loggers/mod_log_config.c Mon Nov 9 09:59:53
> 2009
> @@ -508,31 +508,20 @@
> * - commas to separate cookies
> */
>
> - if ((cookies = apr_table_get(r->headers_in, "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);
> - }
> + if ((cookies_entry = apr_table_get(r->headers_in, "Cookie"))) {
> + char *cookie, *last1, *last2;
> + char *cookies = apr_pstrdup(r->pool, cookies_entry);
> +
> + while ((cookie = apr_strtok(cookies, ";", &last1))) {
> + char *name = apr_strtok(cookie, "=", &last2);
> + char *value;
> + apr_collapse_spaces(name, name);
> +
> + if (!strcasecmp(name, a) && (value = apr_strtok(NULL, "=",
> &last2))) {
> + value += strspn(value, " \t"); /* Move past WS */
What about trailing spaces in the value?
> + return ap_escape_logitem(r->pool, value);
> + }
> + cookies = NULL;
> }
> }
> return NULL;
>
>
Regards
RĂ¼diger