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 2004/08/01 01:56:40 UTC

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

joes        2004/07/31 16:56:40

  Modified:    .        CHANGES
               env      mod_apreq.c
               glue/perl/docs Request.pod Table.pod
               glue/perl/xsbuilder/Apache/Request Apache__Request.h
               glue/perl/xsbuilder/Apache/Upload Apache__Upload.h
               glue/perl/xsbuilder/maps apreq_functions.map
                        apreq_structures.map
               src      apreq_env.c apreq_params.c apreq_params.h
                        apreq_parsers.c apreq_version.h
               t        parsers.c
  Log:
  Add body_status attribute to apreq_request_t, to allow both the environment and the parser to report any errors encountered.
  
  Revision  Changes    Path
  1.61      +3 -0      httpd-apreq-2/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/CHANGES,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- CHANGES	29 Jul 2004 18:10:38 -0000	1.60
  +++ CHANGES	31 Jul 2004 23:56:39 -0000	1.61
  @@ -4,6 +4,9 @@
   
   @section v2_04_dev Changes with libapreq2-2.04-dev
   
  +- C API [joes]
  +  Add body_status attribute to apreq_request_t, to allow the both
  +  environment and the parser to report any errors encountered.
   
   - C API [randyk, joes]
     Cookie parser was locking up on non-alphanumeric chars in cookie names.
  
  
  
  1.57      +9 -3      httpd-apreq-2/env/mod_apreq.c
  
  Index: mod_apreq.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/env/mod_apreq.c,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- mod_apreq.c	5 Jul 2004 17:39:50 -0000	1.56
  +++ mod_apreq.c	31 Jul 2004 23:56:39 -0000	1.57
  @@ -157,7 +157,7 @@
   
   
   #define APREQ_MODULE_NAME               "APACHE2"
  -#define APREQ_MODULE_MAGIC_NUMBER       20040705
  +#define APREQ_MODULE_MAGIC_NUMBER       20040731
   
   static void apache2_log(const char *file, int line, int level, 
                           apr_status_t status, void *env, const char *fmt,
  @@ -313,13 +313,15 @@
                   apreq_log(APREQ_ERROR APR_EGENERAL, r, 
                         "Invalid Content-Length header (%s)", cl);
                   ctx->status = APR_EGENERAL;
  +                apreq_request(r, NULL)->body_status = APR_EGENERAL;
               }
               else if (content_length > (apr_int64_t)cfg->max_body) {
  -                apreq_log(APREQ_ERROR APR_EINIT, r,
  +                apreq_log(APREQ_ERROR APR_EGENERAL, r,
                             "Content-Length header (%s) exceeds configured "
                             "max_body limit (%" APR_OFF_T_FMT ")", 
                             cl, cfg->max_body);
  -                ctx->status = APR_EINIT;
  +                ctx->status = APR_EGENERAL;
  +                apreq_request(r, NULL)->body_status = APR_EGENERAL;
               }
           }
       }
  @@ -510,6 +512,7 @@
                   old_req = apreq_request(ctx->r, NULL);
                   req->parser = old_req->parser;
                   req->body = old_req->body;
  +                req->body_status = old_req->body_status;
                   ctx->r = r;
               }
   
  @@ -526,6 +529,7 @@
               if (req->body != NULL) {
                   req->body = NULL;
                   req->parser = NULL;
  +                req->body_status = APR_EINIT;
               }
           }
       }
  @@ -555,6 +559,7 @@
   
                   if (cfg->max_body >= 0 && ctx->bytes_read > cfg->max_body) {
                       ctx->status = APR_EGENERAL;
  +                    apreq_request(r, NULL)->body_status = APR_EGENERAL;
                       apreq_log(APREQ_ERROR ctx->status, r, "Bytes read (" APR_OFF_T_FMT
                                 ") exceeds configured max_body limit (" APR_OFF_T_FMT ")",
                                 ctx->bytes_read, cfg->max_body);
  @@ -622,6 +627,7 @@
   
           if (cfg->max_body >= 0 && ctx->bytes_read > cfg->max_body) {
               ctx->status = APR_EGENERAL;
  +            apreq_request(r, NULL)->body_status = APR_EGENERAL;
               apreq_log(APREQ_ERROR ctx->status, r, "Bytes read (%" APR_OFF_T_FMT
                         ") exceeds configured max_body limit (%" APR_OFF_T_FMT ")",
                         ctx->bytes_read, cfg->max_body);
  
  
  
  1.8       +7 -6      httpd-apreq-2/glue/perl/docs/Request.pod
  
  Index: Request.pod
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/docs/Request.pod,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Request.pod	30 Jul 2004 16:08:04 -0000	1.7
  +++ Request.pod	31 Jul 2004 23:56:40 -0000	1.8
  @@ -17,7 +17,7 @@
       $req->args->add(foo => 1);
       $req->args->add(bar => 2);
       $req->args->add(foo => 3);
  -
  +    $req->body_status(0);
   
   
   
  @@ -394,12 +394,13 @@
   
       $req->body_status()
   
  -Reports the current I<APR> status code of the POST data parser.
  +Get/set the current I<APR> status code of the parsed POST data.
   APR_SUCCESS when parser has completed, APR_INCOMPLETE if parser
  -has more data to parse, error otherwise.
  +has more data to parse, APR_EINIT if no post data has been parsed,
  +error otherwise.
   
   =for testing
  -    is $req->body_status, 70023; # APR_EINIT ?
  +    is $req->body_status, 0; # APR_SUCCESS
   
   
   
  @@ -427,7 +428,7 @@
   
   Forces the request to be parsed immediately.  In void context,
   this will throw an Apache::Request::Error should the parser fail. 
  -Otherwise it will return the parser's final I<APR> status code.
  +Otherwise it will return the parser's I<APR> status code.
   
   However C<parse> should be avoided in most normal situations.  
   For example, in a mod_perl content handler it is more efficient
  @@ -435,7 +436,7 @@
   
       sub handler {
           my $r = shift;
  -        $req = Apache::Request->new($r);
  +        my $req = Apache::Request->new($r);
           $r->discard_request_body;   # efficiently parses the request body
           my $parser_status = $req->body_status;
   
  
  
  
  1.7       +2 -2      httpd-apreq-2/glue/perl/docs/Table.pod
  
  Index: Table.pod
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/docs/Table.pod,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Table.pod	29 Jul 2004 19:45:12 -0000	1.6
  +++ Table.pod	31 Jul 2004 23:56:40 -0000	1.7
  @@ -40,8 +40,8 @@
   This manpage documents the Apache::*::Table classes provided by the
   Apache::Request, Apache::Upload, and Apache::Cookie modules.  Table
   classes are all derived from APR::Table, however since the underlying 
  -values they contain are not simple character arrays, the C<merge>, C
  -<compress>, and C<overlap> methods from APR::Table are not implemented.
  +values they contain are not simple character arrays, the C<merge>, C<compress>,
  +and C<overlap> methods from APR::Table are not implemented.
   
   
   =head1 Apache::Request::Table
  
  
  
  1.51      +5 -14     httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Apache__Request.h
  
  Index: Apache__Request.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Apache__Request.h,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- Apache__Request.h	29 Jul 2004 16:22:32 -0000	1.50
  +++ Apache__Request.h	31 Jul 2004 23:56:40 -0000	1.51
  @@ -34,15 +34,10 @@
           req = (apreq_request_t *)SvIVX(obj);                            \
           s = req->args_status;                                           \
           if (s == APR_SUCCESS && req->parser)                            \
  -            s = apreq_parse_request(req, NULL);                         \
  -        switch (s) {                                                    \
  -        case APR_INCOMPLETE:                                            \
  -        case APR_SUCCESS:                                               \
  -            break;                                                      \
  -        default:                                                        \
  +            s = req->body_status;                                       \
  +        if (s != APR_SUCCESS)                                           \
               APREQ_XS_THROW_ERROR(request, s, "Apache::Request::param",  \
                                    "Apache::Request::Error");             \
  -       }                                                                \
       }                                                                   \
   } while (0)
   
  @@ -79,14 +74,10 @@
           req = (apreq_request_t *)SvIVX(obj);                            \
           if (req->parser == NULL)                                        \
              break;                                                       \
  -        switch (s = apreq_parse_request(req,NULL)) {                    \
  -        case APR_INCOMPLETE:                                            \
  -        case APR_SUCCESS:                                               \
  -            break;                                                      \
  -        default:                                                        \
  +        s = req->body_status;                                           \
  +        if (s != APR_SUCCESS)                                           \
               APREQ_XS_THROW_ERROR(request, s, "Apache::Request::body",   \
                                    "Apache::Request::Error");             \
  -        }                                                               \
       }                                                                   \
   } while (0)
   
  @@ -415,7 +406,7 @@
       while (s == APR_INCOMPLETE);
   
       if (req->body == NULL)
  -        req->body = apr_table_make(req->env, APREQ_NELTS);
  +        req->body = apr_table_make(apreq_env_pool(req->env), APREQ_NELTS);
   
       if (GIMME_V != G_VOID)
           XSRETURN_IV(s);
  
  
  
  1.33      +1 -1      httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h
  
  Index: Apache__Upload.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Apache__Upload.h	29 Jul 2004 16:22:32 -0000	1.32
  +++ Apache__Upload.h	31 Jul 2004 23:56:40 -0000	1.33
  @@ -33,7 +33,7 @@
           req = (apreq_request_t *)SvIVX(obj);                            \
           if (req->parser == NULL)                                        \
              break;                                                       \
  -        switch (s = apreq_parse_request(req,NULL)) {                    \
  +        switch (s = apreq_env_read(req->env, APR_BLOCK_READ, 0)) {      \
           case APR_INCOMPLETE:                                            \
           case APR_SUCCESS:                                               \
               break;                                                      \
  
  
  
  1.37      +0 -2      httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_functions.map
  
  Index: apreq_functions.map
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_functions.map,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- apreq_functions.map	26 Jul 2004 21:08:04 -0000	1.36
  +++ apreq_functions.map	31 Jul 2004 23:56:40 -0000	1.37
  @@ -11,8 +11,6 @@
    DEFINE_config  | apreq_xs_request_config |
    DEFINE_parse   | apreq_xs_request_parse |
   
  -apr_status_t:DEFINE_body_status  | apreq_parse_request(apreq_xs_sv2(request,sv),NULL) | SV *:sv
  -
   MODULE=Apache::Request PACKAGE=Apache::Request::Table PREFIX=Apache__Request__Table_
    DEFINE_get     | apreq_xs_table_get |
    DEFINE_FETCH   | apreq_xs_table_FETCH |
  
  
  
  1.11      +1 -0      httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_structures.map
  
  Index: apreq_structures.map
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_structures.map,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- apreq_structures.map	25 Jul 2004 00:30:49 -0000	1.10
  +++ apreq_structures.map	31 Jul 2004 23:56:40 -0000	1.11
  @@ -20,6 +20,7 @@
   !   cfg
   !  env
      args_status
  +   body_status
   </apreq_request_t>
   
   <apreq_cookie_t MODULE=Apache::Cookie>
  
  
  
  1.18      +26 -1     httpd-apreq-2/src/apreq_env.c
  
  Index: apreq_env.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_env.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- apreq_env.c	27 Jul 2004 15:03:43 -0000	1.17
  +++ apreq_env.c	31 Jul 2004 23:56:40 -0000	1.18
  @@ -142,7 +142,7 @@
   
   
   #define APREQ_MODULE_NAME         "CGI"
  -#define APREQ_MODULE_MAGIC_NUMBER 20040707
  +#define APREQ_MODULE_MAGIC_NUMBER 20040731
   
   static apr_pool_t *cgi_pool(void *env)
   {
  @@ -300,6 +300,29 @@
           APR_BRIGADE_INSERT_HEAD(ctx.in, stdin_pipe);
           APR_BRIGADE_INSERT_TAIL(ctx.in, eos);
           ctx.status = APR_INCOMPLETE;
  +
  +        if (ctx.max_body >= 0) {
  +            const char *cl = apreq_env_header_in(env, "Content-Length");
  +            if (cl != NULL) {
  +                char *dummy;
  +                apr_int64_t content_length = apr_strtoi64(cl,&dummy,0);
  +
  +                if (dummy == NULL || *dummy != 0) {
  +                    apreq_log(APREQ_ERROR APR_EGENERAL, env,
  +                              "Invalid Content-Length header (%s)", cl);
  +                    ctx.status = APR_EGENERAL;
  +                    req->body_status = APR_EGENERAL;
  +                }
  +                else if (content_length > (apr_int64_t)ctx.max_body) {
  +                    apreq_log(APREQ_ERROR APR_EGENERAL, env,
  +                              "Content-Length header (%s) exceeds configured "
  +                              "max_body limit (%" APR_OFF_T_FMT ")", 
  +                              cl, ctx.max_body);
  +                    ctx.status = APR_EGENERAL;
  +                    req->body_status = APR_EGENERAL;
  +                }
  +            }
  +        }
       }
   
   
  @@ -320,6 +343,7 @@
                             "Bytes read (%" APR_OFF_T_FMT 
                             ") exceeds configured limit (%" APR_OFF_T_FMT ")",
                             ctx.bytes_read, ctx.max_body);
  +                req->body_status = APR_EGENERAL;
                   return ctx.status = APR_EGENERAL;
               }
           }
  @@ -340,6 +364,7 @@
                             "Bytes read (%" APR_OFF_T_FMT 
                             ") exceeds configured limit (%" APR_OFF_T_FMT ")",
                             ctx.bytes_read, ctx.max_body);
  +                req->body_status = APR_EGENERAL;
                   return ctx.status = APR_EGENERAL;
               }
           }
  
  
  
  1.45      +18 -9     httpd-apreq-2/src/apreq_params.c
  
  Index: apreq_params.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_params.c,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- apreq_params.c	7 Jul 2004 13:49:53 -0000	1.44
  +++ apreq_params.c	31 Jul 2004 23:56:40 -0000	1.45
  @@ -96,6 +96,7 @@
       else
           req->args_status = APR_SUCCESS;
   
  +    req->body_status = APR_EINIT;
       return req;
   }
   
  @@ -106,7 +107,7 @@
       const char *val = apr_table_get(req->args, name);
   
       while (val == NULL) {
  -        apr_status_t s = apreq_env_read(req->env, APR_BLOCK_READ,APREQ_READ_AHEAD);
  +        apr_status_t s = apreq_env_read(req->env, APR_BLOCK_READ, APREQ_READ_AHEAD);
           if (req->body == NULL)
               return NULL;
           val = apr_table_get(req->body, name);
  @@ -282,15 +283,23 @@
   APREQ_DECLARE(apr_status_t) apreq_parse_request(apreq_request_t *req, 
                                                   apr_bucket_brigade *bb)
   {
  -    if (req->parser == NULL) {
  -        req->parser = apreq_parser(req->env,NULL);
  -        if (req->parser == NULL)
  -            return APR_ENOTIMPL;
  -    }
  -    if (req->body == NULL)
  -        req->body = apr_table_make(apreq_env_pool(req->env),APREQ_NELTS);
  +    switch (req->body_status) {
  +    case APR_EINIT:
  +        if (req->parser == NULL) {
  +            req->parser = apreq_parser(req->env,NULL);
  +            if (req->parser == NULL)
  +                return APR_ENOTIMPL;
  +        }
  +        if (req->body == NULL)
  +            req->body = apr_table_make(apreq_env_pool(req->env),APREQ_NELTS);
   
  -    return APREQ_RUN_PARSER(req->parser, req->env, req->body, bb);
  +
  +    case APR_INCOMPLETE:
  +        req->body_status = APREQ_RUN_PARSER(req->parser, req->env, 
  +                                            req->body, bb);
  +    default:
  +        return req->body_status;
  +    }
   }
   
   
  
  
  
  1.37      +1 -0      httpd-apreq-2/src/apreq_params.h
  
  Index: apreq_params.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_params.h,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- apreq_params.h	7 Jul 2004 23:53:01 -0000	1.36
  +++ apreq_params.h	31 Jul 2004 23:56:40 -0000	1.37
  @@ -62,6 +62,7 @@
       apreq_parser_t     *parser;       /**< active parser for this request */
       void               *env;          /**< request environment */
       apr_status_t        args_status;  /**< status of query-string parse */
  +    apr_status_t        body_status;  /**< status of post data parse */
   } apreq_request_t;
   
   
  
  
  
  1.59      +9 -2      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.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- apreq_parsers.c	17 Jul 2004 22:00:00 -0000	1.58
  +++ apreq_parsers.c	31 Jul 2004 23:56:40 -0000	1.59
  @@ -815,7 +815,10 @@
           ct = strchr(parser->enctype, ';');
           if (ct == NULL) {
               ctx->status = MFD_ERROR;
  -            return APR_EINIT;
  +            apreq_log(APREQ_ERROR APR_EGENERAL, env, 
  +                      "mfd parser cannot find required "
  +                      "semicolon in Content-Type header");
  +            return APR_EGENERAL;
           }
           *ct++ = 0;
   
  @@ -823,6 +826,9 @@
                                      (const char **)&ctx->bdry, &blen);
           if (s != APR_SUCCESS) {
               ctx->status = MFD_ERROR;
  +            apreq_log(APREQ_ERROR APR_EGENERAL, env,
  +                      "mfd parser cannot find boundary "
  +                      "attribute in Content-Type header");
               return s;
           }
           ctx->bdry[blen] = 0;
  @@ -841,7 +847,8 @@
           ctx->eos = apr_bucket_eos_create(bucket_alloc);
       }
       else if (ctx->status == MFD_COMPLETE) {
  -        apreq_log(APREQ_DEBUG APR_SUCCESS, env, "mfd parser is already complete- "
  +        apreq_log(APREQ_DEBUG APR_SUCCESS, env, 
  +                  "mfd parser is already complete- "
                     "all further input brigades will be ignored.");
           return APR_SUCCESS;
       }
  
  
  
  1.23      +1 -1      httpd-apreq-2/src/apreq_version.h
  
  Index: apreq_version.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_version.h,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- apreq_version.h	27 Jul 2004 16:58:55 -0000	1.22
  +++ apreq_version.h	31 Jul 2004 23:56:40 -0000	1.23
  @@ -61,7 +61,7 @@
   #define APREQ_MINOR_VERSION       0
   
   /** patch level */
  -#define APREQ_PATCH_VERSION      18
  +#define APREQ_PATCH_VERSION      19
   
   /** 
    *  This symbol is defined for internal, "development" copies of libapreq.
  
  
  
  1.19      +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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- parsers.c	18 Jul 2004 04:19:28 -0000	1.18
  +++ parsers.c	31 Jul 2004 23:56:40 -0000	1.19
  @@ -115,7 +115,7 @@
           tail = apr_brigade_split(bb, APR_BUCKET_NEXT(e));
           req->body = NULL;
           req->parser = NULL;
  -
  +        req->body_status = APR_EINIT;
           rv = apreq_parse_request(req,bb);
           CuAssertIntEquals(tc, (j < strlen(form_data)) ? APR_INCOMPLETE : APR_SUCCESS, rv);
           rv = apreq_parse_request(req, tail);