MCPcopy Create free account
hub / github.com/apache/httpd / ap_core_translate

Function ap_core_translate

server/core.c:4764–4814  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4762 */
4763
4764AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r)
4765{
4766 apr_status_t rv;
4767 char *path;
4768
4769 /* XXX this seems too specific, this should probably become
4770 * some general-case test
4771 */
4772 if (r->proxyreq) {
4773 return HTTP_FORBIDDEN;
4774 }
4775 if (!r->uri || ((r->uri[0] != '/') && strcmp(r->uri, "*"))) {
4776 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00126)
4777 "Invalid URI in request '%s' '%s'", r->uri, r->the_request);
4778 return HTTP_BAD_REQUEST;
4779 }
4780
4781 if (r->server->path
4782 && !strncmp(r->uri, r->server->path, r->server->pathlen)
4783 && (r->server->path[r->server->pathlen - 1] == '/'
4784 || r->uri[r->server->pathlen] == '/'
4785 || r->uri[r->server->pathlen] == '\0'))
4786 {
4787 path = r->uri + r->server->pathlen;
4788 }
4789 else {
4790 path = r->uri;
4791 }
4792 /*
4793 * Make sure that we do not mess up the translation by adding two
4794 * /'s in a row. This happens under windows when the document
4795 * root ends with a /
4796 */
4797 /* skip all leading /'s (e.g. http://localhost///foo)
4798 * so we are looking at only the relative path.
4799 */
4800 while (*path == '/') {
4801 ++path;
4802 }
4803 if ((rv = apr_filepath_merge(&r->filename, ap_document_root(r), path,
4804 APR_FILEPATH_TRUENAME
4805 | APR_FILEPATH_SECUREROOT, r->pool))
4806 != APR_SUCCESS) {
4807 ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00127)
4808 "Cannot map %s to file", r->the_request);
4809 return HTTP_FORBIDDEN;
4810 }
4811 r->canonical_filename = r->filename;
4812
4813 return OK;
4814}
4815
4816/*****************************************************************
4817 *

Callers 4

file_cache_xlatFunction · 0.85
send_environmentFunction · 0.85
hook_uri2fileFunction · 0.85
http_core.hFile · 0.85

Calls 1

ap_document_rootFunction · 0.85

Tested by

no test coverage detected