httpd-apreq-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r151821 - in httpd/apreq/branches/multi-env-unstable: ./ env/ glue/perl/xsbuilder/Apache/Request/ glue/perl/xsbuilder/Apache/Upload/ src/ t/
Date Tue, 08 Feb 2005 02:27:28 GMT
Author: joes
Date: Mon Feb  7 18:27:24 2005
New Revision: 151821

URL: http://svn.apache.org/viewcvs?view=rev&rev=151821
Log:
Convert APREQ_RUN_PARSER and APREQ_RUN_HOOK to inline, and downcase them.
Remove apreq_memmem.
Convert apreq_(un)escape to inline.
apreq_escape does not create an apreq_value_t*.
Initialize default_parsers explicitly to NULL.
Convert APREQ_BRIGADE_COPY to inline, and downcase it.
Lowercase APREQ_BRIGADE_SETASIDE, APREQ_BRIGADE_COPY.
Convert apreq_cookie_name and apreq_cookie_value macros to inline.
Convert apreq_param_name, apreq_param_value, apreq_param_info, apreq_param_brigade to inline.
Add apreq_initialize to allow thread-safe parser registration.


Submitted by: Max Kellermann
Reviewed by: joes

Modified:
    httpd/apreq/branches/multi-env-unstable/CHANGES
    httpd/apreq/branches/multi-env-unstable/env/mod_apreq.c
    httpd/apreq/branches/multi-env-unstable/env/test_cgi.c
    httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/Apache/Request/Apache__Request.h
    httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h
    httpd/apreq/branches/multi-env-unstable/src/apreq.c
    httpd/apreq/branches/multi-env-unstable/src/apreq.h
    httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.h
    httpd/apreq/branches/multi-env-unstable/src/apreq_env_cgi.c
    httpd/apreq/branches/multi-env-unstable/src/apreq_env_custom.c
    httpd/apreq/branches/multi-env-unstable/src/apreq_params.h
    httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.c
    httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.h
    httpd/apreq/branches/multi-env-unstable/t/params.c
    httpd/apreq/branches/multi-env-unstable/t/parsers.c
    httpd/apreq/branches/multi-env-unstable/t/testall.c

Modified: httpd/apreq/branches/multi-env-unstable/CHANGES
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/CHANGES?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/CHANGES (original)
+++ httpd/apreq/branches/multi-env-unstable/CHANGES Mon Feb  7 18:27:24 2005
@@ -4,6 +4,22 @@
 
 @section v2_05 Changes with libapreq2-2.05
 
+
+- C API [Max Kellermann]
+  Continue the API improvements:
+
+  - Convert APREQ_RUN_PARSER and APREQ_RUN_HOOK to inline, and downcase them.
+  - Remove apreq_memmem.
+  - Convert apreq_(un)escape to inline.
+  - apreq_escape does not create an apreq_value_t*.
+  - Initialize default_parsers explicitly to NULL.
+  - Convert APREQ_BRIGADE_COPY to inline, and downcase it.
+  - Lowercase APREQ_BRIGADE_SETASIDE, APREQ_BRIGADE_COPY.
+  - Convert apreq_cookie_name and apreq_cookie_value macros to inline.
+  - Convert apreq_param_name, apreq_param_value, apreq_param_info, and
+    apreq_param_brigade to inline.
+  - Add apreq_initialize to allow thread-safe parser registration.
+
 - C API [joes]
   Widespread API refactorization to remove apreq_jar_t and apreq_request_t:
   

Modified: httpd/apreq/branches/multi-env-unstable/env/mod_apreq.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/mod_apreq.c?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/env/mod_apreq.c (original)
+++ httpd/apreq/branches/multi-env-unstable/env/mod_apreq.c Mon Feb  7 18:27:24 2005
@@ -156,6 +156,7 @@
  * XXX apreq as a normal input filter
  * XXX apreq as a "virtual" content handler.
  * XXX apreq as a transparent "tee".
+ * XXX apreq parser registration in post_config
  * </pre>
  * @{
  */
@@ -724,7 +725,7 @@
                     return rv;
                 }
 
-                APREQ_BRIGADE_COPY(ctx->bb, bb);
+                apreq_brigade_copy(ctx->bb, bb);
                 apr_brigade_length(bb, 1, &len);
                 ctx->bytes_read += len;
 
@@ -754,7 +755,7 @@
                 if (APR_BUCKET_IS_EOS(e))
                     e = APR_BUCKET_NEXT(e);
                 ctx->spool = apr_brigade_split(bb, e);
-                APREQ_BRIGADE_SETASIDE(ctx->spool, r->pool);
+                apreq_brigade_setaside(ctx->spool, r->pool);
             }
         }
 
@@ -791,8 +792,8 @@
                 /*XXX how should we handle this filter-chain error? */
                 return rv;
             }
-            APREQ_BRIGADE_SETASIDE(bb, r->pool);
-            APREQ_BRIGADE_COPY(ctx->bb, bb);
+            apreq_brigade_setaside(bb, r->pool);
+            apreq_brigade_copy(ctx->bb, bb);
 
             apr_brigade_length(bb, 1, &len);
             total_read += len;
