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