comparison src/http/ngx_http_core_module.c @ 50:72eb30262aac NGINX_0_1_25

nginx 0.1.25 *) Bugfix: nginx did run on Linux parisc. *) Feature: nginx now does not start under FreeBSD if the sysctl kern.ipc.somaxconn value is too big. *) Bugfix: if a request was internally redirected by the ngx_http_index_module module to the ngx_http_proxy_module or ngx_http_fastcgi_module modules, then the index file was not closed after request completion. *) Feature: the "proxy_pass" can be used in location with regular expression. *) Feature: the ngx_http_rewrite_filter_module module supports the condition like "if ($HTTP_USER_AGENT ~ MSIE)". *) Bugfix: nginx started too slow if the large number of addresses and text values were used in the "geo" directive. *) Change: a variable name must be declared as "$name" in the "geo" directive. The previous variant without "$" is still supported, but will be removed soon. *) Feature: the "%{VARIABLE}v" logging parameter. *) Feature: the "set $name value" directive. *) Bugfix: gcc 4.0 compatibility. *) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
author Igor Sysoev <http://sysoev.ru>
date Sat, 19 Mar 2005 00:00:00 +0300
parents 6cfc63e68377
children 0d75d65c642f
comparison
equal deleted inserted replaced
49:93dabbc9efb9 50:72eb30262aac
783 break; 783 break;
784 } 784 }
785 } 785 }
786 786
787 if (i < r->exten.len) { 787 if (i < r->exten.len) {
788 if (!(p = ngx_palloc(r->pool, r->exten.len))) { 788 p = ngx_palloc(r->pool, r->exten.len);
789 if (p == NULL) {
789 return NGX_HTTP_INTERNAL_SERVER_ERROR; 790 return NGX_HTTP_INTERNAL_SERVER_ERROR;
790 } 791 }
791 792
792 exten = p; 793 exten = p;
793 794
895 for (i = r->uri.len - 1; i > 1; i--) { 896 for (i = r->uri.len - 1; i > 1; i--) {
896 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') { 897 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
897 r->exten.len = r->uri.len - i - 1; 898 r->exten.len = r->uri.len - i - 1;
898 899
899 if (r->exten.len > 0) { 900 if (r->exten.len > 0) {
900 if (!(r->exten.data = ngx_palloc(r->pool, r->exten.len + 1))) { 901 r->exten.data = ngx_palloc(r->pool, r->exten.len + 1);
902 if (r->exten.data == NULL) {
901 return NGX_ERROR; 903 return NGX_ERROR;
902 } 904 }
903 905
904 ngx_cpystrn(r->exten.data, &r->uri.data[i + 1], 906 ngx_cpystrn(r->exten.data, &r->uri.data[i + 1],
905 r->exten.len + 1); 907 r->exten.len + 1);
995 ngx_http_module_t *module; 997 ngx_http_module_t *module;
996 ngx_http_conf_ctx_t *ctx, *http_ctx; 998 ngx_http_conf_ctx_t *ctx, *http_ctx;
997 ngx_http_core_srv_conf_t *cscf, **cscfp; 999 ngx_http_core_srv_conf_t *cscf, **cscfp;
998 ngx_http_core_main_conf_t *cmcf; 1000 ngx_http_core_main_conf_t *cmcf;
999 1001
1000 if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) { 1002 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
1003 if (ctx == NULL) {
1001 return NGX_CONF_ERROR; 1004 return NGX_CONF_ERROR;
1002 } 1005 }
1003 1006
1004 http_ctx = cf->ctx; 1007 http_ctx = cf->ctx;
1005 ctx->main_conf = http_ctx->main_conf; 1008 ctx->main_conf = http_ctx->main_conf;
1024 } 1027 }
1025 1028
1026 module = ngx_modules[m]->ctx; 1029 module = ngx_modules[m]->ctx;
1027 1030
1028 if (module->create_srv_conf) { 1031 if (module->create_srv_conf) {
1029 if (!(mconf = module->create_srv_conf(cf))) { 1032 mconf = module->create_srv_conf(cf);
1033 if (mconf == NULL) {
1030 return NGX_CONF_ERROR; 1034 return NGX_CONF_ERROR;
1031 } 1035 }
1032 1036
1033 ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf; 1037 ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf;
1034 } 1038 }
1035 1039
1036 if (module->create_loc_conf) { 1040 if (module->create_loc_conf) {
1037 if (!(mconf = module->create_loc_conf(cf))) { 1041 mconf = module->create_loc_conf(cf);
1042 if (mconf == NULL) {
1038 return NGX_CONF_ERROR; 1043 return NGX_CONF_ERROR;
1039 } 1044 }
1040 1045
1041 ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf; 1046 ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf;
1042 } 1047 }
1049 cscf->ctx = ctx; 1054 cscf->ctx = ctx;
1050 1055
1051 1056
1052 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; 1057 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
1053 1058
1054 if (!(cscfp = ngx_array_push(&cmcf->servers))) { 1059 cscfp = ngx_array_push(&cmcf->servers);
1060 if (cscfp == NULL) {
1055 return NGX_CONF_ERROR; 1061 return NGX_CONF_ERROR;
1056 } 1062 }
1057 1063
1058 *cscfp = cscf; 1064 *cscfp = cscf;
1059 1065
1093 #if (NGX_PCRE) 1099 #if (NGX_PCRE)
1094 ngx_str_t err; 1100 ngx_str_t err;
1095 u_char errstr[NGX_MAX_CONF_ERRSTR]; 1101 u_char errstr[NGX_MAX_CONF_ERRSTR];
1096 #endif 1102 #endif
1097 1103
1098 if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) { 1104 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
1105 if (ctx == NULL) {
1099 return NGX_CONF_ERROR; 1106 return NGX_CONF_ERROR;
1100 } 1107 }
1101 1108
1102 pctx = cf->ctx; 1109 pctx = cf->ctx;
1103 ctx->main_conf = pctx->main_conf; 1110 ctx->main_conf = pctx->main_conf;
1179 1186
1180 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index]; 1187 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
1181 1188
1182 if (pclcf->name.len == 0) { 1189 if (pclcf->name.len == 0) {
1183 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index]; 1190 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
1184 if (!(clcfp = ngx_array_push(&cscf->locations))) { 1191
1192 clcfp = ngx_array_push(&cscf->locations);
1193 if (clcfp == NULL) {
1185 return NGX_CONF_ERROR; 1194 return NGX_CONF_ERROR;
1186 } 1195 }
1187 1196
1188 } else { 1197 } else {
1189 #if 0 1198 #if 0
1212 &clcf->name, &pclcf->name); 1221 &clcf->name, &pclcf->name);
1213 return NGX_CONF_ERROR; 1222 return NGX_CONF_ERROR;
1214 } 1223 }
1215 1224
1216 if (pclcf->locations.elts == NULL) { 1225 if (pclcf->locations.elts == NULL) {
1217 ngx_init_array(pclcf->locations, cf->pool, 4, sizeof(void *), 1226 if (ngx_array_init(&pclcf->locations, cf->pool, 4, sizeof(void *))
1218 NGX_CONF_ERROR); 1227 != NGX_OK)
1219 } 1228 {
1220 1229 return NGX_CONF_ERROR;
1221 if (!(clcfp = ngx_push_array(&pclcf->locations))) { 1230 }
1231 }
1232
1233 clcfp = ngx_array_push(&pclcf->locations);
1234 if (clcfp == NULL) {
1222 return NGX_CONF_ERROR; 1235 return NGX_CONF_ERROR;
1223 } 1236 }
1224 } 1237 }
1225 1238
1226 *clcfp = clcf; 1239 *clcfp = clcf;
1345 value = cf->args->elts; 1358 value = cf->args->elts;
1346 1359
1347 for (i = 1; i < cf->args->nelts; i++) { 1360 for (i = 1; i < cf->args->nelts; i++) {
1348 ngx_http_types_hash_key(key, value[i]); 1361 ngx_http_types_hash_key(key, value[i]);
1349 1362
1350 if (!(type = ngx_array_push(&lcf->types[key]))) { 1363 type = ngx_array_push(&lcf->types[key]);
1364 if (type == NULL) {
1351 return NGX_CONF_ERROR; 1365 return NGX_CONF_ERROR;
1352 } 1366 }
1353 1367
1354 type->exten = value[i]; 1368 type->exten = value[i];
1355 type->type = value[0]; 1369 type->type = value[0];
1362 static void * 1376 static void *
1363 ngx_http_core_create_main_conf(ngx_conf_t *cf) 1377 ngx_http_core_create_main_conf(ngx_conf_t *cf)
1364 { 1378 {
1365 ngx_http_core_main_conf_t *cmcf; 1379 ngx_http_core_main_conf_t *cmcf;
1366 1380
1367 if (!(cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t)))) { 1381 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
1382 if (cmcf == NULL) {
1368 return NGX_CONF_ERROR; 1383 return NGX_CONF_ERROR;
1369 } 1384 }
1370 1385
1371 if (ngx_array_init(&cmcf->servers, cf->pool, 4, 1386 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
1372 sizeof(ngx_http_core_srv_conf_t *)) == NGX_ERROR) 1387 sizeof(ngx_http_core_srv_conf_t *)) == NGX_ERROR)
1401 static void * 1416 static void *
1402 ngx_http_core_create_srv_conf(ngx_conf_t *cf) 1417 ngx_http_core_create_srv_conf(ngx_conf_t *cf)
1403 { 1418 {
1404 ngx_http_core_srv_conf_t *cscf; 1419 ngx_http_core_srv_conf_t *cscf;
1405 1420
1406 if (!(cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)))) { 1421 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
1422 if (cscf == NULL) {
1407 return NGX_CONF_ERROR; 1423 return NGX_CONF_ERROR;
1408 } 1424 }
1409 1425
1410 /* 1426 /*
1411 * set by ngx_pcalloc(): 1427 * set by ngx_pcalloc():
1453 ngx_http_core_main_conf_t *cmcf; 1469 ngx_http_core_main_conf_t *cmcf;
1454 1470
1455 /* TODO: it does not merge, it inits only */ 1471 /* TODO: it does not merge, it inits only */
1456 1472
1457 if (conf->listen.nelts == 0) { 1473 if (conf->listen.nelts == 0) {
1458 if (!(ls = ngx_array_push(&conf->listen))) { 1474 ls = ngx_array_push(&conf->listen);
1475 if (ls == NULL) {
1459 return NGX_CONF_ERROR; 1476 return NGX_CONF_ERROR;
1460 } 1477 }
1461 1478
1462 ls->addr = INADDR_ANY; 1479 ls->addr = INADDR_ANY;
1463 #if (NGX_WIN32) 1480 #if (NGX_WIN32)
1468 #endif 1485 #endif
1469 ls->family = AF_INET; 1486 ls->family = AF_INET;
1470 } 1487 }
1471 1488
1472 if (conf->server_names.nelts == 0) { 1489 if (conf->server_names.nelts == 0) {
1473 if (!(sn = ngx_array_push(&conf->server_names))) { 1490 sn = ngx_array_push(&conf->server_names);
1491 if (sn == NULL) {
1474 return NGX_CONF_ERROR; 1492 return NGX_CONF_ERROR;
1475 } 1493 }
1476 1494
1477 if (!(sn->name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN))) { 1495 sn->name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN);
1496 if (sn->name.data == NULL) {
1478 return NGX_CONF_ERROR; 1497 return NGX_CONF_ERROR;
1479 } 1498 }
1480 1499
1481 if (gethostname((char *) sn->name.data, NGX_MAXHOSTNAMELEN) == -1) { 1500 if (gethostname((char *) sn->name.data, NGX_MAXHOSTNAMELEN) == -1) {
1482 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, 1501 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
1526 static void * 1545 static void *
1527 ngx_http_core_create_loc_conf(ngx_conf_t *cf) 1546 ngx_http_core_create_loc_conf(ngx_conf_t *cf)
1528 { 1547 {
1529 ngx_http_core_loc_conf_t *lcf; 1548 ngx_http_core_loc_conf_t *lcf;
1530 1549
1531 if (!(lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)))) { 1550 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
1551 if (lcf == NULL) {
1532 return NGX_CONF_ERROR; 1552 return NGX_CONF_ERROR;
1533 } 1553 }
1534 1554
1535 /* 1555 /*
1536 * set by ngx_pcalloc(): 1556 * set by ngx_pcalloc():
1616 1636
1617 for (i = 0; ngx_http_core_default_types[i].exten.len; i++) { 1637 for (i = 0; ngx_http_core_default_types[i].exten.len; i++) {
1618 ngx_http_types_hash_key(key, 1638 ngx_http_types_hash_key(key,
1619 ngx_http_core_default_types[i].exten); 1639 ngx_http_core_default_types[i].exten);
1620 1640
1621 if (!(type = ngx_array_push(&conf->types[key]))) { 1641 type = ngx_array_push(&conf->types[key]);
1642 if (type == NULL) {
1622 return NGX_CONF_ERROR; 1643 return NGX_CONF_ERROR;
1623 } 1644 }
1624 1645
1625 *type = ngx_http_core_default_types[i]; 1646 *type = ngx_http_core_default_types[i];
1626 } 1647 }
1698 /* 1719 /*
1699 * TODO: check duplicate 'listen' directives, 1720 * TODO: check duplicate 'listen' directives,
1700 * add resolved name to server names ??? 1721 * add resolved name to server names ???
1701 */ 1722 */
1702 1723
1703 if (!(ls = ngx_array_push(&scf->listen))) { 1724 ls = ngx_array_push(&scf->listen);
1725 if (ls == NULL) {
1704 return NGX_CONF_ERROR; 1726 return NGX_CONF_ERROR;
1705 } 1727 }
1706 1728
1707 /* AF_INET only */ 1729 /* AF_INET only */
1708 1730
1794 "in \"%V\" directive", 1816 "in \"%V\" directive",
1795 &value[i], &cmd->name); 1817 &value[i], &cmd->name);
1796 return NGX_CONF_ERROR; 1818 return NGX_CONF_ERROR;
1797 } 1819 }
1798 1820
1799 if (!(sn = ngx_array_push(&scf->server_names))) { 1821 sn = ngx_array_push(&scf->server_names);
1822 if (sn == NULL) {
1800 return NGX_CONF_ERROR; 1823 return NGX_CONF_ERROR;
1801 } 1824 }
1802 1825
1803 sn->name.len = value[i].len; 1826 sn->name.len = value[i].len;
1804 sn->name.data = value[i].data; 1827 sn->name.data = value[i].data;
1906 overwrite = 0; 1929 overwrite = 0;
1907 n = 1; 1930 n = 1;
1908 } 1931 }
1909 1932
1910 for (i = 1; i < cf->args->nelts - n; i++) { 1933 for (i = 1; i < cf->args->nelts - n; i++) {
1911 if (!(err = ngx_array_push(lcf->error_pages))) { 1934 err = ngx_array_push(lcf->error_pages);
1935 if (err == NULL) {
1912 return NGX_CONF_ERROR; 1936 return NGX_CONF_ERROR;
1913 } 1937 }
1914 1938
1915 err->status = ngx_atoi(value[i].data, value[i].len); 1939 err->status = ngx_atoi(value[i].data, value[i].len);
1916 1940
1979 static char * 2003 static char *
1980 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 2004 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1981 { 2005 {
1982 ngx_http_core_loc_conf_t *lcf = conf; 2006 ngx_http_core_loc_conf_t *lcf = conf;
1983 2007
1984 if (!(lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args))) { 2008 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args);
2009 if (lcf->err_log == NULL) {
1985 return NGX_CONF_ERROR; 2010 return NGX_CONF_ERROR;
1986 } 2011 }
1987 2012
1988 return ngx_set_error_log_levels(cf, lcf->err_log); 2013 return ngx_set_error_log_levels(cf, lcf->err_log);
1989 } 2014 }
2019 2044
2020 2045
2021 static ngx_int_t 2046 static ngx_int_t
2022 ngx_http_core_init(ngx_cycle_t *cycle) 2047 ngx_http_core_init(ngx_cycle_t *cycle)
2023 { 2048 {
2024 return ngx_http_core_variables_init(cycle); 2049 return ngx_http_variables_init(cycle);
2025 } 2050 }