]> granicus.if.org Git - apache/blobdiff - modules/generators/mod_autoindex.c
adjust remaining modules to use the new handler hook method (Alan Edwards)
[apache] / modules / generators / mod_autoindex.c
index 5f2060ce28e4fe40e7a674ab4b12710b5f5a079f..d4734ff93c1b2b275ef421624c089f433efbc5ad 100644 (file)
@@ -66,6 +66,7 @@
  *
  * Version sort added by Martin Pool <mbp@humbug.org.au>. */
 
+#include "apr_strings.h"
 #include "ap_config.h"
 #include "httpd.h"
 #include "http_config.h"
@@ -76,7 +77,7 @@
 #include "http_main.h"
 #include "util_script.h"
 #include "apr_fnmatch.h"
-#include "apr_strnatcmp.h"
+#include "apr_strings.h"
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
@@ -84,7 +85,7 @@
 #include <strings.h>
 #endif
 
-module MODULE_VAR_EXPORT autoindex_module;
+module AP_MODULE_DECLARE_DATA autoindex_module;
 
 /****************************************************************
  *
@@ -162,12 +163,12 @@ typedef struct autoindex_config_struct {
     int icon_height;
     char *default_order;
 
-    ap_array_header_t *icon_list;
-    ap_array_header_t *alt_list;
-    ap_array_header_t *desc_list;
-    ap_array_header_t *ign_list;
-    ap_array_header_t *hdr_list;
-    ap_array_header_t *rdme_list;
+    apr_array_header_t *icon_list;
+    apr_array_header_t *alt_list;
+    apr_array_header_t *desc_list;
+    apr_array_header_t *ign_list;
+    apr_array_header_t *hdr_list;
+    apr_array_header_t *rdme_list;
 
 } autoindex_config_rec;
 
@@ -182,7 +183,7 @@ static char c_by_encoding, c_by_type, c_by_path;
  * matches ".." or "../").  Hopefully this one call is significantly less
  * expensive than multiple strcmp() calls.
  */
-static ap_inline int is_parent(const char *name)
+static apr_inline int is_parent(const char *name)
 {
     /*
      * Now, IFF the first two bytes are dots, and the third byte is either
@@ -208,10 +209,10 @@ static void emit_preamble(request_rec *r, char *title)
              "</TITLE>\n </HEAD>\n <BODY>\n", NULL);
 }
 
-static void push_item(ap_array_header_t *arr, char *type, const char *to,
+static void push_item(apr_array_header_t *arr, char *type, const char *to,
                      const char *path, const char *data)
 {
-    struct item *p = (struct item *) ap_push_array(arr);
+    struct item *p = (struct item *) apr_push_array(arr);
 
     if (!to) {
        to = "";
@@ -221,14 +222,14 @@ static void push_item(ap_array_header_t *arr, char *type, const char *to,
     }
 
     p->type = type;
-    p->data = data ? ap_pstrdup(arr->cont, data) : NULL;
-    p->apply_path = ap_pstrcat(arr->cont, path, "*", NULL);
+    p->data = data ? apr_pstrdup(arr->cont, data) : NULL;
+    p->apply_path = apr_pstrcat(arr->cont, path, "*", NULL);
 
     if ((type == BY_PATH) && (!ap_is_matchexp(to))) {
-       p->apply_to = ap_pstrcat(arr->cont, "*", to, NULL);
+       p->apply_to = apr_pstrcat(arr->cont, "*", to, NULL);
     }
     else if (to) {
-       p->apply_to = ap_pstrdup(arr->cont, to);
+       p->apply_to = apr_pstrdup(arr->cont, to);
     }
     else {
        p->apply_to = NULL;
@@ -244,7 +245,7 @@ static const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
        }
     }
     if (cmd->info == BY_ENCODING) {
-        char *tmp = ap_pstrdup(cmd->pool, to);
+        char *tmp = apr_pstrdup(cmd->pool, to);
        ap_str_tolower(tmp);
        to = tmp;
     }
@@ -257,7 +258,7 @@ static const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
 static const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
                            const char *to)
 {
-    char *iconbak = ap_pstrdup(cmd->pool, icon);
+    char *iconbak = apr_pstrdup(cmd->pool, icon);
 
     if (icon[0] == '(') {
        char *alt;
@@ -276,7 +277,7 @@ static const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
        }
     }
     if (cmd->info == BY_ENCODING) {
-        char *tmp = ap_pstrdup(cmd->pool, to);
+        char *tmp = apr_pstrdup(cmd->pool, to);
        ap_str_tolower(tmp);
        to = tmp;
     }
@@ -315,20 +316,20 @@ static const char *add_desc(cmd_parms *cmd, void *d, const char *desc,
     ai_desc_t *desc_entry;
     char *prefix = "";
 
-    desc_entry = (ai_desc_t *) ap_push_array(dcfg->desc_list);
+    desc_entry = (ai_desc_t *) apr_push_array(dcfg->desc_list);
     desc_entry->full_path = (ap_strchr_c(to, '/') == NULL) ? 0 : 1;
     desc_entry->wildcards = (WILDCARDS_REQUIRED
                             || desc_entry->full_path
-                            || ap_is_fnmatch(to));
+                            || apr_is_fnmatch(to));
     if (desc_entry->wildcards) {
        prefix = desc_entry->full_path ? "*/" : "*";
-       desc_entry->pattern = ap_pstrcat(dcfg->desc_list->cont,
+       desc_entry->pattern = apr_pstrcat(dcfg->desc_list->cont,
                                         prefix, to, "*", NULL);
     }
     else {
-       desc_entry->pattern = ap_pstrdup(dcfg->desc_list->cont, to);
+       desc_entry->pattern = apr_pstrdup(dcfg->desc_list->cont, to);
     }
-    desc_entry->description = ap_pstrdup(dcfg->desc_list->cont, desc);
+    desc_entry->description = apr_pstrdup(dcfg->desc_list->cont, desc);
     return NULL;
 }
 
