Apache HTTPD
Classes | Macros | Typedefs | Enumerations | Functions | Variables
mod_mime_magic.c File Reference
#include "apr.h"
#include "apr_strings.h"
#include "apr_lib.h"
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_request.h"
#include "http_core.h"
#include "http_log.h"
#include "http_protocol.h"
#include "util_script.h"

Go to the source code of this file.

Classes

struct  magic
 
union  magic::VALUETYPE
 
union  record
 
struct  record::header
 
struct  names
 
struct  magic_rsl_s
 
struct  magic_server_config_rec
 
struct  magic_req_rec
 
struct  uncompress_parms
 

Macros

#define APR_WANT_STRFUNC
 
#define MODNAME   "mod_mime_magic"
 
#define MIME_MAGIC_DEBUG   0
 
#define MIME_BINARY_UNKNOWN   "application/octet-stream"
 
#define MIME_TEXT_UNKNOWN   "text/plain"
 
#define MAXMIMESTRING   256
 
#define HOWMANY   4096
 
#define SMALL_HOWMANY   1024
 
#define MAXDESC   50 /* max leng of text description */
 
#define MAXstring   64 /* max leng of "string" types */
 
#define INDIR   1 /* if '>(...)' appears, */
 
#define UNSIGNED   2 /* comparison is unsigned */
 
#define BYTE   1
 
#define SHORT   2
 
#define LONG   4
 
#define STRING   5
 
#define DATE   6
 
#define BESHORT   7
 
#define BELONG   8
 
#define BEDATE   9
 
#define LESHORT   10
 
#define LELONG   11
 
#define LEDATE   12
 
#define RECORDSIZE   512
 
#define NAMSIZ   100
 
#define TUNMLEN   32
 
#define TGNMLEN   32
 
#define TMAGIC   "ustar " /* 7 chars and a null */
 
#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 NNAMES   ((sizeof(names)/sizeof(struct names)) - 1)
 
#define EATAB   {while (apr_isspace(*l)) ++l;}
 
#define NBYTE   4
 
#define NSHORT   5
 
#define NLONG   4
 
#define NSTRING   6
 
#define NDATE   4
 
#define NBESHORT   7
 
#define NBELONG   6
 
#define NBEDATE   6
 
#define NLESHORT   7
 
#define NLELONG   6
 
#define NLEDATE   6
 
#define STREQ(a, b)   (*(a) == *(b) && strcmp((a), (b)) == 0)
 
#define ncompr   (sizeof(compr) / sizeof(compr[0]))
 
#define isodigit(c)   (((unsigned char)(c) >= '0') && ((unsigned char)(c) <= '7'))
 

Typedefs

typedef struct magic_rsl_s magic_rsl
 

Enumerations

enum  rsl_states {
  rsl_leading_space , rsl_type , rsl_subtype , rsl_separator ,
  rsl_encoding
}
 

Functions

static int ascmagic (request_rec *, unsigned char *, apr_size_t)
 
static int is_tar (unsigned char *, apr_size_t)
 
static int softmagic (request_rec *, unsigned char *, apr_size_t)
 
static int tryit (request_rec *, unsigned char *, apr_size_t, int)
 
static int zmagic (request_rec *, unsigned char *, apr_size_t)
 
static int getvalue (server_rec *, struct magic *, char **)
 
static int hextoint (int)
 
static chargetstr (server_rec *, char *, char *, int, int *)
 
static int parse (server_rec *, apr_pool_t *p, char *, int)
 
static int match (request_rec *, unsigned char *, apr_size_t)
 
static int mget (request_rec *, union VALUETYPE *, unsigned char *, struct magic *, apr_size_t)
 
static int mcheck (request_rec *, union VALUETYPE *, struct magic *)
 
static void mprint (request_rec *, union VALUETYPE *, struct magic *)
 
static int uncompress (request_rec *, int, unsigned char **, apr_size_t)
 
static long from_oct (int, char *)
 
static int fsmagic (request_rec *r, const char *fn)
 
static void * create_magic_server_config (apr_pool_t *p, server_rec *d)
 
static void * merge_magic_server_config (apr_pool_t *p, void *basev, void *addv)
 
static const charset_magicfile (cmd_parms *cmd, void *dummy, const char *arg)
 
static magic_req_recmagic_set_config (request_rec *r)
 
