00001 /* Copyright 1999-2005 The Apache Software Foundation or its licensors, as 00002 * applicable. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef APACHE_HTTP_REQUEST_H 00018 #define APACHE_HTTP_REQUEST_H 00019 00020 #include "apr_hooks.h" 00021 #include "util_filter.h" 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 #define AP_SUBREQ_NO_ARGS 0 00028 #define AP_SUBREQ_MERGE_ARGS 1 00029 00030 /** 00031 * @file http_request.h 00032 * @brief Apache Request library 00033 */ 00034 00035 /* http_request.c is the code which handles the main line of request 00036 * processing, once a request has been read in (finding the right per- 00037 * directory configuration, building it if necessary, and calling all 00038 * the module dispatch functions in the right order). 00039 * 00040 * The pieces here which are public to the modules, allow them to learn 00041 * how the server would handle some other file or URI, or perhaps even 00042 * direct the server to serve that other file instead of the one the 00043 * client requested directly. 00044 * 00045 * There are two ways to do that. The first is the sub_request mechanism, 00046 * which handles looking up files and URIs as adjuncts to some other 00047 * request (e.g., directory entries for multiviews and directory listings); 00048 * the lookup functions stop short of actually running the request, but 00049 * (e.g., for includes), a module may call for the request to be run 00050 * by calling run_sub_req. The space allocated to create sub_reqs can be 00051 * reclaimed by calling destroy_sub_req --- be sure to copy anything you care 00052 * about which was allocated in its apr_pool_t elsewhere before doing this. 00053 */ 00054 00055 /** 00056 * An internal handler used by the ap_process_request, all subrequest mechanisms 00057 * and the redirect mechanism. 00058 * @param r The request, subrequest or internal redirect to pre-process 00059 * @return The return code for the request 00060 */ 00061 AP_DECLARE(int) ap_process_request_internal(request_rec *r); 00062 00063 /** 00064 * Create a subrequest from the given URI. This subrequest can be 00065 * inspected to find information about the requested URI 00066 * @param new_uri The URI to lookup 00067 * @param r The current request 00068 * @param next_filter The first filter the sub_request should use. If this is 00069 * NULL, it defaults to the first filter for the main request 00070 * @return The new request record 00071 * @deffunc request_rec * ap_sub_req_lookup_uri(const char *new_uri, const request_rec *r) 00072 */ 00073 AP_DECLARE(request_rec *) ap_sub_req_lookup_uri(const char *new_uri, 00074 const request_rec *r, 00075 ap_filter_t *next_filter); 00076 00077 /** 00078 * Create a subrequest for the given file. This subrequest can be 00079 * inspected to find information about the requested file 00080 * @param new_file The file to lookup 00081 * @param r The current request 00082 * @param next_filter The first filter the sub_request should use. If this is 00083 * NULL, it defaults to the first filter for the main request 00084 * @return The new request record 00085 * @deffunc request_rec * ap_sub_req_lookup_file(const char *new_file, const request_rec *r) 00086 */ 00087 AP_DECLARE(request_rec *) ap_sub_req_lookup_file(const char *new_file, 00088 const request_rec *r, 00089 ap_filter_t *next_filter); 00090 /** 00091 * Create a subrequest for the given apr_dir_read result. This subrequest 00092 * can be inspected to find information about the requested file 00093 * @param finfo The apr_dir_read result to lookup 00094 * @param r The current request 00095 * @param subtype What type of subrequest to perform, one of; 00096 * <PRE> 00097 * AP_SUBREQ_NO_ARGS ignore r->args and r->path_info 00098 * AP_SUBREQ_MERGE_ARGS merge r->args and r->path_info 00099 * </PRE> 00100 * @param next_filter The first filter the sub_request should use. If this is 00101 * NULL, it defaults to the first filter for the main request 00102 * @return The new request record 00103 * @deffunc request_rec * ap_sub_req_lookup_dirent(apr_finfo_t *finfo, int subtype, const request_rec *r) 00104 * @tip The apr_dir_read flags value APR_FINFO_MIN|APR_FINFO_NAME flag is the 00105 * minimum recommended query if the results will be passed to apr_dir_read. 00106 * The file info passed must include the name, and must have the same relative 00107 * directory as the current request. 00108 */ 00109 AP_DECLARE(request_rec *) ap_sub_req_lookup_dirent(const apr_finfo_t *finfo, 00110 const request_rec *r, 00111 int subtype, 00112 ap_filter_t *next_filter); 00113 /** 00114 * Create a subrequest for the given URI using a specific method. This 00115 * subrequest can be inspected to find information about the requested URI 00116 * @param method The method to use in the new subrequest 00117 * @param new_uri The URI to lookup 00118 * @param r The current request 00119 * @param next_filter The first filter the sub_request should use. If this is 00120 * NULL, it defaults to the first filter for the main request 00121 * @return The new request record 00122 * @deffunc request_rec * ap_sub_req_method_uri(const char *method, const char *new_uri, const request_rec *r) 00123 */ 00124 AP_DECLARE(request_rec *) ap_sub_req_method_uri(const char *method, 00125 const char *new_uri, 00126 const request_rec *r, 00127 ap_filter_t *next_filter); 00128 /** 00129 * An output filter to strip EOS buckets from sub-requests. This always 00130 * has to be inserted at the end of a sub-requests filter stack. 00131 * @param f The current filter 00132 * @param bb The brigade to filter 00133 * @deffunc apr_status_t ap_sub_req_output_filter(ap_filter_t *f, apr_bucket_brigade *bb) 00134 */ 00135 AP_CORE_DECLARE_NONSTD(apr_status_t) ap_sub_req_output_filter(ap_filter_t *f, 00136 apr_bucket_brigade *bb); 00137 00138 /** 00139 * Run the handler for the subrequest 00140 * @param r The subrequest to run 00141 * @return The return code for the subrequest 00142 * @deffunc int ap_run_sub_req(request_rec *r) 00143 */ 00144 AP_DECLARE(int) ap_run_sub_req(request_rec *r); 00145 00146 /** 00147 * Free the memory associated with a subrequest 00148 * @param r The subrequest to finish 00149 * @deffunc void ap_destroy_sub_req(request_rec *r) 00150 */ 00151 AP_DECLARE(void) ap_destroy_sub_req(request_rec *r); 00152 00153 /* 00154 * Then there's the case that you want some other request to be served 00155 * as the top-level request INSTEAD of what the client requested directly. 00156 * If so, call this from a handler, and then immediately return OK. 00157 */ 00158 00159 /** 00160 * Redirect the current request to some other uri 00161 * @param new_uri The URI to replace the current request with 00162 * @param r The current request 00163 * @deffunc void ap_internal_redirect(const char *new_uri, request_rec *r) 00164 */ 00165 AP_DECLARE(void) ap_internal_redirect(const char *new_uri, request_rec *r); 00166 00167 /** 00168 * This function is designed for things like actions or CGI scripts, when 00169 * using AddHandler, and you want to preserve the content type across 00170 * an internal redirect. 00171 * @param new_uri The URI to replace the current request with. 00172 * @param r The current request 00173 * @deffunc void ap_internal_redirect_handler(const char *new_uri, request_rec *r) 00174 */ 00175 AP_DECLARE(void) ap_internal_redirect_handler(const char *new_uri, request_rec *r); 00176 00177 /** 00178 * Redirect the current request to a sub_req, merging the pools 00179 * @param sub_req A subrequest created from this request 00180 * @param r The current request 00181 * @deffunc void ap_internal_fast_redirect(request_rec *sub_req, request_rec *r) 00182 * @tip the sub_req's pool will be merged into r's pool, be very careful 00183 * not to destroy this subrequest, it will be destroyed with the main request! 00184 */ 00185 AP_DECLARE(void) ap_internal_fast_redirect(request_rec *sub_req, request_rec *r); 00186 00187 /** 00188 * Can be used within any handler to determine if any authentication 00189 * is required for the current request 00190 * @param r The current request 00191 * @return 1 if authentication is required, 0 otherwise 00192 * @deffunc int ap_some_auth_required(request_rec *r) 00193 */ 00194 AP_DECLARE(int) ap_some_auth_required(request_rec *r); 00195 00196 /** 00197 * Determine if the current request is the main request or a subrequest 00198 * @param r The current request 00199 * @return 1 if this is the main request, 0 otherwise 00200 * @deffunc int ap_is_initial_req(request_rec *r) 00201 */ 00202 AP_DECLARE(int) ap_is_initial_req(request_rec *r); 00203 00204 /** 00205 * Function to set the r->mtime field to the specified value if it's later 00206 * than what's already there. 00207 * @param r The current request 00208 * @param dependency_time Time to set the mtime to 00209 * @deffunc void ap_update_mtime(request_rec *r, apr_time_t dependency_mtime) 00210 */ 00211 AP_DECLARE(void) ap_update_mtime(request_rec *r, apr_time_t dependency_mtime); 00212 00213 /** 00214 * Add one or more methods to the list permitted to access the resource. 00215 * Usually executed by the content handler before the response header is 00216 * sent, but sometimes invoked at an earlier phase if a module knows it 00217 * can set the list authoritatively. Note that the methods are ADDED 00218 * to any already permitted unless the reset flag is non-zero. The 00219 * list is used to generate the Allow response header field when it 00220 * is needed. 00221 * @param r The pointer to the request identifying the resource. 00222 * @param reset Boolean flag indicating whether this list should 00223 * completely replace any current settings. 00224 * @param ... A NULL-terminated list of strings, each identifying a 00225 * method name to add. 00226 * @return None. 00227 * @deffunc void ap_allow_methods(request_rec *r, int reset, ...) 00228 */ 00229 AP_DECLARE(void) ap_allow_methods(request_rec *r, int reset, ...); 00230 00231 /** 00232 * Add one or more methods to the list permitted to access the resource. 00233 * Usually executed by the content handler before the response header is 00234 * sent, but sometimes invoked at an earlier phase if a module knows it 00235 * can set the list authoritatively. Note that the methods are ADDED 00236 * to any already permitted unless the reset flag is non-zero. The 00237 * list is used to generate the Allow response header field when it 00238 * is needed. 00239 * @param r The pointer to the request identifying the resource. 00240 * @param reset Boolean flag indicating whether this list should 00241 * completely replace any current settings. 00242 * @param ... A list of method identifiers, from the "M_" series 00243 * defined in httpd.h, terminated with a value of -1 00244 * (e.g., "M_GET, M_POST, M_OPTIONS, -1") 00245 * @return None. 00246 * @deffunc void ap_allow_standard_methods(request_rec *r, int reset, ...) 00247 */ 00248 AP_DECLARE(void) ap_allow_standard_methods(request_rec *r, int reset, ...); 00249 00250 #define MERGE_ALLOW 0 00251 #define REPLACE_ALLOW 1 00252 00253 #ifdef CORE_PRIVATE 00254 /* Function called by main.c to handle first-level request */ 00255 void ap_process_request(request_rec *); 00256 /** 00257 * Kill the current request 00258 * @param type Why the request is dieing 00259 * @param r The current request 00260 * @deffunc void ap_die(int type, request_rec *r) 00261 */ 00262 AP_DECLARE(void) ap_die(int type, request_rec *r); 00263 #endif 00264 00265 /* Hooks */ 00266 00267 /** 00268 * Gives modules a chance to create their request_config entry when the 00269 * request is created. 00270 * @param r The current request 00271 * @ingroup hooks 00272 */ 00273 AP_DECLARE_HOOK(int,create_request,(request_rec *r)) 00274 00275 /** 00276 * This hook allow modules an opportunity to translate the URI into an 00277 * actual filename. If no modules do anything special, the server's default 00278 * rules will be followed. 00279 * @param r The current request 00280 * @return OK, DECLINED, or HTTP_... 00281 * @ingroup hooks 00282 */ 00283 AP_DECLARE_HOOK(int,translate_name,(request_rec *r)) 00284 00285 /** 00286 * This hook allow modules to set the per_dir_config based on their own 00287 * context (such as <Proxy > sections) and responds to contextless requests 00288 * such as TRACE that need no security or filesystem mapping. 00289 * based on the filesystem. 00290 * @param r The current request 00291 * @return DONE (or HTTP_) if this contextless request was just fulfilled 00292 * (such as TRACE), OK if this is not a file, and DECLINED if this is a file. 00293 * The core map_to_storage (HOOK_RUN_REALLY_LAST) will directory_walk 00294 * and file_walk the r->filename. 00295 * 00296 * @ingroup hooks 00297 */ 00298 AP_DECLARE_HOOK(int,map_to_storage,(request_rec *r)) 00299 00300 /** 00301 * This hook is used to analyze the request headers, authenticate the user, 00302 * and set the user information in the request record (r->user and 00303 * r->ap_auth_type). This hook is only run when Apache determines that 00304 * authentication/authorization is required for this resource (as determined 00305 * by the 'Require' directive). It runs after the access_checker hook, and 00306 * before the auth_checker hook. 00307 * 00308 * @param r The current request 00309 * @return OK, DECLINED, or HTTP_... 00310 * @ingroup hooks 00311 */ 00312 AP_DECLARE_HOOK(int,check_user_id,(request_rec *r)) 00313 00314 /** 00315 * Allows modules to perform module-specific fixing of header fields. This 00316 * is invoked just before any content-handler 00317 * @param r The current request 00318 * @return OK, DECLINED, or HTTP_... 00319 * @ingroup hooks 00320 */ 00321 AP_DECLARE_HOOK(int,fixups,(request_rec *r)) 00322 00323 /** 00324 * This routine is called to determine and/or set the various document type 00325 * information bits, like Content-type (via r->content_type), language, et 00326 * cetera. 00327 * @param r the current request 00328 * @return OK, DECLINED, or HTTP_... 00329 * @ingroup hooks 00330 */ 00331 AP_DECLARE_HOOK(int,type_checker,(request_rec *r)) 00332 00333 /** 00334 * This hook is used to apply additional access control to this resource. 00335 * It runs *before* a user is authenticated, so this hook is really to 00336 * apply additional restrictions independent of a user. It also runs 00337 * independent of 'Require' directive usage. 00338 * 00339 * @param r the current request 00340 * @return OK, DECLINED, or HTTP_... 00341 * @ingroup hooks 00342 */ 00343 AP_DECLARE_HOOK(int,access_checker,(request_rec *r)) 00344 00345 /** 00346 * This hook is used to check to see if the resource being requested 00347 * is available for the authenticated user (r->user and r->ap_auth_type). 00348 * It runs after the access_checker and check_user_id hooks. Note that 00349 * it will *only* be called if Apache determines that access control has 00350 * been applied to this resource (through a 'Require' directive). 00351 * 00352 * @param r the current request 00353 * @return OK, DECLINED, or HTTP_... 00354 * @ingroup hooks 00355 */ 00356 AP_DECLARE_HOOK(int,auth_checker,(request_rec *r)) 00357 00358 /** 00359 * This hook allows modules to insert filters for the current request 00360 * @param r the current request 00361 * @ingroup hooks 00362 */ 00363 AP_DECLARE_HOOK(void,insert_filter,(request_rec *r)) 00364 00365 AP_DECLARE(int) ap_location_walk(request_rec *r); 00366 AP_DECLARE(int) ap_directory_walk(request_rec *r); 00367 AP_DECLARE(int) ap_file_walk(request_rec *r); 00368 00369 #ifdef __cplusplus 00370 } 00371 #endif 00372 00373 #endif /* !APACHE_HTTP_REQUEST_H */