apr_lib.h 8.5 KB

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