- if (files && (zend_hash_num_elements(files) > 0)) {
- char *key = NULL;
- ulong idx;
- zval **data;
- struct curl_httppost *http_post_data[2] = {NULL, NULL};
-
- /* normal data */
- FOREACH_HASH_KEYVAL(fields, key, idx, data) {
- CURLcode err;
- if (key) {
- 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, Z_STRLEN_PP(data),
- CURLFORM_END
- );
- if (CURLE_OK != err) {
- http_error_ex(E_WARNING, HTTP_E_CURL, "Could not encode post fields: %s", curl_easy_strerror(err));
- curl_formfree(http_post_data[0]);
- return FAILURE;
- }
-
- /* reset */
- key = NULL;
- }
- }
-
- /* file data */
- FOREACH_HASH_VAL(files, data) {
- CURLcode err;
- zval **file, **type, **name;
- if ( SUCCESS == zend_hash_find(Z_ARRVAL_PP(data), "name", sizeof("name"), (void **) &name) &&
- SUCCESS == zend_hash_find(Z_ARRVAL_PP(data), "type", sizeof("type"), (void **) &type) &&
- SUCCESS == zend_hash_find(Z_ARRVAL_PP(data), "file", sizeof("file"), (void **) &file)) {
- err = curl_formadd(&http_post_data[0], &http_post_data[1],
- CURLFORM_COPYNAME, Z_STRVAL_PP(name),
- CURLFORM_FILE, Z_STRVAL_PP(file),
- CURLFORM_CONTENTTYPE, Z_STRVAL_PP(type),
- CURLFORM_END
- );
- if (CURLE_OK != err) {
- http_error_ex(E_WARNING, HTTP_E_CURL, "Could not encode post files: %s", curl_easy_strerror(err));
- curl_formfree(http_post_data[0]);
- return FAILURE;
- }
- } else {
- http_error(E_NOTICE, HTTP_E_PARAM, "Post file array entry misses either 'name', 'type' or 'file' entry");
- }
- }
-
- body->type = HTTP_REQUEST_BODY_CURLPOST;
- body->data = http_post_data[0];
- body->size = 0;
-
- } else {
- char *encoded;
- size_t encoded_len;
-
- if (SUCCESS != http_urlencode_hash_ex(fields, 1, NULL, 0, &encoded, &encoded_len)) {
- http_error(E_WARNING, HTTP_E_ENCODE, "Could not encode post data");
- return FAILURE;
- }
-
- body->type = HTTP_REQUEST_BODY_CSTRING;
- body->data = encoded;
- body->size = encoded_len;
+ if (request->ch) {
+#ifdef HAVE_CURL_EASY_RESET
+ curl_easy_reset(request->ch);
+#endif
+#if defined(ZTS)
+ HTTP_CURL_OPT(NOSIGNAL, 1);
+#endif
+ HTTP_CURL_OPT(PRIVATE, request);
+ HTTP_CURL_OPT(ERRORBUFFER, request->_error);
+ HTTP_CURL_OPT(HEADER, 0);
+ HTTP_CURL_OPT(FILETIME, 1);
+ HTTP_CURL_OPT(AUTOREFERER, 1);
+ HTTP_CURL_OPT(VERBOSE, 1);
+ HTTP_CURL_OPT(HEADERFUNCTION, NULL);
+ HTTP_CURL_OPT(DEBUGFUNCTION, http_curl_raw_callback);
+ HTTP_CURL_OPT(READFUNCTION, http_curl_read_callback);
+ HTTP_CURL_OPT(IOCTLFUNCTION, http_curl_ioctl_callback);
+ HTTP_CURL_OPT(WRITEFUNCTION, http_curl_dummy_callback);
+ HTTP_CURL_OPT(PROGRESSFUNCTION, NULL);
+ HTTP_CURL_OPT(URL, NULL);
+ HTTP_CURL_OPT(NOPROGRESS, 1);
+ HTTP_CURL_OPT(PROXY, NULL);
+ HTTP_CURL_OPT(PROXYPORT, 0);
+ HTTP_CURL_OPT(PROXYUSERPWD, NULL);
+ HTTP_CURL_OPT(PROXYAUTH, 0);
+ HTTP_CURL_OPT(INTERFACE, NULL);
+ HTTP_CURL_OPT(PORT, 0);
+ HTTP_CURL_OPT(USERPWD, NULL);
+ HTTP_CURL_OPT(HTTPAUTH, 0);
+ HTTP_CURL_OPT(ENCODING, NULL);
+ HTTP_CURL_OPT(FOLLOWLOCATION, 0);
+ HTTP_CURL_OPT(UNRESTRICTED_AUTH, 0);
+ HTTP_CURL_OPT(REFERER, NULL);
+ HTTP_CURL_OPT(USERAGENT, "PECL::HTTP/" PHP_EXT_HTTP_VERSION " (PHP/" PHP_VERSION ")");
+ HTTP_CURL_OPT(HTTPHEADER, NULL);
+ HTTP_CURL_OPT(COOKIE, NULL);
+ HTTP_CURL_OPT(COOKIEFILE, NULL);
+ HTTP_CURL_OPT(COOKIEJAR, NULL);
+ HTTP_CURL_OPT(RESUME_FROM, 0);
+ HTTP_CURL_OPT(MAXFILESIZE, 0);
+ HTTP_CURL_OPT(TIMECONDITION, 0);
+ HTTP_CURL_OPT(TIMEVALUE, 0);
+ HTTP_CURL_OPT(TIMEOUT, 0);
+ HTTP_CURL_OPT(CONNECTTIMEOUT, 3);
+ HTTP_CURL_OPT(SSLCERT, NULL);
+ HTTP_CURL_OPT(SSLCERTTYPE, NULL);
+ HTTP_CURL_OPT(SSLCERTPASSWD, NULL);
+ HTTP_CURL_OPT(SSLKEY, NULL);
+ HTTP_CURL_OPT(SSLKEYTYPE, NULL);
+ HTTP_CURL_OPT(SSLKEYPASSWD, NULL);
+ HTTP_CURL_OPT(SSLENGINE, NULL);
+ HTTP_CURL_OPT(SSLVERSION, 0);
+ HTTP_CURL_OPT(SSL_VERIFYPEER, 0);
+ HTTP_CURL_OPT(SSL_VERIFYHOST, 0);
+ HTTP_CURL_OPT(SSL_CIPHER_LIST, NULL);
+ HTTP_CURL_OPT(CAINFO, NULL);
+ HTTP_CURL_OPT(CAPATH, NULL);
+ HTTP_CURL_OPT(RANDOM_FILE, NULL);
+ HTTP_CURL_OPT(EGDSOCKET, NULL);
+ HTTP_CURL_OPT(POSTFIELDS, NULL);
+ HTTP_CURL_OPT(POSTFIELDSIZE, 0);
+ HTTP_CURL_OPT(HTTPPOST, NULL);
+ HTTP_CURL_OPT(IOCTLDATA, NULL);
+ HTTP_CURL_OPT(READDATA, NULL);
+ HTTP_CURL_OPT(INFILESIZE, 0);