home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Web / Servers / apache-1.2.4-MIHS / original-source / src / buff.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-10  |  5.3 KB  |  138 lines

  1. /* ====================================================================
  2.  * Copyright (c) 1996,1997 The Apache Group.  All rights reserved.
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  *
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer. 
  10.  *
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in
  13.  *    the documentation and/or other materials provided with the
  14.  *    distribution.
  15.  *
  16.  * 3. All advertising materials mentioning features or use of this
  17.  *    software must display the following acknowledgment:
  18.  *    "This product includes software developed by the Apache Group
  19.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  20.  *
  21.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  22.  *    endorse or promote products derived from this software without
  23.  *    prior written permission.
  24.  *
  25.  * 5. Redistributions of any form whatsoever must retain the following
  26.  *    acknowledgment:
  27.  *    "This product includes software developed by the Apache Group
  28.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  29.  *
  30.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  31.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  33.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  34.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  41.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  42.  * ====================================================================
  43.  *
  44.  * This software consists of voluntary contributions made by many
  45.  * individuals on behalf of the Apache Group and was originally based
  46.  * on public domain software written at the National Center for
  47.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  48.  * For more information on the Apache Group and the Apache HTTP server
  49.  * project, please see <http://www.apache.org/>.
  50.  *
  51.  */
  52.  
  53. #include <stdarg.h>
  54.  
  55. /* Reading is buffered */
  56. #define B_RD     (1)
  57. /* Writing is buffered */
  58. #define B_WR     (2)
  59. #define B_RDWR   (3)
  60. /* At end of file, or closed stream; no further input allowed */
  61. #define B_EOF    (4)
  62. /* No further output possible */
  63. #define B_EOUT   (8)
  64. /* A read error has occurred */
  65. #define B_RDERR (16)
  66. /* A write error has occurred */
  67. #define B_WRERR (32)
  68. #define B_ERROR (48)
  69. /* Use chunked writing */
  70. #define B_CHUNK (64)
  71. /* bflush() if a read would block */
  72. #define B_SAFEREAD (128)
  73.  
  74. typedef struct buff_struct BUFF;
  75.  
  76. struct buff_struct
  77. {
  78.     int flags;             /* flags */
  79.     unsigned char *inptr;  /* pointer to next location to read */
  80.     int incnt;             /* number of bytes left to read from input buffer;
  81.                 * always 0 if had a read error  */
  82.     int outchunk;       /* location of chunk header when chunking */
  83.     int outchunk_header_size; /* how long the header is */
  84.     int outcnt;            /* number of byte put in output buffer */
  85.     unsigned char *inbase;
  86.     unsigned char *outbase;
  87.     int bufsiz;
  88.     void (*error)(BUFF *fb, int op, void *data);
  89.     void *error_data;
  90.     long int bytes_sent;   /* number of bytes actually written */
  91.  
  92.     pool *pool;
  93.  
  94. /* could also put pointers to the basic I/O routines here */
  95.     int fd;                /* the file descriptor */
  96.     int fd_in;             /* input file descriptor, if different */
  97. };
  98.  
  99. /* Options to bset/getopt */
  100. #define BO_BYTECT (1)
  101.  
  102. /* Stream creation and modification */
  103. extern BUFF *bcreate(pool *p, int flags);
  104. extern void bpushfd(BUFF *fb, int fd_in, int fd_out);
  105. extern int bsetopt(BUFF *fb, int optname, const void *optval);
  106. extern int bgetopt(BUFF *fb, int optname, void *optval);
  107. extern int bsetflag(BUFF *fb, int flag, int value);
  108. extern int bclose(BUFF *fb);
  109.  
  110. #define bgetflag(fb, flag)    ((fb)->flags & (flag))
  111.  
  112. /* Error handling */
  113. extern void bonerror(BUFF *fb, void (*error)(BUFF *, int, void *),
  114.              void *data);
  115.  
  116. /* I/O */
  117. extern int bread(BUFF *fb, void *buf, int nbyte);
  118. extern int bgets(char *s, int n, BUFF *fb);
  119. extern int blookc(char *buff, BUFF *fb);
  120. extern int bskiplf(BUFF *fb);
  121. extern int bwrite(BUFF *fb, const void *buf, int nbyte);
  122. extern int bflush(BUFF *fb);
  123. extern int bputs(const char *x, BUFF *fb);
  124. extern int bvputs(BUFF *fb, ...);
  125. extern int bprintf(BUFF *fb,const char *fmt,...);
  126. extern int vbprintf(BUFF *fb,const char *fmt,va_list vlist);
  127.  
  128. /* Internal routines */
  129. extern int bflsbuf(int c, BUFF *fb);
  130. extern int bfilbuf(BUFF *fb);
  131.  
  132. #define bgetc(fb)   ( ((fb)->incnt == 0) ? bfilbuf(fb) : \
  133.             ((fb)->incnt--, *((fb)->inptr++)) )
  134.  
  135. #define bputc(c, fb) ((((fb)->flags & (B_EOUT|B_WRERR|B_WR)) != B_WR || \
  136.              (fb)->outcnt == (fb)->bufsiz) ? bflsbuf(c, (fb)) : \
  137.              ((fb)->outbase[(fb)->outcnt++] = (c), 0))
  138.