static int magic_rsl_add (request_rec *r, const char *str)
 
static int magic_rsl_puts (request_rec *r, const char *str)
 
static int magic_rsl_printf (request_rec *r, char *str,...)
 
static int magic_rsl_putchar (request_rec *r, char c)
 
static charrsl_strdup (request_rec *r, int start_frag, int start_pos, int len)
 
static int magic_rsl_to_request (request_rec *r)
 
static int magic_process (request_rec *r)
 
static int apprentice (server_rec *s, apr_pool_t *p)
 
static unsigned long signextend (server_rec *s, struct magic *m, unsigned long v)
 
static chargetstr (server_rec *serv, register char *s, register char *p, int plen, int *slen)
 
static int mconvert (request_rec *r, union VALUETYPE *p, struct magic *m)
 
static int create_uncompress_child (struct uncompress_parms *parm, apr_pool_t *cntxt, apr_file_t **pipe_in)
 
static int revision_suffix (request_rec *r)
 
static int magic_init (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_server)
 
static int magic_find_ct (request_rec *r)
 
static void register_hooks (apr_pool_t *p)
 

Variables

static const char *const types []
 
static const struct names names []
 
static const command_rec mime_magic_cmds []
 
struct { 
 
   const char *   magic 
 
   apr_size_t   maglen 
 
   const char *   argv [3] 
 
   int   silent 
 
   const char *   encoding 
 
compr [] 
 
static int *const aplog_module_index = &( mime_magic_module.module_index)
 

Macro Definition Documentation

◆ APR_WANT_STRFUNC

#define APR_WANT_STRFUNC

Definition at line 88 of file mod_mime_magic.c.

◆ BEDATE

#define BEDATE   9

Definition at line 151 of file mod_mime_magic.c.

◆ BELONG

#define BELONG   8

Definition at line 150 of file mod_mime_magic.c.

◆ BESHORT

#define BESHORT   7

Definition at line 149 of file mod_mime_magic.c.

◆ BYTE

#define BYTE   1

Definition at line 144 of file mod_mime_magic.c.

◆ DATE

#define DATE   6

Definition at line 148 of file mod_mime_magic.c.

◆ EATAB

#define EATAB   {while (apr_isspace(*l)) ++l;}

Definition at line 907 of file mod_mime_magic.c.

◆ HOWMANY

#define HOWMANY   4096

Definition at line 122 of file mod_mime_magic.c.

◆ INDIR

#define INDIR   1 /* if '>(...)' appears, */

Definition at line 133 of file mod_mime_magic.c.

◆ isodigit

#define isodigit (   c)    (((unsigned char)(c) >= '0') && ((unsigned char)(c) <= '7'))

Definition at line 2217 of file mod_mime_magic.c.

◆ L_C

#define L_C   1 /* first and foremost on UNIX */

Definition at line 250 of file mod_mime_magic.c.

◆ L_ENG

#define L_ENG   6 /* English */

Definition at line 255 of file mod_mime_magic.c.

◆ L_FORT

#define L_FORT   2 /* the oldest one */

Definition at line 251 of file mod_mime_magic.c.

◆ L_HTML

#define L_HTML   0 /* HTML */

Definition at line 249 of file mod_mime_magic.c.

◆ L_MACH

#define L_MACH   5 /* some kinda assembler */

Definition at line 254 of file mod_mime_magic.c.

◆ L_MAIL

#define L_MAIL   8 /* Electronic mail */

Definition at line 257 of file mod_mime_magic.c.

◆ L_MAKE

#define L_MAKE   3 /* Makefiles */

Definition at line 252 of file mod_mime_magic.c.

◆ L_NEWS

#define L_NEWS   9 /* Usenet Netnews */

Definition at line 258 of file mod_mime_magic.c.

◆ L_PAS

#define L_PAS   7 /* Pascal */

Definition at line 256 of file mod_mime_magic.c.

◆ L_PLI

#define L_PLI   4 /* PL/1 */

Definition at line 253 of file mod_mime_magic.c.

◆ LEDATE

#define LEDATE   12

Definition at line 154 of file mod_mime_magic.c.

◆ LELONG

#define LELONG   11

Definition at line 153 of file mod_mime_magic.c.

◆ LESHORT

#define LESHORT   10

Definition at line 152 of file mod_mime_magic.c.

◆ LONG

#define LONG   4

Definition at line 146 of file mod_mime_magic.c.

◆ MAXDESC

#define MAXDESC   50 /* max leng of text description */

Definition at line 125 of file mod_mime_magic.c.

◆ MAXMIMESTRING

#define MAXMIMESTRING   256

Definition at line 119 of file mod_mime_magic.c.

◆ MAXstring

#define MAXstring   64 /* max leng of "string" types */

Definition at line 126 of file mod_mime_magic.c.

◆ MIME_BINARY_UNKNOWN

#define MIME_BINARY_UNKNOWN   "application/octet-stream"

Definition at line 116 of file mod_mime_magic.c.

◆ MIME_MAGIC_DEBUG

#define MIME_MAGIC_DEBUG   0

Definition at line 114 of file mod_mime_magic.c.

◆ MIME_TEXT_UNKNOWN

#define MIME_TEXT_UNKNOWN   "text/plain"

Definition at line 117 of file mod_mime_magic.c.

◆ MODNAME

#define MODNAME   "mod_mime_magic"

Definition at line 113 of file mod_mime_magic.c.

◆ NAMSIZ

#define NAMSIZ   100

Definition at line 185 of file mod_mime_magic.c.

◆ NBEDATE

#define NBEDATE   6

◆ NBELONG

#define NBELONG   6

◆ NBESHORT

#define NBESHORT   7

◆ NBYTE

#define NBYTE   4

◆ ncompr

#define ncompr   (sizeof(compr) / sizeof(compr[0]))

Definition at line 2079 of file mod_mime_magic.c.

◆ NDATE

#define NDATE   4

◆ NLEDATE

#define NLEDATE   6

◆ NLELONG

#define NLELONG   6

◆ NLESHORT

#define NLESHORT   7

◆ NLONG

#define NLONG   4

◆ NNAMES

#define NNAMES   ((sizeof(names)/sizeof(struct names)) - 1)

Definition at line 435 of file mod_mime_magic.c.

◆ NSHORT

#define NSHORT   5

◆ NSTRING

#define NSTRING   6

◆ RECORDSIZE

#define RECORDSIZE   512

Definition at line 184 of file mod_mime_magic.c.

◆ SHORT

#define SHORT   2

Definition at line 145 of file mod_mime_magic.c.

◆ SMALL_HOWMANY

#define SMALL_HOWMANY   1024

Definition at line 124 of file mod_mime_magic.c.

◆ STREQ

#define STREQ (   a,
  b 
)    (*(a) == *(b) && strcmp((a), (b)) == 0)

