Annotation of win32/apache13/src/include/ap.h, revision 1.1.1.1

1.1       parser      1: /* ====================================================================
                      2:  * Copyright (c) 1998-1999 The Apache Group.  All rights reserved.
                      3:  *
                      4:  * Redistribution and use in source and binary forms, with or without
                      5:  * modification, are permitted provided that the following conditions
                      6:  * are met:
                      7:  *
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer. 
                     10:  *
                     11:  * 2. Redistributions in binary form must reproduce the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer in
                     13:  *    the documentation and/or other materials provided with the
                     14:  *    distribution.
                     15:  *
                     16:  * 3. All advertising materials mentioning features or use of this
                     17:  *    software must display the following acknowledgment:
                     18:  *    "This product includes software developed by the Apache Group
                     19:  *    for use in the Apache HTTP server project (http://www.apache.org/)."
                     20:  *
                     21:  * 4. The names "Apache Server" and "Apache Group" must not be used to
                     22:  *    endorse or promote products derived from this software without
                     23:  *    prior written permission. For written permission, please contact
                     24:  *    apache@apache.org.
                     25:  *
                     26:  * 5. Products derived from this software may not be called "Apache"
                     27:  *    nor may "Apache" appear in their names without prior written
                     28:  *    permission of the Apache Group.
                     29:  *
                     30:  * 6. Redistributions of any form whatsoever must retain the following
                     31:  *    acknowledgment:
                     32:  *    "This product includes software developed by the Apache Group
                     33:  *    for use in the Apache HTTP server project (http://www.apache.org/)."
                     34:  *
                     35:  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
                     36:  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     37:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     38:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
                     39:  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
                     40:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     41:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
                     42:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     43:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
                     44:  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     45:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
                     46:  * OF THE POSSIBILITY OF SUCH DAMAGE.
                     47:  * ====================================================================
                     48:  *
                     49:  * This software consists of voluntary contributions made by many
                     50:  * individuals on behalf of the Apache Group and was originally based
                     51:  * on public domain software written at the National Center for
                     52:  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
                     53:  * For more information on the Apache Group and the Apache HTTP server
                     54:  * project, please see <http://www.apache.org/>.
                     55:  *
                     56:  * The ap_vsnprintf/ap_snprintf functions are based on, and used with the
                     57:  * permission of, the  SIO stdio-replacement strx_* functions by Panos
                     58:  * Tsirigotis <panos@alumni.cs.colorado.edu> for xinetd.
                     59:  */
                     60: 
                     61: #ifndef APACHE_AP_H
                     62: #define APACHE_AP_H
                     63: 
                     64: #ifdef __cplusplus
                     65: extern "C" {
                     66: #endif
                     67: 
                     68: API_EXPORT(char *) ap_cpystrn(char *, const char *, size_t);
                     69: int ap_slack(int, int);
                     70: int ap_execle(const char *, const char *, ...);
                     71: int ap_execve(const char *, char * const argv[], char * const envp[]);
                     72: API_EXPORT(int) ap_getpass(const char *prompt, char *pwbuf, size_t bufsiz);
                     73: 
                     74: /* small utility macros to make things easier to read */
                     75: 
                     76: #ifdef WIN32
                     77: #define ap_killpg(x, y)
                     78: #else
                     79: #ifdef NO_KILLPG
                     80: #define ap_killpg(x, y)                (kill (-(x), (y)))
                     81: #else
                     82: #define ap_killpg(x, y)                (killpg ((x), (y)))
                     83: #endif
                     84: #endif /* WIN32 */
                     85: 
                     86: /* ap_vformatter() is a generic printf-style formatting routine
                     87:  * with some extensions.  The extensions are:
                     88:  *
                     89:  * %pA takes a struct in_addr *, and prints it as a.b.c.d
                     90:  * %pI takes a struct sockaddr_in * and prints it as a.b.c.d:port
                     91:  * %pp  takes a void * and outputs it in hex
                     92:  *
                     93:  * The %p hacks are to force gcc's printf warning code to skip
                     94:  * over a pointer argument without complaining.  This does
                     95:  * mean that the ANSI-style %p (output a void * in hex format) won't
                     96:  * work as expected at all, but that seems to be a fair trade-off
                     97:  * for the increased robustness of having printf-warnings work.
                     98:  *
                     99:  * Additionally, ap_vformatter allows for arbitrary output methods
                    100:  * using the ap_vformatter_buff and flush_func.
                    101:  *
                    102:  * The ap_vformatter_buff has two elements curpos and endpos.
                    103:  * curpos is where ap_vformatter will write the next byte of output.
                    104:  * It proceeds writing output to curpos, and updating curpos, until
                    105:  * either the end of output is reached, or curpos == endpos (i.e. the
                    106:  * buffer is full).
                    107:  *
                    108:  * If the end of output is reached, ap_vformatter returns the
                    109:  * number of bytes written.
                    110:  *
                    111:  * When the buffer is full, the flush_func is called.  The flush_func
                    112:  * can return -1 to indicate that no further output should be attempted,
                    113:  * and ap_vformatter will return immediately with -1.  Otherwise
                    114:  * the flush_func should flush the buffer in whatever manner is
                    115:  * appropriate, re-initialize curpos and endpos, and return 0.
                    116:  *
                    117:  * Note that flush_func is only invoked as a result of attempting to
                    118:  * write another byte at curpos when curpos >= endpos.  So for
                    119:  * example, it's possible when the output exactly matches the buffer
                    120:  * space available that curpos == endpos will be true when
                    121:  * ap_vformatter returns.
                    122:  *
                    123:  * ap_vformatter does not call out to any other code, it is entirely
                    124:  * self-contained.  This allows the callers to do things which are
                    125:  * otherwise "unsafe".  For example, ap_psprintf uses the "scratch"
                    126:  * space at the unallocated end of a block, and doesn't actually
                    127:  * complete the allocation until ap_vformatter returns.  ap_psprintf
                    128:  * would be completely broken if ap_vformatter were to call anything
                    129:  * that used a pool.  Similarly http_bprintf() uses the "scratch"
                    130:  * space at the end of its output buffer, and doesn't actually note
                    131:  * that the space is in use until it either has to flush the buffer
                    132:  * or until ap_vformatter returns.
                    133:  */
                    134: 
                    135: typedef struct {
                    136:     char *curpos;
                    137:     char *endpos;
                    138: } ap_vformatter_buff;
                    139: 
                    140: API_EXPORT(int) ap_vformatter(int (*flush_func)(ap_vformatter_buff *),
                    141:     ap_vformatter_buff *, const char *fmt, va_list ap);
                    142: 
                    143: /* These are snprintf implementations based on ap_vformatter().
                    144:  *
                    145:  * Note that various standards and implementations disagree on the return
                    146:  * value of snprintf, and side-effects due to %n in the formatting string.
                    147:  * ap_snprintf behaves as follows:
                    148:  *
                    149:  * Process the format string until the entire string is exhausted, or
                    150:  * the buffer fills.  If the buffer fills then stop processing immediately
                    151:  * (so no further %n arguments are processed), and return the buffer
                    152:  * length.  In all cases the buffer is NUL terminated.
                    153:  *
                    154:  * In no event does ap_snprintf return a negative number.  It's not possible
                    155:  * to distinguish between an output which was truncated, and an output which
                    156:  * exactly filled the buffer.
                    157:  */
                    158: API_EXPORT(int) ap_snprintf(char *buf, size_t len, const char *format,...)
                    159:                            __attribute__((format(printf,3,4)));
                    160: API_EXPORT(int) ap_vsnprintf(char *buf, size_t len, const char *format,
                    161:                             va_list ap);
                    162: /* Simple BASE64 encode/decode functions.
                    163:  * 
                    164:  * As we might encode binary strings, hence we require the length of
                    165:  * the incoming plain source. And return the length of what we decoded.
                    166:  *
                    167:  * The decoding function takes any non valid char (i.e. whitespace, \0
                    168:  * or anything non A-Z,0-9 etc as terminal.
                    169:  * 
                    170:  * plain strings/binary sequences are not assumed '\0' terminated. Encoded
                    171:  * strings are neither. But propably should.
                    172:  *
                    173:  */
                    174: API_EXPORT(int) ap_base64encode_len(int len);
                    175: API_EXPORT(int) ap_base64encode(char * coded_dst, const char *plain_src,int len_plain_src);
                    176: API_EXPORT(int) ap_base64encode_binary(char * coded_dst, const unsigned char *plain_src,int len_plain_src);
                    177: 
                    178: API_EXPORT(int) ap_base64decode_len(const char * coded_src);
                    179: API_EXPORT(int) ap_base64decode(char * plain_dst, const char *coded_src);
                    180: API_EXPORT(int) ap_base64decode_binary(unsigned char * plain_dst, const char *coded_src);
                    181: 
                    182: /* Password validation, as used in AuthType Basic which is able to cope
                    183:  * (based on the prefix) with the SHA1, Apache's internal MD5 and (depending
                    184:  * on your platform either plain or crypt(3) passwords.
                    185:  */
                    186: API_EXPORT(char *) ap_validate_password(const char *passwd, const char *hash);
                    187: 
                    188: #ifdef __cplusplus
                    189: }
                    190: #endif
                    191: 
                    192: #endif /* !APACHE_AP_H */

E-mail: