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/27 04:07:28 UTC

cvs commit: httpd-apreq-2/t Makefile.am testall.c env.c

joes        2003/10/26 19:07:28

  Modified:    .        CHANGES STATUS
               build    xsbuilder.pl
               env      Makefile.am mod_apreq.c test_cgi.c
               src      Makefile.am apreq_env.h apreq_version.h
               t        Makefile.am testall.c
  Added:       src      apreq_env.c
  Removed:     env      libapreq_cgi.c
               t        env.c
  Log:
  Start 2.0.1 development with CGI as default module (embedded into libapreq2), and introduce new runtime API for setting up alternate environments.  This should make it a bit easier to port libapreq to non-ELF platforms (eg. Win32).  All current tests should still pass.
  
  Revision  Changes    Path
  1.14      +10 -0     httpd-apreq-2/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/CHANGES,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- CHANGES	25 Oct 2003 04:13:15 -0000	1.13
  +++ CHANGES	27 Oct 2003 03:07:28 -0000	1.14
  @@ -1,5 +1,15 @@
   /** @page CHANGES
   
  +@section 2.0.1-dev Changes with libapreq2-2.0.1-dev
  +
  +-October 26, 2003 - C API [joes]
  +
  +Incorporate libapreq_cgi into libapreq2 as the default environment,
  +and add apreq_env_t and initializer apreq_env_module() to manage the
  +environment at runtime (determining the environment at load-time
  +was problematic on non-ELF systems).
  +
  +
   @section 2.0.0-dev Changes with libapreq2-2.0.0-dev
   
   - October 24, 2003 - C API: libapreq_cgi.c [randyk, joes]
  
  
  
  1.29      +2 -2      httpd-apreq-2/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/STATUS,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- STATUS	25 Oct 2003 04:33:13 -0000	1.28
  +++ STATUS	27 Oct 2003 03:07:28 -0000	1.29
  @@ -1,7 +1,7 @@
   Last modified at [$Date$]   -*-text-*-
   /** @page STATUS
   
  -     2.0.0  in development
  +     2.0.1  in development
   
   Contributors looking for a mission:
   
  
  
  
  1.14      +1 -1      httpd-apreq-2/build/xsbuilder.pl
  
  Index: xsbuilder.pl
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/build/xsbuilder.pl,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- xsbuilder.pl	24 Oct 2003 04:31:21 -0000	1.13
  +++ xsbuilder.pl	27 Oct 2003 03:07:28 -0000	1.14
  @@ -147,7 +147,7 @@
           ::c_macro("APREQ_DECLARE", "apreq.h")->();
           ::c_macro("APREQ_DECLARE_HOOK", "apreq_parsers.h")->();
           ::c_macro("APREQ_DECLARE_PARSER", "apreq_parsers.h")->();
  -        ::c_macro("APREQ_DECLARE_LOG", "apreq_env.h")->();
  +#        ::c_macro("APREQ_DECLARE_LOG", "apreq_env.h")->();
           ::c_macro("APR_DECLARE")->();
           ::c_macro("XS")-> ();
       }
  
  
  
  1.16      +0 -6      httpd-apreq-2/env/Makefile.am
  
  Index: Makefile.am
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/env/Makefile.am,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Makefile.am	23 Oct 2003 23:58:14 -0000	1.15
  +++ Makefile.am	27 Oct 2003 03:07:28 -0000	1.16
  @@ -3,13 +3,7 @@
   TEST_CONFIG_SCRIPT = package Apache::TestMM; filter_args(); generate_script("t/TEST")
   EXTRA_DIST = t c-modules
   
  -# XXX: should name libapreq2_cgi.a w/ source file libapreq2_cgi.c
  -lib_LIBRARIES = lib@APREQ_LIBNAME@_cgi.a
  -lib@APREQ_LIBNAME@_cgi_a_SOURCES = libapreq_cgi.c
  -#
   check_PROGRAMS = test_cgi
  -test_cgi_LDADD = lib@APREQ_LIBNAME@_cgi.a
  -test_cgi_SOURCES = test_cgi.c
   
   if BUILD_HTTPD
   
  
  
  
  1.33      +23 -20    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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- mod_apreq.c	23 Oct 2003 19:07:29 -0000	1.32
  +++ mod_apreq.c	27 Oct 2003 03:07:28 -0000	1.33
  @@ -82,8 +82,9 @@
    * @{
    */
   
  -const char apreq_env_name[] = "APACHE2"; /**< internal name of module */
  -const unsigned int apreq_env_magic_number = 20031023; /**< ABI version */
  +
  +#define APREQ_MODULE_NAME "APACHE2"
  +#define APREQ_MODULE_MAGIC_NUMBER 20031025
   
   /** The warehouse. */
   struct env_config {
  @@ -103,31 +104,29 @@
   static const char filter_name[] = "APREQ";
   module AP_MODULE_DECLARE_DATA apreq_module;
   
  -/** request logger */
  -APREQ_DECLARE_LOG(apreq_log)
  +static void apache2_log(const char *file, int line, int level, 
  +                        apr_status_t status, void *env, const char *fmt,
  +                        va_list vp)
   {
       dR;
  -    va_list args;
  -    va_start(args,fmt);
  -    ap_log_rerror(file, line, level, status, r, "%s",
  -                  apr_pvsprintf(r->pool, fmt, args));
  -    va_end(args);
  +    ap_log_rerror(file, line, level, status, r, 
  +                  "%s", apr_pvsprintf(r->pool, fmt, vp));
   }
   
   
  -APREQ_DECLARE(const char*)apreq_env_query_string(void *env)
  +static const char *apache2_query_string(void *env)
   {
       dR;
       return r->args;
   }
   
  -APREQ_DECLARE(apr_pool_t *)apreq_env_pool(void *env)
  +static apr_pool_t *apache2_pool(void *env)
   {
       dR;
       return r->pool;
   }
   
  -APREQ_DECLARE(const char *)apreq_env_header_in(void *env, const char *name)
  +static const char *apache2_header_in(void *env, const char *name)
   {
       dR;
       return apr_table_get(r->headers_in, name);
  @@ -138,8 +137,8 @@
    * @bug Sending a Set-Cookie header on a 304
    * requires a different header table.
    */
  -APREQ_DECLARE(apr_status_t)apreq_env_header_out(void *env, const char *name, 
  -                                                 char *value)
  +static apr_status_t apache2_header_out(void *env, const char *name, 
  +                                       char *value)
   {
       dR;
       apr_table_addn(r->headers_out, name, value);
  @@ -159,7 +158,7 @@
       return cfg;
   }
   
  -APREQ_DECLARE(apreq_jar_t *) apreq_env_jar(void *env, apreq_jar_t *jar)
  +static apreq_jar_t *apache2_jar(void *env, apreq_jar_t *jar)
   {
       dR;
       struct env_config *c = get_cfg(r);
  @@ -202,8 +201,8 @@
       return cfg->f;
   }
   
  -APREQ_DECLARE(apreq_request_t *) apreq_env_request(void *env, 
  -                                                   apreq_request_t *req)
  +static apreq_request_t *apache2_request(void *env, 
  +                                        apreq_request_t *req)
   {
       dR;
       struct env_config *c = get_cfg(r);
  @@ -237,9 +236,9 @@
    * Reads data directly into the parser.
    */
   
  -APREQ_DECLARE(apr_status_t) apreq_env_read(void *env, 
  -                                           apr_read_type_e block,
  -                                           apr_off_t bytes)
  +static apr_status_t apache2_read(void *env, 
  +                                 apr_read_type_e block,
  +                                 apr_off_t bytes)
   {
       dR;
       ap_filter_t *f = get_apreq_filter(r);
  @@ -433,9 +432,13 @@
       return (ctx->status == APR_INCOMPLETE) ? APR_SUCCESS : ctx->status;
   }
   
  +static APREQ_ENV_MODULE(apache2, APREQ_MODULE_NAME,
  +                        APREQ_MODULE_MAGIC_NUMBER);
   
   static void register_hooks (apr_pool_t *p)
   {
  +    const apreq_env_t *old_env;
  +    old_env = apreq_env_module(&apache2_module);
       ap_register_input_filter(filter_name, apreq_filter, apreq_filter_init,
                                AP_FTYPE_CONTENT_SET);
   }
  
  
  
  1.6       +3 -0      httpd-apreq-2/env/test_cgi.c
  
  Index: test_cgi.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/env/test_cgi.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- test_cgi.c	24 Oct 2003 22:09:52 -0000	1.5
  +++ test_cgi.c	27 Oct 2003 03:07:28 -0000	1.6
  @@ -133,6 +133,9 @@
               char *dest = apr_pcalloc(pool, cookie->v.size + 1);
               if (apreq_decode(dest, cookie->v.data, cookie->v.size) >= 0)
                   printf("%s", dest);
  +            else
  +                apreq_log(APREQ_DEBUG 0, pool, "Bad cookie encoding: %s", 
  +                          cookie->v.data);
           }
       }
   
  
  
  
  1.14      +1 -1      httpd-apreq-2/src/Makefile.am
  
  Index: Makefile.am
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/Makefile.am,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Makefile.am	15 Oct 2003 06:22:53 -0000	1.13
  +++ Makefile.am	27 Oct 2003 03:07:28 -0000	1.14
  @@ -3,7 +3,7 @@
   BUILT_SOURCES= @APR_LA@ @APU_LA@
   lib_LTLIBRARIES = lib@APREQ_LIBNAME@.la
   lib@APREQ_LIBNAME@_la_SOURCES = apreq.c apreq_version.c apreq_cookie.c \
  -                       apreq_params.c apreq_parsers.c
  +                       apreq_params.c apreq_parsers.c apreq_env.c
   pkginclude_HEADERS = apreq.h apreq_version.h apreq_cookie.h \
                     apreq_params.h  apreq_env.h apreq_parsers.h
   lib@APREQ_LIBNAME@_la_LDFLAGS = -version-info @APREQ_LIBTOOL_VERSION@
  
  
  
  1.20      +26 -23    httpd-apreq-2/src/apreq_env.h
  
  Index: apreq_env.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_env.h,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- apreq_env.h	14 Oct 2003 18:53:30 -0000	1.19
  +++ apreq_env.h	27 Oct 2003 03:07:28 -0000	1.20
  @@ -112,34 +112,15 @@
    * @{
    */
   
  -#ifndef WIN32
  -extern const char apreq_env_name[];
  -extern const unsigned int apreq_env_magic_number; /**<+ YYYYMMDD */
  -#else
  -#if defined(MOD_APREQ_EXPORTS) || defined(LIBAPREQ_CGI_EXPORTS)
  -__declspec(dllexport) const char apreq_env_name[];
  -__declspec(dllexport) const unsigned int apreq_env_magic_number;
  -#else
  -__declspec(dllimport) const char apreq_env_name[];
  -__declspec(dllimport) const unsigned int apreq_env_magic_number;
  -#endif
  -#endif
  -
  -/** logger */
  -#define APREQ_DECLARE_LOG(f) APREQ_DECLARE_NONSTD(void)(f)(const char *file, \
  -                             int line,  int level, apr_status_t status, \
  -                             void *env, const char *fmt, ...)
  +APREQ_DECLARE_NONSTD(void) apreq_log(const char *file, int line,
  +                                     int level, apr_status_t status,
  +                                     void *env, const char *fmt, ...);
   
  -
  -APREQ_DECLARE_LOG(apreq_log);
   APREQ_DECLARE(apr_pool_t *) apreq_env_pool(void *env);
  -
  -
   APREQ_DECLARE(apreq_jar_t *) apreq_env_jar(void *env, apreq_jar_t *jar);
   APREQ_DECLARE(apreq_request_t *) apreq_env_request(void *env,
                                                      apreq_request_t *req);
   
  -
   APREQ_DECLARE(const char *) apreq_env_query_string(void *env);
   APREQ_DECLARE(const char *) apreq_env_header_in(void *env, const char *name);
   
  @@ -148,7 +129,6 @@
   #define apreq_env_cookie(env) apreq_env_header_in(env, "Cookie")
   #define apreq_env_cookie2(env) apreq_env_header_in(env, "Cookie2")
   
  -/** header out */
   APREQ_DECLARE(apr_status_t)apreq_env_header_out(void *env, 
                                                   const char *name,
                                                   char *val);
  @@ -159,6 +139,29 @@
   APREQ_DECLARE(apr_status_t) apreq_env_read(void *env,
                                              apr_read_type_e block,
                                              apr_off_t bytes);
  +
  +typedef struct apreq_env_t {
  +    const char *name;
  +    apr_uint32_t magic_number;
  +    void (*log)(const char *,int,int,apr_status_t,void *,const char *,va_list);
  +    apr_pool_t *(*pool)(void *);
  +    apreq_jar_t *(*jar)(void *,apreq_jar_t *);
  +    apreq_request_t *(*request)(void *,apreq_request_t *);
  +    const char *(*query_string)(void *);
  +    const char *(*header_in)(void *,const char *);
  +    apr_status_t (*header_out)(void *, const char *,char *);
  +    apr_status_t (*read)(void *,apr_read_type_e,apr_off_t);
  +} apreq_env_t;
  +
  +#define APREQ_ENV_MODULE(pre, name, mmn) const apreq_env_t pre##_module = { \
  +  name, mmn, pre##_log, pre##_pool, pre##_jar, pre##_request,               \
  +  pre##_query_string, pre##_header_in, pre##_header_out, pre##_read }
  +
  +
  +APREQ_DECLARE(const apreq_env_t *) apreq_env_module(const apreq_env_t *mod);
  +
  +#define apreq_env_name (apreq_env_module(NULL)->name)
  +#define apreq_env_magic_number (apreq_env_module(NULL)->magic_number)
   
   /** @} */
   #ifdef __cplusplus
  
  
  
  1.2       +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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apreq_version.h	13 Oct 2003 18:24:47 -0000	1.1
  +++ apreq_version.h	27 Oct 2003 03:07:28 -0000	1.2
  @@ -100,7 +100,7 @@
   #define APREQ_MINOR_VERSION       0
   
   /** patch level */
  -#define APREQ_PATCH_VERSION       0
  +#define APREQ_PATCH_VERSION       1
   
   /** 
    *  This symbol is defined for internal, "development" copies of libapreq.
  
  
  
  1.1                  httpd-apreq-2/src/apreq_env.c
  
  Index: apreq_env.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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/>.
   */
  
  #include "apreq.h"
  #include "apreq_env.h"
  #include "apreq_params.h"
  #include "apreq_parsers.h"
  #include "apreq_cookie.h"
  #include "apr_strings.h"
  #include "apr_lib.h"
  #include "apr_env.h"
  
  #include <stdlib.h>
  #include <stdio.h>
  
  
  /**
   * @file apreq_env.c
   * @brief Source for libapreq_cgi.a.
   */
  
  /**
   * libapreq_cgi is a static library that CGI "scripts" (written
   * in C) can link against to to have libapreq work in a CGI environment.
   *
   * @defgroup libapreq_cgi libapreq_cgi.a
   * @ingroup MODULES
   * @brief Static library for linking libapreq to a CGI C-script.
   * @{
   */
  
  static const apreq_env_t *apreq_env;
  
  APREQ_DECLARE(const apreq_env_t *) apreq_env_module(const apreq_env_t *mod)
  {
      if (mod != NULL) {
          const apreq_env_t *old_mod = apreq_env;
          apreq_env = mod;
          return old_mod;
      }
      return apreq_env;
  }
  
  
  APREQ_DECLARE_NONSTD(void) apreq_log(const char *file, int line,
                                       int level, apr_status_t status,
                                       void *env, const char *fmt, ...)
  {
      va_list vp;
      va_start(vp, fmt);
      apreq_env->log(file,line,level,status,env,fmt,vp);
      va_end(vp);
  }
  
  APREQ_DECLARE(apr_pool_t *) apreq_env_pool(void *env)
  {
      return apreq_env->pool(env);
  }
  
  APREQ_DECLARE(apreq_jar_t *) apreq_env_jar(void *env, apreq_jar_t *jar)
  {
      return apreq_env->jar(env,jar);
  }
  
  APREQ_DECLARE(apreq_request_t *) apreq_env_request(void *env,
                                                     apreq_request_t *req)
  {
      return apreq_env->request(env,req);
  }
  
  APREQ_DECLARE(const char *) apreq_env_query_string(void *env)
  {
      return apreq_env->query_string(env);
  }
  
  APREQ_DECLARE(const char *) apreq_env_header_in(void *env, const char *name)
  {
      return apreq_env->header_in(env, name);
  }
  
  APREQ_DECLARE(apr_status_t)apreq_env_header_out(void *env, 
                                                  const char *name,
                                                  char *val)
  {
      return apreq_env->header_out(env,name,val);
  }
  
  APREQ_DECLARE(apr_status_t) apreq_env_read(void *env,
                                             apr_read_type_e block,
                                             apr_off_t bytes)
  {
      return apreq_env->read(env,block,bytes);
  }
  
  
  /** Default CGI module extracted from libapreq_cgi */
  
  #define APREQ_MODULE_NAME         "CGI"
  #define APREQ_MODULE_MAGIC_NUMBER 20031025
  
  #define dP apr_pool_t *p = (apr_pool_t *)env
  
  static struct {
      apreq_request_t    *req;
      apreq_jar_t        *jar;
      apr_status_t        status;
  } ctx;
  
  #define CRLF "\015\012"
  
  #define APREQ_ENV_STATUS(rc_run, k) do {                                \
           apr_status_t rc = rc_run;                                      \
           if (rc != APR_SUCCESS) {                                       \
               apreq_log(APREQ_DEBUG 0, p,                                \
                         "Lookup of %s failed: status=%d", k, rc);        \
           }                                                              \
       } while (0)
  
  static apr_pool_t *cgi_pool(void *env)
  {
      return (apr_pool_t *)env;
  }
  
  static const char *cgi_query_string(void *env)
  {
      dP;
      char *value = NULL, qs[] = "QUERY_STRING";
      APREQ_ENV_STATUS(apr_env_get(&value, qs, p), qs);
      return value;
  }
  
  static const char *cgi_header_in(void *env, 
                                   const char *name)
  {
      dP;
      char *key = apr_pstrcat(p, "HTTP_", name, NULL);
      char *k, *value = NULL;
      for (k = key; *k; ++k) {
          if (*k == '-')
              *k = '_';
          else
              *k = apr_toupper(*k);
      }
  
      if (!strcmp(key, "HTTP_CONTENT_TYPE") 
          || !strcmp(key, "HTTP_CONTENT_LENGTH"))
      {
          key += 5; /* strlen("HTTP_") */
      }
  
      APREQ_ENV_STATUS(apr_env_get(&value, key, p), key);
  
      return value;
  }
  
  static apr_status_t cgi_header_out(void *env, const char *name, 
                                     char *value)
  {
      dP;
      apr_file_t *out;
      int bytes;
      apr_file_open_stdout(&out, p);
      bytes = apr_file_printf(out, "%s: %s" CRLF, name, value);
      apreq_log(APREQ_DEBUG 0, p, "Setting header: %s => %s", name, value);
      return bytes > 0 ? APR_SUCCESS : APR_EGENERAL;
  }
  
  
  static apreq_jar_t *cgi_jar(void *env, apreq_jar_t *jar)
  {
  
      if (jar != NULL) {
          apreq_jar_t *old_jar = ctx.jar;
          ctx.jar = jar;
          return old_jar;
      }
  
      return ctx.jar;
  }
  
  static apreq_request_t *cgi_request(void *env,
                                      apreq_request_t *req)
  {
  
      if (req != NULL) {
          apreq_request_t *old_req = ctx.req;
          ctx.req = req;
          return old_req;
      }
      return ctx.req;
  }
  
  static void cgi_log(const char *file, int line, int level, 
                      apr_status_t status, void *env, const char *fmt,
                      va_list vp)
  {
      dP;
      fprintf(stderr, "[%s(%d)] %s\n", file, line, apr_pvsprintf(p,fmt,vp));
  }
  
  static apr_status_t cgi_read(void *env, 
                               apr_read_type_e block,
                               apr_off_t bytes)
  {
      dP;
      apreq_request_t *req = apreq_request(env, NULL);
  
      if (req->body == NULL) {
          apr_bucket_alloc_t *alloc = apr_bucket_alloc_create(p);
          apr_bucket_brigade *bb = apr_brigade_create(p, alloc);
          apr_bucket *stdin_pipe, *eos = apr_bucket_eos_create(alloc);
          apr_file_t *in;
          apr_file_open_stdin(&in, p);
          stdin_pipe = apr_bucket_pipe_create(in,alloc);
          APR_BRIGADE_INSERT_HEAD(bb, stdin_pipe);
          APR_BRIGADE_INSERT_TAIL(bb, eos);
          ctx.status = apreq_parse_request(req, bb);
      }
      return ctx.status;
  }
  
  static APREQ_ENV_MODULE(cgi, APREQ_MODULE_NAME, 
                          APREQ_MODULE_MAGIC_NUMBER);
  
  static const apreq_env_t *apreq_env = &cgi_module;
  
  /** @} */
  
  
  
  1.15      +1 -1      httpd-apreq-2/t/Makefile.am
  
  Index: Makefile.am
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/Makefile.am,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Makefile.am	14 Oct 2003 17:55:11 -0000	1.14
  +++ Makefile.am	27 Oct 2003 03:07:28 -0000	1.15
  @@ -2,7 +2,7 @@
   LIBS = ../src/lib@APREQ_LIBNAME@.la @APR_LTLIBS@ @APU_LTLIBS@
   
   noinst_LIBRARIES = lib@APREQ_LIBNAME@_tests.a
  -lib@APREQ_LIBNAME@_tests_a_SOURCES = CuTest.c env.c cookie.c params.c parsers.c
  +lib@APREQ_LIBNAME@_tests_a_SOURCES = CuTest.c cookie.c params.c parsers.c
   
   check_PROGRAMS = testall
   testall_LDADD  = lib@APREQ_LIBNAME@_tests.a
  
  
  
  1.9       +63 -0     httpd-apreq-2/t/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/testall.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- testall.c	9 Jun 2003 04:00:46 -0000	1.8
  +++ testall.c	27 Oct 2003 03:07:28 -0000	1.9
  @@ -56,6 +56,7 @@
   #include <stdlib.h>
   
   #include "test_apreq.h"
  +#include "apreq_env.h"
   
   /* Top-level pool which can be used by tests. */
   apr_pool_t *p;
  @@ -86,6 +87,67 @@
       {"LastTest", NULL}
   };
   
  +
  +/* rigged environent for unit tests */
  +
  +#define APREQ_MODULE_NAME "TEST"
  +#define APREQ_MODULE_MAGIC_NUMBER 20031025
  +
  +#define CRLF "\015\012"
  +
  +apr_bucket_brigade *bb;
  +apr_table_t *table;
  +
  +static apr_pool_t *test_pool(void *env)
  +{
  +    return p;
  +}
  +
  +static const char *test_header_in(void *env, const char *name)
  +{
  +    return env;
  +}
  +
  +static apr_status_t test_header_out(void *env, 
  +                                    const char *name, 
  +                                    char *value)
  +{    
  +    return printf("%s: %s" CRLF, name, value) > 0 ? APR_SUCCESS : APR_EGENERAL;
  +}
  +
  +static const char *test_query_string(void *env)
  +{
  +    return env;
  +}
  +
  +static apreq_jar_t *test_jar(void *env, apreq_jar_t *jar)
  +{
  +    return NULL;
  +}
  +
  +static apreq_request_t *test_request(void *env, apreq_request_t *req)
  +{
  +    return NULL;
  +}
  +
  +static void test_log(const char *file, int line, int level, 
  +                     apr_status_t status, void *env, const char *fmt,
  +                     va_list vp)
  +{
  +    if (level < APREQ_LOG_DEBUG)
  +        fprintf(stderr, "[%s(%d)] %s\n", file, line, apr_pvsprintf(p,fmt,vp));
  +}
  +
  +static apr_status_t test_read(void *env, apr_read_type_e block, 
  +                              apr_off_t bytes)
  +{
  +    return APR_ENOTIMPL;
  +}
  +
  +static APREQ_ENV_MODULE(test, APREQ_MODULE_NAME,
  +                       APREQ_MODULE_MAGIC_NUMBER);
  +
  +
   int main(int argc, char *argv[])
   {
       CuSuiteList *alltests = NULL;
  @@ -95,6 +157,7 @@
   
       apr_initialize();
       atexit(apr_terminate);
  +    apreq_env_module(&test_module);
   
       CuInit(argc, argv);
   
  
  
  

Re: cvs commit: httpd-apreq-2/t Makefile.am testall.c env.c

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Sun, 27 Oct 2003 joes@apache.org wrote:

> joes        2003/10/26 19:07:28
>
>   Modified:    .        CHANGES STATUS
>                build    xsbuilder.pl
>                env      Makefile.am mod_apreq.c test_cgi.c
>                src      Makefile.am apreq_env.h apreq_version.h
>                t        Makefile.am testall.c
>   Added:       src      apreq_env.c
>   Removed:     env      libapreq_cgi.c
>                t        env.c
>   Log:
>   Start 2.0.1 development with CGI as default module
> (embedded into libapreq2), and introduce new runtime API
> for setting up alternate environments.  This should make
> it a bit easier to port libapreq to non-ELF platforms (eg.
> Win32).  All current tests should still pass.

Very nice! With the committed changes in the Win32
makefiles, all tests on Win32 also pass, both the env/ and
glue/perl/ ones. And in building both the c-cmodules and the
perl stuff, we no longer need to link against the mod_apreq
library!

-- 
best regards,
randy