Definition at line 1969 of file mod_mime_magic.c.

◆ STRING

#define STRING   5

Definition at line 147 of file mod_mime_magic.c.

◆ TGNMLEN

#define TGNMLEN   32

Definition at line 187 of file mod_mime_magic.c.

◆ TMAGIC

#define TMAGIC   "ustar " /* 7 chars and a null */

Definition at line 210 of file mod_mime_magic.c.

◆ TUNMLEN

#define TUNMLEN   32

Definition at line 186 of file mod_mime_magic.c.

◆ UNSIGNED

#define UNSIGNED   2 /* comparison is unsigned */

Definition at line 134 of file mod_mime_magic.c.

Typedef Documentation

◆ magic_rsl

Enumeration Type Documentation

◆ rsl_states

Enumerator
rsl_leading_space 
rsl_type 
rsl_subtype 
rsl_separator 
rsl_encoding 

Definition at line 659 of file mod_mime_magic.c.

Function Documentation

◆ apprentice()

static int apprentice ( server_rec s,
apr_pool_t p 
)
static

< Open the file for reading

<

Deprecated:
See also
APR_FOPEN_READ

< Open the file for buffered I/O

<

Deprecated:
See also
APR_FOPEN_BUFFERED

< use OS's default permissions

<

Deprecated:
See also
APR_FPROT_OS_DEFAULT

Definition at line 913 of file mod_mime_magic.c.

◆ ascmagic()

static int ascmagic ( request_rec r,
unsigned char buf,
apr_size_t  nbytes 
)
static

Definition at line 1971 of file mod_mime_magic.c.

◆ create_magic_server_config()

static void * create_magic_server_config ( apr_pool_t p,
server_rec d 
)
static

