X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_url_api.c;h=ccee5b3bf7817a249371c0cedf787c0624d5c2af;hp=459b618b532f551ffbdb73790999b816d5644975;hb=b97243b9bffae6ec360cfa7ea2dd1c7f1c3a556f;hpb=cf9967800843ea01e77b374b4d78fad4bc18a3f6 diff --git a/http_url_api.c b/http_url_api.c index 459b618..ccee5b3 100644 --- a/http_url_api.c +++ b/http_url_api.c @@ -18,27 +18,26 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif - -#ifdef PHP_WIN32 -# include -#elif defined(HAVE_NETDB_H) -# include -#endif - #include "php.h" + +#include "SAPI.h" #include "zend_ini.h" #include "php_output.h" #include "ext/standard/url.h" -#include "SAPI.h" - -#include "phpstr/phpstr.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); /* {{{ char *http_absolute_url(char *) */ @@ -51,20 +50,22 @@ PHP_HTTP_API char *_http_absolute_url_ex( #if defined(PHP_WIN32) || defined(HAVE_NETDB_H) struct servent *se; #endif - php_url *purl, furl = {NULL}; + php_url *purl = NULL, furl; size_t full_len = 0; zval *zhost = NULL; - char *scheme = NULL, *URL = ecalloc(1, HTTP_URI_MAXLEN + 1); + char *scheme = NULL, *uri, *URL; if ((!url || !url_len) && ( (!(url = SG(request_info).request_uri)) || (!(url_len = strlen(SG(request_info).request_uri))))) { - http_error(E_WARNING, HTTP_E_PARAM, "Cannot build an absolute URI if supplied URL and REQUEST_URI is empty"); + http_error(HE_WARNING, HTTP_E_RUNTIME, "Cannot build an absolute URI if supplied URL and REQUEST_URI is empty"); return NULL; } - if (!(purl = php_url_parse((char *) url))) { - http_error_ex(E_WARNING, HTTP_E_PARSE, "Could not parse supplied URL: %s", url); + URL = ecalloc(1, HTTP_URI_MAXLEN + 1); + uri = estrndup(url, url_len); + if (!(purl = php_url_parse(uri))) { + http_error_ex(HE_WARNING, HTTP_E_URL, "Could not parse supplied URL: %s", url); return NULL; } @@ -115,7 +116,7 @@ PHP_HTTP_API char *_http_absolute_url_ex( #define HTTP_URI_STRLCATL(URL, full_len, add_string) HTTP_URI_STRLCAT(URL, full_len, add_string, strlen(add_string)) #define HTTP_URI_STRLCAT(URL, full_len, add_string, add_len) \ if ((full_len += add_len) > HTTP_URI_MAXLEN) { \ - http_error_ex(E_NOTICE, HTTP_E_URL, \ + http_error_ex(HE_NOTICE, HTTP_E_URL, \ "Absolute URI would have exceeded max URI length (%d bytes) - " \ "tried to add %d bytes ('%s')", \ HTTP_URI_MAXLEN, add_len, add_string); \ @@ -123,6 +124,7 @@ PHP_HTTP_API char *_http_absolute_url_ex( efree(scheme); \ } \ php_url_free(purl); \ + efree(uri); \ return URL; \ } else { \ strcat(URL, add_string); \ @@ -172,6 +174,7 @@ PHP_HTTP_API char *_http_absolute_url_ex( efree(scheme); } php_url_free(purl); + efree(uri); return URL; } @@ -194,12 +197,12 @@ PHP_HTTP_API STATUS _http_urlencode_hash_ex(HashTable *hash, zend_bool override_ } if (SUCCESS != http_urlencode_hash_implementation(hash, qstr, arg_sep)) { - phpstr_free(qstr); + phpstr_free(&qstr); return FAILURE; } phpstr_data(qstr, encoded_data, encoded_len); - phpstr_free(qstr); + phpstr_free(&qstr); return SUCCESS; } @@ -215,12 +218,13 @@ PHP_HTTP_API STATUS _http_urlencode_hash_implementation_ex( zval *type TSRMLS_DC) { char *key = NULL, *ekey, *newprefix, *p; - int arg_sep_len, key_len, ekey_len, key_type, newprefix_len; + int arg_sep_len, ekey_len, key_type, newprefix_len; + uint key_len; ulong idx; zval **zdata = NULL, *copyzval; if (!ht || !formstr) { - http_error(E_WARNING, HTTP_E_PARAM, "Invalid parameters"); + http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid parameters"); return FAILURE; } @@ -259,7 +263,7 @@ PHP_HTTP_API STATUS _http_urlencode_hash_implementation_ex( #endif if (zend_hash_get_current_data_ex(ht, (void **)&zdata, NULL) == FAILURE || !zdata || !(*zdata)) { - http_error(E_WARNING, HTTP_E_ENCODE, "Error traversing form data array."); + http_error(HE_WARNING, HTTP_E_ENCODING, "Error traversing form data array."); return FAILURE; } if (Z_TYPE_PP(zdata) == IS_ARRAY || Z_TYPE_PP(zdata) == IS_OBJECT) {