mod_speling.c revision ac65d432dabe462e98489f8e3946b2537ca9ecf6
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu/* ====================================================================
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu * The Apache Software License, Version 1.1
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu * Copyright (c) 2000 The Apache Software Foundation. All rights
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu * Redistribution and use in source and binary forms, with or without
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu * modification, are permitted provided that the following conditions
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu * 1. Redistributions of source code must retain the above copyright
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu * notice, this list of conditions and the following disclaimer.
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * 2. Redistributions in binary form must reproduce the above copyright
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * notice, this list of conditions and the following disclaimer in
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * the documentation and/or other materials provided with the
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * distribution.
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * 3. The end-user documentation included with the redistribution,
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * if any, must include the following acknowledgment:
05d4bb01e11ad19f2efb41a3efec59a7784c9942Christian Maeder * "This product includes software developed by the
05d4bb01e11ad19f2efb41a3efec59a7784c9942Christian Maeder * Apache Software Foundation (http://www.apache.org/)."
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * Alternately, this acknowledgment may appear in the software itself,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * if and wherever such third-party acknowledgments normally appear.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 4. The names "Apache" and "Apache Software Foundation" must
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * not be used to endorse or promote products derived from this
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * software without prior written permission. For written
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * permission, please contact apache@apache.org.
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * 5. Products derived from this software may not be called "Apache",
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * nor may "Apache" appear in their name, without prior written
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * permission of the Apache Software Foundation.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * SUCH DAMAGE.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ====================================================================
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * This software consists of voluntary contributions made by many
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * individuals on behalf of the Apache Software Foundation. For more
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * information on the Apache Software Foundation, please see
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Portions of this software are based upon public domain software
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * originally written at the National Center for Supercomputing Applications,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * University of Illinois, Urbana-Champaign.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/* mod_speling.c - by Alexei Kosut <akosut@organic.com> June, 1996
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * This module is transparent, and simple. It attempts to correct
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * misspellings of URLs that users might have entered, namely by checking
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * capitalizations. If it finds a match, it sends a redirect.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 08-Aug-1997 <Martin.Kraemer@Mch.SNI.De>
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * o Upgraded module interface to apache_1.3a2-dev API (more NULL's in
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * speling_module).
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * o Integrated tcsh's "spelling correction" routine which allows one
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * misspelling (character insertion/omission/typo/transposition).
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Rewrote it to ignore case as well. This ought to catch the majority
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * of misspelled requests.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * o Commented out the second pass where files' suffixes are stripped.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Given the better hit rate of the first pass, this rather ugly
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * (request index.html, receive index.db ?!?!) solution can be
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * o wrote a "kind of" html page for mod_speling
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Activate it with "CheckSpelling On"
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calintypedef struct {
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Create a configuration specific to this module for a server or directory
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * location, and fill it with the default settings.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * The API says that in the absence of a merge function, the record for the
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * closest ancestor is used exclusively. That's what we want, so we don't
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * bother to have such a function.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin spconfig *cfg = apr_pcalloc(p, sizeof(spconfig));
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Respond to a callback to create configuration record for a server or
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * vhost environment.
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maederstatic void *create_mconfig_for_server(apr_pool_t *p, server_rec *s)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Respond to a callback to create a config record for a specific directory.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinstatic void *create_mconfig_for_directory(apr_pool_t *p, char *dir)
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * Handler for the CheckSpelling directive, which is FLAG.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinstatic const char *set_speling(cmd_parms *cmd, void *mconfig, int arg)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Define the directives specific to this module. This structure is referenced
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * later by the 'module' structure.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin AP_INIT_FLAG("CheckSpelling", set_speling, NULL, OR_OPTIONS,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin "whether or not to fix miscapitalized/misspelled requests"),
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calintypedef enum {
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinstatic const char *sp_reason_str[] =
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin "miscapitalized",
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin "transposed characters",
05d4bb01e11ad19f2efb41a3efec59a7784c9942Christian Maeder "character missing",
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin "extra character",
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin "mistyped character",
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin "common basename",
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calintypedef struct {
return DECLINED;
return DECLINED;
return DECLINED;
if (r->main) {
return DECLINED;
* r->uri: /correct-url/mispelling/more
* r->filename: /correct-file/mispelling r->path_info: /more
return DECLINED;
/* postgood = mispelling/more */
return DECLINED;
return DECLINED;
sp_reason q;
return OK;
* missing/extra/transposed char)
* type (index.html <-> index.db).
* > If you're using MultiViews, and have a file named foobar.html,
* > it would locate "foobar.html". Not perfect, but I ran into
#ifdef WANT_BASENAME_MATCH
* (e.g. foo.gif and foo.html) This code will pick the first one
char *nuri;
const char *ref;
return HTTP_MOVED_PERMANENTLY;
apr_pool_t *p;
p = r->pool;
return DECLINED;
*(const char **)apr_push_array(t) =
*(const char **)apr_push_array(t) =
char *vuri;
const char *reason;
NULL);
*(const char **)apr_push_array(t) =
*(const char **)apr_push_array(t) =
/* Pass our apr_table_t to http_protocol.c (see mod_negotiation): */
return HTTP_MULTIPLE_CHOICES;
return OK;