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_copystr(s) _http_curl_copystr((s) TSRMLS_CC)
42 static inline char *_http_curl_copystr(const char *str TSRMLS_DC
);
43 #define http_curl_freestr() _http_curl_freestr(TSRMLS_C)
44 static inline void _http_curl_freestr(TSRMLS_D
);
46 #define http_curl_initbuf() _http_curl_initbuf_ex(0 TSRMLS_CC)
47 #define http_curl_initbuf_ex(s) _http_curl_initbuf_ex((s) TSRMLS_CC)
48 static inline void _http_curl_initbuf_ex(size_t chunk_size TSRMLS_DC
);
50 #define http_curl_freebuf() _http_curl_freebuf(TSRMLS_C)
51 static inline void _http_curl_freebuf(TSRMLS_D
);
52 #define http_curl_sizebuf(l) _http_curl_sizebuf((l) TSRMLS_CC)
53 static inline void _http_curl_sizebuf(size_t len TSRMLS_DC
);
54 #define http_curl_movebuf(d, l) _http_curl_movebuf((d), (l) TSRMLS_CC)
55 static inline void _http_curl_movebuf(char **data
, size_t *data_len TSRMLS_DC
);
56 #define http_curl_copybuf(d, l) _http_curl_copybuf((d), (l) TSRMLS_CC)
57 static inline void _http_curl_copybuf(char **data
, size_t *data_len TSRMLS_DC
);
58 #define http_curl_setopts(c, u, o) _http_curl_setopts((c), (u), (o) TSRMLS_CC)
59 static inline void _http_curl_setopts(CURL
*ch
, const char *url
, HashTable
*options TSRMLS_DC
);
61 #define http_curl_getopt(o, k) _http_curl_getopt((o), (k) TSRMLS_CC, 0)
62 #define http_curl_getopt1(o, k, t1) _http_curl_getopt((o), (k) TSRMLS_CC, 1, (t1))
63 #define http_curl_getopt2(o, k, t1, t2) _http_curl_getopt((o), (k) TSRMLS_CC, 2, (t1), (t2))
64 static inline zval
*_http_curl_getopt(HashTable
*options
, char *key TSRMLS_DC
, int checks
, ...);
66 static size_t http_curl_body_callback(char *, size_t, size_t, void *);
67 static size_t http_curl_hdrs_callback(char *, size_t, size_t, void *);
69 #define http_curl_getinfo(c, h) _http_curl_getinfo((c), (h) TSRMLS_CC)
70 static inline void _http_curl_getinfo(CURL
*ch
, HashTable
*info TSRMLS_DC
);
71 #define http_curl_getinfo_ex(c, i, a) _http_curl_getinfo_ex((c), (i), (a) TSRMLS_CC)
72 static inline void _http_curl_getinfo_ex(CURL
*ch
, CURLINFO i
, zval
*array TSRMLS_DC
);
73 #define http_curl_getinfoname(i) _http_curl_getinfoname((i) TSRMLS_CC)
74 static inline char *_http_curl_getinfoname(CURLINFO i TSRMLS_DC
);
77 static inline char *_http_curl_copystr(const char *str TSRMLS_DC
)
79 char *new_str
= estrdup(str
);
80 zend_llist_add_element(&HTTP_G(to_free
), &new_str
);
86 static inline void _http_curl_freestr(TSRMLS_D
)
88 zend_llist_clean(&HTTP_G(to_free
));
92 /* {{{ static inline void http_curl_initbuf(size_t chunk_size) */
93 static inline void _http_curl_initbuf_ex(size_t chunk_size TSRMLS_DC
)
95 size_t size
= (chunk_size
> 0) ? chunk_size
: HTTP_CURLBUF_SIZE
;
99 HTTP_G(curlbuf
).data
= emalloc(size
);
100 HTTP_G(curlbuf
).free
= size
;
101 HTTP_G(curlbuf
).size
= size
;
105 /* {{{ static inline void http_curl_freebuf(void) */
106 static inline void _http_curl_freebuf(TSRMLS_D
)
108 if (HTTP_G(curlbuf
).data
) {
109 efree(HTTP_G(curlbuf
).data
);
110 HTTP_G(curlbuf
).data
= NULL
;
112 HTTP_G(curlbuf
).used
= 0;
113 HTTP_G(curlbuf
).free
= 0;
114 HTTP_G(curlbuf
).size
= 0;
118 /* {{{ static inline void http_curl_copybuf(char **, size_t *) */
119 static inline void _http_curl_copybuf(char **data
, size_t *data_len TSRMLS_DC
)
121 *data_len
= HTTP_G(curlbuf
).used
;
123 *data
= ecalloc(1, HTTP_G(curlbuf
).used
+ 1);
124 memcpy(*data
, HTTP_G(curlbuf
).data
, *data_len
);
128 /* {{{ static inline void http_curl_movebuf(char **, size_t *) */
129 static inline void _http_curl_movebuf(char **data
, size_t *data_len TSRMLS_DC
)
131 http_curl_copybuf(data
, data_len
);
136 /* {{{ static inline void http_curl_sizebuf(size_t len) */
137 static inline void _http_curl_sizebuf(size_t len TSRMLS_DC
)
139 if (len
> HTTP_G(curlbuf
).free
) {
140 size_t bsize
= HTTP_G(curlbuf
).size
;
141 while (bsize
< len
) {
144 HTTP_G(curlbuf
).data
= erealloc(HTTP_G(curlbuf
).data
, HTTP_G(curlbuf
).used
+ bsize
);
145 HTTP_G(curlbuf
).free
+= bsize
;
150 /* {{{ static size_t http_curl_body_callback(char *, size_t, size_t, void *) */
151 static size_t http_curl_body_callback(char *buf
, size_t len
, size_t n
, void *s
)
155 http_curl_sizebuf(len
*= n
);
157 memcpy(HTTP_G(curlbuf
).data
+ HTTP_G(curlbuf
).used
, buf
, len
);
158 HTTP_G(curlbuf
).free
-= len
;
159 HTTP_G(curlbuf
).used
+= len
;
164 /* {{{ static size_t http_curl_hdrs_callback(char *, size_t, size_t, void *) */
165 static size_t http_curl_hdrs_callback(char *buf
, size_t len
, size_t n
, void *s
)
169 /* discard previous headers */
170 if ((HTTP_G(curlbuf
).used
) && (!strncmp(buf
, "HTTP/1.", sizeof("HTTP/1.") - 1))) {
173 http_curl_sizebuf(len
*= n
);
175 memcpy(HTTP_G(curlbuf
).data
+ HTTP_G(curlbuf
).used
, buf
, len
);
176 HTTP_G(curlbuf
).free
-= len
;
177 HTTP_G(curlbuf
).used
+= len
;
182 /* {{{ static inline zval *http_curl_getopt(HashTable *, char *, int, ...) */
183 static inline zval
*_http_curl_getopt(HashTable
*options
, char *key TSRMLS_DC
, int checks
, ...)
189 if (SUCCESS
!= zend_hash_find(options
, key
, strlen(key
) + 1, (void **) &zoption
)) {
196 va_start(types
, checks
);
197 for (i
= 0; i
< checks
; ++i
) {
198 if ((va_arg(types
, int)) == (Z_TYPE_PP(zoption
))) {
208 /* {{{ static inline void http_curl_setopts(CURL *, char *, HashTable *) */
209 static inline void _http_curl_setopts(CURL
*ch
, const char *url
, HashTable
*options TSRMLS_DC
)
213 /* standard options */
214 curl_easy_setopt(ch
, CURLOPT_URL
, url
);
215 curl_easy_setopt(ch
, CURLOPT_HEADER
, 0);
216 curl_easy_setopt(ch
, CURLOPT_NOPROGRESS
, 1);
217 curl_easy_setopt(ch
, CURLOPT_AUTOREFERER
, 1);
218 curl_easy_setopt(ch
, CURLOPT_WRITEFUNCTION
, http_curl_body_callback
);
219 curl_easy_setopt(ch
, CURLOPT_HEADERFUNCTION
, http_curl_hdrs_callback
);
220 #if defined(ZTS) && (LIBCURL_VERSION_NUM >= 0x070a00)
221 curl_easy_setopt(ch
, CURLOPT_NOSIGNAL
, 1);
224 if ((!options
) || (1 > zend_hash_num_elements(options
))) {
228 /* redirects, defaults to 0 */
229 if (zoption
= http_curl_getopt1(options
, "redirect", IS_LONG
)) {
230 curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, Z_LVAL_P(zoption
) ? 1 : 0);
231 curl_easy_setopt(ch
, CURLOPT_MAXREDIRS
, Z_LVAL_P(zoption
));
232 if (zoption
= http_curl_getopt2(options
, "unrestrictedauth", IS_LONG
, IS_BOOL
)) {
233 curl_easy_setopt(ch
, CURLOPT_UNRESTRICTED_AUTH
, Z_LVAL_P(zoption
));
236 curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, 0);
240 if (zoption
= http_curl_getopt1(options
, "proxyhost", IS_STRING
)) {
241 curl_easy_setopt(ch
, CURLOPT_PROXY
, http_curl_copystr(Z_STRVAL_P(zoption
)));
243 if (zoption
= http_curl_getopt1(options
, "proxyport", IS_LONG
)) {
244 curl_easy_setopt(ch
, CURLOPT_PROXYPORT
, Z_LVAL_P(zoption
));
247 if (zoption
= http_curl_getopt1(options
, "proxyauth", IS_STRING
)) {
248 curl_easy_setopt(ch
, CURLOPT_PROXYUSERPWD
, http_curl_copystr(Z_STRVAL_P(zoption
)));
250 #if LIBCURL_VERSION_NUM > 0x070a06
252 if (zoption
= http_curl_getopt1(options
, "proxyauthtype", IS_LONG
)) {
253 curl_easy_setopt(ch
, CURLOPT_PROXYAUTH
, Z_LVAL_P(zoption
));
259 if (zoption
= http_curl_getopt1(options
, "httpauth", IS_STRING
)) {
260 curl_easy_setopt(ch
, CURLOPT_USERPWD
, http_curl_copystr(Z_STRVAL_P(zoption
)));
262 #if LIBCURL_VERSION_NUM > 0x070a05
263 if (zoption
= http_curl_getopt1(options
, "httpauthtype", IS_LONG
)) {
264 curl_easy_setopt(ch
, CURLOPT_HTTPAUTH
, Z_LVAL_P(zoption
));
268 /* compress, enabled by default (empty string enables deflate and gzip) */
269 if (zoption
= http_curl_getopt2(options
, "compress", IS_LONG
, IS_BOOL
)) {
270 if (Z_LVAL_P(zoption
)) {
271 curl_easy_setopt(ch
, CURLOPT_ENCODING
, "");
274 curl_easy_setopt(ch
, CURLOPT_ENCODING
, "");
278 if (zoption
= http_curl_getopt1(options
, "port", IS_LONG
)) {
279 curl_easy_setopt(ch
, CURLOPT_PORT
, Z_LVAL_P(zoption
));
283 if (zoption
= http_curl_getopt1(options
, "referer", IS_STRING
)) {
284 curl_easy_setopt(ch
, CURLOPT_REFERER
, http_curl_copystr(Z_STRVAL_P(zoption
)));
287 /* useragent, default "PECL::HTTP/version (PHP/version)" */
288 if (zoption
= http_curl_getopt1(options
, "useragent", IS_STRING
)) {
289 curl_easy_setopt(ch
, CURLOPT_USERAGENT
, http_curl_copystr(Z_STRVAL_P(zoption
)));
291 curl_easy_setopt(ch
, CURLOPT_USERAGENT
,
292 "PECL::HTTP/" PHP_EXT_HTTP_VERSION
" (PHP/" PHP_VERSION
")");
295 /* cookies, array('name' => 'value') */
296 if (zoption
= http_curl_getopt1(options
, "cookies", IS_ARRAY
)) {
300 smart_str qstr
= {0};
302 zend_hash_internal_pointer_reset(Z_ARRVAL_P(zoption
));
303 while (HASH_KEY_NON_EXISTANT
!= (key_type
= zend_hash_get_current_key_type(Z_ARRVAL_P(zoption
)))) {
304 if (key_type
== HASH_KEY_IS_STRING
) {
305 zend_hash_get_current_key(Z_ARRVAL_P(zoption
), &cookie_key
, NULL
, 0);
306 zend_hash_get_current_data(Z_ARRVAL_P(zoption
), (void **) &cookie_val
);
307 smart_str_appends(&qstr
, cookie_key
);
308 smart_str_appendl(&qstr
, "=", 1);
309 smart_str_appendl(&qstr
, Z_STRVAL_PP(cookie_val
), Z_STRLEN_PP(cookie_val
));
310 smart_str_appendl(&qstr
, "; ", 2);
311 zend_hash_move_forward(Z_ARRVAL_P(zoption
));
317 curl_easy_setopt(ch
, CURLOPT_COOKIE
, http_curl_copystr(qstr
.c
));
323 if (zoption
= http_curl_getopt1(options
, "cookiestore", IS_STRING
)) {
324 curl_easy_setopt(ch
, CURLOPT_COOKIEFILE
, http_curl_copystr(Z_STRVAL_P(zoption
)));
325 curl_easy_setopt(ch
, CURLOPT_COOKIEJAR
, http_curl_copystr(Z_STRVAL_P(zoption
)));
328 /* additional headers, array('name' => 'value') */
329 if (zoption
= http_curl_getopt1(options
, "headers", IS_ARRAY
)) {
331 char *header_key
, header
[1024] = {0};
333 struct curl_slist
*headers
= NULL
;
335 zend_hash_internal_pointer_reset(Z_ARRVAL_P(zoption
));
336 while (HASH_KEY_NON_EXISTANT
!= (key_type
= zend_hash_get_current_key_type(Z_ARRVAL_P(zoption
)))) {
337 if (key_type
== HASH_KEY_IS_STRING
) {
338 zend_hash_get_current_key(Z_ARRVAL_P(zoption
), &header_key
, NULL
, 0);
339 zend_hash_get_current_data(Z_ARRVAL_P(zoption
), (void **) &header_val
);
340 snprintf(header
, 1023, "%s: %s", header_key
, Z_STRVAL_PP(header_val
));
341 headers
= curl_slist_append(headers
, http_curl_copystr(header
));
342 zend_hash_move_forward(Z_ARRVAL_P(zoption
));
346 curl_easy_setopt(ch
, CURLOPT_HTTPHEADER
, headers
);
352 /* {{{ static inline char *http_curl_getinfoname(CURLINFO) */
353 static inline char *_http_curl_getinfoname(CURLINFO i TSRMLS_DC
)
355 #define CASE(I) case CURLINFO_ ##I : { static char I[] = #I; return pretty_key(I, sizeof(#I)-1, 0, 0); }
358 /* CURLINFO_EFFECTIVE_URL = CURLINFO_STRING +1, */
360 /* CURLINFO_RESPONSE_CODE = CURLINFO_LONG +2, */
361 #if LIBCURL_VERSION_NUM > 0x070a06
366 /* CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE +3, */
368 /* CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE +4, */
369 CASE(NAMELOOKUP_TIME
);
370 /* CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE +5, */
372 /* CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE +6, */
373 CASE(PRETRANSFER_TIME
);
374 /* CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE +7, */
376 /* CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE +8, */
378 /* CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE +9, */
379 CASE(SPEED_DOWNLOAD
);
380 /* CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE +10, */
382 /* CURLINFO_HEADER_SIZE = CURLINFO_LONG +11, */
384 /* CURLINFO_REQUEST_SIZE = CURLINFO_LONG +12, */
386 /* CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG +13, */
387 CASE(SSL_VERIFYRESULT
);
388 /* CURLINFO_FILETIME = CURLINFO_LONG +14, */
390 /* CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE +15, */
391 CASE(CONTENT_LENGTH_DOWNLOAD
);
392 /* CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE +16, */
393 CASE(CONTENT_LENGTH_UPLOAD
);
394 /* CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE +17, */
395 CASE(STARTTRANSFER_TIME
);
396 /* CURLINFO_CONTENT_TYPE = CURLINFO_STRING +18, */
398 /* CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE +19, */
400 /* CURLINFO_REDIRECT_COUNT = CURLINFO_LONG +20, */
401 CASE(REDIRECT_COUNT
);
402 /* CURLINFO_PRIVATE = CURLINFO_STRING +21, * (mike) /
404 /* CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG +22, */
405 CASE(HTTP_CONNECTCODE
);
406 #if LIBCURL_VERSION_NUM > 0x070a07
407 /* CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG +23, */
408 CASE(HTTPAUTH_AVAIL
);
409 /* CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG +24, */
410 CASE(PROXYAUTH_AVAIL
);
418 /* {{{ static inline void http_curl_getinfo_ex(CURL, CURLINFO, zval *) */
419 static inline void _http_curl_getinfo_ex(CURL
*ch
, CURLINFO i
, zval
*array TSRMLS_DC
)
422 if (key
= http_curl_getinfoname(i
)) {
423 switch (i
& ~CURLINFO_MASK
)
425 case CURLINFO_STRING
:
428 if (CURLE_OK
== curl_easy_getinfo(ch
, i
, &c
)) {
429 add_assoc_string(array
, key
, c
? c
: "", 1);
434 case CURLINFO_DOUBLE
:
437 if (CURLE_OK
== curl_easy_getinfo(ch
, i
, &d
)) {
438 add_assoc_double(array
, key
, d
);
446 if (CURLE_OK
== curl_easy_getinfo(ch
, i
, &l
)) {
447 add_assoc_long(array
, key
, l
);
456 /* {{{ static inline http_curl_getinfo(CURL, HashTable *) */
457 static inline void _http_curl_getinfo(CURL
*ch
, HashTable
*info TSRMLS_DC
)
460 Z_ARRVAL(array
) = info
;
462 #define INFO(I) http_curl_getinfo_ex(ch, CURLINFO_ ##I , &array)
463 /* CURLINFO_EFFECTIVE_URL = CURLINFO_STRING +1, */
465 #if LIBCURL_VERSION_NUM > 0x070a06
466 /* CURLINFO_RESPONSE_CODE = CURLINFO_LONG +2, */
471 /* CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE +3, */
473 /* CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE +4, */
474 INFO(NAMELOOKUP_TIME
);
475 /* CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE +5, */
477 /* CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE +6, */
478 INFO(PRETRANSFER_TIME
);
479 /* CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE +7, */
481 /* CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE +8, */
483 /* CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE +9, */
484 INFO(SPEED_DOWNLOAD
);
485 /* CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE +10, */
487 /* CURLINFO_HEADER_SIZE = CURLINFO_LONG +11, */
489 /* CURLINFO_REQUEST_SIZE = CURLINFO_LONG +12, */
491 /* CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG +13, */
492 INFO(SSL_VERIFYRESULT
);
493 /* CURLINFO_FILETIME = CURLINFO_LONG +14, */
495 /* CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE +15, */
496 INFO(CONTENT_LENGTH_DOWNLOAD
);
497 /* CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE +16, */
498 INFO(CONTENT_LENGTH_UPLOAD
);
499 /* CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE +17, */
500 INFO(STARTTRANSFER_TIME
);
501 /* CURLINFO_CONTENT_TYPE = CURLINFO_STRING +18, */
503 /* CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE +19, */
505 /* CURLINFO_REDIRECT_COUNT = CURLINFO_LONG +20, */
506 INFO(REDIRECT_COUNT
);
507 /* CURLINFO_PRIVATE = CURLINFO_STRING +21, */
509 /* CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG +22, */
510 INFO(HTTP_CONNECTCODE
);
511 #if LIBCURL_VERSION_NUM > 0x070a07
512 /* CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG +23, */
513 INFO(HTTPAUTH_AVAIL
);
514 /* CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG +24, */
515 INFO(PROXYAUTH_AVAIL
);
523 /* {{{ STATUS http_get(char *, HashTable *, HashTable *, char **, size_t *) */
524 PHP_HTTP_API STATUS
_http_get(const char *URL
, HashTable
*options
,
525 HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
528 CURL
*ch
= curl_easy_init();
531 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not initialize curl");
535 rs
= http_get_ex(ch
, URL
, options
, info
, data
, data_len
);
536 curl_easy_cleanup(ch
);
541 /* {{{ STATUS http_get_ex(CURL *, char *, HashTable *, HashTable *, char **, size_t *) */
542 PHP_HTTP_API STATUS
_http_get_ex(CURL
*ch
, const char *URL
, HashTable
*options
,
543 HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
546 http_curl_setopts(ch
, URL
, options
);
547 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 0);
548 curl_easy_setopt(ch
, CURLOPT_POST
, 0);
550 if (CURLE_OK
!= curl_easy_perform(ch
)) {
553 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
557 http_curl_getinfo(ch
, info
);
559 http_curl_movebuf(data
, data_len
);
564 /* {{{ STATUS http_head(char *, HashTable *, HashTable *, char **data, size_t *) */
565 PHP_HTTP_API STATUS
_http_head(const char *URL
, HashTable
*options
,
566 HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
569 CURL
*ch
= curl_easy_init();
572 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not initialize curl");
576 rs
= http_head_ex(ch
, URL
, options
, info
, data
, data_len
);
577 curl_easy_cleanup(ch
);
582 /* {{{ STATUS http_head_ex(CURL *, char *, HashTable *, HashTable *, char **data, size_t *) */
583 PHP_HTTP_API STATUS
_http_head_ex(CURL
*ch
, const char *URL
, HashTable
*options
,
584 HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
587 http_curl_setopts(ch
, URL
, options
);
588 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 1);
589 curl_easy_setopt(ch
, CURLOPT_POST
, 0);
591 if (CURLE_OK
!= curl_easy_perform(ch
)) {
594 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
598 http_curl_getinfo(ch
, info
);
600 http_curl_movebuf(data
, data_len
);
605 /* {{{ STATUS http_post_data(char *, char *, size_t, HashTable *, HashTable *, char **, size_t *) */
606 PHP_HTTP_API STATUS
_http_post_data(const char *URL
, char *postdata
,
607 size_t postdata_len
, HashTable
*options
, HashTable
*info
, char **data
,
608 size_t *data_len TSRMLS_DC
)
611 CURL
*ch
= curl_easy_init();
614 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not initialize curl");
617 rs
= http_post_data_ex(ch
, URL
, postdata
, postdata_len
, options
, info
, data
, data_len
);
618 curl_easy_cleanup(ch
);
623 /* {{{ STATUS http_post_data_ex(CURL *, char *, char *, size_t, HashTable *, HashTable *, char **, size_t *) */
624 PHP_HTTP_API STATUS
_http_post_data_ex(CURL
*ch
, const char *URL
, char *postdata
,
625 size_t postdata_len
, HashTable
*options
, HashTable
*info
, char **data
,
626 size_t *data_len TSRMLS_DC
)
629 http_curl_setopts(ch
, URL
, options
);
630 curl_easy_setopt(ch
, CURLOPT_POST
, 1);
631 curl_easy_setopt(ch
, CURLOPT_POSTFIELDS
, postdata
);
632 curl_easy_setopt(ch
, CURLOPT_POSTFIELDSIZE
, postdata_len
);
634 if (CURLE_OK
!= curl_easy_perform(ch
)) {
637 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
641 http_curl_getinfo(ch
, info
);
643 http_curl_movebuf(data
, data_len
);
649 /* {{{ STATUS http_post_array_ex(CURL *, char *, HashTable *, HashTable *, HashTable *, char **, size_t *) */
650 PHP_HTTP_API STATUS
_http_post_array_ex(CURL
*ch
, const char *URL
, HashTable
*postarray
,
651 HashTable
*options
, HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
653 smart_str qstr
= {0};
656 HTTP_URL_ARGSEP_OVERRIDE
;
657 if (php_url_encode_hash_ex(postarray
, &qstr
, NULL
,0,NULL
,0,NULL
,0,NULL TSRMLS_CC
) != SUCCESS
) {
661 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not encode post data");
662 HTTP_URL_ARGSEP_RESTORE
;
666 HTTP_URL_ARGSEP_RESTORE
;
669 status
= http_post_data_ex(ch
, URL
, qstr
.c
, qstr
.len
, options
, info
, data
, data_len
);
671 status
= http_post_data(URL
, qstr
.c
, qstr
.len
, options
, info
, data
, data_len
);
681 /* {{{ STATUS http_post_curldata_ex(CURL *, char *, curl_httppost *, HashTable *, HashTable *, char **, size_t *) */
682 PHP_HTTP_API STATUS
_http_post_curldata_ex(CURL
*ch
, const char *URL
,
683 struct curl_httppost
*curldata
, HashTable
*options
, HashTable
*info
,
684 char **data
, size_t *data_len TSRMLS_DC
)
687 http_curl_setopts(ch
, URL
, options
);
688 curl_easy_setopt(ch
, CURLOPT_POST
, 1);
689 curl_easy_setopt(ch
, CURLOPT_HTTPPOST
, curldata
);
691 if (CURLE_OK
!= curl_easy_perform(ch
)) {
694 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
698 http_curl_getinfo(ch
, info
);
700 http_curl_movebuf(data
, data_len
);
711 * vim600: noet sw=4 ts=4 fdm=marker
712 * vim<600: noet sw=4 ts=4