summaryrefslogtreecommitdiff
path: root/buckets
diff options
context:
space:
mode:
authorRyan Bloom <rbb@apache.org>2000-07-13 21:48:34 +0000
committerRyan Bloom <rbb@apache.org>2000-07-13 21:48:34 +0000
commite1788643c0d329f07374e0e49620c7f01e3a9dc8 (patch)
treee7fdf45892f58d74f7c5f5930c0fa6b79f8d817f /buckets
parent85d6f12f5e74ed91c29f116bf0d6a47f6e43efe1 (diff)
downloadapr-e1788643c0d329f07374e0e49620c7f01e3a9dc8.tar.gz
Update the bucket brigades to be a bit less complex. This makes the
functions get_str and get_len function pointers inside the bucket itself. This is the first step in cleaning these up just a bit. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@60365 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'buckets')
-rw-r--r--buckets/ap_buf.c60
-rw-r--r--buckets/ap_eos_buf.c86
-rw-r--r--buckets/ap_mmap_buf.c31
-rw-r--r--buckets/ap_rmem_buf.c30
-rw-r--r--buckets/ap_rwmem_buf.c43
-rw-r--r--buckets/apr_buf.h45
6 files changed, 183 insertions, 112 deletions
diff --git a/buckets/ap_buf.c b/buckets/ap_buf.c
index 7bc4d9f45..9bdb88dd0 100644
--- a/buckets/ap_buf.c
+++ b/buckets/ap_buf.c
@@ -68,38 +68,28 @@
APR_EXPORT(ap_bucket *) ap_bucket_new(ap_bucket_color_e color)
{
/* TODO: keep a free list of ap_bufels... and allocate them in big chunks */
- ap_bucket *newbuf;
- newbuf = malloc(sizeof(*newbuf));
- newbuf->color = color;
switch (color) {
case AP_BUCKET_rwmem:
- newbuf->data = ap_rwmem_create();
- newbuf->free = ap_rwmem_destroy;
- break;
+ return ap_rwmem_create();
case AP_BUCKET_mmap:
- newbuf->data = ap_mmap_bucket_create();
- newbuf->free = NULL;
- break;
+ return ap_mmap_bucket_create();
case AP_BUCKET_rmem:
- newbuf->data = ap_rmem_create();
- newbuf->free = NULL;
- break;
+ return ap_rmem_create();
case AP_BUCKET_eos:
- newbuf->data = NULL;
- newbuf->free = NULL;
+ return ap_eos_create();
case AP_BUCKET_file:
case AP_BUCKET_filename:
case AP_BUCKET_cached_entity:
case AP_BUCKET_URI:
/* not implemented yet */
- break;
+ return NULL;
}
- return newbuf;
+ return NULL;
}
APR_EXPORT(ap_status_t) ap_bucket_destroy(ap_bucket *e)
{
- if (e->free != NULL) {
+ if (e->free) {
e->free(e);
}
free(e);
@@ -263,45 +253,17 @@ APR_EXPORT(ap_status_t) ap_destroy_bucket_list(ap_bucket_list *buf)
APR_EXPORT(const char *) ap_get_bucket_char_str(ap_bucket *b)
{
- switch (b->color) {
- case AP_BUCKET_rwmem:
- return ap_rwmem_get_char_str(b->data);
- case AP_BUCKET_mmap:
- return ap_mmap_get_char_str(b->data);
- case AP_BUCKET_rmem:
- return ap_rmem_get_char_str(b->data);
- case AP_BUCKET_eos:
- return NULL;
- case AP_BUCKET_file:
- case AP_BUCKET_filename:
- case AP_BUCKET_cached_entity:
- case AP_BUCKET_URI:
- /* not implemented yet */
- return NULL;
+ if (b) {
+ return b->getstr(b);
}
- /* We should NEVER actually get here */
return NULL;
}
APR_EXPORT(int) ap_get_bucket_len(ap_bucket *b)
{
- switch (b->color) {
- case AP_BUCKET_rwmem:
- return ap_rwmem_get_len(b->data);
- case AP_BUCKET_mmap:
- return ap_mmap_get_len(b->data);
- case AP_BUCKET_rmem:
- return ap_rmem_get_len(b->data);
- case AP_BUCKET_eos:
- return 0;
- case AP_BUCKET_file:
- case AP_BUCKET_filename:
- case AP_BUCKET_cached_entity:
- case AP_BUCKET_URI:
- /* not implemented yet */
- return 0;
+ if (b) {
+ return b->getlen(b);
}
- /* We should NEVER actually get here */
return 0;
}
diff --git a/buckets/ap_eos_buf.c b/buckets/ap_eos_buf.c
new file mode 100644
index 000000000..3b53feb22
--- /dev/null
+++ b/buckets/ap_eos_buf.c
@@ -0,0 +1,86 @@
+/* ====================================================================
+ * Copyright (c) 1996-1999 The Apache Group. 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. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgment:
+ * "This product includes software developed by the Apache Group
+ * for use in the Apache HTTP server project (http://www.apache.org/)."
+ *
+ * 4. The names "Apache Server" and "Apache Group" 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 names without prior written
+ * permission of the Apache Group.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by the Apache Group
+ * for use in the Apache HTTP server project (http://www.apache.org/)."
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``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 GROUP 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 Group and was originally based
+ * on public domain software written at the National Center for
+ * Supercomputing Applications, University of Illinois, Urbana-Champaign.
+ * For more information on the Apache Group and the Apache HTTP server
+ * project, please see <http://www.apache.org/>.
+ *
+ */
+
+#include "apr_private.h"
+#include "apr_buf.h"
+#include <stdlib.h>
+
+static const char * eos_get_str(ap_bucket *e)
+{
+ return NULL;
+}
+
+static int eos_get_len(ap_bucket *e)
+{
+ return 0;
+}
+
+APR_EXPORT(ap_bucket *) ap_eos_create(void)
+{
+ ap_bucket *newbuf;
+
+ newbuf = malloc(sizeof(*newbuf));
+
+ newbuf->color = AP_BUCKET_eos;
+ newbuf->getstr = eos_get_str;
+ newbuf->getlen = eos_get_len;
+ newbuf->free = NULL;
+ newbuf->data = NULL;
+
+ return newbuf;
+}
+
diff --git a/buckets/ap_mmap_buf.c b/buckets/ap_mmap_buf.c
index 895b37032..c2ba6f1fc 100644
--- a/buckets/ap_mmap_buf.c
+++ b/buckets/ap_mmap_buf.c
@@ -59,22 +59,35 @@
#include "apr_buf.h"
#include <stdlib.h>
-APR_EXPORT(ap_bucket_mmap *) ap_mmap_bucket_create(void)
+static const char * mmap_get_str(ap_bucket *e)
{
- ap_bucket_mmap *newbuf;
- newbuf = malloc(sizeof(*newbuf));
- newbuf->data = NULL;
- return newbuf;
+ ap_bucket_mmap *b = (ap_bucket_mmap *)e->data;
+ return b->data->mm;
}
-APR_EXPORT(char *) ap_mmap_get_char_str(ap_bucket_mmap *b)
+static int mmap_get_len(ap_bucket *e)
{
- return b->data->mm;
+ ap_bucket_mmap *b = (ap_bucket_mmap *)e->data;
+ return b->data->size;
}
-APR_EXPORT(int) ap_mmap_get_len(ap_bucket_mmap *b)
+APR_EXPORT(ap_bucket *) ap_mmap_bucket_create(void)
{
- return b->data->size;
+ ap_bucket *newbuf;
+ ap_bucket_mmap *b;
+
+ newbuf = malloc(sizeof(*newbuf));
+ b = malloc(sizeof(*b));
+
+ b->data = NULL;
+
+ newbuf->color = AP_BUCKET_mmap;
+ newbuf->getstr = mmap_get_str;
+ newbuf->getlen = mmap_get_len;
+ newbuf->free = NULL;
+ newbuf->data = b;
+
+ return newbuf;
}
APR_EXPORT(void) ap_mmap_bucket_insert(ap_bucket_mmap *b, ap_mmap_t *mm)
diff --git a/buckets/ap_rmem_buf.c b/buckets/ap_rmem_buf.c
index 55e871f3d..985d2efb5 100644
--- a/buckets/ap_rmem_buf.c
+++ b/buckets/ap_rmem_buf.c
@@ -63,21 +63,35 @@
#define DEFAULT_RWBUF_SIZE (4096)
#endif
-APR_EXPORT(ap_bucket_rmem *) ap_rmem_create(void)
+static const char * rmem_get_str(ap_bucket *e)
{
- ap_bucket_rmem *newbuf;
- newbuf = calloc(1, sizeof(*newbuf));
- return newbuf;
+ ap_bucket_rmem *b = (ap_bucket_rmem *)e->data;
+ return b->start;
}
-APR_EXPORT(const char *) ap_rmem_get_char_str(ap_bucket_rmem *b)
+static int rmem_get_len(ap_bucket *e)
{
- return b->start;
+ ap_bucket_rmem *b = (ap_bucket_rmem *)e->data;
+ return (char *)b->end - (char *)b->start;
}
-APR_EXPORT(int) ap_rmem_get_len(ap_bucket_rmem *b)
+APR_EXPORT(ap_bucket *) ap_rmem_create(void)
{
- return (char *)b->end - (char *)b->start;
+ ap_bucket *newbuf;
+ ap_bucket_rmem *b;
+
+ newbuf = malloc(sizeof(*newbuf));
+ b = malloc(sizeof(*b));
+
+ b->alloc_len = 0;
+ b->start = b->end = NULL;
+
+ newbuf->color = AP_BUCKET_rmem;
+ newbuf->getstr = rmem_get_str;
+ newbuf->getlen = rmem_get_len;
+ newbuf->free = NULL;
+ newbuf->data = b;
+ return newbuf;
}
/*
diff --git a/buckets/ap_rwmem_buf.c b/buckets/ap_rwmem_buf.c
index 82cacae5f..f36fcb192 100644
--- a/buckets/ap_rwmem_buf.c
+++ b/buckets/ap_rwmem_buf.c
@@ -63,31 +63,44 @@
#define DEFAULT_RWBUF_SIZE (4096)
#endif
-APR_EXPORT(ap_bucket_rwmem *) ap_rwmem_create(void)
+static const char * rwmem_get_str(ap_bucket *e)
{
- ap_bucket_rwmem *newbuf;
- newbuf = malloc(sizeof(*newbuf));
- newbuf->alloc_addr = calloc(DEFAULT_RWBUF_SIZE, 1);
- newbuf->alloc_len = DEFAULT_RWBUF_SIZE;
- newbuf->start = newbuf->alloc_addr;
- newbuf->end = newbuf->alloc_addr;
- return newbuf;
+ ap_bucket_rwmem *b = (ap_bucket_rwmem *)e->data;
+ return b->start;
}
-APR_EXPORT(void) ap_rwmem_destroy(void *e)
+static int rwmem_get_len(ap_bucket *e)
{
- ap_bucket_rwmem *d = (ap_bucket_rwmem *)e;
- free(d->alloc_addr);
+ ap_bucket_rwmem *b = (ap_bucket_rwmem *)e->data;
+ return (char *)b->end - (char *)b->start;
}
-APR_EXPORT(char *) ap_rwmem_get_char_str(ap_bucket_rwmem *b)
+static void rwmem_destroy(void *e)
{
- return b->start;
+ ap_bucket_rwmem *d = (ap_bucket_rwmem *)e;
+ free(d->alloc_addr);
}
-APR_EXPORT(int) ap_rwmem_get_len(ap_bucket_rwmem *b)
+APR_EXPORT(ap_bucket *) ap_rwmem_create(void)
{
- return (char *)b->end - (char *)b->start;
+ ap_bucket *newbuf;
+ ap_bucket_rwmem *b;
+
+ newbuf = malloc(sizeof(*newbuf));
+ b = malloc(sizeof(*b));
+
+ b->alloc_addr = calloc(DEFAULT_RWBUF_SIZE, 1);
+ b->alloc_len = DEFAULT_RWBUF_SIZE;
+ b->start = b->alloc_addr;
+ b->end = b->alloc_addr;
+
+ newbuf->color = AP_BUCKET_rwmem;
+ newbuf->getstr = rwmem_get_str;
+ newbuf->getlen = rwmem_get_len;
+ newbuf->free = rwmem_destroy;
+ newbuf->data = b;
+
+ return newbuf;
}
/*
diff --git a/buckets/apr_buf.h b/buckets/apr_buf.h
index d4ec87c5c..00701e94b 100644
--- a/buckets/apr_buf.h
+++ b/buckets/apr_buf.h
@@ -62,7 +62,7 @@
#ifdef HAVE_SYS_UIO_H
#include <sys/uio.h> /* for struct iovec */
#endif
-#ifdef APR_HAVE_STDARG_H
+#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif
@@ -81,9 +81,11 @@ typedef enum {
typedef struct ap_bucket ap_bucket;
struct ap_bucket {
- ap_bucket_color_e color; /* what type of bucket is it */
- void (*free)(void *e); /* can be NULL */
- void *data; /* for use by free() */
+ ap_bucket_color_e color; /* what type of bucket is it */
+ void (*free)(void *e); /* can be NULL */
+ void *data; /* for use by free() */
+ const char *(*getstr)(ap_bucket *e); /* Get the string */
+ int (*getlen)(ap_bucket *e); /* Get the length of the string */
};
typedef struct ap_bucket_list ap_bucket_list;
@@ -183,16 +185,7 @@ struct ap_bucket_rwmem {
};
/* Create a read/write memory bucket */
-APR_EXPORT(ap_bucket_rwmem *) ap_rwmem_create(void);
-
-/* destroy a read/write memory bucket */
-APR_EXPORT(void) ap_rwmem_destroy(void *e);
-
-/* Convert a rwmem bucket into a char * */
-APR_EXPORT(char *) ap_rwmem_get_char_str(ap_bucket_rwmem *b);
-
-/* get the length of the data in the rwmem bucket */
-APR_EXPORT(int) ap_rwmem_get_len(ap_bucket_rwmem *b);
+APR_EXPORT(ap_bucket *) ap_rwmem_create(void);
APR_EXPORT(int) ap_rwmem_write(ap_bucket_rwmem *b, const void *buf,
ap_size_t nbyte, ap_ssize_t *bytes_written);
@@ -207,13 +200,7 @@ struct ap_bucket_mmap {
};
/* Create a mmap memory bucket */
-APR_EXPORT(ap_bucket_mmap *) ap_mmap_bucket_create(void);
-
-/* Convert a mmap bucket into a char * */
-APR_EXPORT(char *) ap_mmap_get_char_str(ap_bucket_mmap *b);
-
-/* get the length of the data in the mmap bucket */
-APR_EXPORT(int) ap_mmap_get_len(ap_bucket_mmap *b);
+APR_EXPORT(ap_bucket *) ap_mmap_bucket_create(void);
APR_EXPORT(void) ap_mmap_bucket_insert(ap_bucket_mmap *b, ap_mmap_t *mm);
@@ -228,21 +215,17 @@ struct ap_bucket_rmem {
};
/* Create a read only memory bucket */
-APR_EXPORT(ap_bucket_rmem *) ap_rmem_create(void);
-
-/* destroy a read only memory bucket */
-APR_EXPORT(void) ap_rmem_destroy(void *e);
-
-/* Convert a read only bucket into a char * */
-APR_EXPORT(const char *) ap_rmem_get_char_str(ap_bucket_rmem *b);
-
-/* get the length of the data in the rmem bucket */
-APR_EXPORT(int) ap_rmem_get_len(ap_bucket_rmem *b);
+APR_EXPORT(ap_bucket *) ap_rmem_create(void);
APR_EXPORT(int) ap_rmem_write(ap_bucket_rmem *b, const void *buf,
ap_size_t nbyte, ap_ssize_t *bytes_written);
APR_EXPORT(int) ap_rmem_vputstrs(ap_bucket_rmem *b, va_list va);
+/* ****** RMEM Functions ***** */
+
+/* Create an End of Stream bucket */
+APR_EXPORT(ap_bucket *) ap_eos_create(void);
+
#endif