Mercurial > hg > nginx
comparison src/http/ngx_http_core_module.c @ 144:ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 12 Oct 2003 16:49:16 +0000 |
parents | 5526213be452 |
children | 5afee0074707 |
comparison
equal
deleted
inserted
replaced
143:5526213be452 | 144:ef8c87afcfc5 |
---|---|
6 #include <nginx.h> | 6 #include <nginx.h> |
7 | 7 |
8 | 8 |
9 /* STUB */ | 9 /* STUB */ |
10 int ngx_http_static_handler(ngx_http_request_t *r); | 10 int ngx_http_static_handler(ngx_http_request_t *r); |
11 /**/ | |
11 | 12 |
12 static void ngx_http_phase_event_handler(ngx_event_t *rev); | 13 static void ngx_http_phase_event_handler(ngx_event_t *rev); |
13 static void ngx_http_run_phases(ngx_http_request_t *r); | 14 static void ngx_http_run_phases(ngx_http_request_t *r); |
14 | |
15 static int ngx_http_core_index_handler(ngx_http_request_t *r); | |
16 | 15 |
17 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); | 16 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); |
18 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); | 17 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); |
19 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); | 18 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); |
20 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, | 19 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, |
219 | 218 |
220 /* TEST STUB */ r->lingering_close = 1; | 219 /* TEST STUB */ r->lingering_close = 1; |
221 | 220 |
222 r->connection->write->event_handler = ngx_http_phase_event_handler; | 221 r->connection->write->event_handler = ngx_http_phase_event_handler; |
223 | 222 |
224 r->phase = 0; | |
225 r->phase_handler = 0; | |
226 | |
227 ngx_http_run_phases(r); | 223 ngx_http_run_phases(r); |
228 | 224 |
229 return; | 225 return; |
230 } | 226 } |
231 | 227 |
235 ngx_connection_t *c; | 231 ngx_connection_t *c; |
236 ngx_http_request_t *r; | 232 ngx_http_request_t *r; |
237 | 233 |
238 c = ev->data; | 234 c = ev->data; |
239 r = c->data; | 235 r = c->data; |
236 | |
237 ngx_log_debug(ev->log, "phase event handler"); | |
240 | 238 |
241 ngx_http_run_phases(r); | 239 ngx_http_run_phases(r); |
242 | 240 |
243 return; | 241 return; |
244 } | 242 } |
260 for (r->phase_handler = cmcf->phases[r->phase].handlers.nelts - 1; | 258 for (r->phase_handler = cmcf->phases[r->phase].handlers.nelts - 1; |
261 r->phase_handler >= 0; | 259 r->phase_handler >= 0; |
262 r->phase_handler--) | 260 r->phase_handler--) |
263 { | 261 { |
264 rc = h[r->phase_handler](r); | 262 rc = h[r->phase_handler](r); |
263 | |
264 if (r->closed) { | |
265 return; | |
266 } | |
265 | 267 |
266 if (rc == NGX_DECLINED) { | 268 if (rc == NGX_DECLINED) { |
267 continue; | 269 continue; |
268 } | 270 } |
269 | 271 |
368 } | 370 } |
369 | 371 |
370 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 372 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
371 | 373 |
372 if (r->uri.data[r->uri.len - 1] == '/') { | 374 if (r->uri.data[r->uri.len - 1] == '/') { |
373 r->content_handler = ngx_http_core_index_handler; | 375 if (r->path.data == NULL) { |
374 return NGX_OK; | 376 ngx_test_null(r->path.data, |
377 ngx_palloc(r->pool, | |
378 clcf->doc_root.len + r->uri.len), | |
379 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
380 | |
381 ngx_cpystrn(ngx_cpymem(r->path.data, clcf->doc_root.data, | |
382 clcf->doc_root.len), | |
383 r->uri.data, r->uri.len + 1); | |
384 | |
385 } else { | |
386 r->path.data[r->path.len] = '\0'; | |
387 } | |
388 | |
389 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
390 "directory index of \"%s\" is forbidden", r->path.data); | |
391 | |
392 return NGX_HTTP_FORBIDDEN; | |
375 } | 393 } |
376 | 394 |
377 /* "+ 2" is for trailing '/' in redirect and '\0' */ | 395 /* "+ 2" is for trailing '/' in redirect and '\0' */ |
378 ngx_test_null(r->file.name.data, | 396 ngx_test_null(r->file.name.data, |
379 ngx_palloc(r->pool, clcf->doc_root.len + r->uri.len + 2), | 397 ngx_palloc(r->pool, clcf->doc_root.len + r->uri.len + 2), |
386 | 404 |
387 ngx_log_debug(r->connection->log, "HTTP filename: '%s'" _ r->file.name.data); | 405 ngx_log_debug(r->connection->log, "HTTP filename: '%s'" _ r->file.name.data); |
388 | 406 |
389 #if (WIN9X) | 407 #if (WIN9X) |
390 | 408 |
391 /* There is no way to open a file or a directory in Win9X with | 409 /* |
392 one syscall: Win9X has no FILE_FLAG_BACKUP_SEMANTICS flag. | 410 * There is no way to open a file or a directory in Win9X with |
393 so we need to check its type before the opening */ | 411 * one syscall: Win9X has no FILE_FLAG_BACKUP_SEMANTICS flag. |
412 * so we need to check its type before the opening | |
413 */ | |
394 | 414 |
395 r->file.info.dwFileAttributes = GetFileAttributes(r->file.name.data); | 415 r->file.info.dwFileAttributes = GetFileAttributes(r->file.name.data); |
396 if (r->file.info.dwFileAttributes == INVALID_FILE_ATTRIBUTES) { | 416 if (r->file.info.dwFileAttributes == INVALID_FILE_ATTRIBUTES) { |
397 err = ngx_errno; | 417 err = ngx_errno; |
398 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, | 418 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, |
486 | 506 |
487 return NGX_OK; | 507 return NGX_OK; |
488 } | 508 } |
489 | 509 |
490 | 510 |
491 static int ngx_http_core_index_handler(ngx_http_request_t *r) | |
492 { | |
493 int i, rc; | |
494 ngx_http_handler_pt *h; | |
495 ngx_http_core_main_conf_t *cmcf; | |
496 | |
497 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
498 | |
499 h = cmcf->index_handlers.elts; | |
500 for (i = cmcf->index_handlers.nelts; i > 0; /* void */) { | |
501 rc = h[--i](r); | |
502 | |
503 if (rc != NGX_DECLINED) { | |
504 | |
505 if (rc == NGX_HTTP_NOT_FOUND) { | |
506 ngx_log_error(NGX_LOG_ERR, r->connection->log, r->path_err, | |
507 "\"%s\" is not found", r->path.data); | |
508 } | |
509 | |
510 if (rc == NGX_HTTP_FORBIDDEN) { | |
511 ngx_log_error(NGX_LOG_ERR, r->connection->log, r->path_err, | |
512 "\"%s\" is forbidden", r->path.data); | |
513 } | |
514 | |
515 return rc; | |
516 } | |
517 } | |
518 | |
519 r->path.data[r->path.len] = '\0'; | |
520 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
521 "directory index of \"%s\" is forbidden", r->path.data); | |
522 | |
523 return NGX_HTTP_FORBIDDEN; | |
524 } | |
525 | |
526 | |
527 int ngx_http_send_header(ngx_http_request_t *r) | 511 int ngx_http_send_header(ngx_http_request_t *r) |
528 { | 512 { |
529 return (*ngx_http_top_header_filter)(r); | 513 return (*ngx_http_top_header_filter)(r); |
530 } | 514 } |
531 | 515 |
589 } else if (uri->data[i] == '/') { | 573 } else if (uri->data[i] == '/') { |
590 break; | 574 break; |
591 } | 575 } |
592 } | 576 } |
593 | 577 |
578 /* clear the modules contexts */ | |
579 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module); | |
580 | |
581 r->phase = 0; | |
582 r->phase_handler = 0; | |
583 | |
594 ngx_http_handler(r); | 584 ngx_http_handler(r); |
595 | 585 |
596 return NGX_OK; | 586 return NGX_OK; |
597 } | 587 } |
588 | |
589 | |
590 #if 1 /* STUB: test the delay http handler */ | |
591 | |
592 int ngx_http_delay_handler(ngx_http_request_t *r) | |
593 { | |
594 static int on; | |
595 | |
596 if (on++ == 0) { | |
597 ngx_log_debug(r->connection->log, "SET http delay"); | |
598 ngx_add_timer(r->connection->write, 10000); | |
599 return NGX_AGAIN; | |
600 } | |
601 | |
602 r->connection->write->timedout = 0; | |
603 ngx_log_debug(r->connection->log, "RESET http delay"); | |
604 return NGX_DECLINED; | |
605 } | |
606 | |
607 #endif | |
598 | 608 |
599 | 609 |
600 static int ngx_http_core_init(ngx_cycle_t *cycle) | 610 static int ngx_http_core_init(ngx_cycle_t *cycle) |
601 { | 611 { |
602 ngx_http_handler_pt *h; | 612 ngx_http_handler_pt *h; |
607 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; | 617 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; |
608 | 618 |
609 ngx_test_null(h, ngx_push_array( | 619 ngx_test_null(h, ngx_push_array( |
610 &cmcf->phases[NGX_HTTP_TRANSLATE_PHASE].handlers), | 620 &cmcf->phases[NGX_HTTP_TRANSLATE_PHASE].handlers), |
611 NGX_ERROR); | 621 NGX_ERROR); |
612 | |
613 *h = ngx_http_core_translate_handler; | 622 *h = ngx_http_core_translate_handler; |
623 | |
624 #if 0 | |
625 ngx_test_null(h, ngx_push_array( | |
626 &cmcf->phases[NGX_HTTP_TRANSLATE_PHASE].handlers), | |
627 NGX_ERROR); | |
628 *h = ngx_http_delay_handler; | |
629 #endif | |
614 | 630 |
615 return NGX_OK; | 631 return NGX_OK; |
616 } | 632 } |
617 | 633 |
618 | 634 |