]> granicus.if.org Git - apache/commitdiff
Allow filters to buffer data in a brigade using the ap_f* functions.
authorRyan Bloom <rbb@apache.org>
Fri, 9 Feb 2001 07:04:52 +0000 (07:04 +0000)
committerRyan Bloom <rbb@apache.org>
Fri, 9 Feb 2001 07:04:52 +0000 (07:04 +0000)
These have become simple macros that just wrap the apr_brigade functions,
allowing filter writers to ignore the flush function and the ctx pointer.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@88028 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
include/util_filter.h
server/util_filter.c

diff --git a/CHANGES b/CHANGES
index 9eb6100e448b907ed17e09e198e365fa3b4f8ab6..e2c16a932ff929cb084ed5cb209277428bc28200 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,9 @@
 Changes with Apache 2.0b1
 
+  *) Allow filters to buffer data using the ap_f* functions.  These have
+     become macros that resolve directly to apr_brigade_*.  
+     [Ryan Bloom]
+
   *) Get the Unix MPM's to do a graceful restart again.  If we are going
      to register a cleanup with ap_cleanup_scoreboard, then we have to
      kill the cleanup with the same function,  and that function can't be
index 7931181f808ca73b5377bafb5438de5dbbc88b57..ba3ef7808df0f22fa757c4a15d3dac1b7bc346b8 100644 (file)
@@ -393,6 +393,75 @@ AP_DECLARE(void) ap_remove_output_filter(ap_filter_t *f);
 AP_DECLARE(apr_status_t) ap_save_brigade(ap_filter_t *f, apr_bucket_brigade **save_to,
                                          apr_bucket_brigade **b);    
 
+/**
+ * Flush function for apr_brigade_* calls.  This calls ap_pass_brigade
+ * to flush the brigade if the brigade buffer overflows.
+ * @param bb The brigade to flush
+ * @param ctx The filter to pass the brigade to
+ * @deffunc apr_status_t filter_flush(apr_bucket_brigade *bb, void *ctx)
+ */
+apr_status_t filter_flush(apr_bucket_brigade *bb, void *ctx);
+
+/**
+ * Flush the current brigade down the filter stack
+ * @param f the next filter in the stack
+ * @param bb The brigade to flush
+ * @deffunc int ap_fflush(ap_filter_t *f, apr_bucket_brigade *bb)
+ */
+AP_DECLARE(int) ap_fflush(ap_filter_t *f, apr_bucket_brigade *bb);
+
+/**
+ * Write a buffer for the current filter, buffering if possible.
+ * @param f the filter to write to
+ * @param bb The brigade to buffer into
+ * @param str The string to write
+ * @param byte The number of characters in the string
+ * @deffunc int ap_fwrite(ap_filter_t *f, apr_bucket_brigade *bb, const char *str, apr_ssize_t byte);
+ */
+#define ap_fwrite(f, bb, str, byte) \
+       apr_brigade_write(bb, filter_flush, f->next, str, byte)
+
+/**
+ * Write a buffer for the current filter, buffering if possible.
+ * @param f the filter to write to
+ * @param bb The brigade to buffer into
+ * @param str The string to write
+ * @deffunc int ap_fputs(ap_filter_t *f, apr_bucket_brigade *bb, const char *str);
+ */
+#define ap_fputs(f, bb, str) \
+       apr_brigade_puts(bb, filter_flush, f->next, str)
+
+/**
+ * Write a character for the current filter, buffering if possible.
+ * @param f the filter to write to
+ * @param bb The brigade to buffer into
+ * @param str The character to write
+ * @deffunc int ap_fputc(ap_filter_t *f, apr_bucket_brigade *bb, char str);
+ */
+#define ap_fputc(f, bb, str) \
+       apr_brigade_putc(bb, filter_flush, f->next, str)
+
+/**
+ * Write an unspecified number of strings to the current filter
+ * @param f the filter to write to
+ * @param bb The brigade to buffer into
+ * @param ... The strings to write
+ * @deffunc int ap_fputs(ap_filter_t *f, apr_bucket_brigade *bb, ...);
+ */
+#define ap_fvputs(f, bb, args...) \
+       apr_brigade_putstrs(bb, filter_flush, f->next, ##args)
+
+/**
+ * Output data to the filter in printf format
+ * @param f the filter to write to
+ * @param bb The brigade to buffer into
+ * @param fmt The format string
+ * @param ... The argumets to use to fill out the format string
+ * @deffunc int ap_fputs(ap_filter_t *f, apr_bucket_brigade *bb, const char *fmt, ...);
+ */
+#define ap_fprintf(f, bb, fmt, args...) \
+       apr_brigade_printf(bb, filter_flush, f->next, fmt, ##args)
+
 #ifdef __cplusplus
 }
 #endif
index a5bb1185a407bf97312c80322d69c031b5ecb7f2..595f7e592ad15ae9442ed32bfa955c6bea98af18 100644 (file)
@@ -265,3 +265,22 @@ AP_DECLARE(apr_status_t) ap_save_brigade(ap_filter_t *f, apr_bucket_brigade **sa
     APR_BRIGADE_CONCAT(*saveto, *b);
     return APR_SUCCESS;
 }
+
+apr_status_t filter_flush(apr_bucket_brigade *bb, void *ctx)
+{
+    ap_filter_t *f = ctx;
+
+    return ap_pass_brigade(f, bb);
+}
+
+AP_DECLARE(int) ap_fflush(ap_filter_t *f, apr_bucket_brigade *bb)
+{
+    apr_bucket *b;
+
+    b = apr_bucket_flush_create();
+    APR_BRIGADE_INSERT_TAIL(bb, b);
+    if (ap_pass_brigade(f->next, bb) != APR_SUCCESS)
+        return -1;
+    return 0;
+}
+