mod_alias.c revision afadb90f859c4987505e745edee656850d7f8d49
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * contributor license agreements. See the NOTICE file distributed with
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * this work for additional information regarding copyright ownership.
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * The ASF licenses this file to You under the Apache License, Version 2.0
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * (the "License"); you may not use this file except in compliance with
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the License. You may obtain a copy of the License at
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * http://www.apache.org/licenses/LICENSE-2.0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Unless required by applicable law or agreed to in writing, software
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * distributed under the License is distributed on an "AS IS" BASIS,
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * See the License for the specific language governing permissions and
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * limitations under the License.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * http_alias.c: Stuff for dealing with directory aliases
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding *
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * Original by Rob McCool, rewritten in succession by David Robinson
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * and rst.
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding *
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding */
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "apr_strings.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "apr_lib.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#define APR_WANT_STRFUNC
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "apr_want.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "ap_config.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "httpd.h"
64185f9824e42f21ca7b9ae6c004484215c031a7rbb#include "http_core.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_config.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_request.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_log.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct {
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding const char *real;
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding const char *fake;
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding char *handler;
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding ap_regex_t *regexp;
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding int redir_status; /* 301, 302, 303, 410, etc */
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding} alias_entry;
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_array_header_t *aliases;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_array_header_t *redirects;
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding} alias_server_conf;
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffieldingtypedef struct {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_array_header_t *redirects;
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding} alias_dir_conf;
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffieldingmodule AP_MODULE_DECLARE_DATA alias_module;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void *create_alias_config(apr_pool_t *p, server_rec *s)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_server_conf *a =
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (alias_server_conf *) apr_pcalloc(p, sizeof(alias_server_conf));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding a->aliases = apr_array_make(p, 20, sizeof(alias_entry));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding a->redirects = apr_array_make(p, 20, sizeof(alias_entry));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return a;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
90211b595b36b22a529f9f68238f77fed273e08erbbstatic void *create_alias_dir_config(apr_pool_t *p, char *d)
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb{
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb alias_dir_conf *a =
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb (alias_dir_conf *) apr_pcalloc(p, sizeof(alias_dir_conf));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding a->redirects = apr_array_make(p, 2, sizeof(alias_entry));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return a;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void *merge_alias_config(apr_pool_t *p, void *basev, void *overridesv)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_server_conf *a =
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (alias_server_conf *) apr_pcalloc(p, sizeof(alias_server_conf));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_server_conf *base = (alias_server_conf *) basev;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_server_conf *overrides = (alias_server_conf *) overridesv;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding a->aliases = apr_array_append(p, overrides->aliases, base->aliases);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding a->redirects = apr_array_append(p, overrides->redirects, base->redirects);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return a;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void *merge_alias_dir_config(apr_pool_t *p, void *basev, void *overridesv)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_dir_conf *a =
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (alias_dir_conf *) apr_pcalloc(p, sizeof(alias_dir_conf));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_dir_conf *base = (alias_dir_conf *) basev;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_dir_conf *overrides = (alias_dir_conf *) overridesv;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding a->redirects = apr_array_append(p, overrides->redirects, base->redirects);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return a;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* need prototype for overlap check */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int alias_matches(const char *uri, const char *alias_fakename);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *add_alias_internal(cmd_parms *cmd, void *dummy,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *f, const char *r,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int use_regex)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_rec *s = cmd->server;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_server_conf *conf = ap_get_module_config(s->module_config,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding &alias_module);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_entry *new = apr_array_push(conf->aliases);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_entry *entries = (alias_entry *)conf->aliases->elts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* XX r can NOT be relative to DocumentRoot here... compat bug. */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (use_regex) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->regexp = ap_pregcomp(cmd->pool, f, AP_REG_EXTENDED);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (new->regexp == NULL)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Regular expression could not be compiled.";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->real = r;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* XXX This may be optimized, but we must know that new->real
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * exists. If so, we can dir merge later, trusing new->real
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * and just canonicalizing the remainder. Not till I finish
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * cleaning out the old ap_canonical stuff first.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->real = r;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->fake = f;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->handler = cmd->info;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* check for overlapping (Script)Alias directives
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * and throw a warning if found one
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!use_regex) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < conf->aliases->nelts - 1; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_entry *p = &entries[i];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ( (!p->regexp && alias_matches(f, p->fake) > 0)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || (p->regexp && !ap_regexec(p->regexp, f, 0, NULL, 0))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "The %s directive in %s at line %d will probably "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "never match because it overlaps an earlier "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "%sAlias%s.",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding cmd->cmd->name, cmd->directive->filename,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding cmd->directive->line_num,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->handler ? "Script" : "",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->regexp ? "Match" : "");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding break; /* one warning per alias should be sufficient */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *add_alias(cmd_parms *cmd, void *dummy, const char *f,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *r)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return add_alias_internal(cmd, dummy, f, r, 0);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbbstatic const char *add_alias_regex(cmd_parms *cmd, void *dummy, const char *f,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *r)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return add_alias_internal(cmd, dummy, f, r, 1);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbbstatic const char *add_redirect_internal(cmd_parms *cmd,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb alias_dir_conf *dirconf,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb const char *arg1, const char *arg2,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *arg3, int use_regex)
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_entry *new;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb server_rec *s = cmd->server;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_server_conf *serverconf = ap_get_module_config(s->module_config,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding &alias_module);
07fcce220d1d0801bd38de5a85af72668c9761e0trawick int status = (int) (long) cmd->info;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int grokarg1 = 1;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb ap_regex_t *r = NULL;
ec727afb817df0e5202135278c0d2902923cc980stoddard const char *f = arg2;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb const char *url = arg3;
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb
ec727afb817df0e5202135278c0d2902923cc980stoddard /*
ec727afb817df0e5202135278c0d2902923cc980stoddard * Logic flow:
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * Go ahead and try to grok the 1st arg, in case it is a
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * Redirect status. Now if we have 3 args, we expect that
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * we were able to understand that 1st argument (it's something
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * we expected, so if not, then we bail
f285a4a0695a101af2c2af5257fd660f7fd8affdrbb */
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (!strcasecmp(arg1, "permanent"))
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb status = HTTP_MOVED_PERMANENTLY;
99b130dd1f797c0acf3ffa960b3c9acefd29f0fcrbb else if (!strcasecmp(arg1, "temp"))
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb status = HTTP_MOVED_TEMPORARILY;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb else if (!strcasecmp(arg1, "seeother"))
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb status = HTTP_SEE_OTHER;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb else if (!strcasecmp(arg1, "gone"))
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb status = HTTP_GONE;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb else if (apr_isdigit(*arg1))
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb status = atoi(arg1);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding grokarg1 = 0;
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (arg3 && !grokarg1)
061c3874622b67beff724876b9bd1b1f291f2eaafielding return "Redirect: invalid first argument (of three)";
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * if we don't have the 3rd arg and we didn't understand the 1st
9ede6357edc9aff1fb2f7edebefab473673298aarbb * one, then assume URL-path URL. This also handles case, eg, GONE
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * we even though we don't have a 3rd arg, we did understand the 1st
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * one, so we don't want to re-arrange
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb */
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (!arg3 && !grokarg1) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding f = arg1;
2b484455736f4c30447aa852764f53282cbeb5ddrbb url = arg2;
2b484455736f4c30447aa852764f53282cbeb5ddrbb }
2b484455736f4c30447aa852764f53282cbeb5ddrbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (use_regex) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r = ap_pregcomp(cmd->pool, f, AP_REG_EXTENDED);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (r == NULL)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Regular expression could not be compiled.";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ap_is_HTTP_REDIRECT(status)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!url)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "URL to redirect to is missing";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* PR#35314: we can allow path components here;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * they get correctly resolved to full URLs.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!use_regex && !ap_is_url(url) && (url[0] != '/'))
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Redirect to non-URL";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (url)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Redirect URL not valid for this status";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (cmd->path)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new = apr_array_push(dirconf->redirects);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new = apr_array_push(serverconf->redirects);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->fake = f;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->real = url;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->regexp = r;
061c3874622b67beff724876b9bd1b1f291f2eaafielding new->redir_status = status;
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj return NULL;
95ed69df3d43a7d2758720bad8950f07587bdeb9bjh}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2b484455736f4c30447aa852764f53282cbeb5ddrbbstatic const char *add_redirect(cmd_parms *cmd, void *dirconf,
2b484455736f4c30447aa852764f53282cbeb5ddrbb const char *arg1, const char *arg2,
2b484455736f4c30447aa852764f53282cbeb5ddrbb const char *arg3)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return add_redirect_internal(cmd, dirconf, arg1, arg2, arg3, 0);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *add_redirect2(cmd_parms *cmd, void *dirconf,
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb const char *arg1, const char *arg2)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard return add_redirect_internal(cmd, dirconf, arg1, arg2, NULL, 0);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
40303323ae9960bd38a0f03d2c10e897a7badd88rbbstatic const char *add_redirect_regex(cmd_parms *cmd, void *dirconf,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *arg1, const char *arg2,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *arg3)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return add_redirect_internal(cmd, dirconf, arg1, arg2, arg3, 1);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
c57161db43fe4cf5a62758d7d0834675e59cad0astoddard
5914b312b3377f0275f95487bc9557d7c93e0678stoddardstatic const command_rec alias_cmds[] =
40303323ae9960bd38a0f03d2c10e897a7badd88rbb{
02ecbdc58dc450237cba13a3982bf0b3743d539crbb AP_INIT_TAKE2("Alias", add_alias, NULL, RSRC_CONF,
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard "a fakename and a realname"),
ec727afb817df0e5202135278c0d2902923cc980stoddard AP_INIT_TAKE2("ScriptAlias", add_alias, "cgi-script", RSRC_CONF,
ec727afb817df0e5202135278c0d2902923cc980stoddard "a fakename and a realname"),
ec727afb817df0e5202135278c0d2902923cc980stoddard AP_INIT_TAKE23("Redirect", add_redirect, (void *) HTTP_MOVED_TEMPORARILY,
ec727afb817df0e5202135278c0d2902923cc980stoddard OR_FILEINFO,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "an optional status, then document to be redirected and "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "destination URL"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_TAKE2("AliasMatch", add_alias_regex, NULL, RSRC_CONF,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "a regular expression and a filename"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_TAKE2("ScriptAliasMatch", add_alias_regex, "cgi-script", RSRC_CONF,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "a regular expression and a filename"),
0942697a9b5de44865676345a3828741c827efe6rbb AP_INIT_TAKE23("RedirectMatch", add_redirect_regex,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (void *) HTTP_MOVED_TEMPORARILY, OR_FILEINFO,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "an optional status, then a regular expression and "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "destination URL"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_TAKE2("RedirectTemp", add_redirect2,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb (void *) HTTP_MOVED_TEMPORARILY, OR_FILEINFO,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "a document to be redirected, then the destination URL"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_TAKE2("RedirectPermanent", add_redirect2,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (void *) HTTP_MOVED_PERMANENTLY, OR_FILEINFO,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "a document to be redirected, then the destination URL"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {NULL}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int alias_matches(const char *uri, const char *alias_fakename)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *aliasp = alias_fakename, *urip = uri;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding while (*aliasp) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (*aliasp == '/') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* any number of '/' in the alias matches any number in
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the supplied URI, but there must be at least one...
9ede6357edc9aff1fb2f7edebefab473673298aarbb */
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb if (*urip != '/')
40303323ae9960bd38a0f03d2c10e897a7badd88rbb return 0;
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard
02ecbdc58dc450237cba13a3982bf0b3743d539crbb do {
40303323ae9960bd38a0f03d2c10e897a7badd88rbb ++aliasp;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding } while (*aliasp == '/');
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding do {
0942697a9b5de44865676345a3828741c827efe6rbb ++urip;
0942697a9b5de44865676345a3828741c827efe6rbb } while (*urip == '/');
3597d6b10c88c252f156fe8061b659a38dea38c2rbb }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Other characters are compared literally */
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj if (*urip++ != *aliasp++)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 0;
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Check last alias path component matched all the way */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (aliasp[-1] != '/' && *urip != '\0' && *urip != '/')
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Return number of characters from URI which matched (may be
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * greater than length of alias, since we may have matched
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * doubled slashes)
40303323ae9960bd38a0f03d2c10e897a7badd88rbb */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return urip - uri;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic char *try_alias_list(request_rec *r, apr_array_header_t *aliases,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int doesc, int *status)
2b484455736f4c30447aa852764f53282cbeb5ddrbb{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_entry *entries = (alias_entry *) aliases->elts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_regmatch_t regm[AP_MAX_REG_MATCH];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *found = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < aliases->nelts; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_entry *p = &entries[i];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int l;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (p->regexp) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!ap_regexec(p->regexp, r->uri, AP_MAX_REG_MATCH, regm, 0)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (p->real) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding found = ap_pregsub(r->pool, p->real, r->uri,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_MAX_REG_MATCH, regm);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (found && doesc) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_uri_t uri;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_uri_parse(r->pool, found, &uri);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Do not escape the query string or fragment. */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding found = apr_uri_unparse(r->pool, &uri,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding APR_URI_UNP_OMITQUERY);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding found = ap_escape_uri(r->pool, found);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (uri.query) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding found = apr_pstrcat(r->pool, found, "?",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding uri.query, NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (uri.fragment) {
2b484455736f4c30447aa852764f53282cbeb5ddrbb found = apr_pstrcat(r->pool, found, "#",
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet uri.fragment, NULL);
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet }
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet }
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet }
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* need something non-null */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding found = apr_pstrdup(r->pool, "");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2b484455736f4c30447aa852764f53282cbeb5ddrbb }
2b484455736f4c30447aa852764f53282cbeb5ddrbb else {
2b484455736f4c30447aa852764f53282cbeb5ddrbb l = alias_matches(r->uri, p->fake);
2b484455736f4c30447aa852764f53282cbeb5ddrbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (l > 0) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (doesc) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *escurl;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding escurl = ap_os_escape_path(r->pool, r->uri + l, 1);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding found = apr_pstrcat(r->pool, p->real, escurl, NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding found = apr_pstrcat(r->pool, p->real, r->uri + l, NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (found) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (p->handler) { /* Set handler, and leave a note for mod_cgi */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r->handler = p->handler;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_setn(r->notes, "alias-forced-type", r->handler);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* XXX This is as SLOW as can be, next step, we optimize
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * and merge to whatever part of the found path was already
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * canonicalized. After I finish eliminating os canonical.
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj * Better fail test for ap_server_root_relative needed here.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!doesc) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding found = ap_server_root_relative(r->pool, found);
fd47393e4c08a1515601cb1f1e8deddf4163e858martin }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (found) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *status = p->redir_status;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return found;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb}
3597d6b10c88c252f156fe8061b659a38dea38c2rbb
3597d6b10c88c252f156fe8061b659a38dea38c2rbbstatic int translate_alias_redir(request_rec *r)
3597d6b10c88c252f156fe8061b659a38dea38c2rbb{
3597d6b10c88c252f156fe8061b659a38dea38c2rbb ap_conf_vector_t *sconf = r->server->module_config;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb alias_server_conf *serverconf = ap_get_module_config(sconf, &alias_module);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb char *ret;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb int status;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb
3597d6b10c88c252f156fe8061b659a38dea38c2rbb if (r->uri[0] != '/' && r->uri[0] != '\0') {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb return DECLINED;
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((ret = try_alias_list(r, serverconf->redirects, 1, &status)) != NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ap_is_HTTP_REDIRECT(status)) {
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj /* include QUERY_STRING if any */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (r->args) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ret = apr_pstrcat(r->pool, ret, "?", r->args, NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj apr_table_setn(r->headers_out, "Location", ret);
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj }
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj return status;
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj }
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj
70a2c0407879c11b29adc782d1665a0131f30b3frbb if ((ret = try_alias_list(r, serverconf->aliases, 0, &status)) != NULL) {
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb r->filename = ret;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return OK;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return DECLINED;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int fixup_redir(request_rec *r)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding void *dconf = r->per_dir_config;
0942697a9b5de44865676345a3828741c827efe6rbb alias_dir_conf *dirconf =
0942697a9b5de44865676345a3828741c827efe6rbb (alias_dir_conf *) ap_get_module_config(dconf, &alias_module);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *ret;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int status;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* It may have changed since last time, so try again */
3597d6b10c88c252f156fe8061b659a38dea38c2rbb
3597d6b10c88c252f156fe8061b659a38dea38c2rbb if ((ret = try_alias_list(r, dirconf->redirects, 1, &status)) != NULL) {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb if (ap_is_HTTP_REDIRECT(status)) {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb if (ret[0] == '/') {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb char *orig_target = ret;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb
3597d6b10c88c252f156fe8061b659a38dea38c2rbb ret = ap_construct_url(r->pool, ret, r);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
3597d6b10c88c252f156fe8061b659a38dea38c2rbb "incomplete redirection target of '%s' for "
3597d6b10c88c252f156fe8061b659a38dea38c2rbb "URI '%s' modified to '%s'",
3597d6b10c88c252f156fe8061b659a38dea38c2rbb orig_target, r->uri, ret);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!ap_is_url(ret)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding status = HTTP_INTERNAL_SERVER_ERROR;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "cannot redirect '%s' to '%s'; "
0942697a9b5de44865676345a3828741c827efe6rbb "target is not a valid absoluteURI or abs_path",
0942697a9b5de44865676345a3828741c827efe6rbb r->uri, ret);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* append requested query only, if the config didn't
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * supply its own.
3597d6b10c88c252f156fe8061b659a38dea38c2rbb */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (r->args && !ap_strchr(ret, '?')) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ret = apr_pstrcat(r->pool, ret, "?", r->args, NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_setn(r->headers_out, "Location", ret);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return status;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return DECLINED;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void register_hooks(apr_pool_t *p)
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim{
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim static const char * const aszSucc[]={ "mod_userdir.c",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "mod_vhost_alias.c",NULL };
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_hook_translate_name(translate_alias_redir,NULL,aszSucc,APR_HOOK_MIDDLE);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_hook_fixups(fixup_redir,NULL,NULL,APR_HOOK_MIDDLE);
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
9ede6357edc9aff1fb2f7edebefab473673298aarbbmodule AP_MODULE_DECLARE_DATA alias_module =
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding STANDARD20_MODULE_STUFF,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding create_alias_dir_config, /* dir config creater */
a8577c2083e1fe27d78bf198668eb8bc2687d060martin merge_alias_dir_config, /* dir merger --- default is to override */
a8577c2083e1fe27d78bf198668eb8bc2687d060martin create_alias_config, /* server config */
a8577c2083e1fe27d78bf198668eb8bc2687d060martin merge_alias_config, /* merge server configs */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alias_cmds, /* command apr_table_t */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_hooks /* register hooks */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding