From: Michael Wallner Date: Fri, 19 May 2006 09:54:57 +0000 (+0000) Subject: - add HTTP_URL_STRIP_ALL constant X-Git-Tag: RELEASE_1_0_0~28 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=5773d11d8c9c28fb8b0e3389258f548fc4717892;p=m6w6%2Fext-http - add HTTP_URL_STRIP_ALL constant - recognize HTTPS server variable - simplify building urls where path is based on SG(request_).request_uri --- diff --git a/http_url_api.c b/http_url_api.c index 1ccd4db..827c7b6 100644 --- a/http_url_api.c +++ b/http_url_api.c @@ -62,6 +62,7 @@ PHP_MINIT_FUNCTION(http_url) HTTP_LONG_CONSTANT("HTTP_URL_STRIP_PATH", HTTP_URL_STRIP_PATH); HTTP_LONG_CONSTANT("HTTP_URL_STRIP_QUERY", HTTP_URL_STRIP_QUERY); HTTP_LONG_CONSTANT("HTTP_URL_STRIP_FRAGMENT", HTTP_URL_STRIP_FRAGMENT); + HTTP_LONG_CONSTANT("HTTP_URL_STRIP_ALL", HTTP_URL_STRIP_ALL); return SUCCESS; } @@ -156,6 +157,10 @@ PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_u } if (!url->scheme) { + zval *https = http_get_server_var("HTTPS"); + if (https && !strcasecmp(Z_STRVAL_P(https), "ON")) { + url->scheme = estrndup("https", lenof("https")); + } else switch (url->port) { case 443: @@ -193,7 +198,7 @@ PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_u } if (!url->path) { - if (SG(request_info).request_uri && *SG(request_info).request_uri) { + if (SG(request_info).request_uri && SG(request_info).request_uri[0]) { const char *q = strchr(SG(request_info).request_uri, '?'); if (q) { @@ -204,30 +209,23 @@ PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_u } else { url->path = estrndup("/", 1); } - } else if (*url->path != '/') { - if (SG(request_info).request_uri && *SG(request_info).request_uri) { - const char *q = strchr(SG(request_info).request_uri, '?'); - char *uri, *path; - size_t len; - - if (q) { - uri = estrndup(SG(request_info).request_uri, len = q - SG(request_info).request_uri); - } else { - uri = estrndup(SG(request_info).request_uri, len = strlen(SG(request_info).request_uri)); - } - - php_dirname(uri, len); - spprintf(&path, 0, "%s/%s", uri, url->path); - efree(uri); - STR_SET(url->path, path); - } else { - char *uri; - - spprintf(&uri, 0, "/%s", url->path); - STR_SET(url->path, uri); + } else if (url->path[0] != '/' && SG(request_info).request_uri && SG(request_info).request_uri[0]) { + size_t ulen = strlen(SG(request_info).request_uri); + size_t plen = strlen(url->path); + char *path; + + if (SG(request_info).request_uri[ulen-1] != '/') { + for (--ulen; ulen && SG(request_info).request_uri[ulen - 1] != '/'; --ulen); } + + path = emalloc(ulen + plen + 1); + memcpy(path, SG(request_info).request_uri, ulen); + memcpy(path + ulen, url->path, plen); + path[ulen + plen] = '\0'; + STR_SET(url->path, path); } - if (url->path) { + /* replace directory references if path is not a single slash */ + if (url->path[0] && (url->path[0] != '/' || url->path[1])) { char *ptr, *end = url->path + strlen(url->path) + 1; for (ptr = strstr(url->path, "/."); ptr; ptr = strstr(ptr, "/.")) { diff --git a/php_http_url_api.h b/php_http_url_api.h index cc7951d..fbb4ae1 100644 --- a/php_http_url_api.h +++ b/php_http_url_api.h @@ -32,6 +32,13 @@ PHP_HTTP_API char *_http_absolute_url(const char *url TSRMLS_DC); #define HTTP_URL_STRIP_PATH 0x040 #define HTTP_URL_STRIP_QUERY 0x080 #define HTTP_URL_STRIP_FRAGMENT 0x100 +#define HTTP_URL_STRIP_ALL ( \ + HTTP_URL_STRIP_AUTH | \ + HTTP_URL_STRIP_PORT | \ + HTTP_URL_STRIP_PATH | \ + HTTP_URL_STRIP_QUERY | \ + HTTP_URL_STRIP_FRAGMENT \ +) #define http_build_url(f, o, n, p, s, l) _http_build_url((f), (o), (n), (p), (s), (l) TSRMLS_CC) PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_url *new_url, php_url **url_ptr, char **url_str, size_t *url_len TSRMLS_DC);