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