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