mod_asis.c revision 70a2c0407879c11b29adc782d1665a0131f30b3f
2073N/A/* ====================================================================
2073N/A * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
2073N/A *
2073N/A * Redistribution and use in source and binary forms, with or without
2073N/A * modification, are permitted provided that the following conditions
2073N/A * are met:
2073N/A *
2073N/A * 1. Redistributions of source code must retain the above copyright
2073N/A * notice, this list of conditions and the following disclaimer.
2073N/A *
2073N/A * 2. Redistributions in binary form must reproduce the above copyright
2073N/A * notice, this list of conditions and the following disclaimer in
2073N/A * the documentation and/or other materials provided with the
2073N/A * distribution.
2073N/A *
2073N/A * 3. All advertising materials mentioning features or use of this
2073N/A * software must display the following acknowledgment:
2073N/A * "This product includes software developed by the Apache Group
2073N/A * for use in the Apache HTTP server project (http://www.apache.org/)."
2073N/A *
2073N/A * 4. The names "Apache Server" and "Apache Group" must not be used to
2073N/A * endorse or promote products derived from this software without
5680N/A * prior written permission. For written permission, please contact
2073N/A * apache@apache.org.
5680N/A *
2073N/A * 5. Products derived from this software may not be called "Apache"
2073N/A * nor may "Apache" appear in their names without prior written
2073N/A * permission of the Apache Group.
2073N/A *
2073N/A * 6. Redistributions of any form whatsoever must retain the following
2073N/A * acknowledgment:
2073N/A * "This product includes software developed by the Apache Group
2073N/A * for use in the Apache HTTP server project (http://www.apache.org/)."
2073N/A *
2899N/A * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
2899N/A * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5680N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
5680N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
2073N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3414N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
3414N/A * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2073N/A * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2073N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2073N/A * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5680N/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2073N/A * OF THE POSSIBILITY OF SUCH DAMAGE.
2073N/A * ====================================================================
2073N/A *
2073N/A * This software consists of voluntary contributions made by many
2073N/A * individuals on behalf of the Apache Group and was originally based
2073N/A * on public domain software written at the National Center for
5680N/A * Supercomputing Applications, University of Illinois, Urbana-Champaign.
2073N/A * For more information on the Apache Group and the Apache HTTP server
2073N/A * project, please see <http://www.apache.org/>.
5680N/A *
2073N/A */
2073N/A
2073N/A#include "httpd.h"
2073N/A#include "http_config.h"
2073N/A#include "http_protocol.h"
2073N/A#include "http_log.h"
3414N/A#include "util_script.h"
3414N/A#include "http_main.h"
3414N/A#include "http_request.h"
3414N/A
3414N/Astatic int asis_handler(request_rec *r)
2073N/A{
3414N/A ap_file_t *f;
3414N/A const char *location;
3414N/A FILE *thefile; /* XXX leave these alone until we convert */
3414N/A int thefd; /* everything to use apr_file_t's. */
3414N/A
3414N/A r->allowed |= (1 << M_GET);
3414N/A if (r->method_number != M_GET)
3414N/A return DECLINED;
3414N/A if (r->finfo.st_mode == 0) {
3414N/A ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
3414N/A "File does not exist: %s", r->filename);
3414N/A return NOT_FOUND;
3414N/A }
3414N/A
3588N/A if (ap_open(&f, r->pool, r->filename, APR_READ | APR_BUFFERED,
3588N/A APR_OS_DEFAULT) != APR_SUCCESS) {
3588N/A ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
3588N/A "file permissions deny server access: %s", r->filename);
4766N/A return FORBIDDEN;
4766N/A }
4766N/A
4766N/A ap_get_os_file(&thefd, f);
4766N/A thefile = fdopen(thefd, "r");
4766N/A
4766N/A ap_scan_script_header_err(r, thefile, NULL);
4766N/A location = ap_table_get(r->headers_out, "Location");
4766N/A
4766N/A if (location && location[0] == '/' &&
4766N/A ((r->status == HTTP_OK) || ap_is_HTTP_REDIRECT(r->status))) {
4766N/A
4766N/A ap_close(f);
4766N/A
4766N/A /* Internal redirect -- fake-up a pseudo-request */
4766N/A r->status = HTTP_OK;
4766N/A
4766N/A /* This redirect needs to be a GET no matter what the original
4766N/A * method was.
4766N/A */
2073N/A r->method = ap_pstrdup(r->pool, "GET");
3817N/A r->method_number = M_GET;
3817N/A
3817N/A ap_internal_redirect_handler(location, r);
return OK;
}
ap_send_http_header(r);
if (!r->header_only) {
ap_off_t zero = 0;
ap_seek(f, APR_CUR, &zero);
ap_send_fd(f, r);
}
ap_close(f);
return OK;
}
static const handler_rec asis_handlers[] =
{
{ASIS_MAGIC_TYPE, asis_handler},
{"send-as ap_context_t s", asis_handler},
{NULL}
};
module MODULE_VAR_EXPORT asis_module =
{
STANDARD20_MODULE_STUFF,
NULL, /* create per-directory config structure */
NULL, /* merge per-directory config structures */
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
NULL, /* command ap_table_t */
asis_handlers, /* handlers */
NULL /* register hooks */
};