| modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+
| modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+
/* {{{ http_request_body *http_request_body_new() */
PHP_HTTP_API http_request_body *_http_request_body_init_ex(http_request_body *body, int type, void *data, size_t size, zend_bool free ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
{
/* {{{ http_request_body *http_request_body_new() */
PHP_HTTP_API http_request_body *_http_request_body_init_ex(http_request_body *body, int type, void *data, size_t size, zend_bool free ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
{
- FOREACH_HASH_KEYVAL(pos, fields, key, idx, data) {
- CURLcode err;
- if (key) {
- zval *orig = *data;
-
- convert_to_string_ex(data);
- err = curl_formadd(&http_post_data[0], &http_post_data[1],
- CURLFORM_COPYNAME, key,
- CURLFORM_COPYCONTENTS, Z_STRVAL_PP(data),
- CURLFORM_CONTENTSLENGTH, (long) Z_STRLEN_PP(data),
- CURLFORM_END
- );
-
- if (orig != *data) {
- zval_ptr_dtor(data);
- }
-
- if (CURLE_OK != err) {
- http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post fields: %s", curl_easy_strerror(err));
- curl_formfree(http_post_data[0]);
- return NULL;
+ if (fields) {
+ FOREACH_HASH_KEYVAL(pos, fields, key, idx, data) {
+ if (key) {
+ CURLcode err;
+ zval *orig = *data;
+
+ convert_to_string_ex(data);
+ err = curl_formadd(&http_post_data[0], &http_post_data[1],
+ CURLFORM_COPYNAME, key,
+ CURLFORM_COPYCONTENTS, Z_STRVAL_PP(data),
+ CURLFORM_CONTENTSLENGTH, (long) Z_STRLEN_PP(data),
+ CURLFORM_END
+ );
+
+ if (orig != *data) {
+ zval_ptr_dtor(data);
+ }
+
+ if (CURLE_OK != err) {
+ http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post fields: %s", curl_easy_strerror(err));
+ curl_formfree(http_post_data[0]);
+ return NULL;
+ }
+
+ /* reset */
+ key = NULL;
SUCCESS != zend_hash_find(Z_ARRVAL_PP(data), "file", sizeof("file"), (void **) &file)) {
http_error(HE_NOTICE, HTTP_E_INVALID_PARAM, "Post file array entry misses either 'name', 'type' or 'file' entry");
} else {
SUCCESS != zend_hash_find(Z_ARRVAL_PP(data), "file", sizeof("file"), (void **) &file)) {
http_error(HE_NOTICE, HTTP_E_INVALID_PARAM, "Post file array entry misses either 'name', 'type' or 'file' entry");
} else {
- CURLcode err = curl_formadd(&http_post_data[0], &http_post_data[1],
+ CURLcode err;
+ const char *path;
+ zval *ofile = *file, *otype = *type, *oname = *name;
+
+ convert_to_string_ex(file);
+ convert_to_string_ex(type);
+ convert_to_string_ex(name);
+
+ HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_PP(file), curl_formfree(http_post_data[0]); return NULL);
+
+ /* this is blatant but should be sufficient for most cases */
+ if (strncasecmp(Z_STRVAL_PP(file), "file://", lenof("file://"))) {
+ path = Z_STRVAL_PP(file);
+ } else {
+ path = Z_STRVAL_PP(file) + lenof("file://");
+ }
+
+ err = curl_formadd(&http_post_data[0], &http_post_data[1],
if (CURLE_OK != err) {
http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post files: %s", curl_easy_strerror(err));
curl_formfree(http_post_data[0]);
if (CURLE_OK != err) {
http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post files: %s", curl_easy_strerror(err));
curl_formfree(http_post_data[0]);
- return http_request_body_init_ex(body, HTTP_REQUEST_BODY_CURLPOST, http_post_data[0], 0, 1);
+ return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CURLPOST, http_post_data[0], 0, 1);
- return http_request_body_init_ex(body, HTTP_REQUEST_BODY_CSTRING, encoded, encoded_len, 1);
+ return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CSTRING, encoded, encoded_len, 1);
+ } else {
+ return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CSTRING, estrndup("", 0), 0, 1);
/* {{{ void http_request_body_dtor(http_request_body *) */
PHP_HTTP_API void _http_request_body_dtor(http_request_body *body TSRMLS_DC)
{
/* {{{ void http_request_body_dtor(http_request_body *) */
PHP_HTTP_API void _http_request_body_dtor(http_request_body *body TSRMLS_DC)
{
- if (body && body->free) {
- switch (body->type)
- {
- case HTTP_REQUEST_BODY_CSTRING:
- if (body->data) {
- efree(body->data);
- }
- break;
-
- case HTTP_REQUEST_BODY_CURLPOST:
- curl_formfree(body->data);
- break;
-
- case HTTP_REQUEST_BODY_UPLOADFILE:
- php_stream_close(body->data);
- break;
+ if (body) {
+ if (body->free) {
+ switch (body->type)
+ {
+ case HTTP_REQUEST_BODY_CSTRING:
+ if (body->data) {
+ efree(body->data);
+ }
+ break;
+
+ case HTTP_REQUEST_BODY_CURLPOST:
+ curl_formfree(body->data);
+ break;
+
+ case HTTP_REQUEST_BODY_UPLOADFILE:
+ php_stream_close(body->data);
+ break;
+ }