struct curl_httppost *http_post_data[2] = {NULL, NULL};
/* normal data */
- 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;
+ 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;
}
-
- /* reset */
- key = NULL;
}
}
return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CURLPOST, http_post_data[0], 0, 1);
- } else {
+ } else if (fields) {
char *encoded;
size_t encoded_len;
}
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);
}
}
array_init(return_value);
- if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void **) &options)) {
+ if ( (Z_TYPE_P(opts) == IS_ARRAY) &&
+ (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void **) &options))) {
convert_to_array(*options);
array_copy(*options, return_value);
}
if (!opts || !zend_hash_num_elements(Z_ARRVAL_P(opts))) {
SET_PROP(obj, options, new_opts);
+ zval_ptr_dtor(&new_opts);
RETURN_TRUE;
}
array_copy(files, post);
}
SET_PROP(obj, postFiles, post);
+ zval_ptr_dtor(&post);
RETURN_TRUE;
}
IF_RETVAL_USED {
getObject(http_request_object, obj);
-
- array_init(return_value);
- array_copy(GET_PROP(obj, postFiles), return_value);
+ zval *files = GET_PROP(obj, postFiles);
+
+ RETURN_ZVAL(files, 1, 0);
}
}
/* }}} */
IF_RETVAL_USED {
getObject(http_request_object, obj);
+ zval *data = GET_PROP(obj, responseData);
- array_init(return_value);
- array_copy(GET_PROP(obj, responseData), return_value);
+ RETURN_ZVAL(data, 1, 0);
}
}
/* }}} */