X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_url_api.c;h=4f20de5e847c1117d0cec3d4c830606b15f8cdb7;hb=3706c9ddb362d54d409506010952a0129e78e5e9;hp=aa0c1f37c835692631866bd1083565604c39a6d6;hpb=0fba8595e6e2de88cad39460340d620a089c55ed;p=m6w6%2Fext-http diff --git a/http_url_api.c b/http_url_api.c index aa0c1f3..4f20de5 100644 --- a/http_url_api.c +++ b/http_url_api.c @@ -15,25 +15,17 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include "php.h" + +#define HTTP_WANT_NETDB +#include "php_http.h" #include "SAPI.h" #include "zend_ini.h" #include "php_output.h" #include "ext/standard/url.h" -#include "php_http.h" #include "php_http_api.h" #include "php_http_url_api.h" -#include "php_http_std_defs.h" - -#include "phpstr/phpstr.h" - -#ifdef PHP_WIN32 -# include -#elif defined(HAVE_NETDB_H) -# include -#endif ZEND_EXTERN_MODULE_GLOBALS(http); @@ -59,13 +51,15 @@ PHP_HTTP_API char *_http_absolute_url_ex( return NULL; } - URL = ecalloc(1, HTTP_URI_MAXLEN + 1); uri = estrndup(url, url_len); if (!(purl = php_url_parse(uri))) { + efree(uri); http_error_ex(HE_WARNING, HTTP_E_URL, "Could not parse supplied URL: %s", url); return NULL; } + URL = ecalloc(1, HTTP_URI_MAXLEN + 1); + furl.user = purl->user; furl.pass = purl->pass; furl.path = purl->path; @@ -77,7 +71,7 @@ PHP_HTTP_API char *_http_absolute_url_ex( } else if (purl->scheme) { furl.scheme = purl->scheme; #if defined(PHP_WIN32) || defined(HAVE_NETDB_H) - } else if (port && (se = getservbyport(port, "tcp"))) { + } else if (port && (se = getservbyport(htons((short) port), "tcp"))) { furl.scheme = (scheme = estrdup(se->s_name)); #endif } else { @@ -90,15 +84,16 @@ PHP_HTTP_API char *_http_absolute_url_ex( furl.port = purl->port; } else if (strncmp(furl.scheme, "http", 4)) { #if defined(PHP_WIN32) || defined(HAVE_NETDB_H) - if (se = getservbyname(furl.scheme, "tcp")) { - furl.port = se->s_port; + if ((se = getservbyname(furl.scheme, "tcp"))) { + furl.port = ntohs(se->s_port); } #endif + furl.port = 0; } else { furl.port = (furl.scheme[4] == 's') ? 443 : 80; } - if (host) { + if (host && host_len) { furl.host = (char *) host; } else if (purl->host) { furl.host = purl->host; @@ -141,8 +136,13 @@ PHP_HTTP_API char *_http_absolute_url_ex( HTTP_URI_STRLCATL(URL, full_len, furl.host); - if ( (!strcmp(furl.scheme, "http") && (furl.port != 80)) || - (!strcmp(furl.scheme, "https") && (furl.port != 443))) { + if (furl.port && ( + (!strcmp(furl.scheme, "http") && (furl.port != 80)) || + (!strcmp(furl.scheme, "https") && (furl.port != 443)) +#if defined(PHP_WIN32) || defined(HAVE_NETDB_H) + || ((!(se = getservbyname(furl.scheme, "tcp"))) || (ntohs(se->s_port) != furl.port)) +#endif + )) { char port_string[8] = {0}; snprintf(port_string, 7, ":%u", furl.port); HTTP_URI_STRLCATL(URL, full_len, port_string); @@ -214,6 +214,7 @@ PHP_HTTP_API STATUS _http_urlencode_hash_recursive(HashTable *ht, phpstr *str, c uint len = 0; ulong idx = 0; zval **data = NULL; + HashPosition pos; if (!ht || !str) { http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid parameters"); @@ -223,7 +224,7 @@ PHP_HTTP_API STATUS _http_urlencode_hash_recursive(HashTable *ht, phpstr *str, c return SUCCESS; } - FOREACH_HASH_KEYLENVAL(ht, key, len, idx, data) { + FOREACH_HASH_KEYLENVAL(pos, ht, key, len, idx, data) { char *encoded_key; int encoded_len; phpstr new_prefix;