comparison src/http/ngx_http_core_module.c @ 98:c9b243802a17

nginx-0.0.1-2003-05-30-18:27:59 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 30 May 2003 14:27:59 +0000
parents 70d2345a903f
children a059e1aa65d4
comparison
equal deleted inserted replaced
97:70d2345a903f 98:c9b243802a17
30 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); 30 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy);
31 static int ngx_cmp_locations(const void *first, const void *second); 31 static int ngx_cmp_locations(const void *first, const void *second);
32 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, 32 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd,
33 void *dummy); 33 void *dummy);
34 static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 34 static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
35 static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf);
35 static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 36 static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
36 static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, 37 static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
37 void *conf); 38 void *conf);
38 39
39 40
101 NGX_HTTP_SRV_CONF_OFFSET, 102 NGX_HTTP_SRV_CONF_OFFSET,
102 0, 103 0,
103 NULL}, 104 NULL},
104 105
105 {ngx_string("server_name"), 106 {ngx_string("server_name"),
106 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_ANY, 107 NGX_HTTP_SRV_CONF|NGX_CONF_ANY1,
107 ngx_set_server_name, 108 ngx_set_server_name,
108 NGX_HTTP_SRV_CONF_OFFSET, 109 NGX_HTTP_SRV_CONF_OFFSET,
109 0, 110 0,
110 NULL}, 111 NULL},
111 112
279 int ngx_http_core_translate_handler(ngx_http_request_t *r) 280 int ngx_http_core_translate_handler(ngx_http_request_t *r)
280 { 281 {
281 char *location, *last; 282 char *location, *last;
282 ngx_err_t err; 283 ngx_err_t err;
283 ngx_table_elt_t *h; 284 ngx_table_elt_t *h;
284 ngx_http_in_port_t *in_port;
285 ngx_http_server_name_t *s_name;
286 ngx_http_core_srv_conf_t *cscf; 285 ngx_http_core_srv_conf_t *cscf;
287 ngx_http_core_loc_conf_t *clcf; 286 ngx_http_core_loc_conf_t *clcf;
288 287
289 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 288 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
290 289
667 666
668 return rv; 667 return rv;
669 } 668 }
670 669
671 670
672 static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, char *conf) 671 static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
673 { 672 {
674 ngx_http_core_loc_conf_t *lcf = (ngx_http_core_loc_conf_t *) conf; 673 char *rv;
674 ngx_conf_t pcf;
675
676 pcf = *cf;
677 cf->handler = ngx_set_type;
678 cf->handler_conf = conf;
679 rv = ngx_conf_parse(cf, NULL);
680 *cf = pcf;
681
682 return rv;
683 }
684
685
686 static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
687 {
688 ngx_http_core_loc_conf_t *lcf = conf;
675 689
676 int i, key; 690 int i, key;
677 ngx_str_t *args; 691 ngx_str_t *args;
678 ngx_http_type_t *t; 692 ngx_http_type_t *t;
679 693
703 717
704 return NGX_CONF_OK; 718 return NGX_CONF_OK;
705 } 719 }
706 720
707 721
708 static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
709 {
710 char *rv;
711 ngx_conf_t pcf;
712
713 pcf = *cf;
714 cf->handler = ngx_set_type;
715 cf->handler_conf = conf;
716 rv = ngx_conf_parse(cf, NULL);
717 *cf = pcf;
718
719 return rv;
720 }
721
722
723 static void *ngx_http_core_create_main_conf(ngx_pool_t *pool) 722 static void *ngx_http_core_create_main_conf(ngx_pool_t *pool)
724 { 723 {
725 ngx_http_core_main_conf_t *cmcf; 724 ngx_http_core_main_conf_t *cmcf;
726 725
727 ngx_test_null(cmcf, 726 ngx_test_null(cmcf,
773 772
774 773
775 static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool, 774 static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
776 void *parent, void *child) 775 void *parent, void *child)
777 { 776 {
778 ngx_http_core_srv_conf_t *prev = (ngx_http_core_srv_conf_t *) parent; 777 ngx_http_core_srv_conf_t *prev = parent;
779 ngx_http_core_srv_conf_t *conf = (ngx_http_core_srv_conf_t *) child; 778 ngx_http_core_srv_conf_t *conf = child;
780 779
780 int len;
781 ngx_err_t err; 781 ngx_err_t err;
782 ngx_http_listen_t *l; 782 ngx_http_listen_t *l;
783 ngx_http_server_name_t *n; 783 ngx_http_server_name_t *n;
784 784
785 /* TODO: it does not merge, it init only */ 785 /* TODO: it does not merge, it init only */
796 ngx_test_null(n->name.data, ngx_palloc(pool, NGX_MAXHOSTNAMELEN), 796 ngx_test_null(n->name.data, ngx_palloc(pool, NGX_MAXHOSTNAMELEN),
797 NGX_CONF_ERROR); 797 NGX_CONF_ERROR);
798 798
799 if (gethostname(n->name.data, NGX_MAXHOSTNAMELEN) == -1) { 799 if (gethostname(n->name.data, NGX_MAXHOSTNAMELEN) == -1) {
800 err = ngx_errno; 800 err = ngx_errno;
801 ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1, 801 len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
802 "gethostname() failed (%d: %s)", 802 "gethostname() failed (%d: ", err);
803 err, ngx_strerror(err)); 803 len += ngx_strerror_r(err, ngx_conf_errstr + len,
804 sizeof(ngx_conf_errstr) - len - 1);
805 ngx_conf_errstr[len++] = ')';
806 ngx_conf_errstr[len++] = '\0';
804 return ngx_conf_errstr; 807 return ngx_conf_errstr;
805 } 808 }
806 809
807 n->name.len = ngx_strlen(n->name.data); 810 n->name.len = ngx_strlen(n->name.data);
808 n->core_srv_conf = conf; 811 n->core_srv_conf = conf;
860 863
861 864
862 static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool, 865 static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool,
863 void *parent, void *child) 866 void *parent, void *child)
864 { 867 {
865 ngx_http_core_loc_conf_t *prev = (ngx_http_core_loc_conf_t *) parent; 868 ngx_http_core_loc_conf_t *prev = parent;
866 ngx_http_core_loc_conf_t *conf = (ngx_http_core_loc_conf_t *) child; 869 ngx_http_core_loc_conf_t *conf = child;
867 870
868 int i, key; 871 int i, key;
869 ngx_http_type_t *t; 872 ngx_http_type_t *t;
870 873
871 ngx_conf_merge_str_value(conf->doc_root, 874 ngx_conf_merge_str_value(conf->doc_root,
917 } 920 }
918 921
919 922
920 static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 923 static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
921 { 924 {
922 ngx_http_core_srv_conf_t *scf = (ngx_http_core_srv_conf_t *) conf; 925 ngx_http_core_srv_conf_t *scf = conf;
923 926
924 char *addr; 927 char *addr;
925 u_int p; 928 u_int p;
926 struct hostent *h; 929 struct hostent *h;
927 ngx_str_t *args; 930 ngx_str_t *args;
961 ls->port = 80; 964 ls->port = 80;
962 965
963 } else if ((ls->port == NGX_ERROR && p != 0) /* "listen host:NONNUMBER" */ 966 } else if ((ls->port == NGX_ERROR && p != 0) /* "listen host:NONNUMBER" */
964 || (ls->port < 1 || ls->port > 65536)) { /* "listen 99999" */ 967 || (ls->port < 1 || ls->port > 65536)) { /* "listen 99999" */
965 968
966 ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1, 969 ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
967 "invalid port \"%s\", " 970 "invalid port \"%s\", "
968 "it must be a number between 1 and 65535", 971 "it must be a number between 1 and 65535",
969 &addr[p]); 972 &addr[p]);
970 return ngx_conf_errstr; 973 return ngx_conf_errstr;
971 974
972 } else if (p == 0) { 975 } else if (p == 0) {
973 ls->addr = INADDR_ANY; 976 ls->addr = INADDR_ANY;
974 return NGX_CONF_OK; 977 return NGX_CONF_OK;
975 } 978 }
991 } 994 }
992 995
993 996
994 static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 997 static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
995 { 998 {
996 ngx_http_core_srv_conf_t *scf = (ngx_http_core_srv_conf_t *) conf; 999 ngx_http_core_srv_conf_t *scf = conf;
997 1000
998 ngx_str_t *args; 1001 int i;
1002 ngx_str_t *value;
999 ngx_http_server_name_t *sn; 1003 ngx_http_server_name_t *sn;
1000 1004
1001 /* TODO: several names */ 1005 /* TODO: several names */
1002 /* TODO: warn about duplicate 'server_name' directives */ 1006 /* TODO: warn about duplicate 'server_name' directives */
1003 1007
1004 ngx_test_null(sn, ngx_push_array(&scf->server_names), NGX_CONF_ERROR); 1008 value = cf->args->elts;
1005 1009
1006 args = cf->args->elts; 1010 for (i = 1; i < cf->args->nelts; i++) {
1007 1011 if (value[i].len == 0) {
1008 sn->name.len = args[1].len; 1012 ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
1009 sn->name.data = args[1].data; 1013 "server name \"%s\" is invalid", value[i].data);
1010 sn->core_srv_conf = scf; 1014 return ngx_conf_errstr;
1015 }
1016
1017 ngx_test_null(sn, ngx_push_array(&scf->server_names), NGX_CONF_ERROR);
1018
1019 sn->name.len = value[i].len;
1020 sn->name.data = value[i].data;
1021 sn->core_srv_conf = scf;
1022 }
1011 1023
1012 return NGX_CONF_OK; 1024 return NGX_CONF_OK;
1013 } 1025 }