X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_api.c;h=af42cd5e641cb68a785d72176a967899e78abd92;hp=edeb00b34c1249f37857ca0e09487763134eeeec;hb=074b1d2872d6ce1c7e35fe365aee9cf39ecace24;hpb=a9bf30098351bc77da5171ac420f4b55d8d07647 diff --git a/http_api.c b/http_api.c index edeb00b..af42cd5 100644 --- a/http_api.c +++ b/http_api.c @@ -24,6 +24,12 @@ #include +#ifdef PHP_WIN32 +# include +#elif defined(HAVE_NETDB_H) +# include +#endif + #include "php.h" #include "php_version.h" #include "php_streams.h" @@ -886,7 +892,7 @@ PHP_HTTP_API char *_http_absolute_uri_ex( const char *host, size_t host_len, unsigned port TSRMLS_DC) { -#ifdef ZEND_ENGINE_2 +#if defined(PHP_WIN32) || defined(HAVE_NETDB_H) struct servent *se; #endif php_url *purl, furl = {NULL}; @@ -917,8 +923,8 @@ PHP_HTTP_API char *_http_absolute_uri_ex( furl.scheme = scheme = estrdup(proto); } else if (purl->scheme) { furl.scheme = purl->scheme; -#ifdef ZEND_ENGINE_2 - } else if (port && (se = getservbyport(htons(port), "tcp"))) { +#if defined(PHP_WIN32) || defined(HAVE_NETDB_H) + } else if (port && (se = getservbyport(port, "tcp"))) { furl.scheme = (scheme = estrdup(se->s_name)); #endif } else { @@ -930,9 +936,9 @@ PHP_HTTP_API char *_http_absolute_uri_ex( } else if (purl->port) { furl.port = purl->port; } else if (strncmp(furl.scheme, "http", 4)) { -#ifdef ZEND_ENGINE_2 +#if defined(PHP_WIN32) || defined(HAVE_NETDB_H) if (se = getservbyname(furl.scheme, "tcp")) { - furl.port = ntohs(se->s_port); + furl.port = se->s_port; } else #endif furl.port = 80; @@ -982,14 +988,17 @@ PHP_HTTP_API char *_http_absolute_uri_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 ( (!strcmp(furl.scheme, "http") && (furl.port != 80)) || + (!strcmp(furl.scheme, "https") && (furl.port != 443))) { char port_string[8] = {0}; snprintf(port_string, 7, ":%u", furl.port); HTTP_URI_STRLCATL(URL, full_len, port_string); } if (furl.path) { + if (furl.path[0] != '/') { + HTTP_URI_STRLCATS(URL, full_len, "/"); + } HTTP_URI_STRLCATL(URL, full_len, furl.path); } else { HTTP_URI_STRLCATS(URL, full_len, "/"); @@ -1456,7 +1465,7 @@ PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, PHP_HTTP_API STATUS _http_split_response(zval *response, zval *headers, zval *body TSRMLS_DC) { char *b = NULL; - long l = 0; + size_t l = 0; STATUS status = http_split_response_ex(Z_STRVAL_P(response), Z_STRLEN_P(response), Z_ARRVAL_P(headers), &b, &l); ZVAL_STRINGL(body, b, l, 0); return status;