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