X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_url_api.c;h=60fc11ffb19e086b114a64e10f3a471a2f1cdb0e;hb=1ec34f462819d4a10badd83d8493403b6c0c6e68;hp=827c7b6a2c5d6c1db62c459deb9af71ed7aaa011;hpb=5773d11d8c9c28fb8b0e3389258f548fc4717892;p=m6w6%2Fext-http diff --git a/http_url_api.c b/http_url_api.c index 827c7b6..60fc11f 100644 --- a/http_url_api.c +++ b/http_url_api.c @@ -105,10 +105,10 @@ PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_u if (!(flags & HTTP_URL_STRIP_PORT)) { url->port = (new_url&&new_url->port) ? new_url->port : ((old_url) ? old_url->port : 0); } - if ((!(flags & HTTP_URL_STRIP_AUTH)) && (!(flags & HTTP_URL_STRIP_USER))) { + if (!(flags & HTTP_URL_STRIP_USER)) { __URLCPY(user); } - if ((!(flags & HTTP_URL_STRIP_AUTH)) && (!(flags & HTTP_URL_STRIP_PASS))) { + if (!(flags & HTTP_URL_STRIP_PASS)) { __URLCPY(pass); } @@ -160,19 +160,17 @@ PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_u 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) - { + } else switch (url->port) { case 443: url->scheme = estrndup("https", lenof("https")); - break; + break; #ifndef HTTP_HAVE_NETDB default: #endif case 80: url->scheme = estrndup("http", lenof("http")); - break; + break; #ifdef HTTP_HAVE_NETDB default: @@ -181,7 +179,7 @@ PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_u } else { url->scheme = estrndup("http", lenof("http")); } - break; + break; #endif } } @@ -209,35 +207,43 @@ 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[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); + } else if (url->path[0] != '/') { + if (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); + } else { + size_t plen = strlen(url->path); + char *path = emalloc(plen + 1 + 1); + + path[0] = '/'; + memcpy(&path[1], url->path, plen + 1); + STR_SET(url->path, path); } - - 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); } /* 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, "/.")) { - switch (ptr[2]) - { + switch (ptr[2]) { case '\0': ptr[1] = '\0'; - break; + break; case '/': memmove(&ptr[1], &ptr[3], end - &ptr[3]); - break; + break; case '.': if (ptr[3] == '/') { @@ -249,12 +255,12 @@ PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_u } memmove(&ptr[1], pos, end - pos); } - break; + break; default: /* something else */ ++ptr; - break; + break; } } } @@ -299,9 +305,6 @@ PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_u strlcat(*url_str, port_str, HTTP_URL_MAXLEN); } - if (*url->path != '/') { - strlcat(*url_str, "/", HTTP_URL_MAXLEN); - } strlcat(*url_str, url->path, HTTP_URL_MAXLEN); if (url->query && *url->query) {