You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Ian Kluft <ik...@cisco.com> on 1997/07/12 01:48:52 UTC
more mod_mime_magic cleanup
Here's the patch I promised last night. This depends on Marc's patch from
last night being applied first.
* merge_magic_server_config() was rewritten.
* Some of the debugging code was modified to add instrumentation for
virtual server activity.
* I found some comments that got mangled by "indent" when I did the
style-guide tidying prior to submitting the module to Apache Group.
* Although this may be checking for a condition that currently never
happens, I added a check so that virtual servers will default to
inheriting their configuration rather than just re-read the default
config file again. Just to be safe...
* Plus some other minor cleanups of the old file(1), mainly comments.
--
Ian Kluft KO6YQ PP-ASEL Cisco Systems, Inc.
ikluft@cisco.com (work) ikluft@thunder.sbay.org (home) San Jose, CA
------------------------------------------------------------------------------
*** mod_mime_magic.c.orig Fri Jul 11 06:34:22 1997
--- mod_mime_magic.c Fri Jul 11 06:34:03 1997
***************
*** 515,533 ****
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));
! new->magicfile = add->magicfile ? add->magicfile : base->magicfile;
! if (add->magic && add->last) {
! new->magic = add->magic;
! new->last = add->last;
}
! else if (base->magic && base->last) {
! new->magic = base->magic;
! new->last = base->last;
}
! else {
! new->magic = new->last = NULL;
! }
return new;
}
--- 515,564 ----
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));
+ struct magic *m, *m_copy;
+ int source;
! /*
! * for tracing purposes, we'll try to sanely aggregate the magic file
! * names to indicate which files contributed to this list
! */
! new->magicfile = NULL;
! if ( base->magicfile ) {
! if ( add->magicfile ) {
! new->magicfile = pstrcat(p, base->magicfile, ",", add->magicfile,
! NULL );
! } else {
! new->magicfile = pstrdup(p, base->magicfile);
! }
! } else {
! if ( add->magicfile ) {
! new->magicfile = pstrdup(p, add->magicfile);
! }
! /* if both are NULL, leave new->magicfile alone */
}
!
! /*
! * Copy the entries from the base and add lists to the new list.
! * To avoid duplication of code, this uses a two-step loop where
! * source==0 means *add and source==1 means *base.
! */
! new->magic = new->last = NULL;
! for ( source = 0; source <= 1; source++ ) {
! for (m = ((source==0) ? add->magic : base->magic ); m; m = m->next) {
! m_copy = (struct magic *) palloc ( p, sizeof(struct magic));
! memcpy ( m_copy, m, sizeof(struct magic));
! m_copy->next = NULL;
! if ( new->magic && new->last ) {
! new->last->next = m_copy;
! new->last = m_copy;
! } else {
! new->magic = m_copy;
! new->last = m_copy;
! }
! }
}
!
! /* return the merged structure */
return new;
}
***************
*** 869,877 ****
}
/*
! * magic_process - process input file r Apache API request record
! * (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)
--- 900,910 ----
}
/*
! * magic_process - process input file
! * r Apache API request record
! * (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)
***************
*** 958,965 ****
isspace((unsigned char) *l)) ++l;}
/*
! * apprentice - load configuration from the magic file r
! * API request record
*/
static int
apprentice(server_rec * s, pool * p)
--- 991,998 ----
isspace((unsigned char) *l)) ++l;}
/*
! * apprentice - load configuration from the magic file
! * s - API server record
*/
static int
apprentice(server_rec * s, pool * p)
***************
*** 978,983 ****
--- 1011,1020 ----
get_module_config(s->module_config, &mime_magic_module);
if (!conf->magicfile) {
+ if ( s->is_virtual ) {
+ /* don't re-read default - inherit global if we're active */
+ return 0;
+ }
conf->magicfile = pstrdup(p, MAGIC);
}
fname = server_root_relative(p, conf->magicfile);
***************
*** 1029,1036 ****
#if MIME_MAGIC_DEBUG
log_printf(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",
--- 1066,1073 ----
#if MIME_MAGIC_DEBUG
log_printf(s,
! "%s: apprentice server=%s conf=%x file=%s m=%s m->next=%s last=%s",
! MODNAME, s->server_hostname, conf,
conf->magicfile ? conf->magicfile : "NULL",
conf->magic ? "set" : "NULL",
(conf->magic && conf->magic->next) ? "set" : "NULL",
***************
*** 1104,1110 ****
}
/*
! * parse one line from magic file, put into magic[index++] if valid
*/
static int
parse(server_rec * serv, pool * p, char *l, int lineno)
--- 1141,1147 ----
}
/*
! * parse one line from magic file, put into magic list if valid
*/
static int
parse(server_rec * serv, pool * p, char *l, int lineno)
***************
*** 1669,1676 ****
#if MIME_MAGIC_DEBUG
log_printf(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",
--- 1706,1713 ----
#if MIME_MAGIC_DEBUG
log_printf(r->server,
! "%s: match server=%s conf=%x file=%s m=%s m->next=%s last=%s",
! MODNAME, r->server->server_hostname, conf,
conf->magicfile ? conf->magicfile : "NULL",
conf->magic ? "set" : "NULL",
(conf->magic && conf->magic->next) ? "set" : "NULL",
***************
*** 1805,1817 ****
m = m->next;
}
#if MIME_MAGIC_DEBUG
! log_printf(r->server, "%s: matched after %d rules",
! MODNAME, rule_counter);
#endif
return 1; /* all through */
}
#if MIME_MAGIC_DEBUG
! log_printf(r->server, "%s: failed after %d rules", MODNAME, rule_counter);
#endif
return 0; /* no match at all */
}
--- 1842,1855 ----
m = m->next;
}
#if MIME_MAGIC_DEBUG
! log_printf(r->server, "%s: matched after %d rules on %s",
! MODNAME, rule_counter, r->server->server_hostname );
#endif
return 1; /* all through */
}
#if MIME_MAGIC_DEBUG
! log_printf(r->server, "%s: failed after %d rules on %s",
! MODNAME, rule_counter, r->server->server_hostname);
#endif
return 0; /* no match at all */
}
***************
*** 2401,2407 ****
request_rec *sub;
#if MIME_MAGIC_DEBUG
! log_printf(r->server, "%s: revision_suffix checking%s", MODNAME,
r->filename);
#endif /* MIME_MAGIC_DEBUG */
--- 2439,2445 ----
request_rec *sub;
#if MIME_MAGIC_DEBUG
! log_printf(r->server, "%s: revision_suffix checking %s", MODNAME,
r->filename);
#endif /* MIME_MAGIC_DEBUG */
***************
*** 2467,2473 ****
return;
#if MIME_MAGIC_DEBUG
prevm = 0;
! log_printf(s, "%s: magic_init 1 test", MODNAME);
for (m = conf->magic; m; m = m->next) {
if (isprint((((unsigned long) m) >> 24) & 255) &&
isprint((((unsigned long) m) >> 16) & 255) &&
--- 2505,2512 ----
return;
#if MIME_MAGIC_DEBUG
prevm = 0;
! log_printf(s, "%s: magic_init 1 test (%s)", MODNAME,
! s->server_hostname);
for (m = conf->magic; m; m = m->next) {
if (isprint((((unsigned long) m) >> 24) & 255) &&
isprint((((unsigned long) m) >> 16) & 255) &&
***************
*** 2488,2495 ****
#endif
}
- if (!conf->magic)
- return;
return;
}
--- 2527,2532 ----