2 +----------------------------------------------------------------------+
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 +----------------------------------------------------------------------+
24 # define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
25 # include <winsock2.h>
26 # include <sys/types.h>
29 #include <curl/curl.h>
30 #include <curl/easy.h>
34 #include "php_http_api.h"
35 #include "php_http_curl_api.h"
36 #include "php_http_std_defs.h"
38 #include "ext/standard/php_smart_str.h"
40 ZEND_DECLARE_MODULE_GLOBALS(http
)
42 #define http_curl_startup(ch, clean_curl, URL, options) \
44 if (!(ch = curl_easy_init())) { \
45 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not initialize curl"); \
50 http_curl_initbuf(); \
51 http_curl_setopts(ch, URL, options);
54 #define http_curl_cleanup(ch, clean_curl) \
55 http_curl_freestr(); \
56 http_curl_freebuf(); \
58 curl_easy_cleanup(ch); \
62 #define http_curl_freestr() \
63 zend_llist_clean(&HTTP_G(to_free))
65 #define http_curl_initbuf() http_curl_initbuf_ex(0)
67 #define http_curl_initbuf_ex(chunk_size) \
69 size_t size = (chunk_size > 0) ? chunk_size : HTTP_CURLBUF_SIZE; \
70 http_curl_freebuf(); \
71 HTTP_G(curlbuf).data = emalloc(size); \
72 HTTP_G(curlbuf).free = size; \
73 HTTP_G(curlbuf).size = size; \
76 #define http_curl_freebuf() \
77 if (HTTP_G(curlbuf).data) { \
78 efree(HTTP_G(curlbuf).data); \
79 HTTP_G(curlbuf).data = NULL; \
81 HTTP_G(curlbuf).used = 0; \
82 HTTP_G(curlbuf).free = 0; \
83 HTTP_G(curlbuf).size = 0;
85 #define http_curl_copybuf(data, size) \
86 * size = HTTP_G(curlbuf).used; \
87 * data = ecalloc(1, HTTP_G(curlbuf).used + 1); \
88 memcpy(* data, HTTP_G(curlbuf).data, * size);
90 #define http_curl_sizebuf(for_size) \
92 size_t size = (for_size); \
93 if (size > HTTP_G(curlbuf).free) { \
94 size_t bsize = HTTP_G(curlbuf).size; \
95 while (size > bsize) { \
98 HTTP_G(curlbuf).data = erealloc(HTTP_G(curlbuf).data, HTTP_G(curlbuf).used + bsize); \
99 HTTP_G(curlbuf).free += bsize; \
104 #define http_curl_copystr(s) _http_curl_copystr((s) TSRMLS_CC)
105 static inline char *_http_curl_copystr(const char *str TSRMLS_DC
);
107 #define http_curl_setopts(c, u, o) _http_curl_setopts((c), (u), (o) TSRMLS_CC)
108 static inline void _http_curl_setopts(CURL
*ch
, const char *url
, HashTable
*options TSRMLS_DC
);
110 #define http_curl_getopt(o, k) _http_curl_getopt((o), (k) TSRMLS_CC, 0)
111 #define http_curl_getopt1(o, k, t1) _http_curl_getopt((o), (k) TSRMLS_CC, 1, (t1))
112 #define http_curl_getopt2(o, k, t1, t2) _http_curl_getopt((o), (k) TSRMLS_CC, 2, (t1), (t2))
113 static inline zval
*_http_curl_getopt(HashTable
*options
, char *key TSRMLS_DC
, int checks
, ...);
115 static size_t http_curl_body_callback(char *, size_t, size_t, void *);
116 static size_t http_curl_hdrs_callback(char *, size_t, size_t, void *);
118 #define http_curl_getinfo(c, h) _http_curl_getinfo((c), (h) TSRMLS_CC)
119 static inline void _http_curl_getinfo(CURL
*ch
, HashTable
*info TSRMLS_DC
);
120 #define http_curl_getinfo_ex(c, i, a) _http_curl_getinfo_ex((c), (i), (a) TSRMLS_CC)
121 static inline void _http_curl_getinfo_ex(CURL
*ch
, CURLINFO i
, zval
*array TSRMLS_DC
);
122 #define http_curl_getinfoname(i) _http_curl_getinfoname((i) TSRMLS_CC)
123 static inline char *_http_curl_getinfoname(CURLINFO i TSRMLS_DC
);
125 /* {{{ static inline char *http_curl_copystr(char *) */
126 static inline char *_http_curl_copystr(const char *str TSRMLS_DC
)
128 char *new_str
= estrdup(str
);
129 zend_llist_add_element(&HTTP_G(to_free
), &new_str
);
134 /* {{{ static size_t http_curl_body_callback(char *, size_t, size_t, void *) */
135 static size_t http_curl_body_callback(char *buf
, size_t len
, size_t n
, void *s
)
139 http_curl_sizebuf(len
*= n
);
141 memcpy(HTTP_G(curlbuf
).data
+ HTTP_G(curlbuf
).used
, buf
, len
);
142 HTTP_G(curlbuf
).free
-= len
;
143 HTTP_G(curlbuf
).used
+= len
;
148 /* {{{ static size_t http_curl_hdrs_callback(char *, size_t, size_t, void *) */
149 static size_t http_curl_hdrs_callback(char *buf
, size_t len
, size_t n
, void *s
)
153 /* discard previous headers */
154 if ((HTTP_G(curlbuf
).used
) && (!strncmp(buf
, "HTTP/1.", sizeof("HTTP/1.") - 1))) {
157 http_curl_sizebuf(len
*= n
);
159 memcpy(HTTP_G(curlbuf
).data
+ HTTP_G(curlbuf
).used
, buf
, len
);
160 HTTP_G(curlbuf
).free
-= len
;
161 HTTP_G(curlbuf
).used
+= len
;
166 /* {{{ static inline zval *http_curl_getopt(HashTable *, char *, int, ...) */
167 static inline zval
*_http_curl_getopt(HashTable
*options
, char *key TSRMLS_DC
, int checks
, ...)
173 if (SUCCESS
!= zend_hash_find(options
, key
, strlen(key
) + 1, (void **) &zoption
)) {
180 va_start(types
, checks
);
181 for (i
= 0; i
< checks
; ++i
) {
182 if ((va_arg(types
, int)) == (Z_TYPE_PP(zoption
))) {
192 /* {{{ static inline void http_curl_setopts(CURL *, char *, HashTable *) */
193 static inline void _http_curl_setopts(CURL
*ch
, const char *url
, HashTable
*options TSRMLS_DC
)
197 /* standard options */
198 curl_easy_setopt(ch
, CURLOPT_URL
, url
);
199 curl_easy_setopt(ch
, CURLOPT_HEADER
, 0);
200 curl_easy_setopt(ch
, CURLOPT_NOPROGRESS
, 1);
201 curl_easy_setopt(ch
, CURLOPT_AUTOREFERER
, 1);
202 curl_easy_setopt(ch
, CURLOPT_WRITEFUNCTION
, http_curl_body_callback
);
203 curl_easy_setopt(ch
, CURLOPT_HEADERFUNCTION
, http_curl_hdrs_callback
);
204 #if defined(ZTS) && (LIBCURL_VERSION_NUM >= 0x070a00)
205 curl_easy_setopt(ch
, CURLOPT_NOSIGNAL
, 1);
208 if ((!options
) || (1 > zend_hash_num_elements(options
))) {
212 /* redirects, defaults to 0 */
213 if (zoption
= http_curl_getopt1(options
, "redirect", IS_LONG
)) {
214 curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, Z_LVAL_P(zoption
) ? 1 : 0);
215 curl_easy_setopt(ch
, CURLOPT_MAXREDIRS
, Z_LVAL_P(zoption
));
216 if (zoption
= http_curl_getopt2(options
, "unrestrictedauth", IS_LONG
, IS_BOOL
)) {
217 curl_easy_setopt(ch
, CURLOPT_UNRESTRICTED_AUTH
, Z_LVAL_P(zoption
));
220 curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, 0);
224 if (zoption
= http_curl_getopt1(options
, "proxyhost", IS_STRING
)) {
225 curl_easy_setopt(ch
, CURLOPT_PROXY
, http_curl_copystr(Z_STRVAL_P(zoption
)));
227 if (zoption
= http_curl_getopt1(options
, "proxyport", IS_LONG
)) {
228 curl_easy_setopt(ch
, CURLOPT_PROXYPORT
, Z_LVAL_P(zoption
));
231 if (zoption
= http_curl_getopt1(options
, "proxyauth", IS_STRING
)) {
232 curl_easy_setopt(ch
, CURLOPT_PROXYUSERPWD
, http_curl_copystr(Z_STRVAL_P(zoption
)));
234 #if LIBCURL_VERSION_NUM > 0x070a06
236 if (zoption
= http_curl_getopt1(options
, "proxyauthtype", IS_LONG
)) {
237 curl_easy_setopt(ch
, CURLOPT_PROXYAUTH
, Z_LVAL_P(zoption
));
243 if (zoption
= http_curl_getopt1(options
, "httpauth", IS_STRING
)) {
244 curl_easy_setopt(ch
, CURLOPT_USERPWD
, http_curl_copystr(Z_STRVAL_P(zoption
)));
246 #if LIBCURL_VERSION_NUM > 0x070a05
247 if (zoption
= http_curl_getopt1(options
, "httpauthtype", IS_LONG
)) {
248 curl_easy_setopt(ch
, CURLOPT_HTTPAUTH
, Z_LVAL_P(zoption
));
252 /* compress, enabled by default (empty string enables deflate and gzip) */
253 if (zoption
= http_curl_getopt2(options
, "compress", IS_LONG
, IS_BOOL
)) {
254 if (Z_LVAL_P(zoption
)) {
255 curl_easy_setopt(ch
, CURLOPT_ENCODING
, "");
260 if (zoption
= http_curl_getopt1(options
, "port", IS_LONG
)) {
261 curl_easy_setopt(ch
, CURLOPT_PORT
, Z_LVAL_P(zoption
));
265 if (zoption
= http_curl_getopt1(options
, "referer", IS_STRING
)) {
266 curl_easy_setopt(ch
, CURLOPT_REFERER
, http_curl_copystr(Z_STRVAL_P(zoption
)));
269 /* useragent, default "PECL::HTTP/version (PHP/version)" */
270 if (zoption
= http_curl_getopt1(options
, "useragent", IS_STRING
)) {
271 curl_easy_setopt(ch
, CURLOPT_USERAGENT
, http_curl_copystr(Z_STRVAL_P(zoption
)));
273 curl_easy_setopt(ch
, CURLOPT_USERAGENT
,
274 "PECL::HTTP/" PHP_EXT_HTTP_VERSION
" (PHP/" PHP_VERSION
")");
277 /* cookies, array('name' => 'value') */
278 if (zoption
= http_curl_getopt1(options
, "cookies", IS_ARRAY
)) {
282 smart_str qstr
= {0};
284 zend_hash_internal_pointer_reset(Z_ARRVAL_P(zoption
));
285 while (HASH_KEY_NON_EXISTANT
!= (key_type
= zend_hash_get_current_key_type(Z_ARRVAL_P(zoption
)))) {
286 if (key_type
== HASH_KEY_IS_STRING
) {
287 zend_hash_get_current_key(Z_ARRVAL_P(zoption
), &cookie_key
, NULL
, 0);
288 zend_hash_get_current_data(Z_ARRVAL_P(zoption
), (void **) &cookie_val
);
289 smart_str_appends(&qstr
, cookie_key
);
290 smart_str_appendl(&qstr
, "=", 1);
291 smart_str_appendl(&qstr
, Z_STRVAL_PP(cookie_val
), Z_STRLEN_PP(cookie_val
));
292 smart_str_appendl(&qstr
, "; ", 2);
293 zend_hash_move_forward(Z_ARRVAL_P(zoption
));
299 curl_easy_setopt(ch
, CURLOPT_COOKIE
, http_curl_copystr(qstr
.c
));
305 if (zoption
= http_curl_getopt1(options
, "cookiestore", IS_STRING
)) {
306 curl_easy_setopt(ch
, CURLOPT_COOKIEFILE
, http_curl_copystr(Z_STRVAL_P(zoption
)));
307 curl_easy_setopt(ch
, CURLOPT_COOKIEJAR
, http_curl_copystr(Z_STRVAL_P(zoption
)));
310 /* additional headers, array('name' => 'value') */
311 if (zoption
= http_curl_getopt1(options
, "headers", IS_ARRAY
)) {
313 char *header_key
, header
[1024] = {0};
315 struct curl_slist
*headers
= NULL
;
317 zend_hash_internal_pointer_reset(Z_ARRVAL_P(zoption
));
318 while (HASH_KEY_NON_EXISTANT
!= (key_type
= zend_hash_get_current_key_type(Z_ARRVAL_P(zoption
)))) {
319 if (key_type
== HASH_KEY_IS_STRING
) {
320 zend_hash_get_current_key(Z_ARRVAL_P(zoption
), &header_key
, NULL
, 0);
321 zend_hash_get_current_data(Z_ARRVAL_P(zoption
), (void **) &header_val
);
322 snprintf(header
, 1023, "%s: %s", header_key
, Z_STRVAL_PP(header_val
));
323 headers
= curl_slist_append(headers
, http_curl_copystr(header
));
324 zend_hash_move_forward(Z_ARRVAL_P(zoption
));
328 curl_easy_setopt(ch
, CURLOPT_HTTPHEADER
, headers
);
334 /* {{{ static inline char *http_curl_getinfoname(CURLINFO) */
335 static inline char *_http_curl_getinfoname(CURLINFO i TSRMLS_DC
)
337 #define CASE(I) case CURLINFO_ ##I : { return pretty_key(http_curl_copystr(#I), sizeof(#I)-1, 0, 0); }
340 /* CURLINFO_EFFECTIVE_URL = CURLINFO_STRING +1, */
342 /* CURLINFO_RESPONSE_CODE = CURLINFO_LONG +2, */
343 #if LIBCURL_VERSION_NUM > 0x070a06
348 /* CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE +3, */
350 /* CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE +4, */
351 CASE(NAMELOOKUP_TIME
);
352 /* CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE +5, */
354 /* CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE +6, */
355 CASE(PRETRANSFER_TIME
);
356 /* CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE +7, */
358 /* CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE +8, */
360 /* CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE +9, */
361 CASE(SPEED_DOWNLOAD
);
362 /* CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE +10, */
364 /* CURLINFO_HEADER_SIZE = CURLINFO_LONG +11, */
366 /* CURLINFO_REQUEST_SIZE = CURLINFO_LONG +12, */
368 /* CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG +13, */
369 CASE(SSL_VERIFYRESULT
);
370 /* CURLINFO_FILETIME = CURLINFO_LONG +14, */
372 /* CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE +15, */
373 CASE(CONTENT_LENGTH_DOWNLOAD
);
374 /* CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE +16, */
375 CASE(CONTENT_LENGTH_UPLOAD
);
376 /* CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE +17, */
377 CASE(STARTTRANSFER_TIME
);
378 /* CURLINFO_CONTENT_TYPE = CURLINFO_STRING +18, */
380 /* CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE +19, */
382 /* CURLINFO_REDIRECT_COUNT = CURLINFO_LONG +20, */
383 CASE(REDIRECT_COUNT
);
384 /* CURLINFO_PRIVATE = CURLINFO_STRING +21, * (mike) /
386 /* CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG +22, */
387 CASE(HTTP_CONNECTCODE
);
388 #if LIBCURL_VERSION_NUM > 0x070a07
389 /* CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG +23, */
390 CASE(HTTPAUTH_AVAIL
);
391 /* CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG +24, */
392 CASE(PROXYAUTH_AVAIL
);
400 /* {{{ static inline void http_curl_getinfo_ex(CURL, CURLINFO, zval *) */
401 static inline void _http_curl_getinfo_ex(CURL
*ch
, CURLINFO i
, zval
*array TSRMLS_DC
)
404 if (key
= http_curl_getinfoname(i
)) {
405 switch (i
& ~CURLINFO_MASK
)
407 case CURLINFO_STRING
:
410 if (CURLE_OK
== curl_easy_getinfo(ch
, i
, &c
)) {
411 add_assoc_string(array
, key
, c
? c
: "", 1);
416 case CURLINFO_DOUBLE
:
419 if (CURLE_OK
== curl_easy_getinfo(ch
, i
, &d
)) {
420 add_assoc_double(array
, key
, d
);
428 if (CURLE_OK
== curl_easy_getinfo(ch
, i
, &l
)) {
429 add_assoc_long(array
, key
, l
);
438 /* {{{ static inline http_curl_getinfo(CURL, HashTable *) */
439 static inline void _http_curl_getinfo(CURL
*ch
, HashTable
*info TSRMLS_DC
)
442 Z_ARRVAL(array
) = info
;
444 #define INFO(I) http_curl_getinfo_ex(ch, CURLINFO_ ##I , &array)
445 /* CURLINFO_EFFECTIVE_URL = CURLINFO_STRING +1, */
447 #if LIBCURL_VERSION_NUM > 0x070a06
448 /* CURLINFO_RESPONSE_CODE = CURLINFO_LONG +2, */
453 /* CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE +3, */
455 /* CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE +4, */
456 INFO(NAMELOOKUP_TIME
);
457 /* CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE +5, */
459 /* CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE +6, */
460 INFO(PRETRANSFER_TIME
);
461 /* CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE +7, */
463 /* CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE +8, */
465 /* CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE +9, */
466 INFO(SPEED_DOWNLOAD
);
467 /* CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE +10, */
469 /* CURLINFO_HEADER_SIZE = CURLINFO_LONG +11, */
471 /* CURLINFO_REQUEST_SIZE = CURLINFO_LONG +12, */
473 /* CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG +13, */
474 INFO(SSL_VERIFYRESULT
);
475 /* CURLINFO_FILETIME = CURLINFO_LONG +14, */
477 /* CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE +15, */
478 INFO(CONTENT_LENGTH_DOWNLOAD
);
479 /* CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE +16, */
480 INFO(CONTENT_LENGTH_UPLOAD
);
481 /* CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE +17, */
482 INFO(STARTTRANSFER_TIME
);
483 /* CURLINFO_CONTENT_TYPE = CURLINFO_STRING +18, */
485 /* CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE +19, */
487 /* CURLINFO_REDIRECT_COUNT = CURLINFO_LONG +20, */
488 INFO(REDIRECT_COUNT
);
489 /* CURLINFO_PRIVATE = CURLINFO_STRING +21, */
491 /* CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG +22, */
492 INFO(HTTP_CONNECTCODE
);
493 #if LIBCURL_VERSION_NUM > 0x070a07
494 /* CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG +23, */
495 INFO(HTTPAUTH_AVAIL
);
496 /* CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG +24, */
497 INFO(PROXYAUTH_AVAIL
);
503 /* {{{ STATUS http_get_ex(CURL *, char *, HashTable *, HashTable *, char **, size_t *) */
504 PHP_HTTP_API STATUS
_http_get_ex(CURL
*ch
, const char *URL
, HashTable
*options
,
505 HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
507 zend_bool clean_curl
= 0;
509 http_curl_startup(ch
, clean_curl
, URL
, options
);
510 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 0);
511 curl_easy_setopt(ch
, CURLOPT_POST
, 0);
513 if (CURLE_OK
!= curl_easy_perform(ch
)) {
514 http_curl_cleanup(ch
, clean_curl
);
515 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
520 http_curl_getinfo(ch
, info
);
523 http_curl_copybuf(data
, data_len
);
524 http_curl_cleanup(ch
, clean_curl
);
529 /* {{{ STATUS http_head_ex(CURL *, char *, HashTable *, HashTable *, char **data, size_t *) */
530 PHP_HTTP_API STATUS
_http_head_ex(CURL
*ch
, const char *URL
, HashTable
*options
,
531 HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
533 zend_bool clean_curl
= 0;
535 http_curl_startup(ch
, clean_curl
, URL
, options
);
536 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 1);
537 curl_easy_setopt(ch
, CURLOPT_POST
, 0);
539 if (CURLE_OK
!= curl_easy_perform(ch
)) {
540 http_curl_cleanup(ch
, clean_curl
);
541 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
546 http_curl_getinfo(ch
, info
);
549 http_curl_copybuf(data
, data_len
);
550 http_curl_cleanup(ch
, clean_curl
);
555 /* {{{ STATUS http_post_data_ex(CURL *, char *, char *, size_t, HashTable *, HashTable *, char **, size_t *) */
556 PHP_HTTP_API STATUS
_http_post_data_ex(CURL
*ch
, const char *URL
, char *postdata
,
557 size_t postdata_len
, HashTable
*options
, HashTable
*info
, char **data
,
558 size_t *data_len TSRMLS_DC
)
560 zend_bool clean_curl
= 0;
562 http_curl_startup(ch
, clean_curl
, URL
, options
);
563 curl_easy_setopt(ch
, CURLOPT_POST
, 1);
564 curl_easy_setopt(ch
, CURLOPT_POSTFIELDS
, postdata
);
565 curl_easy_setopt(ch
, CURLOPT_POSTFIELDSIZE
, postdata_len
);
567 if (CURLE_OK
!= curl_easy_perform(ch
)) {
568 http_curl_cleanup(ch
, clean_curl
);
569 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
574 http_curl_getinfo(ch
, info
);
577 http_curl_copybuf(data
, data_len
);
578 http_curl_cleanup(ch
, clean_curl
);
584 /* {{{ STATUS http_post_array_ex(CURL *, char *, HashTable *, HashTable *, HashTable *, char **, size_t *) */
585 PHP_HTTP_API STATUS
_http_post_array_ex(CURL
*ch
, const char *URL
, HashTable
*postarray
,
586 HashTable
*options
, HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
588 smart_str qstr
= {0};
591 HTTP_URL_ARGSEP_OVERRIDE
;
592 if (php_url_encode_hash_ex(postarray
, &qstr
, NULL
,0,NULL
,0,NULL
,0,NULL TSRMLS_CC
) != SUCCESS
) {
596 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not encode post data");
597 HTTP_URL_ARGSEP_RESTORE
;
601 HTTP_URL_ARGSEP_RESTORE
;
603 status
= http_post_data_ex(ch
, URL
, qstr
.c
, qstr
.len
, options
, info
, data
, data_len
);
612 /* {{{ STATUS http_post_curldata_ex(CURL *, char *, curl_httppost *, HashTable *, HashTable *, char **, size_t *) */
613 PHP_HTTP_API STATUS
_http_post_curldata_ex(CURL
*ch
, const char *URL
,
614 struct curl_httppost
*curldata
, HashTable
*options
, HashTable
*info
,
615 char **data
, size_t *data_len TSRMLS_DC
)
617 zend_bool clean_curl
= 0;
619 http_curl_startup(ch
, clean_curl
, URL
, options
);
620 curl_easy_setopt(ch
, CURLOPT_POST
, 1);
621 curl_easy_setopt(ch
, CURLOPT_HTTPPOST
, curldata
);
623 if (CURLE_OK
!= curl_easy_perform(ch
)) {
624 http_curl_cleanup(ch
, clean_curl
);
625 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
630 http_curl_getinfo(ch
, info
);
633 http_curl_copybuf(data
, data_len
);
634 http_curl_cleanup(ch
, clean_curl
);
645 * vim600: noet sw=4 ts=4 fdm=marker
646 * vim<600: noet sw=4 ts=4