/* ====================================================================
- * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
- * 3. All advertising materials mentioning features or use of this
- * software must display the following acknowledgment:
- * "This product includes software developed by the Apache Group
- * for use in the Apache HTTP server project (http://www.apache.org/)."
- *
- * 4. The names "Apache Server" and "Apache Group" must not be used to
- * endorse or promote products derived from this software without
- * prior written permission. For written permission, please contact
- * apache@apache.org.
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
*
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
*
- * 6. Redistributions of any form whatsoever must retain the following
- * acknowledgment:
- * "This product includes software developed by the Apache Group
- * for use in the Apache HTTP server project (http://www.apache.org/)."
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
*
- * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
- * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Group and was originally based
- * on public domain software written at the National Center for
- * Supercomputing Applications, University of Illinois, Urbana-Champaign.
- * For more information on the Apache Group and the Apache HTTP server
- * project, please see <http://www.apache.org/>.
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
*
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
*/
/*
*
*/
+#include "apr_strings.h"
+#include "apr_lib.h"
+
+#define APR_WANT_STRFUNC
+#include "apr_want.h"
+
+#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
+#include "http_request.h"
+
typedef struct {
- char *real;
- char *fake;
+ const char *real;
+ const char *fake;
char *handler;
regex_t *regexp;
int redir_status; /* 301, 302, 303, 410, etc */
} alias_entry;
typedef struct {
- array_header *aliases;
- array_header *redirects;
+ apr_array_header_t *aliases;
+ apr_array_header_t *redirects;
} alias_server_conf;
typedef struct {
- array_header *redirects;
+ apr_array_header_t *redirects;
} alias_dir_conf;
-module MODULE_VAR_EXPORT alias_module;
+module AP_MODULE_DECLARE_DATA alias_module;
-static void *create_alias_config(pool *p, server_rec *s)
+static void *create_alias_config(apr_pool_t *p, server_rec *s)
{
alias_server_conf *a =
- (alias_server_conf *) ap_pcalloc(p, sizeof(alias_server_conf));
+ (alias_server_conf *) apr_pcalloc(p, sizeof(alias_server_conf));
- a->aliases = ap_make_array(p, 20, sizeof(alias_entry));
- a->redirects = ap_make_array(p, 20, sizeof(alias_entry));
+ a->aliases = apr_array_make(p, 20, sizeof(alias_entry));
+ a->redirects = apr_array_make(p, 20, sizeof(alias_entry));
return a;
}
-static void *create_alias_dir_config(pool *p, char *d)
+static void *create_alias_dir_config(apr_pool_t *p, char *d)
{
alias_dir_conf *a =
- (alias_dir_conf *) ap_pcalloc(p, sizeof(alias_dir_conf));
- a->redirects = ap_make_array(p, 2, sizeof(alias_entry));
+ (alias_dir_conf *) apr_pcalloc(p, sizeof(alias_dir_conf));
+ a->redirects = apr_array_make(p, 2, sizeof(alias_entry));
return a;
}
-static void *merge_alias_config(pool *p, void *basev, void *overridesv)
+static void *merge_alias_config(apr_pool_t *p, void *basev, void *overridesv)
{
alias_server_conf *a =
- (alias_server_conf *) ap_pcalloc(p, sizeof(alias_server_conf));
+ (alias_server_conf *) apr_pcalloc(p, sizeof(alias_server_conf));
alias_server_conf *base = (alias_server_conf *) basev, *overrides = (alias_server_conf *) overridesv;
- a->aliases = ap_append_arrays(p, overrides->aliases, base->aliases);
- a->redirects = ap_append_arrays(p, overrides->redirects, base->redirects);
+ a->aliases = apr_array_append(p, overrides->aliases, base->aliases);
+ a->redirects = apr_array_append(p, overrides->redirects, base->redirects);
return a;
}
-static void *merge_alias_dir_config(pool *p, void *basev, void *overridesv)
+static void *merge_alias_dir_config(apr_pool_t *p, void *basev, void *overridesv)
{
alias_dir_conf *a =
- (alias_dir_conf *) ap_pcalloc(p, sizeof(alias_dir_conf));
+ (alias_dir_conf *) apr_pcalloc(p, sizeof(alias_dir_conf));
alias_dir_conf *base = (alias_dir_conf *) basev, *overrides = (alias_dir_conf *) overridesv;
- a->redirects = ap_append_arrays(p, overrides->redirects, base->redirects);
+ a->redirects = apr_array_append(p, overrides->redirects, base->redirects);
return a;
}
-static const char *add_alias_internal(cmd_parms *cmd, void *dummy, char *f, char *r,
+static const char *add_alias_internal(cmd_parms *cmd, void *dummy,
+ const char *f, const char *r,
int use_regex)
{
server_rec *s = cmd->server;
alias_server_conf *conf =
(alias_server_conf *) ap_get_module_config(s->module_config, &alias_module);
- alias_entry *new = ap_push_array(conf->aliases);
+ alias_entry *new = apr_array_push(conf->aliases);
/* XX r can NOT be relative to DocumentRoot here... compat bug. */
new->regexp = ap_pregcomp(cmd->pool, f, REG_EXTENDED);
if (new->regexp == NULL)
return "Regular expression could not be compiled.";
+ new->real = r;
}
+#ifndef OS2
+ else
+ new->real = ap_os_canonical_filename(cmd->pool, r);
+#else
+ new->real = r;
+#endif
new->fake = f;
- new->real = r;
new->handler = cmd->info;
return NULL;
}
-static const char *add_alias(cmd_parms *cmd, void *dummy, char *f, char *r)
+static const char *add_alias(cmd_parms *cmd, void *dummy, const char *f,
+ const char *r)
{
return add_alias_internal(cmd, dummy, f, r, 0);
}
-static const char *add_alias_regex(cmd_parms *cmd, void *dummy, char *f, char *r)
+static const char *add_alias_regex(cmd_parms *cmd, void *dummy, const char *f,
+ const char *r)
{
return add_alias_internal(cmd, dummy, f, r, 1);
}
-static const char *add_redirect_internal(cmd_parms *cmd, alias_dir_conf * dirconf,
- char *arg1, char *arg2, char *arg3,
- int use_regex)
+static const char *add_redirect_internal(cmd_parms *cmd,
+ alias_dir_conf *dirconf,
+ const char *arg1, const char *arg2,
+ const char *arg3, int use_regex)
{
alias_entry *new;
server_rec *s = cmd->server;
(alias_server_conf *) ap_get_module_config(s->module_config, &alias_module);
int status = (int) (long) cmd->info;
regex_t *r = NULL;
- char *f = arg2;
- char *url = arg3;
+ const char *f = arg2;
+ const char *url = arg3;
if (!strcasecmp(arg1, "gone"))
status = HTTP_GONE;
status = HTTP_MOVED_TEMPORARILY;
else if (!strcasecmp(arg1, "seeother"))
status = HTTP_SEE_OTHER;
- else if (ap_isdigit(*arg1))
+ else if (apr_isdigit(*arg1))
status = atoi(arg1);
else {
f = arg1;
}
if (cmd->path)
- new = ap_push_array(dirconf->redirects);
+ new = apr_array_push(dirconf->redirects);
else
- new = ap_push_array(serverconf->redirects);
+ new = apr_array_push(serverconf->redirects);
new->fake = f;
new->real = url;
return NULL;
}
-static const char *add_redirect(cmd_parms *cmd, alias_dir_conf * dirconf, char *arg1,
- char *arg2, char *arg3)
+static const char *add_redirect(cmd_parms *cmd, void *dirconf,
+ const char *arg1, const char *arg2,
+ const char *arg3)
{
return add_redirect_internal(cmd, dirconf, arg1, arg2, arg3, 0);
}
-static const char *add_redirect_regex(cmd_parms *cmd, alias_dir_conf * dirconf,
- char *arg1, char *arg2, char *arg3)
+static const char *add_redirect2(cmd_parms *cmd, void *dirconf,
+ const char *arg1, const char *arg2)
+{
+ return add_redirect_internal(cmd, dirconf, arg1, arg2, NULL, 0);
+}
+
+static const char *add_redirect_regex(cmd_parms *cmd, void *dirconf,
+ const char *arg1, const char *arg2,
+ const char *arg3)
{
return add_redirect_internal(cmd, dirconf, arg1, arg2, arg3, 1);
}
static const command_rec alias_cmds[] =
{
- {"Alias", add_alias, NULL, RSRC_CONF, TAKE2,
- "a fakename and a realname"},
- {"ScriptAlias", add_alias, "cgi-script", RSRC_CONF, TAKE2,
- "a fakename and a realname"},
- {"Redirect", add_redirect, (void *) HTTP_MOVED_TEMPORARILY,
- OR_FILEINFO, TAKE23,
- "an optional status, then document to be redirected and destination URL"},
- {"AliasMatch", add_alias_regex, NULL, RSRC_CONF, TAKE2,
- "a regular expression and a filename"},
- {"ScriptAliasMatch", add_alias_regex, "cgi-script", RSRC_CONF, TAKE2,
- "a regular expression and a filename"},
- {"RedirectMatch", add_redirect_regex, (void *) HTTP_MOVED_TEMPORARILY,
- OR_FILEINFO, TAKE23,
- "an optional status, then a regular expression and destination URL"},
- {"RedirectTemp", add_redirect, (void *) HTTP_MOVED_TEMPORARILY,
- OR_FILEINFO, TAKE2,
- "a document to be redirected, then the destination URL"},
- {"RedirectPermanent", add_redirect, (void *) HTTP_MOVED_PERMANENTLY,
- OR_FILEINFO, TAKE2,
- "a document to be redirected, then the destination URL"},
+ AP_INIT_TAKE2("Alias", add_alias, NULL, RSRC_CONF,
+ "a fakename and a realname"),
+ AP_INIT_TAKE2("ScriptAlias", add_alias, "cgi-script", RSRC_CONF,
+ "a fakename and a realname"),
+ AP_INIT_TAKE23("Redirect", add_redirect, (void *) HTTP_MOVED_TEMPORARILY,
+ OR_FILEINFO,
+ "an optional status, then document to be redirected and "
+ "destination URL"),
+ AP_INIT_TAKE2("AliasMatch", add_alias_regex, NULL, RSRC_CONF,
+ "a regular expression and a filename"),
+ AP_INIT_TAKE2("ScriptAliasMatch", add_alias_regex, "cgi-script", RSRC_CONF,
+ "a regular expression and a filename"),
+ AP_INIT_TAKE23("RedirectMatch", add_redirect_regex,
+ (void *) HTTP_MOVED_TEMPORARILY, OR_FILEINFO,
+ "an optional status, then a regular expression and "
+ "destination URL"),
+ AP_INIT_TAKE2("RedirectTemp", add_redirect2,
+ (void *) HTTP_MOVED_TEMPORARILY, OR_FILEINFO,
+ "a document to be redirected, then the destination URL"),
+ AP_INIT_TAKE2("RedirectPermanent", add_redirect2,
+ (void *) HTTP_MOVED_PERMANENTLY, OR_FILEINFO,
+ "a document to be redirected, then the destination URL"),
{NULL}
};
return urip - uri;
}
-static char *try_alias_list(request_rec *r, array_header *aliases, int doesc, int *status)
+static char *try_alias_list(request_rec *r, apr_array_header_t *aliases, int doesc, int *status)
{
alias_entry *entries = (alias_entry *) aliases->elts;
regmatch_t regm[10];
}
else {
/* need something non-null */
- found = ap_pstrdup(r->pool, "");
+ found = apr_pstrdup(r->pool, "");
}
}
}
char *escurl;
escurl = ap_os_escape_path(r->pool, r->uri + l, 1);
- found = ap_pstrcat(r->pool, p->real, escurl, NULL);
+ found = apr_pstrcat(r->pool, p->real, escurl, NULL);
}
else
- found = ap_pstrcat(r->pool, p->real, r->uri + l, NULL);
+ found = apr_pstrcat(r->pool, p->real, r->uri + l, NULL);
}
}
if (found) {
if (p->handler) { /* Set handler, and leave a note for mod_cgi */
r->handler = p->handler;
- ap_table_setn(r->notes, "alias-forced-type", r->handler);
+ apr_table_setn(r->notes, "alias-forced-type", r->handler);
}
*status = p->redir_status;
if (ap_is_HTTP_REDIRECT(status)) {
/* include QUERY_STRING if any */
if (r->args) {
- ret = ap_pstrcat(r->pool, ret, "?", r->args, NULL);
+ ret = apr_pstrcat(r->pool, ret, "?", r->args, NULL);
}
- ap_table_setn(r->headers_out, "Location", ret);
+ apr_table_setn(r->headers_out, "Location", ret);
}
return status;
}
if ((ret = try_alias_list(r, dirconf->redirects, 1, &status)) != NULL) {
if (ap_is_HTTP_REDIRECT(status))
- ap_table_setn(r->headers_out, "Location", ret);
+ apr_table_setn(r->headers_out, "Location", ret);
return status;
}
return DECLINED;
}
-module MODULE_VAR_EXPORT alias_module =
+static void register_hooks(apr_pool_t *p)
+{
+ static const char * const aszPre[]={ "mod_userdir.c",NULL };
+
+ ap_hook_translate_name(translate_alias_redir,aszPre,NULL,APR_HOOK_MIDDLE);
+ ap_hook_fixups(fixup_redir,NULL,NULL,APR_HOOK_MIDDLE);
+}
+
+module AP_MODULE_DECLARE_DATA alias_module =
{
- STANDARD_MODULE_STUFF,
- NULL, /* initializer */
+ STANDARD20_MODULE_STUFF,
create_alias_dir_config, /* dir config creater */
merge_alias_dir_config, /* dir merger --- default is to override */
create_alias_config, /* server config */
merge_alias_config, /* merge server configs */
- alias_cmds, /* command table */
- NULL, /* handlers */
- translate_alias_redir, /* filename translation */
- NULL, /* check_user_id */
- NULL, /* check auth */
- NULL, /* check access */
- NULL, /* type_checker */
- fixup_redir, /* fixups */
- NULL, /* logger */
- NULL, /* header parser */
- NULL, /* child_init */
- NULL, /* child_exit */
- NULL /* post read-request */
+ alias_cmds, /* command apr_table_t */
+ register_hooks /* register hooks */
};