Definition at line 473 of file mod_mime_magic.c.

◆ create_uncompress_child()

static int create_uncompress_child ( struct uncompress_parms parm,
apr_pool_t cntxt,
apr_file_t **  pipe_in 
)
static

Definition at line 2116 of file mod_mime_magic.c.

◆ from_oct()

static long from_oct ( int  digs,
char where 
)
static

Definition at line 2265 of file mod_mime_magic.c.

◆ fsmagic()

static int fsmagic ( request_rec r,
const char fn 
)
static

< Module has served the response completely * - it's safe to die() with no more output

< Module has served the response completely * - it's safe to die() with no more output

< Module has served the response completely * - it's safe to die() with no more output

< Module has served the response completely * - it's safe to die() with no more output

< Module has served the response completely * - it's safe to die() with no more output

< Module has served the response completely * - it's safe to die() with no more output

< Module has handled this stage.

Definition at line 1435 of file mod_mime_magic.c.

◆ getstr() [1/2]

static char * getstr ( server_rec ,
char ,
char ,
int  ,
int  
)
static

◆ getstr() [2/2]

static char * getstr ( server_rec serv,
register char s,
register char p,
int  plen,
int slen 
)
static

Definition at line 1308 of file mod_mime_magic.c.

◆ getvalue()

static int getvalue ( server_rec s,
struct magic m,
char **  p 
)
static

Definition at line 1290 of file mod_mime_magic.c.

◆ hextoint()

static int hextoint ( int  c)
static

Definition at line 1418 of file mod_mime_magic.c.

◆ is_tar()

static int is_tar ( unsigned char buf,
apr_size_t  nbytes 
)
static

Definition at line 2224 of file mod_mime_magic.c.

◆ magic_find_ct()

static int magic_find_ct ( request_rec r)
static

< Module declines to handle

< Module declines to handle

< Module declines to handle

< Module has handled this stage.

Definition at line 2411 of file mod_mime_magic.c.

◆ magic_init()

static int magic_init ( apr_pool_t p,
apr_pool_t plog,
apr_pool_t ptemp,
server_rec main_server 
)
static

< Module has handled this stage.

< Module has handled this stage.

Definition at line 2359 of file mod_mime_magic.c.

◆ magic_process()

static int magic_process ( request_rec r)
static

< Module has served the response completely * - it's safe to die() with no more output

< Module has handled this stage.

< Module has handled this stage.

< Open the file for reading

<

Deprecated:
See also
APR_FOPEN_READ

< use OS's default permissions

<

Deprecated:
See also
APR_FPROT_OS_DEFAULT

< Module declines to handle

< Module declines to handle

< Module has handled this stage.

< Module has handled this stage.

Definition at line 821 of file mod_mime_magic.c.

◆ magic_rsl_add()

static int magic_rsl_add ( request_rec r,
const char str 
)
static

Definition at line 542 of file mod_mime_magic.c.

◆ magic_rsl_printf()

static int magic_rsl_printf ( request_rec r,
char str,
  ... 
)
static

Definition at line 585 of file mod_mime_magic.c.

◆ magic_rsl_putchar()

static int magic_rsl_putchar ( request_rec r,
char  c 
)
static

Definition at line 601 of file mod_mime_magic.c.

◆ magic_rsl_puts()

static int magic_rsl_puts ( request_rec r,
const char str 
)
static

Definition at line 579 of file mod_mime_magic.c.

◆ magic_rsl_to_request()

static int magic_rsl_to_request ( request_rec r)
static

< Module declines to handle

< Module declines to handle

< Module declines to handle

< Module declines to handle

< Module declines to handle

< Module has handled this stage.

Definition at line 664 of file mod_mime_magic.c.

◆ magic_set_config()

static magic_req_rec * magic_set_config ( request_rec r)
static

Definition at line 530 of file mod_mime_magic.c.

◆ match()

static int match ( request_rec r,
unsigned char s,
apr_size_t  nbytes 
)
static

Definition at line 1529 of file mod_mime_magic.c.

◆ mcheck()

static int mcheck ( request_rec r,
union VALUETYPE *  p,
struct magic m 
)
static

Definition at line 1822 of file mod_mime_magic.c.

◆ mconvert()

static int mconvert ( request_rec r,
union VALUETYPE *  p,
struct magic m 
)
static

