home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / share / os2 / varios / apache / mod_asis.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-16  |  4.4 KB  |  129 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. #include "httpd.h"
  56. #include "http_config.h"
  57. #include "http_protocol.h"
  58. #include "http_log.h"
  59. #include "util_script.h"
  60. #include "http_main.h"
  61. #include "http_request.h"
  62.  
  63. int asis_handler (request_rec *r)
  64. {
  65.     FILE *f;
  66.     char *location;
  67.     
  68.     if (r->method_number != M_GET) return DECLINED;
  69.     if (r->finfo.st_mode == 0) {
  70.     log_reason("File does not exist", r->filename, r);
  71.     return NOT_FOUND;
  72.     }
  73.     
  74.     f = fopen (r->filename, "r");
  75.  
  76.     if (f == NULL) {
  77.         log_reason("file permissions deny server access", r->filename, r);
  78.         return FORBIDDEN;
  79.     }
  80.       
  81.     scan_script_header (r, f);
  82.     location = table_get (r->headers_out, "Location");
  83.  
  84.     if (location && location[0] == '/' && 
  85.         (r->status == 200 || r->status == 301 || r->status == 302)) {
  86.  
  87.         r->status = 200; /* Assume 200 status on whatever we're pointing to */
  88.  
  89.     /* This redirect needs to be a GET no matter what the original
  90.      * method was.
  91.     */
  92.     r->method = pstrdup(r->pool, "GET");
  93.     r->method_number = M_GET;
  94.  
  95.     internal_redirect_handler (location, r);
  96.     return OK;
  97.     }
  98.     
  99.     soft_timeout ("send", r);
  100.     send_http_header (r);
  101.     if (!r->header_only) send_fd (f, r);
  102.     fclose (f);
  103.     return OK;
  104. }
  105.  
  106. handler_rec asis_handlers[] = {
  107. { ASIS_MAGIC_TYPE, asis_handler },
  108. { "send-as-is", asis_handler },
  109. { NULL }
  110. };
  111.  
  112. module asis_module = {
  113.    STANDARD_MODULE_STUFF,
  114.    NULL,            /* initializer */
  115.    NULL,            /* create per-directory config structure */
  116.    NULL,            /* merge per-directory config structures */
  117.    NULL,            /* create per-server config structure */
  118.    NULL,            /* merge per-server config structures */
  119.    NULL,            /* command table */
  120.    asis_handlers,        /* handlers */
  121.    NULL,            /* translate_handler */
  122.    NULL,            /* check_user_id */
  123.    NULL,            /* check auth */
  124.    NULL,            /* check access */
  125.    NULL,            /* type_checker */
  126.    NULL,            /* pre-run fixups */
  127.    NULL                /* logger */
  128. };
  129.