static int ngx_libc_cdecl ngx_http_autoindex_cmp_entries(const void *one,
const void *two);
-static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r,
- ngx_dir_t *dir, ngx_str_t *name);
static ngx_int_t ngx_http_autoindex_init(ngx_conf_t *cf);
static void *ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf);
#endif
- /* TODO: pool should be temporary pool */
- pool = r->pool;
-
- if (ngx_array_init(&entries, pool, 40, sizeof(ngx_http_autoindex_entry_t))
- != NGX_OK)
- {
- return ngx_http_autoindex_error(r, &dir, &path);
- }
-
r->headers_out.status = NGX_HTTP_OK;
switch (format) {
return rc;
}
+ pool = ngx_create_pool(4096, r->connection->log);
+ if (pool == NULL) {
+ goto failed;
+ }
+
+ if (ngx_array_init(&entries, pool, 40, sizeof(ngx_http_autoindex_entry_t))
+ != NGX_OK)
+ {
+ goto failed;
+ }
+
filename = path.data;
filename[path.len] = '/';
if (err != NGX_ENOMOREFILES) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, err,
ngx_read_dir_n " \"%V\" failed", &path);
- return ngx_http_autoindex_error(r, &dir, &path);
+ goto failed;
}
break;
filename = ngx_pnalloc(pool, allocated);
if (filename == NULL) {
- return ngx_http_autoindex_error(r, &dir, &path);
+ goto failed;
}
last = ngx_cpystrn(filename, path.data, path.len + 1);
continue;
}
- return ngx_http_autoindex_error(r, &dir, &path);
+ goto failed;
}
if (ngx_de_link_info(filename, &dir) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
ngx_de_link_info_n " \"%s\" failed",
filename);
- return ngx_http_autoindex_error(r, &dir, &path);
+ goto failed;
}
}
}
entry = ngx_array_push(&entries);
if (entry == NULL) {
- return ngx_http_autoindex_error(r, &dir, &path);
+ goto failed;
}
entry->name.len = len;
entry->name.data = ngx_pnalloc(pool, len + 1);
if (entry->name.data == NULL) {
- return ngx_http_autoindex_error(r, &dir, &path);
+ goto failed;
}
ngx_cpystrn(entry->name.data, ngx_de_name(&dir), len + 1);
break;
}
+ ngx_destroy_pool(pool);
+
if (b == NULL) {
return NGX_ERROR;
}
- /* TODO: free temporary pool */
-
if (r == r->main) {
b->last_buf = 1;
}
out.next = NULL;
return ngx_http_output_filter(r, &out);
+
+failed:
+
+ if (pool != NULL) {
+ ngx_destroy_pool(pool);
+ }
+
+ if (ngx_close_dir(&dir) == NGX_ERROR) {
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
+ ngx_close_dir_n " \"%V\" failed", &path);
+ }
+
+ return NGX_ERROR;
}
#endif
-static ngx_int_t
-ngx_http_autoindex_error(ngx_http_request_t *r, ngx_dir_t *dir, ngx_str_t *name)
-{
- if (ngx_close_dir(dir) == NGX_ERROR) {
- ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
- ngx_close_dir_n " \"%V\" failed", name);
- }
-
- return r->header_sent ? NGX_ERROR : NGX_HTTP_INTERNAL_SERVER_ERROR;
-}
-
static void *
ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf)