You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-cvs@httpd.apache.org by jo...@apache.org on 2003/10/14 20:15:38 UTC

cvs commit: httpd-apreq-2/t parsers.c

joes        2003/10/14 11:15:38

  Modified:    src      apreq.c apreq.h apreq_parsers.c
               t        parsers.c
  Log:
  Opera may include a charset attribute in its Content-Type header.  I dropped nextval() from apreq_parsers.c and replaced it with apreq_header_attribute() in apreq.h.  Updated the mfd parser test in t/parsers.c accordingly.
  
  Revision  Changes    Path
  1.27      +64 -0     httpd-apreq-2/src/apreq.c
  
  Index: apreq.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq.c,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- apreq.c	18 Jul 2003 16:38:23 -0000	1.26
  +++ apreq.c	14 Oct 2003 18:15:38 -0000	1.27
  @@ -751,3 +751,67 @@
       }
       return copy;
   }
  +
  +APREQ_DECLARE(apr_status_t)
  +    apreq_header_attribute(const char *const hdr,
  +                           const char *name, const apr_size_t nlen,
  +                           const char **val, apr_size_t *vlen)
  +{
  +    const char *loc = strchr(hdr, '='), *v;
  +
  +    if (loc == NULL)
  +        return APR_NOTFOUND;
  +
  +    v = loc + 1;
  +    --loc;
  +
  +    while (apr_isspace(*loc) && loc - hdr > nlen)
  +        --loc;
  +
  +    loc -= nlen - 1;
  +
  +    while (apr_isspace(*v))
  +            ++v;
  +
  +    if (*v == '"') {
  +        ++v;
  +        /* value is inside quotes */
  +        for (*val = v; *v; ++v) {
  +            switch (*v) {
  +            case '"':
  +                goto finish;
  +            case '\\':
  +                if (v[1] != 0)
  +                    ++v;
  +            default:
  +                break;
  +            }
  +        }
  +    }
  +    else {
  +        /* value is not wrapped in quotes */
  +        for (*val = v; *v; ++v) {
  +            switch (*v) {
  +            case ' ':
  +            case ';':
  +            case ',':
  +            case '\t':
  +            case '\r':
  +            case '\n':
  +                goto finish;
  +            default:
  +                break;
  +            }
  +        }
  +    }
  +
  + finish:
  +    if (strncasecmp(loc,name,nlen) != 0
  +        || (loc > hdr && apr_isalpha(loc[-1])))
  +        return apreq_header_attribute(v, name, nlen, val, vlen);
  +
  +    *vlen = v - *val;
  +    return APR_SUCCESS;
  +
  +
  +}
  
  
  
  1.34      +4 -0      httpd-apreq-2/src/apreq.h
  
  Index: apreq.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq.h,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- apreq.h	13 Oct 2003 18:24:47 -0000	1.33
  +++ apreq.h	14 Oct 2003 18:15:38 -0000	1.34
  @@ -400,6 +400,10 @@
   APREQ_DECLARE(apr_bucket_brigade *)
            apreq_copy_brigade(const apr_bucket_brigade *bb);
   
  +APREQ_DECLARE(apr_status_t)
  +    apreq_header_attribute(const char *const hdr,
  +                           const char *name, const apr_size_t nlen,
  +                           const char **val, apr_size_t *vlen);
   
   /** @} */
   
  
  
  
  1.36      +10 -84    httpd-apreq-2/src/apreq_parsers.c
  
  Index: apreq_parsers.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_parsers.c,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- apreq_parsers.c	7 Oct 2003 18:25:22 -0000	1.35
  +++ apreq_parsers.c	14 Oct 2003 18:15:38 -0000	1.36
  @@ -778,82 +778,6 @@
   }
   
   
  -static apr_status_t nextval(const char **line, const char *name,
  -                            const char **val, apr_size_t *vlen)
  -{
  -    const char *loc = strchr(*line, '=');
  -    const apr_size_t nlen = strlen(name);
  -    int in_quotes = 0;
  -
  -    if (loc == NULL) {
  -        loc = strchr(*line, ';');
  -
  -        if (loc == NULL || loc - *line < nlen)
  -            return APR_NOTFOUND;
  -
  -        vlen = 0;
  -        *val = loc + 1;
  -        --loc;
  -
  -        while (apr_isspace(*loc) && loc - *line > nlen)
  -            --loc;
  -
  -        loc -= nlen - 1;
  -
  -        if (strncasecmp(loc, name, nlen) != 0)
  -            return APR_NOTFOUND;
  -
  -        while (apr_isspace(**val))
  -            ++*val;
  -
  -        *line = *val;
  -        return APR_SUCCESS;
  -    }
  -
  -
  -    *val = loc + 1;
  -    --loc;
  -
  -    while (apr_isspace(*loc) && loc - *line > nlen)
  -        --loc;
  -
  -    loc -= nlen - 1;
  -
  -    if (strncasecmp(loc, name, nlen) != 0)
  -        return APR_NOTFOUND;
  -
  -    while (apr_isspace(**val))
  -            ++*val;
  -
  -    if (**val == '"') {
  -        ++*val;
  -        in_quotes = 1;
  -    }
  -    for (loc = *val; *loc; ++loc) {
  -        switch (*loc) {
  -        case ' ':
  -        case '\t':
  -        case ';':
  -            if (in_quotes)
  -                continue;
  -            /* else fall through */
  -        case '"':
  -            goto finish;
  -        case '\\':
  -            if (in_quotes && loc[1] != 0)
  -                ++loc;
  -        default:
  -            break;
  -        }
  -    }
  -
  - finish:
  -    *vlen = loc - *val;
  -    *line = (*loc == 0) ? loc : loc + 1;
  -    return APR_SUCCESS;
  -}
  -
  -
   APREQ_DECLARE_PARSER(apreq_parse_multipart)
   {
       apr_pool_t *pool = apr_table_pool(t);
  @@ -880,19 +804,20 @@
           }
           *ct++ = 0;
   
  -        s = nextval((const char **)&ct, "boundary", 
  -                    (const char **)&ctx->bdry, &blen);
  -        if (s != APR_SUCCESS) {
  +        s = apreq_header_attribute(ct, "boundary", 8,
  +                                   (const char **)&ctx->bdry, &blen);
  +        if (s != APR_SUCCESS)
               return s;
  -        }
  +        
  +        ctx->bdry[blen] = 0;
  +
           *--ctx->bdry = '-';
           *--ctx->bdry = '-';
           *--ctx->bdry = '\n';
           *--ctx->bdry = '\r';
   
  -        ctx->bdry[4 + blen] = 0;
           ctx->pattern = apr_strmatch_precompile(pool,ctx->bdry,1);
  -        ctx->hdr_parser = apreq_make_parser(pool,"",apreq_parse_headers,
  +        ctx->hdr_parser = apreq_make_parser(pool, "", apreq_parse_headers,
                                               NULL,NULL);
           ctx->info = NULL;
   
  @@ -953,13 +878,14 @@
                   return APR_BADARG;
               }
   
  -            s = nextval(&cd, "name", &name, &nlen);
  +            s = apreq_header_attribute(cd, "name", 4, &name, &nlen);
  +
               if (s != APR_SUCCESS) {
                   ctx->status = MFD_ERROR;
                   return APR_BADARG;
               }
   
  -            s = nextval(&cd, "filename", &filename, &flen);
  +            s = apreq_header_attribute(cd, "filename", 8, &filename, &flen);
   
               if (s != APR_SUCCESS) {
                   apr_bucket *e;
  
  
  
  1.7       +1 -1      httpd-apreq-2/t/parsers.c
  
  Index: parsers.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/parsers.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- parsers.c	18 Sep 2003 00:38:24 -0000	1.6
  +++ parsers.c	14 Oct 2003 18:15:38 -0000	1.7
  @@ -115,7 +115,7 @@
       apr_table_t *t;
       apr_status_t rv;
       apreq_request_t *req = apreq_request(APREQ_MFD_ENCTYPE
  -                         "; boundary=\"AaB03x\"" ,"");
  +                         "; charset=\"iso-8859-1\"; boundary=\"AaB03x\"" ,"");
       apr_bucket_brigade *bb = apr_brigade_create(p, 
                                      apr_bucket_alloc_create(p));