joes        2003/07/16 19:59:34

  Modified:    .        CHANGES STATUS
               env      mod_apreq.c
               glue/perl/t/response/TestApReq big_input.pm cookie.pm
                        request.pm
               glue/perl/xsbuilder/Apache/Request Apache__Request.h
               glue/perl/xsbuilder/maps apreq_functions.map
               src      apreq_params.c apreq_parsers.c
  Log:
  Add preparse logic to bring behavior in line with apreq-1
  
  Revision  Changes    Path
  1.6       +10 -0     httpd-apreq-2/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/CHANGES,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CHANGES   15 Jul 2003 16:15:50 -0000      1.5
  +++ CHANGES   17 Jul 2003 02:59:33 -0000      1.6
  @@ -2,6 +2,16 @@
   
   @section 2.0.0-dev Changes with libapreq-2.0.0-dev
   
  +- July 16, 2003 - Perl API [joes]
  +
  +Added $req->parse, $req->status, & "preparse" logic 
  +to $req->param & $req->upload.
  +
  +- July 16 ,2003 - C API [joes]
  +
  +Added "preparse" logic to apreq_params & apreq_uploads
  +to bring behavior in line with libapreq-1.x.
  +
   - July 15, 2003 - C API [joes]
   
   Dropped param->charset.
  
  
  
  1.18      +1 -4      httpd-apreq-2/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/STATUS,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- STATUS    15 Jul 2003 14:04:40 -0000      1.17
  +++ STATUS    17 Jul 2003 02:59:33 -0000      1.18
  @@ -15,9 +15,6 @@
   
   RELEASE SHOWSTOPPERS:
   
  -    - Missing Perl API components: 
  -      -# What should $req->parse do?
  -
       - Choose a versioning system:
         -# src/,  (libtool-based, following apr)
         -# env/,  (module-magic-number ?)   
  
  
  
  1.26      +9 -2      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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- mod_apreq.c       15 Jul 2003 16:15:50 -0000      1.25
  +++ mod_apreq.c       17 Jul 2003 02:59:33 -0000      1.26
  @@ -245,14 +245,21 @@
       dR;
       ap_filter_t *f = get_apreq_filter(r);
       struct filter_ctx *ctx;
  +    apr_status_t s;
   
       if (f == NULL)
           return APR_NOTFOUND;
       if (f->ctx == NULL)
           apreq_filter_make_context(f);
       ctx = f->ctx;
  +    if (ctx->status != APR_INCOMPLETE || bytes == 0)
  +        return ctx->status;
  +
       apreq_log(APREQ_DEBUG 0, r, "prefetching %ld bytes", bytes);
  -    return ap_get_brigade(f, NULL, AP_MODE_READBYTES, block, bytes);
  +    s = ap_get_brigade(f, NULL, AP_MODE_READBYTES, block, bytes);
  +    if (s != APR_SUCCESS)
  +        return s;
  +    return ctx->status;
   }
   
   
  @@ -274,7 +281,7 @@
   
           /* if "f" is still at the top of the filter chain, we're ok. Why?*/
           if (r->input_filters == f)
  -            return APR_SUCCESS;
  +           return APR_SUCCESS;
   
           /* We may have already prefetched some data.
            * Since "f" is no longer at the top of the filter chain,
  
  
  
  1.2       +5 -22     httpd-apreq-2/glue/perl/t/response/TestApReq/big_input.pm
  
  Index: big_input.pm
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/t/response/TestApReq/big_input.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- big_input.pm      9 Jun 2003 04:00:45 -0000       1.1
  +++ big_input.pm      17 Jul 2003 02:59:33 -0000      1.2
  @@ -5,36 +5,19 @@
   use Apache::Request ();
   use Apache::RequestIO;
   use Apache::RequestRec;
  -use Apache::Connection;
  -use APR;
  -use APR::Brigade;
  -use APR::Bucket;
  -use Apache::Filter;
   
   sub handler {
       my $r = shift;
  -    my $apr = Apache::Request->new($r);
  -    my $f = $r->input_filters;
  -    my $method = $r->method;
  -    my $bb = APR::Brigade->new($r->pool,
  -                               $r->connection->bucket_alloc);
  +    my $req = Apache::Request->new($r);
       my $len = 0;
   
  -    # ~ $apr->parse ???
  -    if ($method eq "POST") {
  -        do {
  -            $bb->destroy;
  -            $f->get_brigade($bb, 0, 0, 8000);
  -        } while $bb->last && !$bb->last->is_eos;
  -    }
  -
  -    for ($apr->param) {
  -        $len += length($_) + length($apr->param($_)) + 2; # +2 ('=' and '&')
  +    for ($req->param) {
  +        $len += length($_) + length($req->param($_)) + 2; # +2 ('=' and '&')
       }
       $len--; # the stick with two ends one '&' char off
   
  -    $apr->content_type('text/plain');
  -    $apr->print($len);
  +    $req->content_type('text/plain');
  +    $req->print($len);
   
       return 0;
   }
  
  
  
  1.6       +3 -4      httpd-apreq-2/glue/perl/t/response/TestApReq/cookie.pm
  
  Index: cookie.pm
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/t/response/TestApReq/cookie.pm,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- cookie.pm 13 Jul 2003 17:54:59 -0000      1.5
  +++ cookie.pm 17 Jul 2003 02:59:33 -0000      1.6
  @@ -14,13 +14,12 @@
   
   sub handler {
       my $r = shift;
  -    my $apr = Apache::Request->new($r);
  +    my $req = Apache::Request->new($r);
       my %cookies = Apache::Cookie->fetch($r);
   
       $r->content_type('text/plain');
  -    my $test = $apr->param('test');
  -    my $key  = $apr->param('key');
  -
  +    my $test = $req->param('test');
  +    my $key  = $req->param('key');
   
       if ($cookies{$key}) {
           if ($test eq "bake") {
  
  
  
  1.5       +0 -13     httpd-apreq-2/glue/perl/t/response/TestApReq/request.pm
  
  Index: request.pm
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/t/response/TestApReq/request.pm,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- request.pm        27 Jun 2003 11:41:05 -0000      1.4
  +++ request.pm        17 Jul 2003 02:59:33 -0000      1.5
  @@ -9,7 +9,6 @@
   use Apache::Connection;
   use APR::Brigade;
   use APR::Bucket;
  -use Apache::Filter;
   
   sub handler {
       my $r = shift;
  @@ -19,18 +18,6 @@
   
       my $test  = $req->args('test');
       my $method = $r->method;
  -
  -    if ($method eq "POST") {
  -        # ~ $apr->parse ???
  -        my $f = $r->input_filters;
  -        my $bb = APR::Brigade->new($r->pool,
  -                                   $r->connection->bucket_alloc);
  -        while ($f->get_brigade($bb,0,0,8000) == 0) {
  -            last if $bb->last->is_eos;
  -            $bb->destroy;
  -        }
  -        $bb->destroy;
  -    }
   
       if ($test eq 'param') {
           my $value = $req->param('value');
  
  
  
  1.16      +24 -3     
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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Apache__Request.h 15 Jul 2003 13:15:10 -0000      1.15
  +++ Apache__Request.h 17 Jul 2003 02:59:33 -0000      1.16
  @@ -52,6 +52,7 @@
    * <http://www.apache.org/>.
    */
   
  +#define READ_BLOCK_SIZE (1024 * 256)
   
   #define apreq_xs_param2rv(ptr, class) apreq_xs_2sv(ptr,class)
   #define apreq_xs_rv2param(sv) ((apreq_param_t *)SvIVX(SvRV(sv)))
  @@ -66,7 +67,10 @@
   #define S2P(s) (s ? apreq_value_to_param(apreq_strtoval(s)) : NULL)
   #define apreq_xs_request_push(sv,d,key) do {                            \
       apreq_request_t *req = apreq_xs_sv2(request,sv);                    \
  +    apr_status_t s;                                                     \
       apr_table_do(apreq_xs_do(request), d, req->args, key, NULL);        \
  +    do s = apreq_env_read(req->env, APR_BLOCK_READ, READ_BLOCK_SIZE);   \
  +    while (s == APR_INCOMPLETE);                                        \
       if (req->body)                                                      \
           apr_table_do(apreq_xs_do(request), d, req->body, key, NULL);    \
   } while (0)
  @@ -74,9 +78,12 @@
   #define apreq_xs_body_push(sv,d,k) apreq_xs_push(body,sv,d,k)
   #define apreq_xs_table_push(sv,d,k) apreq_xs_push(table,sv,d,k)
   #define apreq_xs_upload_push(sv,d,key) do {                             \
  -    apr_table_t *t = apreq_xs_body_sv2table(sv);                        \
  -    if (t)                                                              \
  -        apr_table_do(apreq_xs_do(upload), d, t, key, NULL);             \
  +    apreq_request_t *req = apreq_xs_sv2(request,sv);                    \
  +    apr_status_t s;                                                     \
  +    do s = apreq_env_read(req->env, APR_BLOCK_READ, READ_BLOCK_SIZE);   \
  +    while (s == APR_INCOMPLETE);                                        \
  +    if (req->body)                                                      \
  +        apr_table_do(apreq_xs_do(upload), d, req->body, key, NULL);     \
   } while (0)
   
   #define apreq_xs_upload_table_push(sv,d,k) apreq_xs_push(upload_table,sv,d,k)
  @@ -196,3 +203,17 @@
       XSRETURN_IV(status);
   }
   
  +static XS(apreq_xs_request_parse)
  +{
  +    dXSARGS;
  +    apreq_request_t *req;
  +    apr_status_t s;
  +    if (items != 1 || !SvROK(ST(0)))
  +        Perl_croak(aTHX_ "usage: $req->parse()");
  +
  +    req = apreq_xs_sv2(request,ST(0));
  +
  +    do s = apreq_env_read(req->env, APR_BLOCK_READ, READ_BLOCK_SIZE);
  +    while (s == APR_INCOMPLETE);
  +    XSRETURN_IV(s);
  +}
  
  
  
  1.15      +2 -0      
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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- apreq_functions.map       13 Jul 2003 17:54:59 -0000      1.14
  +++ apreq_functions.map       17 Jul 2003 02:59:33 -0000      1.15
  @@ -12,6 +12,8 @@
    DEFINE_body    | apreq_xs_body_get |
    DEFINE_upload  | apreq_xs_upload_get |
    DEFINE_config  | apreq_xs_request_config |
  + DEFINE_parse   | apreq_xs_request_parse |
  +apr_status_t:DEFINE_status  | 
