httpd-apreq-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject cvs commit: httpd-apreq-2/src apreq_params.c
Date Wed, 09 Jul 2003 15:55:04 GMT
joes        2003/07/09 08:55:04

  Modified:    env      mod_apreq.c
               env/t    request.t
               src      apreq_params.c
  Added:       env/c-modules/apreq_access_test .cvsignore
                        mod_apreq_access_test.c
  Log:
  Added access tests for mod_apreq.c's prefetch code. Turns out we cannot use AP_MODE_SPECULATIVE
for this situation, since it bypasses ap_http_filter's protocol-specific (POST) logic.
  
  Revision  Changes    Path
  1.20      +16 -4     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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- mod_apreq.c	30 Jun 2003 21:59:32 -0000	1.19
  +++ mod_apreq.c	9 Jul 2003 15:54:58 -0000	1.20
  @@ -220,7 +220,7 @@
       ctx->spool  = apr_brigade_create(r->pool, alloc);
       ctx->bytes_seen = 0;
       ctx->status = APR_INCOMPLETE;
  -    ctx->mode = AP_MODE_SPECULATIVE;
  +    ctx->mode = AP_MODE_READBYTES;
   
       apreq_log(APREQ_DEBUG 0, r, 
                 "apreq filter context created." );    
  @@ -246,7 +246,7 @@
       if (f->ctx == NULL)
           apreq_filter_make_context(f);
       ctx = f->ctx;
  -
  +    apreq_log(APREQ_DEBUG 0, r, "prefetching %ld bytes", bytes);
       return ap_get_brigade(f, NULL, ctx->mode, block, bytes);
   }
   
  @@ -385,12 +385,18 @@
           apr_bucket_brigade *tmp = apr_brigade_create(r->pool, 
                                          apr_bucket_alloc_create(r->pool));
   
  +        apreq_log(APREQ_DEBUG 0, r, "%d <= %s", readbytes,
  +                  apr_table_get(r->headers_in,"Content-Length"));
           rv = ap_get_brigade(f->next, tmp, mode, block,
  -                            readbytes + ctx->bytes_seen);
  +                            readbytes);
  +
  +        if (!APR_BRIGADE_EMPTY(tmp))
  +            apreq_log(APREQ_DEBUG 0, r, "NONEMPTY: read = %d", readbytes);
  +
           if (rv != APR_SUCCESS)
               return rv;
   
  -        if (mode == AP_MODE_SPECULATIVE) {
  +        if (mode == AP_MODE_SPECULATIVE) { /* XXX CHOKES */
               apr_off_t len;
               /* throw away buckets we've already seen */
               rv = apr_brigade_partition(tmp, ctx->bytes_seen, &e);
  @@ -408,7 +414,13 @@
           }
           else {
               /* append a copy of the brigade to the spool */
  +            apr_off_t len;
  +            rv = apr_brigade_length(tmp, 0, &len);
               bb = apreq_copy_brigade(tmp);
  +            if (rv != APR_SUCCESS)
  +                return rv;
  +
  +            apreq_log(APREQ_DEBUG 0, r, "GOT HERE: len = %ld", len);
               APR_BRIGADE_CONCAT(ctx->spool, tmp);
           }
   
  
  
  
  1.1                  httpd-apreq-2/env/c-modules/apreq_access_test/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  .libs
  Makefile
  mod_apreq_request_test.la
  mod_apreq_request_test.slo
  
  
  
  1.1                  httpd-apreq-2/env/c-modules/apreq_access_test/mod_apreq_access_test.c
  
  Index: mod_apreq_access_test.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #if CONFIG_FOR_HTTPD_TEST
  
  <Location /apreq_access_test>
     TestAccess test
     SetHandler apreq_request_test
  </Location>
  
  #endif
  
  #include "apache_httpd_test.h"
  #include "apreq_params.h"
  #include "apreq_env.h"
  #include "httpd.h"
  #include "apr_strings.h"
  
  module AP_MODULE_DECLARE_DATA apreq_access_test_module;
  #define APACHE_HTTPD_TEST_ACCESS_CHECKER apreq_access_checker
  #define APACHE_HTTPD_TEST_COMMANDS       access_cmds
  #define APACHE_HTTPD_TEST_PER_DIR_CREATE create_access_config 
  
  struct access_test_cfg {
      apr_pool_t *pool;
      const char *param;
  };
  
  static const char *access_config(cmd_parms *cmd, void *dv, const char *arg)
  {
      struct access_test_cfg *cfg = (struct access_test_cfg *)dv;
      cfg->param = apr_pstrdup(cfg->pool, arg);
      return NULL;
  }
  
  static const command_rec access_cmds[] =
  {
      AP_INIT_TAKE1("TestAccess", access_config, NULL, OR_LIMIT, "'param'"),
      {NULL}
  };
  
  static void *create_access_config(apr_pool_t *p, char *dummy)
  {
      struct access_test_cfg *cfg = apr_palloc(p, sizeof *cfg);
      cfg->pool = p;
      cfg->param = dummy;
      return cfg;
  }
  
  static int apreq_access_checker(request_rec *r)
  {
      apreq_request_t *req = apreq_request(r, NULL);
      struct access_test_cfg *cfg = (struct access_test_cfg *)
          ap_get_module_config(r->per_dir_config, &apreq_access_test_module);
  
      if (!cfg || !cfg->param)
          return -1;
  
      if (apreq_param(req, cfg->param))
          return 0;
      else {
          if (req->body)
              apreq_log(APREQ_DEBUG HTTP_FORBIDDEN, r, "%s not found in %d elts",
                        cfg->param, apr_table_elts(req->body)->nelts);
          return HTTP_FORBIDDEN;
      }
  }
  
  APACHE_HTTPD_TEST_MODULE(apreq_access_test);
  
  
  
  1.2       +23 -8     httpd-apreq-2/env/t/request.t
  
  Index: request.t
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/env/t/request.t,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- request.t	20 May 2003 20:50:41 -0000	1.1
  +++ request.t	9 Jul 2003 15:55:00 -0000	1.2
  @@ -3,16 +3,31 @@
   
   use Apache::Test;
   use Apache::TestUtil;
  -use Apache::TestRequest qw(GET_BODY UPLOAD_BODY);
  +use Apache::TestRequest qw(GET_BODY UPLOAD_BODY POST_BODY GET_RC);
   
  -plan tests => 2;
  +plan tests => 6;
   
  -my $location = '/apreq_request_test';
  +foreach my $location ('/apreq_request_test', '/apreq_access_test') {
   
  -ok t_cmp("ARGS:\n\ttest => 1\n", 
  -        GET_BODY("$location?test=1"), "simple get");
  +    ok t_cmp("ARGS:\n\ttest => 1\n", 
  +            GET_BODY("$location?test=1"), "simple get");
   
  -ok t_cmp("ARGS:\n\ttest => 2\nBODY:\n\tHTTPUPLOAD => b\n",
  -        UPLOAD_BODY("$location?test=2", content => "unused"), 
  -        "simple upload");
  +    ok t_cmp("ARGS:\n\ttest => 2\nBODY:\n\tHTTPUPLOAD => b\n",
  +            UPLOAD_BODY("$location?test=2", content => "unused"), 
  +            "simple upload");
  +}
   
  +ok t_cmp(403, GET_RC("/apreq_access_test"), "access denied");
  +
  +# XXX 8000 filler chars bombs out- why?
  +my $filler = "1234567" x 1000;
  +my $body = POST_BODY("/apreq_access_test?foo=1;", 
  +                     content => "bar=2&quux=$filler;test=6");
  +ok t_cmp(<<EOT, $body, "prefetch credentials");
  +ARGS:
  +\tfoo => 1
  +BODY:
  +\tbar => 2
  +\tquux => $filler
  +\ttest => 6
  +EOT
  
  
  
  1.30      +5 -7      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.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- apreq_params.c	30 Jun 2003 20:42:14 -0000	1.29
  +++ apreq_params.c	9 Jul 2003 15:55:02 -0000	1.30
  @@ -155,18 +155,16 @@
   {
       const char *val = apr_table_get(req->args, name);
   
  -    if (val)
  -        return apreq_value_to_param(apreq_strtoval(val));
  -    else if (req->body == NULL)
  -        return NULL;
  +    if (val == NULL && req->body)
  +        val = apr_table_get(req->body, name);
   
  -    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_NONBLOCK_READ, cfg->read_ahead);
  -            val = apr_table_get(req->body, name);
  +            apreq_env_read(req->env, APR_BLOCK_READ, cfg->read_ahead);
  +            if (req->body)
  +                val = apr_table_get(req->body, name);
           }
       }
       return val ? apreq_value_to_param(apreq_strtoval(val)) : NULL;
  
  
  

Mime
View raw message