comparison src/http/ngx_http.c @ 2138:fb3b084e7d42

test Content-Type via hash: *) ngx_http_test_content_type() *) ngx_http_types_slot() *) ngx_http_merge_types()
author Igor Sysoev <igor@sysoev.ru>
date Mon, 04 Aug 2008 11:29:09 +0000
parents 8c6521eedf84
children 723df5089c05
comparison
equal deleted inserted replaced
2137:76d5af541412 2138:fb3b084e7d42
1685 a = 0; 1685 a = 0;
1686 } 1686 }
1687 1687
1688 return NGX_OK; 1688 return NGX_OK;
1689 } 1689 }
1690
1691
1692 char *
1693 ngx_http_types_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1694 {
1695 char *p = conf;
1696
1697 ngx_array_t **types;
1698 ngx_str_t *value, *default_type;
1699 ngx_uint_t i, n, hash;
1700 ngx_hash_key_t *type;
1701
1702 types = (ngx_array_t **) (p + cmd->offset);
1703
1704 default_type = cmd->post;
1705
1706 if (*types == NULL) {
1707 *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t));
1708 if (*types == NULL) {
1709 return NGX_CONF_ERROR;
1710 }
1711
1712 if (default_type) {
1713 type = ngx_array_push(*types);
1714 if (type == NULL) {
1715 return NGX_CONF_ERROR;
1716 }
1717
1718 type->key = *default_type;
1719 type->key_hash = ngx_hash_key(default_type->data,
1720 default_type->len);
1721 type->value = (void *) 4;
1722 }
1723 }
1724
1725 value = cf->args->elts;
1726
1727 for (i = 1; i < cf->args->nelts; i++) {
1728
1729 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
1730 value[i].data[value[i].len] = '\0';
1731
1732 type = (*types)->elts;
1733 for (n = 0; n < (*types)->nelts; n++) {
1734
1735 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
1736 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
1737 "duplicate MIME type \"%V\"", &value[i]);
1738 continue;
1739 }
1740 }
1741
1742 type = ngx_array_push(*types);
1743 if (type == NULL) {
1744 return NGX_CONF_ERROR;
1745 }
1746
1747 type->key = value[i];
1748 type->key_hash = hash;
1749 type->value = (void *) 4;
1750 }
1751
1752 return NGX_CONF_OK;
1753 }
1754
1755
1756 char *
1757 ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t *keys, ngx_hash_t *types_hash,
1758 ngx_array_t *prev_keys, ngx_hash_t *prev_types_hash,
1759 ngx_str_t *default_types)
1760 {
1761 ngx_hash_init_t hash;
1762
1763 if (keys == NULL) {
1764
1765 if (prev_keys) {
1766 *types_hash = *prev_types_hash;
1767 return NGX_CONF_OK;
1768 }
1769
1770 if (ngx_http_set_default_types(cf, &keys, default_types)
1771 != NGX_CONF_OK)
1772 {
1773 return NGX_CONF_ERROR;
1774 }
1775 }
1776
1777 hash.hash = types_hash;
1778 hash.key = NULL;
1779 hash.max_size = 2048;
1780 hash.bucket_size = 64;
1781 hash.name = "test_types_hash";
1782 hash.pool = cf->pool;
1783 hash.temp_pool = NULL;
1784
1785 if (ngx_hash_init(&hash, keys->elts, keys->nelts) != NGX_OK) {
1786 return NGX_CONF_ERROR;
1787 }
1788
1789 return NGX_CONF_OK;
1790
1791 }
1792
1793
1794 char *
1795 ngx_http_set_default_types(ngx_conf_t *cf, ngx_array_t **types,
1796 ngx_str_t *default_type)
1797 {
1798 ngx_hash_key_t *type;
1799
1800 *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t));
1801 if (*types == NULL) {
1802 return NGX_CONF_ERROR;
1803 }
1804
1805 while (default_type->len) {
1806
1807 type = ngx_array_push(*types);
1808 if (type == NULL) {
1809 return NGX_CONF_ERROR;
1810 }
1811
1812 type->key = *default_type;
1813 type->key_hash = ngx_hash_key(default_type->data,
1814 default_type->len);
1815 type->value = (void *) 4;
1816
1817 default_type++;
1818 }
1819
1820 return NGX_CONF_OK;
1821 }