*
*/
+#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_log.h"
#include "http_protocol.h"
#include "util_script.h"
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
+
+/* ### this isn't set by configure? does anybody set this? */
#ifdef HAVE_UTIME_H
#include <utime.h>
#endif
/*
* 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 *, 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);
{
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 (apr_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 = apr_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) apr_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
ap_get_module_config(s->module_config, &mime_magic_module);
const char *fname = ap_server_root_relative(p, conf->magicfile);
- result = apr_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; apr_fgets(line, BUFSIZ, f) == APR_SUCCESS; lineno++) {
+ for (lineno = 1; apr_file_gets(line, BUFSIZ, f) == APR_SUCCESS; lineno++) {
int ws_offset;
/* delete newline */
++errs;
}
- (void) apr_close(f);
+ (void) apr_file_close(f);
#if MIME_MAGIC_DEBUG
ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, s,
break;
default:
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0, r,
- MODNAME ": invalid mode 0%o.", (unsigned int)r->finfo.protection);
+ MODNAME ": invalid file type %d.", r->finfo.filetype);
return HTTP_INTERNAL_SERVER_ERROR;
}
* 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;
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;
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;
env = (const char *const *)ap_create_environment(child_context, r->subprocess_env);
- if ((apr_createprocattr_init(&procattr, child_context) != APR_SUCCESS) ||
- (apr_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) ||
- (apr_setprocattr_dir(procattr, r->filename) != APR_SUCCESS) ||
- (apr_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);
}
procnew = apr_pcalloc(child_context, sizeof(*procnew));
- rc = apr_create_process(procnew, compr[parm->method].argv[0],
+ 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 {
- apr_note_subprocess(child_context, procnew, kill_after_timeout);
+ apr_pool_note_subprocess(child_context, procnew, kill_after_timeout);
*pipe_in = procnew->out;
}
}
}
static int uncompress(request_rec *r, int method,
- unsigned char **newch, int n)
+ unsigned char **newch, apr_size_t n)
{
struct uncompress_parms parm;
apr_file_t *pipe_out = NULL;
* there are cases (i.e. generating directory indicies with mod_autoindex)
* where we would end up with LOTS of zombies.
*/
- if (apr_create_pool(&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, &pipe_out)) != APR_SUCCESS) {
}
*newch = (unsigned char *) apr_palloc(r->pool, n);
- rv = apr_read(pipe_out, *newch, &n);
+ rv = apr_file_read(pipe_out, *newch, &n);
if (n == 0) {
- apr_destroy_pool(sub_context);
+ apr_pool_destroy(sub_context);
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
MODNAME ": read failed %s", r->filename);
return -1;
}
- apr_destroy_pool(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;
magic_server_config_rec *conf;
/* the file has to exist */
- if (r->finfo.protection == 0 || !r->filename) {
+ if (r->finfo.filetype == 0 || !r->filename) {
return DECLINED;
}
/* mod_mime_magic should be run after mod_mime, if at all. */
- ap_hook_type_checker(magic_find_ct, aszPre, NULL, AP_HOOK_MIDDLE);
- ap_hook_post_config(magic_init, NULL, NULL, AP_HOOK_FIRST);
+ ap_hook_type_checker(magic_find_ct, aszPre, NULL, APR_HOOK_MIDDLE);
+ ap_hook_post_config(magic_init, NULL, NULL, APR_HOOK_FIRST);
}
/*