httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerenkra...@apache.org
Subject cvs commit: httpd-2.0/server util_xml.c
Date Thu, 27 Feb 2003 04:19:00 GMT
jerenkrantz    2003/02/26 20:18:59

  Modified:    .        Tag: APACHE_2_0_BRANCH CHANGES
               server   Tag: APACHE_2_0_BRANCH util_xml.c
  Log:
  Rework ap_xml_parse_input to work with bucket brigades.
  
  PR: 16134
  Reviewed by:	Jeff Trawick, Andre Malo
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.988.2.47 +3 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.988.2.46
  retrieving revision 1.988.2.47
  diff -u -u -r1.988.2.46 -r1.988.2.47
  --- CHANGES	27 Feb 2003 04:01:19 -0000	1.988.2.46
  +++ CHANGES	27 Feb 2003 04:18:58 -0000	1.988.2.47
  @@ -1,5 +1,8 @@
   Changes with Apache 2.0.45
   
  +  *) Rewrite ap_xml_parse_input to use bucket brigades.  PR 16134.
  +     [Justin Erenkrantz]
  +
     *) Fix segfault which occurred when a section in an included
        configuration file was not closed. PR 17093.  [André Malo]
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.20.2.2  +50 -24    httpd-2.0/server/util_xml.c
  
  Index: util_xml.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/util_xml.c,v
  retrieving revision 1.20.2.1
  retrieving revision 1.20.2.2
  diff -u -u -r1.20.2.1 -r1.20.2.2
  --- util_xml.c	3 Feb 2003 17:32:01 -0000	1.20.2.1
  +++ util_xml.c	27 Feb 2003 04:18:59 -0000	1.20.2.2
  @@ -69,31 +69,49 @@
   AP_DECLARE(int) ap_xml_parse_input(request_rec * r, apr_xml_doc **pdoc)
   {
       apr_xml_parser *parser;
  -    int result;
  +    apr_bucket_brigade *brigade;
  +    int seen_eos;
       apr_status_t status;
       char errbuf[200];
  -
  -    if ((result = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK)) != OK)
  -        return result;
  -
  -    if (r->remaining == 0) {
  -        *pdoc = NULL;
  -        return OK;
  -    }
  +    apr_size_t total_read = 0;
  +    apr_size_t limit_xml_body = ap_get_limit_xml_body(r);
   
       parser = apr_xml_parser_create(r->pool);
  +    brigade = apr_brigade_create(r->pool, r->connection->bucket_alloc);
   
  -    if (ap_should_client_block(r)) {
  -        long len;
  -        char *buffer;
  -        apr_size_t total_read = 0;
  -        apr_size_t limit_xml_body = ap_get_limit_xml_body(r);
  +    seen_eos = 0;
  +    total_read = 0;
   
  -        /* allocate our working buffer */
  -        buffer = apr_palloc(r->pool, READ_BLOCKSIZE);
  +    do {
  +        apr_bucket *bucket;
   
           /* read the body, stuffing it into the parser */
  -        while ((len = ap_get_client_block(r, buffer, READ_BLOCKSIZE)) > 0) {
  +        status = ap_get_brigade(r->input_filters, brigade,
  +                                AP_MODE_READBYTES, APR_BLOCK_READ,
  +                                READ_BLOCKSIZE);
  +
  +        if (status != APR_SUCCESS) {
  +            goto read_error;
  +        }
  +
  +        APR_BRIGADE_FOREACH(bucket, brigade) {
  +            const char *data;
  +            apr_size_t len;
  +
  +            if (APR_BUCKET_IS_EOS(bucket)) {
  +                seen_eos = 1;
  +                break;
  +            }
  +
  +            if (APR_BUCKET_IS_METADATA(bucket)) {
  +                continue;
  +            }
  +
  +            status = apr_bucket_read(bucket, &data, &len, APR_BLOCK_READ);
  +            if (status != APR_SUCCESS) {
  +                goto read_error;
  +            }
  +
               total_read += len;
               if (limit_xml_body && total_read > limit_xml_body) {
                   ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
  @@ -102,19 +120,25 @@
                   goto read_error;
               }
   
  -            status = apr_xml_parser_feed(parser, buffer, len);
  -            if (status)
  +            status = apr_xml_parser_feed(parser, data, len);
  +            if (status) {
                   goto parser_error;
  +            }
           }
  -        if (len == -1) {
  -            /* ap_get_client_block() has logged an error */
  -            goto read_error;
  -        }
  -    }
  +
  +        apr_brigade_cleanup(brigade);
  +    } while (!seen_eos);
  +
  +    apr_brigade_destroy(brigade);
   
       /* tell the parser that we're done */
       status = apr_xml_parser_done(parser, pdoc);
       if (status) {
  +        /* Some parsers are stupid and return an error on blank documents. */
  +        if (!total_read) {
  +            *pdoc = NULL;
  +            return OK;
  +        }
           ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                         "XML parser error (at end). status=%d", status);
           return HTTP_BAD_REQUEST;
  @@ -132,6 +156,8 @@
     read_error:
       /* make sure the parser is terminated */
       (void) apr_xml_parser_done(parser, NULL);
  +
  +    apr_brigade_destroy(brigade);
   
       /* Apache will supply a default error, plus the error log above. */
       return HTTP_BAD_REQUEST;
  
  
  

Mime
View raw message