mod_actions.c revision 7c2df38555e33d4c30de9973722128cc9646a1b3
6ae232055d4d8a97267517c5e50074c2c819941and/* Licensed to the Apache Software Foundation (ASF) under one or more
6ae232055d4d8a97267517c5e50074c2c819941and * contributor license agreements. See the NOTICE file distributed with
6ae232055d4d8a97267517c5e50074c2c819941and * this work for additional information regarding copyright ownership.
6ae232055d4d8a97267517c5e50074c2c819941and * The ASF licenses this file to You under the Apache License, Version 2.0
6ae232055d4d8a97267517c5e50074c2c819941and * (the "License"); you may not use this file except in compliance with
6ae232055d4d8a97267517c5e50074c2c819941and * the License. You may obtain a copy of the License at
6ae232055d4d8a97267517c5e50074c2c819941and * Unless required by applicable law or agreed to in writing, software
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * distributed under the License is distributed on an "AS IS" BASIS,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * limitations under the License.
6ae232055d4d8a97267517c5e50074c2c819941and * mod_actions.c: executes scripts based on MIME type or HTTP method
6ae232055d4d8a97267517c5e50074c2c819941and * by Alexei Kosut; based on mod_cgi.c, mod_mime.c and mod_includes.c,
6ae232055d4d8a97267517c5e50074c2c819941and * adapted by rst from original NCSA code by Rob McCool
b43f840409794ed298e8634f6284741f193b6c4ftakashi * Usage instructions:
b43f840409794ed298e8634f6284741f193b6c4ftakashi * will activate /cgi-bin/script when a file of content type mime/type is
6ae232055d4d8a97267517c5e50074c2c819941and * requested. It sends the URL and file path of the requested document using
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * the standard CGI PATH_INFO and PATH_TRANSLATED environment variables.
b43f840409794ed298e8634f6284741f193b6c4ftakashi * Script PUT /cgi-bin/script
b43f840409794ed298e8634f6284741f193b6c4ftakashi * will activate /cgi-bin/script when a request is received with the
b43f840409794ed298e8634f6284741f193b6c4ftakashi * HTTP method "PUT". The available method names are defined in httpd.h.
6ae232055d4d8a97267517c5e50074c2c819941and * If the method is GET, the script will only be activated if the requested
6ae232055d4d8a97267517c5e50074c2c819941and * URI includes query information (stuff after a ?-mark).
6ae232055d4d8a97267517c5e50074c2c819941andtypedef struct {
6ae232055d4d8a97267517c5e50074c2c819941and const char *scripted[METHODS]; /* Added with Script... */
6ae232055d4d8a97267517c5e50074c2c819941and * called at least once
6ae232055d4d8a97267517c5e50074c2c819941andstatic void *create_action_dir_config(apr_pool_t *p, char *dummy)
6ae232055d4d8a97267517c5e50074c2c819941and (action_dir_config *) apr_pcalloc(p, sizeof(action_dir_config));
6ae232055d4d8a97267517c5e50074c2c819941andstatic void *merge_action_dir_configs(apr_pool_t *p, void *basev, void *addv)
6ae232055d4d8a97267517c5e50074c2c819941and action_dir_config *new = (action_dir_config *) apr_palloc(p,
6ae232055d4d8a97267517c5e50074c2c819941and new->action_types = apr_table_overlay(p, add->action_types,
6ae232055d4d8a97267517c5e50074c2c819941and for (i = 0; i < METHODS; ++i) {
6ae232055d4d8a97267517c5e50074c2c819941and const char *option)
6ae232055d4d8a97267517c5e50074c2c819941and apr_pstrcat(cmd->pool, option ? "1" : "0", script, NULL));
6ae232055d4d8a97267517c5e50074c2c819941and /* In .htaccess, we can't globally register new methods. */
6ae232055d4d8a97267517c5e50074c2c819941and /* ap_method_register recognizes already registered methods,
6ae232055d4d8a97267517c5e50074c2c819941and * so don't bother to check its previous existence explicitely.
6ae232055d4d8a97267517c5e50074c2c819941and return "TRACE not allowed for Script";
6ae232055d4d8a97267517c5e50074c2c819941and return apr_pstrcat(cmd->pool, "Could not register method '", method,
6ae232055d4d8a97267517c5e50074c2c819941and "a media type followed by a script name"),
6ae232055d4d8a97267517c5e50074c2c819941and AP_INIT_TAKE2("Script", set_script, NULL, ACCESS_CONF | RSRC_CONF,
6ae232055d4d8a97267517c5e50074c2c819941and "a method followed by a script name"),
6ae232055d4d8a97267517c5e50074c2c819941and ap_get_module_config(r->per_dir_config, &actions_module);
6ae232055d4d8a97267517c5e50074c2c819941and const char *t, *action;
6ae232055d4d8a97267517c5e50074c2c819941and const char *script;
6ae232055d4d8a97267517c5e50074c2c819941and /* Note that this handler handles _all_ types, so handler is unchecked */
6ae232055d4d8a97267517c5e50074c2c819941and /* Set allowed stuff */
6ae232055d4d8a97267517c5e50074c2c819941and for (i = 0; i < METHODS; ++i) {
6ae232055d4d8a97267517c5e50074c2c819941and /* First, check for the method-handling scripts */
6ae232055d4d8a97267517c5e50074c2c819941and /* Check for looping, which can happen if the CGI script isn't */
6ae232055d4d8a97267517c5e50074c2c819941and /* Second, check for actions (which override the method scripts) */
6ae232055d4d8a97267517c5e50074c2c819941and if (action && (t = apr_table_get(conf->action_types, action))) {
6ae232055d4d8a97267517c5e50074c2c819941and /* propagate the handler name to the script
6ae232055d4d8a97267517c5e50074c2c819941and * (will be REDIRECT_HANDLER there)
6ae232055d4d8a97267517c5e50074c2c819941and ap_internal_redirect_handler(apr_pstrcat(r->pool, script,
6ae232055d4d8a97267517c5e50074c2c819941and merge_action_dir_configs, /* dir merger --- default is to override */