util_script.h revision 3d96ee83babeec32482c9082c9426340cee8c44d
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen/* ====================================================================
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * The Apache Software License, Version 1.1
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen *
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Copyright (c) 2000 The Apache Software Foundation. All rights
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * reserved.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen *
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Redistribution and use in source and binary forms, with or without
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * modification, are permitted provided that the following conditions
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * are met:
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen *
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * 1. Redistributions of source code must retain the above copyright
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * notice, this list of conditions and the following disclaimer.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen *
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * 2. Redistributions in binary form must reproduce the above copyright
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * notice, this list of conditions and the following disclaimer in
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * the documentation and/or other materials provided with the
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * distribution.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen *
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * 3. The end-user documentation included with the redistribution,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * if any, must include the following acknowledgment:
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * "This product includes software developed by the
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Apache Software Foundation (http://www.apache.org/)."
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Alternately, this acknowledgment may appear in the software itself,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * if and wherever such third-party acknowledgments normally appear.
f60e98b33646e7a3317553e13bac591a98ce41c0Lukasz Skalski *
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * 4. The names "Apache" and "Apache Software Foundation" must
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * not be used to endorse or promote products derived from this
39d8db043b599a7382f94bfc904d5e108af438bdLennart Poettering * software without prior written permission. For written
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * permission, please contact apache@apache.org.
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering *
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * 5. Products derived from this software may not be called "Apache",
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * nor may "Apache" appear in their name, without prior written
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * permission of the Apache Software Foundation.
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen *
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * SUCH DAMAGE.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * ====================================================================
a5a807e63a50314e190e9166d8a453cd8dd258e3Zbigniew Jędrzejewski-Szmek *
a5a807e63a50314e190e9166d8a453cd8dd258e3Zbigniew Jędrzejewski-Szmek * This software consists of voluntary contributions made by many
cc56fafeebf814ef035e549115cf1850e6473fa5WaLyong Cho * individuals on behalf of the Apache Software Foundation. For more
a5a807e63a50314e190e9166d8a453cd8dd258e3Zbigniew Jędrzejewski-Szmek * information on the Apache Software Foundation, please see
a5a807e63a50314e190e9166d8a453cd8dd258e3Zbigniew Jędrzejewski-Szmek * <http://www.apache.org/>.
a5a807e63a50314e190e9166d8a453cd8dd258e3Zbigniew Jędrzejewski-Szmek *
a5a807e63a50314e190e9166d8a453cd8dd258e3Zbigniew Jędrzejewski-Szmek * Portions of this software are based upon public domain software
a5a807e63a50314e190e9166d8a453cd8dd258e3Zbigniew Jędrzejewski-Szmek * originally written at the National Center for Supercomputing Applications,
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * University of Illinois, Urbana-Champaign.
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen */
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#ifndef APACHE_UTIL_SCRIPT_H
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen#define APACHE_UTIL_SCRIPT_H
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#ifdef __cplusplus
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersenextern "C" {
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen#endif
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/**
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * @package Apache script tools
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen */
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen#ifndef APACHE_ARG_MAX
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#ifdef _POSIX_ARG_MAX
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#define APACHE_ARG_MAX _POSIX_ARG_MAX
b9e7a9d870ac41d4db954edd52a1f5dd7d153389Lennart Poettering#else
b9e7a9d870ac41d4db954edd52a1f5dd7d153389Lennart Poettering#define APACHE_ARG_MAX 512
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#endif
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#endif
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/**
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Create an environment variable out of an Apache table of key-value pairs
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * @param p pool to allocate out of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * @param t Apache table of key-value pairs
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * @return An array containing the same key-value pairs suitable for
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * use with an exec call.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * @deffunc char **ap_create_environment(apr_pool_t *p, apr_table_t *t)
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering */
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart PoetteringAP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t);
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering/**
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering * This "cute" little function comes about because the path info on
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering * filenames and URLs aren't always the same. So we take the two,
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * and find as much of the two that match as possible.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * @param uri The uri we are currently parsing
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * @param path_info The current path info
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * @return The length of the path info
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * @deffunc int ap_fine_path_info(const char *uri, const char *path_info)
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen */
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenAP_DECLARE(int) ap_find_path_info(const char *uri, const char *path_info);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen/**
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Add CGI environment variables required by HTTP/1.1 to the request's
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * environment table
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * @param r the current request
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * @deffunc void ap_add_cgi_vars(request_rec *r)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering */
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenAP_DECLARE(void) ap_add_cgi_vars(request_rec *r);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
96e6e394431dcc1db52847be311e2c8e61d7a9d6Lennart Poettering/**
96e6e394431dcc1db52847be311e2c8e61d7a9d6Lennart Poettering * Add common CGI environment variables to the requests environment table
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * @param r The current request
af4ec4309e8f82aad87a8d574785c12f8763d5f8Lennart Poettering * @deffunc void ap_add_common_vars(request_rec *r)
b37d45c9ab5f645502695e47d268af1a54216e0eTom Gundersen */
af4ec4309e8f82aad87a8d574785c12f8763d5f8Lennart PoetteringAP_DECLARE(void) ap_add_common_vars(request_rec *r);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen/**
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Read headers output from a script, ensuring that the output is valid. If
* the output is valid, then the headers are added to the headers out of the
* current request
* @param r The current request
* @param f The file to read from
* @param buffer Empty when calling the function. On output, if there was an
* error, the string that cause the error is stored here.
* @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
* @deffunc int ap_scan_script_header_err(request_rec *r, apr_file_t *f, char *buffer)
*/
AP_DECLARE(int) ap_scan_script_header_err(request_rec *r, apr_file_t *f, char *buffer);
/**
* Read headers strings from a script, ensuring that the output is valid. If
* the output is valid, then the headers are added to the headers out of the
* current request
* @param r The current request
* @param buffer Empty when calling the function. On output, if there was an
* error, the string that cause the error is stored here.
* @param termch Pointer to the last character parsed.
* @param termarg Pointer to an int to capture the last argument parsed.
* @param args String arguments to parse consecutively for headers,
* a NULL argument terminates the list.
* @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
* @deffunc int ap_scan_script_header_err_core(request_rec *r, char *buffer, int (*getsfunc)(char *, int, void *), void *getsfunc_data)
*/
AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs(request_rec *r,
char *buffer,
const char **termch,
int *termarg, ...);
/**
* Read headers output from a script, ensuring that the output is valid. If
* the output is valid, then the headers are added to the headers out of the
* current request
* @param r The current request
* @param buffer Empty when calling the function. On output, if there was an
* error, the string that cause the error is stored here.
* @param getsfunc Function to read the headers from. This function should
act like gets()
* @param getsfunc_data The place to read from
* @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
* @deffunc int ap_scan_script_header_err_core(request_rec *r, char *buffer, int (*getsfunc)(char *, int, void *), void *getsfunc_data)
*/
AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer,
int (*getsfunc) (char *, int, void *),
void *getsfunc_data);
/**
* Convert the file size given in size into a formatted string and send the
* string to the client. The size should always be in bytes, although the
* string sent to the client may be in bytes, kb, or MB, depending on the size
* of the file.
* @param size The size of the file
* @param r The currnt request
* @deffunc void ap_send_size(apr_ssize_t size, request_rec *r)
*/
AP_DECLARE(void) ap_send_size(apr_ssize_t size, request_rec *r);
#ifdef __cplusplus
}
#endif
#endif /* !APACHE_UTIL_SCRIPT_H */