| 1532 | |
| 1533 | |
| 1534 | static ngx_int_t |
| 1535 | ngx_http_server_names(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf, |
| 1536 | ngx_http_conf_addr_t *addr) |
| 1537 | { |
| 1538 | ngx_int_t rc; |
| 1539 | ngx_uint_t n, s; |
| 1540 | ngx_hash_init_t hash; |
| 1541 | ngx_hash_keys_arrays_t ha; |
| 1542 | ngx_http_server_name_t *name; |
| 1543 | ngx_http_core_srv_conf_t **cscfp; |
| 1544 | #if (NGX_PCRE) |
| 1545 | ngx_uint_t regex, i; |
| 1546 | |
| 1547 | regex = 0; |
| 1548 | #endif |
| 1549 | |
| 1550 | ngx_memzero(&ha, sizeof(ngx_hash_keys_arrays_t)); |
| 1551 | |
| 1552 | ha.temp_pool = ngx_create_pool(NGX_DEFAULT_POOL_SIZE, cf->log); |
| 1553 | if (ha.temp_pool == NULL) { |
| 1554 | return NGX_ERROR; |
| 1555 | } |
| 1556 | |
| 1557 | ha.pool = cf->pool; |
| 1558 | |
| 1559 | if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) { |
| 1560 | goto failed; |
| 1561 | } |
| 1562 | |
| 1563 | cscfp = addr->servers.elts; |
| 1564 | |
| 1565 | for (s = 0; s < addr->servers.nelts; s++) { |
| 1566 | |
| 1567 | name = cscfp[s]->server_names.elts; |
| 1568 | |
| 1569 | for (n = 0; n < cscfp[s]->server_names.nelts; n++) { |
| 1570 | |
| 1571 | #if (NGX_PCRE) |
| 1572 | if (name[n].regex) { |
| 1573 | regex++; |
| 1574 | continue; |
| 1575 | } |
| 1576 | #endif |
| 1577 | |
| 1578 | rc = ngx_hash_add_key(&ha, &name[n].name, name[n].server, |
| 1579 | NGX_HASH_WILDCARD_KEY); |
| 1580 | |
| 1581 | if (rc == NGX_ERROR) { |
| 1582 | goto failed; |
| 1583 | } |
| 1584 | |
| 1585 | if (rc == NGX_DECLINED) { |
| 1586 | ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
| 1587 | "invalid server name or wildcard \"%V\" on %V", |
| 1588 | &name[n].name, &addr->opt.addr_text); |
| 1589 | goto failed; |
| 1590 | } |
| 1591 |
no test coverage detected