comparison src/http/modules/ngx_http_index_handler.c @ 400:69e851f83522

nginx-0.0.8-2004-07-26-20:21:18 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 26 Jul 2004 16:21:18 +0000
parents 6f3b20c1ac50
children b32ca005e025
comparison
equal deleted inserted replaced
399:4e21d1291a14 400:69e851f83522
105 ngx_err_t err; 105 ngx_err_t err;
106 ngx_log_t *log; 106 ngx_log_t *log;
107 ngx_http_index_ctx_t *ctx; 107 ngx_http_index_ctx_t *ctx;
108 ngx_http_core_loc_conf_t *clcf; 108 ngx_http_core_loc_conf_t *clcf;
109 ngx_http_index_loc_conf_t *ilcf; 109 ngx_http_index_loc_conf_t *ilcf;
110 #if (NGX_HTTP_CACHE) 110 #if (NGX_HTTP_CACHE0)
111 /* crc must be in ctx !! */
111 uint32_t crc; 112 uint32_t crc;
112 #endif 113 #endif
113 114
114 if (r->uri.data[r->uri.len - 1] != '/') { 115 if (r->uri.data[r->uri.len - 1] != '/') {
115 return NGX_DECLINED; 116 return NGX_DECLINED;
172 ctx->redirect.data = ngx_cpymem(ctx->path.data, clcf->root.data, 173 ctx->redirect.data = ngx_cpymem(ctx->path.data, clcf->root.data,
173 clcf->root.len); 174 clcf->root.len);
174 #endif 175 #endif
175 176
176 if (clcf->alias) { 177 if (clcf->alias) {
177 if (clcf->root.len > clcf->name.len) { 178 ctx->path.data = ngx_palloc(r->pool, clcf->root.len
178 ctx->path.data = ngx_palloc(r->pool, clcf->root.len 179 + r->uri.len + 1 - clcf->name.len
179 + r->uri.len 180 + ilcf->max_index_len);
180 - clcf->name.len 181 if (ctx->path.data == NULL) {
181 + ilcf->max_index_len); 182 return NGX_HTTP_INTERNAL_SERVER_ERROR;
182 if (ctx->path.data == NULL) { 183 }
183 return NGX_HTTP_INTERNAL_SERVER_ERROR; 184
184 } 185 ctx->redirect.data = ngx_palloc(r->pool, r->uri.len
185 186 + ilcf->max_index_len);
186 ctx->redirect.data = ctx->path.data + clcf->root.len + 1 187 if (ctx->redirect.data == NULL) {
187 - clcf->name.len; 188 return NGX_HTTP_INTERNAL_SERVER_ERROR;
188
189 } else {
190 ctx->redirect.data = ngx_palloc(r->pool, r->uri.len
191 + ilcf->max_index_len);
192 if (ctx->redirect.data == NULL) {
193 return NGX_HTTP_INTERNAL_SERVER_ERROR;
194 }
195
196 ctx->path.data = ctx->redirect.data + clcf->name.len
197 - clcf->root.len;
198 } 189 }
199 190
200 ngx_memcpy(ctx->path.data, clcf->root.data, clcf->root.len); 191 ngx_memcpy(ctx->path.data, clcf->root.data, clcf->root.len);
201 192
202 ctx->last = ngx_cpystrn(ctx->path.data + clcf->root.len, 193 ctx->last = ngx_cpystrn(ctx->path.data + clcf->root.len,
203 r->uri.data + clcf->name.len, 194 r->uri.data + clcf->name.len,
204 r->uri.len + 1 - clcf->name.len); 195 r->uri.len + 1 - clcf->name.len);
205 196
197 #if 0
206 /* 198 /*
207 * aliases usually have trailling "/", 199 * aliases usually have trailling "/",
208 * set it in the start of the possible redirect 200 * set it in the start of the possible redirect
209 */ 201 */
210 202
211 if (*ctx->redirect.data != '/') { 203 if (*ctx->redirect.data != '/') {
212 ctx->redirect.data--; 204 ctx->redirect.data--;
213 } 205 }
206 #endif
214 207
215 } else { 208 } else {
216 ctx->path.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len 209 ctx->path.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len
217 + ilcf->max_index_len); 210 + ilcf->max_index_len);
218 if (ctx->path.data == NULL) { 211 if (ctx->path.data == NULL) {
239 ngx_memcpy(ctx->last, index[ctx->index].data, 232 ngx_memcpy(ctx->last, index[ctx->index].data,
240 index[ctx->index].len + 1); 233 index[ctx->index].len + 1);
241 name = ctx->path.data; 234 name = ctx->path.data;
242 } 235 }
243 236
237 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
238 "open index \"%s\"", name);
239
244 fd = ngx_open_file(name, NGX_FILE_RDONLY, NGX_FILE_OPEN); 240 fd = ngx_open_file(name, NGX_FILE_RDONLY, NGX_FILE_OPEN);
245 241
246 if (fd == (ngx_fd_t) NGX_AGAIN) { 242 if (fd == (ngx_fd_t) NGX_AGAIN) {
247 return NGX_AGAIN; 243 return NGX_AGAIN;
248 } 244 }
249 245
250 if (fd == NGX_INVALID_FILE) { 246 if (fd == NGX_INVALID_FILE) {
251 err = ngx_errno; 247 err = ngx_errno;
252 248
253 ngx_log_error(NGX_LOG_DEBUG, log, err, 249 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, err,
254 "debug: " ngx_open_file_n " %s failed", name); 250 ngx_open_file_n " %s failed", name);
255 251
256 if (err == NGX_ENOTDIR) { 252 if (err == NGX_ENOTDIR) {
257 return ngx_http_index_error(r, ctx, err); 253 return ngx_http_index_error(r, ctx, err);
258 254
259 } else if (err == NGX_EACCES) { 255 } else if (err == NGX_EACCES) {
291 ctx->redirect.len = index[ctx->index].len; 287 ctx->redirect.len = index[ctx->index].len;
292 ctx->redirect.data = index[ctx->index].data; 288 ctx->redirect.data = index[ctx->index].data;
293 289
294 } else { 290 } else {
295 if (clcf->alias) { 291 if (clcf->alias) {
296 ngx_memcpy(ctx->redirect.data, clcf->name.data, clcf->name.len); 292 name = ngx_cpymem(ctx->redirect.data, r->uri.data, r->uri.len);
297 } 293 ngx_memcpy(name, index[ctx->index].data,
298 294 index[ctx->index].len + 1);
299 ctx->redirect.len = r->uri.len + index[ctx->index].len 295 }
300 - clcf->alias * clcf->name.len; 296
297 ctx->redirect.len = r->uri.len + index[ctx->index].len;
301 r->file.name.len = clcf->root.len + r->uri.len 298 r->file.name.len = clcf->root.len + r->uri.len
302 - clcf->alias * clcf->name.len 299 - clcf->alias * clcf->name.len
303 + index[ctx->index].len; 300 + index[ctx->index].len;
304 } 301 }
305 302