00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef APR_LIB_H 00018 #define APR_LIB_H 00019 00020 /** 00021 * @file apr_lib.h 00022 * This is collection of oddballs that didn't fit anywhere else, 00023 * and might move to more appropriate headers with the release 00024 * of APR 1.0. 00025 * @brief APR general purpose library routines 00026 */ 00027 00028 #include "apr.h" 00029 #include "apr_errno.h" 00030 00031 #if APR_HAVE_CTYPE_H 00032 #include <ctype.h> 00033 #endif 00034 #if APR_HAVE_STDARG_H 00035 #include <stdarg.h> 00036 #endif 00037 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif /* __cplusplus */ 00041 00042 /** 00043 * @defgroup apr_lib General Purpose Library Routines 00044 * @ingroup APR 00045 * This is collection of oddballs that didn't fit anywhere else, 00046 * and might move to more appropriate headers with the release 00047 * of APR 1.0. 00048 * @{ 00049 */ 00050 00051 /** A constant representing a 'large' string. */ 00052 #define HUGE_STRING_LEN 8192 00053 00054 /* 00055 * Define the structures used by the APR general-purpose library. 00056 */ 00057 00058 /** @see apr_vformatter_buff_t */ 00059 typedef struct apr_vformatter_buff_t apr_vformatter_buff_t; 00060 00061 /** 00062 * Structure used by the variable-formatter routines. 00063 */ 00064 struct apr_vformatter_buff_t { 00065 /** The current position */ 00066 char *curpos; 00067 /** The end position of the format string */ 00068 char *endpos; 00069 }; 00070 00071 /** 00072 * return the final element of the pathname 00073 * @param pathname The path to get the final element of 00074 * @return the final element of the path 00075 * @remark 00076 * <PRE> 00077 * For example: 00078 * "/foo/bar/gum" -> "gum" 00079 * "/foo/bar/gum/" -> "" 00080 * "gum" -> "gum" 00081 * "bs\\path\\stuff" -> "stuff" 00082 * </PRE> 00083 */ 00084 APR_DECLARE(const char *) apr_filepath_name_get(const char *pathname); 00085 00086 /** 00087 * apr_killpg 00088 * Small utility macros to make things easier to read. Not usually a 00089 * goal, to be sure.. 00090 */ 00091 00092 #ifdef WIN32 00093 #define apr_killpg(x, y) 00094 #else /* WIN32 */ 00095 #ifdef NO_KILLPG 00096 #define apr_killpg(x, y) (kill (-(x), (y))) 00097 #else /* NO_KILLPG */ 00098 #define apr_killpg(x, y) (killpg ((x), (y))) 00099 #endif /* NO_KILLPG */ 00100 #endif /* WIN32 */ 00101 00102 /** 00103 * apr_vformatter() is a generic printf-style formatting routine 00104 * with some extensions. 00105 * @param flush_func The function to call when the buffer is full 00106 * @param c The buffer to write to 00107 * @param fmt The format string 00108 * @param ap The arguments to use to fill out the format string. 00109 * 00110 * @remark 00111 * <PRE> 00112 * The extensions are: 00113 * 00114 * %%pA takes a struct in_addr *, and prints it as a.b.c.d 00115 * %%pI takes an apr_sockaddr_t * and prints it as a.b.c.d:port or 00116 * [ipv6-address]:port 00117 * %%pT takes an apr_os_thread_t * and prints it in decimal 00118 * ('0' is printed if !APR_HAS_THREADS) 00119 * %%pt takes an apr_os_thread_t * and prints it in hexadecimal 00120 * ('0' is printed if !APR_HAS_THREADS) 00121 * %%pm takes an apr_status_t * and prints the appropriate error 00122 * string (from apr_strerror) corresponding to that error code. 00123 * %%pp takes a void * and outputs it in hex 00124 * %%pB takes a apr_uint32_t * as bytes and outputs it's apr_strfsize 00125 * %%pF same as above, but takes a apr_off_t * 00126 * %%pS same as above, but takes a apr_size_t * 00127 * 00128 * %%pt is only available from APR 1.2.0 onwards. 00129 * %%pm, %%pB, %%pF and %%pS are only available from APR 1.3.0 onwards. 00130 * 00131 * The %%p hacks are to force gcc's printf warning code to skip 00132 * over a pointer argument without complaining. This does 00133 * mean that the ANSI-style %%p (output a void * in hex format) won't 00134 * work as expected at all, but that seems to be a fair trade-off 00135 * for the increased robustness of having printf-warnings work. 00136 * 00137 * Additionally, apr_vformatter allows for arbitrary output methods 00138 * using the apr_vformatter_buff and flush_func. 00139 * 00140 * The apr_vformatter_buff has two elements curpos and endpos. 00141 * curpos is where apr_vformatter will write the next byte of output. 00142 * It proceeds writing output to curpos, and updating curpos, until 00143 * either the end of output is reached, or curpos == endpos (i.e. the 00144 * buffer is full). 00145 * 00146 * If the end of output is reached, apr_vformatter returns the 00147 * number of bytes written. 00148 * 00149 * When the buffer is full, the flush_func is called. The flush_func 00150 * can return -1 to indicate that no further output should be attempted, 00151 * and apr_vformatter will return immediately with -1. Otherwise 00152 * the flush_func should flush the buffer in whatever manner is 00153 * appropriate, re apr_pool_t nitialize curpos and endpos, and return 0. 00154 * 00155 * Note that flush_func is only invoked as a result of attempting to 00156 * write another byte at curpos when curpos >= endpos. So for 00157 * example, it's possible when the output exactly matches the buffer 00158 * space available that curpos == endpos will be true when 00159 * apr_vformatter returns. 00160 * 00161 * apr_vformatter does not call out to any other code, it is entirely 00162 * self-contained. This allows the callers to do things which are 00163 * otherwise "unsafe". For example, apr_psprintf uses the "scratch" 00164 * space at the unallocated end of a block, and doesn't actually 00165 * complete the allocation until apr_vformatter returns. apr_psprintf 00166 * would be completely broken if apr_vformatter were to call anything 00167 * that used this same pool. Similarly http_bprintf() uses the "scratch" 00168 * space at the end of its output buffer, and doesn't actually note 00169 * that the space is in use until it either has to flush the buffer 00170 * or until apr_vformatter returns. 00171 * </PRE> 00172 */ 00173 APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *b), 00174 apr_vformatter_buff_t *c, const char *fmt, 00175 va_list ap); 00176 00177 /** 00178 * Display a prompt and read in the password from stdin. 00179 * @param prompt The prompt to display 00180 * @param pwbuf Buffer to store the password 00181 * @param bufsize The length of the password buffer. 00182 * @remark If the password entered must be truncated to fit in 00183 * the provided buffer, APR_ENAMETOOLONG will be returned. 00184 * Note that the bufsize paramater is passed by reference for no 00185 * reason; its value will never be modified by the apr_password_get() 00186 * function. 00187 */ 00188 APR_DECLARE(apr_status_t) apr_password_get(const char *prompt, char *pwbuf, 00189 apr_size_t *bufsize); 00190 00191 /** @} */ 00192 00193 /** 00194 * @defgroup apr_ctype ctype functions 00195 * These macros allow correct support of 8-bit characters on systems which 00196 * support 8-bit characters. Pretty dumb how the cast is required, but 00197 * that's legacy libc for ya. These new macros do not support EOF like 00198 * the standard macros do. Tough. 00199 * @{ 00200 */ 00201 /** @see isalnum */ 00202 #define apr_isalnum(c) (isalnum(((unsigned char)(c)))) 00203 /** @see isalpha */ 00204 #define apr_isalpha(c) (isalpha(((unsigned char)(c)))) 00205 /** @see iscntrl */ 00206 #define apr_iscntrl(c) (iscntrl(((unsigned char)(c)))) 00207 /** @see isdigit */ 00208 #define apr_isdigit(c) (isdigit(((unsigned char)(c)))) 00209 /** @see isgraph */ 00210 #define apr_isgraph(c) (isgraph(((unsigned char)(c)))) 00211 /** @see islower*/ 00212 #define apr_islower(c) (islower(((unsigned char)(c)))) 00213 /** @see isascii */ 00214 #ifdef isascii 00215 #define apr_isascii(c) (isascii(((unsigned char)(c)))) 00216 #else 00217 #define apr_isascii(c) (((c) & ~0x7f)==0) 00218 #endif 00219 /** @see isprint */ 00220 #define apr_isprint(c) (isprint(((unsigned char)(c)))) 00221 /** @see ispunct */ 00222 #define apr_ispunct(c) (ispunct(((unsigned char)(c)))) 00223 /** @see isspace */ 00224 #define apr_isspace(c) (isspace(((unsigned char)(c)))) 00225 /** @see isupper */ 00226 #define apr_isupper(c) (isupper(((unsigned char)(c)))) 00227 /** @see isxdigit */ 00228 #define apr_isxdigit(c) (isxdigit(((unsigned char)(c)))) 00229 /** @see tolower */ 00230 #define apr_tolower(c) (tolower(((unsigned char)(c)))) 00231 /** @see toupper */ 00232 #define apr_toupper(c) (toupper(((unsigned char)(c)))) 00233 00234 /** @} */ 00235 00236 #ifdef __cplusplus 00237 } 00238 #endif 00239 00240 #endif /* ! APR_LIB_H */