/packages/httpd22/src/apr/apr_lib.inc

https://github.com/slibre/freepascal · Pascal · 223 lines · 22 code · 15 blank · 186 comment · 0 complexity · ae0884b95e7add85eee7e3e944ae13b5 MD5 · raw file

  1. { Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * 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. {
  17. * @file apr_lib.h
  18. * This is collection of oddballs that didn't fit anywhere else,
  19. * and might move to more appropriate headers with the release
  20. * of APR 1.0.
  21. * @brief APR general purpose library routines
  22. }
  23. {#include "apr.h"
  24. #include "apr_errno.h"
  25. #if APR_HAVE_CTYPE_H
  26. #include <ctype.h>
  27. #endif
  28. #if APR_HAVE_STDARG_H
  29. #include <stdarg.h>
  30. #endif}
  31. {
  32. * @defgroup apr_lib General Purpose Library Routines
  33. * @ingroup APR
  34. * This is collection of oddballs that didn't fit anywhere else,
  35. * and might move to more appropriate headers with the release
  36. * of APR 1.0.
  37. }
  38. { A constant representing a 'large' string. }
  39. const HUGE_STRING_LEN = 8192;
  40. {
  41. * Define the structures used by the APR general-purpose library.
  42. }
  43. { @see apr_vformatter_buff_t }
  44. type
  45. Papr_vformatter_buff_t = ^apr_vformatter_buff_t;
  46. {
  47. * Structure used by the variable-formatter routines.
  48. }
  49. apr_vformatter_buff_t = record
  50. { The current position }
  51. curpos: PChar;
  52. { The end position of the format string }
  53. endpos: PChar;
  54. end;
  55. {
  56. * return the final element of the pathname
  57. * @param pathname The path to get the final element of
  58. * @return the final element of the path
  59. * @remark
  60. * <PRE>
  61. * For example:
  62. * "/foo/bar/gum" -> "gum"
  63. * "/foo/bar/gum/" -> ""
  64. * "gum" -> "gum"
  65. * "bs\\path\\stuff" -> "stuff"
  66. * </PRE>
  67. }
  68. function apr_filepath_name_get(const pathname: PChar): PChar;
  69. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  70. external LibAPR name LibNamePrefix + 'apr_filepath_name_get' + LibSuff4;
  71. {
  72. * apr_killpg
  73. * Small utility macros to make things easier to read. Not usually a
  74. * goal, to be sure..
  75. }
  76. //#ifdef WIN32
  77. //#define apr_killpg(x, y)
  78. //#else { WIN32 }
  79. //#ifdef NO_KILLPG
  80. //#define apr_killpg(x, y) (kill (-(x), (y)))
  81. //#else { NO_KILLPG }
  82. //#define apr_killpg(x, y) (killpg ((x), (y)))
  83. //#endif { NO_KILLPG }
  84. //#endif { WIN32 }
  85. {
  86. * apr_vformatter() is a generic printf-style formatting routine
  87. * with some extensions.
  88. * @param flush_func The function to call when the buffer is full
  89. * @param c The buffer to write to
  90. * @param fmt The format string
  91. * @param ap The arguments to use to fill out the format string.
  92. *
  93. * @remark
  94. * <PRE>
  95. * The extensions are:
  96. *
  97. * %%pA takes a struct in_addr *, and prints it as a.b.c.d
  98. * %%pI takes an apr_sockaddr_t * and prints it as a.b.c.d:port or
  99. * [ipv6-address]:port
  100. * %%pT takes an apr_os_thread_t * and prints it in decimal
  101. * ('0' is printed if !APR_HAS_THREADS)
  102. * %%pt takes an apr_os_thread_t * and prints it in hexadecimal
  103. * ('0' is printed if !APR_HAS_THREADS)
  104. * %%pp takes a void * and outputs it in hex
  105. *
  106. * The %%p hacks are to force gcc's printf warning code to skip
  107. * over a pointer argument without complaining. This does
  108. * mean that the ANSI-style %%p (output a void * in hex format) won't
  109. * work as expected at all, but that seems to be a fair trade-off
  110. * for the increased robustness of having printf-warnings work.
  111. *
  112. * Additionally, apr_vformatter allows for arbitrary output methods
  113. * using the apr_vformatter_buff and flush_func.
  114. *
  115. * The apr_vformatter_buff has two elements curpos and endpos.
  116. * curpos is where apr_vformatter will write the next byte of output.
  117. * It proceeds writing output to curpos, and updating curpos, until
  118. * either the end of output is reached, or curpos == endpos (i.e. the
  119. * buffer is full).
  120. *
  121. * If the end of output is reached, apr_vformatter returns the
  122. * number of bytes written.
  123. *
  124. * When the buffer is full, the flush_func is called. The flush_func
  125. * can return -1 to indicate that no further output should be attempted,
  126. * and apr_vformatter will return immediately with -1. Otherwise
  127. * the flush_func should flush the buffer in whatever manner is
  128. * appropriate, re apr_pool_t nitialize curpos and endpos, and return 0.
  129. *
  130. * Note that flush_func is only invoked as a result of attempting to
  131. * write another byte at curpos when curpos >= endpos. So for
  132. * example, it's possible when the output exactly matches the buffer
  133. * space available that curpos == endpos will be true when
  134. * apr_vformatter returns.
  135. *
  136. * apr_vformatter does not call out to any other code, it is entirely
  137. * self-contained. This allows the callers to do things which are
  138. * otherwise "unsafe". For example, apr_psprintf uses the "scratch"
  139. * space at the unallocated end of a block, and doesn't actually
  140. * complete the allocation until apr_vformatter returns. apr_psprintf
  141. * would be completely broken if apr_vformatter were to call anything
  142. * that used this same pool. Similarly http_bprintf() uses the "scratch"
  143. * space at the end of its output buffer, and doesn't actually note
  144. * that the space is in use until it either has to flush the buffer
  145. * or until apr_vformatter returns.
  146. * </PRE>
  147. }
  148. type
  149. flush_func_t = function (b: Papr_vformatter_buff_t): Integer;
  150. function apr_vformatter(flush_func: flush_func_t;
  151. c: Papr_vformatter_buff_t; const fmt: PChar; ap: va_list): Integer;
  152. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  153. external LibAPR name LibNamePrefix + 'apr_vformatter' + LibSuff16;
  154. {
  155. * Display a prompt and read in the password from stdin.
  156. * @param prompt The prompt to display
  157. * @param pwbuf Buffer to store the password
  158. * @param bufsize The length of the password buffer.
  159. * @remark If the password entered must be truncated to fit in
  160. * the provided buffer, APR_ENAMETOOLONG will be returned.
  161. * Note that the bufsize paramater is passed by reference for no
  162. * reason; its value will never be modified by the apr_password_get()
  163. * function.
  164. }
  165. function apr_password_get(const prompt: PChar;
  166. pwbuf: PChar; bufsize: Papr_size_t): apr_status_t;
  167. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  168. external LibAPR name LibNamePrefix + 'apr_password_get' + LibSuff12;
  169. {
  170. * @defgroup apr_ctype ctype functions
  171. * These macros allow correct support of 8-bit characters on systems which
  172. * support 8-bit characters. Pretty dumb how the cast is required, but
  173. * that's legacy libc for ya. These new macros do not support EOF like
  174. * the standard macros do. Tough.
  175. }
  176. { @see isalnum }
  177. //#define apr_isalnum(c) (isalnum(((unsigned char)(c))))
  178. { @see isalpha }
  179. //#define apr_isalpha(c) (isalpha(((unsigned char)(c))))
  180. { @see iscntrl }
  181. //#define apr_iscntrl(c) (iscntrl(((unsigned char)(c))))
  182. { @see isdigit }
  183. //#define apr_isdigit(c) (isdigit(((unsigned char)(c))))
  184. { @see isgraph }
  185. //#define apr_isgraph(c) (isgraph(((unsigned char)(c))))
  186. { @see islower}
  187. //#define apr_islower(c) (islower(((unsigned char)(c))))
  188. { @see isascii }
  189. {#ifdef isascii
  190. #define apr_isascii(c) (isascii(((unsigned char)(c))))
  191. #else
  192. #define apr_isascii(c) (((c) & ~0x7f)==0)
  193. #endif}
  194. { @see isprint }
  195. //#define apr_isprint(c) (isprint(((unsigned char)(c))))
  196. { @see ispunct }
  197. //#define apr_ispunct(c) (ispunct(((unsigned char)(c))))
  198. { @see isspace }
  199. //#define apr_isspace(c) (isspace(((unsigned char)(c))))
  200. { @see isupper }
  201. //#define apr_isupper(c) (isupper(((unsigned char)(c))))
  202. { @see isxdigit }
  203. //#define apr_isxdigit(c) (isxdigit(((unsigned char)(c))))
  204. { @see tolower }
  205. function apr_tolower(c: Char): Char;
  206. { @see toupper }
  207. function apr_toupper(c: Char): Char;