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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @brief Apache script tools
21 * @defgroup APACHE_CORE_SCRIPT Script Tools
22 * @ingroup APACHE_CORE
26 #ifndef APACHE_UTIL_SCRIPT_H
27 #define APACHE_UTIL_SCRIPT_H
29 #include "apr_buckets.h"
30 #include "ap_config.h"
36 #ifndef APACHE_ARG_MAX
38 #define APACHE_ARG_MAX _POSIX_ARG_MAX
40 #define APACHE_ARG_MAX 512
45 * Create an environment variable out of an Apache table of key-value pairs
46 * @param p pool to allocate out of
47 * @param t Apache table of key-value pairs
48 * @return An array containing the same key-value pairs suitable for
49 * use with an exec call.
50 * @fn char **ap_create_environment(apr_pool_t *p, apr_table_t *t)
52 AP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t);
55 * This "cute" little function comes about because the path info on
56 * filenames and URLs aren't always the same. So we take the two,
57 * and find as much of the two that match as possible.
58 * @param uri The uri we are currently parsing
59 * @param path_info The current path info
60 * @return The length of the path info
61 * @fn int ap_find_path_info(const char *uri, const char *path_info)
63 AP_DECLARE(int) ap_find_path_info(const char *uri, const char *path_info);
66 * Add CGI environment variables required by HTTP/1.1 to the request's
68 * @param r the current request
69 * @fn void ap_add_cgi_vars(request_rec *r)
71 AP_DECLARE(void) ap_add_cgi_vars(request_rec *r);
74 * Add common CGI environment variables to the requests environment table
75 * @param r The current request
76 * @fn void ap_add_common_vars(request_rec *r)
78 AP_DECLARE(void) ap_add_common_vars(request_rec *r);
81 * Read headers output from a script, ensuring that the output is valid. If
82 * the output is valid, then the headers are added to the headers out of the
83 * current request. If the request method is GET or HEAD and the script's
84 * response will not meet the request's HTTP conditions, a conditional status
86 * @param r The current request
87 * @param f The file to read from
88 * @param buffer Empty when calling the function. On output, if there was an
89 * error, the string that cause the error is stored here.
90 * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR or other 5xx status
91 * code on failure, or a conditional status code (HTTP_NOT_MODIFIED or
92 * HTTP_PRECONDITION_FAILED) to indicate that the script's response does
93 * not meet the request's conditions
94 * @fn int ap_scan_script_header_err(request_rec *r, apr_file_t *f, char *buffer)
96 AP_DECLARE(int) ap_scan_script_header_err(request_rec *r, apr_file_t *f, char *buffer);
99 * Read headers output from a script, ensuring that the output is valid. If
100 * the output is valid, then the headers are added to the headers out of the
101 * current request. If the request method is GET or HEAD and the script's
102 * response will not meet the request's HTTP conditions, a conditional status
104 * @param r The current request
105 * @param f The file to read from
106 * @param buffer Empty when calling the function. On output, if there was an
107 * error, the string that cause the error is stored here.
108 * @param module_index The module index to be used for logging
109 * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR or other 5xx status
110 * code on failure, or a conditional status code (HTTP_NOT_MODIFIED or
111 * HTTP_PRECONDITION_FAILED) to indicate that the script's response does
112 * not meet the request's conditions
114 AP_DECLARE(int) ap_scan_script_header_err_ex(request_rec *r, apr_file_t *f,
115 char *buffer, int module_index);
119 * Read headers output from a script, ensuring that the output is valid. If
120 * the output is valid, then the headers are added to the headers out of the
121 * current request. If the request method is GET or HEAD and the script's
122 * response will not meet the request's HTTP conditions, a conditional status
124 * @param r The current request
125 * @param bb The brigade from which to read
126 * @param buffer Empty when calling the function. On output, if there was an
127 * error, the string that cause the error is stored here.
128 * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR or other 5xx status
129 * code on failure, or a conditional status code (HTTP_NOT_MODIFIED or
130 * HTTP_PRECONDITION_FAILED) to indicate that the script's response does
131 * not meet the request's conditions
132 * @fn int ap_scan_script_header_err_brigade(request_rec *r, apr_bucket_brigade *bb, char *buffer)
134 AP_DECLARE(int) ap_scan_script_header_err_brigade(request_rec *r,
135 apr_bucket_brigade *bb,
139 * Read headers output from a script, ensuring that the output is valid. If
140 * the output is valid, then the headers are added to the headers out of the
141 * current request. If the request method is GET or HEAD and the script's
142 * response will not meet the request's HTTP conditions, a conditional status
144 * @param r The current request
145 * @param bb The brigade from which to read
146 * @param buffer Empty when calling the function. On output, if there was an
147 * error, the string that cause the error is stored here.
148 * @param module_index The module index to be used for logging
149 * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR or other 5xx status
150 * code on failure, or a conditional status code (HTTP_NOT_MODIFIED or
151 * HTTP_PRECONDITION_FAILED) to indicate that the script's response does
152 * not meet the request's conditions
154 AP_DECLARE(int) ap_scan_script_header_err_brigade_ex(request_rec *r,
155 apr_bucket_brigade *bb,
160 * Read headers strings from a script, ensuring that the output is valid. If
161 * the output is valid, then the headers are added to the headers out of the
162 * current request. If the request method is GET or HEAD and the script's
163 * response will not meet the request's HTTP conditions, a conditional status
165 * @param r The current request
166 * @param buffer Empty when calling the function. On output, if there was an
167 * error, the string that cause the error is stored here.
168 * @param termch Pointer to the last character parsed.
169 * @param termarg Pointer to an int to capture the last argument parsed.
171 * The varargs are string arguments to parse consecutively for headers,
172 * with a NULL argument to terminate the list.
174 * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR or other 5xx status
175 * code on failure, or a conditional status code (HTTP_NOT_MODIFIED or
176 * HTTP_PRECONDITION_FAILED) to indicate that the script's response does
177 * not meet the request's conditions
179 AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs(request_rec *r,
186 * Read headers strings from a script, ensuring that the output is valid. If
187 * the output is valid, then the headers are added to the headers out of the
188 * current request. If the request method is GET or HEAD and the script's
189 * response will not meet the request's HTTP conditions, a conditional status
191 * @param r The current request
192 * @param buffer Empty when calling the function. On output, if there was an
193 * error, the string that cause the error is stored here.
194 * @param module_index The module index to be used for logging
195 * @param termch Pointer to the last character parsed.
196 * @param termarg Pointer to an int to capture the last argument parsed.
198 * The varargs are string arguments to parse consecutively for headers,
199 * with a NULL argument to terminate the list.
201 * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR or other 5xx status
202 * code on failure, or a conditional status code (HTTP_NOT_MODIFIED or
203 * HTTP_PRECONDITION_FAILED) to indicate that the script's response does
204 * not meet the request's conditions
206 AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs_ex(request_rec *r,
215 * Read headers output from a script, ensuring that the output is valid. If
216 * the output is valid, then the headers are added to the headers out of the
217 * current request. If the request method is GET or HEAD and the script's
218 * response will not meet the request's HTTP conditions, a conditional status
220 * @param r The current request
221 * @param buffer Empty when calling the function. On output, if there was an
222 * error, the string that cause the error is stored here.
223 * @param getsfunc Function to read the headers from. This function should
225 * @param getsfunc_data The place to read from
226 * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR or other 5xx status
227 * code on failure, or a conditional status code (HTTP_NOT_MODIFIED or
228 * HTTP_PRECONDITION_FAILED) to indicate that the script's response does
229 * not meet the request's conditions
231 AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer,
232 int (*getsfunc) (char *, int, void *),
233 void *getsfunc_data);
236 * Read headers output from a script, ensuring that the output is valid. If
237 * the output is valid, then the headers are added to the headers out of the
238 * current request. If the request method is GET or HEAD and the script's
239 * response will not meet the request's HTTP conditions, a conditional status
241 * @param r The current request
242 * @param buffer Empty when calling the function. On output, if there was an
243 * error, the string that cause the error is stored here.
244 * @param getsfunc Function to read the headers from. This function should
246 * @param getsfunc_data The place to read from
247 * @param module_index The module index to be used for logging
248 * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR or other 5xx status
249 * code on failure, or a conditional status code (HTTP_NOT_MODIFIED or
250 * HTTP_PRECONDITION_FAILED) to indicate that the script's response does
251 * not meet the request's conditions
253 AP_DECLARE(int) ap_scan_script_header_err_core_ex(request_rec *r, char *buffer,
254 int (*getsfunc) (char *, int, void *),
255 void *getsfunc_data, int module_index);
259 * Parse query args for the request and store in a new table allocated
260 * from the request pool.
261 * For args with no value, "1" will be used instead.
262 * If no query args were specified, the table will be empty.
263 * @param r The current request
264 * @param table A new table on output.
266 AP_DECLARE(void) ap_args_to_table(request_rec *r, apr_table_t **table);
272 #endif /* !APACHE_UTIL_SCRIPT_H */