Mercurial > hg > nginx
comparison src/http/ngx_http_core_module.c @ 119:cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 20 Jul 2003 21:15:59 +0000 |
parents | 5bf52498665c |
children | 5526213be452 |
comparison
equal
deleted
inserted
replaced
118:5bf52498665c | 119:cd54bcbaf3b5 |
---|---|
9 int ngx_http_static_handler(ngx_http_request_t *r); | 9 int ngx_http_static_handler(ngx_http_request_t *r); |
10 | 10 |
11 | 11 |
12 static int ngx_http_core_index_handler(ngx_http_request_t *r); | 12 static int ngx_http_core_index_handler(ngx_http_request_t *r); |
13 | 13 |
14 static void *ngx_http_core_create_main_conf(ngx_pool_t *pool); | 14 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); |
15 static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf); | 15 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); |
16 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool); | 16 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); |
17 static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool, | 17 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, |
18 void *parent, void *child); | 18 void *parent, void *child); |
19 static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool); | 19 static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf); |
20 static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool, | 20 static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, |
21 void *parent, void *child); | 21 void *parent, void *child); |
22 | 22 |
23 static int ngx_http_core_init(ngx_cycle_t *cycle); | 23 static int ngx_http_core_init(ngx_cycle_t *cycle); |
24 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); | 24 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); |
25 static int ngx_cmp_locations(const void *first, const void *second); | 25 static int ngx_cmp_locations(const void *first, const void *second); |
26 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, | 26 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, |
27 void *dummy); | 27 void *dummy); |
28 static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 28 static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
29 static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); | 29 static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); |
30 static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 30 static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
31 static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, | 31 static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, |
32 void *conf); | 32 void *conf); |
33 static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | |
33 | 34 |
34 | 35 |
35 static ngx_command_t ngx_http_core_commands[] = { | 36 static ngx_command_t ngx_http_core_commands[] = { |
36 | 37 |
37 {ngx_string("server"), | 38 {ngx_string("server"), |
163 ngx_conf_set_msec_slot, | 164 ngx_conf_set_msec_slot, |
164 NGX_HTTP_LOC_CONF_OFFSET, | 165 NGX_HTTP_LOC_CONF_OFFSET, |
165 offsetof(ngx_http_core_loc_conf_t, lingering_timeout), | 166 offsetof(ngx_http_core_loc_conf_t, lingering_timeout), |
166 NULL}, | 167 NULL}, |
167 | 168 |
169 {ngx_string("error_log"), | |
170 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
171 ngx_set_error_log, | |
172 NGX_HTTP_LOC_CONF_OFFSET, | |
173 0, | |
174 NULL}, | |
175 | |
168 ngx_null_command | 176 ngx_null_command |
169 }; | 177 }; |
170 | 178 |
171 | 179 |
172 ngx_http_module_t ngx_http_core_module_ctx = { | 180 ngx_http_module_t ngx_http_core_module_ctx = { |
224 clcfp = cscf->locations.elts; | 232 clcfp = cscf->locations.elts; |
225 for (i = 0; i < cscf->locations.nelts; i++) { | 233 for (i = 0; i < cscf->locations.nelts; i++) { |
226 #if 0 | 234 #if 0 |
227 ngx_log_debug(r->connection->log, "trans: %s" _ clcfp[i]->name.data); | 235 ngx_log_debug(r->connection->log, "trans: %s" _ clcfp[i]->name.data); |
228 #endif | 236 #endif |
229 if (r->uri.len < clcfp[i]->name.len) { | 237 if (r->uri.len < clcfp[i]->name.len) { |
230 continue; | 238 continue; |
231 } | 239 } |
232 | 240 |
233 rc = ngx_strncmp(r->uri.data, clcfp[i]->name.data, | 241 rc = ngx_strncmp(r->uri.data, clcfp[i]->name.data, |
234 clcfp[i]->name.len); | 242 clcfp[i]->name.len); |
235 | 243 |
236 ngx_log_debug(r->connection->log, "rc: %d" _ rc); | 244 ngx_log_debug(r->connection->log, "rc: %d" _ rc); |
237 | 245 |
238 if (rc < 0) { | 246 if (rc < 0) { |
239 break; | 247 break; |
240 } | 248 } |
241 | 249 |
242 if (rc == 0) { | 250 if (rc == 0) { |
243 r->loc_conf = clcfp[i]->loc_conf; | 251 r->loc_conf = clcfp[i]->loc_conf; |
244 } | 252 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
253 r->connection->log->file = clcf->err_log->file; | |
254 r->connection->log->log_level = clcf->err_log->log_level; | |
255 } | |
245 } | 256 } |
246 | 257 |
247 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 258 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
248 | 259 |
249 if ((ngx_io.flags & NGX_IO_SENDFILE) == 0 || clcf->sendfile == 0) { | 260 if ((ngx_io.flags & NGX_IO_SENDFILE) == 0 || clcf->sendfile == 0) { |
581 | 592 |
582 module = ngx_modules[m]->ctx; | 593 module = ngx_modules[m]->ctx; |
583 | 594 |
584 if (module->create_srv_conf) { | 595 if (module->create_srv_conf) { |
585 ngx_test_null(ctx->srv_conf[ngx_modules[m]->ctx_index], | 596 ngx_test_null(ctx->srv_conf[ngx_modules[m]->ctx_index], |
586 module->create_srv_conf(cf->pool), | 597 module->create_srv_conf(cf), |
587 NGX_CONF_ERROR); | 598 NGX_CONF_ERROR); |
588 } | 599 } |
589 | 600 |
590 if (module->create_loc_conf) { | 601 if (module->create_loc_conf) { |
591 ngx_test_null(ctx->loc_conf[ngx_modules[m]->ctx_index], | 602 ngx_test_null(ctx->loc_conf[ngx_modules[m]->ctx_index], |
592 module->create_loc_conf(cf->pool), | 603 module->create_loc_conf(cf), |
593 NGX_CONF_ERROR); | 604 NGX_CONF_ERROR); |
594 } | 605 } |
595 } | 606 } |
596 | 607 |
597 /* create links of the srv_conf's */ | 608 /* create links of the srv_conf's */ |
662 | 673 |
663 module = ngx_modules[m]->ctx; | 674 module = ngx_modules[m]->ctx; |
664 | 675 |
665 if (module->create_loc_conf) { | 676 if (module->create_loc_conf) { |
666 ngx_test_null(ctx->loc_conf[ngx_modules[m]->ctx_index], | 677 ngx_test_null(ctx->loc_conf[ngx_modules[m]->ctx_index], |
667 module->create_loc_conf(cf->pool), | 678 module->create_loc_conf(cf), |
668 NGX_CONF_ERROR); | 679 NGX_CONF_ERROR); |
669 } | 680 } |
670 } | 681 } |
671 | 682 |
672 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index]; | 683 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index]; |
738 | 749 |
739 return NGX_CONF_OK; | 750 return NGX_CONF_OK; |
740 } | 751 } |
741 | 752 |
742 | 753 |
743 static void *ngx_http_core_create_main_conf(ngx_pool_t *pool) | 754 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf) |
744 { | 755 { |
745 ngx_http_core_main_conf_t *cmcf; | 756 ngx_http_core_main_conf_t *cmcf; |
746 | 757 |
747 ngx_test_null(cmcf, | 758 ngx_test_null(cmcf, |
748 ngx_palloc(pool, sizeof(ngx_http_core_main_conf_t)), | 759 ngx_palloc(cf->pool, sizeof(ngx_http_core_main_conf_t)), |
749 NGX_CONF_ERROR); | 760 NGX_CONF_ERROR); |
750 | 761 |
751 ngx_init_array(cmcf->servers, pool, 5, sizeof(ngx_http_core_srv_conf_t *), | 762 ngx_init_array(cmcf->servers, cf->pool, |
763 5, sizeof(ngx_http_core_srv_conf_t *), | |
752 NGX_CONF_ERROR); | 764 NGX_CONF_ERROR); |
753 | 765 |
754 return cmcf; | 766 return cmcf; |
755 } | 767 } |
756 | 768 |
757 | 769 |
758 static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf) | 770 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) |
759 { | 771 { |
760 ngx_http_core_main_conf_t *cmcf = conf; | 772 ngx_http_core_main_conf_t *cmcf = conf; |
761 | 773 |
762 /* TODO: remove it if no directives */ | 774 /* TODO: remove it if no directives */ |
763 | 775 |
764 return NGX_CONF_OK; | 776 return NGX_CONF_OK; |
765 } | 777 } |
766 | 778 |
767 | 779 |
768 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool) | 780 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf) |
769 { | 781 { |
770 ngx_http_core_srv_conf_t *cscf; | 782 ngx_http_core_srv_conf_t *cscf; |
771 | 783 |
772 ngx_test_null(cscf, | 784 ngx_test_null(cscf, |
773 ngx_pcalloc(pool, sizeof(ngx_http_core_srv_conf_t)), | 785 ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)), |
774 NGX_CONF_ERROR); | 786 NGX_CONF_ERROR); |
775 | 787 |
776 ngx_init_array(cscf->locations, pool, 5, sizeof(void *), NGX_CONF_ERROR); | 788 ngx_init_array(cscf->locations, cf->pool, |
777 ngx_init_array(cscf->listen, pool, 5, sizeof(ngx_http_listen_t), | 789 5, sizeof(void *), NGX_CONF_ERROR); |
790 ngx_init_array(cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t), | |
778 NGX_CONF_ERROR); | 791 NGX_CONF_ERROR); |
779 ngx_init_array(cscf->server_names, pool, 5, sizeof(ngx_http_server_name_t), | 792 ngx_init_array(cscf->server_names, cf->pool, |
780 NGX_CONF_ERROR); | 793 5, sizeof(ngx_http_server_name_t), NGX_CONF_ERROR); |
781 | 794 |
782 cscf->connection_pool_size = NGX_CONF_UNSET; | 795 cscf->connection_pool_size = NGX_CONF_UNSET; |
783 cscf->post_accept_timeout = NGX_CONF_UNSET; | 796 cscf->post_accept_timeout = NGX_CONF_UNSET; |
784 cscf->request_pool_size = NGX_CONF_UNSET; | 797 cscf->request_pool_size = NGX_CONF_UNSET; |
785 cscf->client_header_timeout = NGX_CONF_UNSET; | 798 cscf->client_header_timeout = NGX_CONF_UNSET; |
788 | 801 |
789 return cscf; | 802 return cscf; |
790 } | 803 } |
791 | 804 |
792 | 805 |
793 static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool, | 806 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, |
794 void *parent, void *child) | 807 void *parent, void *child) |
795 { | 808 { |
796 ngx_http_core_srv_conf_t *prev = parent; | 809 ngx_http_core_srv_conf_t *prev = parent; |
797 ngx_http_core_srv_conf_t *conf = child; | 810 ngx_http_core_srv_conf_t *conf = child; |
798 | 811 |
799 int len; | |
800 ngx_err_t err; | |
801 ngx_http_listen_t *l; | 812 ngx_http_listen_t *l; |
802 ngx_http_server_name_t *n; | 813 ngx_http_server_name_t *n; |
803 | 814 |
804 /* TODO: it does not merge, it inits only */ | 815 /* TODO: it does not merge, it inits only */ |
805 | 816 |
815 l->family = AF_INET; | 826 l->family = AF_INET; |
816 } | 827 } |
817 | 828 |
818 if (conf->server_names.nelts == 0) { | 829 if (conf->server_names.nelts == 0) { |
819 ngx_test_null(n, ngx_push_array(&conf->server_names), NGX_CONF_ERROR); | 830 ngx_test_null(n, ngx_push_array(&conf->server_names), NGX_CONF_ERROR); |
820 ngx_test_null(n->name.data, ngx_palloc(pool, NGX_MAXHOSTNAMELEN), | 831 ngx_test_null(n->name.data, ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN), |
821 NGX_CONF_ERROR); | 832 NGX_CONF_ERROR); |
822 | 833 |
823 if (gethostname(n->name.data, NGX_MAXHOSTNAMELEN) == -1) { | 834 if (gethostname(n->name.data, NGX_MAXHOSTNAMELEN) == -1) { |
824 #if 0 | |
825 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, | 835 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, |
826 "gethostname() failed"); | 836 "gethostname() failed"); |
827 return NGX_CONF_ERROR; | 837 return NGX_CONF_ERROR; |
828 #endif | |
829 | |
830 err = ngx_errno; | |
831 len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1, | |
832 "gethostname() failed (%d: ", err); | |
833 len += ngx_strerror_r(err, ngx_conf_errstr + len, | |
834 sizeof(ngx_conf_errstr) - len - 1); | |
835 ngx_conf_errstr[len++] = ')'; | |
836 ngx_conf_errstr[len++] = '\0'; | |
837 return ngx_conf_errstr; | |
838 } | 838 } |
839 | 839 |
840 n->name.len = ngx_strlen(n->name.data); | 840 n->name.len = ngx_strlen(n->name.data); |
841 n->core_srv_conf = conf; | 841 n->core_srv_conf = conf; |
842 } | 842 } |
856 | 856 |
857 return NGX_CONF_OK; | 857 return NGX_CONF_OK; |
858 } | 858 } |
859 | 859 |
860 | 860 |
861 static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool) | 861 static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf) |
862 { | 862 { |
863 ngx_http_core_loc_conf_t *lcf; | 863 ngx_http_core_loc_conf_t *lcf; |
864 | 864 |
865 ngx_test_null(lcf, | 865 ngx_test_null(lcf, |
866 ngx_pcalloc(pool, sizeof(ngx_http_core_loc_conf_t)), | 866 ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)), |
867 NGX_CONF_ERROR); | 867 NGX_CONF_ERROR); |
868 | 868 |
869 /* set by ngx_pcalloc(): | 869 /* set by ngx_pcalloc(): |
870 | 870 |
871 lcf->doc_root.len = 0; | 871 lcf->doc_root.len = 0; |
895 { ngx_string("jpg"), ngx_string("image/jpeg") }, | 895 { ngx_string("jpg"), ngx_string("image/jpeg") }, |
896 { ngx_null_string, ngx_null_string } | 896 { ngx_null_string, ngx_null_string } |
897 }; | 897 }; |
898 | 898 |
899 | 899 |
900 static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool, | 900 static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, |
901 void *parent, void *child) | 901 void *parent, void *child) |
902 { | 902 { |
903 ngx_http_core_loc_conf_t *prev = parent; | 903 ngx_http_core_loc_conf_t *prev = parent; |
904 ngx_http_core_loc_conf_t *conf = child; | 904 ngx_http_core_loc_conf_t *conf = child; |
905 | 905 |
912 if (prev->types) { | 912 if (prev->types) { |
913 conf->types = prev->types; | 913 conf->types = prev->types; |
914 | 914 |
915 } else { | 915 } else { |
916 ngx_test_null(conf->types, | 916 ngx_test_null(conf->types, |
917 ngx_palloc(pool, NGX_HTTP_TYPES_HASH_PRIME | 917 ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME |
918 * sizeof(ngx_array_t)), | 918 * sizeof(ngx_array_t)), |
919 NGX_CONF_ERROR); | 919 NGX_CONF_ERROR); |
920 | 920 |
921 for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) { | 921 for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) { |
922 ngx_init_array(conf->types[i], pool, 5, sizeof(ngx_http_type_t), | 922 ngx_init_array(conf->types[i], cf->pool, |
923 NGX_CONF_ERROR); | 923 5, sizeof(ngx_http_type_t), NGX_CONF_ERROR); |
924 } | 924 } |
925 | 925 |
926 for (i = 0; default_types[i].exten.len; i++) { | 926 for (i = 0; default_types[i].exten.len; i++) { |
927 ngx_http_types_hash_key(key, default_types[i].exten); | 927 ngx_http_types_hash_key(key, default_types[i].exten); |
928 | 928 |
931 t->exten.len = default_types[i].exten.len; | 931 t->exten.len = default_types[i].exten.len; |
932 t->exten.data = default_types[i].exten.data; | 932 t->exten.data = default_types[i].exten.data; |
933 t->type.len = default_types[i].type.len; | 933 t->type.len = default_types[i].type.len; |
934 t->type.data = default_types[i].type.data; | 934 t->type.data = default_types[i].type.data; |
935 } | 935 } |
936 } | |
937 } | |
938 | |
939 if (conf->err_log == NULL) { | |
940 if (prev->err_log) { | |
941 conf->err_log = prev->err_log; | |
942 } else { | |
943 conf->err_log = cf->cycle->log; | |
936 } | 944 } |
937 } | 945 } |
938 | 946 |
939 ngx_conf_merge_str_value(conf->default_type, | 947 ngx_conf_merge_str_value(conf->default_type, |
940 prev->default_type, "text/plain"); | 948 prev->default_type, "text/plain"); |