@@ -514,7 +515,7 @@ static const char *set_default_order(cmd_parms *cmd, void *m, const char *direct
     char temp[4];
     autoindex_config_rec *d_cfg = (autoindex_config_rec *) m;
 
-    ap_cpystrn(temp, "k=d", sizeof(temp));
+    apr_cpystrn(temp, "k=d", sizeof(temp));
     if (!strcasecmp(direction, "Ascending")) {
        temp[2] = D_ASCENDING;
     }
@@ -543,10 +544,10 @@ static const char *set_default_order(cmd_parms *cmd, void *m, const char *direct
     }
 
     if (d_cfg->default_order == NULL) {
-       d_cfg->default_order = ap_palloc(cmd->pool, 4);
+       d_cfg->default_order = apr_palloc(cmd->pool, 4);
        d_cfg->default_order[3] = '\0';
     }
-    ap_cpystrn(d_cfg->default_order, temp, sizeof(temp));
+    apr_cpystrn(d_cfg->default_order, temp, sizeof(temp));
     return NULL;
 }
 
@@ -586,21 +587,21 @@ static const command_rec autoindex_cmds[] =
     {NULL}
 };
 
-static void *create_autoindex_config(ap_pool_t *p, char *dummy)
+static void *create_autoindex_config(apr_pool_t *p, char *dummy)
 {
     autoindex_config_rec *new =
-    (autoindex_config_rec *) ap_pcalloc(p, sizeof(autoindex_config_rec));
+    (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
 
     new->icon_width = 0;
     new->icon_height = 0;
     new->name_width = DEFAULT_NAME_WIDTH;
     new->name_adjust = K_UNSET;
-    new->icon_list = ap_make_array(p, 4, sizeof(struct item));
-    new->alt_list = ap_make_array(p, 4, sizeof(struct item));
-    new->desc_list = ap_make_array(p, 4, sizeof(ai_desc_t));
-    new->ign_list = ap_make_array(p, 4, sizeof(struct item));
-    new->hdr_list = ap_make_array(p, 4, sizeof(struct item));
-    new->rdme_list = ap_make_array(p, 4, sizeof(struct item));
+    new->icon_list = apr_make_array(p, 4, sizeof(struct item));
+    new->alt_list = apr_make_array(p, 4, sizeof(struct item));
+    new->desc_list = apr_make_array(p, 4, sizeof(ai_desc_t));
+    new->ign_list = apr_make_array(p, 4, sizeof(struct item));
+    new->hdr_list = apr_make_array(p, 4, sizeof(struct item));
+    new->rdme_list = apr_make_array(p, 4, sizeof(struct item));
     new->opts = 0;
     new->incremented_opts = 0;
     new->decremented_opts = 0;
@@ -609,24 +610,24 @@ static void *create_autoindex_config(ap_pool_t *p, char *dummy)
     return (void *) new;
 }
 
-static void *merge_autoindex_configs(ap_pool_t *p, void *basev, void *addv)
+static void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv)
 {
     autoindex_config_rec *new;
     autoindex_config_rec *base = (autoindex_config_rec *) basev;
     autoindex_config_rec *add = (autoindex_config_rec *) addv;
 
-    new = (autoindex_config_rec *) ap_pcalloc(p, sizeof(autoindex_config_rec));
+    new = (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
     new->default_icon = add->default_icon ? add->default_icon
                                           : base->default_icon;
     new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
     new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
 
-    new->alt_list = ap_append_arrays(p, add->alt_list, base->alt_list);
-    new->ign_list = ap_append_arrays(p, add->ign_list, base->ign_list);
-    new->hdr_list = ap_append_arrays(p, add->hdr_list, base->hdr_list);
-    new->desc_list = ap_append_arrays(p, add->desc_list, base->desc_list);
-    new->icon_list = ap_append_arrays(p, add->icon_list, base->icon_list);
-    new->rdme_list = ap_append_arrays(p, add->rdme_list, base->rdme_list);
+    new->alt_list = apr_append_arrays(p, add->alt_list, base->alt_list);
+    new->ign_list = apr_append_arrays(p, add->ign_list, base->ign_list);
+    new->hdr_list = apr_append_arrays(p, add->hdr_list, base->hdr_list);
+    new->desc_list = apr_append_arrays(p, add->desc_list, base->desc_list);
+    new->icon_list = apr_append_arrays(p, add->icon_list, base->icon_list);
+    new->rdme_list = apr_append_arrays(p, add->rdme_list, base->rdme_list);
     if (add->opts & NO_OPTIONS) {
        /*
         * If the current directory says 'no options' then we also
@@ -701,13 +702,13 @@ struct ent {
     char *alt;
     char *desc;
     off_t size;
-    ap_time_t lm;
+    apr_time_t lm;
     struct ent *next;
     int ascending, version_sort;
     char key;
 };
 
-static char *find_item(request_rec *r, ap_array_header_t *list, int path_only)
+static char *find_item(request_rec *r, apr_array_header_t *list, int path_only)
 {
     const char *content_type = ap_field_noparam(r->pool, r->content_type);
     const char *content_encoding = r->content_encoding;
@@ -818,7 +819,7 @@ static char *find_desc(autoindex_config_rec *dcfg, request_rec *r)
         * wildcard checking if we must.
         */
        if (tuple->wildcards) {
-           found = (ap_fnmatch(tuple->pattern, filename, MATCH_FLAGS) == 0);
+           found = (apr_fnmatch(tuple->pattern, filename, MATCH_FLAGS) == 0);
        }
        else {
            found = (ap_strstr_c(filename, tuple->pattern) != NULL);
@@ -832,7 +833,7 @@ static char *find_desc(autoindex_config_rec *dcfg, request_rec *r)
 
 static int ignore_entry(autoindex_config_rec *d, char *path)
 {
-    ap_array_header_t *list = d->ign_list;
+    apr_array_header_t *list = d->ign_list;
     struct item *items = (struct item *) list->elts;
     char *tt;
     int i;
@@ -907,20 +908,20 @@ static int ignore_entry(autoindex_config_rec *d, char *path)
 /*
  * emit a plain text file
  */
-static void do_emit_plain(request_rec *r, ap_file_t *f)
+static void do_emit_plain(request_rec *r, apr_file_t *f)
 {
     char buf[IOBUFSIZE + 1];
     int i, c, ch;
-    ap_ssize_t n;
-    ap_status_t stat;
+    apr_size_t n;
+    apr_status_t stat;
 
     ap_rputs("<PRE>\n", r);
-    while (!ap_eof(f)) {
+    while (!apr_eof(f)) {
        do {
             n = sizeof(char) * IOBUFSIZE;
-           stat = ap_read(f, buf, &n);
+           stat = apr_read(f, buf, &n);
        }
-       while (stat != APR_SUCCESS && stat == EINTR);
+       while (stat != APR_SUCCESS && APR_STATUS_IS_EINTR(stat));
        if (n == -1 || n == 0) {
            break;
        }
@@ -962,7 +963,7 @@ static void do_emit_plain(request_rec *r, ap_file_t *f)
 static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
                      char *title)
 {
-    ap_file_t *f = NULL;
+    apr_file_t *f = NULL;
     request_rec *rr = NULL;
     int emit_amble = 1;
     int emit_H1 = 1;
@@ -973,7 +974,7 @@ static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
      * pretend there's nothing there.
      */
     if ((header_fname != NULL)
-       && (rr = ap_sub_req_lookup_uri(header_fname, r))
+       && (rr = ap_sub_req_lookup_uri(header_fname, r, NULL))
        && (rr->status == HTTP_OK)
        && (rr->filename != NULL)
        && rr->finfo.filetype == APR_REG) {
@@ -1010,12 +1011,12 @@ static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
                 * the file's contents, any HTML header it had won't end up
                 * where it belongs.
                 */
-               if (ap_open(&f, rr->filename, APR_READ,
+               if (apr_open(&f, rr->filename, APR_READ,
                             APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
                    emit_preamble(r, title);
                    emit_amble = 0;
                    do_emit_plain(r, f);
-                   ap_close(f);
+                   apr_close(f);
                    emit_H1 = 0;
                }
            }
@@ -1045,7 +1046,7 @@ static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
  */
 static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
 {
-    ap_file_t *f = NULL;
+    apr_file_t *f = NULL;
     request_rec *rr = NULL;
     int suppress_post = 0;
     int suppress_sig = 0;
@@ -1056,7 +1057,7 @@ static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
      * pretend there's nothing there.
      */
     if ((readme_fname != NULL)
-       && (rr = ap_sub_req_lookup_uri(readme_fname, r))
+       && (rr = ap_sub_req_lookup_uri(readme_fname, r, NULL))
        && (rr->status == HTTP_OK)
        && (rr->filename != NULL)
        && rr->finfo.filetype == APR_REG) {
@@ -1078,10 +1079,10 @@ static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
                /*
                 * If we can open the file, suppress the signature.
                 */
-               if (ap_open(&f, rr->filename, APR_READ,
+               if (apr_open(&f, rr->filename, APR_READ,
                             APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
                    do_emit_plain(r, f);
-                   ap_close(f);
+                   apr_close(f);
                    suppress_sig = 1;
                }
            }
@@ -1103,9 +1104,9 @@ static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
 static char *find_title(request_rec *r)
 {
     char titlebuf[MAX_STRING_LEN], *find = "<TITLE>";
-    ap_file_t *thefile = NULL;
+    apr_file_t *thefile = NULL;
     int x, y, p;
-    ap_ssize_t n;
+    apr_size_t n;
 
     if (r->status != HTTP_OK) {
        return NULL;
@@ -1115,19 +1116,19 @@ static char *find_title(request_rec *r)
                        "text/html")
            || !strcmp(r->content_type, INCLUDES_MAGIC_TYPE))
        && !r->content_encoding) {
-        if (ap_open(&thefile, r->filename, APR_READ,
+        if (apr_open(&thefile, r->filename, APR_READ,
                     APR_OS_DEFAULT, r->pool) != APR_SUCCESS) {
            return NULL;
        }
         n = sizeof(char) * (MAX_STRING_LEN - 1);
-       ap_read(thefile, titlebuf, &n);
+       apr_read(thefile, titlebuf, &n);
        if (n <= 0) {
-           ap_close(thefile);
+           apr_close(thefile);
            return NULL;
        }
        titlebuf[n] = '\0';
        for (x = 0, p = 0; titlebuf[x]; x++) {
-           if (ap_toupper(titlebuf[x]) == find[p]) {
+           if (apr_toupper(titlebuf[x]) == find[p]) {
                if (!find[++p]) {
                    if ((p = ap_ind(&titlebuf[++x], '<')) != -1) {
                        titlebuf[x + p] = '\0';
@@ -1143,20 +1144,20 @@ static char *find_title(request_rec *r)
                            }
                        }
                    }
-                   ap_close(thefile);
-                   return ap_pstrdup(r->pool, &titlebuf[x]);
+                   apr_close(thefile);
+                   return apr_pstrdup(r->pool, &titlebuf[x]);
                }
            }
            else {
                p = 0;
            }
        }
-       ap_close(thefile);
+       apr_close(thefile);
     }
     return NULL;
 }
 
-static struct ent *make_autoindex_entry(char *name, int autoindex_opts,
+static struct ent *make_autoindex_entry(const char *name, int autoindex_opts,
                                        autoindex_config_rec *d,
                                        request_rec *r, char keyid,
                                        char direction)
@@ -1171,19 +1172,19 @@ static struct ent *make_autoindex_entry(char *name, int autoindex_opts,
         return (NULL);
     }
 
-    p = (struct ent *) ap_pcalloc(r->pool, sizeof(struct ent));
-    p->name = ap_pstrdup(r->pool, name);
+    p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
+    p->name = apr_pstrdup(r->pool, name);
     p->size = -1;
     p->icon = NULL;
     p->alt = NULL;
     p->desc = NULL;
     p->lm = -1;
-    p->key = ap_toupper(keyid);
-    p->ascending = (ap_toupper(direction) == D_ASCENDING);
+    p->key = apr_toupper(keyid);
+    p->ascending = (apr_toupper(direction) == D_ASCENDING);
     p->version_sort = autoindex_opts & VERSION_SORT;
 
     if (autoindex_opts & FANCY_INDEXING) {
-        request_rec *rr = ap_sub_req_lookup_file(name, r);
+        request_rec *rr = ap_sub_req_lookup_file(name, r, NULL);
 
        if (rr->finfo.protection != 0) {
            p->lm = rr->finfo.mtime;
@@ -1195,7 +1196,7 @@ static struct ent *make_autoindex_entry(char *name, int autoindex_opts,
                    p->alt = "DIR";
                }
                p->size = -1;
-               p->name = ap_pstrcat(r->pool, name, "/", NULL);
+               p->name = apr_pstrcat(r->pool, name, "/", NULL);
            }
            else {
                p->icon = find_icon(d, rr, 0);
@@ -1207,7 +1208,7 @@ static struct ent *make_autoindex_entry(char *name, int autoindex_opts,
        p->desc = find_desc(d, rr);
 
        if ((!p->desc) && (autoindex_opts & SCAN_HTML_TITLES)) {
-           p->desc = ap_pstrdup(r->pool, find_title(rr));
+           p->desc = apr_pstrdup(r->pool, find_title(rr));
        }
 
        ap_destroy_sub_req(rr);
@@ -1298,16 +1299,16 @@ static void output_directories(struct ent **ar, int n,
                               int autoindex_opts, char keyid, char direction)
 {
     int x;
-    ap_size_t rv;
+    apr_size_t rv;
     char *name = r->uri;
     char *tp;
     int static_columns = (autoindex_opts & SUPPRESS_COLSORT);
-    ap_pool_t *scratch;
+    apr_pool_t *scratch;
     int name_width;
     char *name_scratch;
     char *pad_scratch;
 
-    ap_create_pool(&scratch, r->pool);
+    apr_create_pool(&scratch, r->pool);
     if (name[0] == '\0') {
        name = "/";
     }
@@ -1321,8 +1322,8 @@ static void output_directories(struct ent **ar, int n,
            }
        }
     }
-    name_scratch = ap_palloc(r->pool, name_width + 1);
-    pad_scratch = ap_palloc(r->pool, name_width + 1);
+    name_scratch = apr_palloc(r->pool, name_width + 1);
+    pad_scratch = apr_palloc(r->pool, name_width + 1);
     memset(pad_scratch, ' ', name_width);
     pad_scratch[name_width] = '\0';
 
@@ -1371,7 +1372,7 @@ static void output_directories(struct ent **ar, int n,
        char *anchor, *t, *t2;
        int nwidth;
 
-       ap_clear_pool(scratch);
+       apr_clear_pool(scratch);
 
        if (is_parent(ar[x]->name)) {
            t = ap_make_full_path(scratch, name, "../");
@@ -1429,9 +1430,9 @@ static void output_directories(struct ent **ar, int n,
            if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
                if (ar[x]->lm != -1) {
                    char time_str[MAX_STRING_LEN];
-                   ap_exploded_time_t ts;
-                    ap_explode_localtime(&ts, ar[x]->lm);
-                   ap_strftime(time_str, &rv, MAX_STRING_LEN, 
+                   apr_exploded_time_t ts;
+                    apr_explode_localtime(&ts, ar[x]->lm);
+                   apr_strftime(time_str, &rv, MAX_STRING_LEN, 
                                 "%d-%b-%Y %H:%M  ", &ts);
                    ap_rputs(time_str, r);
                }
@@ -1518,7 +1519,7 @@ static int dsortf(struct ent **e1, struct ent **e2)
         break;
     case K_DESC:
        if (c1->version_sort)
-           result = ap_strnatcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : "");
+           result = apr_strnatcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : "");
        else
            result = strcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : "");
         if (result) {
@@ -1527,7 +1528,7 @@ static int dsortf(struct ent **e1, struct ent **e2)
         break;
     }
     if (c1->version_sort)
-       return ap_strnatcmp(c1->name, c2->name);
+       return apr_strnatcmp(c1->name, c2->name);
     else
        return strcmp(c1->name, c2->name);
 }
@@ -1540,8 +1541,8 @@ static int index_directory(request_rec *r,
     char *title_endp;
     char *name = r->filename;
 
-    ap_dir_t *d;
-    ap_status_t status;
+    apr_dir_t *d;
+    apr_status_t status;
     int num_ent = 0, x;
     struct ent *head, *p;
     struct ent **ar = NULL;
@@ -1550,18 +1551,25 @@ static int index_directory(request_rec *r,
     char keyid;
     char direction;
 
-    if ((status = ap_opendir(&d, name, r->pool)) != APR_SUCCESS) {
+    if ((status = apr_dir_open(&d, name, r->pool)) != APR_SUCCESS) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
                    "Can't open directory for index: %s", r->filename);
        return HTTP_FORBIDDEN;
     }
 
+#if APR_HAS_UNICODE_FS 
+    r->content_type = "text/html;charset=utf-8";
+#else
     r->content_type = "text/html";
+#endif
+    ap_update_mtime(r, r->finfo.mtime);
+    ap_set_last_modified(r);
+    ap_set_etag(r);
 
     ap_send_http_header(r);
 
     if (r->header_only) {
-       ap_closedir(d);
+       apr_closedir(d);
        return 0;
     }
 
@@ -1613,9 +1621,9 @@ static int index_directory(request_rec *r,
      * linked list and then arrayificate them so qsort can use them. 
      */
     head = NULL;
-    while (ap_readdir(d) == APR_SUCCESS) {
-        char *d_name;
-        ap_get_dir_filename(&d_name, d);
+    while (apr_readdir(d) == APR_SUCCESS) {
+        const char *d_name;
+        apr_get_dir_filename(&d_name, d);
        p = make_autoindex_entry(d_name, autoindex_opts,
                                 autoindex_conf, r, keyid, direction);
        if (p != NULL) {
@@ -1625,7 +1633,7 @@ static int index_directory(request_rec *r,
        }
     }
     if (num_ent > 0) {
-       ar = (struct ent **) ap_palloc(r->pool,
+       ar = (struct ent **) apr_palloc(r->pool,
                                       num_ent * sizeof(struct ent *));
        p = head;
        x = 0;
@@ -1639,7 +1647,7 @@ static int index_directory(request_rec *r,
     }
     output_directories(ar, num_ent, autoindex_conf, r, autoindex_opts, keyid,
                       direction);
-    ap_closedir(d);
+    apr_closedir(d);
 
     if (autoindex_opts & FANCY_INDEXING) {
        ap_rputs("<HR>\n", r);
@@ -1655,7 +1663,12 @@ static int index_directory(request_rec *r,
 static int handle_autoindex(request_rec *r)
 {
     autoindex_config_rec *d;
-    int allow_opts = ap_allow_options(r);
+    int allow_opts;
+
+    if(strcmp(r->handler,DIR_MAGIC_TYPE))
+       return DECLINED;
+
+    allow_opts = ap_allow_options(r);
 
     d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config,
                                                      &autoindex_module);
@@ -1674,7 +1687,7 @@ static int handle_autoindex(request_rec *r)
         */
 
        if (r->filename[strlen(r->filename) - 1] != '/') {
-           r->filename = ap_pstrcat(r->pool, r->filename, "/", NULL);
+           r->filename = apr_pstrcat(r->pool, r->filename, "/", NULL);
        }
        return index_directory(r, d);
     }
@@ -1685,21 +1698,18 @@ static int handle_autoindex(request_rec *r)
     }
 }
 
-
-static const handler_rec autoindex_handlers[] =
+static void register_hooks(void)
 {
-    {DIR_MAGIC_TYPE, handle_autoindex},
-    {NULL}
-};
+    ap_hook_handler(handle_autoindex,NULL,NULL,AP_HOOK_MIDDLE);
+}
 
-module MODULE_VAR_EXPORT autoindex_module =
+module AP_MODULE_DECLARE_DATA autoindex_module =
 {
     STANDARD20_MODULE_STUFF,
     create_autoindex_config,   /* dir config creater */
     merge_autoindex_configs,   /* dir merger --- default is to override */
     NULL,                      /* server config */
     NULL,                      /* merge server config */
-    autoindex_cmds,            /* command ap_table_t */
-    autoindex_handlers,                /* handlers */
-    NULL                       /* register hooks */
+    autoindex_cmds,            /* command apr_table_t */
+    register_hooks             /* register hooks */
 };