88#define APR_WANT_STRFUNC
113#define MODNAME "mod_mime_magic"
114#define MIME_MAGIC_DEBUG 0
116#define MIME_BINARY_UNKNOWN "application/octet-stream"
117#define MIME_TEXT_UNKNOWN "text/plain"
119#define MAXMIMESTRING 256
124#define SMALL_HOWMANY 1024
184#define RECORDSIZE 512
210#define TMAGIC "ustar "
272 "application/binary",
435#define NNAMES ((sizeof(names)/sizeof(struct names)) - 1)
471module AP_MODULE_DECLARE_DATA mime_magic_module;
499 return MODNAME ": server structure not allocated";
512 "Path to MIME Magic file (in file(1) format)"),
551 MODNAME ": request config should not be NULL");
726 MODNAME ": bad state %d (ws)", state);
770 MODNAME ": bad state %d (ns)", state);
806 MODNAME ": unexpected state %d; could be caused by bad "
807 "data in magic file",
907#define EATAB {while (apr_isspace(*l)) ++l;}
946 char *
last = line + strlen(line) - 1;
986 MODNAME ": apprentice conf=%pp file=%s m=%s m->next=%s last=%s",
989 conf->
magic ?
"set" :
"NULL",
991 conf->
last ?
"set" :
"NULL");
993 MODNAME ": apprentice read %d lines, %d rules, %d errors",
1007 MODNAME ": apprentice: POINTER CLOBBERED! "
1008 "m=\"%c%c%c%c\" line=%d",
1009 (((
unsigned long)
m) >> 24) & 255,
1010 (((
unsigned long)
m) >> 16) & 255,
1011 (((
unsigned long)
m) >> 8) & 255,
1012 ((
unsigned long)
m) & 255,
1020 return (
errs ? -1 : 0);
1054 MODNAME ": can't happen: m->type=%d",
m->type);
1093 if (
m->cont_level != 0 && *l ==
'(') {
1102 MODNAME ": offset %s invalid", l);
1125 MODNAME ": indirect offset type %c invalid", *l);
1131 if (*l ==
'+' || *l ==
'-')
1136 m->in.offset = -
m->in.offset;
1142 MODNAME ": missing ')' in indirect offset");
1216 MODNAME ": type %s invalid", l);
1267 else if ((l[0] ==
'\\') && (l[1] ==
'b')) {
1278 MODNAME ": parse line=%d m=%pp next=%pp cont=%d desc=%s",
1298 else if (
m->reln !=
'x')
1316 while ((
c = *
s++) !=
'\0') {
1369 if (
c >=
'0' &&
c <=
'7') {
1372 if (
c >=
'0' &&
c <=
'7')
1422 if ((
c >=
'a') && (
c <=
'f'))
1423 return c + 10 -
'a';
1424 if ((
c >=
'A') && (
c <=
'F'))
1425 return c + 10 -
'A';
1467 MODNAME ": broken symlink (%s)", fn);
1543 MODNAME ": match conf=%pp file=%s m=%s m->next=%s last=%s",
1545 conf->magicfile ? conf->magicfile :
"NULL",
1546 conf->magic ?
"set" :
"NULL",
1547 (conf->magic && conf->magic->next) ?
"set" :
"NULL",
1548 conf->last ?
"set" :
"NULL");
1552 for (
m = conf->magic;
m;
m =
m->next) {
1558 MODNAME ": match: POINTER CLOBBERED! "
1560 (((
unsigned long)
m) >> 24) & 255,
1561 (((
unsigned long)
m) >> 16) & 255,
1562 (((
unsigned long)
m) >> 8) & 255,
1563 ((
unsigned long)
m) & 255);
1569 for (
m = conf->magic;
m;
m =
m->next) {
1573 MODNAME ": line=%d desc=%s",
m->lineno,
m->desc);
1584 if (!
m->next || (
m->next->cont_level == 0)) {
1593 MODNAME ": line=%d mc=%pp mc->next=%pp cont=%d desc=%s",
1612 MODNAME ": rule matched, line=%d type=%d %s",
1614 (
m->type ==
STRING) ?
m->value.s :
"");
1633 while (
m && (
m->cont_level != 0)) {
1636 MODNAME ": match line=%d cont=%d type=%d %s",
1637 m->lineno,
m->cont_level,
m->type,
1638 (
m->type ==
STRING) ?
m->value.s :
"");
1657 && (
m->nospflag == 0)
1658 && (
m->desc[0] !=
'\0')
1715 if (
m->reln ==
'=') {
1732 MODNAME ": invalid m->type (%d) in mprint().",
1756 p->s[
sizeof(
p->s) - 1] =
'\0';
1761 p->h = (
short) ((
p->hs[0] << 8) | (
p->hs[1]));
1766 ((
p->hl[0] << 24) | (
p->hl[1] << 16) | (
p->hl[2] << 8) | (
p->hl[3]));
1769 p->h = (
short) ((
p->hs[1] << 8) | (
p->hs[0]));
1774 ((
p->hl[3] << 24) | (
p->hl[2] << 16) | (
p->hl[1] << 8) | (
p->hl[0]));
1778 MODNAME ": invalid type %d in mconvert().",
m->type);
1799 switch (
m->in.type) {
1824 register unsigned long l =
m->value.l;
1825 register unsigned long v;
1828 if ((
m->value.s[0] ==
'x') && (
m->value.s[1] ==
'\0')) {
1863 register unsigned char *
a = (
unsigned char *)
m->value.s;
1864 register unsigned char *
b = (
unsigned char *)
p->s;
1865 register int len =
m->vallen;
1868 if ((v = *
b++ - *
a++) != 0)
1875 MODNAME ": invalid type %d in mcheck().",
m->type);
1885 "%lu == *any* = 1", v);
1894 "%lu != %lu = %d", v, l, matched);
1902 "%lu == %lu = %d", v, l, matched);
1911 "%lu > %lu = %d", v, l, matched);
1915 matched = (
long) v > (
long) l;
1918 "%ld > %ld = %d", v, l, matched);
1928 "%lu < %lu = %d", v, l, matched);
1932 matched = (
long) v < (
long) l;
1935 "%ld < %ld = %d", v, l, matched);
1941 matched = (v & l) == l;
1944 "((%lx & %lx) == %lx) = %d", v, l, l, matched);
1949 matched = (v & l) != l;
1952 "((%lx & %lx) != %lx) = %d", v, l, l, matched);
1960 MODNAME ": mcheck: can't happen: invalid relation %d.",
1969#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
1989 unsigned char *tp =
buf + 1;
2015 if (
STREQ(
p->name, token)) {
2046static const struct {
2060 "gzip",
"-dcq",
NULL
2065 "gzip",
"-dcq",
NULL
2074 "gzip",
"-dcq",
NULL
2079#define ncompr (sizeof(compr) / sizeof(compr[0]))
2140 "couldn't setup child process: %s",
r->
filename);
2155 MODNAME ": could not execute `%s'.",
2188 MODNAME ": couldn't spawn uncompress process: %s",
r->
uri);
2217#define isodigit(c) (((unsigned char)(c) >= '0') && ((unsigned char)(c) <= '7'))
2238 for (
i =
sizeof(
union record); --
i >= 0;) {
2267 register long value;
2332 MODNAME ": subrequest %s got %s",
2383 MODNAME ": magic_init 1 test");
2390 MODNAME ": magic_init 1: POINTER CLOBBERED! "
2391 "m=\"%c%c%c%c\" line=%d",
2392 (((
unsigned long)
m) >> 24) & 255,
2393 (((
unsigned long)
m) >> 16) & 255,
2394 (((
unsigned long)
m) >> 8) & 255,
2395 ((
unsigned long)
m) & 255,
2427 if (!conf || !conf->
magic) {
2450 static const char *
const aszPre[]={
"mod_mime.c",
NULL };
Symbol export macros and hook functions.
int int const char ** match
const char apr_size_t len
APR general purpose library routines.
apr_size_t const unsigned char unsigned int unsigned int d
APR Standard Headers Support.
#define AP_INIT_TAKE1(directive, func, mconfig, where, help)
#define ap_get_module_config(v, m)
void ap_hook_post_config(ap_HOOK_post_config_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
#define AP_DECLARE_MODULE(foo)
char * ap_server_root_relative(apr_pool_t *p, const char *fname)
#define ap_set_module_config(v, m, val)
const char server_rec * main_server
const unsigned char * buf
void ap_set_content_type_ex(request_rec *r, const char *ct, int trusted)
request_rec * ap_sub_req_lookup_file(const char *new_file, const request_rec *r, ap_filter_t *next_filter)
void ap_hook_type_checker(ap_HOOK_type_checker_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
void ap_destroy_sub_req(request_rec *r)
apr_bucket apr_bucket_brigade * a
const char const char apr_int32_t apr_fileperms_t apr_pool_t * cntxt
const char apr_ssize_t slen
const char *const * aszPre
#define HTTP_INTERNAL_SERVER_ERROR
#define STANDARD20_MODULE_STUFF
char * ap_make_dirstr_parent(apr_pool_t *p, const char *s)
void ap_content_type_tolower(char *s)
void ap_str_tolower(char *s)
apr_seek_where_t apr_off_t * offset
apr_array_header_t ** result
void * memchr(const void *s, int c, size_t n)
apr_vformatter_buff_t * c
apr_vformatter_buff_t const char va_list ap
apr_uint32_t apr_pool_t apr_uint32_t apr_pollset_method_e method
#define apr_pool_create(newpool, parent)
#define apr_pcalloc(p, size)
apr_size_t const char * filename
#define apr_time_from_sec(sec)
struct magic_rsl_s magic_rsl
static int magic_rsl_putchar(request_rec *r, char c)
static int revision_suffix(request_rec *r)
static void * create_magic_server_config(apr_pool_t *p, server_rec *d)
static int fsmagic(request_rec *r, const char *fn)
static int zmagic(request_rec *, unsigned char *, apr_size_t)
#define MIME_TEXT_UNKNOWN
static unsigned long signextend(server_rec *s, struct magic *m, unsigned long v)
static long from_oct(int, char *)
static int tryit(request_rec *, unsigned char *, apr_size_t, int)
static magic_req_rec * magic_set_config(request_rec *r)
static int mconvert(request_rec *r, union VALUETYPE *p, struct magic *m)
static int magic_rsl_puts(request_rec *r, const char *str)
static const struct @26 compr[]
static int softmagic(request_rec *, unsigned char *, apr_size_t)
static int create_uncompress_child(struct uncompress_parms *parm, apr_pool_t *cntxt, apr_file_t **pipe_in)
static int magic_process(request_rec *r)
static int is_tar(unsigned char *, apr_size_t)
static void register_hooks(apr_pool_t *p)
static int mget(request_rec *, union VALUETYPE *, unsigned char *, struct magic *, apr_size_t)
static const char *const types[]
static int apprentice(server_rec *s, apr_pool_t *p)
static int uncompress(request_rec *, int, unsigned char **, apr_size_t)
static const command_rec mime_magic_cmds[]
static char * getstr(server_rec *, char *, char *, int, int *)
static int magic_rsl_add(request_rec *r, const char *str)
#define MIME_BINARY_UNKNOWN
static const char * set_magicfile(cmd_parms *cmd, void *dummy, const char *arg)
static void mprint(request_rec *, union VALUETYPE *, struct magic *)
static int getvalue(server_rec *, struct magic *, char **)
static int magic_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_server)
static char * rsl_strdup(request_rec *r, int start_frag, int start_pos, int len)
static int magic_rsl_to_request(request_rec *r)
static int parse(server_rec *, apr_pool_t *p, char *, int)
static int magic_find_ct(request_rec *r)
static int ascmagic(request_rec *, unsigned char *, apr_size_t)
static int mcheck(request_rec *, union VALUETYPE *, struct magic *)
static void * merge_magic_server_config(apr_pool_t *p, void *basev, void *addv)
static int magic_rsl_printf(request_rec *r, char *str,...)
struct magic_rsl_s * next
union magic::VALUETYPE value
A structure that represents the current request.
apr_array_header_t * content_languages
const char * content_type
struct ap_conf_vector_t * request_config
const char * content_encoding
A structure to store information for each virtual server.
struct ap_conf_vector_t * module_config
struct record::header header
apr_status_t apr_ctime(char *date_str, apr_time_t t)
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray