e94e5dc732d5446e87022f22f4fc1ff2c7491541
[m6w6/ext-http] / http_curl_api.c
1 /*
2 +----------------------------------------------------------------------+
3 | PECL :: http |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
14 */
15
16 /* $Id$ */
17
18 #ifdef HAVE_CONFIG_H
19 # include "config.h"
20 #endif
21
22 #ifdef PHP_WIN32
23 # include <winsock2.h>
24 #endif
25
26 #include <curl/curl.h>
27
28 #include "phpstr/phpstr.h"
29
30 #include "php.h"
31 #include "php_http.h"
32 #include "php_http_std_defs.h"
33 #include "php_http_api.h"
34 #include "php_http_curl_api.h"
35 #include "php_http_url_api.h"
36
37 ZEND_EXTERN_MODULE_GLOBALS(http)
38
39 #if LIBCURL_VERSION_NUM >= 0x070c01
40 # define http_curl_reset(ch) curl_easy_reset(ch)
41 #else
42 # define http_curl_reset(ch)
43 #endif
44
45 #if LIBCURL_VERSION_NUM < 0x070c00
46 # define http_curl_error(dummy) HTTP_G(curlerr)
47 # define curl_easy_strerror(code) "unkown error"
48 #else
49 # define http_curl_error(code) curl_easy_strerror(code)
50 #endif
51
52 #define http_curl_startup(ch, clean_curl, URL, options, response) \
53 if (!ch) { \
54 if (!(ch = curl_easy_init())) { \
55 http_error(E_WARNING, HTTP_E_CURL, "Could not initialize curl"); \
56 return FAILURE; \
57 } \
58 clean_curl = 1; \
59 } else { \
60 http_curl_reset(ch); \
61 } \
62 http_curl_setopts(ch, URL, options, response);
63
64 #define http_curl_perform(ch, clean_curl, response) \
65 { \
66 CURLcode result; \
67 if (CURLE_OK != (result = curl_easy_perform(ch))) { \
68 http_error_ex(E_WARNING, HTTP_E_CURL, "Could not perform request: %s", curl_easy_strerror(result)); \
69 http_curl_cleanup(ch, clean_curl, response); \
70 return FAILURE; \
71 } \
72 }
73
74 #define http_curl_cleanup(ch, clean_curl, response) \
75 zend_llist_clean(&HTTP_G(to_free)); \
76 if (clean_curl) { \
77 curl_easy_cleanup(ch); \
78 ch = NULL; \
79 } \
80 phpstr_fix(PHPSTR(response))
81
82 #define http_curl_copystr(s) _http_curl_copystr((s) TSRMLS_CC)
83 static inline char *_http_curl_copystr(const char *str TSRMLS_DC);
84
85 #define http_curl_setopts(c, u, o, r) _http_curl_setopts((c), (u), (o), (r) TSRMLS_CC)
86 static void _http_curl_setopts(CURL *ch, const char *url, HashTable *options, phpstr *response TSRMLS_DC);
87
88 #define http_curl_getopt(o, k, t) _http_curl_getopt((o), (k), (t) TSRMLS_CC)
89 static inline zval *_http_curl_getopt(HashTable *options, char *key, int type TSRMLS_DC);
90
91 static size_t http_curl_callback(char *, size_t, size_t, void *);
92
93 #define http_curl_getinfo(c, h) _http_curl_getinfo((c), (h) TSRMLS_CC)
94 static inline void _http_curl_getinfo(CURL *ch, HashTable *info TSRMLS_DC);
95
96 /* {{{ static inline char *http_curl_copystr(char *) */
97 static inline char *_http_curl_copystr(const char *str TSRMLS_DC)
98 {
99 char *new_str = estrdup(str);
100 zend_llist_add_element(&HTTP_G(to_free), &new_str);
101 return new_str;
102 }
103 /* }}} */
104
105 /* {{{ static size_t http_curl_callback(char *, size_t, size_t, void *) */
106 static size_t http_curl_callback(char *buf, size_t len, size_t n, void *s)
107 {
108 phpstr_append(PHPSTR(s), buf, len *= n);
109 return len;
110 }
111 /* }}} */
112
113 /* {{{ static inline zval *http_curl_getopt(HashTable *, char *, int) */
114 static inline zval *_http_curl_getopt(HashTable *options, char *key, int type TSRMLS_DC)
115 {
116 zval **zoption;
117
118 if (SUCCESS != zend_hash_find(options, key, strlen(key) + 1, (void **) &zoption)) {
119 return NULL;
120 }
121
122 if (Z_TYPE_PP(zoption) != type) {
123 switch (type)
124 {
125 case IS_BOOL: convert_to_boolean_ex(zoption); break;
126 case IS_LONG: convert_to_long_ex(zoption); break;
127 case IS_DOUBLE: convert_to_double_ex(zoption); break;
128 case IS_STRING: convert_to_string_ex(zoption); break;
129 case IS_ARRAY: convert_to_array_ex(zoption); break;
130 case IS_OBJECT: convert_to_object_ex(zoption); break;
131 default:
132 break;
133 }
134 }
135
136 return *zoption;
137 }
138 /* }}} */
139
140 /* {{{ static void http_curl_setopts(CURL *, char *, HashTable *, phpstr *) */
141 static void _http_curl_setopts(CURL *ch, const char *url, HashTable *options, phpstr *response TSRMLS_DC)
142 {
143 zval *zoption;
144 zend_bool range_req = 0;
145
146 #define HTTP_CURL_OPT(OPTION, p) curl_easy_setopt(ch, CURLOPT_##OPTION, (p))
147
148 /* standard options */
149 HTTP_CURL_OPT(URL, url);
150 HTTP_CURL_OPT(HEADER, 0);
151 HTTP_CURL_OPT(FILETIME, 1);
152 HTTP_CURL_OPT(NOPROGRESS, 1);
153 HTTP_CURL_OPT(AUTOREFERER, 1);
154 HTTP_CURL_OPT(WRITEFUNCTION, http_curl_callback);
155 HTTP_CURL_OPT(HEADERFUNCTION, http_curl_callback);
156 HTTP_CURL_OPT(WRITEDATA, response);
157 HTTP_CURL_OPT(WRITEHEADER, response);
158 #if defined(ZTS) && (LIBCURL_VERSION_NUM >= 0x070a00)
159 HTTP_CURL_OPT(NOSIGNAL, 1);
160 #endif
161 #if LIBCURL_VERSION_NUM < 0x070c00
162 HTTP_CURL_OPT(ERRORBUFFER, HTTP_G(curlerr));
163 #endif
164
165 /* proxy */
166 if (zoption = http_curl_getopt(options, "proxyhost", IS_STRING)) {
167 HTTP_CURL_OPT(PROXY, http_curl_copystr(Z_STRVAL_P(zoption)));
168 /* port */
169 if (zoption = http_curl_getopt(options, "proxyport", IS_LONG)) {
170 HTTP_CURL_OPT(PROXYPORT, Z_LVAL_P(zoption));
171 }
172 /* user:pass */
173 if (zoption = http_curl_getopt(options, "proxyauth", IS_STRING)) {
174 HTTP_CURL_OPT(PROXYUSERPWD, http_curl_copystr(Z_STRVAL_P(zoption)));
175 }
176 #if LIBCURL_VERSION_NUM >= 0x070a07
177 /* auth method */
178 if (zoption = http_curl_getopt(options, "proxyauthtype", IS_LONG)) {
179 HTTP_CURL_OPT(PROXYAUTH, Z_LVAL_P(zoption));
180 }
181 #endif
182 }
183
184 /* outgoing interface */
185 if (zoption = http_curl_getopt(options, "interface", IS_STRING)) {
186 HTTP_CURL_OPT(INTERFACE, http_curl_copystr(Z_STRVAL_P(zoption)));
187 }
188
189 /* another port */
190 if (zoption = http_curl_getopt(options, "port", IS_LONG)) {
191 HTTP_CURL_OPT(PORT, Z_LVAL_P(zoption));
192 }
193
194 /* auth */
195 if (zoption = http_curl_getopt(options, "httpauth", IS_STRING)) {
196 HTTP_CURL_OPT(USERPWD, http_curl_copystr(Z_STRVAL_P(zoption)));
197 }
198 #if LIBCURL_VERSION_NUM >= 0x070a06
199 if (zoption = http_curl_getopt(options, "httpauthtype", IS_LONG)) {
200 HTTP_CURL_OPT(HTTPAUTH, Z_LVAL_P(zoption));
201 }
202 #endif
203
204 /* compress, empty string enables deflate and gzip */
205 if (zoption = http_curl_getopt(options, "compress", IS_BOOL)) {
206 if (Z_LVAL_P(zoption)) {
207 HTTP_CURL_OPT(ENCODING, "");
208 }
209 }
210
211 /* redirects, defaults to 0 */
212 if (zoption = http_curl_getopt(options, "redirect", IS_LONG)) {
213 HTTP_CURL_OPT(FOLLOWLOCATION, Z_LVAL_P(zoption) ? 1 : 0);
214 HTTP_CURL_OPT(MAXREDIRS, Z_LVAL_P(zoption));
215 if (zoption = http_curl_getopt(options, "unrestrictedauth", IS_BOOL)) {
216 HTTP_CURL_OPT(UNRESTRICTED_AUTH, Z_LVAL_P(zoption));
217 }
218 } else {
219 HTTP_CURL_OPT(FOLLOWLOCATION, 0);
220 }
221
222 /* referer */
223 if (zoption = http_curl_getopt(options, "referer", IS_STRING)) {
224 HTTP_CURL_OPT(REFERER, http_curl_copystr(Z_STRVAL_P(zoption)));
225 }
226
227 /* useragent, default "PECL::HTTP/version (PHP/version)" */
228 if (zoption = http_curl_getopt(options, "useragent", IS_STRING)) {
229 HTTP_CURL_OPT(USERAGENT, http_curl_copystr(Z_STRVAL_P(zoption)));
230 } else {
231 HTTP_CURL_OPT(USERAGENT,
232 "PECL::HTTP/" HTTP_PEXT_VERSION " (PHP/" PHP_VERSION ")");
233 }
234
235 /* additional headers, array('name' => 'value') */
236 if (zoption = http_curl_getopt(options, "headers", IS_ARRAY)) {
237 char *header_key;
238 long header_idx;
239 struct curl_slist *headers = NULL;
240
241 FOREACH_KEY(zoption, header_key, header_idx) {
242 if (header_key) {
243 zval **header_val;
244 if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void **) &header_val)) {
245 char header[1024] = {0};
246 snprintf(header, 1023, "%s: %s", header_key, Z_STRVAL_PP(header_val));
247 headers = curl_slist_append(headers, http_curl_copystr(header));
248 }
249
250 /* reset */
251 header_key = NULL;
252 }
253 }
254
255 if (headers) {
256 HTTP_CURL_OPT(HTTPHEADER, headers);
257 }
258 }
259
260 /* cookies, array('name' => 'value') */
261 if (zoption = http_curl_getopt(options, "cookies", IS_ARRAY)) {
262 char *cookie_key = NULL;
263 long cookie_idx = 0;
264 phpstr *qstr = phpstr_new();
265
266 FOREACH_KEY(zoption, cookie_key, cookie_idx) {
267 if (cookie_key) {
268 zval **cookie_val;
269 if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void **) &cookie_val)) {
270 phpstr_appendf(qstr, "%s=%s; ", cookie_key, Z_STRVAL_PP(cookie_val));
271 }
272
273 /* reset */
274 cookie_key = NULL;
275 }
276 }
277
278 if (qstr->used) {
279 phpstr_fix(qstr);
280 HTTP_CURL_OPT(COOKIE, http_curl_copystr(qstr->data));
281 }
282 phpstr_free(qstr);
283 }
284
285 /* cookiestore */
286 if (zoption = http_curl_getopt(options, "cookiestore", IS_STRING)) {
287 HTTP_CURL_OPT(COOKIEFILE, http_curl_copystr(Z_STRVAL_P(zoption)));
288 HTTP_CURL_OPT(COOKIEJAR, http_curl_copystr(Z_STRVAL_P(zoption)));
289 }
290
291 /* resume */
292 if (zoption = http_curl_getopt(options, "resume", IS_LONG)) {
293 range_req = 1;
294 HTTP_CURL_OPT(RESUME_FROM, Z_LVAL_P(zoption));
295 }
296
297 /* maxfilesize */
298 if (zoption = http_curl_getopt(options, "maxfilesize", IS_LONG)) {
299 HTTP_CURL_OPT(MAXFILESIZE, Z_LVAL_P(zoption));
300 }
301
302 /* lastmodified */
303 if (zoption = http_curl_getopt(options, "lastmodified", IS_LONG)) {
304 HTTP_CURL_OPT(TIMECONDITION, range_req ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE);
305 HTTP_CURL_OPT(TIMEVALUE, Z_LVAL_P(zoption));
306 }
307
308 /* timeout */
309 if (zoption = http_curl_getopt(options, "timeout", IS_LONG)) {
310 HTTP_CURL_OPT(TIMEOUT, Z_LVAL_P(zoption));
311 }
312
313 /* connecttimeout, defaults to 1 */
314 if (zoption = http_curl_getopt(options, "connecttimeout", IS_LONG)) {
315 HTTP_CURL_OPT(CONNECTTIMEOUT, Z_LVAL_P(zoption));
316 } else {
317 HTTP_CURL_OPT(CONNECTTIMEOUT, 1);
318 }
319
320 /* ssl */
321 if (zoption = http_curl_getopt(options, "ssl", IS_ARRAY)) {
322 #define HTTP_CURL_OPT_STRING(keyname) HTTP_CURL_OPT_STRING_EX(keyname, keyname)
323 #define HTTP_CURL_OPT_SSL_STRING(keyname) HTTP_CURL_OPT_STRING_EX(keyname, SSL##keyname)
324 #define HTTP_CURL_OPT_SSL_STRING_(keyname) HTTP_CURL_OPT_STRING_EX(keyname, SSL_##keyname)
325 #define HTTP_CURL_OPT_STRING_EX(keyname, optname) \
326 if (!strcasecmp(key, #keyname)) { \
327 convert_to_string_ex(param); \
328 HTTP_CURL_OPT(optname, Z_STRVAL_PP(param)); \
329 key = NULL; \
330 continue; \
331 }
332 #define HTTP_CURL_OPT_LONG(keyname) HTTP_OPT_SSL_LONG_EX(keyname, keyname)
333 #define HTTP_CURL_OPT_SSL_LONG(keyname) HTTP_CURL_OPT_LONG_EX(keyname, SSL##keyname)
334 #define HTTP_CURL_OPT_SSL_LONG_(keyname) HTTP_CURL_OPT_LONG_EX(keyname, SSL_##keyname)
335 #define HTTP_CURL_OPT_LONG_EX(keyname, optname) \
336 if (!strcasecmp(key, #keyname)) { \
337 convert_to_long_ex(param); \
338 HTTP_CURL_OPT(optname, Z_LVAL_PP(param)); \
339 key = NULL; \
340 continue; \
341 }
342
343 long idx;
344 char *key = NULL;
345 zval **param;
346
347 FOREACH_KEYVAL(zoption, key, idx, param) {
348 if (key) {fprintf(stderr, "%s\n", key);
349 HTTP_CURL_OPT_SSL_STRING(CERT);
350 #if LIBCURL_VERSION_NUM >= 0x070903
351 HTTP_CURL_OPT_SSL_STRING(CERTTYPE);
352 #endif
353 HTTP_CURL_OPT_SSL_STRING(CERTPASSWD);
354
355 HTTP_CURL_OPT_SSL_STRING(KEY);
356 HTTP_CURL_OPT_SSL_STRING(KEYTYPE);
357 HTTP_CURL_OPT_SSL_STRING(KEYPASSWD);
358
359 HTTP_CURL_OPT_SSL_STRING(ENGINE);
360 HTTP_CURL_OPT_SSL_LONG(VERSION);
361
362 HTTP_CURL_OPT_SSL_LONG_(VERIFYPEER);
363 HTTP_CURL_OPT_SSL_LONG_(VERIFYHOST);
364 HTTP_CURL_OPT_SSL_STRING_(CIPHER_LIST);
365
366
367 HTTP_CURL_OPT_STRING(CAINFO);
368 #if LIBCURL_VERSION_NUM >= 0x070908
369 HTTP_CURL_OPT_STRING(CAPATH);
370 #endif
371 HTTP_CURL_OPT_STRING(RANDOM_FILE);
372 HTTP_CURL_OPT_STRING(EGDSOCKET);
373
374 /* reset key */
375 key = NULL;
376 }
377 }
378 } else {
379 /* disable SSL verification by default */
380 HTTP_CURL_OPT(SSL_VERIFYPEER, 0);
381 HTTP_CURL_OPT(SSL_VERIFYHOST, 0);
382 }
383 }
384 /* }}} */
385
386 /* {{{ static inline http_curl_getinfo(CURL, HashTable *) */
387 static inline void _http_curl_getinfo(CURL *ch, HashTable *info TSRMLS_DC)
388 {
389 zval array;
390 Z_ARRVAL(array) = info;
391
392 #define HTTP_CURL_INFO(I) HTTP_CURL_INFO_EX(I, I)
393 #define HTTP_CURL_INFO_EX(I, X) \
394 switch (CURLINFO_ ##I & ~CURLINFO_MASK) \
395 { \
396 case CURLINFO_STRING: \
397 { \
398 char *c; \
399 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_ ##I, &c)) { \
400 add_assoc_string(&array, pretty_key(http_curl_copystr(#X), sizeof(#X)-1, 0, 0), c ? c : "", 1); \
401 } \
402 } \
403 break; \
404 \
405 case CURLINFO_DOUBLE: \
406 { \
407 double d; \
408 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_ ##I, &d)) { \
409 add_assoc_double(&array, pretty_key(http_curl_copystr(#X), sizeof(#X)-1, 0, 0), d); \
410 } \
411 } \
412 break; \
413 \
414 case CURLINFO_LONG: \
415 { \
416 long l; \
417 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_ ##I, &l)) { \
418 add_assoc_long(&array, pretty_key(http_curl_copystr(#X), sizeof(#X)-1, 0, 0), l); \
419 } \
420 } \
421 break; \
422 }
423
424 HTTP_CURL_INFO(EFFECTIVE_URL);
425
426 #if LIBCURL_VERSION_NUM >= 0x070a07
427 HTTP_CURL_INFO(RESPONSE_CODE);
428 #else
429 HTTP_CURL_INFO_EX(HTTP_CODE, RESPONSE_CODE);
430 #endif
431 HTTP_CURL_INFO(HTTP_CONNECTCODE);
432
433 #if LIBCURL_VERSION_NUM >= 0x070500
434 HTTP_CURL_INFO(FILETIME);
435 #endif
436 HTTP_CURL_INFO(TOTAL_TIME);
437 HTTP_CURL_INFO(NAMELOOKUP_TIME);
438 HTTP_CURL_INFO(CONNECT_TIME);
439 HTTP_CURL_INFO(PRETRANSFER_TIME);
440 HTTP_CURL_INFO(STARTTRANSFER_TIME);
441 #if LIBCURL_VERSION_NUM >= 0x070907
442 HTTP_CURL_INFO(REDIRECT_TIME);
443 HTTP_CURL_INFO(REDIRECT_COUNT);
444 #endif
445
446 HTTP_CURL_INFO(SIZE_UPLOAD);
447 HTTP_CURL_INFO(SIZE_DOWNLOAD);
448 HTTP_CURL_INFO(SPEED_DOWNLOAD);
449 HTTP_CURL_INFO(SPEED_UPLOAD);
450
451 HTTP_CURL_INFO(HEADER_SIZE);
452 HTTP_CURL_INFO(REQUEST_SIZE);
453
454 HTTP_CURL_INFO(SSL_VERIFYRESULT);
455 #if LIBCURL_VERSION_NUM >= 0x070c03
456 /*HTTP_CURL_INFO(SSL_ENGINES);
457 todo: CURLINFO_SLIST */
458 #endif
459
460 HTTP_CURL_INFO(CONTENT_LENGTH_DOWNLOAD);
461 HTTP_CURL_INFO(CONTENT_LENGTH_UPLOAD);
462 HTTP_CURL_INFO(CONTENT_TYPE);
463
464 #if LIBCURL_VERSION_NUM >= 0x070a03
465 /*HTTP_CURL_INFO(PRIVATE);*/
466 #endif
467
468 #if LIBCURL_VERSION_NUM >= 0x070a08
469 HTTP_CURL_INFO(HTTPAUTH_AVAIL);
470 HTTP_CURL_INFO(PROXYAUTH_AVAIL);
471 #endif
472
473 #if LIBCURL_VERSION_NUM >= 0x070c02
474 /*HTTP_CURL_INFO(OS_ERRNO);*/
475 #endif
476
477 #if LIBCURL_VERSION_NUM >= 0x070c03
478 HTTP_CURL_INFO(NUM_CONNECTS);
479 #endif
480 }
481 /* }}} */
482
483 /* {{{ STATUS http_get_ex(CURL *, char *, HashTable *, HashTable *, phpstr *) */
484 PHP_HTTP_API STATUS _http_get_ex(CURL *ch, const char *URL, HashTable *options, HashTable *info, phpstr *response TSRMLS_DC)
485 {
486 zend_bool clean_curl = 0;
487
488 http_curl_startup(ch, clean_curl, URL, options, response);
489 curl_easy_setopt(ch, CURLOPT_HTTPGET, 1);
490 http_curl_perform(ch, clean_curl, response);
491
492 if (info) {
493 http_curl_getinfo(ch, info);
494 }
495
496 http_curl_cleanup(ch, clean_curl, response);
497
498 return SUCCESS;
499 }
500
501 /* {{{ STATUS http_head_ex(CURL *, char *, HashTable *, HashTable *, phpstr *) */
502 PHP_HTTP_API STATUS _http_head_ex(CURL *ch, const char *URL, HashTable *options,HashTable *info, phpstr *response TSRMLS_DC)
503 {
504 zend_bool clean_curl = 0;
505
506 http_curl_startup(ch, clean_curl, URL, options, response);
507 curl_easy_setopt(ch, CURLOPT_NOBODY, 1);
508 http_curl_perform(ch, clean_curl, response);
509
510 if (info) {
511 http_curl_getinfo(ch, info);
512 }
513
514 http_curl_cleanup(ch, clean_curl, response);
515
516 return SUCCESS;
517 }
518
519 /* {{{ STATUS http_post_data_ex(CURL *, char *, char *, size_t, HashTable *, HashTable *, phpstr *) */
520 PHP_HTTP_API STATUS _http_post_data_ex(CURL *ch, const char *URL, char *postdata,
521 size_t postdata_len, HashTable *options, HashTable *info, phpstr *response TSRMLS_DC)
522 {
523 zend_bool clean_curl = 0;
524
525 http_curl_startup(ch, clean_curl, URL, options, response);
526 curl_easy_setopt(ch, CURLOPT_POST, 1);
527 curl_easy_setopt(ch, CURLOPT_POSTFIELDS, postdata);
528 curl_easy_setopt(ch, CURLOPT_POSTFIELDSIZE, postdata_len);
529 http_curl_perform(ch, clean_curl, response);
530
531 if (info) {
532 http_curl_getinfo(ch, info);
533 }
534
535 http_curl_cleanup(ch, clean_curl, response);
536
537 return SUCCESS;
538 }
539 /* }}} */
540
541 /* {{{ STATUS http_post_array_ex(CURL *, char *, HashTable *, HashTable *, HashTable *, phpstr *) */
542 PHP_HTTP_API STATUS _http_post_array_ex(CURL *ch, const char *URL, HashTable *postarray,
543 HashTable *options, HashTable *info, phpstr *response TSRMLS_DC)
544 {
545 STATUS status;
546 char *encoded;
547 size_t encoded_len;
548
549 if (SUCCESS != http_urlencode_hash_ex(postarray, 1, NULL, 0, &encoded, &encoded_len)) {
550 http_error(E_WARNING, HTTP_E_ENCODE, "Could not encode post data");
551 return FAILURE;
552 }
553
554 status = http_post_data_ex(ch, URL, encoded, encoded_len, options, info, response);
555 efree(encoded);
556
557 return status;
558 }
559 /* }}} */
560
561 /* {{{ STATUS http_post_curldata_ex(CURL *, char *, curl_httppost *, HashTable *, HashTable *, phpstr *) */
562 PHP_HTTP_API STATUS _http_post_curldata_ex(CURL *ch, const char *URL, struct curl_httppost *curldata,
563 HashTable *options, HashTable *info, phpstr *response TSRMLS_DC)
564 {
565 zend_bool clean_curl = 0;
566
567 http_curl_startup(ch, clean_curl, URL, options, response);
568 curl_easy_setopt(ch, CURLOPT_POST, 1);
569 curl_easy_setopt(ch, CURLOPT_HTTPPOST, curldata);
570 http_curl_perform(ch, clean_curl, response);
571
572 if (info) {
573 http_curl_getinfo(ch, info);
574 }
575
576 http_curl_cleanup(ch, clean_curl, response);
577
578 return SUCCESS;
579 }
580 /* }}} */
581
582 /*
583 * Local variables:
584 * tab-width: 4
585 * c-basic-offset: 4
586 * End:
587 * vim600: noet sw=4 ts=4 fdm=marker
588 * vim<600: noet sw=4 ts=4
589 */