diff src/http/modules/ngx_http_index_handler.c @ 44:0e81ac0bb3e2

nginx-0.0.1-2003-01-09-08:36:00 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 09 Jan 2003 05:36:00 +0000
parents 53cd05892261
children f1ee46c036a4
line wrap: on
line diff
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -9,11 +9,12 @@
 
 #include <ngx_http.h>
 #include <ngx_http_config.h>
+#include <ngx_http_core_module.h>
 #include <ngx_http_index_handler.h>
 
 
 static void *ngx_http_index_create_conf(ngx_pool_t *pool);
-static void *ngx_http_index_merge_conf(ngx_pool_t *p,
+static char *ngx_http_index_merge_conf(ngx_pool_t *p,
                                        void *parent, void *child);
 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
                                       char *conf);
@@ -50,6 +51,7 @@ ngx_http_module_t  ngx_http_index_module
 
 
 ngx_module_t  ngx_http_index_module = {
+    0,                                     /* module index */
     &ngx_http_index_module_ctx,            /* module context */
     ngx_http_index_commands,               /* module directives */
     NGX_HTTP_MODULE_TYPE,                  /* module type */
@@ -65,18 +67,23 @@ int ngx_http_index_handler(ngx_http_requ
     ngx_err_t    err;
     ngx_fd_t     fd;
 
-    ngx_http_index_conf_t  *cf;
+    ngx_http_index_conf_t     *cf;
+    ngx_http_core_loc_conf_t  *core_cf;
 
     cf = (ngx_http_index_conf_t *)
                    ngx_http_get_module_loc_conf(r, ngx_http_index_module_ctx);
 
+    core_cf = (ngx_http_core_loc_conf_t *)
+                    ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx);
+
     ngx_test_null(name,
                   ngx_palloc(r->pool,
-                             r->server->doc_root_len + r->uri.len
+                             core_cf->doc_root.len + r->uri.len
                              + cf->max_index_len),
                   NGX_HTTP_INTERNAL_SERVER_ERROR);
 
-    loc.data = ngx_cpystrn(name, r->server->doc_root, r->server->doc_root_len);
+    loc.data = ngx_cpystrn(name, core_cf->doc_root.data,
+                           core_cf->doc_root.len + 1);
     file = ngx_cpystrn(loc.data, r->uri.data, r->uri.len + 1);
 
     index = (ngx_str_t *) cf->indices->elts;
@@ -101,7 +108,7 @@ int ngx_http_index_handler(ngx_http_requ
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
         }
 
-        r->file.name.len = r->server->doc_root_len + r->uri.len + index[i].len;
+        r->file.name.len = core_cf->doc_root.len + r->uri.len + index[i].len;
         r->file.name.data = name; 
         r->file.fd = fd; 
 
@@ -117,17 +124,34 @@ static void *ngx_http_index_create_conf(
 {
     ngx_http_index_conf_t  *conf;
 
-    ngx_test_null(conf, ngx_pcalloc(pool, sizeof(ngx_http_index_conf_t)), NULL);
+    ngx_test_null(conf, ngx_pcalloc(pool, sizeof(ngx_http_index_conf_t)),
+                  NGX_CONF_ERROR);
 
     ngx_test_null(conf->indices,
                   ngx_create_array(pool, sizeof(ngx_str_t), 3),
-                  NULL);
+                  NGX_CONF_ERROR);
 
     return conf;
 }
 
 
-static void *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child)
+static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child)
+{
+    ngx_http_index_conf_t *prev = (ngx_http_index_conf_t *) parent;
+    ngx_http_index_conf_t *conf = (ngx_http_index_conf_t *) child;
+    ngx_str_t  *index;
+
+    ngx_test_null(index, ngx_push_array(conf->indices), NGX_CONF_ERROR);
+    index->len = sizeof(NGX_HTTP_INDEX) - 1;
+    index->data = NGX_HTTP_INDEX;
+    conf->max_index_len = sizeof(NGX_HTTP_INDEX);
+
+    return NULL;
+}
+
+
+#if 0
+static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child)
 {
     ngx_http_index_conf_t *prev = (ngx_http_index_conf_t *) parent;
     ngx_http_index_conf_t *conf = (ngx_http_index_conf_t *) child;
@@ -146,7 +170,7 @@ static void *ngx_http_index_merge_conf(n
 
     return conf;
 }
-
+#endif
 
 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
                                       char *conf)