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