home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / modules / standard / mod_asis.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-08  |  4.9 KB  |  146 lines

  1. /* ====================================================================
  2.  * Copyright (c) 1995-1999 The Apache Group.  All rights reserved.
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  *
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer. 
  10.  *
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in
  13.  *    the documentation and/or other materials provided with the
  14.  *    distribution.
  15.  *
  16.  * 3. All advertising materials mentioning features or use of this
  17.  *    software must display the following acknowledgment:
  18.  *    "This product includes software developed by the Apache Group
  19.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  20.  *
  21.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  22.  *    endorse or promote products derived from this software without
  23.  *    prior written permission. For written permission, please contact
  24.  *    apache@apache.org.
  25.  *
  26.  * 5. Products derived from this software may not be called "Apache"
  27.  *    nor may "Apache" appear in their names without prior written
  28.  *    permission of the Apache Group.
  29.  *
  30.  * 6. Redistributions of any form whatsoever must retain the following
  31.  *    acknowledgment:
  32.  *    "This product includes software developed by the Apache Group
  33.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  36.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  37.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  44.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  45.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  46.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Group and was originally based
  51.  * on public domain software written at the National Center for
  52.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  53.  * For more information on the Apache Group and the Apache HTTP server
  54.  * project, please see <http://www.apache.org/>.
  55.  *
  56.  */
  57.  
  58. #include "httpd.h"
  59. #include "http_config.h"
  60. #include "http_protocol.h"
  61. #include "http_log.h"
  62. #include "util_script.h"
  63. #include "http_main.h"
  64. #include "http_request.h"
  65.  
  66. static int asis_handler(request_rec *r)
  67. {
  68.     FILE *f;
  69.     const char *location;
  70.  
  71.     r->allowed |= (1 << M_GET);
  72.     if (r->method_number != M_GET)
  73.     return DECLINED;
  74.     if (r->finfo.st_mode == 0) {
  75.     ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
  76.             "File does not exist: %s", r->filename);
  77.     return NOT_FOUND;
  78.     }
  79.  
  80.     f = ap_pfopen(r->pool, r->filename, "r");
  81.  
  82.     if (f == NULL) {
  83.     ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
  84.             "file permissions deny server access: %s", r->filename);
  85.     return FORBIDDEN;
  86.     }
  87.  
  88.     ap_scan_script_header_err(r, f, NULL);
  89.     location = ap_table_get(r->headers_out, "Location");
  90.  
  91.     if (location && location[0] == '/' &&
  92.     ((r->status == HTTP_OK) || ap_is_HTTP_REDIRECT(r->status))) {
  93.  
  94.     ap_pfclose(r->pool, f);
  95.  
  96.     /* Internal redirect -- fake-up a pseudo-request */
  97.     r->status = HTTP_OK;
  98.  
  99.     /* This redirect needs to be a GET no matter what the original
  100.      * method was.
  101.      */
  102.     r->method = ap_pstrdup(r->pool, "GET");
  103.     r->method_number = M_GET;
  104.  
  105.     ap_internal_redirect_handler(location, r);
  106.     return OK;
  107.     }
  108.  
  109.     ap_send_http_header(r);
  110.     if (!r->header_only)
  111.     ap_send_fd(f, r);
  112.  
  113.     ap_pfclose(r->pool, f);
  114.     return OK;
  115. }
  116.  
  117. static const handler_rec asis_handlers[] =
  118. {
  119.     {ASIS_MAGIC_TYPE, asis_handler},
  120.     {"send-as-is", asis_handler},
  121.     {NULL}
  122. };
  123.  
  124. module MODULE_VAR_EXPORT asis_module =
  125. {
  126.     STANDARD_MODULE_STUFF,
  127.     NULL,            /* initializer */
  128.     NULL,            /* create per-directory config structure */
  129.     NULL,            /* merge per-directory config structures */
  130.     NULL,            /* create per-server config structure */
  131.     NULL,            /* merge per-server config structures */
  132.     NULL,            /* command table */
  133.     asis_handlers,        /* handlers */
  134.     NULL,            /* translate_handler */
  135.     NULL,            /* check_user_id */
  136.     NULL,            /* check auth */
  137.     NULL,            /* check access */
  138.     NULL,            /* type_checker */
  139.     NULL,            /* pre-run fixups */
  140.     NULL,            /* logger */
  141.     NULL,            /* header parser */
  142.     NULL,            /* child_init */
  143.     NULL,            /* child_exit */
  144.     NULL            /* post read-request */
  145. };
  146.