1251875Speter/* Licensed to the Apache Software Foundation (ASF) under one or more 2251875Speter * contributor license agreements. See the NOTICE file distributed with 3251875Speter * this work for additional information regarding copyright ownership. 4251875Speter * The ASF licenses this file to You under the Apache License, Version 2.0 5251875Speter * (the "License"); you may not use this file except in compliance with 6251875Speter * the License. You may obtain a copy of the License at 7251875Speter * 8251875Speter * http://www.apache.org/licenses/LICENSE-2.0 9251875Speter * 10251875Speter * Unless required by applicable law or agreed to in writing, software 11251875Speter * distributed under the License is distributed on an "AS IS" BASIS, 12251875Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13251875Speter * See the License for the specific language governing permissions and 14251875Speter * limitations under the License. 15251875Speter */ 16251875Speter 17251875Speter#ifndef APR_LIB_H 18251875Speter#define APR_LIB_H 19251875Speter 20251875Speter/** 21251875Speter * @file apr_lib.h 22251875Speter * This is collection of oddballs that didn't fit anywhere else, 23251875Speter * and might move to more appropriate headers with the release 24251875Speter * of APR 1.0. 25251875Speter * @brief APR general purpose library routines 26251875Speter */ 27251875Speter 28251875Speter#include "apr.h" 29251875Speter#include "apr_errno.h" 30251875Speter 31251875Speter#if APR_HAVE_CTYPE_H 32251875Speter#include <ctype.h> 33251875Speter#endif 34251875Speter#if APR_HAVE_STDARG_H 35251875Speter#include <stdarg.h> 36251875Speter#endif 37251875Speter 38251875Speter#ifdef __cplusplus 39251875Speterextern "C" { 40251875Speter#endif /* __cplusplus */ 41251875Speter 42251875Speter/** 43251875Speter * @defgroup apr_lib General Purpose Library Routines 44251875Speter * @ingroup APR 45251875Speter * This is collection of oddballs that didn't fit anywhere else, 46251875Speter * and might move to more appropriate headers with the release 47251875Speter * of APR 1.0. 48251875Speter * @{ 49251875Speter */ 50251875Speter 51251875Speter/** A constant representing a 'large' string. */ 52251875Speter#define HUGE_STRING_LEN 8192 53251875Speter 54251875Speter/* 55251875Speter * Define the structures used by the APR general-purpose library. 56251875Speter */ 57251875Speter 58251875Speter/** @see apr_vformatter_buff_t */ 59251875Spetertypedef struct apr_vformatter_buff_t apr_vformatter_buff_t; 60251875Speter 61251875Speter/** 62251875Speter * Structure used by the variable-formatter routines. 63251875Speter */ 64251875Speterstruct apr_vformatter_buff_t { 65251875Speter /** The current position */ 66251875Speter char *curpos; 67251875Speter /** The end position of the format string */ 68251875Speter char *endpos; 69251875Speter}; 70251875Speter 71251875Speter/** 72251875Speter * return the final element of the pathname 73251875Speter * @param pathname The path to get the final element of 74251875Speter * @return the final element of the path 75251875Speter * @remark 76251875Speter * <PRE> 77251875Speter * For example: 78251875Speter * "/foo/bar/gum" -> "gum" 79251875Speter * "/foo/bar/gum/" -> "" 80251875Speter * "gum" -> "gum" 81251875Speter * "bs\\path\\stuff" -> "stuff" 82251875Speter * </PRE> 83251875Speter */ 84251875SpeterAPR_DECLARE(const char *) apr_filepath_name_get(const char *pathname); 85251875Speter 86251875Speter/** 87251875Speter * apr_killpg 88251875Speter * Small utility macros to make things easier to read. Not usually a 89251875Speter * goal, to be sure.. 90251875Speter */ 91251875Speter 92251875Speter#ifdef WIN32 93251875Speter#define apr_killpg(x, y) 94251875Speter#else /* WIN32 */ 95251875Speter#ifdef NO_KILLPG 96251875Speter#define apr_killpg(x, y) (kill (-(x), (y))) 97251875Speter#else /* NO_KILLPG */ 98251875Speter#define apr_killpg(x, y) (killpg ((x), (y))) 99251875Speter#endif /* NO_KILLPG */ 100251875Speter#endif /* WIN32 */ 101251875Speter 102251875Speter/** 103251875Speter * apr_vformatter() is a generic printf-style formatting routine 104251875Speter * with some extensions. 105251875Speter * @param flush_func The function to call when the buffer is full 106251875Speter * @param c The buffer to write to 107251875Speter * @param fmt The format string 108251875Speter * @param ap The arguments to use to fill out the format string. 109251875Speter * 110251875Speter * @remark 111251875Speter * <PRE> 112251875Speter * The extensions are: 113251875Speter * 114266735Speter * - %%pA takes a struct in_addr *, and prints it as a.b.c.d 115266735Speter * - %%pI takes an apr_sockaddr_t * and prints it as a.b.c.d:port or 116266735Speter * \[ipv6-address\]:port 117266735Speter * - %%pT takes an apr_os_thread_t * and prints it in decimal 118266735Speter * ('0' is printed if !APR_HAS_THREADS) 119266735Speter * - %%pt takes an apr_os_thread_t * and prints it in hexadecimal 120266735Speter * ('0' is printed if !APR_HAS_THREADS) 121266735Speter * - %%pm takes an apr_status_t * and prints the appropriate error 122266735Speter * string (from apr_strerror) corresponding to that error code. 123266735Speter * - %%pp takes a void * and outputs it in hex 124266735Speter * - %%pB takes a apr_uint32_t * as bytes and outputs it's apr_strfsize 125266735Speter * - %%pF same as above, but takes a apr_off_t * 126266735Speter * - %%pS same as above, but takes a apr_size_t * 127251875Speter * 128251875Speter * %%pA, %%pI, %%pT, %%pp are available from APR 1.0.0 onwards (and in 0.9.x). 129251875Speter * %%pt is only available from APR 1.2.0 onwards. 130251875Speter * %%pm, %%pB, %%pF and %%pS are only available from APR 1.3.0 onwards. 131251875Speter * 132251875Speter * The %%p hacks are to force gcc's printf warning code to skip 133251875Speter * over a pointer argument without complaining. This does 134251875Speter * mean that the ANSI-style %%p (output a void * in hex format) won't 135251875Speter * work as expected at all, but that seems to be a fair trade-off 136251875Speter * for the increased robustness of having printf-warnings work. 137251875Speter * 138251875Speter * Additionally, apr_vformatter allows for arbitrary output methods 139251875Speter * using the apr_vformatter_buff and flush_func. 140251875Speter * 141251875Speter * The apr_vformatter_buff has two elements curpos and endpos. 142251875Speter * curpos is where apr_vformatter will write the next byte of output. 143251875Speter * It proceeds writing output to curpos, and updating curpos, until 144251875Speter * either the end of output is reached, or curpos == endpos (i.e. the 145251875Speter * buffer is full). 146251875Speter * 147251875Speter * If the end of output is reached, apr_vformatter returns the 148251875Speter * number of bytes written. 149251875Speter * 150251875Speter * When the buffer is full, the flush_func is called. The flush_func 151251875Speter * can return -1 to indicate that no further output should be attempted, 152251875Speter * and apr_vformatter will return immediately with -1. Otherwise 153251875Speter * the flush_func should flush the buffer in whatever manner is 154251875Speter * appropriate, re apr_pool_t nitialize curpos and endpos, and return 0. 155251875Speter * 156251875Speter * Note that flush_func is only invoked as a result of attempting to 157251875Speter * write another byte at curpos when curpos >= endpos. So for 158251875Speter * example, it's possible when the output exactly matches the buffer 159251875Speter * space available that curpos == endpos will be true when 160251875Speter * apr_vformatter returns. 161251875Speter * 162251875Speter * apr_vformatter does not call out to any other code, it is entirely 163251875Speter * self-contained. This allows the callers to do things which are 164251875Speter * otherwise "unsafe". For example, apr_psprintf uses the "scratch" 165251875Speter * space at the unallocated end of a block, and doesn't actually 166251875Speter * complete the allocation until apr_vformatter returns. apr_psprintf 167251875Speter * would be completely broken if apr_vformatter were to call anything 168251875Speter * that used this same pool. Similarly http_bprintf() uses the "scratch" 169251875Speter * space at the end of its output buffer, and doesn't actually note 170251875Speter * that the space is in use until it either has to flush the buffer 171251875Speter * or until apr_vformatter returns. 172251875Speter * </PRE> 173251875Speter */ 174251875SpeterAPR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *b), 175251875Speter apr_vformatter_buff_t *c, const char *fmt, 176251875Speter va_list ap); 177251875Speter 178251875Speter/** 179251875Speter * Display a prompt and read in the password from stdin. 180251875Speter * @param prompt The prompt to display 181251875Speter * @param pwbuf Buffer to store the password 182251875Speter * @param bufsize The length of the password buffer. 183251875Speter * @remark If the password entered must be truncated to fit in 184251875Speter * the provided buffer, APR_ENAMETOOLONG will be returned. 185251875Speter * Note that the bufsize paramater is passed by reference for no 186251875Speter * reason; its value will never be modified by the apr_password_get() 187251875Speter * function. 188251875Speter */ 189251875SpeterAPR_DECLARE(apr_status_t) apr_password_get(const char *prompt, char *pwbuf, 190251875Speter apr_size_t *bufsize); 191251875Speter 192251875Speter/** @} */ 193251875Speter 194251875Speter/** 195251875Speter * @defgroup apr_ctype ctype functions 196251875Speter * These macros allow correct support of 8-bit characters on systems which 197251875Speter * support 8-bit characters. Pretty dumb how the cast is required, but 198251875Speter * that's legacy libc for ya. These new macros do not support EOF like 199251875Speter * the standard macros do. Tough. 200251875Speter * @{ 201251875Speter */ 202251875Speter/** @see isalnum */ 203251875Speter#define apr_isalnum(c) (isalnum(((unsigned char)(c)))) 204251875Speter/** @see isalpha */ 205251875Speter#define apr_isalpha(c) (isalpha(((unsigned char)(c)))) 206251875Speter/** @see iscntrl */ 207251875Speter#define apr_iscntrl(c) (iscntrl(((unsigned char)(c)))) 208251875Speter/** @see isdigit */ 209251875Speter#define apr_isdigit(c) (isdigit(((unsigned char)(c)))) 210251875Speter/** @see isgraph */ 211251875Speter#define apr_isgraph(c) (isgraph(((unsigned char)(c)))) 212251875Speter/** @see islower*/ 213251875Speter#define apr_islower(c) (islower(((unsigned char)(c)))) 214251875Speter/** @see isascii */ 215251875Speter#ifdef isascii 216251875Speter#define apr_isascii(c) (isascii(((unsigned char)(c)))) 217251875Speter#else 218251875Speter#define apr_isascii(c) (((c) & ~0x7f)==0) 219251875Speter#endif 220251875Speter/** @see isprint */ 221251875Speter#define apr_isprint(c) (isprint(((unsigned char)(c)))) 222251875Speter/** @see ispunct */ 223251875Speter#define apr_ispunct(c) (ispunct(((unsigned char)(c)))) 224251875Speter/** @see isspace */ 225251875Speter#define apr_isspace(c) (isspace(((unsigned char)(c)))) 226251875Speter/** @see isupper */ 227251875Speter#define apr_isupper(c) (isupper(((unsigned char)(c)))) 228251875Speter/** @see isxdigit */ 229251875Speter#define apr_isxdigit(c) (isxdigit(((unsigned char)(c)))) 230251875Speter/** @see tolower */ 231251875Speter#define apr_tolower(c) (tolower(((unsigned char)(c)))) 232251875Speter/** @see toupper */ 233251875Speter#define apr_toupper(c) (toupper(((unsigned char)(c)))) 234251875Speter 235251875Speter/** @} */ 236251875Speter 237251875Speter#ifdef __cplusplus 238251875Speter} 239251875Speter#endif 240251875Speter 241251875Speter#endif /* ! APR_LIB_H */ 242