httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/include apr_buf.h
Date Tue, 11 Jul 2000 00:25:57 GMT
rbb         00/07/10 17:25:57

  Modified:    src/lib/apr configure.in
  Added:       src/lib/apr/buckets Makefile.in ap_buf.c ap_mmap_buf.c
                        ap_rwmem_buf.c
               src/lib/apr/include apr_buf.h
  Log:
  First pass at buckets brigades.
  
  Revision  Changes    Path
  1.132     +2 -2      apache-2.0/src/lib/apr/configure.in
  
  Index: configure.in
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/configure.in,v
  retrieving revision 1.131
  retrieving revision 1.132
  diff -u -r1.131 -r1.132
  --- configure.in	2000/06/30 21:09:06	1.131
  +++ configure.in	2000/07/11 00:25:56	1.132
  @@ -678,8 +678,8 @@
   AC_SUBST(EXEEXT)
   
   echo "Construct Makefiles and header files."
  -MAKEFILE1="Makefile lib/Makefile "
  -SUBDIRS="lib "
  +MAKEFILE1="Makefile lib/Makefile buckets/Makefile"
  +SUBDIRS="lib buckets"
   for dir in $MODULES
   do
       test -d $dir || $MKDIR -p $dir
  
  
  
  1.1                  apache-2.0/src/lib/apr/buckets/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  #CFLAGS=$(OPTIM) $(CFLAGS1) $(EXTRA_CFLAGS)
  #LIBS=$(EXTRA_LIBS) $(LIBS1)
  #INCLUDES=$(INCLUDES1) $(INCLUDES0) $(EXTRA_INCLUDES)
  #LDFLAGS=$(LDFLAGS1) $(EXTRA_LDFLAGS)
  
  RM=@RM@
  CC=@CC@
  RANLIB=@RANLIB@
  CFLAGS=@CFLAGS@ @OPTIM@
  LIBS=@LIBS@
  LDFLAGS=@LDFLAGS@ $(LIBS)
  INCDIR=../include
  INCLUDES=-I$(INCDIR) -I.
  
  #LIB=libfile.a
  
  OBJS=ap_buf.o \
  	ap_rwmem_buf.o \
  	ap_mmap_buf.o \
  
  .c.o:
  	$(CC) $(CFLAGS) -c $(INCLUDES) $<
  
  all: $(OBJS)
  
  clean:
  	$(RM) -f *.o *.a *.so
  
  distclean: clean
  	-$(RM) -f Makefile
  
  
  #$(LIB): $(OBJS)
  #	$(RM) -f $@
  #	$(AR) cr $@ $(OBJS)
  #	$(RANLIB) $@
  
  #
  # We really don't expect end users to use this rule.  It works only with
  # gcc, and rebuilds Makefile.in.  You have to re-run configure after
  # using it.
  #
  depend:
  	cp Makefile.in Makefile.in.bak \
  	    && sed -ne '1,/^# DO NOT REMOVE/p' Makefile.in > Makefile.new \
  	    && gcc -MM $(INCLUDES) $(CFLAGS) *.c >> Makefile.new \
  	    && sed -e '1,$$s: $(INCDIR)/: $$(INCDIR)/:g' \
  	           -e '1,$$s: $(OSDIR)/: $$(OSDIR)/:g' Makefile.new \
  		> Makefile.in \
  	    && rm Makefile.new
  
  # DO NOT REMOVE
  
  
  
  1.1                  apache-2.0/src/lib/apr/buckets/ap_buf.c
  
  Index: ap_buf.c
  ===================================================================
  /* ====================================================================
   * 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_lib.h"
  #include "apr_errno.h"
  #include <stdlib.h>
  #include <sys/uio.h>
  #include "apr_buf.h"
  
  /* We are creating a new bucket here.  We could replace the switch with a
   * function pointer if we want to.  I'm not sure it's a real win though.
   */
  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;
          case AP_BUCKET_mmap:
              newbuf->data = ap_mmap_bucket_create();
              newbuf->free = ap_mmap_bucket_destroy;
              break;
          case AP_BUCKET_rmem:
          case AP_BUCKET_file:
          case AP_BUCKET_filename:
          case AP_BUCKET_cached_entity:
          case AP_BUCKET_URI:
              /* not implemented yet */
              break;
      }
      return newbuf;
  }
  
  APR_EXPORT(ap_status_t) ap_bucket_destroy(ap_bucket *e)
  {
      e->free(e);
      free(e);
      return APR_SUCCESS;
  }
  
  APR_EXPORT(ap_status_t) ap_bucket_brigade_destroy(void *data)
  {
      ap_bucket_brigade *b = data;
      ap_bucket_list *bl = b->head;
  
      ap_destroy_bucket_list(bl);
  
      return APR_SUCCESS;
  }        
  
  APR_EXPORT(ap_bucket_brigade *) ap_bucket_brigade_create(ap_pool_t *p)
  {
      ap_bucket_brigade *b;
  
      b = malloc(sizeof(*b));
      b->p = p;
      b->head = b->tail = NULL;
  
      ap_register_cleanup(b->p, b, ap_bucket_brigade_destroy, 
                          ap_bucket_brigade_destroy);
      return b;
  }
  
  APR_EXPORT(ap_bucket_list *) ap_bucket_list_create(void)
  {
      ap_bucket_list *b;
      
      b = malloc(sizeof(*b));
      return b;
  }
  
  APR_EXPORT(void) ap_bucket_list_init(ap_bucket_list *b)
  {
      b->bucket = NULL;
      b->next = b->prev = NULL;
  }
  
  APR_EXPORT(void) ap_bucket_brigade_append(ap_bucket_brigade *b, 
                                            ap_bucket_list *e)
  {
      e->next = b->tail;
      b->tail->prev = e;
      /* This doesn't actually work */
      b->tail = e->next;
  }
  
  APR_EXPORT(int) ap_bucket_brigade_to_iovec(ap_bucket_brigade *b, 
                                             struct iovec *vec, int nvec)
  {
      ap_bucket_list *e;
      struct iovec *orig;
  
      orig = vec;
      e = b->head;
      while (e && nvec) {
  	vec->iov_base = ap_get_bucket_char_str(e->bucket);
  	vec->iov_len = ap_get_bucket_len(e->bucket);
  	e = e->next;
  	--nvec;
  	++vec;
      }
      return vec - orig;
  }
  
  APR_EXPORT(void) ap_bucket_brigade_catenate(ap_bucket_brigade *a, 
                                              ap_bucket_brigade *b)
  {
      if (b->head) {
          if (a->tail) {
              a->tail->next = b->head;
          }
  	a->tail = b->tail;
          if (!a->head) {
              a->head = b->head;
          }
  	b->head = NULL;
  	b->tail = b->head;
      }
  }
  
  APR_EXPORT(ap_status_t) ap_bucket_brigade_to_iol(ap_ssize_t *total_bytes,
                                                   ap_bucket_brigade *b, 
                                                   ap_iol *iol)
  {
      ap_status_t status;
      int iov_used;
      struct iovec vec[16];   /* seems like a reasonable number to me */
      ap_ssize_t bytes = 0;
  
      *total_bytes = 0;
      do {
          iov_used = ap_bucket_brigade_to_iovec(b, vec, 16);
          status = iol_writev(iol, vec, iov_used, &bytes);
          if (status != APR_SUCCESS) {
              return status;
          }
          *total_bytes += bytes;
      } while (iov_used == 16);
      return APR_SUCCESS;
  }
  
  APR_EXPORT(ap_status_t) ap_destroy_bucket_list(ap_bucket_list *buf)
  {
      ap_bucket_list *dptr = buf;
     
      while (dptr) {
          ap_bucket_destroy(dptr->bucket);
          dptr = dptr->next;
      }
      return APR_SUCCESS;
  }
  
  APR_EXPORT(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:
          case AP_BUCKET_file:
          case AP_BUCKET_filename:
          case AP_BUCKET_cached_entity:
          case AP_BUCKET_URI:
              /* not implemented yet */
              return NULL;
      }
      /* 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:
          case AP_BUCKET_file:
          case AP_BUCKET_filename:
          case AP_BUCKET_cached_entity:
          case AP_BUCKET_URI:
              /* not implemented yet */
              return 0;
      }
      /* We should NEVER actually get here */
      return 0;
  }    
  
  APR_EXPORT(int) ap_brigade_vputs(ap_bucket_brigade *b, ...)
  {
      ap_bucket_list *dptr = b->tail;
      ap_bucket_rwmem *r;
      va_list va;
      int n;
  
      if (dptr->bucket->color != AP_BUCKET_rwmem) {
          r = ap_rwmem_create();
      }
      else {
          r = dptr->bucket->data;
      }
      
      va_start(va, b);
      n = ap_rwmem_vputstrs(r, va);
      va_end(va);
  
      return n;
  }
  
  
  
  1.1                  apache-2.0/src/lib/apr/buckets/ap_mmap_buf.c
  
  Index: ap_mmap_buf.c
  ===================================================================
  /* ====================================================================
   * 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>
  
  APR_EXPORT(ap_bucket_mmap *) ap_mmap_bucket_create(void)
  {
      ap_bucket_mmap *newbuf;
      newbuf = malloc(sizeof(*newbuf));
      newbuf->data = NULL;
      return newbuf;
  }
  
  APR_EXPORT(void) ap_mmap_bucket_destroy(void *e)
  {
      ap_bucket_mmap *d = (ap_bucket_mmap *)e;
      free(d);
  }
  
  APR_EXPORT(char *) ap_mmap_get_char_str(ap_bucket_mmap *b)
  {
      return b->data->mm;
  }
  
  APR_EXPORT(int) ap_mmap_get_len(ap_bucket_mmap *b)
  {
      return b->data->size;
  }
  
  APR_EXPORT(void) ap_mmap_bucket_insert(ap_bucket_mmap *b, ap_mmap_t *mm)
  {
      b->data = mm;
  }
      
  
  
  
  1.1                  apache-2.0/src/lib/apr/buckets/ap_rwmem_buf.c
  
  Index: ap_rwmem_buf.c
  ===================================================================
  /* ====================================================================
   * 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>
  
  #ifndef DEFAULT_RWBUF_SIZE
  #define DEFAULT_RWBUF_SIZE (4096)
  #endif
  
  APR_EXPORT(ap_bucket_rwmem *) ap_rwmem_create(void)
  {
      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;
  }
  
  APR_EXPORT(void) ap_rwmem_destroy(void *e)
  {
      ap_bucket_rwmem *d = (ap_bucket_rwmem *)e;
      free(d->alloc_addr);
      free(d);
  }
  
  APR_EXPORT(char *) ap_rwmem_get_char_str(ap_bucket_rwmem *b)
  {
      return b->start;
  }
  
  APR_EXPORT(int) ap_rwmem_get_len(ap_bucket_rwmem *b)
  {
      return b->end - b->start;
  }
  
  /*
   * save nbyte bytes to the bucket.
   * Only returns fewer than nbyte if an error ocurred.
   * Returns -1 if no bytes were written before the error ocurred.
   * It is worth noting that if an error occurs, the buffer is in an unknown
   * state.
   */
  APR_EXPORT(int) ap_rwmem_write(ap_bucket_rwmem *b, const void *buf,
                                 ap_size_t nbyte, ap_ssize_t *bytes_written)
  {
      int amt;
      int total;
  
      if (nbyte == 0) {
          *bytes_written = 0;
          return APR_SUCCESS;
      }
  
  /*
   * At this point, we need to make sure we aren't trying to write too much
   * data to the bucket.  We will need to write to the dist here, but I am
   * leaving that for a later pass.  The basics are presented below, but this
   * is horribly broken.
   */
      amt = b->alloc_len - (b->end - b->start);
      total = 0;
      if (nbyte > amt) {
          /* loop through and write to the disk */
          /* Replace the rwmem buckets with file buckets */
      }
      /* now we know that nbyte < b->alloc_len */
      memcpy(b->end, buf, nbyte);
      b->end += nbyte;
      *bytes_written = total + nbyte;
      return APR_SUCCESS;
  }
  
  APR_EXPORT(int) ap_rwmem_vputstrs(ap_bucket_rwmem *b, va_list va)
  {
      int j, k;
      ap_ssize_t i;
      const char *x;
      int rv;
  
      for (k = 0;;) {
          x = va_arg(va, const char *);
          if (x == NULL)
              break;
          j = strlen(x);
          rv = ap_rwmem_write(b, x, j, &i);
          if (i != j) {
              /* Do we need better error reporting?  */
              return -1;
          }
          k += i;
      }
  
      return k;
  }
  
  
  
  1.1                  apache-2.0/src/lib/apr/include/apr_buf.h
  
  Index: apr_buf.h
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 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/>.
   */
  
  #ifndef AP_BUF_H
  #define AP_BUF_H
  
  #include "apr_mmap.h"
  #include "apr_errno.h"
  #include "../../../include/ap_iol.h"
  #include "apr_private.h"
  #ifdef HAVE_SYS_UIO_H
  #include <sys/uio.h>	/* for struct iovec */
  #endif
  #ifdef HAVE_STDARG_H
  #include <stdarg.h>
  #endif
  
  typedef enum {
      AP_BUCKET_rwmem,
      AP_BUCKET_rmem,
      AP_BUCKET_file,
      AP_BUCKET_mmap,
      AP_BUCKET_filename,
      AP_BUCKET_cached_entity,
      AP_BUCKET_URI,
  } ap_bucket_color_e;
  
  typedef struct ap_bucket ap_bucket;
  struct ap_bucket {
      ap_bucket_color_e color;            /* what type of bucket is it */
      void (*free)(void *e);              /* never NULL */
      void *data;				/* for use by free() */
  };
  
  typedef struct ap_bucket_list ap_bucket_list;
  struct ap_bucket_list {
      ap_bucket *bucket;                   /* The bucket */
      ap_bucket_list *next;                /* The start of the bucket list */
      ap_bucket_list *prev;                /* The end of the bucket list */
  };
  
  typedef struct ap_bucket_brigade ap_bucket_brigade;
  struct ap_bucket_brigade {
      ap_pool_t *p;                       /* The pool to associate this with.
                                             I do not allocate out of the pool,
                                             but this lets me register a cleanup
                                             to put a limit on the brigade's 
                                             lifetime. */
      ap_bucket_list *head;               /* The start of the brigade */
      ap_bucket_list *tail;               /* The end of the brigade */
  };
  
  /*   ******  Bucket Brigade Functions  *****  */
  
  /* Create a new bucket brigade */
  APR_EXPORT(ap_bucket_brigade *) ap_bucket_brigade_create(ap_pool_t *p);
  
  /* destroy an enitre bucket brigade */
  APR_EXPORT(ap_status_t) ap_bucket_brigade_destroy(void *b);
  
  /* append a bucket_brigade to a bucket_brigade */
  APR_EXPORT(void) ap_bucket_brigade_append(ap_bucket_brigade *b, 
                                            ap_bucket_list *e);
  
  /* consume nbytes from beginning of b -- call ap_bucket_destroy as
      appropriate, and/or modify start on last element */
  APR_EXPORT(void) ap_bucket_brigade_consume(ap_bucket_brigade *, int nbytes);
  
  /* create an iovec of the elements in a bucket_brigade... return number 
      of elements used */
  APR_EXPORT(int) ap_bucket_brigade_to_iovec(ap_bucket_brigade *, 
                                             struct iovec *vec, int nvec);
  
  /* catenate bucket_brigade b onto bucket_brigade a, bucket_brigade b is 
      empty after this */
  APR_EXPORT(void) ap_bucket_brigade_catenate(ap_bucket_brigade *a, 
                                              ap_bucket_brigade *b);
  
  /* save the buf out to the specified iol.  This can be used to flush the
      data to the disk, or to send it out to the network. */
  APR_EXPORT(ap_status_t) ap_bucket_brigade_to_iol(ap_ssize_t *total_bytes,
                                                   ap_bucket_brigade *a, 
                                                   ap_iol *iol);
  
  APR_EXPORT(int) ap_brigade_vputs(ap_bucket_brigade *b, ...);
  
  /*   ******  Bucket List Functions  *****  */
  
  /* create a new bucket_list */
  APR_EXPORT(ap_bucket_list *) ap_bucket_list_create(void);
  
  /* initialize a bucket_list */
  APR_EXPORT(void) ap_bucket_list_init(ap_bucket_list *b);
  
  /* destroy an entire bucket_list */
  APR_EXPORT(ap_status_t) ap_destroy_bucket_list(ap_bucket_list *b);
  
  /*   ******  Bucket Functions  *****  */
  
  /* allocate a bucket of type color */
  APR_EXPORT(ap_bucket *) ap_bucket_new(ap_bucket_color_e color);
  
  /* destroy a bucket */
  APR_EXPORT(ap_status_t) ap_bucket_destroy(ap_bucket *e);
  
  /* Convert a bucket to a char * */
  APR_EXPORT(char *) ap_get_bucket_char_str(ap_bucket *b);
  
  /* get the length of the data in the bucket */
  APR_EXPORT(int) ap_get_bucket_len(ap_bucket *b);
  
  /*   ******  RWMEM Functions  *****  */
  
  typedef struct ap_bucket_rwmem ap_bucket_rwmem;
  struct ap_bucket_rwmem {
      void    *alloc_addr;                /* Where does the data start */
      size_t  alloc_len;                  /* how much was allocated */
      void    *start;                     /* Where does the actual data start
                                             in the alloc'ed block */
      void    *end;                       /* where does the data actually end? */
  };
  
  /* 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(int) ap_rwmem_write(ap_bucket_rwmem *b, const void *buf,
                                 ap_size_t nbyte, ap_ssize_t *bytes_written);
  
  APR_EXPORT(int) ap_rwmem_vputs(ap_bucket_rwmem *b, va_list va);
  
  APR_EXPORT(int) ap_rwmem_vputstrs(ap_bucket_rwmem *b, va_list va);
  
  /*   ******  MMAP Functions  *****  */
  
  typedef struct ap_bucket_mmap ap_bucket_mmap;
  struct ap_bucket_mmap {
      ap_mmap_t *data;
  };
  
  /* Create a read/write memory bucket */
  APR_EXPORT(ap_bucket_mmap *) ap_mmap_bucket_create(void);
  
  /* destroy a read/write memory bucket */
  APR_EXPORT(void) ap_mmap_bucket_destroy(void *e);
  
  /* 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(void) ap_mmap_bucket_insert(ap_bucket_mmap *b, ap_mmap_t *mm);
  
  #endif
  
  
  
  

Mime
View raw message