Mercurial > hg > nginx
comparison src/http/modules/ngx_http_index_handler.c @ 0:4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
The first code that uses "ngx_" prefix, the previous one used "gx_" prefix.
At that point the code is not yet usable. The first draft ideas are dated
back to 23.10.2001.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 06 Aug 2002 16:39:45 +0000 |
parents | |
children | d220029ac7f3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4eff17414a43 |
---|---|
1 | |
2 #include <ngx_config.h> | |
3 | |
4 #include <ngx_strings.h> | |
5 #include <ngx_open.h> | |
6 #include <ngx_stat.h> | |
7 | |
8 #include <ngx_http.h> | |
9 | |
10 int ngx_http_index_handler(ngx_http_request_t *r) | |
11 { | |
12 int index_len, err, i; | |
13 char *name, *loc, *file | |
14 ngx_file_t fd; | |
15 | |
16 ngx_http_index_t *index; | |
17 ngx_http_index_handler_loc_conf_t *cf; | |
18 | |
19 cf = (ngx_http_index_handler_loc_conf_t *) | |
20 ngx_get_module_loc_conf(r, &ngx_http_index_handler_module); | |
21 | |
22 index_len = (*(r->uri_end - 1) == '/') ? cf->max_index_len : 0; | |
23 name = ngx_palloc(r->pool, r->uri_end - r->uri_start + index_len | |
24 + r->server->doc_root_len); | |
25 if (name == NULL) | |
26 return NGX_ERROR; | |
27 | |
28 loc = ngx_cpystrn(name, r->server->doc_root, r->server->doc_root_len); | |
29 file = ngx_cpystrn(loc, r->uri_start, r->uri_end - r->uri_start + 1); | |
30 | |
31 /* URI without / on the end - check directory */ | |
32 if (index_len == 0) { | |
33 | |
34 if (ngx_stat(name, &r->stat) == -1) { | |
35 err = ngx_errno; | |
36 ngx_log_error(GX_LOG_ERR, r->connection->log, err, | |
37 "ngx_http_handler: " ngx_stat_n " %s failed", name); | |
38 | |
39 if (err == NGX_ENOENT) | |
40 return NGX_HTTP_NOT_FOUND; | |
41 else | |
42 return NGX_ERROR; | |
43 } | |
44 | |
45 if (ngx_is_dir(r->stat)) { | |
46 *file++ = '/'; | |
47 *file = '\0'; | |
48 r->headers_out->location = loc; | |
49 return NGX_HTTP_MOVED_PERMANENTLY; | |
50 } | |
51 | |
52 r->file = name; | |
53 r->stat_valid = 1; | |
54 | |
55 return NGX_OK; | |
56 } | |
57 | |
58 /* look for index file */ | |
59 index = (ngx_http_index_t *) cf->indices->elts; | |
60 for (i = 0; i < cf->indices->nelts; i++) { | |
61 ngx_memcpy(file, index[i].name; index[i].len); | |
62 | |
63 fd = ngx_open(name, O_RDONLY); | |
64 if (fd != -1) { | |
65 r->file = name; | |
66 r->fd = fd; | |
67 return NGX_OK; | |
68 } | |
69 } | |
70 | |
71 return NGX_HTTP_FORBIDDEN; | |
72 } | |
73 | |
74 /* | |
75 | |
76 static void *ngx_create_index_config() | |
77 { | |
78 ngx_http_index_handler_loc_conf_t *cf; | |
79 | |
80 ngx_check_null(cf, ngx_alloc(p, sizeof(ngx_http_index_handler_loc_conf)), | |
81 NULL); | |
82 | |
83 cf->indices = ngx_create_array(p, sizeof(ngx_http_index_t), 5); | |
84 if (cf->indices == NULL) | |
85 return NULL; | |
86 | |
87 cf->max_index_len = 0; | |
88 | |
89 return cf; | |
90 } | |
91 | |
92 static void *ngx_merge_index_config() | |
93 { | |
94 if (p->indices->nelts > 0) { | |
95 | |
96 copy and check dups | |
97 | |
98 if (c->max_index_len < c->max_index_len) | |
99 c->max_index_len < c->max_index_len); | |
100 } | |
101 } | |
102 | |
103 static void *ngx_set_index() | |
104 { | |
105 if (*conf == NULL) { | |
106 cf = ngx_create_index_conf(); | |
107 if (cf == NULL) | |
108 return "can not create config"; | |
109 } | |
110 | |
111 while (args) { | |
112 index = ngx_push_array(cf->indices); | |
113 index->name = arg; | |
114 index->len = ngx_strlen(arg) + 1; | |
115 | |
116 if (cf->max_index_len < index->len) | |
117 cf->max_index_len = index->len; | |
118 } | |
119 | |
120 *conf = cf; | |
121 } | |
122 | |
123 */ |