]> granicus.if.org Git - apache/blobdiff - modules/metadata/mod_mime_magic.c
*) continued header revamping
[apache] / modules / metadata / mod_mime_magic.c
index 6294a000353e491d26fef1dcfa682ce0063e45d7..67eb4409e2fdfbc8a7bbc0a8e73113640493b931 100644 (file)
  *
  */
 
+#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
@@ -246,25 +251,25 @@ union record {
 /*
  * 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);
 
@@ -856,7 +861,7 @@ static int magic_process(request_rec *r)
 {
     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;
 
     /*
@@ -873,7 +878,7 @@ static int magic_process(request_rec *r)
        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);
@@ -885,7 +890,7 @@ static int magic_process(request_rec *r)
      * 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;
@@ -898,14 +903,14 @@ static int magic_process(request_rec *r)
        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
@@ -954,7 +959,7 @@ static int apprentice(server_rec *s, apr_pool_t *p)
                    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);
@@ -965,7 +970,7 @@ static int apprentice(server_rec *s, apr_pool_t *p)
     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 */
@@ -998,7 +1003,7 @@ static int apprentice(server_rec *s, apr_pool_t *p)
            ++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,
@@ -1493,7 +1498,7 @@ static int fsmagic(request_rec *r, const char *fn)
        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;
     }
 
@@ -1512,7 +1517,7 @@ static int fsmagic(request_rec *r, const char *fn)
  * 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;
@@ -1546,7 +1551,7 @@ static int softmagic(request_rec *r, unsigned char *buf, int nbytes)
  * 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;
@@ -1803,7 +1808,7 @@ static int mconvert(request_rec *r, union VALUETYPE *p, struct magic *m)
 
 
 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;
 
@@ -1989,7 +1994,7 @@ static int mcheck(request_rec *r, union VALUETYPE *p, struct magic *m)
 /* 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;
@@ -2108,7 +2113,7 @@ static struct {
 
 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;
@@ -2152,11 +2157,11 @@ static int uncompress_child(struct uncompress_parms *parm, apr_pool_t *cntxt,
 
     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);
@@ -2172,7 +2177,7 @@ static int uncompress_child(struct uncompress_parms *parm, apr_pool_t *cntxt,
         }
 
         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) {
@@ -2182,7 +2187,7 @@ static int uncompress_child(struct uncompress_parms *parm, apr_pool_t *cntxt,
                           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;
         }
     }
@@ -2191,7 +2196,7 @@ static int uncompress_child(struct uncompress_parms *parm, apr_pool_t *cntxt,
 }
 
 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;
@@ -2205,7 +2210,7 @@ static int uncompress(request_rec *r, int method,
      * 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) {
@@ -2215,14 +2220,14 @@ static int uncompress(request_rec *r, int method,
     }
 
     *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;
 }
 
@@ -2246,7 +2251,7 @@ static int uncompress(request_rec *r, int method,
  * 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;
@@ -2432,7 +2437,7 @@ static int magic_find_ct(request_rec *r)
     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;
     }
 
@@ -2469,8 +2474,8 @@ static void register_hooks(apr_pool_t *p)
 
     /* 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);
 }
 
 /*