buff.inc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. { Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. }
  16. {$ifdef B_SFIO}
  17. #include "sfio.h"
  18. {$endif}
  19. //#include <stdarg.h>
  20. const
  21. { Reading is buffered }
  22. B_RD = (1);
  23. { Writing is buffered }
  24. B_WR = (2);
  25. B_RDWR = (3);
  26. { At end of file, or closed stream; no further input allowed }
  27. B_EOF = (4);
  28. { No further output possible }
  29. B_EOUT = (8);
  30. { A read error has occurred }
  31. B_RDERR =(16);
  32. { A write error has occurred }
  33. B_WRERR =(32);
  34. //#ifdef B_ERROR { in SVR4: sometimes defined in /usr/include/sys/buf.h }
  35. //#undef B_ERROR
  36. //#endif
  37. B_ERROR =(48);
  38. { Use chunked writing }
  39. B_CHUNK =(64);
  40. { bflush() if a read would block }
  41. B_SAFEREAD =(128);
  42. { buffer is a socket }
  43. B_SOCKET =(256);
  44. {$ifdef CHARSET_EBCDIC}
  45. B_ASCII2EBCDIC = $40000000; { Enable conversion for this buffer }
  46. B_EBCDIC2ASCII = $80000000; { Enable conversion for this buffer }
  47. {$endif} {CHARSET_EBCDIC}
  48. type
  49. Pbuff_struct = ^buff_struct;
  50. PBUFF = Pbuff_struct;
  51. PPBUFF = ^PBUFF;
  52. error_t = procedure (fb: PBUFF; op: cint; data: Pointer);
  53. filter_callback_t = procedure (param1: PBUFF; const param2: Pointer; param3: cint);
  54. buff_struct = record
  55. flags: cint; { flags }
  56. inptr: PChar; { pointer to next location to read }
  57. incnt: cint; { number of bytes left to read from input buffer;
  58. * always 0 if had a read error }
  59. outchunk: cint; { location of chunk header when chunking }
  60. outcnt: cint; { number of byte put in output buffer }
  61. inbase: PChar;
  62. outbase: PChar;
  63. bufsiz: cint;
  64. error: error_t;
  65. error_data: PChar;
  66. bytes_sent: clong; { number of bytes actually written }
  67. pool: Pap_pool;
  68. { could also put pointers to the basic I/O routines here }
  69. fd: cint; { the file descriptor }
  70. fd_in: cint; { input file descriptor, if different }
  71. {$ifdef WINDOWS}
  72. hFH: HANDLE; { Windows filehandle }
  73. {$endif}
  74. { transport handle, for RPC binding handle or some such }
  75. t_handle: PChar;
  76. {$ifdef B_SFIO}
  77. sf_in: PSfio_t;
  78. sf_out: PSfio_t;
  79. {$endif}
  80. callback_data: Pointer;
  81. filter_callback: filter_callback_t;
  82. end;
  83. {$ifdef B_SFIO}
  84. apache_sfio = record
  85. disc: Sfdisc_t;
  86. buff: PBUFF;
  87. end;
  88. extern Sfdisc_t *bsfio_new(pool *p, BUFF *b);
  89. {$endif}
  90. { Options to bset/getopt }
  91. const
  92. BO_BYTECT = (1);
  93. { Stream creation and modification }
  94. function ap_bcreate(p: PPool; flags: cint): PBUFF;
  95. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  96. procedure ap_bpushfd(fb: PBUFF; fd_in, fd_out: cint);
  97. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  98. {$ifdef WINDOWS}
  99. procedure ap_bpushh(fb: PBUFF; hFH: HANDLE);
  100. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  101. {$endif}
  102. function ap_bsetopt(fb: PBUFF; optname: cint; const optval: Pointer): cint;
  103. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  104. function ap_bgetopt(fb: PBUFF; optname: cint; optval: Pointer): cint;
  105. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  106. function ap_bsetflag(fb: PBUFF; flag, value: cint): cint;
  107. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  108. function ap_bclose(fb: PBUFF): cint;
  109. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  110. //#define ap_bgetflag(fb, flag) ((fb)->flags & (flag))
  111. { Error handling }
  112. procedure ap_bonerror(fb: PBUFF; error: error_t; data: Pointer);
  113. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  114. { I/O }
  115. function ap_bread(fb: PBUFF; buf: Pointer; nbyte: cint): cint;
  116. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  117. {API_EXPORT(int) ap_bgets(char *s, int n, BUFF *fb);
  118. API_EXPORT(int) ap_blookc(char *buff, BUFF *fb);
  119. API_EXPORT(int) ap_bskiplf(BUFF *fb);
  120. API_EXPORT(int) ap_bwrite(BUFF *fb, const void *buf, int nbyte);
  121. API_EXPORT(int) ap_bflush(BUFF *fb);
  122. API_EXPORT(int) ap_bputs(const char *x, BUFF *fb);
  123. API_EXPORT_NONSTD(int) ap_bvputs(BUFF *fb,...);
  124. API_EXPORT_NONSTD(int) ap_bprintf(BUFF *fb, const char *fmt,...)
  125. __attribute__((format(printf,2,3)));
  126. API_EXPORT(int) ap_vbprintf(BUFF *fb, const char *fmt, va_list vlist);
  127. }
  128. { Internal routines }
  129. {API_EXPORT(int) ap_bflsbuf(int c, BUFF *fb);
  130. API_EXPORT(int) ap_bfilbuf(BUFF *fb);
  131. #ifndef CHARSET_EBCDIC
  132. #define ap_bgetc(fb) ( ((fb)->incnt == 0) ? ap_bfilbuf(fb) : \
  133. ((fb)->incnt--, *((fb)->inptr++)) )
  134. #define ap_bputc(c, fb) ((((fb)->flags & (B_EOUT|B_WRERR|B_WR)) != B_WR || \
  135. (fb)->outcnt == (fb)->bufsiz) ? ap_bflsbuf(c, (fb)) : \
  136. ((fb)->outbase[(fb)->outcnt++] = (c), 0))
  137. #else} {CHARSET_EBCDIC}
  138. {
  139. #define ap_bgetc(fb) ( ((fb)->incnt == 0) ? ap_bfilbuf(fb) : \
  140. ((fb)->incnt--, (fb->flags & B_ASCII2EBCDIC)\
  141. ?os_toebcdic[(unsigned char)*((fb)->inptr++)]:*((fb)->inptr++)) )
  142. #define ap_bputc(c, fb) ((((fb)->flags & (B_EOUT|B_WRERR|B_WR)) != B_WR || \
  143. (fb)->outcnt == (fb)->bufsiz) ? ap_bflsbuf(c, (fb)) : \
  144. ((fb)->outbase[(fb)->outcnt++] = (fb->flags & B_EBCDIC2ASCII)\
  145. ?os_toascii[(unsigned char)c]:(c), 0))
  146. #endif} {CHARSET_EBCDIC}
  147. type
  148. child_info = record
  149. {$ifdef WINDOWS}
  150. {
  151. * These handles are used by ap_call_exec to call
  152. * create process with pipe handles.
  153. }
  154. hPipeInputRead: HANDLE;
  155. hPipeOutputWrite: HANDLE;
  156. hPipeErrorWrite: HANDLE;
  157. {$else}
  158. {
  159. * We need to put a dummy member in here to avoid compilation
  160. * errors under certain Unix compilers, like SGI's and HPUX's,
  161. * which fail to compile a zero-sized struct. Of course
  162. * it would be much nicer if there was actually a use for this
  163. * structure under Unix. Aah the joys of x-platform code.
  164. }
  165. dummy: cint;
  166. {$endif}
  167. end;
  168. Pchild_info = ^child_info;
  169. func_t = function (param1: Pointer; param2: Pchild_info): cint;
  170. function ap_bspawn_child(p: PPool;
  171. func: func_t; data: Pointer; kill_how: kill_conditions; pipe_in, pipe_out, pipe_err: PPBUFF): cint;
  172. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  173. { enable non-blocking operations }
  174. function ap_bnonblock(fb: PBUFF; direction: cint): cint;
  175. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  176. { and get an fd to select() on }
  177. function ap_bfileno(fb: PBUFF; direction: cint): cint;
  178. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  179. { bflush() if a read now would block, but don't actually read anything }
  180. procedure ap_bhalfduplex(fb: PBUFF);
  181. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  182. {$if defined(WINDOWS) or defined(NETWARE) or defined(CYGWIN_WINSOCK)}
  183. { ap_recvwithtimeout/ap_sendwithtimeout socket primitives for WinSock }
  184. //API_EXPORT(int) ap_sendwithtimeout(int sock, const char *buf, int len, int flags);
  185. //API_EXPORT(int) ap_recvwithtimeout(int sock, char *buf, int len, int flags);
  186. {$endif}