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 2005/03/15 03:04:39 UTC

svn commit: r157492 - in httpd/apreq/branches/multi-env-unstable: include/apreq_util.h library/module_cgi.c library/module_custom.c module/apache2/filter.c

Author: joes
Date: Mon Mar 14 18:04:37 2005
New Revision: 157492

URL: http://svn.apache.org/viewcvs?view=rev&rev=157492
Log:
Replace leaky uses of apr_brigade_split
with new apreq_brigade_move, patterned on
Paul Querna's r154200 patch to httpd's
core_filters.c.

Modified:
    httpd/apreq/branches/multi-env-unstable/include/apreq_util.h
    httpd/apreq/branches/multi-env-unstable/library/module_cgi.c
    httpd/apreq/branches/multi-env-unstable/library/module_custom.c
    httpd/apreq/branches/multi-env-unstable/module/apache2/filter.c

Modified: httpd/apreq/branches/multi-env-unstable/include/apreq_util.h
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/include/apreq_util.h?view=diff&r1=157491&r2=157492
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/include/apreq_util.h (original)
+++ httpd/apreq/branches/multi-env-unstable/include/apreq_util.h Mon Mar 14 18:04:37 2005
@@ -303,6 +303,36 @@
     }
 }
 
+/**
+ * Move the front of a brigade.
+ *
+ * @param d (destination) Append buckets to this brigade.
+ * @param s (source) Brigade to take buckets from.
+ * @param e First bucket of s after the move.  All buckets
+ *          before e are appended to d.
+ *
+ * @remarks This moves all buckets when e == APR_BRIGADE_SENTINEL(s).
+ */
+
+static APR_INLINE
+void apreq_brigade_move(apr_bucket_brigade *d, apr_bucket_brigade *s,
+                        apr_bucket *e)
+{
+    apr_bucket *f;     
+
+    if (e != APR_BRIGADE_SENTINEL(s)) {
+        f = APR_RING_FIRST(&s->list);
+        APR_RING_UNSPLICE(f, e, link);
+        APR_RING_SPLICE_HEAD(&d->list, f, e, apr_bucket, link);
+    }
+    else {
+        APR_BRIGADE_CONCAT(d, s);
+    }
+
+    APR_BRIGADE_CHECK_CONSISTENCY(s);
+    APR_BRIGADE_CHECK_CONSISTENCY(d);
+}
+
 
 /**
  * Search a header string for the value of a particular named attribute.

Modified: httpd/apreq/branches/multi-env-unstable/library/module_cgi.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/library/module_cgi.c?view=diff&r1=157491&r2=157492
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/library/module_cgi.c (original)
+++ httpd/apreq/branches/multi-env-unstable/library/module_cgi.c Mon Mar 14 18:04:37 2005
@@ -20,6 +20,7 @@
 #include "apr_strings.h"
 #include "apr_lib.h"
 #include "apr_env.h"
+#include "apreq_util.h"
 
 #define USER_DATA_KEY "apreq"
 
@@ -60,6 +61,7 @@
     apr_uint64_t                 bytes_read;
 
     apr_bucket_brigade          *in;
+    apr_bucket_brigade          *tmpbb;
 
 };
 
@@ -255,6 +257,7 @@
 
     handle->hook_queue = NULL;
     handle->in         = apr_brigade_create(pool, ba);
+    handle->tmpbb      = apr_brigade_create(pool, ba);
 
     apr_file_open_stdin(&file, pool); // error status?    
     pipe = apr_bucket_pipe_create(file, ba);
@@ -281,13 +284,11 @@
 
 
     switch (s = apr_brigade_partition(handle->in, bytes, &e)) {
-        apr_bucket_brigade *bb;
         apr_off_t len;
 
     case APR_SUCCESS:
 
-        bb = handle->in;
-        handle->in = apr_brigade_split(bb, e);
+        apreq_brigade_move(handle->tmpbb, handle->in, e);
         handle->bytes_read += bytes;
 
         if (handle->bytes_read > handle->read_limit) {
@@ -300,16 +301,15 @@
         }
 
         handle->body_status =
-            apreq_parser_run(handle->parser, handle->body, bb);
-        apr_brigade_destroy(bb);
+            apreq_parser_run(handle->parser, handle->body, handle->tmpbb);
+        apr_brigade_cleanup(handle->tmpbb);
         break;
 
 
     case APR_INCOMPLETE:
 
-        bb = handle->in;
-        handle->in = apr_brigade_split(bb, e);
-        s = apr_brigade_length(bb, 1, &len);
+        apreq_brigade_move(handle->tmpbb, handle->in, e);
+        s = apr_brigade_length(handle->tmpbb, 1, &len);
 
         if (s != APR_SUCCESS) {
             handle->body_status = s;
@@ -328,8 +328,8 @@
         }
 
         handle->body_status =
-            apreq_parser_run(handle->parser, handle->body, bb);
-        apr_brigade_destroy(bb);
+            apreq_parser_run(handle->parser, handle->body, handle->tmpbb);
+        apr_brigade_cleanup(handle->tmpbb);
         break;
 
     default:

Modified: httpd/apreq/branches/multi-env-unstable/library/module_custom.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/library/module_custom.c?view=diff&r1=157491&r2=157492
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/library/module_custom.c (original)
+++ httpd/apreq/branches/multi-env-unstable/library/module_custom.c Mon Mar 14 18:04:37 2005
@@ -17,6 +17,7 @@
 #include "apr_strings.h"
 #include "apreq_module.h"
 #include "apreq_error.h"
+#include "apreq_util.h"
 
 #define READ_BYTES (64 * 1024)
 
@@ -34,6 +35,7 @@
     apr_uint64_t                 read_limit;
     apr_uint64_t                 bytes_read;
     apr_bucket_brigade          *in;
+    apr_bucket_brigade          *tmpbb;
 };
 
 
@@ -47,11 +49,10 @@
         return handle->body_status;
 
     switch (s = apr_brigade_partition(handle->in, bytes, &e)) {
-        apr_bucket_brigade *bb;
         apr_uint64_t len;
 
     case APR_SUCCESS:
-        bb = apr_brigade_split(handle->in, e);
+        apreq_brigade_move(handle->tmpbb, handle->in, e);
         handle->bytes_read += bytes;
 
         if (handle->bytes_read > handle->read_limit) {
@@ -60,15 +61,14 @@
         }
 
         handle->body_status = 
-            apreq_parser_run(handle->parser, handle->body, handle->in);
+            apreq_parser_run(handle->parser, handle->body, handle->tmpbb);
 
-        apr_brigade_cleanup(handle->in);
-        APR_BRIGADE_CONCAT(handle->in, bb);
+        apr_brigade_cleanup(handle->tmpbb);
         break;
 
     case APR_INCOMPLETE:
-        bb = apr_brigade_split(handle->in, e);
-        s = apr_brigade_length(handle->in, 1, &len);
+        apreq_brigade_move(handle->tmpbb, handle->in, e);
+        s = apr_brigade_length(handle->tmpbb, 1, &len);
         if (s != APR_SUCCESS) {
             handle->body_status = s;
             break;
@@ -80,10 +80,9 @@
             break;
         }
         handle->body_status = 
-            apreq_parser_run(handle->parser, handle->body, handle->in);
+            apreq_parser_run(handle->parser, handle->body, handle->tmpbb);
 
-        apr_brigade_cleanup(handle->in);
-        APR_BRIGADE_CONCAT(handle->in, bb);
+        apr_brigade_cleanup(handle->tmpbb);
         break;
 
     default:
@@ -321,6 +320,7 @@
     }
 
     if (in != NULL) {
+        handle->tmpbb = apr_brigade_create(in->p, in->bucket_alloc);
         handle->body = apr_table_make(pool, APREQ_DEFAULT_NELTS);
         handle->body_status = APR_INCOMPLETE;
     }

Modified: httpd/apreq/branches/multi-env-unstable/module/apache2/filter.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/module/apache2/filter.c?view=diff&r1=157491&r2=157492
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/module/apache2/filter.c (original)
+++ httpd/apreq/branches/multi-env-unstable/module/apache2/filter.c Mon Mar 14 18:04:37 2005
@@ -409,10 +409,10 @@
         }
 
         if (!APR_BRIGADE_EMPTY(ctx->spool)) {
-            APR_BRIGADE_PREPEND(bb, ctx->spool);
+            APR_BRIGADE_CONCAT(ctx->spool, bb);
             if (mode == AP_MODE_READBYTES) {
                 apr_bucket *e;
-                rv = apr_brigade_partition(bb, readbytes, &e);
+                rv = apr_brigade_partition(ctx->spool, readbytes, &e);
                 if (rv != APR_SUCCESS && rv != APR_INCOMPLETE) {
                     ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, 
                                  "partition failed");
@@ -420,7 +420,7 @@
                 }
                 if (APR_BUCKET_IS_EOS(e))
                     e = APR_BUCKET_NEXT(e);
-                ctx->spool = apr_brigade_split(bb, e);
+                apreq_brigade_move(bb, ctx->spool, e);
                 apreq_brigade_setaside(ctx->spool, r->pool);
             }
         }