apreq_env_read(apreq_xs_sv2(request,sv),APR_BLOCK_READ,0) | SV *:sv
   
   MODULE=Apache::Request PACKAGE=Apache::Request::Table 
PREFIX=Apache__Request__Table_
    DEFINE_get     | apreq_xs_table_get |
  
  
  
  1.33      +31 -15    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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- apreq_params.c    15 Jul 2003 16:15:50 -0000      1.32
  +++ apreq_params.c    17 Jul 2003 02:59:33 -0000      1.33
  @@ -62,16 +62,11 @@
   #include "apr_strings.h"
   #include "apr_lib.h"
   
  -/** default parser configuration */
  -
  -static const apreq_cfg_t default_cfg = {
  -    1024 * 1024, /**< limit on POST data size */
  -    1024 * 256,  /**< limit on brigade size */
  -    200,         /**< maximum number of form fields */
  -    1024 * 64    /**< maximum amount of prefetch data */
  -};
  +#define MAX_LEN         (1024 * 1024)
  +#define MAX_BRIGADE_LEN (1024 * 256)
  +#define MAX_FIELDS      (200)
  +#define READ_AHEAD      (1024 * 64)
       
  -
   APREQ_DECLARE(apreq_param_t *) apreq_make_param(apr_pool_t *p, 
                                                   const char *name, 
                                                   const apr_size_t nlen, 
  @@ -98,9 +93,18 @@
   APREQ_DECLARE(apreq_request_t *) apreq_request(void *env, const char *qs)
   {
       apreq_request_t *req;
  +    apreq_cfg_t *cfg;
       apr_pool_t *p;
       apr_status_t s;
   
  +    /** default parser configuration */
  +    static const apreq_cfg_t default_cfg = {
  +        MAX_LEN, /**< limit on POST data size */
  +        MAX_BRIGADE_LEN,  /**< limit on brigade size */
  +        MAX_FIELDS,         /**< maximum number of form fields */
  +        READ_AHEAD    /**< maximum amount of prefetch data */
  +    };
  +
       if (qs == NULL) {
           apreq_request_t *old_req = apreq_env_request(env,NULL);
           if (old_req != NULL)
  @@ -116,7 +120,6 @@
           req->body     = NULL;
           req->parser   = apreq_parser(env, NULL);
   
  -        *req->cfg = default_cfg;
           /* XXX need to install copy/merge callbacks for apreq_param_t */
   
           /* XXX get/set race condition here wrt apreq_env_request? */
  @@ -138,10 +141,11 @@
           req->body     = NULL;
           req->parser   = apreq_parser(env, NULL);
   
  -        *req->cfg = default_cfg;
           /* XXX need to install copy/merge callbacks for apreq_param_t */ 
       }
   
  +    *req->cfg = default_cfg;
  +
       s = (qs == NULL) ? APR_SUCCESS : 
           apreq_parse_query_string(p, req->args, qs);
   
  @@ -158,10 +162,8 @@
           val = apr_table_get(req->body, name);
   
       if (val == NULL) {
  -        apreq_cfg_t *cfg = req->cfg;
  -
  -        if (cfg && cfg->read_ahead) {
  -            apreq_env_read(req->env, APR_BLOCK_READ, cfg->read_ahead);
  +        if (req->cfg->read_ahead) {
  +            apreq_env_read(req->env, APR_BLOCK_READ, req->cfg->read_ahead);
               if (req->body)
                   val = apr_table_get(req->body, name);
           }
  @@ -173,6 +175,12 @@
   APREQ_DECLARE(apr_table_t *) apreq_params(apr_pool_t *pool,
                                             const apreq_request_t *req)
   {
  +    if (req->cfg->read_ahead) {
  +        apr_status_t s;
  +        do s = apreq_env_read(req->env, APR_BLOCK_READ, 
req->cfg->read_ahead);
  +        while (s == APR_INCOMPLETE);
  +    }
  +
       return req->body ? apr_table_overlay(pool, req->args, req->body) :
           apr_table_copy(pool, req->args);
   }
  @@ -314,6 +322,12 @@
                                              const apreq_request_t *req)
   {
       apr_table_t *t;
  +    if (req->cfg->read_ahead) {
  +        apr_status_t s;
  +        do s = apreq_env_read(req->env, APR_BLOCK_READ, 
req->cfg->read_ahead);
  +        while (s == APR_INCOMPLETE);
  +    }
  +
       if (req->body == NULL)
           return NULL;
   
  @@ -339,6 +353,8 @@
                                               const char *key)
   {
       apreq_param_t *param = NULL;
  +    if (req->cfg->read_ahead)
  +        apreq_env_read(req->env, APR_BLOCK_READ, req->cfg->read_ahead);
       if (req->body == NULL)
           return NULL;
       apr_table_do(upload_get, &param, req->body, key, NULL);
  
  
  
  1.34      +1 -1      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.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- apreq_parsers.c   15 Jul 2003 16:15:50 -0000      1.33
  +++ apreq_parsers.c   17 Jul 2003 02:59:33 -0000      1.34
  @@ -828,7 +828,7 @@
           ++*val;
           in_quotes = 1;
       }
  -    for(loc = *val; *loc; ++loc) {
  +    for (loc = *val; *loc; ++loc) {
           switch (*loc) {
           case ' ':
           case '\t':
  
  
  

Reply via email to