#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-
-#ifdef PHP_WIN32
-# include <winsock2.h>
-#elif defined(HAVE_NETDB_H)
-# include <netdb.h>
-#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 <winsock2.h>
+#elif defined(HAVE_NETDB_H)
+# include <netdb.h>
+#endif
+
ZEND_EXTERN_MODULE_GLOBALS(http);
/* {{{ char *http_absolute_url(char *) */
php_url *purl, furl = {NULL};
size_t full_len = 0;
zval *zhost = NULL;
- char *scheme = NULL, *URL = ecalloc(1, HTTP_URI_MAXLEN + 1);
+ char *scheme = NULL, *uri, *URL = ecalloc(1, HTTP_URI_MAXLEN + 1);
if ((!url || !url_len) && (
(!(url = SG(request_info).request_uri)) ||
(!(url_len = strlen(SG(request_info).request_uri))))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
- "Cannot build an absolute URI if supplied URL and REQUEST_URI is empty");
+ http_error(E_WARNING, HTTP_E_PARAM, "Cannot build an absolute URI if supplied URL and REQUEST_URI is empty");
return NULL;
}
- if (!(purl = php_url_parse((char *) url))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse supplied URL");
+ uri = estrndup(url, url_len);
+ if (!(purl = php_url_parse(uri))) {
+ http_error_ex(E_WARNING, HTTP_E_PARSE, "Could not parse supplied URL: %s", url);
return NULL;
}
#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) { \
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, \
+ http_error_ex(E_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); \
efree(scheme); \
} \
php_url_free(purl); \
+ efree(uri); \
return URL; \
} else { \
strcat(URL, add_string); \
efree(scheme);
}
php_url_free(purl);
+ efree(uri);
return URL;
}
}
if (SUCCESS != http_urlencode_hash_implementation(hash, qstr, arg_sep)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't encode query data");
phpstr_free(qstr);
return FAILURE;
}
zval **zdata = NULL, *copyzval;
if (!ht || !formstr) {
+ http_error(E_WARNING, HTTP_E_PARAM, "Invalid parameters");
return FAILURE;
}
#endif
if (zend_hash_get_current_data_ex(ht, (void **)&zdata, NULL) == FAILURE || !zdata || !(*zdata)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error traversing form data array.");
+ http_error(E_WARNING, HTTP_E_ENCODE, "Error traversing form data array.");
return FAILURE;
}
if (Z_TYPE_PP(zdata) == IS_ARRAY || Z_TYPE_PP(zdata) == IS_OBJECT) {