* If a port is pecified in either the url or as sperate parameter,
* it will be added if it differs from te default port for HTTP(S).
*
- * Returns the absolute URI as string.
+ * Returns the absolute URI as string on success or false on failure.
*
* Examples:
* <pre>
*/
PHP_FUNCTION(http_build_uri)
{
- char *url = NULL, *proto = NULL, *host = NULL;
+ char *url = NULL, *proto = NULL, *host = NULL, *built = NULL;
int url_len = 0, proto_len = 0, host_len = 0;
long port = 0;
RETURN_FALSE;
}
- RETURN_STRING(http_absolute_uri_ex(url, url_len, proto, proto_len, host, host_len, port), 0);
+ if ((built = http_absolute_uri_ex(url, url_len, proto, proto_len, host, host_len, port))) {
+ RETURN_STRING(built, 0);
+ }
+ RETURN_FALSE;
}
/* }}} */
} 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(port), "tcp"))) {
furl.scheme = (scheme = estrdup(se->s_name));
#endif
} else {
furl.port = port;
} else if (purl->port) {
furl.port = purl->port;
- } else if (strncmp(furl.scheme, "http", 4)) {
+ } else if ((!furl.scheme) || strncmp(furl.scheme, "http", 4)) {
#if defined(PHP_WIN32) || defined(HAVE_NETDB_H)
if ((se = getservbyname(furl.scheme, "tcp"))) {
- furl.port = se->s_port;
+ furl.port = ntohs(se->s_port);
}
#endif
} else {
- furl.port = (furl.scheme[4] == 's') ? 443 : 80;
+ furl.port = (furl.scheme && furl.scheme[4] == 's') ? 443 : 80;
}
- if (host) {
+ if (host && host_len) {
furl.host = (char *) host;
} else if (purl->host) {
furl.host = purl->host;