1 /* ====================================================================
2 * Copyright (c) 1996-1998 The Apache Group. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
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
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/)."
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
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.
30 * 6. Redistributions of any form whatsoever must retain the following
32 * "This product includes software developed by the Apache Group
33 * for use in the Apache HTTP server project (http://www.apache.org/)."
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 * ====================================================================
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/>.
71 /* Reading is buffered */
73 /* Writing is buffered */
76 /* At end of file, or closed stream; no further input allowed */
78 /* No further output possible */
80 /* A read error has occurred */
82 /* A write error has occurred */
84 #ifdef B_ERROR /* in SVR4: sometimes defined in /usr/include/sys/buf.h */
88 /* Use chunked writing */
90 /* bflush() if a read would block */
91 #define B_SAFEREAD (128)
92 /* buffer is a socket */
93 #define B_SOCKET (256)
95 #define B_ASCII2EBCDIC 0x40000000 /* Enable conversion for this buffer */
96 #define B_EBCDIC2ASCII 0x80000000 /* Enable conversion for this buffer */
97 #endif /*CHARSET_EBCDIC */
99 typedef struct buff_struct BUFF
;
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
;
111 void (*error
) (BUFF
* fb
, int op
, void *data
);
113 long int bytes_sent
; /* number of bytes actually written */
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 */
121 HANDLE hFH
; /* Windows filehandle */
124 /* transport handle, for RPC binding handle or some such */
139 extern Sfdisc_t
*bsfio_new(pool
* p
, BUFF
* b
);
142 /* Options to bset/getopt */
143 #define BO_BYTECT (1)
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
);
149 API_EXPORT(void) ap_bpushh(BUFF
* fb
, HANDLE hFH
);
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
);
156 #define ap_bgetflag(fb, flag) ((fb)->flags & (flag))
159 API_EXPORT(void) ap_bonerror(BUFF
* fb
,
160 void (*error
) (BUFF
*, int, void *),
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
);
176 /* Internal routines */
177 API_EXPORT(int) ap_bflsbuf(int c
, BUFF
* fb
);
178 API_EXPORT(int) ap_bfilbuf(BUFF
* fb
);
180 #ifndef CHARSET_EBCDIC
182 #define ap_bgetc(fb) ( ((fb)->incnt == 0) ? ap_bfilbuf(fb) : \
183 ((fb)->incnt--, *((fb)->inptr++)) )
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))
189 #else /*CHARSET_EBCDIC */
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++)) )
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))
200 #endif /*CHARSET_EBCDIC */
204 * These handles are used by ap_call_exec to call
205 * create process with pipe handles.
207 HANDLE hPipeInputRead
;
208 HANDLE hPipeOutputWrite
;
209 HANDLE hPipeErrorWrite
;
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.
221 API_EXPORT(int) ap_bspawn_child(pool
*, int (*)(void *, child_info
*),
222 void *, enum kill_conditions
,
223 BUFF
** pipe_in
, BUFF
** pipe_out
,
226 /* enable non-blocking operations */
227 API_EXPORT(int) ap_bnonblock(BUFF
* fb
, int direction
);
228 /* and get an fd to select() on */
229 API_EXPORT(int) ap_bfileno(BUFF
* fb
, int direction
);
231 /* bflush() if a read now would block, but don't actually read anything */
232 API_EXPORT(void) ap_bhalfduplex(BUFF
* fb
);
237 #endif /* !APACHE_BUFF_H */