]> granicus.if.org Git - apache/blob - include/util_script.h
3119e8be89166c42963f483200ad7e0dcaff04f5
[apache] / include / util_script.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file  util_script.h
19  * @brief Apache script tools
20  *
21  * @defgroup APACHE_CORE_SCRIPT Script Tools
22  * @ingroup  APACHE_CORE
23  * @{
24  */
25
26 #ifndef APACHE_UTIL_SCRIPT_H
27 #define APACHE_UTIL_SCRIPT_H
28
29 #include "apr_buckets.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #ifndef APACHE_ARG_MAX
36 #ifdef _POSIX_ARG_MAX
37 #define APACHE_ARG_MAX _POSIX_ARG_MAX
38 #else
39 #define APACHE_ARG_MAX 512
40 #endif
41 #endif
42
43 /**
44  * Create an environment variable out of an Apache table of key-value pairs
45  * @param p pool to allocate out of
46  * @param t Apache table of key-value pairs
47  * @return An array containing the same key-value pairs suitable for
48  *         use with an exec call.
49  * @fn char **ap_create_environment(apr_pool_t *p, apr_table_t *t)
50  */
51 AP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t);
52
53 /**
54  * This "cute" little function comes about because the path info on
55  * filenames and URLs aren't always the same. So we take the two,
56  * and find as much of the two that match as possible.
57  * @param uri The uri we are currently parsing
58  * @param path_info The current path info
59  * @return The length of the path info
60  * @fn int ap_find_path_info(const char *uri, const char *path_info)
61  */
62 AP_DECLARE(int) ap_find_path_info(const char *uri, const char *path_info);
63
64 /**
65  * Add CGI environment variables required by HTTP/1.1 to the request's 
66  * environment table
67  * @param r the current request
68  * @fn void ap_add_cgi_vars(request_rec *r)
69  */
70 AP_DECLARE(void) ap_add_cgi_vars(request_rec *r);
71
72 /**
73  * Add common CGI environment variables to the requests environment table
74  * @param r The current request
75  * @fn void ap_add_common_vars(request_rec *r)
76  */
77 AP_DECLARE(void) ap_add_common_vars(request_rec *r);
78
79 /**
80  * Read headers output from a script, ensuring that the output is valid.  If
81  * the output is valid, then the headers are added to the headers out of the
82  * current request
83  * @param r The current request
84  * @param f The file to read from
85  * @param buffer Empty when calling the function.  On output, if there was an
86  *               error, the string that cause the error is stored here. 
87  * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
88  * @fn int ap_scan_script_header_err(request_rec *r, apr_file_t *f, char *buffer)
89  */ 
90 AP_DECLARE(int) ap_scan_script_header_err(request_rec *r, apr_file_t *f, char *buffer);
91
92 /**
93  * Read headers output from a script, ensuring that the output is valid.  If
94  * the output is valid, then the headers are added to the headers out of the
95  * current request
96  * @param r The current request
97  * @param bb The brigade from which to read
98  * @param buffer Empty when calling the function.  On output, if there was an
99  *               error, the string that cause the error is stored here. 
100  * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
101  * @fn int ap_scan_script_header_err_brigade(request_rec *r, apr_bucket_brigade *bb, char *buffer)
102  */ 
103 AP_DECLARE(int) ap_scan_script_header_err_brigade(request_rec *r,
104                                                   apr_bucket_brigade *bb,
105                                                   char *buffer);
106
107 /**
108  * Read headers strings from a script, ensuring that the output is valid.  If
109  * the output is valid, then the headers are added to the headers out of the
110  * current request
111  * @param r The current request
112  * @param buffer Empty when calling the function.  On output, if there was an
113  *               error, the string that cause the error is stored here. 
114  * @param termch Pointer to the last character parsed.
115  * @param termarg Pointer to an int to capture the last argument parsed.
116  * 
117  * The varargs are string arguments to parse consecutively for headers, 
118  * with a NULL argument to terminate the list.
119  *
120  * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
121  */ 
122 AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs(request_rec *r, 
123                                                       char *buffer, 
124                                                       const char **termch,
125                                                       int *termarg, ...);
126
127 /**
128  * Read headers output from a script, ensuring that the output is valid.  If
129  * the output is valid, then the headers are added to the headers out of the
130  * current request
131  * @param r The current request
132  * @param buffer Empty when calling the function.  On output, if there was an
133  *               error, the string that cause the error is stored here. 
134  * @param getsfunc Function to read the headers from.  This function should
135                    act like gets()
136  * @param getsfunc_data The place to read from
137  * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
138  */ 
139 AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer,
140                                        int (*getsfunc) (char *, int, void *),
141                                        void *getsfunc_data);
142
143 /**
144  * Parse query args for the request and store in a new table allocated
145  * from the request pool.
146  * For args with no value, "1" will be used instead.
147  * If no query args were specified, the table will be empty.
148  * @param r The current request
149  * @param table A new table on output.
150  */
151 AP_DECLARE(void) ap_args_to_table(request_rec *r, apr_table_t **table);
152
153 #ifdef __cplusplus
154 }
155 #endif
156
157 #endif  /* !APACHE_UTIL_SCRIPT_H */
158 /** @} */