Annotation of win32/apache13/src/include/buff.h, revision 1.1.1.1

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

E-mail: