/* ====================================================================
- * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* the documentation and/or other materials provided with the
* distribution.
*
- * 3. All advertising materials mentioning features or use of this
- * software must display the following acknowledgment:
- * "This product includes software developed by the Apache Group
- * for use in the Apache HTTP server project (http://www.apache.org/)."
- *
- * 4. The names "Apache Server" and "Apache Group" must not be used to
- * endorse or promote products derived from this software without
- * prior written permission. For written permission, please contact
- * apache@apache.org.
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
*
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
*
- * 6. Redistributions of any form whatsoever must retain the following
- * acknowledgment:
- * "This product includes software developed by the Apache Group
- * for use in the Apache HTTP server project (http://www.apache.org/)."
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
*
- * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
- * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Group and was originally based
- * on public domain software written at the National Center for
- * Supercomputing Applications, University of Illinois, Urbana-Champaign.
- * For more information on the Apache Group and the Apache HTTP server
- * project, please see <http://www.apache.org/>.
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
*
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
*/
/*
* mod_mime_magic: MIME type lookup via file magic numbers
* Copyright (c) 1996-1997 Cisco Systems, Inc.
*
- * This software was submitted by Cisco Systems to the Apache Group in July
+ * This software was submitted by Cisco Systems to the Apache Software Foundation in July
* 1997. Future revisions and derivatives of this source code must
* acknowledge Cisco Systems as the original contributor of this module.
- * All other licensing and usage conditions are those of the Apache Group.
+ * All other licensing and usage conditions are those of the Apache Software Foundation.
*
* Some of this code is derived from the free version of the file command
* originally posted to comp.sources.unix. Copyright info for that program
* modified from the free "file" command.
* - all-in-one file for compilation convenience when moving from one
* version of Apache to the next.
- * - Memory allocation is done through the Apache API's ap_context_t structure.
+ * - Memory allocation is done through the Apache API's apr_pool_t structure.
* - All functions have had necessary Apache API request or server
* structures passed to them where necessary to call other Apache API
* routines. (i.e. usually for logging, files, or memory allocation in
*
* Initial installation July/August 1996
* Misc bug fixes May 1997
- * Submission to Apache Group July 1997
+ * Submission to Apache Software Foundation July 1997
*
*/
+#include "apr.h"
+#include "apr_strings.h"
+
+#if APR_HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_request.h"
#include "http_protocol.h"
#include "util_script.h"
+/* ### this isn't set by configure? does anybody set this? */
+#ifdef HAVE_UTIME_H
#include <utime.h>
-
+#endif
/*
* data structures and related constants
/*
* file-function prototypes
*/
-static int ascmagic(request_rec *, unsigned char *, int);
-static int is_tar(unsigned char *, int);
-static int softmagic(request_rec *, unsigned char *, int);
-static void tryit(request_rec *, unsigned char *, int, int);
-static int zmagic(request_rec *, unsigned char *, int);
+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 void 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 char *getstr(server_rec *, char *, char *, int, int *);
-static int parse(server_rec *, ap_context_t *p, char *, int);
+static int parse(server_rec *, apr_pool_t *p, char *, int);
-static int match(request_rec *, unsigned char *, int);
+static int match(request_rec *, unsigned char *, apr_size_t);
static int mget(request_rec *, union VALUETYPE *, unsigned char *,
- struct magic *, int);
+ 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 **, int);
+ unsigned char **, apr_size_t);
static long from_oct(int, char *);
static int fsmagic(request_rec *r, const char *fn);
* make HOWMANY too high unless you have a very fast CPU.
*/
-/* these types are used to index the ap_table_t 'types': keep em in sync! */
+/* these types are used to index the apr_table_t 'types': keep em in sync! */
/* HTML inserted in first because this is a web server module now */
#define L_HTML 0 /* HTML */
#define L_C 1 /* first and foremost on UNIX */
/* per-server info */
typedef struct {
- char *magicfile; /* where magic be found */
+ const char *magicfile; /* where magic be found */
struct magic *magic; /* head of magic config list */
struct magic *last;
} magic_server_config_rec;
module mime_magic_module;
-static void *create_magic_server_config(ap_context_t *p, server_rec *d)
+static void *create_magic_server_config(apr_pool_t *p, server_rec *d)
{
/* allocate the config - use pcalloc because it needs to be zeroed */
- return ap_pcalloc(p, sizeof(magic_server_config_rec));
+ return apr_pcalloc(p, sizeof(magic_server_config_rec));
}
-static void *merge_magic_server_config(ap_context_t *p, void *basev, void *addv)
+static void *merge_magic_server_config(apr_pool_t *p, void *basev, void *addv)
{
magic_server_config_rec *base = (magic_server_config_rec *) basev;
magic_server_config_rec *add = (magic_server_config_rec *) addv;
magic_server_config_rec *new = (magic_server_config_rec *)
- ap_palloc(p, sizeof(magic_server_config_rec));
+ apr_palloc(p, sizeof(magic_server_config_rec));
new->magicfile = add->magicfile ? add->magicfile : base->magicfile;
new->magic = NULL;
return new;
}
-static const char *set_magicfile(cmd_parms *cmd, char *d, char *arg)
+static const char *set_magicfile(cmd_parms *cmd, void *dummy, const char *arg)
{
magic_server_config_rec *conf = (magic_server_config_rec *)
ap_get_module_config(cmd->server->module_config,
static const command_rec mime_magic_cmds[] =
{
- {"MimeMagicFile", set_magicfile, NULL, RSRC_CONF, TAKE1,
- "Path to MIME Magic file (in file(1) format)"},
+ AP_INIT_TAKE1("MimeMagicFile", set_magicfile, NULL, RSRC_CONF,
+ "Path to MIME Magic file (in file(1) format)"),
{NULL}
};
/* allocate a per-request structure and put it in the request record */
static magic_req_rec *magic_set_config(request_rec *r)
{
- magic_req_rec *req_dat = (magic_req_rec *) ap_palloc(r->pool,
+ magic_req_rec *req_dat = (magic_req_rec *) apr_palloc(r->pool,
sizeof(magic_req_rec));
req_dat->head = req_dat->tail = (magic_rsl *) NULL;
}
/* allocate the list entry */
- rsl = (magic_rsl *) ap_palloc(r->pool, sizeof(magic_rsl));
+ rsl = (magic_rsl *) apr_palloc(r->pool, sizeof(magic_rsl));
/* fill it */
rsl->str = str;
/* assemble the string into the buffer */
va_start(ap, str);
- ap_vsnprintf(buf, sizeof(buf), str, ap);
+ apr_vsnprintf(buf, sizeof(buf), str, ap);
va_end(ap);
/* add the buffer to the list */
ap_get_module_config(r->request_config, &mime_magic_module);
/* allocate the result string */
- result = (char *) ap_palloc(r->pool, len + 1);
+ result = (char *) apr_palloc(r->pool, len + 1);
/* loop through and collect the string */
res_pos = 0;
frag = frag->next, cur_frag++) {
/* loop through the characters in the fragment */
for (cur_pos = 0; frag->str[cur_pos]; cur_pos++) {
- if (ap_isspace(frag->str[cur_pos])) {
+ if (apr_isspace(frag->str[cur_pos])) {
/* process whitespace actions for each state */
if (state == rsl_leading_space) {
/* eat whitespace in this state */
*/
static int magic_process(request_rec *r)
{
- ap_file_t *fd = NULL;
+ apr_file_t *fd = NULL;
unsigned char buf[HOWMANY + 1]; /* one extra for terminating '\0' */
- int nbytes = 0; /* number of bytes read from a datafile */
+ apr_size_t nbytes = 0; /* number of bytes read from a datafile */
int result;
/*
return result;
}
- if (ap_open(&fd, r->filename, APR_READ, APR_OS_DEFAULT, r->pool) != APR_SUCCESS) {
+ if (apr_file_open(&fd, r->filename, APR_READ, APR_OS_DEFAULT, r->pool) != APR_SUCCESS) {
/* We can't open it, but we were able to stat it. */
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
MODNAME ": can't read `%s'", r->filename);
* try looking at the first HOWMANY bytes
*/
nbytes = sizeof(buf) - 1;
- if ((result = ap_read(fd, (char *) buf, &nbytes)) != APR_SUCCESS) {
+ if ((result = apr_file_read(fd, (char *) buf, &nbytes)) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, result, r,
MODNAME ": read failed: %s", r->filename);
return HTTP_INTERNAL_SERVER_ERROR;
tryit(r, buf, nbytes, 1);
}
- (void) ap_close(fd);
+ (void) apr_file_close(fd);
(void) magic_rsl_putchar(r, '\n');
return OK;
}
-static void tryit(request_rec *r, unsigned char *buf, int nb, int checkzmagic)
+static void tryit(request_rec *r, unsigned char *buf, apr_size_t nb, int checkzmagic)
{
/*
* Try compression stuff
magic_rsl_puts(r, MIME_BINARY_UNKNOWN);
}
-#define EATAB {while (ap_isspace((unsigned char) *l)) ++l;}
+#define EATAB {while (apr_isspace((unsigned char) *l)) ++l;}
/*
* apprentice - load configuration from the magic file r
* API request record
*/
-static int apprentice(server_rec *s, ap_context_t *p)
+static int apprentice(server_rec *s, apr_pool_t *p)
{
- ap_file_t *f;
- ap_status_t result;
+ apr_file_t *f = NULL;
+ apr_status_t result;
char line[BUFSIZ + 1];
int errs = 0;
int lineno;
ap_get_module_config(s->module_config, &mime_magic_module);
const char *fname = ap_server_root_relative(p, conf->magicfile);
- result = ap_open(&f, fname, APR_READ | APR_BUFFERED, APR_OS_DEFAULT, p);
+ result = apr_file_open(&f, fname, APR_READ | APR_BUFFERED, APR_OS_DEFAULT, p);
if (result != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, result, s,
MODNAME ": can't read magic file %s", fname);
conf->magic = conf->last = NULL;
/* parse it */
- for (lineno = 1; ap_fgets(line, BUFSIZ, f) == APR_SUCCESS; lineno++) {
+ for (lineno = 1; apr_file_gets(line, BUFSIZ, f) == APR_SUCCESS; lineno++) {
int ws_offset;
/* delete newline */
/* skip leading whitespace */
ws_offset = 0;
- while (line[ws_offset] && ap_isspace(line[ws_offset])) {
+ while (line[ws_offset] && apr_isspace(line[ws_offset])) {
ws_offset++;
}
++errs;
}
- (void) ap_close(f);
+ (void) apr_file_close(f);
#if MIME_MAGIC_DEBUG
ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, s,
ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, s,
MODNAME ": apprentice test");
for (m = conf->magic; m; m = m->next) {
- if (ap_isprint((((unsigned long) m) >> 24) & 255) &&
- ap_isprint((((unsigned long) m) >> 16) & 255) &&
- ap_isprint((((unsigned long) m) >> 8) & 255) &&
- ap_isprint(((unsigned long) m) & 255)) {
+ if (apr_isprint((((unsigned long) m) >> 24) & 255) &&
+ apr_isprint((((unsigned long) m) >> 16) & 255) &&
+ apr_isprint((((unsigned long) m) >> 8) & 255) &&
+ apr_isprint(((unsigned long) m) & 255)) {
ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, s,
MODNAME ": apprentice: POINTER CLOBBERED! "
"m=\"%c%c%c%c\" line=%d",
/*
* parse one line from magic file, put into magic[index++] if valid
*/
-static int parse(server_rec *serv, ap_context_t *p, char *l, int lineno)
+static int parse(server_rec *serv, apr_pool_t *p, char *l, int lineno)
{
struct magic *m;
char *t, *s;
ap_get_module_config(serv->module_config, &mime_magic_module);
/* allocate magic structure entry */
- m = (struct magic *) ap_pcalloc(p, sizeof(struct magic));
+ m = (struct magic *) apr_pcalloc(p, sizeof(struct magic));
/* append to linked list */
m->next = NULL;
s = l;
if (*l == '+' || *l == '-')
l++;
- if (ap_isdigit((unsigned char) *l)) {
+ if (apr_isdigit((unsigned char) *l)) {
m->in.offset = strtol(l, &t, 0);
if (*s == '-')
m->in.offset = -m->in.offset;
}
- while (ap_isdigit((unsigned char) *l))
+ while (apr_isdigit((unsigned char) *l))
++l;
EATAB;
}
/* FALL THROUGH */
default:
- if (*l == 'x' && ap_isspace((unsigned char) l[1])) {
+ if (*l == 'x' && apr_isspace((unsigned char) l[1])) {
m->reln = *l;
++l;
goto GetDesc; /* Bill The Cat */
register int val;
while ((c = *s++) != '\0') {
- if (ap_isspace((unsigned char) c))
+ if (apr_isspace((unsigned char) c))
break;
if (p >= pmax) {
ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0, serv,
/* Single hex char to int; -1 if not a hex char. */
static int hextoint(int c)
{
- if (ap_isdigit((unsigned char) c))
+ if (apr_isdigit((unsigned char) c))
return c - '0';
if ((c >= 'a') && (c <= 'f'))
return c + 10 - 'a';
*/
static int fsmagic(request_rec *r, const char *fn)
{
- switch (r->finfo.st_mode & S_IFMT) {
- case S_IFDIR:
+ switch (r->finfo.filetype) {
+ case APR_DIR:
magic_rsl_puts(r, DIR_MAGIC_TYPE);
return DONE;
- case S_IFCHR:
+ case APR_CHR:
/*
* (void) magic_rsl_printf(r,"character special (%d/%d)",
* major(sb->st_rdev), minor(sb->st_rdev));
*/
(void) magic_rsl_puts(r, MIME_BINARY_UNKNOWN);
return DONE;
-#ifdef S_IFBLK
- case S_IFBLK:
+ case APR_BLK:
/*
* (void) magic_rsl_printf(r,"block special (%d/%d)",
* major(sb->st_rdev), minor(sb->st_rdev));
(void) magic_rsl_puts(r, MIME_BINARY_UNKNOWN);
return DONE;
/* TODO add code to handle V7 MUX and Blit MUX files */
-#endif
-#ifdef S_IFIFO
- case S_IFIFO:
+ case APR_PIPE:
/*
* magic_rsl_puts(r,"fifo (named pipe)");
*/
(void) magic_rsl_puts(r, MIME_BINARY_UNKNOWN);
return DONE;
-#endif
-#ifdef S_IFLNK
- case S_IFLNK:
+ case APR_LNK:
/* We used stat(), the only possible reason for this is that the
* symlink is broken.
*/
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0, r,
MODNAME ": broken symlink (%s)", fn);
return HTTP_INTERNAL_SERVER_ERROR;
-#endif
-#ifdef S_IFSOCK
-#ifndef __COHERENT__
- case S_IFSOCK:
+ case APR_SOCK:
magic_rsl_puts(r, MIME_BINARY_UNKNOWN);
return DONE;
-#endif
-#endif
- case S_IFREG:
+ case APR_REG:
break;
default:
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0, r,
- MODNAME ": invalid mode 0%o.", (unsigned int)r->finfo.st_mode);
+ MODNAME ": invalid file type %d.", r->finfo.filetype);
return HTTP_INTERNAL_SERVER_ERROR;
}
/*
* regular file, check next possibility
*/
- if (r->finfo.st_size == 0) {
+ if (r->finfo.size == 0) {
magic_rsl_puts(r, MIME_TEXT_UNKNOWN);
return DONE;
}
* apprentice.c). Passed the name and FILE * of one file to be typed.
*/
/* ARGSUSED1 *//* nbytes passed for regularity, maybe need later */
-static int softmagic(request_rec *r, unsigned char *buf, int nbytes)
+static int softmagic(request_rec *r, unsigned char *buf, apr_size_t nbytes)
{
if (match(r, buf, nbytes))
return 1;
* If a continuation matches, we bump the current continuation level so that
* higher-level continuations are processed.
*/
-static int match(request_rec *r, unsigned char *s, int nbytes)
+static int match(request_rec *r, unsigned char *s, apr_size_t nbytes)
{
#if MIME_MAGIC_DEBUG
int rule_counter = 0;
#if MIME_MAGIC_DEBUG
for (m = conf->magic; m; m = m->next) {
- if (ap_isprint((((unsigned long) m) >> 24) & 255) &&
- ap_isprint((((unsigned long) m) >> 16) & 255) &&
- ap_isprint((((unsigned long) m) >> 8) & 255) &&
- ap_isprint(((unsigned long) m) & 255)) {
+ if (apr_isprint((((unsigned long) m) >> 24) & 255) &&
+ apr_isprint((((unsigned long) m) >> 16) & 255) &&
+ apr_isprint((((unsigned long) m) >> 8) & 255) &&
+ apr_isprint(((unsigned long) m) & 255)) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, r,
MODNAME ": match: POINTER CLOBBERED! "
"m=\"%c%c%c%c\"",
static int mget(request_rec *r, union VALUETYPE *p, unsigned char *s,
- struct magic *m, int nbytes)
+ struct magic *m, apr_size_t nbytes)
{
long offset = m->offset;
/* an optimization over plain strcmp() */
#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
-static int ascmagic(request_rec *r, unsigned char *buf, int nbytes)
+static int ascmagic(request_rec *r, unsigned char *buf, apr_size_t nbytes)
{
int has_escapes = 0;
unsigned char *s;
if (*buf == '.') {
unsigned char *tp = buf + 1;
- while (ap_isspace(*tp))
+ while (apr_isspace(*tp))
++tp; /* skip leading whitespace */
- if ((ap_isalnum(*tp) || *tp == '\\') &&
- (ap_isalnum(*(tp + 1)) || *tp == '"')) {
+ if ((apr_isalnum(*tp) || *tp == '\\') &&
+ (apr_isalnum(*(tp + 1)) || *tp == '"')) {
magic_rsl_puts(r, "application/x-troff");
return 1;
}
}
- if ((*buf == 'c' || *buf == 'C') && ap_isspace(*(buf + 1))) {
+ if ((*buf == 'c' || *buf == 'C') && apr_isspace(*(buf + 1))) {
/* Fortran */
magic_rsl_puts(r, "text/plain");
return 1;
static int ncompr = sizeof(compr) / sizeof(compr[0]);
-static int zmagic(request_rec *r, unsigned char *buf, int nbytes)
+static int zmagic(request_rec *r, unsigned char *buf, apr_size_t nbytes)
{
unsigned char *newbuf;
int newsize;
int method;
};
-static int uncompress_child(struct uncompress_parms *parm, ap_context_t *cntxt,
- BUFF **script_in)
+static int uncompress_child(struct uncompress_parms *parm, apr_pool_t *cntxt,
+ apr_file_t **pipe_in)
{
int rc = 1;
- char *new_argv[4];
- char **env;
+ const char *new_argv[4];
+ const char *const *env;
request_rec *r = parm->r;
- ap_context_t *child_context = cntxt;
- ap_procattr_t *procattr;
- ap_proc_t *procnew = NULL;
- ap_os_proc_t fred;
- ap_file_t *file;
- ap_iol *iol;
+ apr_pool_t *child_context = cntxt;
+ apr_procattr_t *procattr;
+ apr_proc_t *procnew;
- ap_block_alarms();
+ env = (const char *const *)ap_create_environment(child_context, r->subprocess_env);
- env = ap_create_environment(child_context, r->subprocess_env);
-
- if ((ap_createprocattr_init(&procattr, child_context) != APR_SUCCESS) ||
- (ap_setprocattr_io(procattr, APR_FULL_BLOCK,
+ if ((apr_procattr_create(&procattr, child_context) != APR_SUCCESS) ||
+ (apr_procattr_io_set(procattr, APR_FULL_BLOCK,
APR_FULL_BLOCK, APR_NO_PIPE) != APR_SUCCESS) ||
- (ap_setprocattr_dir(procattr, r->filename) != APR_SUCCESS) ||
- (ap_setprocattr_cmdtype(procattr, APR_PROGRAM) != APR_SUCCESS)) {
+ (apr_procattr_dir_set(procattr, r->filename) != APR_SUCCESS) ||
+ (apr_procattr_cmdtype_set(procattr, APR_PROGRAM) != APR_SUCCESS)) {
/* Something bad happened, tell the world. */
ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_ENOPROC, r,
"couldn't setup child process: %s", r->filename);
close(STDERR_FILENO);
}
- rc = ap_create_process(&procnew, compr[parm->method].argv[0],
+ procnew = apr_pcalloc(child_context, sizeof(*procnew));
+ rc = apr_proc_create(procnew, compr[parm->method].argv[0],
new_argv, env, procattr, child_context);
if (rc != APR_SUCCESS) {
compr[parm->method].argv[0]);
}
else {
-#ifndef WIN32
- /* pjr - this is a cheap hack for now to get the basics working in
- * stages. ap_note_subprocess and free_proc need to be redon
-
- * to make use of ap_proc_t instead of pid.
- */
- ap_get_os_proc(&fred, procnew);
- ap_note_subprocess(child_context, fred, kill_after_timeout);
-#endif
- /* Fill in BUFF structure for parents pipe to child's stdout */
- ap_get_childout(&file, procnew);
- iol = ap_create_file_iol(file);
- if (!iol)
- return APR_EBADF;
- if (script_in) {
- *script_in = ap_bcreate(child_context, B_RD);
- }
- ap_bpush_iol(*script_in, iol);
+ apr_pool_note_subprocess(child_context, procnew, kill_after_timeout);
+ *pipe_in = procnew->out;
}
}
- ap_unblock_alarms();
return (rc);
}
static int uncompress(request_rec *r, int method,
- unsigned char **newch, int n)
+ unsigned char **newch, apr_size_t n)
{
struct uncompress_parms parm;
- BUFF *bout = NULL;
- ap_context_t *sub_context;
- ap_status_t rv;
+ apr_file_t *pipe_out = NULL;
+ apr_pool_t *sub_context;
+ apr_status_t rv;
parm.r = r;
parm.method = method;
* there are cases (i.e. generating directory indicies with mod_autoindex)
* where we would end up with LOTS of zombies.
*/
- if (ap_create_context(&sub_context, r->pool) != APR_SUCCESS)
+ if (apr_pool_create(&sub_context, r->pool) != APR_SUCCESS)
return -1;
- if ((rv = uncompress_child(&parm, sub_context, &bout)) != APR_SUCCESS) {
+ if ((rv = uncompress_child(&parm, sub_context, &pipe_out)) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
MODNAME ": couldn't spawn uncompress process: %s", r->uri);
return -1;
}
- *newch = (unsigned char *) ap_palloc(r->pool, n);
- rv = ap_bread(bout, *newch, n, &n);
+ *newch = (unsigned char *) apr_palloc(r->pool, n);
+ rv = apr_file_read(pipe_out, *newch, &n);
if (n == 0) {
- ap_destroy_context(sub_context);
+ apr_pool_destroy(sub_context);
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
MODNAME ": read failed %s", r->filename);
return -1;
}
- ap_destroy_context(sub_context);
+ apr_pool_destroy(sub_context);
return n;
}
* old UNIX tar file, 2 for Unix Std (POSIX) tar file.
*/
-static int is_tar(unsigned char *buf, int nbytes)
+static int is_tar(unsigned char *buf, apr_size_t nbytes)
{
register union record *header = (union record *) buf;
register int i;
{
register long value;
- while (ap_isspace(*where)) { /* Skip spaces */
+ while (apr_isspace(*where)) { /* Skip spaces */
where++;
if (--digs <= 0)
return -1; /* All blank field */
--digs;
}
- if (digs > 0 && *where && !ap_isspace(*where))
+ if (digs > 0 && *where && !apr_isspace(*where))
return -1; /* Ended on non-space/nul */
return value;
/* check for recognized revision suffix */
suffix_pos = strlen(r->filename) - 1;
- if (!ap_isdigit(r->filename[suffix_pos])) {
+ if (!apr_isdigit(r->filename[suffix_pos])) {
return 0;
}
- while (suffix_pos >= 0 && ap_isdigit(r->filename[suffix_pos]))
+ while (suffix_pos >= 0 && apr_isdigit(r->filename[suffix_pos]))
suffix_pos--;
if (suffix_pos < 0 || r->filename[suffix_pos] != '@') {
return 0;
/* perform sub-request for the file name without the suffix */
result = 0;
- sub_filename = ap_pstrndup(r->pool, r->filename, suffix_pos);
+ sub_filename = apr_pstrndup(r->pool, r->filename, suffix_pos);
#if MIME_MAGIC_DEBUG
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, r,
MODNAME ": subrequest lookup for %s", sub_filename);
#endif /* MIME_MAGIC_DEBUG */
- sub = ap_sub_req_lookup_file(sub_filename, r);
+ sub = ap_sub_req_lookup_file(sub_filename, r, NULL);
/* extract content type/encoding/language from sub-request */
if (sub->content_type) {
- r->content_type = ap_pstrdup(r->pool, sub->content_type);
+ r->content_type = apr_pstrdup(r->pool, sub->content_type);
#if MIME_MAGIC_DEBUG
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, r,
MODNAME ": subrequest %s got %s",
#endif /* MIME_MAGIC_DEBUG */
if (sub->content_encoding)
r->content_encoding =
- ap_pstrdup(r->pool, sub->content_encoding);
+ apr_pstrdup(r->pool, sub->content_encoding);
if (sub->content_language)
r->content_language =
- ap_pstrdup(r->pool, sub->content_language);
+ apr_pstrdup(r->pool, sub->content_language);
result = 1;
}
/*
* initialize the module
*/
-static void magic_init(ap_context_t *p, ap_context_t *plog, ap_context_t *ptemp, server_rec *main_server)
+static void magic_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_server)
{
int result;
magic_server_config_rec *conf;
ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, s,
MODNAME ": magic_init 1 test");
for (m = conf->magic; m; m = m->next) {
- if (ap_isprint((((unsigned long) m) >> 24) & 255) &&
- ap_isprint((((unsigned long) m) >> 16) & 255) &&
- ap_isprint((((unsigned long) m) >> 8) & 255) &&
- ap_isprint(((unsigned long) m) & 255)) {
+ if (apr_isprint((((unsigned long) m) >> 24) & 255) &&
+ apr_isprint((((unsigned long) m) >> 16) & 255) &&
+ apr_isprint((((unsigned long) m) >> 8) & 255) &&
+ apr_isprint(((unsigned long) m) & 255)) {
ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, s,
MODNAME ": magic_init 1: POINTER CLOBBERED! "
"m=\"%c%c%c%c\" line=%d",
magic_server_config_rec *conf;
/* the file has to exist */
- if (r->finfo.st_mode == 0 || !r->filename) {
+ if (r->finfo.filetype == 0 || !r->filename) {
return DECLINED;
}
return magic_rsl_to_request(r);
}
-static void register_hooks(void)
+static void register_hooks(apr_pool_t *p)
{
- ap_hook_type_checker(magic_find_ct, NULL, NULL, HOOK_MIDDLE);
- ap_hook_post_config(magic_init, NULL, NULL, HOOK_FIRST);
+ static const char * const aszPre[]={ "mod_mime.c", NULL };
+
+ /* mod_mime_magic should be run after mod_mime, if at all. */
+
+ ap_hook_type_checker(magic_find_ct, aszPre, NULL, APR_HOOK_MIDDLE);
+ ap_hook_post_config(magic_init, NULL, NULL, APR_HOOK_FIRST);
}
/*
NULL, /* dir merger --- default is to override */
create_magic_server_config, /* server config */
merge_magic_server_config, /* merge server config */
- mime_magic_cmds, /* command ap_table_t */
- NULL, /* handlers */
+ mime_magic_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};