Commit 2e7d4eb8 authored by Philip M. Gollucci's avatar Philip M. Gollucci
Browse files

import apreq include files

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1200458 13f79535-47bb-0310-9956-ffa450edef68
parent 1d73ae0f
Loading
Loading
Loading
Loading

include/apreq.h

0 → 100644
+308 −0
Original line number Diff line number Diff line
/*
**  Licensed to the Apache Software Foundation (ASF) under one or more
** contributor license agreements.  See the NOTICE file distributed with
** this work for additional information regarding copyright ownership.
** The ASF licenses this file to You under the Apache License, Version 2.0
** (the "License"); you may not use this file except in compliance with
** the License.  You may obtain a copy of the License at
**
**      http://www.apache.org/licenses/LICENSE-2.0
**
**  Unless required by applicable law or agreed to in writing, software
**  distributed under the License is distributed on an "AS IS" BASIS,
**  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
**  See the License for the specific language governing permissions and
**  limitations under the License.
*/

#ifndef APREQ_H
#define APREQ_H

#ifdef APREQ_DEBUG
#include <assert.h>
#endif

#include "apr_tables.h"
#include <stddef.h>

#ifdef  __cplusplus
 extern "C" {
#endif

/**
 * @file apreq.h
 * @brief Main header file...
 * @ingroup libapreq2
 *
 * Define the generic APREQ_ macros and common data structures.
 */

#ifndef WIN32
/**
 * The public APREQ functions are declared with APREQ_DECLARE(), so they may
 * use the most appropriate calling convention.  Public APR functions with 
 * variable arguments must use APR_DECLARE_NONSTD().
 *
 * @remark Both the declaration and implementations must use the same macro.
 */
/** APREQ_DECLARE(rettype) apeq_func(args)
 */
#define APREQ_DECLARE(d)                APR_DECLARE(d)
/**
 * The public APEQ functions using variable arguments are declared with 
 * APEQ_DECLARE_NONSTD(), as they must follow the C language calling convention.
 * @see APEQ_DECLARE @see APEQ_DECLARE_DATA
 * @remark Both the declaration and implementations must use the same macro.
 * @example
 */
/** APEQ_DECLARE_NONSTD(rettype) apr_func(args, ...);
 */
#define APREQ_DECLARE_NONSTD(d)         APR_DECLARE_NONSTD(d)
/**
 * The public APREQ variables are declared with APREQ_DECLARE_DATA.
 * This assures the appropriate indirection is invoked at compile time.
 * @see APREQ_DECLARE @see APREQ_DECLARE_NONSTD
 * @remark Note that the declaration and implementations use different forms,
 * but both must include the macro.
 */
/** extern APREQ_DECLARE_DATA type apr_variable;\n
 * APREQ_DECLARE_DATA type apr_variable = value;
 */
#define APREQ_DECLARE_DATA
#elif defined (APREQ_DECLARE_STATIC)
#define APREQ_DECLARE(type)             type __stdcall
#define APREQ_DECLARE_NONSTD(type)      type
#define APREQ_DECLARE_DATA
#elif defined (APREQ_DECLARE_EXPORT)
#define APREQ_DECLARE(type)             __declspec(dllexport) type __stdcall
#define APREQ_DECLARE_NONSTD(type)      __declspec(dllexport) type
#define APREQ_DECLARE_DATA              __declspec(dllexport)
#else
#define APREQ_DECLARE(type)             __declspec(dllimport) type __stdcall
#define APREQ_DECLARE_NONSTD(type)      __declspec(dllimport) type
#define APREQ_DECLARE_DATA              __declspec(dllimport)
#endif

/**
 * Read chucks of data in 64k blocks from the request 
 */

#define APREQ_DEFAULT_READ_BLOCK_SIZE   (64  * 1024)

/**
 * Maximum number of bytes mod_apreq2 will send off to libapreq2 for parsing. 
 * mod_apreq2 will log this event and subsequently remove itself 
 * from the filter chain.  
 * @see ap_set_read_limit  
 */
#define APREQ_DEFAULT_READ_LIMIT        (64 * 1024 * 1024)
/**
 * Maximum number of bytes mod_apreq2 will let accumulate within the 
 * heap-buckets in a brigade. Excess data will be spooled to an 
 * appended file bucket
 * @see ap_set_brigade_read_limit
 */
#define APREQ_DEFAULT_BRIGADE_LIMIT     (256 * 1024)

/**
 * Number of elements in the initial apr_table
 * @see apr_table_make
 */
#define APREQ_DEFAULT_NELTS              8



/**
 * Check to see if specified bit f is off in bitfield name
 */
#define APREQ_FLAGS_OFF(f, name) ((f) &= ~(name##_MASK << name##_BIT))
/**
 * Check to see if specified bit f is on in bitfield name
 */
#define APREQ_FLAGS_ON(f, name)  ((f) |=  (name##_MASK << name##_BIT))
/**
 *  Get specified bit f in bitfield name
 */
#define APREQ_FLAGS_GET(f, name) (((f) >> name##_BIT) & name##_MASK)
/**
 * Set specified bit f in bitfield name to value 
 * Note the below BIT/Mask defines are used sans the
 * _BIT, _MASK because of the this define's \#\#_MASK, \#\#_BIT usage.
 * Each come in a pair
 */
#define APREQ_FLAGS_SET(f, name, value)                 \
    ((f) = (((f) & ~(name##_MASK << name##_BIT))        \
            | ((name##_MASK & (value)) << name##_BIT)))

/**
 * Charset Bit 
 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
 */
#define APREQ_CHARSET_BIT           0

/**
 * Charset Mask
 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
 */
#define APREQ_CHARSET_MASK        255

/**
 * Tainted Bit 
 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
 */
#define APREQ_TAINTED_BIT           8
/**
 * Tainted Mask
 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
 */
#define APREQ_TAINTED_MASK          1

/**
 * Cookier Version Bit
 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
 */

#define APREQ_COOKIE_VERSION_BIT   11
/**
 * Cookie Version Mask
 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
 */
#define APREQ_COOKIE_VERSION_MASK   3

/**
 * Cookie's Secure Bit 
 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
 */
#define APREQ_COOKIE_SECURE_BIT    13
/**
 * Cookie's Secure Mask
 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
 */
#define APREQ_COOKIE_SECURE_MASK    1

/**
 * Cookie's HttpOnly Bit 
 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
 */
#define APREQ_COOKIE_HTTPONLY_BIT    14
/**
 * Cookie's HttpOnly Mask
 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
 */
#define APREQ_COOKIE_HTTPONLY_MASK    1

/** Character encodings. */
typedef enum {
    APREQ_CHARSET_ASCII  =0,
    APREQ_CHARSET_LATIN1 =1, /* ISO-8859-1   */
    APREQ_CHARSET_CP1252 =2, /* Windows-1252 */
    APREQ_CHARSET_UTF8   =8
} apreq_charset_t;


/** @enum apreq_join_t Join type */
typedef enum {
    APREQ_JOIN_AS_IS,      /**< Join the strings without modification */
    APREQ_JOIN_ENCODE,     /**< Url-encode the strings before joining them */
    APREQ_JOIN_DECODE,     /**< Url-decode the strings before joining them */
    APREQ_JOIN_QUOTE       /**< Quote the strings, backslashing existing quote marks. */
} apreq_join_t;

/** @enum apreq_match_t Match type */
typedef enum {
    APREQ_MATCH_FULL,       /**< Full match only. */
    APREQ_MATCH_PARTIAL     /**< Partial matches are ok. */
} apreq_match_t;

/** @enum apreq_expires_t Expiration date format */
typedef enum {
    APREQ_EXPIRES_HTTP,       /**< Use date formatting consistent with RFC 2616 */
    APREQ_EXPIRES_NSCOOKIE    /**< Use format consistent with Netscape's Cookie Spec */
} apreq_expires_t;


/** @brief libapreq's pre-extensible string type */
typedef struct apreq_value_t {
    char             *name;    /**< value name */
    apr_size_t        nlen;    /**< length of name */
    apr_size_t        dlen;    /**< length of data */
    char              data[1]; /**< value data  */
} apreq_value_t;

/**
 * Adds the specified apreq_value_t to the apr_table_t.
 *
 * @param v value to add
 * @param t add v to this table
 *
 * @return void
 *
 * @ see apr_table_t @see apr_value_t
 */
  
static APR_INLINE
void apreq_value_table_add(const apreq_value_t *v, apr_table_t *t) {
    apr_table_addn(t, v->name, v->data);
}

/**
 * @param T type
 * @param A attribute
 * @param P
 *
 * XXX
 */
#define apreq_attr_to_type(T,A,P) ( (T*) ((char*)(P)-offsetof(T,A)) )

/**
 * Initialize libapreq2. Applications (except apache modules using
 * mod_apreq) should call this exactly once before they use any
 * libapreq2 modules.  If you want to modify the list of default parsers
 * with apreq_register_parser(), please use apreq_pre_initialize()
 * and apreq_post_initialize() instead.
 *
 * @param pool a base pool persisting while libapreq2 is used
 * @remarks after you detroy the pool, you have to call this function again
 *    with a new pool if you still plan to use libapreq2
 */
APREQ_DECLARE(apr_status_t) apreq_initialize(apr_pool_t *pool);


/**
 * Pre-initialize libapreq2. Applications (except apache modules using
 * mod_apreq2) should call this exactly once before they register custom
 * parsers with libapreq2. mod_apreq2 does this automatically during the
 * post-config phase, so modules that need call apreq_register_parser should
 * create a post-config hook using APR_HOOK_MIDDLE.
 *
 * @param pool a base pool persisting while libapreq2 is used
 * @remarks after you detroyed the pool, you have to call this function again
 *    with a new pool if you still plan to use libapreq2
 */
APREQ_DECLARE(apr_status_t) apreq_pre_initialize(apr_pool_t *pool);

/**
 * Post-initialize libapreq2. Applications (except apache modules using
 * mod_apreq2) should this exactly once before they use any
 * libapreq2 modules for parsing.
 *
 * @param pool the same pool that was used in apreq_pre_initialize().
 */
APREQ_DECLARE(apr_status_t) apreq_post_initialize(apr_pool_t *pool);


#ifdef __cplusplus
 }
#endif

#endif /* APREQ_H */

include/apreq_cookie.h

0 → 100644
+237 −0
Original line number Diff line number Diff line
/*
**  Licensed to the Apache Software Foundation (ASF) under one or more
** contributor license agreements.  See the NOTICE file distributed with
** this work for additional information regarding copyright ownership.
** The ASF licenses this file to You under the Apache License, Version 2.0
** (the "License"); you may not use this file except in compliance with
** the License.  You may obtain a copy of the License at
**
**      http://www.apache.org/licenses/LICENSE-2.0
**
**  Unless required by applicable law or agreed to in writing, software
**  distributed under the License is distributed on an "AS IS" BASIS,
**  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
**  See the License for the specific language governing permissions and
**  limitations under the License.
*/

#ifndef APREQ_COOKIE_H
#define APREQ_COOKIE_H

#include "apreq.h"
#include "apr_time.h"

#ifdef  __cplusplus
extern "C" {
#endif

/**
 * @file apreq_cookie.h
 * @brief Cookies and Jars.
 * @ingroup libapreq2
 *
 * apreq_cookie.h describes a common server-side API for request (incoming)
 * and response (outgoing) cookies.  It aims towards compliance with the
 * standard cookie specifications listed below.
 *
 * @see http://wp.netscape.com/newsref/std/cookie_spec.html
 * @see http://www.ietf.org/rfc/rfc2109.txt
 * @see http://www.ietf.org/rfc/rfc2964.txt
 * @see http://www.ietf.org/rfc/rfc2965.txt
 *
 */

/** This macro is deprecated.
 *
 * Maximum length of a single Set-Cookie(2) header. 
 */
#define APREQ_COOKIE_MAX_LENGTH            4096

/** @brief Cookie type, supporting both Netscape and RFC cookie specifications.
 */

typedef struct apreq_cookie_t {

    char           *path;        /**< Restricts url path */
    char           *domain;      /**< Restricts server domain */
    char           *port;        /**< Restricts server port */
    char           *comment;     /**< RFC cookies may send a comment */
    char           *commentURL;  /**< RFC cookies may place an URL here */
    apr_time_t      max_age;     /**< total duration of cookie: -1 == session */
    unsigned        flags;       /**< charsets, taint marks, app-specific bits */
    const apreq_value_t   v;     /**< "raw" cookie value */

} apreq_cookie_t;


/** Upgrades a jar's table values to apreq_cookie_t structs. */
static APR_INLINE
apreq_cookie_t *apreq_value_to_cookie(const char *val)
{
    union { const char *in; char *out; } deconst;

    deconst.in = val;
    return apreq_attr_to_type(apreq_cookie_t, v,
           apreq_attr_to_type(apreq_value_t, data, deconst.out));
}

/**@return 1 if this is an RFC cookie, 0 if its a Netscape cookie. */
static APR_INLINE
unsigned apreq_cookie_version(const apreq_cookie_t *c) {
    return APREQ_FLAGS_GET(c->flags, APREQ_COOKIE_VERSION);
}

/** Sets the cookie's protocol version. */
static APR_INLINE
void apreq_cookie_version_set(apreq_cookie_t *c, unsigned v) {
    APREQ_FLAGS_SET(c->flags, APREQ_COOKIE_VERSION, v);
}

/** @return 1 if the secure flag is set, 0 otherwise. */
static APR_INLINE
unsigned apreq_cookie_is_secure(const apreq_cookie_t *c) {
    return APREQ_FLAGS_GET(c->flags, APREQ_COOKIE_SECURE);
}

/** Sets the cookie's secure flag, meaning it only
 *  comes back over an SSL-encrypted connction.
 */
static APR_INLINE
void apreq_cookie_secure_on(apreq_cookie_t *c) {
    APREQ_FLAGS_ON(c->flags, APREQ_COOKIE_SECURE);
}

/** Turns off the cookie's secure flag. */
static APR_INLINE
void apreq_cookie_secure_off(apreq_cookie_t *c) {
    APREQ_FLAGS_OFF(c->flags, APREQ_COOKIE_SECURE);
}

/** @return 1 if the HttpOnly flag is set, 0 otherwise. */
static APR_INLINE
unsigned apreq_cookie_is_httponly(const apreq_cookie_t *c) {
    return APREQ_FLAGS_GET(c->flags, APREQ_COOKIE_HTTPONLY);
}

/** Sets the cookie's HttpOnly flag, meaning it is not
 *  accessible through client-side script in supported
 *  browsers.
 */
static APR_INLINE
void apreq_cookie_httponly_on(apreq_cookie_t *c) {
    APREQ_FLAGS_ON(c->flags, APREQ_COOKIE_HTTPONLY);
}

/** Turns off the cookie's HttpOnly flag. */
static APR_INLINE
void apreq_cookie_httponly_off(apreq_cookie_t *c) {
    APREQ_FLAGS_OFF(c->flags, APREQ_COOKIE_HTTPONLY);
}


/** @return 1 if the taint flag is set, 0 otherwise. */
static APR_INLINE
unsigned apreq_cookie_is_tainted(const apreq_cookie_t *c) {
    return APREQ_FLAGS_GET(c->flags, APREQ_TAINTED);
}

/** Sets the cookie's tainted flag. */
static APR_INLINE
void apreq_cookie_tainted_on(apreq_cookie_t *c) {
    APREQ_FLAGS_ON(c->flags, APREQ_TAINTED);
}

/** Turns off the cookie's tainted flag. */
static APR_INLINE
void apreq_cookie_tainted_off(apreq_cookie_t *c) {
    APREQ_FLAGS_OFF(c->flags, APREQ_TAINTED);
}

/**
 * Parse a cookie header and store the cookies in an apr_table_t.
 *
 * @param pool pool which allocates the cookies
 * @param jar table where parsed cookies are stored
 * @param header the header value
 *
 * @return APR_SUCCESS.
 * @return ::APREQ_ERROR_BADSEQ if an unparseable character sequence appears.
 * @return ::APREQ_ERROR_MISMATCH if an rfc-cookie attribute appears in a
 *         netscape cookie header.
 * @return ::APR_ENOTIMPL if an unrecognized rfc-cookie attribute appears.
 * @return ::APREQ_ERROR_NOTOKEN if a required token was not present.
 * @return ::APREQ_ERROR_BADCHAR if an unexpected token was present.
 */
APREQ_DECLARE(apr_status_t) apreq_parse_cookie_header(apr_pool_t *pool,
                                                      apr_table_t *jar,
                                                      const char *header);

/**
 * Returns a new cookie, made from the argument list.
 *
 * @param pool  Pool which allocates the cookie.
 * @param name  The cookie's name.
 * @param nlen  Length of name.
 * @param value The cookie's value.
 * @param vlen  Length of value.
 *
 * @return the new cookie
 */
APREQ_DECLARE(apreq_cookie_t *) apreq_cookie_make(apr_pool_t *pool,
                                                  const char *name,
                                                  const apr_size_t nlen,
                                                  const char *value,
                                                  const apr_size_t vlen);

/**
 * Returns a string that represents the cookie as it would appear
 * in a valid "Set-Cookie*" header.
 *
 * @param c cookie.
 * @param p pool which allocates the returned string.
 *
 * @return header string.
 */
APREQ_DECLARE(char*) apreq_cookie_as_string(const apreq_cookie_t *c,
                                            apr_pool_t *p);


/**
 * Same functionality as apreq_cookie_as_string.  Stores the string
 * representation in buf, using up to len bytes in buf as storage.
 * The return value has the same semantics as that of apr_snprintf,
 * including the special behavior for a "len = 0" argument.
 *
 * @param c   cookie.
 * @param buf storage location for the result.
 * @param len size of buf's storage area.
 *
 * @return size of resulting header string.
 */
APREQ_DECLARE(int) apreq_cookie_serialize(const apreq_cookie_t *c,
                                          char *buf, apr_size_t len);

/**
 * Set the Cookie's expiration date.
 *
 * @param c The cookie.
 * @param time_str If NULL, the Cookie's expiration date is unset,
 * making it a session cookie.  This means no "expires" or "max-age"
 * attribute will appear in the cookie's serialized form. If time_str
 * is not NULL, the expiration date will be reset to the offset (from now)
 * represented by time_str.  The time_str should be in a format that
 * apreq_atoi64t() can understand, namely /[+-]?\\d+\\s*[YMDhms]/.
 *
 * @remarks Now time_str may also be a fixed date; see apr_date_parse_rfc()
 * for admissible formats.
 */
APREQ_DECLARE(void) apreq_cookie_expires(apreq_cookie_t *c,
                                         const char *time_str);

#ifdef __cplusplus
 }
#endif

#endif /*APREQ_COOKIE_H*/

include/apreq_error.h

0 → 100644
+97 −0
Original line number Diff line number Diff line
/*
**  Licensed to the Apache Software Foundation (ASF) under one or more
** contributor license agreements.  See the NOTICE file distributed with
** this work for additional information regarding copyright ownership.
** The ASF licenses this file to You under the Apache License, Version 2.0
** (the "License"); you may not use this file except in compliance with
** the License.  You may obtain a copy of the License at
**
**      http://www.apache.org/licenses/LICENSE-2.0
**
**  Unless required by applicable law or agreed to in writing, software
**  distributed under the License is distributed on an "AS IS" BASIS,
**  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
**  See the License for the specific language governing permissions and
**  limitations under the License.
*/

#ifndef APREQ_ERROR_H
#define APREQ_ERROR_H

#include "apr_errno.h"
#include "apreq.h"

#ifdef  __cplusplus
 extern "C" {
#endif

/**
 * apreq's wrapper around apr_strerror();
 * recognizes APREQ_ERROR_* status codes.
 */
APREQ_DECLARE(char *)
apreq_strerror(apr_status_t s, char *buf, apr_size_t bufsize);

/**
 * @file apreq_error.h
 * @brief Error status codes.
 * @ingroup libapreq2
 *
 * Define the APREQ_ error codes.
 */

#ifndef APR_EBADARG
/**
 * Bad Arguments return value
 * @see APR_BADARG
 */
#define APR_EBADARG                APR_BADARG   /* XXX: don't use APR_BADARG */
#endif

/** Internal apreq error. */
#define APREQ_ERROR_GENERAL        APR_OS_START_USERERR
/** Attempted to perform unsafe action with tainted data. */
#define APREQ_ERROR_TAINTED        (APREQ_ERROR_GENERAL + 1)
/** Parsing interrupted. */
#define APREQ_ERROR_INTERRUPT      (APREQ_ERROR_GENERAL + 2)

/** Invalid input data. */
#define APREQ_ERROR_BADDATA        (APREQ_ERROR_GENERAL  + 10)
/** Invalid character. */
#define APREQ_ERROR_BADCHAR        (APREQ_ERROR_BADDATA  +  1)
/** Invalid byte sequence. */
#define APREQ_ERROR_BADSEQ         (APREQ_ERROR_BADDATA  +  2)
/** Invalid attribute. */
#define APREQ_ERROR_BADATTR        (APREQ_ERROR_BADDATA  +  3)
/** Invalid header. */
#define APREQ_ERROR_BADHEADER      (APREQ_ERROR_BADDATA  +  4)
/** Invalid utf8 encoding. */
#define APREQ_ERROR_BADUTF8        (APREQ_ERROR_BADDATA  +  5)

/** Missing input data. */
#define APREQ_ERROR_NODATA         (APREQ_ERROR_GENERAL  + 20)
/** Missing required token. */
#define APREQ_ERROR_NOTOKEN        (APREQ_ERROR_NODATA   +  1)
/** Missing attribute. */
#define APREQ_ERROR_NOATTR         (APREQ_ERROR_NODATA   +  2)
/** Missing header. */
#define APREQ_ERROR_NOHEADER       (APREQ_ERROR_NODATA   +  3)
/** Missing parser. */
#define APREQ_ERROR_NOPARSER       (APREQ_ERROR_NODATA   +  4)


/** Conflicting information. */
#define APREQ_ERROR_MISMATCH       (APREQ_ERROR_GENERAL  + 30)
/** Exceeds configured maximum limit. */
#define APREQ_ERROR_OVERLIMIT      (APREQ_ERROR_MISMATCH +  1)
/** Below configured minimum limit. */
#define APREQ_ERROR_UNDERLIMIT     (APREQ_ERROR_MISMATCH +  2)
/** Setting already configured. */
#define APREQ_ERROR_NOTEMPTY       (APREQ_ERROR_MISMATCH +  3)


#ifdef __cplusplus
 }
#endif

#endif /* APREQ_ERROR_H */

include/apreq_module.h

0 → 100644
+457 −0

File added.

Preview size limit exceeded, changes collapsed.

include/apreq_param.h

0 → 100644
+209 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading