Mercurial > hg > nginx
comparison src/http/ngx_http_core_module.c @ 290:87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 16 Mar 2004 07:10:12 +0000 |
parents | 35a6a9df2d25 |
children | ec3c049681fd |
comparison
equal
deleted
inserted
replaced
289:0750faf8d7e3 | 290:87e73f067470 |
---|---|
26 static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 26 static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
27 static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); | 27 static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); |
28 static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 28 static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
29 static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, | 29 static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, |
30 void *conf); | 30 void *conf); |
31 static char *ngx_set_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | |
31 static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 32 static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
32 static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 33 static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
33 | 34 |
34 static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data); | 35 static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data); |
35 | 36 |
127 offsetof(ngx_http_core_loc_conf_t, default_type), | 128 offsetof(ngx_http_core_loc_conf_t, default_type), |
128 NULL }, | 129 NULL }, |
129 | 130 |
130 { ngx_string("root"), | 131 { ngx_string("root"), |
131 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 132 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
132 ngx_conf_set_str_slot, | 133 ngx_set_root, |
133 NGX_HTTP_LOC_CONF_OFFSET, | 134 NGX_HTTP_LOC_CONF_OFFSET, |
134 offsetof(ngx_http_core_loc_conf_t, doc_root), | 135 0, |
136 NULL }, | |
137 | |
138 { ngx_string("alias"), | |
139 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
140 ngx_set_root, | |
141 NGX_HTTP_LOC_CONF_OFFSET, | |
142 0, | |
135 NULL }, | 143 NULL }, |
136 | 144 |
137 { ngx_string("client_body_timeout"), | 145 { ngx_string("client_body_timeout"), |
138 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 146 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
139 ngx_conf_set_msec_slot, | 147 ngx_conf_set_msec_slot, |
380 | 388 |
381 if (r->uri.data[r->uri.len - 1] == '/') { | 389 if (r->uri.data[r->uri.len - 1] == '/') { |
382 | 390 |
383 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 391 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
384 | 392 |
385 if (!(path = ngx_palloc(r->pool, clcf->doc_root.len + r->uri.len))) { | 393 if (!(path = ngx_palloc(r->pool, clcf->root.len + r->uri.len))) { |
386 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 394 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
387 return; | 395 return; |
388 } | 396 } |
389 | 397 |
390 ngx_cpystrn(ngx_cpymem(path, clcf->doc_root.data, clcf->doc_root.len), | 398 ngx_cpystrn(ngx_cpymem(path, clcf->root.data, clcf->root.len), |
391 r->uri.data, r->uri.len + 1); | 399 r->uri.data, r->uri.len + 1); |
392 | 400 |
393 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 401 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
394 "directory index of \"%s\" is forbidden", path); | 402 "directory index of \"%s\" is forbidden", path); |
395 | 403 |
404 } | 412 } |
405 | 413 |
406 | 414 |
407 int ngx_http_find_location_config(ngx_http_request_t *r) | 415 int ngx_http_find_location_config(ngx_http_request_t *r) |
408 { | 416 { |
409 ngx_int_t i, rc, exact; | 417 int rc; |
418 ngx_uint_t i, exact; | |
410 ngx_str_t *auto_redirect; | 419 ngx_str_t *auto_redirect; |
411 ngx_http_core_loc_conf_t *clcf, **clcfp; | 420 ngx_http_core_loc_conf_t *clcf, **clcfp; |
412 ngx_http_core_srv_conf_t *cscf; | 421 ngx_http_core_srv_conf_t *cscf; |
413 | 422 |
414 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 423 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
542 | 551 |
543 | 552 |
544 ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r) | 553 ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r) |
545 { | 554 { |
546 uint32_t key; | 555 uint32_t key; |
547 ngx_int_t i; | 556 ngx_uint_t i; |
548 ngx_http_type_t *type; | 557 ngx_http_type_t *type; |
549 ngx_http_core_loc_conf_t *clcf; | 558 ngx_http_core_loc_conf_t *clcf; |
550 | 559 |
551 if (!(r->headers_out.content_type = | 560 if (!(r->headers_out.content_type = |
552 ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) | 561 ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) |
854 ngx_http_conf_ctx_t *ctx, *pvctx; | 863 ngx_http_conf_ctx_t *ctx, *pvctx; |
855 ngx_http_core_srv_conf_t *cscf; | 864 ngx_http_core_srv_conf_t *cscf; |
856 ngx_http_core_loc_conf_t *clcf, **clcfp; | 865 ngx_http_core_loc_conf_t *clcf, **clcfp; |
857 #if (HAVE_PCRE) | 866 #if (HAVE_PCRE) |
858 ngx_str_t err; | 867 ngx_str_t err; |
859 char errstr[NGX_MAX_CONF_ERRSTR]; | 868 u_char errstr[NGX_MAX_CONF_ERRSTR]; |
860 #endif | 869 #endif |
861 | 870 |
862 if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) { | 871 if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) { |
863 return NGX_CONF_ERROR; | 872 return NGX_CONF_ERROR; |
864 } | 873 } |
971 | 980 |
972 static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) | 981 static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) |
973 { | 982 { |
974 ngx_http_core_loc_conf_t *lcf = conf; | 983 ngx_http_core_loc_conf_t *lcf = conf; |
975 | 984 |
976 int i, key; | 985 uint32_t key; |
986 ngx_uint_t i; | |
977 ngx_str_t *args; | 987 ngx_str_t *args; |
978 ngx_http_type_t *type; | 988 ngx_http_type_t *type; |
979 | 989 |
980 if (lcf->types == NULL) { | 990 if (lcf->types == NULL) { |
981 ngx_test_null(lcf->types, | 991 ngx_test_null(lcf->types, |
1019 } | 1029 } |
1020 | 1030 |
1021 | 1031 |
1022 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) | 1032 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) |
1023 { | 1033 { |
1034 #if 0 | |
1024 ngx_http_core_main_conf_t *cmcf = conf; | 1035 ngx_http_core_main_conf_t *cmcf = conf; |
1025 | 1036 |
1026 /* TODO: remove it if no directives */ | 1037 /* TODO: remove it if no directives */ |
1038 #endif | |
1027 | 1039 |
1028 return NGX_CONF_OK; | 1040 return NGX_CONF_OK; |
1029 } | 1041 } |
1030 | 1042 |
1031 | 1043 |
1042 ngx_init_array(cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t), | 1054 ngx_init_array(cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t), |
1043 NGX_CONF_ERROR); | 1055 NGX_CONF_ERROR); |
1044 ngx_init_array(cscf->server_names, cf->pool, | 1056 ngx_init_array(cscf->server_names, cf->pool, |
1045 5, sizeof(ngx_http_server_name_t), NGX_CONF_ERROR); | 1057 5, sizeof(ngx_http_server_name_t), NGX_CONF_ERROR); |
1046 | 1058 |
1047 cscf->connection_pool_size = NGX_CONF_UNSET; | 1059 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE; |
1048 cscf->post_accept_timeout = NGX_CONF_UNSET; | 1060 cscf->post_accept_timeout = NGX_CONF_UNSET_MSEC; |
1049 cscf->request_pool_size = NGX_CONF_UNSET; | 1061 cscf->request_pool_size = NGX_CONF_UNSET_SIZE; |
1050 cscf->client_header_timeout = NGX_CONF_UNSET; | 1062 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC; |
1051 cscf->client_header_buffer_size = NGX_CONF_UNSET; | 1063 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE; |
1052 cscf->large_client_header = NGX_CONF_UNSET; | 1064 cscf->large_client_header = NGX_CONF_UNSET; |
1053 | 1065 |
1054 return cscf; | 1066 return cscf; |
1055 } | 1067 } |
1056 | 1068 |
1081 if (conf->server_names.nelts == 0) { | 1093 if (conf->server_names.nelts == 0) { |
1082 ngx_test_null(n, ngx_push_array(&conf->server_names), NGX_CONF_ERROR); | 1094 ngx_test_null(n, ngx_push_array(&conf->server_names), NGX_CONF_ERROR); |
1083 ngx_test_null(n->name.data, ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN), | 1095 ngx_test_null(n->name.data, ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN), |
1084 NGX_CONF_ERROR); | 1096 NGX_CONF_ERROR); |
1085 | 1097 |
1086 if (gethostname(n->name.data, NGX_MAXHOSTNAMELEN) == -1) { | 1098 if (gethostname((char *) n->name.data, NGX_MAXHOSTNAMELEN) == -1) { |
1087 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, | 1099 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, |
1088 "gethostname() failed"); | 1100 "gethostname() failed"); |
1089 return NGX_CONF_ERROR; | 1101 return NGX_CONF_ERROR; |
1090 } | 1102 } |
1091 | 1103 |
1118 ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)), | 1130 ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)), |
1119 NGX_CONF_ERROR); | 1131 NGX_CONF_ERROR); |
1120 | 1132 |
1121 /* set by ngx_pcalloc(): | 1133 /* set by ngx_pcalloc(): |
1122 | 1134 |
1123 lcf->doc_root.len = 0; | 1135 lcf->root.len = 0; |
1124 lcf->doc_root.data = NULL; | 1136 lcf->root.data = NULL; |
1125 lcf->types = NULL; | 1137 lcf->types = NULL; |
1126 lcf->default_type.len = 0; | 1138 lcf->default_type.len = 0; |
1127 lcf->default_type.data = NULL; | 1139 lcf->default_type.data = NULL; |
1128 lcf->err_log = NULL; | 1140 lcf->err_log = NULL; |
1129 lcf->error_pages = NULL; | 1141 lcf->error_pages = NULL; |
1130 | 1142 |
1131 lcf->regex = NULL; | 1143 lcf->regex = NULL; |
1132 lcf->exact_match = 0; | 1144 lcf->exact_match = 0; |
1133 lcf->auto_redirect = 0; | 1145 lcf->auto_redirect = 0; |
1146 lcf->alias = 0; | |
1134 | 1147 |
1135 */ | 1148 */ |
1136 | 1149 |
1137 lcf->client_body_timeout = NGX_CONF_UNSET; | 1150 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC; |
1138 lcf->sendfile = NGX_CONF_UNSET; | 1151 lcf->sendfile = NGX_CONF_UNSET; |
1139 lcf->tcp_nopush = NGX_CONF_UNSET; | 1152 lcf->tcp_nopush = NGX_CONF_UNSET; |
1140 lcf->send_timeout = NGX_CONF_UNSET; | 1153 lcf->send_timeout = NGX_CONF_UNSET_MSEC; |
1141 lcf->send_lowat = NGX_CONF_UNSET; | 1154 lcf->send_lowat = NGX_CONF_UNSET_SIZE; |
1142 lcf->discarded_buffer_size = NGX_CONF_UNSET; | 1155 lcf->discarded_buffer_size = NGX_CONF_UNSET_SIZE; |
1143 lcf->keepalive_timeout = NGX_CONF_UNSET; | 1156 lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; |
1144 lcf->lingering_time = NGX_CONF_UNSET; | 1157 lcf->lingering_time = NGX_CONF_UNSET_MSEC; |
1145 lcf->lingering_timeout = NGX_CONF_UNSET; | 1158 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC; |
1146 | 1159 |
1147 lcf->msie_padding = NGX_CONF_UNSET; | 1160 lcf->msie_padding = NGX_CONF_UNSET; |
1148 | 1161 |
1149 return lcf; | 1162 return lcf; |
1150 } | 1163 } |
1165 ngx_http_core_loc_conf_t *conf = child; | 1178 ngx_http_core_loc_conf_t *conf = child; |
1166 | 1179 |
1167 int i, key; | 1180 int i, key; |
1168 ngx_http_type_t *t; | 1181 ngx_http_type_t *t; |
1169 | 1182 |
1170 ngx_conf_merge_str_value(conf->doc_root, prev->doc_root, "html"); | 1183 ngx_conf_merge_str_value(conf->root, prev->root, "html"); |
1171 | 1184 |
1172 if (conf->types == NULL) { | 1185 if (conf->types == NULL) { |
1173 if (prev->types) { | 1186 if (prev->types) { |
1174 conf->types = prev->types; | 1187 conf->types = prev->types; |
1175 | 1188 |
1239 | 1252 |
1240 static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1253 static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
1241 { | 1254 { |
1242 ngx_http_core_srv_conf_t *scf = conf; | 1255 ngx_http_core_srv_conf_t *scf = conf; |
1243 | 1256 |
1244 char *addr; | 1257 u_char *addr; |
1245 u_int p; | 1258 u_int p; |
1246 struct hostent *h; | 1259 struct hostent *h; |
1247 ngx_str_t *args; | 1260 ngx_str_t *args; |
1248 ngx_http_listen_t *ls; | 1261 ngx_http_listen_t *ls; |
1249 | 1262 |
1253 ngx_test_null(ls, ngx_push_array(&scf->listen), NGX_CONF_ERROR); | 1266 ngx_test_null(ls, ngx_push_array(&scf->listen), NGX_CONF_ERROR); |
1254 | 1267 |
1255 /* AF_INET only */ | 1268 /* AF_INET only */ |
1256 | 1269 |
1257 ls->family = AF_INET; | 1270 ls->family = AF_INET; |
1258 ls->flags = 0; | 1271 ls->default_server = 0; |
1259 ls->file_name = cf->conf_file->file.name; | 1272 ls->file_name = cf->conf_file->file.name; |
1260 ls->line = cf->conf_file->line; | 1273 ls->line = cf->conf_file->line; |
1261 | 1274 |
1262 args = cf->args->elts; | 1275 args = cf->args->elts; |
1263 addr = args[1].data; | 1276 addr = args[1].data; |
1293 } else if (p == 0) { | 1306 } else if (p == 0) { |
1294 ls->addr = INADDR_ANY; | 1307 ls->addr = INADDR_ANY; |
1295 return NGX_CONF_OK; | 1308 return NGX_CONF_OK; |
1296 } | 1309 } |
1297 | 1310 |
1298 ls->addr = inet_addr(addr); | 1311 ls->addr = inet_addr((const char *) addr); |
1299 if (ls->addr == INADDR_NONE) { | 1312 if (ls->addr == INADDR_NONE) { |
1300 h = gethostbyname(addr); | 1313 h = gethostbyname((const char *) addr); |
1301 | 1314 |
1302 if (h == NULL || h->h_addr_list[0] == NULL) { | 1315 if (h == NULL || h->h_addr_list[0] == NULL) { |
1303 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1316 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1304 "can not resolve host \"%s\" " | 1317 "can not resolve host \"%s\" " |
1305 "in \"%s\" directive", addr, cmd->name.data); | 1318 "in \"%s\" directive", addr, cmd->name.data); |
1315 | 1328 |
1316 static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1329 static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
1317 { | 1330 { |
1318 ngx_http_core_srv_conf_t *scf = conf; | 1331 ngx_http_core_srv_conf_t *scf = conf; |
1319 | 1332 |
1320 int i; | 1333 ngx_uint_t i; |
1321 ngx_str_t *value; | 1334 ngx_str_t *value; |
1322 ngx_http_server_name_t *sn; | 1335 ngx_http_server_name_t *sn; |
1323 | 1336 |
1324 /* TODO: several names */ | 1337 /* TODO: several names */ |
1325 /* TODO: warn about duplicate 'server_name' directives */ | 1338 /* TODO: warn about duplicate 'server_name' directives */ |
1344 | 1357 |
1345 return NGX_CONF_OK; | 1358 return NGX_CONF_OK; |
1346 } | 1359 } |
1347 | 1360 |
1348 | 1361 |
1362 static char *ngx_set_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1363 { | |
1364 ngx_http_core_loc_conf_t *lcf = conf; | |
1365 | |
1366 ngx_uint_t alias; | |
1367 ngx_str_t *value; | |
1368 | |
1369 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0; | |
1370 | |
1371 if (lcf->root.data) { | |
1372 if (lcf->alias == alias) { | |
1373 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1374 "\"%s\" directive is duplicate", | |
1375 cmd->name.data); | |
1376 } else { | |
1377 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1378 "\"%s\" directive is duplicate, " | |
1379 "\"%s\" directive is specified before", | |
1380 cmd->name.data, lcf->alias ? "alias" : "root"); | |
1381 } | |
1382 | |
1383 return NGX_CONF_ERROR; | |
1384 } | |
1385 | |
1386 value = cf->args->elts; | |
1387 | |
1388 lcf->alias = alias; | |
1389 lcf->root = value[1]; | |
1390 | |
1391 return NGX_CONF_OK; | |
1392 } | |
1393 | |
1394 | |
1349 static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1395 static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
1350 { | 1396 { |
1351 ngx_http_core_loc_conf_t *lcf = conf; | 1397 ngx_http_core_loc_conf_t *lcf = conf; |
1352 | 1398 |
1353 int i; | 1399 ngx_uint_t i; |
1354 ngx_str_t *value; | 1400 ngx_str_t *value; |
1355 ngx_http_err_page_t *err; | 1401 ngx_http_err_page_t *err; |
1356 | 1402 |
1357 if (lcf->error_pages == NULL) { | 1403 if (lcf->error_pages == NULL) { |
1358 lcf->error_pages = ngx_create_array(cf->pool, 5, | 1404 lcf->error_pages = ngx_create_array(cf->pool, 5, |
1401 | 1447 |
1402 static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data) | 1448 static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data) |
1403 { | 1449 { |
1404 #if (HAVE_LOWAT_EVENT) | 1450 #if (HAVE_LOWAT_EVENT) |
1405 | 1451 |
1406 int *np = data; | 1452 ssize_t *np = data; |
1407 | 1453 |
1408 if (*np >= ngx_freebsd_net_inet_tcp_sendspace) { | 1454 if (*np >= ngx_freebsd_net_inet_tcp_sendspace) { |
1409 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1455 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1410 "\"send_lowat\" must be less than %d " | 1456 "\"send_lowat\" must be less than %d " |
1411 "(sysctl net.inet.tcp.sendspace)", | 1457 "(sysctl net.inet.tcp.sendspace)", |