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