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"
37 #include "ext/standard/php_smart_str.h"
39 ZEND_DECLARE_MODULE_GLOBALS(http
)
41 #define http_curl_startup(ch, clean_curl, URL, options) \
43 if (!(ch = curl_easy_init())) { \
44 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not initialize curl"); \
49 http_curl_initbuf(); \
50 http_curl_setopts(ch, URL, options);
53 #define http_curl_cleanup(ch, clean_curl) \
54 http_curl_freestr(); \
55 http_curl_freebuf(); \
57 curl_easy_cleanup(ch); \
61 #define http_curl_freestr() \
62 zend_llist_clean(&HTTP_G(to_free))
64 #define http_curl_initbuf() http_curl_initbuf_ex(0)
66 #define http_curl_initbuf_ex(chunk_size) \
68 size_t size = (chunk_size > 0) ? chunk_size : HTTP_CURLBUF_SIZE; \
69 http_curl_freebuf(); \
70 HTTP_G(curlbuf).data = emalloc(size); \
71 HTTP_G(curlbuf).free = size; \
72 HTTP_G(curlbuf).size = size; \
75 #define http_curl_freebuf() \
76 if (HTTP_G(curlbuf).data) { \
77 efree(HTTP_G(curlbuf).data); \
78 HTTP_G(curlbuf).data = NULL; \
80 HTTP_G(curlbuf).used = 0; \
81 HTTP_G(curlbuf).free = 0; \
82 HTTP_G(curlbuf).size = 0;
84 #define http_curl_copybuf(data, size) \
85 * size = HTTP_G(curlbuf).used; \
86 * data = ecalloc(1, HTTP_G(curlbuf).used + 1); \
87 memcpy(* data, HTTP_G(curlbuf).data, * size);
89 #define http_curl_sizebuf(for_size) \
91 size_t size = (for_size); \
92 if (size > HTTP_G(curlbuf).free) { \
93 size_t bsize = HTTP_G(curlbuf).size; \
94 while (size > bsize) { \
97 HTTP_G(curlbuf).data = erealloc(HTTP_G(curlbuf).data, HTTP_G(curlbuf).used + bsize); \
98 HTTP_G(curlbuf).free += bsize; \
103 #define http_curl_copystr(s) _http_curl_copystr((s) TSRMLS_CC)
104 static inline char *_http_curl_copystr(const char *str TSRMLS_DC
);
106 #define http_curl_setopts(c, u, o) _http_curl_setopts((c), (u), (o) TSRMLS_CC)
107 static inline void _http_curl_setopts(CURL
*ch
, const char *url
, HashTable
*options TSRMLS_DC
);
109 #define http_curl_getopt(o, k) _http_curl_getopt((o), (k) TSRMLS_CC, 0)
110 #define http_curl_getopt1(o, k, t1) _http_curl_getopt((o), (k) TSRMLS_CC, 1, (t1))
111 #define http_curl_getopt2(o, k, t1, t2) _http_curl_getopt((o), (k) TSRMLS_CC, 2, (t1), (t2))
112 static inline zval
*_http_curl_getopt(HashTable
*options
, char *key TSRMLS_DC
, int checks
, ...);
114 static size_t http_curl_body_callback(char *, size_t, size_t, void *);
115 static size_t http_curl_hdrs_callback(char *, size_t, size_t, void *);
117 #define http_curl_getinfo(c, h) _http_curl_getinfo((c), (h) TSRMLS_CC)
118 static inline void _http_curl_getinfo(CURL
*ch
, HashTable
*info TSRMLS_DC
);
119 #define http_curl_getinfo_ex(c, i, a) _http_curl_getinfo_ex((c), (i), (a) TSRMLS_CC)
120 static inline void _http_curl_getinfo_ex(CURL
*ch
, CURLINFO i
, zval
*array TSRMLS_DC
);
121 #define http_curl_getinfoname(i) _http_curl_getinfoname((i) TSRMLS_CC)
122 static inline char *_http_curl_getinfoname(CURLINFO i TSRMLS_DC
);
124 /* {{{ static inline char *http_curl_copystr(char *) */
125 static inline char *_http_curl_copystr(const char *str TSRMLS_DC
)
127 char *new_str
= estrdup(str
);
128 zend_llist_add_element(&HTTP_G(to_free
), &new_str
);
133 /* {{{ static size_t http_curl_body_callback(char *, size_t, size_t, void *) */
134 static size_t http_curl_body_callback(char *buf
, size_t len
, size_t n
, void *s
)
138 http_curl_sizebuf(len
*= n
);
140 memcpy(HTTP_G(curlbuf
).data
+ HTTP_G(curlbuf
).used
, buf
, len
);
141 HTTP_G(curlbuf
).free
-= len
;
142 HTTP_G(curlbuf
).used
+= len
;
147 /* {{{ static size_t http_curl_hdrs_callback(char *, size_t, size_t, void *) */
148 static size_t http_curl_hdrs_callback(char *buf
, size_t len
, size_t n
, void *s
)
152 /* discard previous headers */
153 if ((HTTP_G(curlbuf
).used
) && (!strncmp(buf
, "HTTP/1.", sizeof("HTTP/1.") - 1))) {
156 http_curl_sizebuf(len
*= n
);
158 memcpy(HTTP_G(curlbuf
).data
+ HTTP_G(curlbuf
).used
, buf
, len
);
159 HTTP_G(curlbuf
).free
-= len
;
160 HTTP_G(curlbuf
).used
+= len
;
165 /* {{{ static inline zval *http_curl_getopt(HashTable *, char *, int, ...) */
166 static inline zval
*_http_curl_getopt(HashTable
*options
, char *key TSRMLS_DC
, int checks
, ...)
172 if (SUCCESS
!= zend_hash_find(options
, key
, strlen(key
) + 1, (void **) &zoption
)) {
179 va_start(types
, checks
);
180 for (i
= 0; i
< checks
; ++i
) {
181 if ((va_arg(types
, int)) == (Z_TYPE_PP(zoption
))) {
191 /* {{{ static inline void http_curl_setopts(CURL *, char *, HashTable *) */
192 static inline void _http_curl_setopts(CURL
*ch
, const char *url
, HashTable
*options TSRMLS_DC
)
196 /* standard options */
197 curl_easy_setopt(ch
, CURLOPT_URL
, url
);
198 curl_easy_setopt(ch
, CURLOPT_HEADER
, 0);
199 curl_easy_setopt(ch
, CURLOPT_NOPROGRESS
, 1);
200 curl_easy_setopt(ch
, CURLOPT_AUTOREFERER
, 1);
201 curl_easy_setopt(ch
, CURLOPT_WRITEFUNCTION
, http_curl_body_callback
);
202 curl_easy_setopt(ch
, CURLOPT_HEADERFUNCTION
, http_curl_hdrs_callback
);
203 #if defined(ZTS) && (LIBCURL_VERSION_NUM >= 0x070a00)
204 curl_easy_setopt(ch
, CURLOPT_NOSIGNAL
, 1);
207 if ((!options
) || (1 > zend_hash_num_elements(options
))) {
211 /* redirects, defaults to 0 */
212 if (zoption
= http_curl_getopt1(options
, "redirect", IS_LONG
)) {
213 curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, Z_LVAL_P(zoption
) ? 1 : 0);
214 curl_easy_setopt(ch
, CURLOPT_MAXREDIRS
, Z_LVAL_P(zoption
));
215 if (zoption
= http_curl_getopt2(options
, "unrestrictedauth", IS_LONG
, IS_BOOL
)) {
216 curl_easy_setopt(ch
, CURLOPT_UNRESTRICTED_AUTH
, Z_LVAL_P(zoption
));
219 curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, 0);
223 if (zoption
= http_curl_getopt1(options
, "proxyhost", IS_STRING
)) {
224 curl_easy_setopt(ch
, CURLOPT_PROXY
, http_curl_copystr(Z_STRVAL_P(zoption
)));
226 if (zoption
= http_curl_getopt1(options
, "proxyport", IS_LONG
)) {
227 curl_easy_setopt(ch
, CURLOPT_PROXYPORT
, Z_LVAL_P(zoption
));
230 if (zoption
= http_curl_getopt1(options
, "proxyauth", IS_STRING
)) {
231 curl_easy_setopt(ch
, CURLOPT_PROXYUSERPWD
, http_curl_copystr(Z_STRVAL_P(zoption
)));
233 #if LIBCURL_VERSION_NUM > 0x070a06
235 if (zoption
= http_curl_getopt1(options
, "proxyauthtype", IS_LONG
)) {
236 curl_easy_setopt(ch
, CURLOPT_PROXYAUTH
, Z_LVAL_P(zoption
));
242 if (zoption
= http_curl_getopt1(options
, "httpauth", IS_STRING
)) {
243 curl_easy_setopt(ch
, CURLOPT_USERPWD
, http_curl_copystr(Z_STRVAL_P(zoption
)));
245 #if LIBCURL_VERSION_NUM > 0x070a05
246 if (zoption
= http_curl_getopt1(options
, "httpauthtype", IS_LONG
)) {
247 curl_easy_setopt(ch
, CURLOPT_HTTPAUTH
, Z_LVAL_P(zoption
));
251 /* compress, enabled by default (empty string enables deflate and gzip) */
252 if (zoption
= http_curl_getopt2(options
, "compress", IS_LONG
, IS_BOOL
)) {
253 if (Z_LVAL_P(zoption
)) {
254 curl_easy_setopt(ch
, CURLOPT_ENCODING
, "");
257 curl_easy_setopt(ch
, CURLOPT_ENCODING
, "");
261 if (zoption
= http_curl_getopt1(options
, "port", IS_LONG
)) {
262 curl_easy_setopt(ch
, CURLOPT_PORT
, Z_LVAL_P(zoption
));
266 if (zoption
= http_curl_getopt1(options
, "referer", IS_STRING
)) {
267 curl_easy_setopt(ch
, CURLOPT_REFERER
, http_curl_copystr(Z_STRVAL_P(zoption
)));
270 /* useragent, default "PECL::HTTP/version (PHP/version)" */
271 if (zoption
= http_curl_getopt1(options
, "useragent", IS_STRING
)) {
272 curl_easy_setopt(ch
, CURLOPT_USERAGENT
, http_curl_copystr(Z_STRVAL_P(zoption
)));
274 curl_easy_setopt(ch
, CURLOPT_USERAGENT
,
275 "PECL::HTTP/" PHP_EXT_HTTP_VERSION
" (PHP/" PHP_VERSION
")");
278 /* cookies, array('name' => 'value') */
279 if (zoption
= http_curl_getopt1(options
, "cookies", IS_ARRAY
)) {
283 smart_str qstr
= {0};
285 zend_hash_internal_pointer_reset(Z_ARRVAL_P(zoption
));
286 while (HASH_KEY_NON_EXISTANT
!= (key_type
= zend_hash_get_current_key_type(Z_ARRVAL_P(zoption
)))) {
287 if (key_type
== HASH_KEY_IS_STRING
) {
288 zend_hash_get_current_key(Z_ARRVAL_P(zoption
), &cookie_key
, NULL
, 0);
289 zend_hash_get_current_data(Z_ARRVAL_P(zoption
), (void **) &cookie_val
);
290 smart_str_appends(&qstr
, cookie_key
);
291 smart_str_appendl(&qstr
, "=", 1);
292 smart_str_appendl(&qstr
, Z_STRVAL_PP(cookie_val
), Z_STRLEN_PP(cookie_val
));
293 smart_str_appendl(&qstr
, "; ", 2);
294 zend_hash_move_forward(Z_ARRVAL_P(zoption
));
300 curl_easy_setopt(ch
, CURLOPT_COOKIE
, http_curl_copystr(qstr
.c
));
306 if (zoption
= http_curl_getopt1(options
, "cookiestore", IS_STRING
)) {
307 curl_easy_setopt(ch
, CURLOPT_COOKIEFILE
, http_curl_copystr(Z_STRVAL_P(zoption
)));
308 curl_easy_setopt(ch
, CURLOPT_COOKIEJAR
, http_curl_copystr(Z_STRVAL_P(zoption
)));
311 /* additional headers, array('name' => 'value') */
312 if (zoption
= http_curl_getopt1(options
, "headers", IS_ARRAY
)) {
314 char *header_key
, header
[1024] = {0};
316 struct curl_slist
*headers
= NULL
;
318 zend_hash_internal_pointer_reset(Z_ARRVAL_P(zoption
));
319 while (HASH_KEY_NON_EXISTANT
!= (key_type
= zend_hash_get_current_key_type(Z_ARRVAL_P(zoption
)))) {
320 if (key_type
== HASH_KEY_IS_STRING
) {
321 zend_hash_get_current_key(Z_ARRVAL_P(zoption
), &header_key
, NULL
, 0);
322 zend_hash_get_current_data(Z_ARRVAL_P(zoption
), (void **) &header_val
);
323 snprintf(header
, 1023, "%s: %s", header_key
, Z_STRVAL_PP(header_val
));
324 headers
= curl_slist_append(headers
, http_curl_copystr(header
));
325 zend_hash_move_forward(Z_ARRVAL_P(zoption
));
329 curl_easy_setopt(ch
, CURLOPT_HTTPHEADER
, headers
);
335 /* {{{ static inline char *http_curl_getinfoname(CURLINFO) */
336 static inline char *_http_curl_getinfoname(CURLINFO i TSRMLS_DC
)
338 #define CASE(I) case CURLINFO_ ##I : { return pretty_key(http_curl_copystr(#I), sizeof(#I)-1, 0, 0); }
341 /* CURLINFO_EFFECTIVE_URL = CURLINFO_STRING +1, */
343 /* CURLINFO_RESPONSE_CODE = CURLINFO_LONG +2, */
344 #if LIBCURL_VERSION_NUM > 0x070a06
349 /* CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE +3, */
351 /* CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE +4, */
352 CASE(NAMELOOKUP_TIME
);
353 /* CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE +5, */
355 /* CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE +6, */
356 CASE(PRETRANSFER_TIME
);
357 /* CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE +7, */
359 /* CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE +8, */
361 /* CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE +9, */
362 CASE(SPEED_DOWNLOAD
);
363 /* CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE +10, */
365 /* CURLINFO_HEADER_SIZE = CURLINFO_LONG +11, */
367 /* CURLINFO_REQUEST_SIZE = CURLINFO_LONG +12, */
369 /* CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG +13, */
370 CASE(SSL_VERIFYRESULT
);
371 /* CURLINFO_FILETIME = CURLINFO_LONG +14, */
373 /* CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE +15, */
374 CASE(CONTENT_LENGTH_DOWNLOAD
);
375 /* CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE +16, */
376 CASE(CONTENT_LENGTH_UPLOAD
);
377 /* CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE +17, */
378 CASE(STARTTRANSFER_TIME
);
379 /* CURLINFO_CONTENT_TYPE = CURLINFO_STRING +18, */
381 /* CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE +19, */
383 /* CURLINFO_REDIRECT_COUNT = CURLINFO_LONG +20, */
384 CASE(REDIRECT_COUNT
);
385 /* CURLINFO_PRIVATE = CURLINFO_STRING +21, * (mike) /
387 /* CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG +22, */
388 CASE(HTTP_CONNECTCODE
);
389 #if LIBCURL_VERSION_NUM > 0x070a07
390 /* CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG +23, */
391 CASE(HTTPAUTH_AVAIL
);
392 /* CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG +24, */
393 CASE(PROXYAUTH_AVAIL
);
401 /* {{{ static inline void http_curl_getinfo_ex(CURL, CURLINFO, zval *) */
402 static inline void _http_curl_getinfo_ex(CURL
*ch
, CURLINFO i
, zval
*array TSRMLS_DC
)
405 if (key
= http_curl_getinfoname(i
)) {
406 switch (i
& ~CURLINFO_MASK
)
408 case CURLINFO_STRING
:
411 if (CURLE_OK
== curl_easy_getinfo(ch
, i
, &c
)) {
412 add_assoc_string(array
, key
, c
? c
: "", 1);
417 case CURLINFO_DOUBLE
:
420 if (CURLE_OK
== curl_easy_getinfo(ch
, i
, &d
)) {
421 add_assoc_double(array
, key
, d
);
429 if (CURLE_OK
== curl_easy_getinfo(ch
, i
, &l
)) {
430 add_assoc_long(array
, key
, l
);
439 /* {{{ static inline http_curl_getinfo(CURL, HashTable *) */
440 static inline void _http_curl_getinfo(CURL
*ch
, HashTable
*info TSRMLS_DC
)
443 Z_ARRVAL(array
) = info
;
445 #define INFO(I) http_curl_getinfo_ex(ch, CURLINFO_ ##I , &array)
446 /* CURLINFO_EFFECTIVE_URL = CURLINFO_STRING +1, */
448 #if LIBCURL_VERSION_NUM > 0x070a06
449 /* CURLINFO_RESPONSE_CODE = CURLINFO_LONG +2, */
454 /* CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE +3, */
456 /* CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE +4, */
457 INFO(NAMELOOKUP_TIME
);
458 /* CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE +5, */
460 /* CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE +6, */
461 INFO(PRETRANSFER_TIME
);
462 /* CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE +7, */
464 /* CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE +8, */
466 /* CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE +9, */
467 INFO(SPEED_DOWNLOAD
);
468 /* CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE +10, */
470 /* CURLINFO_HEADER_SIZE = CURLINFO_LONG +11, */
472 /* CURLINFO_REQUEST_SIZE = CURLINFO_LONG +12, */
474 /* CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG +13, */
475 INFO(SSL_VERIFYRESULT
);
476 /* CURLINFO_FILETIME = CURLINFO_LONG +14, */
478 /* CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE +15, */
479 INFO(CONTENT_LENGTH_DOWNLOAD
);
480 /* CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE +16, */
481 INFO(CONTENT_LENGTH_UPLOAD
);
482 /* CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE +17, */
483 INFO(STARTTRANSFER_TIME
);
484 /* CURLINFO_CONTENT_TYPE = CURLINFO_STRING +18, */
486 /* CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE +19, */
488 /* CURLINFO_REDIRECT_COUNT = CURLINFO_LONG +20, */
489 INFO(REDIRECT_COUNT
);
490 /* CURLINFO_PRIVATE = CURLINFO_STRING +21, */
492 /* CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG +22, */
493 INFO(HTTP_CONNECTCODE
);
494 #if LIBCURL_VERSION_NUM > 0x070a07
495 /* CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG +23, */
496 INFO(HTTPAUTH_AVAIL
);
497 /* CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG +24, */
498 INFO(PROXYAUTH_AVAIL
);
504 /* {{{ STATUS http_get_ex(CURL *, char *, HashTable *, HashTable *, char **, size_t *) */
505 PHP_HTTP_API STATUS
_http_get_ex(CURL
*ch
, const char *URL
, HashTable
*options
,
506 HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
508 zend_bool clean_curl
= 0;
510 http_curl_startup(ch
, clean_curl
, URL
, options
);
511 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 0);
512 curl_easy_setopt(ch
, CURLOPT_POST
, 0);
514 if (CURLE_OK
!= curl_easy_perform(ch
)) {
515 http_curl_cleanup(ch
, clean_curl
);
516 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
521 http_curl_getinfo(ch
, info
);
524 http_curl_copybuf(data
, data_len
);
525 http_curl_cleanup(ch
, clean_curl
);
530 /* {{{ STATUS http_head_ex(CURL *, char *, HashTable *, HashTable *, char **data, size_t *) */
531 PHP_HTTP_API STATUS
_http_head_ex(CURL
*ch
, const char *URL
, HashTable
*options
,
532 HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
534 zend_bool clean_curl
= 0;
536 http_curl_startup(ch
, clean_curl
, URL
, options
);
537 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 1);
538 curl_easy_setopt(ch
, CURLOPT_POST
, 0);
540 if (CURLE_OK
!= curl_easy_perform(ch
)) {
541 http_curl_cleanup(ch
, clean_curl
);
542 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
547 http_curl_getinfo(ch
, info
);
550 http_curl_copybuf(data
, data_len
);
551 http_curl_cleanup(ch
, clean_curl
);
556 /* {{{ STATUS http_post_data_ex(CURL *, char *, char *, size_t, HashTable *, HashTable *, char **, size_t *) */
557 PHP_HTTP_API STATUS
_http_post_data_ex(CURL
*ch
, const char *URL
, char *postdata
,
558 size_t postdata_len
, HashTable
*options
, HashTable
*info
, char **data
,
559 size_t *data_len TSRMLS_DC
)
561 zend_bool clean_curl
= 0;
563 http_curl_startup(ch
, clean_curl
, URL
, options
);
564 curl_easy_setopt(ch
, CURLOPT_POST
, 1);
565 curl_easy_setopt(ch
, CURLOPT_POSTFIELDS
, postdata
);
566 curl_easy_setopt(ch
, CURLOPT_POSTFIELDSIZE
, postdata_len
);
568 if (CURLE_OK
!= curl_easy_perform(ch
)) {
569 http_curl_cleanup(ch
, clean_curl
);
570 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
575 http_curl_getinfo(ch
, info
);
578 http_curl_copybuf(data
, data_len
);
579 http_curl_cleanup(ch
, clean_curl
);
585 /* {{{ STATUS http_post_array_ex(CURL *, char *, HashTable *, HashTable *, HashTable *, char **, size_t *) */
586 PHP_HTTP_API STATUS
_http_post_array_ex(CURL
*ch
, const char *URL
, HashTable
*postarray
,
587 HashTable
*options
, HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
589 smart_str qstr
= {0};
592 HTTP_URL_ARGSEP_OVERRIDE
;
593 if (php_url_encode_hash_ex(postarray
, &qstr
, NULL
,0,NULL
,0,NULL
,0,NULL TSRMLS_CC
) != SUCCESS
) {
597 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not encode post data");
598 HTTP_URL_ARGSEP_RESTORE
;
602 HTTP_URL_ARGSEP_RESTORE
;
604 status
= http_post_data_ex(ch
, URL
, qstr
.c
, qstr
.len
, options
, info
, data
, data_len
);
613 /* {{{ STATUS http_post_curldata_ex(CURL *, char *, curl_httppost *, HashTable *, HashTable *, char **, size_t *) */
614 PHP_HTTP_API STATUS
_http_post_curldata_ex(CURL
*ch
, const char *URL
,
615 struct curl_httppost
*curldata
, HashTable
*options
, HashTable
*info
,
616 char **data
, size_t *data_len TSRMLS_DC
)
618 zend_bool clean_curl
= 0;
620 http_curl_startup(ch
, clean_curl
, URL
, options
);
621 curl_easy_setopt(ch
, CURLOPT_POST
, 1);
622 curl_easy_setopt(ch
, CURLOPT_HTTPPOST
, curldata
);
624 if (CURLE_OK
!= curl_easy_perform(ch
)) {
625 http_curl_cleanup(ch
, clean_curl
);
626 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
631 http_curl_getinfo(ch
, info
);
634 http_curl_copybuf(data
, data_len
);
635 http_curl_cleanup(ch
, clean_curl
);
646 * vim600: noet sw=4 ts=4 fdm=marker
647 * vim<600: noet sw=4 ts=4