Definition at line 1744 of file mod_mime_magic.c.

◆ merge_magic_server_config()

static void * merge_magic_server_config ( apr_pool_t p,
void *  basev,
void *  addv 
)
static

Definition at line 479 of file mod_mime_magic.c.

◆ mget()

static int mget ( request_rec r,
union VALUETYPE *  p,
unsigned char s,
struct magic m,
apr_size_t  nbytes 
)
static

Definition at line 1784 of file mod_mime_magic.c.

◆ mprint()

static void mprint ( request_rec r,
union VALUETYPE *  p,
struct magic m 
)
static

Definition at line 1691 of file mod_mime_magic.c.

◆ parse()

static int parse ( server_rec serv,
apr_pool_t p,
char l,
int  lineno 
)
static

Definition at line 1063 of file mod_mime_magic.c.

◆ register_hooks()

static void register_hooks ( apr_pool_t p)
static

Definition at line 2448 of file mod_mime_magic.c.

◆ revision_suffix()

static int revision_suffix ( request_rec r)
static

Definition at line 2296 of file mod_mime_magic.c.

◆ rsl_strdup()

static char * rsl_strdup ( request_rec r,
int  start_frag,
int  start_pos,
int  len 
)
static

Definition at line 612 of file mod_mime_magic.c.

◆ set_magicfile()

static const char * set_magicfile ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

Definition at line 492 of file mod_mime_magic.c.

◆ signextend()

static unsigned long signextend ( server_rec s,
struct magic m,
unsigned long  v 
)
static

Definition at line 1026 of file mod_mime_magic.c.

◆ softmagic()

static int softmagic ( request_rec r,
unsigned char buf,
apr_size_t  nbytes 
)
static

Definition at line 1495 of file mod_mime_magic.c.

◆ tryit()

static int tryit ( request_rec r,
unsigned char buf,
apr_size_t  nb,
int  checkzmagic 
)
static

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

< Module declines to handle

Definition at line 878 of file mod_mime_magic.c.

◆ uncompress()

static int uncompress ( request_rec r,
int  method,
unsigned char **  newch,
apr_size_t  n 
)
static

Definition at line 2167 of file mod_mime_magic.c.

◆ zmagic()

static int zmagic ( request_rec r,
unsigned char buf,
apr_size_t  nbytes 
)
static

< Module has handled this stage.

Definition at line 2081 of file mod_mime_magic.c.

Variable Documentation

◆ aplog_module_index

int* const aplog_module_index = &( mime_magic_module.module_index)
static

Definition at line 2462 of file mod_mime_magic.c.

◆ argv

const char* argv[3]

Definition at line 2049 of file mod_mime_magic.c.

◆ [struct]

const struct { ... } compr[]
Initial value:
= {
{
"\037\235", 2, {
"gzip", "-dcq", NULL
}, 0, "x-compress"
},
{
"\037\213", 2, {
"gzip", "-dcq", NULL
}, 1, "x-gzip"
},
{
"\037\036", 2, {
"gzip", "-dcq", NULL
}, 0, "x-gzip"
},
}
return NULL
Definition mod_so.c:359

◆ encoding

Definition at line 2051 of file mod_mime_magic.c.

◆ magic

Definition at line 2047 of file mod_mime_magic.c.

◆ maglen

apr_size_t maglen

Definition at line 2048 of file mod_mime_magic.c.

◆ mime_magic_cmds

const command_rec mime_magic_cmds[]
static
Initial value:
=
{
{ "MimeMagicFile" , set_magicfile , NULL , 128 , TAKE1, "Path to MIME Magic file (in file(1) format)" },
{NULL}
}
@ TAKE1
Definition http_config.h:51
static const char * set_magicfile(cmd_parms *cmd, void *dummy, const char *arg)

Definition at line 509 of file mod_mime_magic.c.

◆ names

const struct names names[]
static

◆ silent

int silent

Definition at line 2050 of file mod_mime_magic.c.

◆ types

const char* const types[]
static
Initial value:
=
{
"text/html",
"text/plain",
"text/plain",
"text/plain",
"text/plain",
"text/plain",
"text/plain",
"text/plain",
"message/rfc822",
"message/news",
"application/binary",
0
}

Definition at line 260 of file mod_mime_magic.c.