mod_imap.c revision fc9b2e8809c305f340d86a789566f8abb1ca8a19
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
842ae4bd224140319ae7feec1872b93dfd491143fielding *
842ae4bd224140319ae7feec1872b93dfd491143fielding * Redistribution and use in source and binary forms, with or without
842ae4bd224140319ae7feec1872b93dfd491143fielding * modification, are permitted provided that the following conditions
842ae4bd224140319ae7feec1872b93dfd491143fielding * are met:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 1. Redistributions of source code must retain the above copyright
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * notice, this list of conditions and the following disclaimer.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 2. Redistributions in binary form must reproduce the above copyright
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * notice, this list of conditions and the following disclaimer in
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * the documentation and/or other materials provided with the
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * distribution.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 3. All advertising materials mentioning features or use of this
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * software must display the following acknowledgment:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * "This product includes software developed by the Apache Group
e8f95a682820a599fe41b22977010636be5c2717jim * for use in the Apache HTTP server project (http://www.apache.org/)."
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
e8f95a682820a599fe41b22977010636be5c2717jim * 4. The names "Apache Server" and "Apache Group" must not be used to
1747d30b98aa1bdbc43994c02cd46ab4cb9319e4fielding * endorse or promote products derived from this software without
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * prior written permission. For written permission, please contact
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * apache@apache.org.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 5. Products derived from this software may not be called "Apache"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * nor may "Apache" appear in their names without prior written
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * permission of the Apache Group.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 6. Redistributions of any form whatsoever must retain the following
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * acknowledgment:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * "This product includes software developed by the Apache Group
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * for use in the Apache HTTP server project (http://www.apache.org/)."
5c0419d51818eb02045cf923a9fe456127a44c60wrowe *
5c0419d51818eb02045cf923a9fe456127a44c60wrowe * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * IT'S CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * OF THE POSSIBILITY OF SUCH DAMAGE.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * ====================================================================
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes *
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes * This software consists of voluntary contributions made by many
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes * individuals on behalf of the Apache Group and was originally based
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes * on public domain software written at the National Center for
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes * Supercomputing Applications, University of Illinois, Urbana-Champaign.
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes * For more information on the Apache Group and the Apache HTTP server
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes * project, please see <http://www.apache.org/>.
cd3bbd6d2df78d6c75e5d159a81ef8bdd5f70df9trawick *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/*
0568280364eb026393be492ebc732795c4934643jorton * This imagemap module started as a port of the original imagemap.c
0568280364eb026393be492ebc732795c4934643jorton * written by Rob McCool (11/13/93 robm@ncsa.uiuc.edu).
0568280364eb026393be492ebc732795c4934643jorton * This version includes the mapping algorithms found in version 1.3
0568280364eb026393be492ebc732795c4934643jorton * of imagemap.c.
0568280364eb026393be492ebc732795c4934643jorton *
0568280364eb026393be492ebc732795c4934643jorton * Contributors to this code include:
0568280364eb026393be492ebc732795c4934643jorton *
0568280364eb026393be492ebc732795c4934643jorton * Kevin Hughes, kevinh@pulua.hcc.hawaii.edu
0568280364eb026393be492ebc732795c4934643jorton *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Eric Haines, erich@eye.com
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * "macmartinized" polygon code copyright 1992 by Eric Haines, erich@eye.com
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Randy Terbush, randy@zyzzyva.com
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * port to Apache module format, "base_uri" and support for relative URLs
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * James H. Cloos, Jr., cloos@jhcloos.com
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Added point datatype, using code in NCSA's version 1.8 imagemap.c
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * program, as distributed with version 1.4.1 of their server.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * The point code is originally added by Craig Milo Rogers, Rogers@ISI.Edu
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
796e4a7141265d8ed7036e4628161c6eafb2a789jorton * Nathan Kurz, nate@tripod.com
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Rewrite/reorganization. New handling of default, base and relative URLs.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * New Configuration directives:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * ImapMenu {none, formatted, semiformatted, unformatted}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * ImapDefault {error, nocontent, referer, menu, URL}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * ImapBase {map, referer, URL}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Support for creating non-graphical menu added. (backwards compatible):
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Old: directive URL [x,y ...]
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * New: directive URL "Menu text" [x,y ...]
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * or: directive URL x,y ... "Menu text"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Map format and menu concept courtesy Joshua Bell, jsbell@acs.ucalgary.ca.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Mark Cox, mark@ukweb.com, Allow relative URLs even when no base specified
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "httpd.h"
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe#include "http_config.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "http_request.h"
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe#include "http_core.h"
e8f95a682820a599fe41b22977010636be5c2717jim#include "http_protocol.h"
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe#include "http_main.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "http_log.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "util_script.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define IMAP_MAGIC_TYPE "application/x-httpd-imap"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define MAXVERTS 100
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define X 0
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define Y 1
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define IMAP_MENU_DEFAULT "formatted"
713a2b68bac4aeb1e9c48785006c0732451039depquerna#define IMAP_DEFAULT_DEFAULT "nocontent"
713a2b68bac4aeb1e9c48785006c0732451039depquerna#define IMAP_BASE_DEFAULT "map"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef SUNOS4
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesdouble strtod(); /* SunOS needed this */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowemodule MODULE_VAR_EXPORT imap_module;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholestypedef struct {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *imap_menu;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *imap_default;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *imap_base;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes} imap_conf_rec;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic void *create_imap_dir_config(ap_context_t *p, char *dummy)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener imap_conf_rec *icr =
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes (imap_conf_rec *) ap_palloc(p, sizeof(imap_conf_rec));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes icr->imap_menu = NULL;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes icr->imap_default = NULL;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes icr->imap_base = NULL;
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return icr;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic void *merge_imap_dir_configs(ap_context_t *p, void *basev, void *addv)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes imap_conf_rec *new = (imap_conf_rec *) ap_pcalloc(p, sizeof(imap_conf_rec));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes imap_conf_rec *base = (imap_conf_rec *) basev;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes imap_conf_rec *add = (imap_conf_rec *) addv;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes new->imap_menu = add->imap_menu ? add->imap_menu : base->imap_menu;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes new->imap_default = add->imap_default ? add->imap_default
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes : base->imap_default;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes new->imap_base = add->imap_base ? add->imap_base : base->imap_base;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return new;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic const command_rec imap_cmds[] =
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"ImapMenu", ap_set_string_slot,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener (void *) XtOffsetOf(imap_conf_rec, imap_menu), OR_INDEXES, TAKE1,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "the type of menu generated: none, formatted, semiformatted, unformatted"},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"ImapDefault", ap_set_string_slot,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes (void *) XtOffsetOf(imap_conf_rec, imap_default), OR_INDEXES, TAKE1,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "the action taken if no match: error, nocontent, referer, menu, URL"},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"ImapBase", ap_set_string_slot,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes (void *) XtOffsetOf(imap_conf_rec, imap_base), OR_INDEXES, TAKE1,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener "the base for all URL's: map, referer, URL (or start of)"},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {NULL}
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe};
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int pointinrect(const double point[2], double coords[MAXVERTS][2])
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes double max[2], min[2];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (coords[0][X] > coords[1][X]) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes max[0] = coords[0][X];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes min[0] = coords[1][X];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes else {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes max[0] = coords[1][X];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes min[0] = coords[0][X];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (coords[0][Y] > coords[1][Y]) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes max[1] = coords[0][Y];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes min[1] = coords[1][Y];
1f299703465bd9975d94e9f229f76af807442de2covener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener else {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener max[1] = coords[1][Y];
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener min[1] = coords[0][Y];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return ((point[X] >= min[0] && point[X] <= max[0]) &&
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes (point[Y] >= min[1] && point[Y] <= max[1]));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int pointincircle(const double point[2], double coords[MAXVERTS][2])
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes double radius1, radius2;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes radius1 = ((coords[0][Y] - coords[1][Y]) * (coords[0][Y] - coords[1][Y]))
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes + ((coords[0][X] - coords[1][X]) * (coords[0][X] - coords[1][X]));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes radius2 = ((coords[0][Y] - point[Y]) * (coords[0][Y] - point[Y]))
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes + ((coords[0][X] - point[X]) * (coords[0][X] - point[X]));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return (radius2 <= radius1);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes#define fmin(a,b) (((a)>(b))?(b):(a))
e8f95a682820a599fe41b22977010636be5c2717jim#define fmax(a,b) (((a)>(b))?(a):(b))
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic int pointinpoly(const double point[2], double pgon[MAXVERTS][2])
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener{
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener int i, numverts, crossings = 0;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener double x = point[X], y = point[Y];
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener for (numverts = 0; pgon[numverts][X] != -1 && numverts < MAXVERTS;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener numverts++) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener /* just counting the vertexes */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener for (i = 0; i < numverts; i++) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener double x1=pgon[i][X];
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener double y1=pgon[i][Y];
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener double x2=pgon[(i + 1) % numverts][X];
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener double y2=pgon[(i + 1) % numverts][Y];
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener double d=(y - y1) * (x2 - x1) - (x - x1) * (y2 - y1);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if ((y1 >= y) != (y2 >= y)) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener crossings +=y2 - y1 >= 0 ? d >= 0 : d <= 0;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (!d && fmin(x1,x2) <= x && x <= fmax(x1,x2)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener && fmin(y1,y2) <= y && y <= fmax(y1,y2)) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return 1;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return crossings & 0x01;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic int is_closer(const double point[2], double coords[MAXVERTS][2],
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener double *closest)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener{
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener double dist_squared = ((point[X] - coords[0][X])
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * (point[X] - coords[0][X]))
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener + ((point[Y] - coords[0][Y])
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * (point[Y] - coords[0][Y]));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (point[X] < 0 || point[Y] < 0) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return (0); /* don't mess around with negative coordinates */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (*closest < 0 || dist_squared < *closest) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *closest = dist_squared;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return (1); /* if this is the first point or is the closest yet
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener set 'closest' equal to this distance^2 */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return (0); /* if it's not the first or closest */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic double get_x_coord(const char *args)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener{
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener char *endptr; /* we want it non-null */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener double x_coord = -1; /* -1 is returned if no coordinate is given */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (args == NULL) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return (-1); /* in case we aren't passed anything */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
68d5e906a21c3abe1ebd0da30d2f0e8e4c2ad28cjim while (*args && !ap_isdigit(*args) && *args != ',') {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes args++; /* jump to the first digit, but not past
b08925593f214f621161742925dcf074a8047e0acovener a comma or end */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes x_coord = strtod(args, &endptr);
e8f95a682820a599fe41b22977010636be5c2717jim
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes if (endptr > args) { /* if a conversion was made */
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes return (x_coord);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return (-1); /* else if no conversion was made,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes or if no args was given */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic double get_y_coord(const char *args)
ebe5305f8b22507374358f32b74d12fb50c05a25covener{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes char *endptr; /* we want it non-null */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes char *start_of_y = NULL;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes double y_coord = -1; /* -1 is returned on error */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (args == NULL) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return (-1); /* in case we aren't passed anything */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes start_of_y = strchr(args, ','); /* the comma */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (start_of_y) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes start_of_y++; /* start looking at the character after
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes the comma */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes while (*start_of_y && !ap_isdigit(*start_of_y)) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes start_of_y++; /* jump to the first digit, but not
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes past the end */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes y_coord = strtod(start_of_y, &endptr);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (endptr > start_of_y) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return (y_coord);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
ebe5305f8b22507374358f32b74d12fb50c05a25covener return (-1); /* if no conversion was made, or
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes no comma was found in args */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/* See if string has a "quoted part", and if so set *quoted_part to
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * the first character of the quoted part, then hammer a \0 onto the
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * trailing quote, and set *string to point at the first character
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * past the second quote.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes *
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * Otherwise set *quoted_part to NULL, and leave *string alone.
ebe5305f8b22507374358f32b74d12fb50c05a25covener */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic void read_quoted(char **string, char **quoted_part)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes char *strp = *string;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* assume there's no quoted part */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *quoted_part = NULL;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (ap_isspace(*strp)) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes strp++; /* go along string until non-whitespace */
b08925593f214f621161742925dcf074a8047e0acovener }
b08925593f214f621161742925dcf074a8047e0acovener
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (*strp == '"') { /* if that character is a double quote */
7add8f7fb048534390571801b7794f71cd9e127abnicholes strp++; /* step over it */
7add8f7fb048534390571801b7794f71cd9e127abnicholes *quoted_part = strp; /* note where the quoted part begins */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem while (*strp && *strp != '"') {
7add8f7fb048534390571801b7794f71cd9e127abnicholes ++strp; /* skip the quoted portion */
7add8f7fb048534390571801b7794f71cd9e127abnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes *strp = '\0'; /* end the string with a NUL */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes strp++; /* step over the last double quote */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes *string = strp;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
7add8f7fb048534390571801b7794f71cd9e127abnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/*
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * returns the mapped URL or NULL.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic char *imap_url(request_rec *r, const char *base, const char *value)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/* translates a value into a URL. */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes int slen, clen;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes char *string_pos = NULL;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *string_pos_const = NULL;
7add8f7fb048534390571801b7794f71cd9e127abnicholes char *directory = NULL;
7add8f7fb048534390571801b7794f71cd9e127abnicholes const char *referer = NULL;
141e1368614dc7564e1627671361b01b4869b491bnicholes char *my_base;
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (!strcasecmp(value, "map") || !strcasecmp(value, "menu")) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return ap_construct_url(r->pool, r->uri, r);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
e8f95a682820a599fe41b22977010636be5c2717jim
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (!strcasecmp(value, "nocontent") || !strcasecmp(value, "error")) {
ebe5305f8b22507374358f32b74d12fb50c05a25covener return ap_pstrdup(r->pool, value); /* these are handled elsewhere,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes so just copy them */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (!strcasecmp(value, "referer")) {
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes referer = ap_table_get(r->headers_in, "Referer");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (referer && *referer) {
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes return ap_pstrdup(r->pool, referer);
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes else {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* XXX: This used to do *value = '\0'; ... which is totally bogus
e8f95a682820a599fe41b22977010636be5c2717jim * because it hammers the passed in value, which can be a string
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * constant, or part of a config, or whatever. Total garbage.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * This works around that without changing the rest of this
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * code much
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes value = ""; /* if 'referer' but no referring page,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes null the value */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes string_pos_const = value;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes while (ap_isalpha(*string_pos_const)) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes string_pos_const++; /* go along the URL from the map
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes until a non-letter */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (*string_pos_const == ':') {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* if letters and then a colon (like http:) */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* it's an absolute URL, so use it! */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return ap_pstrdup(r->pool, value);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (!base || !*base) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (value && *value) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return ap_pstrdup(r->pool, value); /* no base: use what is given */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* no base, no value: pick a simple default */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return ap_construct_url(r->pool, "/", r);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* must be a relative URL to be combined with base */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (strchr(base, '/') == NULL && (!strncmp(value, "../", 3)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes || !strcmp(value, ".."))) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "invalid base directive in map file: %s", r->uri);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return NULL;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes my_base = ap_pstrdup(r->pool, base);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes string_pos = my_base;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (*string_pos) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (*string_pos == '/' && *(string_pos + 1) == '/') {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes string_pos += 2; /* if there are two slashes, jump over them */
e8f95a682820a599fe41b22977010636be5c2717jim continue;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (*string_pos == '/') { /* the first single slash */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (value[0] == '/') {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *string_pos = '\0';
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes } /* if the URL from the map starts from root,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes end the base URL string at the first single
54d22ed1c429b903b029bbd62621f11a9e286137minfrin slash */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin else {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin directory = string_pos; /* save the start of
54d22ed1c429b903b029bbd62621f11a9e286137minfrin the directory portion */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes string_pos = strrchr(string_pos, '/'); /* now reuse
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes string_pos */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes string_pos++; /* step over that last slash */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes *string_pos = '\0';
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes } /* but if the map url is relative, leave the
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes slash on the base (if there is one) */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes break;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes string_pos++; /* until we get to the end of my_base without
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes finding a slash by itself */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (!strncmp(value, "../", 3) || !strcmp(value, "..")) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (directory && (slen = strlen(directory))) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* for each '..', knock a directory off the end
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes by ending the string right at the last slash.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes But only consider the directory portion: don't eat
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes into the server name. And only try if a directory
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes portion was found */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes clen = slen - 1;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin while ((slen - clen) == 1) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if ((string_pos = strrchr(directory, '/'))) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin *string_pos = '\0';
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin clen = strlen(directory);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (clen == 0) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin break;
e8f95a682820a599fe41b22977010636be5c2717jim }
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe }
8a03cd420b800a2428f49f4617293de9b2387b20jorton
54d22ed1c429b903b029bbd62621f11a9e286137minfrin value += 2; /* jump over the '..' that we found in the
54d22ed1c429b903b029bbd62621f11a9e286137minfrin value */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin else if (directory) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin "invalid directory name in map file: %s", r->uri);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return NULL;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (!strncmp(value, "/../", 4) || !strcmp(value, "/..")) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin value++; /* step over the '/' if there are more '..'
54d22ed1c429b903b029bbd62621f11a9e286137minfrin to do. This way, we leave the starting
54d22ed1c429b903b029bbd62621f11a9e286137minfrin '/' on value after the last '..', but get
54d22ed1c429b903b029bbd62621f11a9e286137minfrin rid of it otherwise */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin } /* by this point, value does not start
edc346c3223efd41e6a2057c37cea69744b73dccwrowe with '..' */
edc346c3223efd41e6a2057c37cea69744b73dccwrowe
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (value && *value) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return ap_pstrcat(r->pool, my_base, value, NULL);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return my_base;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin}
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrinstatic int imap_reply(request_rec *r, char *redirect)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(redirect, "error")) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return SERVER_ERROR; /* they actually requested an error! */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(redirect, "nocontent")) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return HTTP_NO_CONTENT; /* tell the client to keep the page it has */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (redirect && *redirect) {
e8f95a682820a599fe41b22977010636be5c2717jim ap_table_setn(r->headers_out, "Location", redirect);
e8f95a682820a599fe41b22977010636be5c2717jim return REDIRECT; /* must be a URL, so redirect to it */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return SERVER_ERROR;
e8f95a682820a599fe41b22977010636be5c2717jim}
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe
8113dac419143273351446c3ad653f3fe5ba5cfdwrowestatic void menu_header(request_rec *r, char *menu)
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe{
f0f6f1b90ab582896f8a7d56d85bd62a55e57d90covener r->content_type = "text/html";
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe ap_send_http_header(r);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
560fd0658902ab57754616c172d8953e69fc4722bnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rvputs(r, DOCTYPE_HTML_3_2, "<html><head>\n<title>Menu for ", r->uri,
e8f95a682820a599fe41b22977010636be5c2717jim "</title>\n</head><body>\n", NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(menu, "formatted")) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rvputs(r, "<h1>Menu for ", r->uri, "</h1>\n<hr>\n\n", NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic void menu_blank(request_rec *r, char *menu)
560fd0658902ab57754616c172d8953e69fc4722bnicholes{
560fd0658902ab57754616c172d8953e69fc4722bnicholes if (!strcasecmp(menu, "formatted")) {
560fd0658902ab57754616c172d8953e69fc4722bnicholes ap_rputs("\n", r);
560fd0658902ab57754616c172d8953e69fc4722bnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(menu, "semiformatted")) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rputs("<br>\n", r);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(menu, "unformatted")) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rputs("\n", r);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return;
e8f95a682820a599fe41b22977010636be5c2717jim}
e8f95a682820a599fe41b22977010636be5c2717jim
e8f95a682820a599fe41b22977010636be5c2717jimstatic void menu_comment(request_rec *r, char *menu, char *comment)
e8f95a682820a599fe41b22977010636be5c2717jim{
e8f95a682820a599fe41b22977010636be5c2717jim if (!strcasecmp(menu, "formatted")) {
e8f95a682820a599fe41b22977010636be5c2717jim ap_rputs("\n", r); /* print just a newline if 'formatted' */
e8f95a682820a599fe41b22977010636be5c2717jim }
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe if (!strcasecmp(menu, "semiformatted") && *comment) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rvputs(r, comment, "\n", NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(menu, "unformatted") && *comment) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rvputs(r, comment, "\n", NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return; /* comments are ignored in the
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes 'formatted' form */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic void menu_default(request_rec *r, char *menu, char *href, char *text)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(href, "error") || !strcasecmp(href, "nocontent")) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return; /* don't print such lines, these aren't
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes really href's */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(menu, "formatted")) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rvputs(r, "<pre>(Default) <a href=\"", href, "\">", text,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "</a></pre>\n", NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(menu, "semiformatted")) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rvputs(r, "<pre>(Default) <a href=\"", href, "\">", text,
e8f95a682820a599fe41b22977010636be5c2717jim "</a></pre>\n", NULL);
560fd0658902ab57754616c172d8953e69fc4722bnicholes }
e8f95a682820a599fe41b22977010636be5c2717jim if (!strcasecmp(menu, "unformatted")) {
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe ap_rvputs(r, "<a href=\"", href, "\">", text, "</a>", NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic void menu_directive(request_rec *r, char *menu, char *href, char *text)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(href, "error") || !strcasecmp(href, "nocontent")) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return; /* don't print such lines, as this isn't
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes really an href */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(menu, "formatted")) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rvputs(r, "<pre> <a href=\"", href, "\">", text,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "</a></pre>\n", NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(menu, "semiformatted")) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rvputs(r, "<pre> <a href=\"", href, "\">", text,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "</a></pre>\n", NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(menu, "unformatted")) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rvputs(r, "<a href=\"", href, "\">", text, "</a>", NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic void menu_footer(request_rec *r)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener{
ebe5305f8b22507374358f32b74d12fb50c05a25covener ap_rputs("\n\n</body>\n</html>\n", r); /* finish the menu */
ebe5305f8b22507374358f32b74d12fb50c05a25covener}
ebe5305f8b22507374358f32b74d12fb50c05a25covener
ebe5305f8b22507374358f32b74d12fb50c05a25covenerstatic int imap_handler(request_rec *r)
ebe5305f8b22507374358f32b74d12fb50c05a25covener{
ebe5305f8b22507374358f32b74d12fb50c05a25covener char input[MAX_STRING_LEN];
ebe5305f8b22507374358f32b74d12fb50c05a25covener char *directive;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener char *value;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener char *href_text;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener char *base;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener char *redirect;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener char *mapdflt;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener char *closest = NULL;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener double closest_yet = -1;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener double testpoint[2];
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener double pointarray[MAXVERTS + 1][2];
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener int vertex;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener char *string_pos;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int showmenu = 0;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes imap_conf_rec *icr = ap_get_module_config(r->per_dir_config, &imap_module);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *imap_menu = icr->imap_menu ? icr->imap_menu : IMAP_MENU_DEFAULT;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener char *imap_default = icr->imap_default
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ? icr->imap_default : IMAP_DEFAULT_DEFAULT;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *imap_base = icr->imap_base ? icr->imap_base : IMAP_BASE_DEFAULT;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes configfile_t *imap;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (r->method_number != M_GET) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return DECLINED;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin imap = ap_pcfg_openfile(r->pool, r->filename);
560fd0658902ab57754616c172d8953e69fc4722bnicholes
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (!imap) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return NOT_FOUND;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener base = imap_url(r, NULL, imap_base); /* set base according
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener to default */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!base) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return HTTP_INTERNAL_SERVER_ERROR;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes mapdflt = imap_url(r, NULL, imap_default); /* and default to
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes global default */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!mapdflt) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return HTTP_INTERNAL_SERVER_ERROR;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes testpoint[X] = get_x_coord(r->args);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes testpoint[Y] = get_y_coord(r->args);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((testpoint[X] == -1 || testpoint[Y] == -1) ||
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes (testpoint[X] == 0 && testpoint[Y] == 0)) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* if either is -1 or if both are zero (new Lynx) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* we don't have valid coordinates */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes testpoint[X] = -1;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe testpoint[Y] = -1;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe if (strncasecmp(imap_menu, "none", 2)) {
e8f95a682820a599fe41b22977010636be5c2717jim showmenu = 1; /* show the menu _unless_ ImapMenu is
e8f95a682820a599fe41b22977010636be5c2717jim 'none' or 'no' */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (showmenu) { /* send start of imagemap menu if
e8f95a682820a599fe41b22977010636be5c2717jim we're going to */
e8f95a682820a599fe41b22977010636be5c2717jim menu_header(r, imap_menu);
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (!ap_cfg_getline(input, sizeof(input), imap)) {
e8f95a682820a599fe41b22977010636be5c2717jim if (!input[0]) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (showmenu) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes menu_blank(r, imap_menu);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes continue;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (input[0] == '#') {
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe if (showmenu) {
e8f95a682820a599fe41b22977010636be5c2717jim menu_comment(r, imap_menu, input + 1);
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes continue;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes } /* blank lines and comments are ignored
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if we aren't printing a menu */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* find the first two space delimited fields, recall that
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * ap_cfg_getline has removed leading/trailing whitespace.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * note that we're tokenizing as we go... if we were to use the
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * ap_getword() class of functions we would end up allocating extra
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * memory for every line of the map file
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes string_pos = input;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!*string_pos) { /* need at least two fields */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes goto need_2_fields;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes directive = string_pos;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (*string_pos && !ap_isspace(*string_pos)) { /* past directive */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ++string_pos;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!*string_pos) { /* need at least two fields */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes goto need_2_fields;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *string_pos++ = '\0';
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!*string_pos) { /* need at least two fields */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes goto need_2_fields;
e8f95a682820a599fe41b22977010636be5c2717jim }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while(*string_pos && ap_isspace(*string_pos)) { /* past whitespace */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ++string_pos;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes value = string_pos;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (*string_pos && !ap_isspace(*string_pos)) { /* past value */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ++string_pos;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (ap_isspace(*string_pos)) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *string_pos++ = '\0';
e8f95a682820a599fe41b22977010636be5c2717jim }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes else {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* end of input, don't advance past it */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *string_pos = '\0';
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strncasecmp(directive, "base", 4)) { /* base, base_uri */
43c3e6a4b559b76b750c245ee95e2782c15b4296jim base = imap_url(r, NULL, value);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!base) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes goto menu_bail;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes continue; /* base is never printed to a menu */
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes }
43c3e6a4b559b76b750c245ee95e2782c15b4296jim
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes read_quoted(&string_pos, &href_text);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(directive, "default")) { /* default */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes mapdflt = imap_url(r, NULL, value);
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe if (!mapdflt) {
e8f95a682820a599fe41b22977010636be5c2717jim goto menu_bail;
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes }
e8f95a682820a599fe41b22977010636be5c2717jim if (showmenu) { /* print the default if there's a menu */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe redirect = imap_url(r, base, mapdflt);
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe if (!redirect) {
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe goto menu_bail;
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes menu_default(r, imap_menu, redirect,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes href_text ? href_text : mapdflt);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes continue;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes vertex = 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (vertex < MAXVERTS &&
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes sscanf(string_pos, "%lf%*[, ]%lf",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes &pointarray[vertex][X], &pointarray[vertex][Y]) == 2) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Now skip what we just read... we can't use ANSIism %n */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (ap_isspace(*string_pos)) { /* past whitespace */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes string_pos++;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (ap_isdigit(*string_pos)) { /* and the 1st number */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes string_pos++;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes string_pos++; /* skip the ',' */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (ap_isspace(*string_pos)) { /* past any more whitespace */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes string_pos++;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (ap_isdigit(*string_pos)) { /* 2nd number */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes string_pos++;
e8f95a682820a599fe41b22977010636be5c2717jim }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes vertex++;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe } /* so long as there are more vertices to
e8f95a682820a599fe41b22977010636be5c2717jim read, and we have room, read them in.
e8f95a682820a599fe41b22977010636be5c2717jim We start where we left off of the last
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe sscanf, not at the beginning. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pointarray[vertex][X] = -1; /* signals the end of vertices */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (showmenu) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!href_text) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes read_quoted(&string_pos, &href_text); /* href text could
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes be here instead */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes redirect = imap_url(r, base, value);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!redirect) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes goto menu_bail;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes menu_directive(r, imap_menu, redirect,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes href_text ? href_text : value);
e8f95a682820a599fe41b22977010636be5c2717jim continue;
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem }
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* note that we don't make it past here if we are making a menu */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (testpoint[X] == -1 || pointarray[0][X] == -1) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes continue; /* don't try the following tests if testpoints
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe are invalid, or if there are no
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe coordinates */
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(directive, "poly")) { /* poly */
e8f95a682820a599fe41b22977010636be5c2717jim
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (pointinpoly(testpoint, pointarray)) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_cfg_closefile(imap);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes redirect = imap_url(r, base, value);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!redirect) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return HTTP_INTERNAL_SERVER_ERROR;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe return (imap_reply(r, redirect));
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe }
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe continue;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(directive, "circle")) { /* circle */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (pointincircle(testpoint, pointarray)) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_cfg_closefile(imap);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes redirect = imap_url(r, base, value);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!redirect) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return HTTP_INTERNAL_SERVER_ERROR;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return (imap_reply(r, redirect));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes continue;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
e8f95a682820a599fe41b22977010636be5c2717jim
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(directive, "rect")) { /* rect */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (pointinrect(testpoint, pointarray)) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_cfg_closefile(imap);
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj redirect = imap_url(r, base, value);
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj if (!redirect) {
e8f95a682820a599fe41b22977010636be5c2717jim return HTTP_INTERNAL_SERVER_ERROR;
e8f95a682820a599fe41b22977010636be5c2717jim }
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe return (imap_reply(r, redirect));
e8f95a682820a599fe41b22977010636be5c2717jim }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes continue;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strcasecmp(directive, "point")) { /* point */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (is_closer(testpoint, pointarray, &closest_yet)) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes closest = ap_pstrdup(r->pool, value);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes continue;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes } /* move on to next line whether it's
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes closest or not */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes } /* nothing matched, so we get another line! */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_cfg_closefile(imap); /* we are done with the map file; close it */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (showmenu) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes menu_footer(r); /* finish the menu and we are done */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return OK;
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj }
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj if (closest) { /* if a 'point' directive has been seen */
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj redirect = imap_url(r, base, closest);
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj if (!redirect) {
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj return HTTP_INTERNAL_SERVER_ERROR;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return (imap_reply(r, redirect));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (mapdflt) { /* a default should be defined, even if
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes only 'nocontent' */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes redirect = imap_url(r, base, mapdflt);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!redirect) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return HTTP_INTERNAL_SERVER_ERROR;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return (imap_reply(r, redirect));
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj }
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return HTTP_INTERNAL_SERVER_ERROR; /* If we make it this far,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes we failed. They lose! */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesneed_2_fields:
bb07ee33bce1a448bcc60ca43720b1ab1c413f87minfrin ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
bb07ee33bce1a448bcc60ca43720b1ab1c413f87minfrin "map file %s, line %d syntax error: requires at "
bb07ee33bce1a448bcc60ca43720b1ab1c413f87minfrin "least two fields", r->uri, imap->line_number);
bb07ee33bce1a448bcc60ca43720b1ab1c413f87minfrin /* fall through */
e8f95a682820a599fe41b22977010636be5c2717jimmenu_bail:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_cfg_closefile(imap);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (showmenu) {
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes /* There's not much else we can do ... we've already sent the headers
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * to the client.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rputs("\n\n[an internal server error occured]\n", r);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes menu_footer(r);
e8f95a682820a599fe41b22977010636be5c2717jim return OK;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return HTTP_INTERNAL_SERVER_ERROR;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic const handler_rec imap_handlers[] =
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj {IMAP_MAGIC_TYPE, imap_handler},
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj {"imap-file", imap_handler},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {NULL}
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe};
e8f95a682820a599fe41b22977010636be5c2717jim
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowemodule MODULE_VAR_EXPORT imap_module =
e8f95a682820a599fe41b22977010636be5c2717jim{
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe STANDARD20_MODULE_STUFF,
e8f95a682820a599fe41b22977010636be5c2717jim create_imap_dir_config, /* dir config creater */
e8f95a682820a599fe41b22977010636be5c2717jim merge_imap_dir_configs, /* dir merger --- default is to override */
e8f95a682820a599fe41b22977010636be5c2717jim NULL, /* server config */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe NULL, /* merge server config */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe imap_cmds, /* command ap_table_t */
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj imap_handlers, /* handlers */
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj NULL /* register hooks */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem};
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem