|
|||||||||||
|
mod_cern_meta.c v 0.1.0
From: Andrew Wilson <andrew(at)aaaaaaaa.demon.co.uk>
Date: Sat Jun 29 1996 - 17:07:18 EDT Ay.
/* ====================================================================
/*
#include "httpd.h" #include "http_config.h" #include #define DIR_CMD_PERMS OR_INDEXES #define DEFAULT_METADIR ".web" #define DEFAULT_METASUFFIX ".meta" #define DEFAULT_METAFILES 0 module cern_meta_module; typedef struct { char *metadir; char *metasuffix; char *metafiles; } cern_meta_dir_config; void *create_cern_meta_dir_config (pool *p, char *dummy) {
cern_meta_dir_config *new =
new->metadir = NULL;
new->metasuffix = NULL;
new->metafiles = DEFAULT_METAFILES;
return new;
void *merge_cern_meta_dir_configs (pool *p, void *basev, void *addv) {
cern_meta_dir_config *base = (cern_meta_dir_config *)basev;
cern_meta_dir_config *add = (cern_meta_dir_config *)addv;
cern_meta_dir_config *new =
(cern_meta_dir_config *)palloc (p, sizeof(cern_meta_dir_config));
new->metadir = add->metadir ? add->metadir : base->metadir;
new->metasuffix = add->metasuffix ? add->metasuffix : base->metasuffix;
new->metafiles = add->metafiles;
return new;
char *set_metadir (cmd_parms *parms, cern_meta_dir_config *dconf, char *arg) {
dconf->metadir = arg;
char *set_metasuffix (cmd_parms *parms, cern_meta_dir_config *dconf, char *arg) {
dconf->metasuffix = arg;
char *set_metafiles (cmd_parms *parms, cern_meta_dir_config *dconf, char *arg) {
dconf->metafiles = arg;
command_rec cern_meta_cmds[] = {
"the name of the directory containing meta files"}, { "MetaSuffix", set_metasuffix, NULL, DIR_CMD_PERMS, TAKE1,
"the filename suffix for meta files"},
{ NULL }
int scan_meta_file(request_rec *r, FILE *f) {
char w[MAX_STRING_LEN];
while( fgets(w, MAX_STRING_LEN-1, f) != NULL ) { /* Delete terminal (CR?)LF */
p = strlen(w);
if (p > 0 && w[p-1] == '\n')
{
if (p > 1 && w[p-2] == '\015') w[p-2] = '\0';
else w[p-1] = '\0';
}
if(w[0] == '\0') {
return OK;
}
/* if we see a bogus header don't ignore it. Shout and scream */
if(!(l = strchr(w,':'))) {
log_reason ("malformed header in meta file", r->filename, r);
return SERVER_ERROR;
}
*l++ = '\0';
while (*l && isspace (*l)) ++l;
if(!strcasecmp(w,"Content-type")) {
/* Nuke trailing whitespace */
char *endp = l + strlen(l) - 1;
while (endp > l && isspace(*endp)) *endp-- = '\0';
r->content_type = pstrdup (r->pool, l);
}
else if(!strcasecmp(w,"Status")) {
sscanf(l, "%d", &r->status);
r->status_line = pstrdup(r->pool, l);
}
else {
table_set (r->headers_out, w, l);
}
} return OK; }
int add_cern_meta_data(request_rec *r)
char *metafilename;
char *last_slash;
char *real_file;
char *scrap_book;
struct stat meta_stat; FILE *f; cern_meta_dir_config *dconf ; int rv; dconf = get_module_config (r->per_dir_config, &cern_meta_module); if (!dconf->metafiles) {
return DECLINED;
/* if ./.web/$1.meta exists then output 'asis' */ if (r->finfo.st_mode == 0) {
return DECLINED;
/* does uri end in a trailing slash? */ if ( r->uri[strlen(r->uri) - 1] == '/' ) {
return DECLINED;
/* what directory is this file in? */
scrap_book = pstrdup( r->pool, r->filename );
/* skip leading slash, recovered in later processing */
scrap_book++;
/* skip over last slash */ real_file = last_slash; real_file++; *last_slash = '\0'; } else { /* no last slash, buh?! */ log_reason("internal error in mod_cern_meta", r->filename, r); /* should really barf, but hey, let's be friends... */ return DECLINED; }; metafilename = pstrcat(r->pool, "/", scrap_book, "/",
dconf->metadir ? dconf->metadir : DEFAULT_METADIR,
"/", real_file,
dconf->metasuffix ? dconf->metasuffix : DEFAULT_METASUFFIX,
NULL);
/*
* stat can legitimately fail for a bewildering number of reasons,
* only one of which implies the file isn't there. A hardened
* version of this module should test for all conditions, but later...
*/
if (stat(metafilename, &meta_stat) == -1) {
/* stat failed, possibly file missing */
return DECLINED;
};
/*
* this check is to be found in other Jan/96 Apache code, I've
* not been able to find any corroboration in the man pages but
* I've been wrong before so I'll put it in anyway. Never
* admit to being clueless...
*/
if ( meta_stat.st_mode == 0 ) {
/* stat failed, definately file missing */
return DECLINED;
}; f = pfopen (r->pool, metafilename, "r"); if (f == NULL) {
log_reason("meta file permissions deny server access", metafilename, r);
return FORBIDDEN;
};
/* read the headers in */
return rv;
module cern_meta_module = { STANDARD_MODULE_STUFF, NULL, /* initializer */ create_cern_meta_dir_config, /* dir config creater */ merge_cern_meta_dir_configs, /* dir merger --- default is to override */ NULL, /* server config */ NULL, /* merge server configs */ cern_meta_cmds, /* command table */ NULL, /* handlers */ NULL, /* filename translation */ NULL, /* check_user_id */ NULL, /* check auth */ NULL, /* check access */ NULL, /* type_checker */ add_cern_meta_data, /* fixups */ NULL, /* logger */ }; Received on Sat Jun 29 16:54:11 1996 This archive was generated by hypermail 2.1.8 : Thu Aug 24 2006 - 14:43:52 EDT |
||||||||||
|
|||||||||||