apr_lib.h

Go to the documentation of this file.
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  * %%pp takes a void * and outputs it in hex
00122  *
00123  * The %%p hacks are to force gcc's printf warning code to skip
00124  * over a pointer argument without complaining.  This does
00125  * mean that the ANSI-style %%p (output a void * in hex format) won't
00126  * work as expected at all, but that seems to be a fair trade-off
00127  * for the increased robustness of having printf-warnings work.
00128  *
00129  * Additionally, apr_vformatter allows for arbitrary output methods
00130  * using the apr_vformatter_buff and flush_func.
00131  *
00132  * The apr_vformatter_buff has two elements curpos and endpos.
00133  * curpos is where apr_vformatter will write the next byte of output.
00134  * It proceeds writing output to curpos, and updating curpos, until
00135  * either the end of output is reached, or curpos == endpos (i.e. the
00136  * buffer is full).
00137  *
00138  * If the end of output is reached, apr_vformatter returns the
00139  * number of bytes written.
00140  *
00141  * When the buffer is full, the flush_func is called.  The flush_func
00142  * can return -1 to indicate that no further output should be attempted,
00143  * and apr_vformatter will return immediately with -1.  Otherwise
00144  * the flush_func should flush the buffer in whatever manner is
00145  * appropriate, re apr_pool_t nitialize curpos and endpos, and return 0.
00146  *
00147  * Note that flush_func is only invoked as a result of attempting to
00148  * write another byte at curpos when curpos >= endpos.  So for
00149  * example, it's possible when the output exactly matches the buffer
00150  * space available that curpos == endpos will be true when
00151  * apr_vformatter returns.
00152  *
00153  * apr_vformatter does not call out to any other code, it is entirely
00154  * self-contained.  This allows the callers to do things which are
00155  * otherwise "unsafe".  For example, apr_psprintf uses the "scratch"
00156  * space at the unallocated end of a block, and doesn't actually
00157  * complete the allocation until apr_vformatter returns.  apr_psprintf
00158  * would be completely broken if apr_vformatter were to call anything
00159  * that used this same pool.  Similarly http_bprintf() uses the "scratch"
00160  * space at the end of its output buffer, and doesn't actually note
00161  * that the space is in use until it either has to flush the buffer
00162  * or until apr_vformatter returns.
00163  * </PRE>
00164  */
00165 APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *b),
00166                                 apr_vformatter_buff_t *c, const char *fmt,
00167                                 va_list ap);
00168 
00169 /**
00170  * Display a prompt and read in the password from stdin.
00171  * @param prompt The prompt to display
00172  * @param pwbuf Buffer to store the password
00173  * @param bufsize The length of the password buffer.
00174  * @remark If the password entered must be truncated to fit in
00175  * the provided buffer, APR_ENAMETOOLONG will be returned.
00176  * Note that the bufsize paramater is passed by reference for no
00177  * reason; its value will never be modified by the apr_password_get()
00178  * function.
00179  */
00180 APR_DECLARE(apr_status_t) apr_password_get(const char *prompt, char *pwbuf, 
00181                                            apr_size_t *bufsize);
00182 
00183 /** @} */
00184 
00185 /**
00186  * @defgroup apr_ctype ctype functions
00187  * These macros allow correct support of 8-bit characters on systems which
00188  * support 8-bit characters.  Pretty dumb how the cast is required, but
00189  * that's legacy libc for ya.  These new macros do not support EOF like
00190  * the standard macros do.  Tough.
00191  * @{
00192  */
00193 /** @see isalnum */
00194 #define apr_isalnum(c) (isalnum(((unsigned char)(c))))
00195 /** @see isalpha */
00196 #define apr_isalpha(c) (isalpha(((unsigned char)(c))))
00197 /** @see iscntrl */
00198 #define apr_iscntrl(c) (iscntrl(((unsigned char)(c))))
00199 /** @see isdigit */
00200 #define apr_isdigit(c) (isdigit(((unsigned char)(c))))
00201 /** @see isgraph */
00202 #define apr_isgraph(c) (isgraph(((unsigned char)(c))))
00203 /** @see islower*/
00204 #define apr_islower(c) (islower(((unsigned char)(c))))
00205 /** @see isascii */
00206 #ifdef isascii
00207 #define apr_isascii(c) (isascii(((unsigned char)(c))))
00208 #else
00209 #define apr_isascii(c) (((c) & ~0x7f)==0)
00210 #endif
00211 /** @see isprint */
00212 #define apr_isprint(c) (isprint(((unsigned char)(c))))
00213 /** @see ispunct */
00214 #define apr_ispunct(c) (ispunct(((unsigned char)(c))))
00215 /** @see isspace */
00216 #define apr_isspace(c) (isspace(((unsigned char)(c))))
00217 /** @see isupper */
00218 #define apr_isupper(c) (isupper(((unsigned char)(c))))
00219 /** @see isxdigit */
00220 #define apr_isxdigit(c) (isxdigit(((unsigned char)(c))))
00221 /** @see tolower */
00222 #define apr_tolower(c) (tolower(((unsigned char)(c))))
00223 /** @see toupper */
00224 #define apr_toupper(c) (toupper(((unsigned char)(c))))
00225 
00226 /** @} */
00227 
00228 #ifdef __cplusplus
00229 }
00230 #endif
00231 
00232 #endif  /* ! APR_LIB_H */

Generated on Mon Nov 26 11:23:52 2007 for Apache Portable Runtime by  doxygen 1.5.2