* generic map lookup */
| 1742 | * generic map lookup |
| 1743 | */ |
| 1744 | static char *lookup_map(request_rec *r, char *name, char *key) |
| 1745 | { |
| 1746 | rewrite_server_conf *conf; |
| 1747 | rewritemap_entry *s; |
| 1748 | char *value; |
| 1749 | apr_finfo_t st; |
| 1750 | apr_status_t rv; |
| 1751 | |
| 1752 | /* get map configuration */ |
| 1753 | conf = ap_get_module_config(r->server->module_config, &rewrite_module); |
| 1754 | s = apr_hash_get(conf->rewritemaps, name, APR_HASH_KEY_STRING); |
| 1755 | |
| 1756 | /* map doesn't exist */ |
| 1757 | if (!s) { |
| 1758 | return NULL; |
| 1759 | } |
| 1760 | |
| 1761 | switch (s->type) { |
| 1762 | /* |
| 1763 | * Text file map (perhaps random) |
| 1764 | */ |
| 1765 | case MAPTYPE_RND: |
| 1766 | case MAPTYPE_TXT: |
| 1767 | rv = apr_stat(&st, s->checkfile, APR_FINFO_MIN, r->pool); |
| 1768 | if (rv != APR_SUCCESS) { |
| 1769 | ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00661) |
| 1770 | "mod_rewrite: can't access text RewriteMap file %s", |
| 1771 | s->checkfile); |
| 1772 | return NULL; |
| 1773 | } |
| 1774 | |
| 1775 | value = get_cache_value(s->cachename, st.mtime, key, r->pool); |
| 1776 | if (!value) { |
| 1777 | rewritelog(r, 6, NULL, |
| 1778 | "cache lookup FAILED, forcing new map lookup"); |
| 1779 | |
| 1780 | value = lookup_map_txtfile(r, s->datafile, key); |
| 1781 | if (!value) { |
| 1782 | rewritelog(r, 5, NULL, "map lookup FAILED: map=%s[txt] key=%s", |
| 1783 | name, key); |
| 1784 | set_cache_value(s->cachename, st.mtime, key, ""); |
| 1785 | return NULL; |
| 1786 | } |
| 1787 | |
| 1788 | rewritelog(r, 5, NULL, "map lookup OK: map=%s[txt] key=%s -> val=%s", |
| 1789 | name, key, value); |
| 1790 | set_cache_value(s->cachename, st.mtime, key, value); |
| 1791 | } |
| 1792 | else { |
| 1793 | rewritelog(r, 5, NULL, "cache lookup OK: map=%s[txt] key=%s -> val=%s", |
| 1794 | name, key, value); |
| 1795 | } |
| 1796 | |
| 1797 | if (s->type == MAPTYPE_RND && *value) { |
| 1798 | value = select_random_value_part(r, value); |
| 1799 | rewritelog(r, 5, NULL, "randomly chosen the subvalue `%s'",value); |
| 1800 | } |
| 1801 |
no test coverage detected