brian 97/09/15 21:30:26
Modified: src INDENT src/modules/standard mod_mime_magic.c mod_speling.c mod_unique_id.c mod_userdir.c Log: Okay, enough damage for tonight. If any of this is wrong, someone please scream. If not, I'll try and do some more tomorrow; I'm just being extra careful. Revision Changes Path 1.24 +4 -4 apachen/src/INDENT Index: INDENT =================================================================== RCS file: /export/home/cvs/apachen/src/INDENT,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- INDENT 1997/09/16 03:51:29 1.23 +++ INDENT 1997/09/16 04:30:13 1.24 @@ -82,15 +82,15 @@ mod_log_referer.c mod_mime.c mod_mime.h - mod_mime_magic.c RESERVED by Brian + mod_mime_magic.c DONE by Brian mod_negotiation.c DONE by Ken mod_rewrite.c mod_rewrite.h mod_setenvif.c DONE by Ken - mod_speling.c RESERVED by Brian + mod_speling.c DONE by Brian mod_status.c - mod_unique_id.c RESERVED by Brian - mod_userdir.c RESERVED by Brian + mod_unique_id.c DONE by Brian + mod_userdir.c DONE by Brian mod_usertrack.c DONE by Brian ./os/unix: 1.15 +354 -385 apachen/src/modules/standard/mod_mime_magic.c Index: mod_mime_magic.c =================================================================== RCS file: /export/home/cvs/apachen/src/modules/standard/mod_mime_magic.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- mod_mime_magic.c 1997/09/01 02:22:56 1.14 +++ mod_mime_magic.c 1997/09/16 04:30:21 1.15 @@ -6,7 +6,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -53,39 +53,39 @@ /* * mod_mime_magic: MIME type lookup via file magic numbers * Copyright (c) 1996-1997 Cisco Systems, Inc. - * + * * This software was submitted by Cisco Systems to the Apache Group in July * 1997. Future revisions and derivatives of this source code must * acknowledge Cisco Systems as the original contributor of this module. * All other licensing and usage conditions are those of the Apache Group. - * + * * Some of this code is derived from the free version of the file command * originally posted to comp.sources.unix. Copyright info for that program * is included below as required. * --------------------------------------------------------------------------- * - Copyright (c) Ian F. Darwin, 1987. Written by Ian F. Darwin. - * + * * This software is not subject to any license of the American Telephone and * Telegraph Company or of the Regents of the University of California. - * + * * Permission is granted to anyone to use this software for any purpose on any * computer system, and to alter it and redistribute it freely, subject to * the following restrictions: - * + * * 1. The author is not responsible for the consequences of use of this * software, no matter how awful, even if they arise from flaws in it. - * + * * 2. The origin of this software must not be misrepresented, either by * explicit claim or by omission. Since few users ever read sources, credits * must appear in the documentation. - * + * * 3. Altered versions must be plainly marked as such, and must not be * misrepresented as being the original software. Since few users ever read * sources, credits must appear in the documentation. - * + * * 4. This notice may not be removed or altered. * ------------------------------------------------------------------------- - * + * * For compliance with Mr Darwin's terms: this has been very significantly * modified from the free "file" command. * - all-in-one file for compilation convenience when moving from one @@ -105,17 +105,17 @@ * list where they're used to set the MIME type in the Apache request * record. * - Command-line flags have been removed since they will never be used here. - * + * * Ian Kluft <[EMAIL PROTECTED]> * Engineering Information Framework * Central Engineering * Cisco Systems, Inc. * San Jose, CA, USA - * + * * Initial installation July/August 1996 * Misc bug fixes May 1997 * Submission to Apache Group July 1997 - * + * */ #include "httpd.h" @@ -143,26 +143,26 @@ #define MAXMIMESTRING 256 -#define HOWMANY 1024 /* big enough to recognize most WWW files */ -#define MAXDESC 50 /* max leng of text description */ -#define MAXstring 64 /* max leng of "string" types */ +#define HOWMANY 1024 /* big enough to recognize most WWW files */ +#define MAXDESC 50 /* max leng of text description */ +#define MAXstring 64 /* max leng of "string" types */ struct magic { - struct magic *next; /* link to next entry */ - int lineno; /* line number from magic file */ + struct magic *next; /* link to next entry */ + int lineno; /* line number from magic file */ short flag; -#define INDIR 1 /* if '>(...)' appears, */ -#define UNSIGNED 2 /* comparison is unsigned */ - short cont_level; /* level of ">" */ +#define INDIR 1 /* if '>(...)' appears, */ +#define UNSIGNED 2 /* comparison is unsigned */ + short cont_level; /* level of ">" */ struct { - char type; /* byte short long */ - long offset; /* offset from indirection */ - } in; - long offset; /* offset to magic number */ - unsigned char reln; /* relation (0=eq, '>'=gt, etc) */ - char type; /* int, short, long or string. */ - char vallen; /* length of string value, if any */ + char type; /* byte short long */ + long offset; /* offset from indirection */ + } in; + long offset; /* offset to magic number */ + unsigned char reln; /* relation (0=eq, '>'=gt, etc) */ + char type; /* int, short, long or string. */ + char vallen; /* length of string value, if any */ #define BYTE 1 #define SHORT 2 #define LONG 4 @@ -181,24 +181,24 @@ char s[MAXstring]; unsigned char hs[2]; /* 2 bytes of a fixed-endian "short" */ unsigned char hl[4]; /* 2 bytes of a fixed-endian "long" */ - } value; /* either number or string */ - unsigned long mask; /* mask before comparison with value */ - char nospflag; /* supress space character */ + } value; /* either number or string */ + unsigned long mask; /* mask before comparison with value */ + char nospflag; /* supress space character */ /* NOTE: this string is suspected of overrunning - find it! */ - char desc[MAXDESC]; /* description */ + char desc[MAXDESC]; /* description */ }; /* * data structures for tar file recognition * -------------------------------------------------------------------------- * Header file for public domain tar (tape archive) program. - * + * * @(#)tar.h 1.20 86/10/29 Public Domain. Created 25 August 1985 by John * Gilmore, ihnp4!hoptoad!gnu. - * + * * Header block on tape. - * + * * I'm going to use traditional DP naming conventions here. A "block" is a big * chunk of stuff that we do I/O on. A "record" is a piece of info that we * care about. Typically many "record"s fit into a "block". @@ -225,11 +225,11 @@ char gname[TGNMLEN]; char devmajor[8]; char devminor[8]; - } header; + } header; }; /* The magic field is filled with this if uname and gname are valid. */ -#define TMAGIC "ustar " /* 7 chars and a null */ +#define TMAGIC "ustar " /* 7 chars and a null */ /* * file-function prototypes @@ -246,26 +246,24 @@ static int getvalue(server_rec *, struct magic *, char **); static int hextoint(int); static char *getstr(server_rec *, char *, char *, int, int *); -static int parse(server_rec *, pool * p, char *, int); +static int parse(server_rec *, pool *p, char *, int); static int match(request_rec *, unsigned char *, int); -static int -mget(request_rec *, union VALUETYPE *, unsigned char *, - struct magic *, int); +static int mget(request_rec *, union VALUETYPE *, unsigned char *, + struct magic *, int); static int mcheck(request_rec *, union VALUETYPE *, struct magic *); static void mprint(request_rec *, union VALUETYPE *, struct magic *); static int mconvert(request_rec *, union VALUETYPE *, struct magic *); -static int -uncompress(request_rec *, int, const unsigned char *, - unsigned char **, int); +static int uncompress(request_rec *, int, const unsigned char *, + unsigned char **, int); static long from_oct(int, char *); -static int fsmagic(request_rec * r, const char *fn, struct stat * sb); +static int fsmagic(request_rec *r, const char *fn, struct stat * sb); /* * includes for ASCII substring recognition formerly "names.h" in file * command - * + * * Original notes: names and types used by ascmagic in file(1). These tokens are * here because they can appear anywhere in the first HOWMANY bytes, while * tokens in /etc/magic must appear at fixed offsets into the file. Don't @@ -274,29 +272,29 @@ /* these types are used to index the table 'types': keep em in sync! */ /* HTML inserted in first because this is a web server module now */ -#define L_HTML 0 /* HTML */ -#define L_C 1 /* first and foremost on UNIX */ -#define L_FORT 2 /* the oldest one */ -#define L_MAKE 3 /* Makefiles */ -#define L_PLI 4 /* PL/1 */ -#define L_MACH 5 /* some kinda assembler */ -#define L_ENG 6 /* English */ -#define L_PAS 7 /* Pascal */ -#define L_MAIL 8 /* Electronic mail */ -#define L_NEWS 9 /* Usenet Netnews */ +#define L_HTML 0 /* HTML */ +#define L_C 1 /* first and foremost on UNIX */ +#define L_FORT 2 /* the oldest one */ +#define L_MAKE 3 /* Makefiles */ +#define L_PLI 4 /* PL/1 */ +#define L_MACH 5 /* some kinda assembler */ +#define L_ENG 6 /* English */ +#define L_PAS 7 /* Pascal */ +#define L_MAIL 8 /* Electronic mail */ +#define L_NEWS 9 /* Usenet Netnews */ static char *types[] = { - "text/html", /* HTML */ - "text/plain", /* "c program text", */ - "text/plain", /* "fortran program text", */ - "text/plain", /* "make commands text", */ - "text/plain", /* "pl/1 program text", */ - "text/plain", /* "assembler program text", */ - "text/plain", /* "English text", */ - "text/plain", /* "pascal program text", */ - "message/rfc822", /* "mail text", */ - "message/news", /* "news text", */ - "application/binary", /* "can't happen error on names.h/types", */ + "text/html", /* HTML */ + "text/plain", /* "c program text", */ + "text/plain", /* "fortran program text", */ + "text/plain", /* "make commands text", */ + "text/plain", /* "pl/1 program text", */ + "text/plain", /* "assembler program text", */ + "text/plain", /* "English text", */ + "text/plain", /* "pascal program text", */ + "message/rfc822", /* "mail text", */ + "message/news", /* "news text", */ + "application/binary", /* "can't happen error on names.h/types", */ 0}; static struct names { @@ -337,7 +335,7 @@ }, { "/*", L_C - }, /* must precede "The", "the", etc. */ + }, /* must precede "The", "the", etc. */ { "#include", L_C }, @@ -381,8 +379,8 @@ ".PRECIOUS", L_MAKE }, /* - * Too many files of text have these words in them. Find another way - * to recognize Fortrash. + * Too many files of text have these words in them. Find another way to + * recognize Fortrash. */ #ifdef NOTDEF { @@ -406,7 +404,7 @@ { "data", L_FORT }, -#endif /* NOTDEF */ +#endif /* NOTDEF */ { ".ascii", L_MACH }, @@ -461,16 +459,16 @@ /* * Result String List (RSL) - * + * * The file(1) command prints its output. Instead, we store the various * "printed" strings in a list (allocating memory as we go) and concatenate * them at the end when we finally know how much space they'll need. */ typedef struct magic_rsl_s { - char *str; /* string, possibly a fragment */ - struct magic_rsl_s *next; /* pointer to next fragment */ -} magic_rsl; + char *str; /* string, possibly a fragment */ + struct magic_rsl_s *next; /* pointer to next fragment */ +} magic_rsl; /* * Apache module configuration structures @@ -478,17 +476,17 @@ /* per-server info */ typedef struct { - char *magicfile; /* where magic be found */ - struct magic *magic, /* head of magic config list */ - *last; -} magic_server_config_rec; + char *magicfile; /* where magic be found */ + struct magic *magic, /* head of magic config list */ + *last; +} magic_server_config_rec; /* per-request info */ typedef struct { - magic_rsl *head, /* result string list */ - *tail; - unsigned suf_recursion; /* recursion depth in suffix check */ -} magic_req_rec; + magic_rsl *head, /* result string list */ + *tail; + unsigned suf_recursion; /* recursion depth in suffix check */ +} magic_req_rec; /* * configuration functions - called by Apache API routines @@ -498,19 +496,19 @@ extern module mime_module; static void * -create_magic_server_config(pool * p, server_rec *d) + create_magic_server_config(pool *p, server_rec *d) { /* allocate the config - use pcalloc because it needs to be zeroed */ return pcalloc(p, sizeof(magic_server_config_rec)); } static void * -merge_magic_server_config(pool * p, void *basev, void *addv) + merge_magic_server_config(pool *p, void *basev, void *addv) { magic_server_config_rec *base = (magic_server_config_rec *) basev; magic_server_config_rec *add = (magic_server_config_rec *) addv; magic_server_config_rec *new = (magic_server_config_rec *) - palloc(p, sizeof(magic_server_config_rec)); + palloc(p, sizeof(magic_server_config_rec)); new->magicfile = add->magicfile ? add->magicfile : base->magicfile; if (add->magic && add->last) { @@ -528,11 +526,11 @@ } static const char * -set_magicfile(cmd_parms * cmd, char *d, char *arg) + set_magicfile(cmd_parms *cmd, char *d, char *arg) { magic_server_config_rec *conf = (magic_server_config_rec *) - get_module_config(cmd->server->module_config, - &mime_magic_module); + get_module_config(cmd->server->module_config, + &mime_magic_module); if (!conf) { return MODNAME ": server structure not allocated"; @@ -553,12 +551,12 @@ /* * RSL (result string list) processing routines - * + * * These collect strings that would have been printed in fragments by file(1) * into a list of magic_rsl structures with the strings. When complete, * they're concatenated together to become the MIME content and encoding * types. - * + * * return value conventions for these functions: functions which return int: * failure = -1, other = result functions which return pointers: failure = 0, * other = result @@ -566,15 +564,15 @@ /* allocate a per-request structure and put it in the request record */ static magic_req_rec * -magic_set_config(request_rec * r) + magic_set_config(request_rec *r) { magic_req_rec *req_dat = (magic_req_rec *) - palloc(r->pool, sizeof(magic_req_rec)); + palloc(r->pool, sizeof(magic_req_rec)); if (!req_dat) { - aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: memory allocation failure in magic_set_config()", - MODNAME); + aplog_error(APLOG_MARK, APLOG_ERR, r->server, + "%s: memory allocation failure in magic_set_config()", + MODNAME); return NULL; } req_dat->head = req_dat->tail = (magic_rsl *) NULL; @@ -584,18 +582,17 @@ /* add a string to the result string list for this request */ /* it is the responsibility of the caller to allocate "str" */ -static int -magic_rsl_add(request_rec * r, char *str) +static int magic_rsl_add(request_rec *r, char *str) { magic_req_rec *req_dat = (magic_req_rec *) - get_module_config(r->request_config, &mime_magic_module); + get_module_config(r->request_config, &mime_magic_module); magic_rsl *rsl; /* make sure we have a list to put it in */ if (!req_dat) { - aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: request config should not be NULL", - MODNAME); + aplog_error(APLOG_MARK, APLOG_ERR, r->server, + "%s: request config should not be NULL", + MODNAME); if (!(req_dat = magic_set_config(r))) { /* failure */ return -1; @@ -605,8 +602,8 @@ /* allocate the list entry */ if (!(rsl = (magic_rsl *) palloc(r->pool, sizeof(magic_rsl)))) { aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: memory allocation failure in magic_rsl_add()", - MODNAME); + "%s: memory allocation failure in magic_rsl_add()", + MODNAME); /* failure */ return -1; } @@ -629,15 +626,13 @@ } /* RSL hook for puts-type functions */ -static int -magic_rsl_puts(request_rec * r, char *str) +static int magic_rsl_puts(request_rec *r, char *str) { return magic_rsl_add(r, str); } /* RSL hook for printf-type functions */ -static int -magic_rsl_printf(request_rec * r, char *str,...) +static int magic_rsl_printf(request_rec *r, char *str,...) { va_list ap; @@ -653,8 +648,7 @@ } /* RSL hook for putchar-type functions */ -static int -magic_rsl_putchar(request_rec * r, char c) +static int magic_rsl_putchar(request_rec *r, char c) { char str[2]; @@ -666,22 +660,22 @@ /* allocate and copy a contiguous string from a result string list */ static char * -rsl_strdup(request_rec * r, int start_frag, int start_pos, int len) + rsl_strdup(request_rec *r, int start_frag, int start_pos, int len) { - char *result; /* return value */ - int cur_frag, /* current fragment number/counter */ - cur_pos, /* current position within fragment */ - res_pos; /* position in result string */ - magic_rsl *frag; /* list-traversal pointer */ + char *result; /* return value */ + int cur_frag, /* current fragment number/counter */ + cur_pos, /* current position within fragment */ + res_pos; /* position in result string */ + magic_rsl *frag; /* list-traversal pointer */ magic_req_rec *req_dat = (magic_req_rec *) - get_module_config(r->request_config, &mime_magic_module); + get_module_config(r->request_config, &mime_magic_module); /* allocate the result string */ if (!(result = (char *) palloc(r->pool, len + 1))) { aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: memory allocation failure in rsl_strdup()", - MODNAME); + "%s: memory allocation failure in rsl_strdup()", + MODNAME); return NULL; } @@ -713,7 +707,7 @@ result[res_pos] = 0; #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%s: rsl_strdup() %d chars: %s", MODNAME, res_pos - 1, result); + "%s: rsl_strdup() %d chars: %s", MODNAME, res_pos - 1, result); #endif return result; } @@ -721,26 +715,25 @@ /* states for the state-machine algorithm in magic_rsl_to_request() */ typedef enum { rsl_leading_space, rsl_type, rsl_subtype, rsl_separator, rsl_encoding -} rsl_states; +} rsl_states; /* process the RSL and set the MIME info in the request record */ -static int -magic_rsl_to_request(request_rec * r) +static int magic_rsl_to_request(request_rec *r) { - int cur_frag, /* current fragment number/counter */ - cur_pos, /* current position within fragment */ - type_frag, /* content type starting point: fragment */ - type_pos, /* content type starting point: position */ - type_len, /* content type length */ - encoding_frag, /* content encoding starting point: fragment */ - encoding_pos, /* content encoding starting point: position */ - encoding_len; /* content encoding length */ + int cur_frag, /* current fragment number/counter */ + cur_pos, /* current position within fragment */ + type_frag, /* content type starting point: fragment */ + type_pos, /* content type starting point: position */ + type_len, /* content type length */ + encoding_frag, /* content encoding starting point: fragment */ + encoding_pos, /* content encoding starting point: position */ + encoding_len; /* content encoding length */ - magic_rsl *frag; /* list-traversal pointer */ + magic_rsl *frag; /* list-traversal pointer */ rsl_states state; magic_req_rec *req_dat = (magic_req_rec *) - get_module_config(r->request_config, &mime_magic_module); + get_module_config(r->request_config, &mime_magic_module); /* check if we have a result */ if (!req_dat || !req_dat->head) { @@ -786,13 +779,13 @@ /* should not be possible */ /* abandon malfunctioning module */ aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: bad state %d (ws)", MODNAME); + "%s: bad state %d (ws)", MODNAME); return DECLINED; } /* NOTREACHED */ } else if (state == rsl_type && - frag->str[cur_pos] == '/') { + frag->str[cur_pos] == '/') { /* copy the char and go to rsl_subtype state */ type_len++; state++; @@ -808,7 +801,7 @@ continue; } else if (state == rsl_type || - state == rsl_subtype) { + state == rsl_subtype) { /* non-space: adds to type */ type_len++; continue; @@ -830,7 +823,7 @@ /* should not be possible */ /* abandon malfunctioning module */ aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: bad state %d (ns)", MODNAME); + "%s: bad state %d (ns)", MODNAME); return DECLINED; } /* NOTREACHED */ @@ -853,7 +846,7 @@ } if (state == rsl_encoding) { r->content_encoding = rsl_strdup(r, encoding_frag, - encoding_pos, encoding_len); + encoding_pos, encoding_len); } /* detect memory allocation errors */ @@ -871,14 +864,13 @@ * (formerly called "process" in file command, prefix added for clarity) Opens * the file and reads a fixed-size buffer to begin processing the contents. */ -static void -magic_process(request_rec * r) +static void magic_process(request_rec *r) { int fd = 0; - unsigned char buf[HOWMANY + 1]; /* one extra for terminating '\0' */ + unsigned char buf[HOWMANY + 1]; /* one extra for terminating '\0' */ struct utimbuf utbuf; struct stat sb; - int nbytes = 0; /* number of bytes read from a datafile */ + int nbytes = 0; /* number of bytes read from a datafile */ /* * first try judging the file based on its filesystem status @@ -891,8 +883,8 @@ if ((fd = open(r->filename, O_RDONLY)) < 0) { /* We can't open it, but we were able to stat it. */ /* - * if (sb.st_mode & 0002) magic_rsl_puts(r,"writable, "); if - * (sb.st_mode & 0111) magic_rsl_puts(r,"executable, "); + * if (sb.st_mode & 0002) magic_rsl_puts(r,"writable, "); + * if (sb.st_mode & 0111) magic_rsl_puts(r,"executable, "); */ aplog_error(APLOG_MARK, APLOG_ERR, r->server, "can't read `%s'", r->filename); return; @@ -909,7 +901,7 @@ if (nbytes == 0) magic_rsl_puts(r, MIME_TEXT_UNKNOWN); else { - buf[nbytes++] = '\0'; /* null-terminate it */ + buf[nbytes++] = '\0'; /* null-terminate it */ tryit(r, buf, nbytes); } @@ -918,14 +910,13 @@ */ utbuf.actime = sb.st_atime; utbuf.modtime = sb.st_mtime; - (void) utime(r->filename, &utbuf); /* don't care if loses */ + (void) utime(r->filename, &utbuf); /* don't care if loses */ (void) close(fd); (void) magic_rsl_putchar(r, '\n'); } -static void -tryit(request_rec * r, unsigned char *buf, int nb) +static void tryit(request_rec *r, unsigned char *buf, int nb) { /* * Try compression stuff @@ -958,7 +949,7 @@ * apprentice - load configuration from the magic file r * API request record */ -static int apprentice (server_rec * s, pool * p) +static int apprentice(server_rec *s, pool *p) { FILE *f; char line[BUFSIZ + 1]; @@ -971,7 +962,7 @@ char *fname; magic_server_config_rec *conf = (magic_server_config_rec *) - get_module_config(s->module_config, &mime_magic_module); + get_module_config(s->module_config, &mime_magic_module); if (!conf->magicfile) { conf->magicfile = pstrdup(p, MAGIC); @@ -979,8 +970,8 @@ fname = server_root_relative(p, conf->magicfile); f = pfopen(p, fname, "r"); if (f == NULL) { - aplog_error(APLOG_MARK, APLOG_ERR, s, - "%s: can't read magic file %s", MODNAME, fname); + aplog_error(APLOG_MARK, APLOG_ERR, s, + "%s: can't read magic file %s", MODNAME, fname); return -1; } @@ -1025,15 +1016,15 @@ #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, s, - "%s: apprentice conf=%x file=%s m=%s m->next=%s last=%s", - MODNAME, conf, - conf->magicfile ? conf->magicfile : "NULL", - conf->magic ? "set" : "NULL", - (conf->magic && conf->magic->next) ? "set" : "NULL", - conf->last ? "set" : "NULL"); + "%s: apprentice conf=%x file=%s m=%s m->next=%s last=%s", + MODNAME, conf, + conf->magicfile ? conf->magicfile : "NULL", + conf->magic ? "set" : "NULL", + (conf->magic && conf->magic->next) ? "set" : "NULL", + conf->last ? "set" : "NULL"); aplog_error(APLOG_MARK, APLOG_DEBUG, s, - "%s: apprentice read %d lines, %d rules, %d errors", - MODNAME, lineno, rule, errs); + "%s: apprentice read %d lines, %d rules, %d errors", + MODNAME, lineno, rule, errs); #endif #if MIME_MAGIC_DEBUG @@ -1045,13 +1036,13 @@ isprint((((unsigned long) m) >> 8) & 255) && isprint(((unsigned long) m) & 255)) { aplog_error(APLOG_MARK, APLOG_DEBUG, s, - "%s: apprentice: POINTER CLOBBERED! " - "m=\"%c%c%c%c\" line=%d", MODNAME, - (((unsigned long) m) >> 24) & 255, - (((unsigned long) m) >> 16) & 255, - (((unsigned long) m) >> 8) & 255, - ((unsigned long) m) & 255, - prevm ? prevm->lineno : -1); + "%s: apprentice: POINTER CLOBBERED! " + "m=\"%c%c%c%c\" line=%d", MODNAME, + (((unsigned long) m) >> 24) & 255, + (((unsigned long) m) >> 16) & 255, + (((unsigned long) m) >> 8) & 255, + ((unsigned long) m) & 255, + prevm ? prevm->lineno : -1); break; } prevm = m; @@ -1064,14 +1055,13 @@ /* * extend the sign bit if the comparison is to be signed */ -static unsigned long signextend (server_rec * s, struct magic * m, unsigned long v) +static unsigned long signextend(server_rec *s, struct magic * m, unsigned long v) { if (!(m->flag & UNSIGNED)) switch (m->type) { /* - * Do not remove the casts below. They are vital. - * When later compared with the data, the sign - * extension must have happened. + * Do not remove the casts below. They are vital. When later + * compared with the data, the sign extension must have happened. */ case BYTE: v = (char) v; @@ -1093,7 +1083,7 @@ break; default: aplog_error(APLOG_MARK, APLOG_ERR, s, - "%s: can't happen: m->type=%d", MODNAME, m->type); + "%s: can't happen: m->type=%d", MODNAME, m->type); return -1; } return v; @@ -1102,19 +1092,18 @@ /* * parse one line from magic file, put into magic[index++] if valid */ -static int -parse(server_rec * serv, pool * p, char *l, int lineno) +static int parse(server_rec *serv, pool *p, char *l, int lineno) { int i = 0; struct magic *m; char *t, *s; magic_server_config_rec *conf = (magic_server_config_rec *) - get_module_config(serv->module_config, &mime_magic_module); + get_module_config(serv->module_config, &mime_magic_module); /* allocate magic structure entry */ if ((m = (struct magic *) pcalloc(p, sizeof(struct magic))) == NULL) { (void) aplog_error(APLOG_MARK, APLOG_ERR, serv, - "%s: Out of memory.", MODNAME); + "%s: Out of memory.", MODNAME); return -1; } @@ -1134,12 +1123,12 @@ m->lineno = lineno; while (*l == '>') { - ++l; /* step over */ + ++l; /* step over */ m->cont_level++; } if (m->cont_level != 0 && *l == '(') { - ++l; /* step over */ + ++l; /* step over */ m->flag |= INDIR; } @@ -1147,7 +1136,7 @@ m->offset = (int) strtol(l, &t, 0); if (l == t) { aplog_error(APLOG_MARK, APLOG_ERR, serv, - "%s: offset %s invalid", MODNAME, l); + "%s: offset %s invalid", MODNAME, l); } l = t; @@ -1170,7 +1159,7 @@ break; default: aplog_error(APLOG_MARK, APLOG_ERR, serv, - "%s: indirect offset type %c invalid", MODNAME, *l); + "%s: indirect offset type %c invalid", MODNAME, *l); break; } l++; @@ -1187,7 +1176,7 @@ t = l; if (*t++ != ')') { aplog_error(APLOG_MARK, APLOG_ERR, serv, - "%s: missing ')' in indirect offset", MODNAME); + "%s: missing ')' in indirect offset", MODNAME); } l = t; } @@ -1261,7 +1250,7 @@ } else { aplog_error(APLOG_MARK, APLOG_ERR, serv, - "%s: type %s invalid", MODNAME, l); + "%s: type %s invalid", MODNAME, l); return -1; } /* New-style anding: "0 byte&0x80 =0x80 dynamically linked" */ @@ -1295,7 +1284,7 @@ isspace((unsigned char) l[1])) { m->reln = *l; ++l; - goto GetDesc; /* Bill The Cat */ + goto GetDesc; /* Bill The Cat */ } m->reln = '='; break; @@ -1325,10 +1314,10 @@ #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, serv, - "%s: parse line=%d m=%x next=%x cont=%d desc=%s", - MODNAME, lineno, m, m->next, m->cont_level, - m->desc ? m->desc : "NULL"); -#endif /* MIME_MAGIC_DEBUG */ + "%s: parse line=%d m=%x next=%x cont=%d desc=%s", + MODNAME, lineno, m, m->next, m->cont_level, + m->desc ? m->desc : "NULL"); +#endif /* MIME_MAGIC_DEBUG */ return 0; } @@ -1338,8 +1327,7 @@ * pointer, according to the magic type. Update the string pointer to point * just after the number read. Return 0 for success, non-zero for failure. */ -static int -getvalue(server_rec * s, struct magic * m, char **p) +static int getvalue(server_rec *s, struct magic * m, char **p) { int slen; @@ -1358,8 +1346,8 @@ * *slen. Return updated scan pointer as function result. */ static char * -getstr(server_rec *serv, register char *s, register char *p, - int plen, int *slen) + getstr(server_rec *serv, register char *s, register char *p, + int plen, int *slen) { char *origs = s, *origp = p; char *pmax = p + plen - 1; @@ -1417,10 +1405,10 @@ case '6': case '7': val = c - '0'; - c = *s++; /* try for 2 */ + c = *s++; /* try for 2 */ if (c >= '0' && c <= '7') { val = (val << 3) | (c - '0'); - c = *s++; /* try for 3 */ + c = *s++; /* try for 3 */ if (c >= '0' && c <= '7') val = (val << 3) | (c - '0'); else @@ -1433,8 +1421,8 @@ /* \x and up to 3 hex digits */ case 'x': - val = 'x'; /* Default if no digits */ - c = hextoint(*s++); /* Get next char */ + val = 'x'; /* Default if no digits */ + c = hextoint(*s++); /* Get next char */ if (c >= 0) { val = c; c = hextoint(*s++); @@ -1467,8 +1455,7 @@ /* Single hex char to int; -1 if not a hex char. */ -static int -hextoint(c) +static int hextoint(c) int c; { if (!isascii((unsigned char) c)) @@ -1483,25 +1470,24 @@ } -static int -fsmagic(request_rec * r, const char *fn, struct stat * sb) +static int fsmagic(request_rec *r, const char *fn, struct stat * sb) { int ret = 0; /* - * Fstat is cheaper but fails for files you don't have read perms on. - * On 4.2BSD and similar systems, use lstat() to identify symlinks. + * Fstat is cheaper but fails for files you don't have read perms on. On + * 4.2BSD and similar systems, use lstat() to identify symlinks. */ - ret = stat(fn, sb); /* don't merge into if; see "ret =" above */ + ret = stat(fn, sb); /* don't merge into if; see "ret =" above */ if (ret) { return 1; } /* - * if (sb->st_mode & S_ISUID) magic_rsl_puts(r,"setuid "); if - * (sb->st_mode & S_ISGID) magic_rsl_puts(r,"setgid "); if - * (sb->st_mode & S_ISVTX) magic_rsl_puts(r,"sticky "); + * if (sb->st_mode & S_ISUID) magic_rsl_puts(r,"setuid "); + * if (sb->st_mode & S_ISGID) magic_rsl_puts(r,"setgid "); + * if (sb->st_mode & S_ISVTX) magic_rsl_puts(r,"sticky "); */ switch (sb->st_mode & S_IFMT) { @@ -1540,8 +1526,8 @@ if ((nch = readlink(fn, buf, BUFSIZ - 1)) <= 0) { /* - * magic_rsl_printf(r, "unreadable symlink - * (%s).", strerror(errno)); + * magic_rsl_printf(r, "unreadable symlink (%s).", + * strerror(errno)); */ magic_rsl_puts(r, MIME_BINARY_UNKNOWN); return 1; @@ -1552,8 +1538,8 @@ if (*buf == '/') { if (stat(buf, &tstatbuf) < 0) { /* - * magic_rsl_printf(r, "broken - * symbolic link to %s", buf); + * magic_rsl_printf(r, "broken symbolic link to %s", + * buf); */ magic_rsl_puts(r, MIME_BINARY_UNKNOWN); return 1; @@ -1564,19 +1550,18 @@ char buf2[BUFSIZ + BUFSIZ + 4]; if ((tmp = strrchr(fn, '/')) == NULL) { - tmp = buf; /* in current directory - * anyway */ + tmp = buf; /* in current directory anyway */ } else { - /* directory part plus (relative) symlink */ - ap_snprintf(buf2, sizeof(buf2), "%s%s", - fn, buf); + /* directory part plus (relative) symlink */ + ap_snprintf(buf2, sizeof(buf2), "%s%s", + fn, buf); tmp = buf2; } if (stat(tmp, &tstatbuf) < 0) { /* - * magic_rsl_printf(r, "broken - * symbolic link to %s", buf); + * magic_rsl_printf(r, "broken symbolic link to %s", + * buf); */ magic_rsl_puts(r, MIME_BINARY_UNKNOWN); return 1; @@ -1587,7 +1572,7 @@ /* So just handle it. */ magic_process(r); } - return 1; + return 1; #endif #ifdef S_IFSOCK #ifndef __COHERENT__ @@ -1600,7 +1585,7 @@ break; default: aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: invalid mode 0%o.", MODNAME, sb->st_mode); + "%s: invalid mode 0%o.", MODNAME, sb->st_mode); /* NOTREACHED */ } @@ -1618,9 +1603,8 @@ * softmagic - lookup one file in database (already read from /etc/magic by * apprentice.c). Passed the name and FILE * of one file to be typed. */ -/* ARGSUSED1 *//* nbytes passed for regularity, maybe need later */ -static int -softmagic(request_rec * r, unsigned char *buf, int nbytes) + /* ARGSUSED1 *//* nbytes passed for regularity, maybe need later */ +static int softmagic(request_rec *r, unsigned char *buf, int nbytes) { if (match(r, buf, nbytes)) return 1; @@ -1631,31 +1615,30 @@ /* * Go through the whole list, stopping if you find a match. Process all the * continuations of that match before returning. - * + * * We support multi-level continuations: - * + * * At any time when processing a successful top-level match, there is a current * continuation level; it represents the level of the last successfully * matched continuation. - * + * * Continuations above that level are skipped as, if we see one, it means that * the continuation that controls them - i.e, the lower-level continuation * preceding them - failed to match. - * + * * Continuations below that level are processed as, if we see one, it means * we've finished processing or skipping higher-level continuations under the * control of a successful or unsuccessful lower-level continuation, and are * now seeing the next lower-level continuation and should process it. The * current continuation level reverts to the level of the one we're seeing. - * + * * Continuations at the current level are processed as, if we see one, there's * no lower-level continuation that may have failed. - * + * * If a continuation matches, we bump the current continuation level so that * higher-level continuations are processed. */ -static int -match(request_rec * r, unsigned char *s, int nbytes) +static int match(request_rec *r, unsigned char *s, int nbytes) { #if MIME_MAGIC_DEBUG int rule_counter = 0; @@ -1664,17 +1647,17 @@ int need_separator = 0; union VALUETYPE p; magic_server_config_rec *conf = (magic_server_config_rec *) - get_module_config(r->server->module_config, &mime_magic_module); + get_module_config(r->server->module_config, &mime_magic_module); struct magic *m; #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%s: match conf=%x file=%s m=%s m->next=%s last=%s", - MODNAME, conf, - conf->magicfile ? conf->magicfile : "NULL", - conf->magic ? "set" : "NULL", - (conf->magic && conf->magic->next) ? "set" : "NULL", - conf->last ? "set" : "NULL"); + "%s: match conf=%x file=%s m=%s m->next=%s last=%s", + MODNAME, conf, + conf->magicfile ? conf->magicfile : "NULL", + conf->magic ? "set" : "NULL", + (conf->magic && conf->magic->next) ? "set" : "NULL", + conf->last ? "set" : "NULL"); #endif #if MIME_MAGIC_DEBUG @@ -1684,12 +1667,12 @@ isprint((((unsigned long) m) >> 8) & 255) && isprint(((unsigned long) m) & 255)) { aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%s: match: POINTER CLOBBERED! " - "m=\"%c%c%c%c\"", MODNAME, - (((unsigned long) m) >> 24) & 255, - (((unsigned long) m) >> 16) & 255, - (((unsigned long) m) >> 8) & 255, - ((unsigned long) m) & 255); + "%s: match: POINTER CLOBBERED! " + "m=\"%c%c%c%c\"", MODNAME, + (((unsigned long) m) >> 24) & 255, + (((unsigned long) m) >> 16) & 255, + (((unsigned long) m) >> 8) & 255, + ((unsigned long) m) & 255); break; } } @@ -1699,7 +1682,7 @@ #if MIME_MAGIC_DEBUG rule_counter++; aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%s: line=%d desc=%s", MODNAME, m->lineno, m->desc); + "%s: line=%d desc=%s", MODNAME, m->lineno, m->desc); #endif /* check if main entry matches */ @@ -1719,14 +1702,14 @@ #if MIME_MAGIC_DEBUG rule_counter++; aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%s: line=%d mc=%x mc->next=%x cont=%d desc=%s", - MODNAME, m_cont->lineno, m_cont, - m_cont->next, m_cont->cont_level, - m_cont->desc ? m_cont->desc : "NULL"); + "%s: line=%d mc=%x mc->next=%x cont=%d desc=%s", + MODNAME, m_cont->lineno, m_cont, + m_cont->next, m_cont->cont_level, + m_cont->desc ? m_cont->desc : "NULL"); #endif /* - * this trick allows us to keep *m in sync - * when the continue advances the pointer + * this trick allows us to keep *m in sync when the continue + * advances the pointer */ m = m_cont; m_cont = m_cont->next; @@ -1738,49 +1721,48 @@ /* this will be the last run through the loop */ #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%s: rule matched, line=%d type=%d %s", - MODNAME, m->lineno, m->type, - (m->type == STRING) ? m->value.s : ""); + "%s: rule matched, line=%d type=%d %s", + MODNAME, m->lineno, m->type, + (m->type == STRING) ? m->value.s : ""); #endif /* print the match */ mprint(r, &p, m); /* - * If we printed something, we'll need to print a blank - * before we print something else. + * If we printed something, we'll need to print a blank before we + * print something else. */ if (m->desc[0]) need_separator = 1; /* and any continuations that match */ cont_level++; /* - * while (m && m->next && m->next->cont_level != 0 && ( m = - * m->next )) + * while (m && m->next && m->next->cont_level != 0 && ( m = m->next + * )) */ m = m->next; while (m && (m->cont_level != 0)) { #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%s: match line=%d cont=%d type=%d %s", - MODNAME, m->lineno, m->cont_level, m->type, - (m->type == STRING) ? m->value.s : ""); + "%s: match line=%d cont=%d type=%d %s", + MODNAME, m->lineno, m->cont_level, m->type, + (m->type == STRING) ? m->value.s : ""); #endif if (cont_level >= m->cont_level) { if (cont_level > m->cont_level) { /* - * We're at the end of the level - * "cont_level" continuations. + * We're at the end of the level "cont_level" + * continuations. */ cont_level = m->cont_level; } if (mget(r, &p, s, m, nbytes) && mcheck(r, &p, m)) { /* - * This continuation matched. Print - * its message, with a blank before - * it if the previous item printed - * and this item isn't empty. + * This continuation matched. Print its message, with a + * blank before it if the previous item printed and this + * item isn't empty. */ /* space if previous printed */ if (need_separator @@ -1795,8 +1777,8 @@ need_separator = 1; /* - * If we see any continuations at a - * higher level, process them. + * If we see any continuations at a higher level, process + * them. */ cont_level++; } @@ -1807,19 +1789,18 @@ } #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%s: matched after %d rules", MODNAME, rule_counter); + "%s: matched after %d rules", MODNAME, rule_counter); #endif - return 1; /* all through */ + return 1; /* all through */ } #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%s: failed after %d rules", MODNAME, rule_counter); + "%s: failed after %d rules", MODNAME, rule_counter); #endif - return 0; /* no match at all */ + return 0; /* no match at all */ } -static void -mprint(request_rec * r, union VALUETYPE * p, struct magic * m) +static void mprint(request_rec *r, union VALUETYPE * p, struct magic * m) { char *pp, *rt; unsigned long v; @@ -1861,8 +1842,8 @@ return; default: aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: invalid m->type (%d) in mprint().", - MODNAME, m->type); + "%s: invalid m->type (%d) in mprint().", + MODNAME, m->type); return; } @@ -1873,8 +1854,7 @@ /* * Convert the byte order of the data we are looking at */ -static int -mconvert(request_rec * r, union VALUETYPE * p, struct magic * m) +static int mconvert(request_rec *r, union VALUETYPE * p, struct magic * m) { char *rt; @@ -1908,15 +1888,14 @@ return 1; default: aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: invalid type %d in mconvert().", MODNAME, m->type); + "%s: invalid type %d in mconvert().", MODNAME, m->type); return 0; } } -static int -mget(request_rec * r, union VALUETYPE * p, unsigned char *s, struct magic * m, - int nbytes) +static int mget(request_rec *r, union VALUETYPE * p, unsigned char *s, struct magic * m, + int nbytes) { long offset = m->offset; if (offset + sizeof(union VALUETYPE) > nbytes) @@ -1953,8 +1932,7 @@ return 1; } -static int -mcheck(request_rec * r, union VALUETYPE * p, struct magic * m) +static int mcheck(request_rec *r, union VALUETYPE * p, struct magic * m) { register unsigned long l = m->value.l; register unsigned long v; @@ -1989,9 +1967,9 @@ case STRING: l = 0; /* - * What we want here is: v = strncmp(m->value.s, p->s, - * m->vallen); but ignoring any nulls. bcmp doesn't give - * -/+/0 and isn't universally available anyway. + * What we want here is: v = strncmp(m->value.s, p->s, m->vallen); + * but ignoring any nulls. bcmp doesn't give -/+/0 and isn't + * universally available anyway. */ v = 0; { @@ -2006,8 +1984,8 @@ break; default: aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: invalid type %d in mcheck().", MODNAME, m->type); - return 0; /* NOTREACHED */ + "%s: invalid type %d in mcheck().", MODNAME, m->type); + return 0; /* NOTREACHED */ } v = signextend(r->server, m, v) & m->mask; @@ -2024,7 +2002,7 @@ matched = v != l; #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%lu != %lu = %d", v, l, matched); + "%lu != %lu = %d", v, l, matched); #endif break; @@ -2032,7 +2010,7 @@ matched = v == l; #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%lu == %lu = %d", v, l, matched); + "%lu == %lu = %d", v, l, matched); #endif break; @@ -2041,14 +2019,14 @@ matched = v > l; #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%lu > %lu = %d", v, l, matched); + "%lu > %lu = %d", v, l, matched); #endif } else { matched = (long) v > (long) l; #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%ld > %ld = %d", v, l, matched); + "%ld > %ld = %d", v, l, matched); #endif } break; @@ -2057,15 +2035,15 @@ if (m->flag & UNSIGNED) { matched = v < l; #if MIME_MAGIC_DEBUG - aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%lu < %lu = %d", v, l, matched); + aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, + "%lu < %lu = %d", v, l, matched); #endif } else { matched = (long) v < (long) l; #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%ld < %ld = %d", v, l, matched); + "%ld < %ld = %d", v, l, matched); #endif } break; @@ -2074,7 +2052,7 @@ matched = (v & l) == l; #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "((%lx & %lx) == %lx) = %d", v, l, l, matched); + "((%lx & %lx) == %lx) = %d", v, l, l, matched); #endif break; @@ -2082,16 +2060,16 @@ matched = (v & l) != l; #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "((%lx & %lx) != %lx) = %d", v, l, l, matched); + "((%lx & %lx) != %lx) = %d", v, l, l, matched); #endif break; default: matched = 0; aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: mcheck: can't happen: invalid relation %d.", - MODNAME, m->reln); - break; /* NOTREACHED */ + "%s: mcheck: can't happen: invalid relation %d.", + MODNAME, m->reln); + break; /* NOTREACHED */ } return matched; @@ -2100,29 +2078,28 @@ /* an optimization over plain strcmp() */ #define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) -static int -ascmagic(request_rec * r, unsigned char *buf, int nbytes) +static int ascmagic(request_rec *r, unsigned char *buf, int nbytes) { int i, has_escapes = 0; unsigned char *s; - char nbuf[HOWMANY + 1]; /* one extra for terminating '\0' */ + char nbuf[HOWMANY + 1]; /* one extra for terminating '\0' */ char *token; register struct names *p; /* these are easy, do them first */ /* - * for troff, look for . + letter + letter or .\"; this must be done - * to disambiguate tar archives' ./file and other trash from real - * troff input. + * for troff, look for . + letter + letter or .\"; this must be done to + * disambiguate tar archives' ./file and other trash from real troff + * input. */ if (*buf == '.') { unsigned char *tp = buf + 1; while (isascii(*tp) && isspace(*tp)) - ++tp; /* skip leading whitespace */ + ++tp; /* skip leading whitespace */ if ((isascii(*tp) && (isalnum(*tp) || *tp == '\\') && - isascii(*(tp + 1)) && (isalnum(*(tp + 1)) || *tp == '"'))) { + isascii(*(tp + 1)) && (isalnum(*(tp + 1)) || *tp == '"'))) { magic_rsl_puts(r, "application/x-troff"); return 1; } @@ -2140,7 +2117,7 @@ s[nbytes] = '\0'; has_escapes = (memchr(s, '\033', nbytes) != NULL); while ((token = strtok((char *) s, " \t\n\r\f")) != NULL) { - s = NULL; /* make strtok() keep on tokin' */ + s = NULL; /* make strtok() keep on tokin' */ for (p = names; p < names + NNAMES; p++) { if (STREQ(p->name, token)) { magic_rsl_puts(r, types[p->type]); @@ -2164,7 +2141,7 @@ for (i = 0; i < nbytes; i++) { if (!isascii(*(buf + i))) - return 0; /* not all ascii */ + return 0; /* not all ascii */ } /* all else fails, but it is ascii... */ @@ -2201,24 +2178,23 @@ }, { "\037\213", 2, { - "gzip", "-dcq", NULL + "gzip", "-dcq", NULL }, 1, "x-gzip" }, /* - * XXX pcat does not work, cause I don't know how to make it read - * stdin, so we use gzip + * XXX pcat does not work, cause I don't know how to make it read stdin, + * so we use gzip */ { "\037\036", 2, { - "gzip", "-dcq", NULL + "gzip", "-dcq", NULL }, 0, "x-gzip" }, }; static int ncompr = sizeof(compr) / sizeof(compr[0]); -static int -zmagic(request_rec * r, unsigned char *buf, int nbytes) +static int zmagic(request_rec *r, unsigned char *buf, int nbytes) { unsigned char *newbuf; int newsize; @@ -2244,19 +2220,18 @@ } -static int -uncompress(request_rec *r, int method, const unsigned char *old, - unsigned char **newch, int n) +static int uncompress(request_rec *r, int method, const unsigned char *old, + unsigned char **newch, int n) { int fdin[2], fdout[2]; if (pipe(fdin) == -1 || pipe(fdout) == -1) { aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: cannot create pipe.", MODNAME); + "%s: cannot create pipe.", MODNAME); return -1; } switch (fork()) { - case 0: /* child */ + case 0: /* child */ (void) close(STDIN_FILENO); (void) dup(fdin[0]); (void) close(fdin[0]); @@ -2271,30 +2246,30 @@ execvp(compr[method].argv[0], compr[method].argv); aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: could not execute `%s'.", MODNAME, compr[method].argv[0]); + "%s: could not execute `%s'.", MODNAME, compr[method].argv[0]); return -1; case -1: aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: could not fork.", MODNAME); + "%s: could not fork.", MODNAME); return -1; - default: /* parent */ + default: /* parent */ (void) close(fdin[0]); (void) close(fdout[1]); if (write(fdin[1], old, n) != n) { aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: write failed.", MODNAME); + "%s: write failed.", MODNAME); return -1; } (void) close(fdin[1]); if ((*newch = (unsigned char *) palloc(r->pool, n)) == NULL) { aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: out of memory in uncompress()", MODNAME); + "%s: out of memory in uncompress()", MODNAME); return -1; } if ((n = read(fdout[0], *newch, n)) <= 0) { aplog_error(APLOG_MARK, APLOG_ERR, r->server, - "%s: read failed", MODNAME); + "%s: read failed", MODNAME); return -1; } (void) close(fdout[0]); @@ -2305,13 +2280,13 @@ /* * is_tar() -- figure out whether file is a tar archive. - * + * * Stolen (by author of file utility) from the public domain tar program: Public * Domain version written 26 Aug 1985 John Gilmore (ihnp4!hoptoad!gnu). - * + * * @(#)list.c 1.18 9/23/86 Public Domain - gnu $Id: mod_mime_magic.c,v 1.7 * 1997/06/24 00:41:02 ikluft Exp ikluft $ - * + * * Comments changed and some code/comments reformatted for file command by Ian * Darwin. */ @@ -2323,8 +2298,7 @@ * old UNIX tar file, 2 for Unix Std (POSIX) tar file. */ -static int -is_tar(buf, nbytes) +static int is_tar(buf, nbytes) unsigned char *buf; int nbytes; { @@ -2342,8 +2316,7 @@ p = header->charptr; for (i = sizeof(union record); --i >= 0;) { /* - * We can't use unsigned char here because of old compilers, - * e.g. V7. + * We can't use unsigned char here because of old compilers, e.g. V7. */ sum += 0xFF & *p++; } @@ -2354,38 +2327,37 @@ sum += ' ' * sizeof header->header.chksum; if (sum != recsum) - return 0; /* Not a tar archive */ + return 0; /* Not a tar archive */ if (0 == strcmp(header->header.magic, TMAGIC)) - return 2; /* Unix Standard tar archive */ + return 2; /* Unix Standard tar archive */ - return 1; /* Old fashioned tar archive */ + return 1; /* Old fashioned tar archive */ } /* * Quick and dirty octal conversion. - * + * * Result is -1 if the field is invalid (all blank, or nonoctal). */ -static long -from_oct(int digs, char *where) +static long from_oct(int digs, char *where) { register long value; - while (isspace(*where)) { /* Skip spaces */ + while (isspace(*where)) { /* Skip spaces */ where++; if (--digs <= 0) - return -1; /* All blank field */ + return -1; /* All blank field */ } value = 0; - while (digs > 0 && isodigit(*where)) { /* Scan til nonoctal */ + while (digs > 0 && isodigit(*where)) { /* Scan til nonoctal */ value = (value << 3) | (*where++ - '0'); --digs; } if (digs > 0 && *where && !isspace(*where)) - return -1; /* Ended on non-space/nul */ + return -1; /* Ended on non-space/nul */ return value; } @@ -2400,8 +2372,7 @@ * through a sub-request. The base file name (without the @num suffix) * must exist because its type will be used as the result. */ -static int -revision_suffix(request_rec * r) +static int revision_suffix(request_rec *r) { int suffix_pos, result; char *sub_filename; @@ -2409,8 +2380,8 @@ #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%s: revision_suffix checking%s", MODNAME, r->filename); -#endif /* MIME_MAGIC_DEBUG */ + "%s: revision_suffix checking%s", MODNAME, r->filename); +#endif /* MIME_MAGIC_DEBUG */ /* check for recognized revision suffix */ suffix_pos = strlen(r->filename) - 1; @@ -2428,8 +2399,8 @@ sub_filename = pstrndup(r->pool, r->filename, suffix_pos); #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%s: subrequest lookup for %s", MODNAME, sub_filename); -#endif /* MIME_MAGIC_DEBUG */ + "%s: subrequest lookup for %s", MODNAME, sub_filename); +#endif /* MIME_MAGIC_DEBUG */ sub = sub_req_lookup_file(sub_filename, r); /* extract content type/encoding/language from sub-request */ @@ -2437,9 +2408,9 @@ r->content_type = pstrdup(r->pool, sub->content_type); #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, - "%s: subrequest %s got %s", - MODNAME, sub_filename, r->content_type); -#endif /* MIME_MAGIC_DEBUG */ + "%s: subrequest %s got %s", + MODNAME, sub_filename, r->content_type); +#endif /* MIME_MAGIC_DEBUG */ if (sub->content_encoding) r->content_encoding = pstrdup(r->pool, sub->content_encoding); @@ -2459,15 +2430,14 @@ * initialize the module */ -static void -magic_init(server_rec * s, pool * p) +static void magic_init(server_rec *s, pool *p) { int result; magic_server_config_rec *conf = (magic_server_config_rec *) - get_module_config(s->module_config, &mime_magic_module); + get_module_config(s->module_config, &mime_magic_module); #if MIME_MAGIC_DEBUG struct magic *m, *prevm; -#endif /* MIME_MAGIC_DEBUG */ +#endif /* MIME_MAGIC_DEBUG */ /* on the first time through we read the magic file */ if (conf->magicfile && !conf->magic) { @@ -2483,13 +2453,13 @@ isprint((((unsigned long) m) >> 8) & 255) && isprint(((unsigned long) m) & 255)) { aplog_error(APLOG_MARK, APLOG_DEBUG, s, - "%s: magic_init 1: POINTER CLOBBERED! " - "m=\"%c%c%c%c\" line=%d", MODNAME, - (((unsigned long) m) >> 24) & 255, - (((unsigned long) m) >> 16) & 255, - (((unsigned long) m) >> 8) & 255, - ((unsigned long) m) & 255, - prevm ? prevm->lineno : -1); + "%s: magic_init 1: POINTER CLOBBERED! " + "m=\"%c%c%c%c\" line=%d", MODNAME, + (((unsigned long) m) >> 24) & 255, + (((unsigned long) m) >> 16) & 255, + (((unsigned long) m) >> 8) & 255, + ((unsigned long) m) & 255, + prevm ? prevm->lineno : -1); break; } prevm = m; @@ -2506,8 +2476,7 @@ * Find the Content-Type from any resource this module has available */ -static int -magic_find_ct(request_rec * r) +static int magic_find_ct(request_rec *r) { int result; @@ -2544,23 +2513,23 @@ */ module mime_magic_module = { - STANDARD_MODULE_STUFF, - magic_init, /* initializer */ - NULL, /* dir config creator */ - NULL, /* dir merger --- default is to override */ - create_magic_server_config, /* server config */ - merge_magic_server_config, /* merge server config */ - mime_magic_cmds, /* command table */ - NULL, /* handlers */ - NULL, /* filename translation */ - NULL, /* check_user_id */ - NULL, /* check auth */ - NULL, /* check access */ - magic_find_ct, /* type_checker */ - NULL, /* fixups */ - NULL, /* logger */ - NULL, /* header parser */ - NULL, /* child_init */ - NULL, /* child_exit */ - NULL /* post read-request */ + STANDARD_MODULE_STUFF, + magic_init, /* initializer */ + NULL, /* dir config creator */ + NULL, /* dir merger --- default is to override */ + create_magic_server_config, /* server config */ + merge_magic_server_config, /* merge server config */ + mime_magic_cmds, /* command table */ + NULL, /* handlers */ + NULL, /* filename translation */ + NULL, /* check_user_id */ + NULL, /* check auth */ + NULL, /* check access */ + magic_find_ct, /* type_checker */ + NULL, /* fixups */ + NULL, /* logger */ + NULL, /* header parser */ + NULL, /* child_init */ + NULL, /* child_exit */ + NULL /* post read-request */ }; 1.2 +210 -205 apachen/src/modules/standard/mod_speling.c Index: mod_speling.c =================================================================== RCS file: /export/home/cvs/apachen/src/modules/standard/mod_speling.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- mod_speling.c 1997/09/11 18:50:33 1.1 +++ mod_speling.c 1997/09/16 04:30:22 1.2 @@ -7,7 +7,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -82,12 +82,12 @@ * here it's just one int! */ -static void *create_speling_config(pool * dummy, server_rec * s) +static void *create_speling_config(pool *dummy, server_rec *s) { return (void *) 0; } -static const char *set_speling(cmd_parms * cmd, void *dummy, int arg) +static const char *set_speling(cmd_parms *cmd, void *dummy, int arg) { void *server_conf = cmd->server->module_config; @@ -98,7 +98,7 @@ command_rec speling_cmds[] = { {"CheckSpelling", set_speling, NULL, RSRC_CONF, FLAG, - "whether or not to fix miscapitalized/misspelled requests"}, + "whether or not to fix miscapitalized/misspelled requests"}, {NULL} }; @@ -126,7 +126,7 @@ typedef struct { const char *name; sp_reason quality; -} misspelled_file; +} misspelled_file; /* * spdist() is taken from Kernighan & Pike, @@ -150,31 +150,31 @@ static sp_reason spdist(const char *s, const char *t) { for (; tolower(*s) == tolower(*t); t++, s++) - if (*t == '\0') - return SP_MISCAPITALIZED; /* exact match (sans case) */ + if (*t == '\0') + return SP_MISCAPITALIZED; /* exact match (sans case) */ if (*s) { - if (*t) { - if (s[1] && t[1] && tolower(*s) == tolower(t[1]) && - tolower(*t) == tolower(s[1]) && strcasecmp(s + 2, t + 2) == 0) - return SP_TRANSPOSITION; /* transposition */ - if (strcasecmp(s + 1, t + 1) == 0) - return SP_SIMPLETYPO; /* 1 char mismatch */ - } - if (strcasecmp(s + 1, t) == 0) - return SP_EXTRACHAR; /* extra character */ + if (*t) { + if (s[1] && t[1] && tolower(*s) == tolower(t[1]) && + tolower(*t) == tolower(s[1]) && strcasecmp(s + 2, t + 2) == 0) + return SP_TRANSPOSITION; /* transposition */ + if (strcasecmp(s + 1, t + 1) == 0) + return SP_SIMPLETYPO; /* 1 char mismatch */ + } + if (strcasecmp(s + 1, t) == 0) + return SP_EXTRACHAR;/* extra character */ } if (*t && strcasecmp(s, t + 1) == 0) - return SP_MISSINGCHAR; /* missing character */ - return SP_VERYDIFFERENT; /* distance too large to fix. */ + return SP_MISSINGCHAR; /* missing character */ + return SP_VERYDIFFERENT; /* distance too large to fix. */ } static int sort_by_quality(const void *left, const void *rite) { return (int) (((misspelled_file *) left)->quality) - - (int) (((misspelled_file *) rite)->quality); + - (int) (((misspelled_file *) rite)->quality); } -static int check_speling(request_rec * r) +static int check_speling(request_rec *r) { void *server_conf = r->server->module_config; char *good, *bad, *postgood, *url; @@ -184,21 +184,22 @@ array_header *candidates = NULL; if (!(int) get_module_config(server_conf, &speling_module)) - return DECLINED; + return DECLINED; /* We only want to worry about GETs */ if (r->method_number != M_GET) - return DECLINED; + return DECLINED; /* We've already got a file of some kind or another */ if (r->proxyreq || (r->finfo.st_mode != 0)) - return DECLINED; + return DECLINED; /* This is a sub request - don't mess with it */ if (r->main) - return DECLINED; + return DECLINED; - /* The request should end up looking like this: + /* + * The request should end up looking like this: * r->uri: /correct-url/mispelling/more * r->filename: /correct-file/mispelling r->path_info: /more * @@ -207,7 +208,7 @@ filoc = rind(r->filename, '/'); if (filoc == -1) - return DECLINED; + return DECLINED; /* good = /correct-file */ good = pstrndup(r->pool, r->filename, filoc); @@ -221,211 +222,215 @@ /* Check to see if the URL pieces add up */ if (strcmp(postgood, r->uri + (urlen - pglen))) - return DECLINED; + return DECLINED; /* url = /correct-url */ url = pstrndup(r->pool, r->uri, (urlen - pglen)); /* Now open the directory and do ourselves a check... */ dirp = opendir(good); - if (dirp == NULL) /* Oops, not a directory... */ - return DECLINED; + if (dirp == NULL) /* Oops, not a directory... */ + return DECLINED; candidates = make_array(r->pool, 2, sizeof(misspelled_file)); dotloc = ind(bad, '.'); if (dotloc == -1) - dotloc = strlen(bad); + dotloc = strlen(bad); while ((dir_entry = readdir(dirp))) { - sp_reason q; + sp_reason q; - /* If we end up with a "fixed" URL which is identical to the - * requested one, we must have found a broken symlink or some such. - * Do _not_ try to redirect this, it causes a loop! - */ - if (strcmp(bad, dir_entry->d_name) == 0) - { - closedir(dirp); - return OK; - } - /* - * miscapitalization errors are checked first - * (like, e.g., lower case file, upper case request) - */ - else if (strcasecmp(bad, dir_entry->d_name) == 0) { - misspelled_file *sp_new = (misspelled_file *) push_array(candidates); - sp_new->name = pstrdup(r->pool, dir_entry->d_name); - sp_new->quality = SP_MISCAPITALIZED; - } - /* - * simple typing errors are checked next - * (like, e.g., missing/extra/transposed char) - */ - else if ((q = spdist(bad, dir_entry->d_name)) != SP_VERYDIFFERENT) { - misspelled_file *sp_new = (misspelled_file *) push_array(candidates); - sp_new->name = pstrdup(r->pool, dir_entry->d_name); - sp_new->quality = q; - } - /* The spdist() should have found the majority of the misspelled requests. - * it is of questionable use to continue looking for files with the same - * base name, but potentially of totally wrong type (index.html <-> index.db) - * I would propose to not set the WANT_BASENAME_MATCH define. - * 08-Aug-1997 <[EMAIL PROTECTED]> - * - * However, Alexei replied giving some reasons to add it anyway: - * > Oh, by the way, I remembered why having the - * > extension-stripping-and-matching stuff is a good idea: - * > - * > If you're using MultiViews, and have a file named foobar.html, which you - * > refer to as "foobar", and someone tried to access "Foobar", mod_speling - * > won't find it, because it won't find anything matching that - * > spelling. With the extension-munging, it would locate "foobar.html". Not - * > perfect, but I ran into that problem when I first wrote the module. - */ - else { + /* + * If we end up with a "fixed" URL which is identical to the + * requested one, we must have found a broken symlink or some such. + * Do _not_ try to redirect this, it causes a loop! + */ + if (strcmp(bad, dir_entry->d_name) == 0) { + closedir(dirp); + return OK; + } + /* + * miscapitalization errors are checked first (like, e.g., lower case + * file, upper case request) + */ + else if (strcasecmp(bad, dir_entry->d_name) == 0) { + misspelled_file *sp_new = (misspelled_file *) push_array(candidates); + sp_new->name = pstrdup(r->pool, dir_entry->d_name); + sp_new->quality = SP_MISCAPITALIZED; + } + /* + * simple typing errors are checked next (like, e.g., + * missing/extra/transposed char) + */ + else if ((q = spdist(bad, dir_entry->d_name)) != SP_VERYDIFFERENT) { + misspelled_file *sp_new = (misspelled_file *) push_array(candidates); + sp_new->name = pstrdup(r->pool, dir_entry->d_name); + sp_new->quality = q; + } + /* The spdist() should have found the majority of the misspelled requests. + * it is of questionable use to continue looking for files with the same + * base name, but potentially of totally wrong type (index.html <-> index.db) + * I would propose to not set the WANT_BASENAME_MATCH define. + * 08-Aug-1997 <[EMAIL PROTECTED]> + * + * However, Alexei replied giving some reasons to add it anyway: + * > Oh, by the way, I remembered why having the + * > extension-stripping-and-matching stuff is a good idea: + * > + * > If you're using MultiViews, and have a file named foobar.html, which you + * > refer to as "foobar", and someone tried to access "Foobar", mod_speling + * > won't find it, because it won't find anything matching that + * > spelling. With the extension-munging, it would locate "foobar.html". Not + * > perfect, but I ran into that problem when I first wrote the module. + */ + else { #ifdef WANT_BASENAME_MATCH - /* Okay... we didn't find anything. Now we take out the hard-core - * power tools. There are several cases here. Someone might have - * entered a wrong extension (.htm instead of .html or vice versa) - * or the document could be negotiated. At any rate, now we just compare - * stuff before the first dot. If it matches, we figure we got us a - * match. This can result in wrong things if there are files of - * different content types but the same prefix (e.g. foo.gif and foo.html) - * This code will pick the first one it finds. Better than a Not Found, - * though. - */ - int entloc = ind(dir_entry->d_name, '.'); - if (entloc == -1) - entloc = strlen(dir_entry->d_name); - - if ((dotloc == entloc) - && !strncasecmp(bad, dir_entry->d_name, dotloc)) { - misspelled_file *sp_new = (misspelled_file *) push_array(candidates); - sp_new->name = pstrdup(r->pool, dir_entry->d_name); - sp_new->quality = SP_VERYDIFFERENT; - } + /* + * Okay... we didn't find anything. Now we take out the hard-core + * power tools. There are several cases here. Someone might have + * entered a wrong extension (.htm instead of .html or vice + * versa) or the document could be negotiated. At any rate, now + * we just compare stuff before the first dot. If it matches, we + * figure we got us a match. This can result in wrong things if + * there are files of different content types but the same prefix + * (e.g. foo.gif and foo.html) This code will pick the first one + * it finds. Better than a Not Found, though. + */ + int entloc = ind(dir_entry->d_name, '.'); + if (entloc == -1) + entloc = strlen(dir_entry->d_name); + + if ((dotloc == entloc) + && !strncasecmp(bad, dir_entry->d_name, dotloc)) { + misspelled_file *sp_new = (misspelled_file *) push_array(candidates); + sp_new->name = pstrdup(r->pool, dir_entry->d_name); + sp_new->quality = SP_VERYDIFFERENT; + } #endif - } + } } closedir(dirp); if (candidates->nelts != 0) { - /* Wow... we found us a mispelling. Construct a fixed url */ - char *nuri, *ref; - misspelled_file *variant = (misspelled_file *) candidates->elts; - int i; - - ref = table_get(r->headers_in, "Referer"); - - qsort((void *) candidates->elts, candidates->nelts, - sizeof(misspelled_file), sort_by_quality); - - /* - * Conditions for immediate redirection: - * a) the first candidate was not found by stripping the suffix + /* Wow... we found us a mispelling. Construct a fixed url */ + char *nuri, *ref; + misspelled_file *variant = (misspelled_file *) candidates->elts; + int i; + + ref = table_get(r->headers_in, "Referer"); + + qsort((void *) candidates->elts, candidates->nelts, + sizeof(misspelled_file), sort_by_quality); + + /* + * Conditions for immediate redirection: + * a) the first candidate was not found by stripping the suffix * AND b) there exists only one candidate OR the best match is not ambigous - * - * Otherwise, a "[300] Multiple Choices" list with the variants is returned. - */ - if (variant[0].quality != SP_VERYDIFFERENT && - (candidates->nelts == 1 || variant[0].quality != variant[1].quality)) { - - nuri = pstrcat(r->pool, url, variant[0].name, - r->path_info, NULL); - - table_set(r->headers_out, "Location", - construct_url(r->pool, nuri, r->server)); - - aplog_error(APLOG_MARK, APLOG_ERR, r->server, - ref ? "Fixed spelling: %s to %s from %s" - : "Fixed spelling: %s to %s", - r->uri, nuri, ref); - - return HTTP_MOVED_PERMANENTLY; - } - /* - * Otherwise, a "[300] Multiple Choices" list with the variants is returned. - */ - else { - char *t; - pool *pool; - table *notes; - - if (r->main == NULL) { - pool = r->pool; - notes = r->notes; - } - else { - pool = r->main->pool; - notes = r->main->notes; - } - - /* Generate the reponse text. */ - t = pstrcat(pool, "The document name you requested (<code>", - r->uri, "</code>) could not be found on this server.\n" - "However, we found documents with names similar to the one you requested.<p>" - "Available documents:\n<ul>\n", NULL); - - for (i = 0; i < candidates->nelts; ++i) { - - /* The format isn't very neat... */ - t = pstrcat(pool, t, "<li><a href=\"", variant[i].name, "\">", - variant[i].name, "</a> (", - sp_reason_str[(int) (variant[i].quality)], ")\n", NULL); - - /* when we have printed the "close matches" and there - * are more "distant matches" (matched by stripping the - * suffix), then we insert an additional separator text - * to suggest that the user LOOK CLOSELY whether these - * are really the files she wanted. - */ - if (i > 0 && i < candidates->nelts - 1 - && variant[i].quality != SP_VERYDIFFERENT - && variant[i + 1].quality == SP_VERYDIFFERENT) { - t = pstrcat(pool, t, "</ul>\nFurthermore, the following related documents were found:\n<ul>\n", NULL); - } - } - t = pstrcat(pool, t, "</ul>\n", NULL); - - /* If we know there was a referring page, add a note: */ - if (ref != NULL) - t = pstrcat(pool, t, "Please consider informing the owner of the <a href=\"", - ref, "\">referring page</a> about the broken link.\n", NULL); - - /* Pass our table to http_protocol.c (see mod_negotiation): */ - table_set(notes, "variant-list", t); - - aplog_error(APLOG_MARK, APLOG_WARNING, r->server, - ref ? "Spelling fix: %s: %d candidates from %s" - : "Spelling fix: %s: %d candidates", - r->uri, candidates->nelts, ref); + * + * Otherwise, a "[300] Multiple Choices" list with the variants is + * returned. + */ + if (variant[0].quality != SP_VERYDIFFERENT && + (candidates->nelts == 1 || variant[0].quality != variant[1].quality)) { + + nuri = pstrcat(r->pool, url, variant[0].name, + r->path_info, NULL); + + table_set(r->headers_out, "Location", + construct_url(r->pool, nuri, r->server)); + + aplog_error(APLOG_MARK, APLOG_ERR, r->server, + ref ? "Fixed spelling: %s to %s from %s" + : "Fixed spelling: %s to %s", + r->uri, nuri, ref); + + return HTTP_MOVED_PERMANENTLY; + } + /* + * Otherwise, a "[300] Multiple Choices" list with the variants is + * returned. + */ + else { + char *t; + pool *pool; + table *notes; + + if (r->main == NULL) { + pool = r->pool; + notes = r->notes; + } + else { + pool = r->main->pool; + notes = r->main->notes; + } + + /* Generate the reponse text. */ + t = pstrcat(pool, "The document name you requested (<code>", + r->uri, "</code>) could not be found on this server.\n" + "However, we found documents with names similar to the one you requested.<p>" + "Available documents:\n<ul>\n", NULL); + + for (i = 0; i < candidates->nelts; ++i) { + + /* The format isn't very neat... */ + t = pstrcat(pool, t, "<li><a href=\"", variant[i].name, "\">", + variant[i].name, "</a> (", + sp_reason_str[(int) (variant[i].quality)], ")\n", NULL); + + /* + * when we have printed the "close matches" and there are + * more "distant matches" (matched by stripping the suffix), + * then we insert an additional separator text to suggest + * that the user LOOK CLOSELY whether these are really the + * files she wanted. + */ + if (i > 0 && i < candidates->nelts - 1 + && variant[i].quality != SP_VERYDIFFERENT + && variant[i + 1].quality == SP_VERYDIFFERENT) { + t = pstrcat(pool, t, "</ul>\nFurthermore, the following related documents were found:\n<ul>\n", NULL); + } + } + t = pstrcat(pool, t, "</ul>\n", NULL); + + /* If we know there was a referring page, add a note: */ + if (ref != NULL) + t = pstrcat(pool, t, "Please consider informing the owner of the <a href=\"", + ref, "\">referring page</a> about the broken link.\n", NULL); + + /* Pass our table to http_protocol.c (see mod_negotiation): */ + table_set(notes, "variant-list", t); + + aplog_error(APLOG_MARK, APLOG_WARNING, r->server, + ref ? "Spelling fix: %s: %d candidates from %s" + : "Spelling fix: %s: %d candidates", + r->uri, candidates->nelts, ref); - return HTTP_MULTIPLE_CHOICES; - } + return HTTP_MULTIPLE_CHOICES; + } } return OK; } module MODULE_VAR_EXPORT speling_module = { - STANDARD_MODULE_STUFF, - NULL, /* initializer */ - NULL, /* create per-dir config */ - NULL, /* merge per-dir config */ - create_speling_config, /* server config */ - NULL, /* merge server config */ - speling_cmds, /* command table */ - NULL, /* handlers */ - NULL, /* filename translation */ - NULL, /* check_user_id */ - NULL, /* check auth */ - NULL, /* check access */ - NULL, /* type_checker */ - check_speling, /* fixups */ - NULL, /* logger */ - NULL, /* header parser */ - NULL, /* child_init */ - NULL, /* child_exit */ - NULL /* post read-request */ + STANDARD_MODULE_STUFF, + NULL, /* initializer */ + NULL, /* create per-dir config */ + NULL, /* merge per-dir config */ + create_speling_config, /* server config */ + NULL, /* merge server config */ + speling_cmds, /* command table */ + NULL, /* handlers */ + NULL, /* filename translation */ + NULL, /* check_user_id */ + NULL, /* check auth */ + NULL, /* check access */ + NULL, /* type_checker */ + check_speling, /* fixups */ + NULL, /* logger */ + NULL, /* header parser */ + NULL, /* child_init */ + NULL, /* child_exit */ + NULL /* post read-request */ }; 1.3 +107 -100 apachen/src/modules/standard/mod_unique_id.c Index: mod_unique_id.c =================================================================== RCS file: /export/home/cvs/apachen/src/modules/standard/mod_unique_id.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- mod_unique_id.c 1997/09/01 02:49:45 1.2 +++ mod_unique_id.c 1997/09/16 04:30:22 1.3 @@ -6,7 +6,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -72,7 +72,7 @@ unsigned int in_addr; unsigned int pid; unsigned short counter; -} unique_id_rec; +} unique_id_rec; /* Comments: * @@ -127,129 +127,136 @@ static APACHE_TLS unique_id_rec cur_unique_id; -static void unique_id_global_init (server_rec *s, pool *p) +static void unique_id_global_init(server_rec *s, pool *p) { #ifndef MAXHOSTNAMELEN #define MAXHOSTNAMELEN 256 #endif - char str[MAXHOSTNAMELEN+1]; + char str[MAXHOSTNAMELEN + 1]; struct hostent *hent; #ifndef NO_GETTIMEOFDAY struct timeval tv; #endif - /* First of all, verify some assumptions that have been made about - * the contents of unique_id_rec. We do it this way because it - * isn't affected by trailing padding. + /* + * First of all, verify some assumptions that have been made about the + * contents of unique_id_rec. We do it this way because it isn't + * affected by trailing padding. */ - if (XtOffsetOf (unique_id_rec, counter) + sizeof (cur_unique_id.counter) - != 14) { - aplog_error(APLOG_MARK, APLOG_ALERT, s, - "mod_unique_id: sorry the size assumptions are wrong " - "in mod_unique_id.c, please remove it from your server " - "or fix the code!"); - exit (1); + if (XtOffsetOf(unique_id_rec, counter) + sizeof(cur_unique_id.counter) + != 14) { + aplog_error(APLOG_MARK, APLOG_ALERT, s, + "mod_unique_id: sorry the size assumptions are wrong " + "in mod_unique_id.c, please remove it from your server " + "or fix the code!"); + exit(1); } - /* Now get the global in_addr. Note that it is not sufficient to use - * one of the addresses from the main_server, since those aren't as likely - * to be unique as the physical address of the machine + /* + * Now get the global in_addr. Note that it is not sufficient to use one + * of the addresses from the main_server, since those aren't as likely to + * be unique as the physical address of the machine */ - if (gethostname (str, sizeof (str) - 1) != 0) { - aplog_error(APLOG_MARK, APLOG_ALERT, s, - "gethostname: mod_unique_id requires the hostname of the server"); - exit (1); + if (gethostname(str, sizeof(str) - 1) != 0) { + aplog_error(APLOG_MARK, APLOG_ALERT, s, + "gethostname: mod_unique_id requires the hostname of the server"); + exit(1); } - if ((hent = gethostbyname (str)) == NULL) { - aplog_error(APLOG_MARK, APLOG_ALERT, s, - "mod_unique_id: unable to gethostbyname(\"%s\")", str); - exit (1); + if ((hent = gethostbyname(str)) == NULL) { + aplog_error(APLOG_MARK, APLOG_ALERT, s, + "mod_unique_id: unable to gethostbyname(\"%s\")", str); + exit(1); } - global_in_addr = ((struct in_addr *)hent->h_addr_list[0])->s_addr; + global_in_addr = ((struct in_addr *) hent->h_addr_list[0])->s_addr; aplog_error(APLOG_MARK, APLOG_INFO, s, - "mod_unique_id: using ip addr %s", - inet_ntoa (*(struct in_addr *)hent->h_addr_list[0])); + "mod_unique_id: using ip addr %s", + inet_ntoa(*(struct in_addr *) hent->h_addr_list[0])); - /* If the server is pummelled with restart requests we could possibly - * end up in a situation where we're starting again during the same - * second that has been used in previous identifiers. Avoid that - * situation. - * - * In truth, for this to actually happen not only would it have to - * restart in the same second, but it would have to somehow get the - * same pids as one of the other servers that was running in that second. - * Which would mean a 64k wraparound on pids ... not very likely at - * all. - * - * But protecting against it is relatively cheap. We just sleep into - * the next second. + /* + * If the server is pummelled with restart requests we could possibly end + * up in a situation where we're starting again during the same second + * that has been used in previous identifiers. Avoid that situation. + * + * In truth, for this to actually happen not only would it have to restart + * in the same second, but it would have to somehow get the same pids as + * one of the other servers that was running in that second. Which would + * mean a 64k wraparound on pids ... not very likely at all. + * + * But protecting against it is relatively cheap. We just sleep into the + * next second. */ #ifdef NO_GETTIMEOFDAY - sleep (1); + sleep(1); #else - if (gettimeofday (&tv, NULL) == -1) { - sleep (1); - } else if (tv.tv_usec) { - tv.tv_sec = 0; - tv.tv_usec = 1000000 - tv.tv_usec; - select (0, NULL, NULL, NULL, &tv); + if (gettimeofday(&tv, NULL) == -1) { + sleep(1); + } + else if (tv.tv_usec) { + tv.tv_sec = 0; + tv.tv_usec = 1000000 - tv.tv_usec; + select(0, NULL, NULL, NULL, &tv); } #endif } -static void unique_id_child_init (server_rec *s, pool *p) +static void unique_id_child_init(server_rec *s, pool *p) { pid_t pid; #ifndef NO_GETTIMEOFDAY struct timeval tv; #endif - /* Note that we use the pid because it's possible that on the same - * physical machine there are multiple servers (i.e. using Listen). - * But it's guaranteed that none of them will share the same pids - * between children. - * - * XXX: for multithread this needs to use a pid/tid combo and probably - * XXX: needs to be expanded to 32 bits + /* + * Note that we use the pid because it's possible that on the same + * physical machine there are multiple servers (i.e. using Listen). But + * it's guaranteed that none of them will share the same pids between + * children. + * + * XXX: for multithread this needs to use a pid/tid combo and probably XXX: + * needs to be expanded to 32 bits */ pid = getpid(); cur_unique_id.pid = pid; - /* Test our assumption that the pid is 16-bits. But note we can't just - * test sizeof (pid_t) because on some machines pid_t is 32-bits but - * pids are actually only 16-bits. It would have been really nice to - * test this during global_init ... but oh well. + /* + * Test our assumption that the pid is 16-bits. But note we can't just + * test sizeof (pid_t) because on some machines pid_t is 32-bits but pids + * are actually only 16-bits. It would have been really nice to test + * this during global_init ... but oh well. */ if (cur_unique_id.pid != pid) { - aplog_error(APLOG_MARK, APLOG_DEBUG, s, - "oh no! pids are greater than 16-bits! I'm broken!"); + aplog_error(APLOG_MARK, APLOG_DEBUG, s, + "oh no! pids are greater than 16-bits! I'm broken!"); } cur_unique_id.in_addr = global_in_addr; - /* If we use 0 as the initial counter we have a little less protection - * against restart problems, and a little less protection against a - * clock going backwards in time. + /* + * If we use 0 as the initial counter we have a little less protection + * against restart problems, and a little less protection against a clock + * going backwards in time. */ #ifndef NO_GETTIMEOFDAY - if (gettimeofday (&tv, NULL) == -1) { - cur_unique_id.counter = 0; - } else { - cur_unique_id.counter = tv.tv_usec; + if (gettimeofday(&tv, NULL) == -1) { + cur_unique_id.counter = 0; + } + else { + cur_unique_id.counter = tv.tv_usec; } #else cur_unique_id.counter = 0; #endif - /* We must always use network ordering for these bytes, so that identifiers - * are comparable between machines of different byte orderings. Note - * in_addr is already in network order. + /* + * We must always use network ordering for these bytes, so that + * identifiers are comparable between machines of different byte + * orderings. Note in_addr is already in network order. */ - cur_unique_id.pid = htons (cur_unique_id.pid); - cur_unique_id.counter = htons (cur_unique_id.counter); + cur_unique_id.pid = htons(cur_unique_id.pid); + cur_unique_id.counter = htons(cur_unique_id.counter); } /* NOTE: This is *NOT* the same encoding used by uuencode ... the last two @@ -265,17 +272,17 @@ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '@', '-', }; -static int gen_unique_id (request_rec *r) +static int gen_unique_id(request_rec *r) { /* when we uuencode it will take 19 bytes plus \0 */ char str[19 + 1]; const unsigned char *x; unsigned short counter; - cur_unique_id.stamp = htonl (r->request_time); + cur_unique_id.stamp = htonl(r->request_time); /* do the uuencoding */ - x = (const unsigned char *)&cur_unique_id; + x = (const unsigned char *) &cur_unique_id; str[0] = uuencoder[x[0] >> 2]; str[1] = uuencoder[((x[0] & 0x03) << 4) | ((x[1] & 0xf0) >> 4)]; str[2] = uuencoder[((x[1] & 0x0f) << 2) | ((x[2] & 0xc0) >> 6)]; @@ -298,37 +305,37 @@ x += 3; str[16] = uuencoder[x[0] >> 2]; str[17] = uuencoder[((x[0] & 0x03) << 4) | ((x[1] & 0xf0) >> 4)]; - str[18] = uuencoder[((x[1] & 0x0f) << 2) | (( 0 & 0xc0) >> 6)]; + str[18] = uuencoder[((x[1] & 0x0f) << 2) | ((0 & 0xc0) >> 6)]; str[19] = '\0'; - table_set (r->subprocess_env, "UNIQUE_ID", str); + table_set(r->subprocess_env, "UNIQUE_ID", str); /* and increment the identifier for the next call */ - counter = ntohs (cur_unique_id.counter) + 1; - cur_unique_id.counter = htons (counter); + counter = ntohs(cur_unique_id.counter) + 1; + cur_unique_id.counter = htons(counter); return DECLINED; } module MODULE_VAR_EXPORT unique_id_module = { - STANDARD_MODULE_STUFF, - unique_id_global_init, /* initializer */ - NULL, /* dir config creater */ - NULL, /* dir merger --- default is to override */ - NULL, /* server config */ - NULL, /* merge server configs */ - NULL, /* command table */ - NULL, /* handlers */ - NULL, /* filename translation */ - NULL, /* check_user_id */ - NULL, /* check auth */ - NULL, /* check access */ - NULL, /* type_checker */ - NULL, /* fixups */ - NULL, /* logger */ - NULL, /* header parser */ - unique_id_child_init, /* child_init */ - NULL, /* child_exit */ - gen_unique_id /* post_read_request */ + STANDARD_MODULE_STUFF, + unique_id_global_init, /* initializer */ + NULL, /* dir config creater */ + NULL, /* dir merger --- default is to override */ + NULL, /* server config */ + NULL, /* merge server configs */ + NULL, /* command table */ + NULL, /* handlers */ + NULL, /* filename translation */ + NULL, /* check_user_id */ + NULL, /* check auth */ + NULL, /* check access */ + NULL, /* type_checker */ + NULL, /* fixups */ + NULL, /* logger */ + NULL, /* header parser */ + unique_id_child_init, /* child_init */ + NULL, /* child_exit */ + gen_unique_id /* post_read_request */ }; 1.23 +125 -125 apachen/src/modules/standard/mod_userdir.c Index: mod_userdir.c =================================================================== RCS file: /export/home/cvs/apachen/src/modules/standard/mod_userdir.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- mod_userdir.c 1997/09/16 04:13:06 1.22 +++ mod_userdir.c 1997/09/16 04:30:23 1.23 @@ -6,7 +6,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -91,11 +91,11 @@ module userdir_module; typedef struct userdir_config { - int globally_disabled; - char *userdir; - table *enabled_users; - table *disabled_users; -} userdir_config; + int globally_disabled; + char *userdir; + table *enabled_users; + table *disabled_users; +} userdir_config; /* * Server config for this module: global disablement flag, a list of usernames @@ -103,69 +103,70 @@ * explicit) disablement, and the replacement string for all others. */ -static void *create_userdir_config (pool *p, server_rec *s) { +static void *create_userdir_config(pool *p, server_rec *s) +{ userdir_config - *newcfg = (userdir_config *) pcalloc (p, sizeof(userdir_config)); + * newcfg = (userdir_config *) pcalloc(p, sizeof(userdir_config)); newcfg->globally_disabled = 0; newcfg->userdir = DEFAULT_USER_DIR; - newcfg->enabled_users = make_table (p, 4); - newcfg->disabled_users = make_table (p, 4); - return (void *) newcfg; + newcfg->enabled_users = make_table(p, 4); + newcfg->disabled_users = make_table(p, 4); + return (void *) newcfg; } #define O_DEFAULT 0 #define O_ENABLE 1 #define O_DISABLE 2 -static const char *set_user_dir (cmd_parms *cmd, void *dummy, char *arg) +static const char *set_user_dir(cmd_parms *cmd, void *dummy, char *arg) { userdir_config - *s_cfg = (userdir_config *) get_module_config - ( - cmd->server->module_config, - &userdir_module - ); - char *username; + * s_cfg = (userdir_config *) get_module_config + ( + cmd->server->module_config, + &userdir_module + ); + char *username; const char - *usernames = arg; - char *kw = getword_conf (cmd->pool, &usernames); - table *usertable; - int optype = O_DEFAULT; + *usernames = arg; + char *kw = getword_conf(cmd->pool, &usernames); + table *usertable; + int optype = O_DEFAULT; /* * Let's do the comparisons once. */ - if ((! strcasecmp (kw, "disable")) || (! strcasecmp (kw, "disabled"))) { + if ((!strcasecmp(kw, "disable")) || (!strcasecmp(kw, "disabled"))) { optype = O_DISABLE; /* * If there are no usernames specified, this is a global disable - we * need do no more at this point than record the fact. */ - if (strlen (usernames) == 0) { + if (strlen(usernames) == 0) { s_cfg->globally_disabled = 1; return NULL; } usertable = s_cfg->disabled_users; } - else if ((! strcasecmp (kw, "enable")) || (! strcasecmp (kw, "enabled"))) { + else if ((!strcasecmp(kw, "enable")) || (!strcasecmp(kw, "enabled"))) { /* * The "disable" keyword can stand alone or take a list of names, but * the "enable" keyword requires the list. Whinge if it doesn't have * it. */ - if (strlen (usernames) == 0) { + if (strlen(usernames) == 0) { return "UserDir \"enable\" keyword requires a list of usernames"; } optype = O_ENABLE; usertable = s_cfg->enabled_users; } else { - /* - * If the first (only?) value isn't one of our keywords, just copy the - * string to the userdir string. - */ - s_cfg->userdir = pstrdup (cmd->pool, arg); + /* + * If the first (only?) value isn't one of our keywords, just copy + * the string to the userdir string. + */ + s_cfg->userdir = pstrdup(cmd->pool, arg); return NULL; } /* @@ -173,25 +174,25 @@ * the appropriate table. */ while (*usernames) { - username = getword_conf (cmd->pool, &usernames); - table_set (usertable, username, kw); + username = getword_conf(cmd->pool, &usernames); + table_set(usertable, username, kw); } return NULL; } static command_rec userdir_cmds[] = { -{ "UserDir", set_user_dir, NULL, RSRC_CONF, RAW_ARGS, - "the public subdirectory in users' home directories, or 'disabled', or 'disabled username username...', or 'enabled username username...'" }, -{ NULL } + {"UserDir", set_user_dir, NULL, RSRC_CONF, RAW_ARGS, + "the public subdirectory in users' home directories, or 'disabled', or 'disabled username username...', or 'enabled username username...'"}, + {NULL} }; -static int translate_userdir (request_rec *r) +static int translate_userdir(request_rec *r) { void *server_conf = r->server->module_config; const userdir_config *s_cfg = - (userdir_config *) get_module_config (server_conf, &userdir_module); + (userdir_config *) get_module_config(server_conf, &userdir_module); char *name = r->uri; - const char *userdirs = pstrdup (r->pool, s_cfg->userdir); + const char *userdirs = pstrdup(r->pool, s_cfg->userdir); const char *w, *dname, *redirect; char *x = NULL; struct stat statbuf; @@ -204,7 +205,7 @@ (s_cfg->userdir == NULL) || (name[0] != '/') || (name[1] != '~') - ) { + ) { return DECLINED; } @@ -212,13 +213,12 @@ w = getword(r->pool, &dname, '/'); /* - * The 'dname' funny business involves backing it up to capture - * the '/' delimiting the "/~user" part from the rest of the URL, - * in case there was one (the case where there wasn't being just - * "GET /~user HTTP/1.0", for which we don't want to tack on a - * '/' onto the filename). + * The 'dname' funny business involves backing it up to capture the '/' + * delimiting the "/~user" part from the rest of the URL, in case there + * was one (the case where there wasn't being just "GET /~user HTTP/1.0", + * for which we don't want to tack on a '/' onto the filename). */ - + if (dname[-1] == '/') { --dname; } @@ -226,23 +226,23 @@ /* * If there's no username, it's not for us. */ - if (! strcmp(w, "")) { + if (!strcmp(w, "")) { return DECLINED; } /* * Nor if there's an username but it's in the disabled list. */ - if (table_get (s_cfg->disabled_users, w) != NULL) { + if (table_get(s_cfg->disabled_users, w) != NULL) { return DECLINED; } /* - * If there's a global interdiction on UserDirs, check to see if this name - * is one of the Blessed. + * If there's a global interdiction on UserDirs, check to see if this + * name is one of the Blessed. */ if ( s_cfg->globally_disabled && - (table_get (s_cfg->enabled_users, w) == NULL) - ) { + (table_get(s_cfg->enabled_users, w) == NULL) + ) { return DECLINED; } @@ -251,96 +251,96 @@ */ while (*userdirs) { - const char *userdir = getword_conf (r->pool, &userdirs); - char *filename = NULL; + const char *userdir = getword_conf(r->pool, &userdirs); + char *filename = NULL; - if (strchr(userdir, '*')) - x = getword(r->pool, &userdir, '*'); + if (strchr(userdir, '*')) + x = getword(r->pool, &userdir, '*'); #if defined(__EMX__) || defined(WIN32) - /* Add support for OS/2 drive letters */ - if ((userdir[0] == '/') || (userdir[1] == ':') || (userdir[0] == '\0')) { + /* Add support for OS/2 drive letters */ + if ((userdir[0] == '/') || (userdir[1] == ':') || (userdir[0] == '\0')) { #else - if ((userdir[0] == '/') || (userdir[0] == '\0')) { + if ((userdir[0] == '/') || (userdir[0] == '\0')) { #endif - if (x) { + if (x) { #ifdef WIN32 - /* - * Crummy hack. Need to figure out whether we have - * been redirected to a URL or to a file on some - * drive. Since I know of no protocols that are a - * single letter, if the : is the second character, - * I will assume a file was specified - */ - if (strchr(x+2, ':')) { + /* + * Crummy hack. Need to figure out whether we have been + * redirected to a URL or to a file on some drive. Since I + * know of no protocols that are a single letter, if the : is + * the second character, I will assume a file was specified + */ + if (strchr(x + 2, ':')) { #else - if (strchr(x, ':')) { -#endif /* WIN32 */ - redirect = pstrcat(r->pool, x, w, userdir, dname, NULL); - table_set (r->headers_out, "Location", redirect); + if (strchr(x, ':')) { +#endif /* WIN32 */ + redirect = pstrcat(r->pool, x, w, userdir, dname, NULL); + table_set(r->headers_out, "Location", redirect); + return REDIRECT; + } + else + filename = pstrcat(r->pool, x, w, userdir, NULL); + } + else + filename = pstrcat(r->pool, userdir, "/", w, NULL); + } + else if (strchr(userdir, ':')) { + redirect = pstrcat(r->pool, userdir, "/", w, dname, NULL); + table_set(r->headers_out, "Location", redirect); return REDIRECT; - } - else - filename = pstrcat (r->pool, x, w, userdir, NULL); } - else - filename = pstrcat (r->pool, userdir, "/", w, NULL); - } - else if (strchr(userdir, ':')) { - redirect = pstrcat(r->pool, userdir, "/", w, dname, NULL); - table_set (r->headers_out, "Location", redirect); - return REDIRECT; - } - else { + else { #ifdef WIN32 - /* Need to figure out home dirs on NT */ - return DECLINED; -#else /* WIN32 */ - struct passwd *pw; - if ((pw = getpwnam(w))) { + /* Need to figure out home dirs on NT */ + return DECLINED; +#else /* WIN32 */ + struct passwd *pw; + if ((pw = getpwnam(w))) { #ifdef __EMX__ - /* Need to manually add user name for OS/2 */ - filename = pstrcat (r->pool, pw->pw_dir, w, "/", userdir, NULL); + /* Need to manually add user name for OS/2 */ + filename = pstrcat(r->pool, pw->pw_dir, w, "/", userdir, NULL); #else - filename = pstrcat (r->pool, pw->pw_dir, "/", userdir, NULL); + filename = pstrcat(r->pool, pw->pw_dir, "/", userdir, NULL); #endif + } +#endif /* WIN32 */ } -#endif /* WIN32 */ - } - /* Now see if it exists, or we're at the last entry. If we are at the - last entry, then use the filename generated (if there is one) anyway, - in the hope that some handler might handle it. This can be used, for - example, to run a CGI script for the user. - */ - if (filename && (!*userdirs || stat(filename, &statbuf) != -1)) { - r->filename = pstrcat(r->pool, filename, dname, NULL); - r->finfo = statbuf; - return OK; - } + /* + * Now see if it exists, or we're at the last entry. If we are at the + * last entry, then use the filename generated (if there is one) + * anyway, in the hope that some handler might handle it. This can be + * used, for example, to run a CGI script for the user. + */ + if (filename && (!*userdirs || stat(filename, &statbuf) != -1)) { + r->filename = pstrcat(r->pool, filename, dname, NULL); + r->finfo = statbuf; + return OK; + } } - return DECLINED; + return DECLINED; } - + module userdir_module = { - STANDARD_MODULE_STUFF, - NULL, /* initializer */ - NULL, /* dir config creater */ - NULL, /* dir merger --- default is to override */ - create_userdir_config, /* server config */ - NULL, /* merge server config */ - userdir_cmds, /* command table */ - NULL, /* handlers */ - translate_userdir, /*filename translation */ - NULL, /* check_user_id */ - NULL, /* check auth */ - NULL, /* check access */ - NULL, /* type_checker */ - NULL, /* fixups */ - NULL, /* logger */ - NULL, /* header parser */ - NULL, /* child_init */ - NULL, /* child_exit */ - NULL /* post read-request */ + STANDARD_MODULE_STUFF, + NULL, /* initializer */ + NULL, /* dir config creater */ + NULL, /* dir merger --- default is to override */ + create_userdir_config, /* server config */ + NULL, /* merge server config */ + userdir_cmds, /* command table */ + NULL, /* handlers */ + translate_userdir, /* filename translation */ + NULL, /* check_user_id */ + NULL, /* check auth */ + NULL, /* check access */ + NULL, /* type_checker */ + NULL, /* fixups */ + NULL, /* logger */ + NULL, /* header parser */ + NULL, /* child_init */ + NULL, /* child_exit */ + NULL /* post read-request */ };