@@ -836,7 +837,7 @@
         return APR_SUCCESS;
 
     if (ctx->status == APR_INCOMPLETE) {
-        ctx->status = APREQ_RUN_PARSER(ctx->parser, ctx->body, ctx->bb);
+        ctx->status = apreq_run_parser(ctx->parser, ctx->body, ctx->bb);
         apr_brigade_cleanup(ctx->bb);
     }
 
@@ -859,9 +860,26 @@
     return APR_SUCCESS;
 }
 
+static int apreq_post_config(apr_pool_t *p, apr_pool_t *plog,
+                             apr_pool_t *ptemp, server_rec *base_server) {
+    apr_status_t status;
+
+    status = apreq_initialize(p);
+    if (status != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_ERR, status, base_server,
+                     "Failed to initialize libapreq2");
+        return HTTP_INTERNAL_SERVER_ERROR;
+    }
+
+    return OK;
+}
+
 static void register_hooks (apr_pool_t *p)
 {
-    apreq_register_parser(NULL,NULL);
+    /* APR_HOOK_FIRST because we want other modules to be able to
+       register parsers in their post_config hook */
+    ap_hook_post_config(apreq_post_config, NULL, NULL, APR_HOOK_FIRST);
+
     ap_register_input_filter(filter_name, apreq_filter, apreq_filter_init,
                              AP_FTYPE_PROTOCOL-1);
 }

Modified: httpd/apreq/branches/multi-env-unstable/env/test_cgi.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/test_cgi.c?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/env/test_cgi.c (original)
+++ httpd/apreq/branches/multi-env-unstable/env/test_cgi.c Mon Feb  7 18:27:24 2005
@@ -47,7 +47,11 @@
         fprintf(stderr, "apr_pool_create failed\n");
         exit(-1);
     }
-    (void)apreq_register_parser(NULL,NULL);
+
+    if (apreq_initialize(pool) != APR_SUCCESS) {
+        fprintf(stderr, "apreq_initialize failed\n");
+        exit(-1);
+    }
 
     req = apreq_handle_cgi(pool);
 

Modified: httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/Apache/Request/Apache__Request.h
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/Apache/Request/Apache__Request.h?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/Apache/Request/Apache__Request.h
(original)
+++ httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/Apache/Request/Apache__Request.h
Mon Feb  7 18:27:24 2005
@@ -279,7 +279,7 @@
     }
 
     if (hook->next)
-        s = APREQ_RUN_HOOK(hook->next, env, param, bb);
+        s = apreq_run_hook(hook->next, env, param, bb);
 
     return s;
 }

Modified: httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h
(original)
+++ httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h
Mon Feb  7 18:27:24 2005
@@ -397,7 +397,7 @@
     obj = apreq_xs_find_bb_obj(aTHX_ ST(1));
     bb = (apr_bucket_brigade *)SvIVX(obj);
     bb_copy = apr_brigade_create(bb->p,bb->bucket_alloc);
-    APREQ_BRIGADE_COPY(bb_copy, bb);
+    apreq_brigade_copy(bb_copy, bb);
 
     sv = sv_setref_pv(newSV(0), class, bb_copy);
     if (SvTAINTED(obj))

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq.c?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq.c (original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq.c Mon Feb  7 18:27:24 2005
@@ -130,36 +130,6 @@
 }
 
 
-/*
-  search for a string in a fixed-length byte string.
-  if partial is true, partial matches are allowed at the end of the buffer.
-  returns NULL if not found, or a pointer to the start of the first match.
-*/
-
-/* XXX: should we drop this and replace it with apreq_index ? */
-APREQ_DECLARE(char *) apreq_memmem(char* hay, apr_size_t hlen, 
-                                   const char* ndl, apr_size_t nlen,
-                                   const apreq_match_t type)
-{
-    apr_size_t len = hlen;
-    char *end = hay + hlen;
-
-    while ( (hay = memchr(hay, ndl[0], len)) ) {
-	len = end - hay;
-
-	/* done if matches up to capacity of buffer */
-	if ( memcmp(hay, ndl, MIN(nlen, len)) == 0 ) {
-            if (type == APREQ_MATCH_FULL && len < nlen)
-                hay = NULL;     /* insufficient room for match */
-	    break;
-        }
-        --len;
-        ++hay;
-    }
-
-    return hay;
-}
-
 APREQ_DECLARE(apr_ssize_t ) apreq_index(const char* hay, apr_size_t hlen, 
                                         const char* ndl, apr_size_t nlen, 
                                         const apreq_match_t type)
@@ -578,30 +548,6 @@
     *d = 0;
     rv->size = d - rv->data;
     return rv->data;
-}
-
-APREQ_DECLARE(char *) apreq_escape(apr_pool_t *p,
-                                         const char *src, const apr_size_t slen)
-{
-    apreq_value_t *rv;
-    if (src == NULL)
-        return NULL;
-
-    rv = apr_palloc(p, 3 * slen + sizeof *rv);
-    rv->name = NULL;
-    rv->size = apreq_encode(rv->data, src, slen);
-    return rv->data;
-}
-
-APR_INLINE
-APREQ_DECLARE(apr_ssize_t) apreq_unescape(char *str)
-{
-    apr_size_t len;
-    apr_status_t rv = apreq_decode(str,&len,str,strlen(str));
-    if (rv == APR_SUCCESS)
-        return (apr_ssize_t)len;
-    else
-        return -1;
 }
 
 APR_INLINE

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq.h
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq.h?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq.h (original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq.h Mon Feb  7 18:27:24 2005
@@ -154,19 +154,6 @@
 } apreq_match_t;
 
 /**
- * Return a pointer to the match string, or NULL if no match is found.
- * @param hay  Location of bytes to scan.
- * @param hlen Number of bytes available for scanning.
- * @param ndl  Search string
- * @param nlen Length of search string.
- * @param type Match type.
- *
- */
-APREQ_DECLARE(char *) apreq_memmem(char* hay, apr_size_t hlen, 
-                                   const char* ndl, apr_size_t nlen, 
-                                   const apreq_match_t type);
-
-/**
  * Returns offset of match string's location, or -1 if no match is found.
  * @param hay  Location of bytes to scan.
  * @param hlen Number of bytes available for scanning.
@@ -253,8 +240,19 @@
  *          overflow dest.
  */
 
-APREQ_DECLARE(char *) apreq_escape(apr_pool_t *p, 
-                                   const char *src, const apr_size_t slen);
+static APR_INLINE
+char *apreq_escape(apr_pool_t *p,
+                   const char *src, const apr_size_t slen)
+{
+    char *rv;
+
+    if (src == NULL)
+        return NULL;
+
+    rv = apr_palloc(p, 3 * slen + 1);
+    apreq_encode(rv, src, slen);
+    return rv;
+}
 
 /**
  * An \e in-situ url-decoder.
@@ -263,7 +261,16 @@
  * @remark Equivalent to apreq_decode(str,str,strlen(str)).
  */
 
-APREQ_DECLARE(apr_ssize_t) apreq_unescape(char *str);
+static APR_INLINE
+apr_ssize_t apreq_unescape(char *str)
+{
+    apr_size_t len;
+    apr_status_t rv = apreq_decode(str,&len,str,strlen(str));
+    if (rv == APR_SUCCESS)
+        return (apr_ssize_t)len;
+    else
+        return -1;
+}
 
 
 /** @enum apreq_expires_t Expiration date format */
@@ -343,7 +350,7 @@
  */
 
 static APR_INLINE void
-APREQ_BRIGADE_SETASIDE(apr_bucket_brigade *bb, apr_pool_t *p)
+apreq_brigade_setaside(apr_bucket_brigade *bb, apr_pool_t *p)
 {
     apr_bucket *e;
     for (e = APR_BRIGADE_FIRST(bb); e != APR_BRIGADE_SENTINEL(bb);
@@ -361,16 +368,17 @@
  * @remark s == d produces Undefined Behavior.
  */
 
-#define APREQ_BRIGADE_COPY(d,s) do {                                \
-    apr_bucket *e;                                                  \
-    for (e = APR_BRIGADE_FIRST(s); e != APR_BRIGADE_SENTINEL(s);    \
-         e = APR_BUCKET_NEXT(e))                                    \
-    {                                                               \
-        apr_bucket *c;                                              \
-        apr_bucket_copy(e, &c);                                     \
-        APR_BRIGADE_INSERT_TAIL(d, c);                              \
-    }                                                               \
-} while (0)
+static APR_INLINE
+void apreq_brigade_copy(apr_bucket_brigade *d, apr_bucket_brigade *s) {
+    apr_bucket *e;
+    for (e = APR_BRIGADE_FIRST(s); e != APR_BRIGADE_SENTINEL(s);
+         e = APR_BUCKET_NEXT(e))
+    {
+        apr_bucket *c;
+        apr_bucket_copy(e, &c);
+        APR_BRIGADE_INSERT_TAIL(d, c);
+    }
+}
 
 
 /**
@@ -405,6 +413,18 @@
                                                  apr_size_t brigade_limit,
                                                  apr_bucket_brigade *out, 
                                                  apr_bucket_brigade *in);
+
+
+/**
+ * Initialize libapreq2. Applications (except apache modules using
+ * mod_apreq) have to call this exactly once before they use
+ * libapreq2.
+ *
+ * @param pool a base pool persisting while libapreq2 is used
+ * @remark after you detroyed the pool, you have to call this function again
+ *    with a new pool if you still plan to use libapreq2
+ */
+APREQ_DECLARE(apr_status_t) apreq_initialize(apr_pool_t *pool);
 
 
 #ifdef __cplusplus

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.h
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.h?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.h (original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.h Mon Feb  7 18:27:24 2005
@@ -90,9 +90,15 @@
            apreq_attr_to_type(apreq_value_t, data, deconst.out));
 }
 
-#define apreq_cookie_name(c)  ((c)->v.name)
-#define apreq_cookie_value(c) ((c)->v.data)
+static APR_INLINE
+const char *apreq_cookie_name(const apreq_cookie_t *c) {
+    return c->v.name;
+}
 
+static APR_INLINE
+const char *apreq_cookie_value(const apreq_cookie_t *c) {
+    return c->v.data;
+}
 
 APREQ_DECLARE(apr_status_t)apreq_parse_cookie_header(apr_pool_t *pool,
                                                      apr_table_t *jar,

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_env_cgi.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_env_cgi.c?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_env_cgi.c (original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_env_cgi.c Mon Feb  7 18:27:24 2005
@@ -309,7 +309,7 @@
         }
 
         handle->body_status =
-            APREQ_RUN_PARSER(handle->parser, handle->body, bb);
+            apreq_run_parser(handle->parser, handle->body, bb);
         apr_brigade_destroy(bb);
         break;
 
@@ -337,7 +337,7 @@
         }
 
         handle->body_status =
-            APREQ_RUN_PARSER(handle->parser, handle->body, bb);
+            apreq_run_parser(handle->parser, handle->body, bb);
         apr_brigade_destroy(bb);
         break;
 

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_env_custom.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_env_custom.c?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_env_custom.c (original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_env_custom.c Mon Feb  7 18:27:24 2005
@@ -59,7 +59,7 @@
         }
 
         handle->body_status = 
-            APREQ_RUN_PARSER(handle->parser, handle->body, handle->in);
+            apreq_run_parser(handle->parser, handle->body, handle->in);
 
         apr_brigade_cleanup(handle->in);
         APR_BRIGADE_CONCAT(handle->in, bb);
@@ -79,7 +79,7 @@
             break;
         }
         handle->body_status = 
-            APREQ_RUN_PARSER(handle->parser, handle->body, handle->in);
+            apreq_run_parser(handle->parser, handle->body, handle->in);
 
         apr_brigade_cleanup(handle->in);
         APR_BRIGADE_CONCAT(handle->in, bb);

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_params.h
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_params.h?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_params.h (original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_params.h Mon Feb  7 18:27:24 2005
@@ -52,11 +52,33 @@
 }
 
 
