Determine if "url" matches the hostname, scheme and port and path * in "filter". All but the path comparisons are case-insensitive. */
| 31 | * in "filter". All but the path comparisons are case-insensitive. |
| 32 | */ |
| 33 | static int uri_meets_conditions(const apr_uri_t *filter, const apr_size_t pathlen, |
| 34 | const apr_uri_t *url, const char *path) |
| 35 | { |
| 36 | /* Scheme, hostname port and local part. The filter URI and the |
| 37 | * URI we test may have the following shapes: |
| 38 | * /<path> |
| 39 | * <scheme>[:://<hostname>[:<port>][/<path>]] |
| 40 | * That is, if there is no scheme then there must be only the path, |
| 41 | * and we check only the path; if there is a scheme, we check the |
| 42 | * scheme for equality, and then if present we match the hostname, |
| 43 | * and then if present match the port, and finally the path if any. |
| 44 | * |
| 45 | * Note that this means that "/<path>" only matches local paths, |
| 46 | * and to match proxied paths one *must* specify the scheme. |
| 47 | */ |
| 48 | |
| 49 | /* Is the filter is just for a local path or a proxy URI? */ |
| 50 | if (!filter->scheme) { |
| 51 | if (url->scheme || url->hostname) { |
| 52 | return 0; |
| 53 | } |
| 54 | } |
| 55 | else { |
| 56 | /* The URI scheme must be present and identical except for case. */ |
| 57 | if (!url->scheme || ap_cstr_casecmp(filter->scheme, url->scheme)) { |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | /* If the filter hostname is null or empty it matches any hostname, |
| 62 | * if it begins with a "*" it matches the _end_ of the URI hostname |
| 63 | * excluding the "*", if it begins with a "." it matches the _end_ |
| 64 | * of the URI * hostname including the ".", otherwise it must match |
| 65 | * the URI hostname exactly. */ |
| 66 | |
| 67 | if (filter->hostname && filter->hostname[0]) { |
| 68 | if (filter->hostname[0] == '.') { |
| 69 | const size_t fhostlen = strlen(filter->hostname); |
| 70 | const size_t uhostlen = url->hostname ? strlen(url->hostname) : 0; |
| 71 | |
| 72 | if (fhostlen > uhostlen |
| 73 | || (url->hostname |
| 74 | && strcasecmp(filter->hostname, |
| 75 | url->hostname + uhostlen - fhostlen))) { |
| 76 | return 0; |
| 77 | } |
| 78 | } |
| 79 | else if (filter->hostname[0] == '*') { |
| 80 | const size_t fhostlen = strlen(filter->hostname + 1); |
| 81 | const size_t uhostlen = url->hostname ? strlen(url->hostname) : 0; |
| 82 | |
| 83 | if (fhostlen > uhostlen |
| 84 | || (url->hostname |
| 85 | && strcasecmp(filter->hostname + 1, |
| 86 | url->hostname + uhostlen - fhostlen))) { |
| 87 | return 0; |
| 88 | } |
| 89 | } |
| 90 | else if (!url->hostname || strcasecmp(filter->hostname, url->hostname)) { |
no test coverage detected