home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / linux / apache / contrib / modules / probably_obsolete / mod_actions.c next >
Encoding:
C/C++ Source or Header  |  1998-06-11  |  5.3 KB  |  162 lines

  1.  
  2. /* ====================================================================
  3.  * Copyright (c) 1995 The Apache Group.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer. 
  11.  *
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in
  14.  *    the documentation and/or other materials provided with the
  15.  *    distribution.
  16.  *
  17.  * 3. All advertising materials mentioning features or use of this
  18.  *    software must display the following acknowledgment:
  19.  *    "This product includes software developed by the Apache Group
  20.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  21.  *
  22.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  23.  *    endorse or promote products derived from this software without
  24.  *    prior written permission.
  25.  *
  26.  * 5. Redistributions of any form whatsoever must retain the following
  27.  *    acknowledgment:
  28.  *    "This product includes software developed by the Apache Group
  29.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  30.  *
  31.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  32.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  35.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  42.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  43.  * ====================================================================
  44.  *
  45.  * This software consists of voluntary contributions made by many
  46.  * individuals on behalf of the Apache Group and was originally based
  47.  * on public domain software written at the National Center for
  48.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  49.  * For more information on the Apache Group and the Apache HTTP server
  50.  * project, please see <http://www.apache.org/>.
  51.  *
  52.  */
  53.  
  54. /*
  55.  * mod_actions.c: executes scripts based on MIME type
  56.  *
  57.  * by Alexei Kosut; based on mod_cgi.c, mod_mime.c and mod_includes.c,
  58.  * adapted by rst from original NCSA code by Rob McCool
  59.  *
  60.  * Usage instructions:
  61.  *
  62.  * Action mime/type /cgi-bin/script
  63.  * 
  64.  * will activate /cgi-bin/script when a file of content type mime/type. It
  65.  * sends the URL and file path of the requested document using the standard
  66.  * CGI PATH_INFO and PATH_TRANSLATED environment variables.
  67.  *
  68.  */
  69.  
  70. #include "httpd.h"
  71. #include "http_config.h"
  72. #include "http_request.h"
  73. #include "http_core.h"
  74. #include "http_protocol.h"
  75. #include "http_main.h"
  76. #include "http_log.h"
  77. #include "util_script.h"
  78.  
  79. typedef struct {
  80.     table *action_types;    /* Added with Action... */
  81. } action_dir_config;
  82.  
  83. module action_module;
  84.  
  85. void *create_action_dir_config (pool *p, char *dummy)
  86. {
  87.     action_dir_config *new =
  88.       (action_dir_config *) palloc (p, sizeof(action_dir_config));
  89.  
  90.     new->action_types = make_table (p, 4);
  91.     
  92.     return new;
  93. }
  94.  
  95. void *merge_action_dir_configs (pool *p, void *basev, void *addv)
  96. {
  97.     action_dir_config *base = (action_dir_config *)basev;
  98.     action_dir_config *add = (action_dir_config *)addv;
  99.     action_dir_config *new =
  100.       (action_dir_config *)palloc (p, sizeof(action_dir_config));
  101.  
  102.     new->action_types = overlay_tables (p, add->action_types,
  103.                       base->action_types);
  104.  
  105.     return new;
  106. }
  107.  
  108. char *add_action(cmd_parms *cmd, action_dir_config *m, char *type, char *script)
  109. {
  110.     table_set (m->action_types, type, script);
  111.     return NULL;
  112. }
  113.  
  114. command_rec action_cmds[] = {
  115. { "Action", add_action, NULL, OR_FILEINFO, TAKE2, 
  116.     "a media type followed by a script name" },
  117. { NULL }
  118. };
  119.  
  120. int action_handler (request_rec *r)
  121. {
  122.     action_dir_config *conf =
  123.       (action_dir_config *)get_module_config(r->per_dir_config,&action_module);
  124.     char *t;
  125.  
  126.     if (!r->content_type ||
  127.     !(t = table_get(conf->action_types,  r->content_type)))
  128.       return DECLINED;
  129.  
  130.     if (r->finfo.st_mode == 0) {
  131.       log_reason("File does not exist", r->filename, r);
  132.       return NOT_FOUND;
  133.     }
  134.  
  135.     internal_redirect(pstrcat(r->pool, t, escape_uri(r->pool, r->uri),
  136.                   r->args ? "?" : NULL, r->args, NULL), r);
  137.     return OK;
  138. }
  139.  
  140. handler_rec action_handlers[] = {
  141. { "*/*", action_handler },
  142. { NULL }
  143. };
  144.  
  145. module action_module = {
  146.    STANDARD_MODULE_STUFF,
  147.    NULL,            /* initializer */
  148.    create_action_dir_config,    /* dir config creater */
  149.    merge_action_dir_configs,    /* dir merger --- default is to override */
  150.    NULL,            /* server config */
  151.    NULL,            /* merge server config */
  152.    action_cmds,            /* command table */
  153.    action_handlers,        /* handlers */
  154.    NULL,            /* filename translation */
  155.    NULL,            /* check_user_id */
  156.    NULL,            /* check auth */
  157.    NULL,            /* check access */
  158.    NULL,            /* type_checker */
  159.    NULL,            /* fixups */
  160.    NULL                /* logger */
  161. };
  162.