-/** accessor macros */
-#define apreq_param_name(p)      ((p)->v.name)
-#define apreq_param_value(p)     ((p)->v.data)
-#define apreq_param_info(p)      ((p)->info)
-#define apreq_param_brigade(p) ((p)->bb ? apreq_copy_brigade((p)->bb) : NULL)
+static APR_INLINE
+const char *apreq_param_name(const apreq_param_t *p) {
+    return p->v.name;
+}
+
+static APR_INLINE
+const char *apreq_param_value(const apreq_param_t *p) {
+    return p->v.data;
+}
+
+static APR_INLINE
+const apr_table_t *apreq_param_info(const apreq_param_t *p) {
+    return p->info;
+}
+
+static APR_INLINE
+apr_bucket_brigade *apreq_param_brigade(const apreq_param_t *p) {
+    apr_bucket_brigade *bb;
+
+    if (p->upload == NULL)
+        return NULL;
+
+    bb = apr_brigade_create(p->upload->p, p->upload->bucket_alloc);
+    apreq_brigade_copy(bb, p->upload);
+
+    return bb;
+}
 
 /** creates a param from name/value information */
 APREQ_DECLARE(apreq_param_t *) apreq_make_param(apr_pool_t *p, 

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.c?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.c (original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.c Mon Feb  7 18:27:24 2005
@@ -21,6 +21,7 @@
 #include "apr_strmatch.h"
 #include "apr_xml.h"
 #include "apr_hash.h"
+#include "apr_thread_rwlock.h"
 
 #ifndef MAX
 #define MAX(A,B)  ( (A) > (B) ? (A) : (B) )
@@ -95,31 +96,68 @@
     return APR_SUCCESS;
 }
 
-static apr_hash_t *default_parsers;
-static apr_pool_t *default_parser_pool;
+static apr_thread_rwlock_t *default_parsers_lock = NULL;
+static apr_hash_t *default_parsers = NULL;
+static apr_pool_t *default_parser_pool = NULL;
+
+static apr_status_t apreq_parsers_cleanup(void *data) {
+    default_parsers_lock = NULL;
+    default_parsers = NULL;
+    default_parser_pool = NULL;
 
-static void apreq_parser_initialize(void)
+    return APR_SUCCESS;
+}
+
+static apr_status_t apreq_parser_initialize(apr_pool_t *pool)
 {
-    if (default_parsers != NULL)
-        return;
-    apr_pool_create(&default_parser_pool, NULL);
+    apr_status_t status;
+
+    if (default_parser_pool != NULL)
+        return APR_EGENERAL;
+
+    status = apr_pool_create(&default_parser_pool, pool);
+    if (status != APR_SUCCESS)
+        return status;
+
+    apr_pool_cleanup_register(default_parser_pool, NULL,
+                              apreq_parsers_cleanup,
+                              apr_pool_cleanup_null);
+
+    status = apr_thread_rwlock_create(&default_parsers_lock,
+                                      default_parser_pool);
+    if (status != APR_SUCCESS)
+        return status;
+
     default_parsers = apr_hash_make(default_parser_pool);
 
     apreq_register_parser("application/x-www-form-urlencoded",
                           apreq_parse_urlencoded);
     apreq_register_parser("multipart/form-data", apreq_parse_multipart);
     apreq_register_parser("multipart/related", apreq_parse_multipart);
+
+    return APR_SUCCESS;
+}
+
+APREQ_DECLARE(apr_status_t) apreq_initialize(apr_pool_t *pool) {
+    return apreq_parser_initialize(pool);
 }
 
-APREQ_DECLARE(void) apreq_register_parser(const char *enctype,
-                                          apreq_parser_function_t parser)
+APREQ_DECLARE(apr_status_t) apreq_register_parser(const char *enctype,
+                                                  apreq_parser_function_t parser)
 {
+    apr_status_t status;
     apreq_parser_function_t *f = NULL;
 
-    if (enctype == NULL) {
-        apreq_parser_initialize();
-        return;
-    }
+    if (default_parsers == NULL)
+        return APR_EINIT;
+
+    if (enctype == NULL)
+        return APR_EINVAL;
+
+    status = apr_thread_rwlock_wrlock(default_parsers_lock);
+    if (status != APR_SUCCESS)
+        return status;
+
     if (parser != NULL) {
         f = apr_palloc(default_parser_pool, sizeof *f);
         *f = parser;
@@ -127,20 +165,30 @@
     apr_hash_set(default_parsers, apr_pstrdup(default_parser_pool, enctype),
                  APR_HASH_KEY_STRING, f);
 
+    apr_thread_rwlock_unlock(default_parsers_lock);
+
+    return APR_SUCCESS;
 }
 APREQ_DECLARE(apreq_parser_function_t)apreq_parser(const char *enctype)
 {
+    apr_status_t status;
     apreq_parser_function_t *f;
     apr_size_t tlen = 0;
 
     if (enctype == NULL || default_parsers == NULL)
         return NULL;
 
+    status = apr_thread_rwlock_rdlock(default_parsers_lock);
+    if (status != APR_SUCCESS)
+        return NULL;
+
     while(enctype[tlen] && enctype[tlen] != ';')
         ++tlen;
 
     f = apr_hash_get(default_parsers, enctype, tlen);
 
+    apr_thread_rwlock_unlock(default_parsers_lock);
+
     if (f != NULL)
         return *f;
     else
@@ -279,7 +327,7 @@
             else {
                 s = split_urlword(&param, pool, ctx->bb, nlen, vlen);
                 if (parser->hook != NULL && s == APR_SUCCESS)
-                    s = APREQ_RUN_HOOK(parser->hook, param, NULL);
+                    s = apreq_run_hook(parser->hook, param, NULL);
 
                 if (s == APR_SUCCESS) {
                     apr_table_addn(t, param->v.name,  param->v.data);
@@ -324,7 +372,7 @@
                 case ';':
                     s = split_urlword(&param, pool, ctx->bb, nlen, vlen);
                     if (parser->hook != NULL && s == APR_SUCCESS)
-                        s = APREQ_RUN_HOOK(parser->hook, param, NULL);
+                        s = apreq_run_hook(parser->hook, param, NULL);
 
                     if (s != APR_SUCCESS) {
                         ctx->status = URL_ERROR;
@@ -343,7 +391,7 @@
             ; /* not reached */
         }
     }
-    APREQ_BRIGADE_SETASIDE(ctx->bb, pool);
+    apreq_brigade_setaside(ctx->bb, pool);
     return APR_INCOMPLETE;
 }
 
@@ -608,7 +656,7 @@
                         apr_bucket_split(e, off);
                     s = split_header_line(&param, pool, ctx->bb, nlen, glen, vlen);
                     if (parser->hook != NULL && s == APR_SUCCESS)
-                        s = APREQ_RUN_HOOK(parser->hook, param, NULL);
+                        s = apreq_run_hook(parser->hook, param, NULL);
 
                     if (s != APR_SUCCESS) {
                         ctx->status = HDR_ERROR;
@@ -648,7 +696,7 @@
             ; /* not reached */
         }
     }
-    APREQ_BRIGADE_SETASIDE(ctx->bb,pool);
+    apreq_brigade_setaside(ctx->bb,pool);
     return APR_INCOMPLETE;
 }
 
@@ -896,8 +944,8 @@
         {
             s = split_on_bdry(ctx->bb, ctx->in, NULL, ctx->bdry + 2);
             if (s != APR_SUCCESS) {
-                APREQ_BRIGADE_SETASIDE(ctx->in, pool);
-                APREQ_BRIGADE_SETASIDE(ctx->bb, pool);
+                apreq_brigade_setaside(ctx->in, pool);
+                apreq_brigade_setaside(ctx->bb, pool);
                 return s;
             }
             ctx->status = MFD_NEXTLINE;
@@ -911,8 +959,8 @@
         {
             s = split_on_bdry(ctx->bb, ctx->in, NULL, CRLF);
             if (s != APR_SUCCESS) {
-                APREQ_BRIGADE_SETASIDE(ctx->in, pool);
-                APREQ_BRIGADE_SETASIDE(ctx->bb, pool);
+                apreq_brigade_setaside(ctx->in, pool);
+                apreq_brigade_setaside(ctx->bb, pool);
                 return s;
             }
             if (!APR_BRIGADE_EMPTY(ctx->bb)) {
@@ -937,13 +985,13 @@
                 /* flush out old header parser internal structs for reuse */
                 ctx->hdr_parser->ctx = NULL;
             }
-            s = APREQ_RUN_PARSER(ctx->hdr_parser, ctx->info, ctx->in);
+            s = apreq_run_parser(ctx->hdr_parser, ctx->info, ctx->in);
             switch (s) {
             case APR_SUCCESS:
                 ctx->status = MFD_POST_HEADER;
                 break;
             case APR_INCOMPLETE:
-                APREQ_BRIGADE_SETASIDE(ctx->in, pool);
+                apreq_brigade_setaside(ctx->in, pool);
                 return APR_INCOMPLETE;
             default:
                 ctx->status = MFD_ERROR;
@@ -975,7 +1023,7 @@
             switch (brigade_start_string(ctx->in, ctx->bdry + 2)) {
 
             case APR_INCOMPLETE:
-                APREQ_BRIGADE_SETASIDE(ctx->in, pool);
+                apreq_brigade_setaside(ctx->in, pool);
                 return APR_INCOMPLETE;
 
             case APR_SUCCESS:
@@ -1101,8 +1149,8 @@
             switch (s) {
 
             case APR_INCOMPLETE:
-                APREQ_BRIGADE_SETASIDE(ctx->in, pool);
-                APREQ_BRIGADE_SETASIDE(ctx->bb, pool);
+                apreq_brigade_setaside(ctx->in, pool);
+                apreq_brigade_setaside(ctx->bb, pool);
                 return s;
 
             case APR_SUCCESS:
@@ -1123,7 +1171,7 @@
                 v->data[v->size] = 0;
 
                 if (parser->hook != NULL) {
-                    s = APREQ_RUN_HOOK(parser->hook, param, NULL);
+                    s = apreq_run_hook(parser->hook, param, NULL);
                     if (s != APR_SUCCESS) {
                         ctx->status = MFD_ERROR;
                         return s;
@@ -1154,14 +1202,14 @@
 
             case APR_INCOMPLETE:
                 if (parser->hook != NULL) {
-                    s = APREQ_RUN_HOOK(parser->hook, param, ctx->bb);
+                    s = apreq_run_hook(parser->hook, param, ctx->bb);
                     if (s != APR_SUCCESS) {
                         ctx->status = MFD_ERROR;
                         return s;
                     }
                 }
-                APREQ_BRIGADE_SETASIDE(ctx->bb, pool);
-                APREQ_BRIGADE_SETASIDE(ctx->in, pool);
+                apreq_brigade_setaside(ctx->bb, pool);
+                apreq_brigade_setaside(ctx->in, pool);
                 s = apreq_brigade_concat(pool, parser->temp_dir, parser->brigade_limit,

                                          param->upload, ctx->bb);
                 return (s == APR_SUCCESS) ? APR_INCOMPLETE : s;
@@ -1169,7 +1217,7 @@
             case APR_SUCCESS:
                 if (parser->hook != NULL) {
                     APR_BRIGADE_INSERT_TAIL(ctx->bb, ctx->eos);
-                    s = APREQ_RUN_HOOK(parser->hook, param, ctx->bb);
+                    s = apreq_run_hook(parser->hook, param, ctx->bb);
                     APR_BUCKET_REMOVE(ctx->eos);
                     if (s != APR_SUCCESS) {
                         ctx->status = MFD_ERROR;
@@ -1177,7 +1225,7 @@
                     }
                 }
                 apr_table_addn(t, param->v.name, param->v.data);
-                APREQ_BRIGADE_SETASIDE(ctx->bb, pool);
+                apreq_brigade_setaside(ctx->bb, pool);
                 s = apreq_brigade_concat(pool, parser->temp_dir, parser->brigade_limit,
                                          param->upload, ctx->bb);
 
@@ -1198,7 +1246,7 @@
 
     case MFD_MIXED:
         {
-            s = APREQ_RUN_PARSER(ctx->mix_parser, t, ctx->in);
+            s = apreq_run_parser(ctx->mix_parser, t, ctx->in);
             switch (s) {
             case APR_SUCCESS:
                 ctx->status = MFD_INIT;
@@ -1230,7 +1278,7 @@
 {
     apr_status_t s = APR_SUCCESS;
     if (hook->next)
-        s = APREQ_RUN_HOOK(hook->next, param, bb);
+        s = apreq_run_hook(hook->next, param, bb);
     if (bb != NULL)
         apr_brigade_cleanup(bb);
     return s;
@@ -1277,14 +1325,14 @@
     }
 
     if (parser->hook != NULL) {
-        s = APREQ_RUN_HOOK(parser->hook, ctx->param, bb);
+        s = apreq_run_hook(parser->hook, ctx->param, bb);
         if (s != APR_SUCCESS) {
             ctx->status = GEN_ERROR;
             return s;
         }
     }
 
-    APREQ_BRIGADE_SETASIDE(bb, pool);
+    apreq_brigade_setaside(bb, pool);
     s = apreq_brigade_concat(pool, parser->temp_dir, parser->brigade_limit,
                              ctx->param->upload, bb);
 
@@ -1340,7 +1388,7 @@
             if (s == APR_SUCCESS) {
                 ctx->status = XML_COMPLETE;
                 if (hook->next)
-                    s = APREQ_RUN_HOOK(hook->next, param, bb);
+                    s = apreq_run_hook(hook->next, param, bb);
             }
             else {
                 ctx->status = XML_ERROR;
@@ -1368,7 +1416,7 @@
     }
 
     if (hook->next)
-        return APREQ_RUN_HOOK(hook->next, param, bb);
+        return apreq_run_hook(hook->next, param, bb);
 
     return APR_SUCCESS;
 }

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.h
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.h?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.h (original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.h Mon Feb  7 18:27:24 2005
@@ -73,7 +73,11 @@
  * @remark  bb == NULL is valid: the parser should return its 
  * public status: APR_INCOMPLETE, APR_SUCCESS, or an error code.
  */
-#define APREQ_RUN_PARSER(psr,t,bb) (psr)->parser(psr,t,bb)
+static APR_INLINE
+apr_status_t apreq_run_parser(struct apreq_parser_t *psr, apr_table_t *t,
+                              apr_bucket_brigade *bb) {
+    return psr->parser(psr, t, bb);
+}
 
 /**
  * Run the hook with the current parameter and the incoming 
@@ -82,13 +86,17 @@
  * be added to the parameter's bb attribute.
  * @return APR_SUCCESS on success. All other values represent errors.
  */
-#define APREQ_RUN_HOOK(h,param,bb) (h)->hook(h,param,bb)
+static APR_INLINE
+apr_status_t apreq_run_hook(struct apreq_hook_t *h, apreq_param_t *param,
+                            apr_bucket_brigade *bb) {
+    return h->hook(h, param, bb);
+}
 
 
 /**
  * Rfc822 Header parser. It will reject all data
  * after the first CRLF CRLF sequence (an empty line).
- * See #APREQ_RUN_PARSER for more info on rejected data.
+ * See #apreq_run_parser for more info on rejected data.
  */
 APREQ_DECLARE_PARSER(apreq_parse_headers);
 
@@ -101,7 +109,7 @@
  * Rfc2388 multipart/form-data (and XForms 1.0 multipart/related)
  * parser. It will reject any buckets representing preamble and 
  * postamble text (this is normal behavior, not an error condition).
- * See #APREQ_RUN_PARSER for more info on rejected data.
+ * See #apreq_run_parser for more info on rejected data.
  */
 APREQ_DECLARE_PARSER(apreq_parse_multipart);
 
@@ -199,8 +207,8 @@
  * or within a request-thread mutex.
  */
 
-APREQ_DECLARE(void) apreq_register_parser(const char *enctype, 
-                                          apreq_parser_function_t parser);
+APREQ_DECLARE(apr_status_t) apreq_register_parser(const char *enctype,
+                                                  apreq_parser_function_t parser);
 
 
 /**

Modified: httpd/apreq/branches/multi-env-unstable/t/params.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/params.c?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/params.c (original)
+++ httpd/apreq/branches/multi-env-unstable/t/params.c Mon Feb  7 18:27:24 2005
@@ -206,30 +206,6 @@
     }
 }
 
-static void test_memmem(CuTest *tc)
-{
-    char *hay = apr_palloc(p,29);
-    char *partial, *full;
-    apr_size_t hlen = 28;
-    strcpy(hay, "The fear of fear is fearful.");
-
-    partial = apreq_memmem(hay, hlen, "fear of fly", 11, APREQ_MATCH_PARTIAL);
-    if (partial == NULL) CuAssertTrue(tc, 1);
-    partial = apreq_memmem(hay, hlen, "fear ", 5, APREQ_MATCH_PARTIAL);
-    CuAssertStrEquals(tc, "fear of fear is fearful.", partial);
-    partial = apreq_memmem(hay, hlen, "fear is", 7, APREQ_MATCH_PARTIAL);
-    CuAssertStrEquals(tc, "fear is fearful.", partial);
-    partial = apreq_memmem(hay, hlen, hay, hlen, APREQ_MATCH_PARTIAL);
-    CuAssertStrEquals(tc, hay, partial);
-    full = apreq_memmem(hay, hlen, "fear is", 7, APREQ_MATCH_FULL);
-    if (full == NULL) CuAssertTrue(tc, 1);
-    partial = apreq_memmem(hay, hlen, "fear of fly", 11, APREQ_MATCH_FULL);
-    if (partial == NULL) CuAssertTrue(tc, 1);
-    full = apreq_memmem(hay, hlen, hay, hlen, APREQ_MATCH_FULL);
-    CuAssertStrEquals(tc, hay, full);
-}
-
-
 CuSuite *testparam(void)
 {
     CuSuite *suite = CuSuiteNew("Param");
@@ -242,7 +218,6 @@
     SUITE_ADD_TEST(suite, make_values);
     SUITE_ADD_TEST(suite, quote_strings);
     SUITE_ADD_TEST(suite, make_param);
-    SUITE_ADD_TEST(suite, test_memmem);
     return suite;
 }
 

Modified: httpd/apreq/branches/multi-env-unstable/t/parsers.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/parsers.c?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/parsers.c (original)
+++ httpd/apreq/branches/multi-env-unstable/t/parsers.c Mon Feb  7 18:27:24 2005
@@ -142,7 +142,7 @@
         apr_bucket_immortal_create(url_data,strlen(url_data), 
                                    bb->bucket_alloc));
 
-    rv = APREQ_RUN_PARSER(parser, body, bb);
+    rv = apreq_run_parser(parser, body, bb);
     CuAssertIntEquals(tc, APR_INCOMPLETE, rv);
 
     APR_BRIGADE_INSERT_HEAD(bb,
@@ -151,7 +151,7 @@
     APR_BRIGADE_INSERT_TAIL(bb,
            apr_bucket_eos_create(bb->bucket_alloc));
 
-    rv = APREQ_RUN_PARSER(parser, body, bb);
+    rv = apreq_run_parser(parser, body, bb);
     CuAssertIntEquals(tc, APR_SUCCESS, rv);
 
     val = apr_table_get(body,"alpha");
@@ -207,9 +207,9 @@
                 apr_bucket_split(f, i - j);
 
             tail = apr_brigade_split(bb, f);
-            rv = APREQ_RUN_PARSER(parser, body, bb);
+            rv = apreq_run_parser(parser, body, bb);
             CuAssertIntEquals(tc, (j < strlen(form_data)) ? APR_INCOMPLETE : APR_SUCCESS,
rv);
-            rv = APREQ_RUN_PARSER(parser, body, tail);
+            rv = apreq_run_parser(parser, body, tail);
             CuAssertIntEquals(tc, APR_SUCCESS, rv);
             CuAssertIntEquals(tc, 2, apr_table_elts(body)->nelts);
 
@@ -266,7 +266,7 @@
                                1000, NULL, hook, NULL);
 
 
-    rv = APREQ_RUN_PARSER(parser, body, bb);
+    rv = apreq_run_parser(parser, body, bb);
     CuAssertIntEquals(tc, APR_EGENERAL, rv);
     CuAssertIntEquals(tc, 1, apr_table_elts(body)->nelts);
 
@@ -303,7 +303,7 @@
     parser = apreq_make_parser(p, ba, "application/xml", 
                                apreq_parse_generic, 1000, NULL, NULL, NULL);
 
-    rv = APREQ_RUN_PARSER(parser, body, bb);
+    rv = apreq_run_parser(parser, body, bb);
     CuAssertIntEquals(tc, APR_SUCCESS, rv);
     dummy = *(apreq_param_t **)parser->ctx;
     CuAssertPtrNotNull(tc, dummy);
@@ -336,7 +336,7 @@
                                apreq_parse_generic, 1000, NULL, hook, NULL);
 
 
-    rv = APREQ_RUN_PARSER(parser, body, bb);
+    rv = apreq_run_parser(parser, body, bb);
     CuAssertIntEquals(tc, APR_SUCCESS, rv);
     dummy = *(apreq_param_t **)parser->ctx;
     CuAssertPtrNotNull(tc, dummy);
@@ -375,7 +375,7 @@
     parser = apreq_make_parser(p, ba, ct, apreq_parse_multipart, 
                                1000, NULL, xml_hook, NULL);
 
-    rv = APREQ_RUN_PARSER(parser, body, bb);
+    rv = apreq_run_parser(parser, body, bb);
     CuAssertIntEquals(tc, APR_SUCCESS, rv);
 
     val = apr_table_get(body, "<980119.X53GGT@example.com>");
@@ -447,7 +447,7 @@
     parser = apreq_make_parser(p, ba, ct, apreq_parse_multipart, 
                                1000, NULL, NULL, NULL);
 
-    rv = APREQ_RUN_PARSER(parser, body, bb);
+    rv = apreq_run_parser(parser, body, bb);
     CuAssertIntEquals(tc, APR_SUCCESS, rv);
 
     val = apr_table_get(body, "submit-name");

Modified: httpd/apreq/branches/multi-env-unstable/t/testall.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/testall.c?view=diff&r1=151820&r2=151821
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/testall.c (original)
+++ httpd/apreq/branches/multi-env-unstable/t/testall.c Mon Feb  7 18:27:24 2005
@@ -62,6 +62,7 @@
 
 int main(int argc, char *argv[])
 {
+    apr_status_t status;
     CuSuiteList *alltests = NULL;
     CuString *output = CuStringNew();
     int i;
@@ -73,6 +74,10 @@
     CuInit(argc, argv);
 
     apr_pool_create(&p, NULL);
+
+    status = apreq_initialize(p);
+    if (status != APR_SUCCESS)
+        return 1;
 
     /* build the list of tests to run */
     for (i = 1; i < argc; i++) {



Mime
View raw message