home *** CD-ROM | disk | FTP | other *** search
/ PC World Plus! (NZ) 2001 October / PCW1001.iso / Linux / apache / apache_1.3.20-win32-no_src-r2.msi / Data.Cab / F160728_buff.h < prev    next >
C/C++ Source or Header  |  2001-05-15  |  8KB  |  238 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  *
  54.  * Portions of this software are based upon public domain software
  55.  * originally written at the National Center for Supercomputing Applications,
  56.  * University of Illinois, Urbana-Champaign.
  57.  */
  58.  
  59. #ifndef APACHE_BUFF_H
  60. #define APACHE_BUFF_H
  61.  
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65.  
  66. #ifdef B_SFIO
  67. #include "sfio.h"
  68. #endif
  69.  
  70. #include <stdarg.h>
  71.  
  72. /* Reading is buffered */
  73. #define B_RD     (1)
  74. /* Writing is buffered */
  75. #define B_WR     (2)
  76. #define B_RDWR   (3)
  77. /* At end of file, or closed stream; no further input allowed */
  78. #define B_EOF    (4)
  79. /* No further output possible */
  80. #define B_EOUT   (8)
  81. /* A read error has occurred */
  82. #define B_RDERR (16)
  83. /* A write error has occurred */
  84. #define B_WRERR (32)
  85. #ifdef B_ERROR  /* in SVR4: sometimes defined in /usr/include/sys/buf.h */
  86. #undef B_ERROR
  87. #endif
  88. #define B_ERROR (48)
  89. /* Use chunked writing */
  90. #define B_CHUNK (64)
  91. /* bflush() if a read would block */
  92. #define B_SAFEREAD (128)
  93. /* buffer is a socket */
  94. #define B_SOCKET (256)
  95. #ifdef CHARSET_EBCDIC
  96. #define B_ASCII2EBCDIC 0x40000000  /* Enable conversion for this buffer */
  97. #define B_EBCDIC2ASCII 0x80000000  /* Enable conversion for this buffer */
  98. #endif /*CHARSET_EBCDIC*/
  99.  
  100. typedef struct buff_struct BUFF;
  101.  
  102. struct buff_struct {
  103.     int flags;            /* flags */
  104.     unsigned char *inptr;    /* pointer to next location to read */
  105.     int incnt;            /* number of bytes left to read from input buffer;
  106.                  * always 0 if had a read error  */
  107.     int outchunk;        /* location of chunk header when chunking */
  108.     int outcnt;            /* number of byte put in output buffer */
  109.     unsigned char *inbase;
  110.     unsigned char *outbase;
  111.     int bufsiz;
  112.     void (*error) (BUFF *fb, int op, void *data);
  113.     void *error_data;
  114.     long int bytes_sent;    /* number of bytes actually written */
  115.  
  116.     ap_pool *pool;
  117.  
  118. /* could also put pointers to the basic I/O routines here */
  119.     int fd;            /* the file descriptor */
  120.     int fd_in;            /* input file descriptor, if different */
  121. #ifdef WIN32
  122.     HANDLE hFH;            /* Windows filehandle */
  123. #endif
  124.  
  125.     /* transport handle, for RPC binding handle or some such */
  126.     void *t_handle;
  127.  
  128. #ifdef B_SFIO
  129.     Sfio_t *sf_in;
  130.     Sfio_t *sf_out;
  131. #endif
  132. };
  133.  
  134. #ifdef B_SFIO
  135. typedef struct {
  136.     Sfdisc_t disc;
  137.     BUFF *buff;
  138. } apache_sfio;
  139.  
  140. extern Sfdisc_t *bsfio_new(pool *p, BUFF *b);
  141. #endif
  142.  
  143. /* Options to bset/getopt */
  144. #define BO_BYTECT (1)
  145.  
  146. /* Stream creation and modification */
  147. API_EXPORT(BUFF *) ap_bcreate(pool *p, int flags);
  148. API_EXPORT(void) ap_bpushfd(BUFF *fb, int fd_in, int fd_out);
  149. #ifdef WIN32
  150. API_EXPORT(void) ap_bpushh(BUFF *fb, HANDLE hFH);
  151. #endif
  152. API_EXPORT(int) ap_bsetopt(BUFF *fb, int optname, const void *optval);
  153. API_EXPORT(int) ap_bgetopt(BUFF *fb, int optname, void *optval);
  154. API_EXPORT(int) ap_bsetflag(BUFF *fb, int flag, int value);
  155. API_EXPORT(int) ap_bclose(BUFF *fb);
  156.  
  157. #define ap_bgetflag(fb, flag)    ((fb)->flags & (flag))
  158.  
  159. /* Error handling */
  160. API_EXPORT(void) ap_bonerror(BUFF *fb, void (*error) (BUFF *, int, void *),
  161.               void *data);
  162.  
  163. /* I/O */
  164. API_EXPORT(int) ap_bread(BUFF *fb, void *buf, int nbyte);
  165. API_EXPORT(int) ap_bgets(char *s, int n, BUFF *fb);
  166. API_EXPORT(int) ap_blookc(char *buff, BUFF *fb);
  167. API_EXPORT(int) ap_bskiplf(BUFF *fb);
  168. API_EXPORT(int) ap_bwrite(BUFF *fb, const void *buf, int nbyte);
  169. API_EXPORT(int) ap_bflush(BUFF *fb);
  170. API_EXPORT(int) ap_bputs(const char *x, BUFF *fb);
  171. API_EXPORT(int) ap_bvputs(BUFF *fb,...);
  172. API_EXPORT_NONSTD(int) ap_bprintf(BUFF *fb, const char *fmt,...)
  173.                 __attribute__((format(printf,2,3)));
  174. API_EXPORT(int) ap_vbprintf(BUFF *fb, const char *fmt, va_list vlist);
  175.  
  176. /* Internal routines */
  177. API_EXPORT(int) ap_bflsbuf(int c, BUFF *fb);
  178. API_EXPORT(int) ap_bfilbuf(BUFF *fb);
  179.  
  180. #ifndef CHARSET_EBCDIC
  181.  
  182. #define ap_bgetc(fb)   ( ((fb)->incnt == 0) ? ap_bfilbuf(fb) : \
  183.             ((fb)->incnt--, *((fb)->inptr++)) )
  184.  
  185. #define ap_bputc(c, fb) ((((fb)->flags & (B_EOUT|B_WRERR|B_WR)) != B_WR || \
  186.              (fb)->outcnt == (fb)->bufsiz) ? ap_bflsbuf(c, (fb)) : \
  187.              ((fb)->outbase[(fb)->outcnt++] = (c), 0))
  188.  
  189. #else /*CHARSET_EBCDIC*/
  190.  
  191. #define ap_bgetc(fb)   ( ((fb)->incnt == 0) ? ap_bfilbuf(fb) : \
  192.             ((fb)->incnt--, (fb->flags & B_ASCII2EBCDIC)\
  193.             ?os_toebcdic[(unsigned char)*((fb)->inptr++)]:*((fb)->inptr++)) )
  194.  
  195. #define ap_bputc(c, fb) ((((fb)->flags & (B_EOUT|B_WRERR|B_WR)) != B_WR || \
  196.              (fb)->outcnt == (fb)->bufsiz) ? ap_bflsbuf(c, (fb)) : \
  197.              ((fb)->outbase[(fb)->outcnt++] = (fb->flags & B_EBCDIC2ASCII)\
  198.              ?os_toascii[(unsigned char)c]:(c), 0))
  199.  
  200. #endif /*CHARSET_EBCDIC*/
  201. struct child_info {
  202. #ifdef WIN32
  203.     /*
  204.      *  These handles are used by ap_call_exec to call 
  205.      *  create process with pipe handles.
  206.      */
  207.     HANDLE hPipeInputRead;
  208.     HANDLE hPipeOutputWrite;
  209.     HANDLE hPipeErrorWrite;
  210. #else
  211.     /* 
  212.      * We need to put a dummy member in here to avoid compilation
  213.      * errors under certain Unix compilers, like SGI's and HPUX's,
  214.      * which fail to compile a zero-sized struct.  Of course
  215.      * it would be much nicer if there was actually a use for this
  216.      * structure under Unix.  Aah the joys of x-platform code.
  217.      */
  218.     int dummy;
  219. #endif
  220. };
  221. API_EXPORT(int) ap_bspawn_child(pool *, int (*)(void *, child_info *), void *,
  222.                     enum kill_conditions, BUFF **pipe_in, BUFF **pipe_out,
  223.                     BUFF **pipe_err);
  224.  
  225. /* enable non-blocking operations */
  226. API_EXPORT(int) ap_bnonblock(BUFF *fb, int direction);
  227. /* and get an fd to select() on */
  228. API_EXPORT(int) ap_bfileno(BUFF *fb, int direction);
  229.  
  230. /* bflush() if a read now would block, but don't actually read anything */
  231. API_EXPORT(void) ap_bhalfduplex(BUFF *fb);
  232.  
  233. #ifdef __cplusplus
  234. }
  235. #endif
  236.  
  237. #endif    /* !APACHE_BUFF_H */
  238.