| 948 | } |
| 949 | |
| 950 | static void map_link(link_ctx *ctx) |
| 951 | { |
| 952 | if (ctx->link_start < ctx->link_end) { |
| 953 | char buffer[HUGE_STRING_LEN]; |
| 954 | size_t need_len, link_len, buffer_len, prepend_p_server; |
| 955 | const char *mapped; |
| 956 | |
| 957 | buffer[0] = '\0'; |
| 958 | buffer_len = 0; |
| 959 | link_len = ctx->link_end - ctx->link_start; |
| 960 | need_len = link_len + 1; |
| 961 | prepend_p_server = (ctx->s[ctx->link_start] == '/'); |
| 962 | if (prepend_p_server) { |
| 963 | /* common to use relative uris in link header, for mappings |
| 964 | * to work need to prefix the backend server uri */ |
| 965 | need_len += ctx->psu_len; |
| 966 | apr_cpystrn(buffer, ctx->p_server_uri, sizeof(buffer)); |
| 967 | buffer_len = ctx->psu_len; |
| 968 | } |
| 969 | if (need_len > sizeof(buffer)) |
| 970 | goto out; |
| 971 | apr_cpystrn(buffer + buffer_len, ctx->s + ctx->link_start, link_len + 1); |
| 972 | if (!prepend_p_server |
| 973 | && strcmp(ctx->real_backend_uri, ctx->p_server_uri) |
| 974 | && !strncmp(buffer, ctx->real_backend_uri, ctx->rbu_len)) { |
| 975 | /* the server uri and our local proxy uri we use differ, for mapping |
| 976 | * to work, we need to use the proxy uri */ |
| 977 | int path_start = ctx->link_start + ctx->rbu_len; |
| 978 | link_len -= ctx->rbu_len; |
| 979 | need_len = ctx->psu_len + link_len; |
| 980 | if (need_len > sizeof(buffer)) |
| 981 | goto out; |
| 982 | memcpy(buffer, ctx->p_server_uri, ctx->psu_len); |
| 983 | memcpy(buffer + ctx->psu_len, ctx->s + path_start, link_len); |
| 984 | buffer_len = ctx->psu_len + link_len; |
| 985 | buffer[buffer_len] = '\0'; |
| 986 | } |
| 987 | mapped = ap_proxy_location_reverse_map(ctx->r, ctx->conf, buffer); |
| 988 | ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, ctx->r, |
| 989 | "reverse_map[%s] %s --> %s", ctx->p_server_uri, buffer, mapped); |
| 990 | if (mapped != buffer) { |
| 991 | if (prepend_p_server) { |
| 992 | if (ctx->server_uri == NULL) { |
| 993 | ctx->server_uri = ap_construct_url(ctx->pool, "", ctx->r); |
| 994 | ctx->su_len = (int)strlen(ctx->server_uri); |
| 995 | } |
| 996 | if (!strncmp(mapped, ctx->server_uri, ctx->su_len)) { |
| 997 | mapped += ctx->su_len; |
| 998 | } |
| 999 | } |
| 1000 | subst_str(ctx, ctx->link_start, ctx->link_end, mapped); |
| 1001 | } |
| 1002 | out: |
| 1003 | if (need_len > sizeof(buffer)) { |
| 1004 | ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, ctx->r, APLOGNO(03482) |
| 1005 | "link_reverse_map uri too long, skipped: %s", ctx->s); |
| 1006 | } |
| 1007 | } |
no test coverage detected