httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgau...@hyperreal.org
Subject cvs commit: apachen/htdocs/manual/mod mod_mime_magic.html
Date Sun, 25 Jan 1998 03:52:20 GMT
dgaudet     98/01/24 19:52:20

  Modified:    src      CHANGES
               src/modules/standard mod_mime_magic.c
               htdocs/manual/mod mod_mime_magic.html
  Log:
  - no need to use stat() since r->finfo is already what we need
  - no need to play with atime/mtime crud, the web server doesn't preserve
      that info normally anyhow
  - deal with r->finfo.st_mode == 0 || !r->filename (i.e. not a disk file)
  - don't reference mime_module.type_checker, this should be controlled by
      the ordering within Configuration
  - work properly with multiple vhosts
  - doc update: even prior to this patch, the code was disabled if there
      was no MimeMagicFile directive.
  
  Revision  Changes    Path
  1.599     +6 -0      apachen/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/CHANGES,v
  retrieving revision 1.598
  retrieving revision 1.599
  diff -u -r1.598 -r1.599
  --- CHANGES	1998/01/25 01:40:53	1.598
  +++ CHANGES	1998/01/25 03:52:15	1.599
  @@ -1,5 +1,11 @@
   Changes with Apache 1.3b4
   
  +  *) More mod_mime_magic cleanup:  fewer syscalls; should handle "files"
  +     which don't exist on disk more gracefully; handles vhosts properly.
  +     Update documentation to reflect the code -- if there's no
  +     MimeMagicFile directive then the module is not enabled.
  +     [Dean Gaudet]
  +
     *) PORT: Some older *nix dialects cannot automatically start scripts
        which begin with a #! interpreter line (the shell starts the scripts
        appropriately on these platforms). Apache now supports starting of
  
  
  
  1.24      +56 -95    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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- mod_mime_magic.c	1998/01/07 16:46:53	1.23
  +++ mod_mime_magic.c	1998/01/25 03:52:18	1.24
  @@ -136,9 +136,6 @@
   #define MODNAME        "mod_mime_magic"
   #define MIME_MAGIC_DEBUG        0
   
  -#ifndef MAGIC
  -#define MAGIC "conf/magic"
  -#endif
   #define MIME_BINARY_UNKNOWN    "application/octet-stream"
   #define MIME_TEXT_UNKNOWN    "text/plain"
   
  @@ -258,7 +255,7 @@
   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);
   
   /*
    * includes for ASCII substring recognition formerly "names.h" in file
  @@ -296,7 +293,8 @@
       "message/rfc822",		/* "mail text", */
       "message/news",		/* "news text", */
       "application/binary",	/* "can't happen error on names.h/types", */
  -    0};
  +    0
  +};
   
   static struct names {
       char *name;
  @@ -495,7 +493,6 @@
    */
   
   module mime_magic_module;
  -extern module mime_module;
   
   static void *create_magic_server_config(pool *p, server_rec *d)
   {
  @@ -511,17 +508,8 @@
   			    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;
  -    }
  +    new->magic = NULL;
  +    new->last = NULL;
       return new;
   }
   
  @@ -545,7 +533,7 @@
   static command_rec mime_magic_cmds[] =
   {
       {"MimeMagicFile", set_magicfile, NULL, RSRC_CONF, TAKE1,
  -     "Path to MIME Magic file (in file(1) format, default " MAGIC ")"},
  +     "Path to MIME Magic file (in file(1) format)"},
       {NULL}
   };
   
  @@ -847,15 +835,13 @@
   {
       int fd = 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 result;
   
       /*
        * first try judging the file based on its filesystem status
        */
  -    switch ((result = fsmagic(r, r->filename, &sb))) {
  +    switch ((result = fsmagic(r, r->filename))) {
       case DONE:
   	magic_rsl_putchar(r, '\n');
   	return result;
  @@ -868,10 +854,6 @@
   
       if ((fd = popenf(r->pool, r->filename, O_RDONLY, 0)) < 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, ");
  -	 */
   	aplog_error(APLOG_MARK, APLOG_ERR, r->server,
   		    MODNAME ": can't read `%s'", r->filename);
   	/* let some other handler decide what the problem is */
  @@ -894,12 +876,6 @@
   	tryit(r, buf, nbytes);
       }
   
  -    /*
  -     * Try to restore access, modification times if read it.
  -     */
  -    utbuf.actime = sb.st_atime;
  -    utbuf.modtime = sb.st_mtime;
  -    (void) utime(r->filename, &utbuf);	/* don't care if loses */
       (void) pclosef(r->pool, fd);
       (void) magic_rsl_putchar(r, '\n');
   
  @@ -955,9 +931,6 @@
       magic_server_config_rec *conf = (magic_server_config_rec *)
   		    get_module_config(s->module_config, &mime_magic_module);
   
  -    if (!conf->magicfile) {
  -	conf->magicfile = pstrdup(p, MAGIC);
  -    }
       fname = server_root_relative(p, conf->magicfile);
       f = pfopen(p, fname, "r");
       if (f == NULL) {
  @@ -1460,28 +1433,9 @@
    * return OK to indicate it's a regular file still needing handling
    * other returns indicate a failure of some sort
    */
  -static int fsmagic(request_rec *r, const char *fn, struct stat *sb)
  +static int fsmagic(request_rec *r, const char *fn)
   {
  -    int ret = 0;
  -
  -    /* we don't care to identify symlinks, only their contents are
  -     * important */
  -    ret = stat(fn, sb);		/* don't merge into if; see "ret =" above */
  -
  -    if (ret) {
  -	/* If the file doesn't exist or something let some other module
  -	 * further along handle it.
  -	 */
  -	return DECLINED;
  -    }
  -
  -    /*
  -     * 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) {
  +    switch (r->finfo.st_mode & S_IFMT) {
       case S_IFDIR:
   	magic_rsl_puts(r, DIR_MAGIC_TYPE);
   	return DONE;
  @@ -1530,14 +1484,14 @@
   	break;
       default:
   	aplog_error(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, r->server,
  -		    MODNAME ": invalid mode 0%o.", (unsigned int)sb->st_mode);
  +		    MODNAME ": invalid mode 0%o.", (unsigned int)r->finfo.st_mode);
   	return HTTP_INTERNAL_SERVER_ERROR;
       }
   
       /*
        * regular file, check next possibility
        */
  -    if (sb->st_size == 0) {
  +    if (r->finfo.st_size == 0) {
   	magic_rsl_puts(r, MIME_TEXT_UNKNOWN);
   	return DONE;
       }
  @@ -2394,47 +2348,51 @@
    * initialize the module
    */
   
  -static void magic_init(server_rec *s, pool *p)
  +static void magic_init(server_rec *main_server, pool *p)
   {
       int result;
  -    magic_server_config_rec *conf = (magic_server_config_rec *)
  -			get_module_config(s->module_config, &mime_magic_module);
  +    magic_server_config_rec *conf;
  +    magic_server_config_rec *main_conf;
  +    server_rec *s;
   #if MIME_MAGIC_DEBUG
       struct magic *m, *prevm;
   #endif /* MIME_MAGIC_DEBUG */
   
  -    /* on the first time through we read the magic file */
  -    if (conf->magicfile && !conf->magic) {
  -	result = apprentice(s, p);
  -	if (result == -1)
  -	    return;
  -#if MIME_MAGIC_DEBUG
  -	prevm = 0;
  -	aplog_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, s,
  -		    MODNAME ": magic_init 1 test");
  -	for (m = conf->magic; m; m = m->next) {
  -	    if (isprint((((unsigned long) m) >> 24) & 255) &&
  -		isprint((((unsigned long) m) >> 16) & 255) &&
  -		isprint((((unsigned long) m) >> 8) & 255) &&
  -		isprint(((unsigned long) m) & 255)) {
  -		aplog_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, s,
  -			    MODNAME ": magic_init 1: POINTER CLOBBERED! "
  -			    "m=\"%c%c%c%c\" line=%d",
  -			    (((unsigned long) m) >> 24) & 255,
  -			    (((unsigned long) m) >> 16) & 255,
  -			    (((unsigned long) m) >> 8) & 255,
  -			    ((unsigned long) m) & 255,
  -			    prevm ? prevm->lineno : -1);
  -		break;
  +    main_conf = get_module_config(main_server->module_config, &mime_magic_module);
  +    for (s = main_server; s; s = s->next) {
  +	conf = get_module_config(s->module_config, &mime_magic_module);
  +	if (conf->magicfile == NULL && s != main_server) {
  +	    /* inherits from the parent */
  +	    *conf = *main_conf;
  +	}
  +	else if (conf->magicfile) {
  +	    result = apprentice(s, p);
  +	    if (result == -1)
  +		return;
  +#if MIME_MAGIC_DEBUG
  +	    prevm = 0;
  +	    aplog_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, s,
  +			MODNAME ": magic_init 1 test");
  +	    for (m = conf->magic; m; m = m->next) {
  +		if (isprint((((unsigned long) m) >> 24) & 255) &&
  +		    isprint((((unsigned long) m) >> 16) & 255) &&
  +		    isprint((((unsigned long) m) >> 8) & 255) &&
  +		    isprint(((unsigned long) m) & 255)) {
  +		    aplog_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, s,
  +				MODNAME ": magic_init 1: POINTER CLOBBERED! "
  +				"m=\"%c%c%c%c\" line=%d",
  +				(((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;
   	    }
  -	    prevm = m;
  -	}
   #endif
  +	}
       }
  -
  -    if (!conf->magic)
  -	return;
  -    return;
   }
   
   /*
  @@ -2444,18 +2402,21 @@
   static int magic_find_ct(request_rec *r)
   {
       int result;
  +    magic_server_config_rec *conf;
  +
  +    /* the file has to exist */
  +    if (r->finfo.st_mode == 0 || !r->filename) {
  +	return DECLINED;
  +    }
   
       /* was someone else already here? */
       if (r->content_type) {
   	return DECLINED;
       }
   
  -    /* make sure mime_module was called first - it's cheaper! */
  -    if (mime_module.type_checker) {
  -	result = (mime_module.type_checker) (r);
  -	if (result == OK) {
  -	    return OK;
  -	}
  +    conf = get_module_config(r->server->module_config, &mime_magic_module);
  +    if (!conf || !conf->magic) {
  +	return DECLINED;
       }
   
       /* initialize per-request info */
  
  
  
  1.5       +9 -9      apachen/htdocs/manual/mod/mod_mime_magic.html
  
  Index: mod_mime_magic.html
  ===================================================================
  RCS file: /export/home/cvs/apachen/htdocs/manual/mod/mod_mime_magic.html,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- mod_mime_magic.html	1997/09/11 13:27:51	1.4
  +++ mod_mime_magic.html	1998/01/25 03:52:19	1.5
  @@ -42,11 +42,8 @@
     In the case of this module,
     it tries to figure out the MIME type of the file.
     <p>
  -  This module is only active if the magic file exists and
  -  was successfully opened at server-configuration time.
  -  The magic file can be named by the
  -  <A HREF="#mimemagicfile"><code>MimeMagicFile</code></a>
  -  directive or defaults to conf/magic.
  +  This module active only if the magic file is specified by the 
  +  <A HREF="#mimemagicfile"><code>MimeMagicFile</code></a> directive.
     <p>
     The contents of the file are plain ASCII text in 4-5 columns.
     Blank lines are allowed but ignored.
  @@ -175,7 +172,7 @@
     <P>
     <STRONG>Syntax:</STRONG> MimeMagicFile <em>magic-file-name</em>
     <BR>
  -  <STRONG>Default:</STRONG> conf/magic
  +  <STRONG>Default:</STRONG> none
     <BR>
     <STRONG>Context:</STRONG> server config, virtual host
     <BR>
  @@ -184,9 +181,12 @@
     <STRONG>Module:</STRONG> mod_mime_magic
     <p>
   
  -  The MimeMagicFile directive can be used to change the location of the
  -  magic file from its default location at <code>conf/magic</code>.
  -  Non-rooted paths are relative to the ServerRoot.
  +  The <code>MimeMagicFile</code> directive can be used to enable this module,
  +  the default file is distributed at <code>conf/magic</code>.
  +  Non-rooted paths are relative to the ServerRoot.  Virtual hosts
  +  will use the same file as the main server unless a more specific setting
  +  is used, in which case the more specific setting overrides the main server's
  +  file.
     <p>
     <HR>
   
  
  
  

Mime
View raw message