2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
14 #include "php_http_client.h"
16 #if PHP_HTTP_HAVE_CURL
18 #if PHP_HTTP_HAVE_EVENT
19 # if !PHP_HTTP_HAVE_EVENT2 && /* just be really sure */ !(LIBEVENT_VERSION_NUMBER >= 0x02000000)
21 # define event_base_new event_init
22 # define event_assign(e, b, s, a, cb, d) do {\
23 event_set(e, s, a, cb, d); \
24 event_base_set(b, e); \
27 # if PHP_HTTP_HAVE_EVENT2
28 # include <event2/event.h>
29 # include <event2/event_struct.h>
31 # error "libevent presence is unknown"
39 #ifdef PHP_HTTP_HAVE_OPENSSL
40 # include <openssl/ssl.h>
42 #ifdef PHP_HTTP_HAVE_GNUTLS
46 typedef struct php_http_client_curl_handle
{
49 } php_http_client_curl_handle_t
;
51 typedef struct php_http_client_curl
{
52 php_http_client_curl_handle_t
*handle
;
54 int unfinished
; /* int because of curl_multi_perform() */
56 #if PHP_HTTP_HAVE_EVENT
57 struct event_base
*evbase
;
58 struct event
*timeout
;
61 } php_http_client_curl_t
;
63 typedef struct php_http_client_curl_handler
{
65 php_resource_factory_t
*rf
;
66 php_http_client_t
*client
;
67 php_http_client_progress_state_t progress
;
68 php_http_client_enqueue_t queue
;
71 php_http_buffer_t headers
;
72 php_http_message_body_t
*body
;
78 struct curl_slist
*proxyheaders
;
79 struct curl_slist
*headers
;
80 struct curl_slist
*resolve
;
81 php_http_buffer_t cookies
;
82 php_http_buffer_t ranges
;
85 unsigned range_request
:1;
86 unsigned encode_cookies
:1;
95 } php_http_client_curl_handler_t
;
97 typedef struct php_http_curle_storage
{
101 char errorbuffer
[0x100];
102 } php_http_curle_storage_t
;
104 static inline php_http_curle_storage_t
*php_http_curle_get_storage(CURL
*ch
) {
105 php_http_curle_storage_t
*st
= NULL
;
107 curl_easy_getinfo(ch
, CURLINFO_PRIVATE
, &st
);
110 st
= pecalloc(1, sizeof(*st
), 1);
111 curl_easy_setopt(ch
, CURLOPT_PRIVATE
, st
);
112 curl_easy_setopt(ch
, CURLOPT_ERRORBUFFER
, st
->errorbuffer
);
118 static void *php_http_curle_ctor(void *opaque
, void *init_arg TSRMLS_DC
)
122 if ((ch
= curl_easy_init())) {
123 php_http_curle_get_storage(ch
);
129 static void *php_http_curle_copy(void *opaque
, void *handle TSRMLS_DC
)
133 if ((ch
= curl_easy_duphandle(handle
))) {
135 php_http_curle_get_storage(ch
);
141 static void php_http_curle_dtor(void *opaque
, void *handle TSRMLS_DC
)
143 php_http_curle_storage_t
*st
= php_http_curle_get_storage(handle
);
145 curl_easy_cleanup(handle
);
151 if (st
->cookiestore
) {
152 pefree(st
->cookiestore
, 1);
158 static php_resource_factory_ops_t php_http_curle_resource_factory_ops
= {
164 static void *php_http_curlm_ctor(void *opaque
, void *init_arg TSRMLS_DC
)
166 php_http_client_curl_handle_t
*curl
= calloc(1, sizeof(*curl
));
168 if (!(curl
->multi
= curl_multi_init())) {
172 if (!(curl
->share
= curl_share_init())) {
173 curl_multi_cleanup(curl
->multi
);
177 curl_share_setopt(curl
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_COOKIE
);
178 curl_share_setopt(curl
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_SSL_SESSION
);
182 static void php_http_curlm_dtor(void *opaque
, void *handle TSRMLS_DC
)
184 php_http_client_curl_handle_t
*curl
= handle
;
186 curl_share_cleanup(curl
->share
);
187 curl_multi_cleanup(curl
->multi
);
191 static php_resource_factory_ops_t php_http_curlm_resource_factory_ops
= {
199 static size_t php_http_curle_read_callback(void *data
, size_t len
, size_t n
, void *ctx
)
201 php_http_message_body_t
*body
= ctx
;
203 if (body
&& body
->stream_id
) {
204 php_stream
*s
= php_http_message_body_stream(body
);
207 TSRMLS_FETCH_FROM_CTX(body
->ts
);
208 return php_stream_read(s
, data
, len
* n
);
214 #if PHP_HTTP_CURL_VERSION(7,32,0)
215 static int php_http_curle_xferinfo_callback(void *ctx
, curl_off_t dltotal
, curl_off_t dlnow
, curl_off_t ultotal
, curl_off_t ulnow
)
217 static int php_http_curle_progress_callback(void *ctx
, double dltotal
, double dlnow
, double ultotal
, double ulnow
)
220 php_http_client_curl_handler_t
*h
= ctx
;
221 zend_bool update
= 0;
223 if (h
->progress
.dl
.total
!= dltotal
224 || h
->progress
.dl
.now
!= dlnow
225 || h
->progress
.ul
.total
!= ultotal
226 || h
->progress
.ul
.now
!= ulnow
230 h
->progress
.dl
.total
= dltotal
;
231 h
->progress
.dl
.now
= dlnow
;
232 h
->progress
.ul
.total
= ultotal
;
233 h
->progress
.ul
.now
= ulnow
;
236 if (update
&& h
->client
->callback
.progress
.func
) {
237 h
->client
->callback
.progress
.func(h
->client
->callback
.progress
.arg
, h
->client
, &h
->queue
, &h
->progress
);
243 static int php_http_curle_seek_callback(void *userdata
, curl_off_t offset
, int origin
)
245 php_http_message_body_t
*body
= userdata
;
246 TSRMLS_FETCH_FROM_CTX(body
->ts
);
251 if (0 == php_stream_seek(php_http_message_body_stream(body
), offset
, origin
)) {
257 static int php_http_curle_raw_callback(CURL
*ch
, curl_infotype type
, char *data
, size_t length
, void *ctx
)
259 php_http_client_curl_handler_t
*h
= ctx
;
264 if (data
[0] == '-') {
265 } else if (php_memnstr(data
, ZEND_STRL("Adding handle:"), data
+ length
)) {
266 h
->progress
.info
= "setup";
267 } else if (php_memnstr(data
, ZEND_STRL("addHandle"), data
+ length
)) {
268 h
->progress
.info
= "setup";
269 } else if (php_memnstr(data
, ZEND_STRL("About to connect"), data
+ length
)) {
270 h
->progress
.info
= "resolve";
271 } else if (php_memnstr(data
, ZEND_STRL("Trying"), data
+ length
)) {
272 h
->progress
.info
= "connect";
273 } else if (php_memnstr(data
, ZEND_STRL("Found bundle for host"), data
+ length
)) {
274 h
->progress
.info
= "connect";
275 } else if (php_memnstr(data
, ZEND_STRL("Connected"), data
+ length
)) {
276 h
->progress
.info
= "connected";
277 } else if (php_memnstr(data
, ZEND_STRL("Re-using existing connection!"), data
+ length
)) {
278 h
->progress
.info
= "connected";
279 } else if (php_memnstr(data
, ZEND_STRL("blacklisted"), data
+ length
)) {
280 h
->progress
.info
= "blacklist check";
281 } else if (php_memnstr(data
, ZEND_STRL("SSL"), data
+ length
)) {
282 h
->progress
.info
= "ssl negotiation";
283 } else if (php_memnstr(data
, ZEND_STRL("upload"), data
+ length
)) {
284 h
->progress
.info
= "uploaded";
285 } else if (php_memnstr(data
, ZEND_STRL("left intact"), data
+ length
)) {
286 h
->progress
.info
= "not disconnected";
287 } else if (php_memnstr(data
, ZEND_STRL("closed"), data
+ length
)) {
288 h
->progress
.info
= "disconnected";
289 } else if (php_memnstr(data
, ZEND_STRL("Issue another request"), data
+ length
)) {
290 h
->progress
.info
= "redirect";
291 } else if (php_memnstr(data
, ZEND_STRL("Operation timed out"), data
+ length
)) {
292 h
->progress
.info
= "timeout";
295 h
->progress
.info
= data
;
296 data
[length
- 1] = '\0';
299 if (h
->client
->callback
.progress
.func
) {
300 h
->client
->callback
.progress
.func(h
->client
->callback
.progress
.arg
, h
->client
, &h
->queue
, &h
->progress
);
303 case CURLINFO_HEADER_OUT
:
304 case CURLINFO_DATA_OUT
:
305 case CURLINFO_SSL_DATA_OUT
:
306 h
->progress
.info
= "send";
308 case CURLINFO_HEADER_IN
:
309 case CURLINFO_DATA_IN
:
310 case CURLINFO_SSL_DATA_IN
:
311 h
->progress
.info
= "receive";
319 _dpf(type
, data
, length
);
325 static int php_http_curle_header_callback(char *data
, size_t n
, size_t l
, void *arg
)
327 php_http_client_curl_handler_t
*h
= arg
;
329 return php_http_buffer_append(&h
->response
.headers
, data
, n
* l
);
332 static int php_http_curle_body_callback(char *data
, size_t n
, size_t l
, void *arg
)
334 php_http_client_curl_handler_t
*h
= arg
;
336 return php_http_message_body_append(h
->response
.body
, data
, n
*l
);
339 static ZEND_RESULT_CODE
php_http_curle_get_info(CURL
*ch
, HashTable
*info
)
344 struct curl_slist
*s
, *p
;
345 zval
*subarray
, array
;
346 INIT_PZVAL_ARRAY(&array
, info
);
348 /* BEGIN::CURLINFO */
349 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_EFFECTIVE_URL
, &c
)) {
350 add_assoc_string_ex(&array
, "effective_url", sizeof("effective_url"), c
? c
: "", 1);
352 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_RESPONSE_CODE
, &l
)) {
353 add_assoc_long_ex(&array
, "response_code", sizeof("response_code"), l
);
355 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TOTAL_TIME
, &d
)) {
356 add_assoc_double_ex(&array
, "total_time", sizeof("total_time"), d
);
358 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_NAMELOOKUP_TIME
, &d
)) {
359 add_assoc_double_ex(&array
, "namelookup_time", sizeof("namelookup_time"), d
);
361 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONNECT_TIME
, &d
)) {
362 add_assoc_double_ex(&array
, "connect_time", sizeof("connect_time"), d
);
364 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRETRANSFER_TIME
, &d
)) {
365 add_assoc_double_ex(&array
, "pretransfer_time", sizeof("pretransfer_time"), d
);
367 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SIZE_UPLOAD
, &d
)) {
368 add_assoc_double_ex(&array
, "size_upload", sizeof("size_upload"), d
);
370 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SIZE_DOWNLOAD
, &d
)) {
371 add_assoc_double_ex(&array
, "size_download", sizeof("size_download"), d
);
373 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_DOWNLOAD
, &d
)) {
374 add_assoc_double_ex(&array
, "speed_download", sizeof("speed_download"), d
);
376 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_UPLOAD
, &d
)) {
377 add_assoc_double_ex(&array
, "speed_upload", sizeof("speed_upload"), d
);
379 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HEADER_SIZE
, &l
)) {
380 add_assoc_long_ex(&array
, "header_size", sizeof("header_size"), l
);
382 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REQUEST_SIZE
, &l
)) {
383 add_assoc_long_ex(&array
, "request_size", sizeof("request_size"), l
);
385 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SSL_VERIFYRESULT
, &l
)) {
386 add_assoc_long_ex(&array
, "ssl_verifyresult", sizeof("ssl_verifyresult"), l
);
388 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_FILETIME
, &l
)) {
389 add_assoc_long_ex(&array
, "filetime", sizeof("filetime"), l
);
391 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_DOWNLOAD
, &d
)) {
392 add_assoc_double_ex(&array
, "content_length_download", sizeof("content_length_download"), d
);
394 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_UPLOAD
, &d
)) {
395 add_assoc_double_ex(&array
, "content_length_upload", sizeof("content_length_upload"), d
);
397 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_STARTTRANSFER_TIME
, &d
)) {
398 add_assoc_double_ex(&array
, "starttransfer_time", sizeof("starttransfer_time"), d
);
400 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_TYPE
, &c
)) {
401 add_assoc_string_ex(&array
, "content_type", sizeof("content_type"), c
? c
: "", 1);
403 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_TIME
, &d
)) {
404 add_assoc_double_ex(&array
, "redirect_time", sizeof("redirect_time"), d
);
406 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_COUNT
, &l
)) {
407 add_assoc_long_ex(&array
, "redirect_count", sizeof("redirect_count"), l
);
409 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTP_CONNECTCODE
, &l
)) {
410 add_assoc_long_ex(&array
, "connect_code", sizeof("connect_code"), l
);
412 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTPAUTH_AVAIL
, &l
)) {
413 add_assoc_long_ex(&array
, "httpauth_avail", sizeof("httpauth_avail"), l
);
415 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXYAUTH_AVAIL
, &l
)) {
416 add_assoc_long_ex(&array
, "proxyauth_avail", sizeof("proxyauth_avail"), l
);
418 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_OS_ERRNO
, &l
)) {
419 add_assoc_long_ex(&array
, "os_errno", sizeof("os_errno"), l
);
421 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_NUM_CONNECTS
, &l
)) {
422 add_assoc_long_ex(&array
, "num_connects", sizeof("num_connects"), l
);
424 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SSL_ENGINES
, &s
)) {
425 MAKE_STD_ZVAL(subarray
);
426 array_init(subarray
);
427 for (p
= s
; p
; p
= p
->next
) {
429 add_next_index_string(subarray
, p
->data
, 1);
432 add_assoc_zval_ex(&array
, "ssl_engines", sizeof("ssl_engines"), subarray
);
433 curl_slist_free_all(s
);
435 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_URL
, &c
)) {
436 add_assoc_string_ex(&array
, "redirect_url", sizeof("redirect_url"), c
? c
: "", 1);
438 #if PHP_HTTP_CURL_VERSION(7,19,0)
439 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRIMARY_IP
, &c
)) {
440 add_assoc_string_ex(&array
, "primary_ip", sizeof("primary_ip"), c
? c
: "", 1);
443 #if PHP_HTTP_CURL_VERSION(7,19,0)
444 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_APPCONNECT_TIME
, &d
)) {
445 add_assoc_double_ex(&array
, "appconnect_time", sizeof("appconnect_time"), d
);
448 #if PHP_HTTP_CURL_VERSION(7,19,4)
449 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONDITION_UNMET
, &l
)) {
450 add_assoc_long_ex(&array
, "condition_unmet", sizeof("condition_unmet"), l
);
453 #if PHP_HTTP_CURL_VERSION(7,21,0)
454 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRIMARY_PORT
, &l
)) {
455 add_assoc_long_ex(&array
, "primary_port", sizeof("primary_port"), l
);
458 #if PHP_HTTP_CURL_VERSION(7,21,0)
459 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_LOCAL_IP
, &c
)) {
460 add_assoc_string_ex(&array
, "local_ip", sizeof("local_ip"), c
? c
: "", 1);
463 #if PHP_HTTP_CURL_VERSION(7,21,0)
464 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_LOCAL_PORT
, &l
)) {
465 add_assoc_long_ex(&array
, "local_port", sizeof("local_port"), l
);
471 #if PHP_HTTP_CURL_VERSION(7,34,0)
474 struct curl_tlssessioninfo
*ti
;
476 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TLS_SESSION
, &ti
)) {
479 MAKE_STD_ZVAL(subarray
);
481 MAKE_STD_ZVAL(ti_array
);
482 array_init(ti_array
);
484 switch (ti
->backend
) {
485 case CURLSSLBACKEND_NONE
:
488 case CURLSSLBACKEND_OPENSSL
:
490 #ifdef PHP_HTTP_HAVE_OPENSSL
492 SSL_CTX
*ctx
= ti
->internals
;
494 array_init(subarray
);
495 add_assoc_long_ex(subarray
, ZEND_STRS("number"), SSL_CTX_sess_number(ctx
));
496 add_assoc_long_ex(subarray
, ZEND_STRS("connect"), SSL_CTX_sess_connect(ctx
));
497 add_assoc_long_ex(subarray
, ZEND_STRS("connect_good"), SSL_CTX_sess_connect_good(ctx
));
498 add_assoc_long_ex(subarray
, ZEND_STRS("connect_renegotiate"), SSL_CTX_sess_connect_renegotiate(ctx
));
499 add_assoc_long_ex(subarray
, ZEND_STRS("hits"), SSL_CTX_sess_hits(ctx
));
500 add_assoc_long_ex(subarray
, ZEND_STRS("cache_full"), SSL_CTX_sess_cache_full(ctx
));
504 case CURLSSLBACKEND_GNUTLS
:
506 #ifdef PHP_HTTP_HAVE_GNUTLS
508 gnutls_session_t sess
= ti
->internals
;
511 array_init(subarray
);
512 if ((desc
= gnutls_session_get_desc(sess
))) {
513 add_assoc_string_ex(subarray
, ZEND_STRS("desc"), desc
, 1);
516 add_assoc_bool_ex(subarray
, ZEND_STRS("resumed"), gnutls_session_is_resumed(sess
));
520 case CURLSSLBACKEND_NSS
:
523 #if !PHP_HTTP_CURL_VERSION(7,39,0)
524 case CURLSSLBACKEND_QSOSSL
:
528 case CURLSSLBACKEND_GSKIT
:
532 case CURLSSLBACKEND_POLARSSL
:
533 backend
= "polarssl";
535 case CURLSSLBACKEND_CYASSL
:
538 case CURLSSLBACKEND_SCHANNEL
:
539 backend
= "schannel";
541 case CURLSSLBACKEND_DARWINSSL
:
542 backend
= "darwinssl";
547 add_assoc_string_ex(ti_array
, ZEND_STRS("backend"), estrdup(backend
), 0);
548 add_assoc_zval_ex(ti_array
, ZEND_STRS("internals"), subarray
);
549 add_assoc_zval_ex(&array
, "tls_session", sizeof("tls_session"), ti_array
);
554 #if (PHP_HTTP_CURL_VERSION(7,19,1) && defined(PHP_HTTP_HAVE_OPENSSL)) || (PHP_HTTP_CURL_VERSION(7,34,0) && defined(PHP_HTTP_HAVE_NSS)) || (PHP_HTTP_CURL_VERSION(7,42,0) && defined(PHP_HTTP_HAVE_GNUTLS)) || (PHP_HTTP_CURL_VERSION(7,39,0) && defined(PHP_HTTP_HAVE_GSKIT))
558 struct curl_certinfo
*ci
;
559 char *colon
, *keyname
;
561 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CERTINFO
, &ci
)) {
562 MAKE_STD_ZVAL(ci_array
);
563 array_init(ci_array
);
565 for (i
= 0; i
< ci
->num_of_certs
; ++i
) {
568 MAKE_STD_ZVAL(subarray
);
569 array_init(subarray
);
570 for (p
= s
; p
; p
= p
->next
) {
572 if ((colon
= strchr(p
->data
, ':'))) {
573 keyname
= estrndup(p
->data
, colon
- p
->data
);
574 add_assoc_string_ex(subarray
, keyname
, colon
- p
->data
+ 1, colon
+ 1, 1);
577 add_next_index_string(subarray
, p
->data
, 1);
581 add_next_index_zval(ci_array
, subarray
);
583 add_assoc_zval_ex(&array
, "certinfo", sizeof("certinfo"), ci_array
);
588 php_http_curle_storage_t
*st
= php_http_curle_get_storage(ch
);
590 add_assoc_long_ex(&array
, "curlcode", sizeof("curlcode"), st
->errorcode
);
591 add_assoc_string_ex(&array
, "error", sizeof("error"), st
->errorbuffer
, 1);
597 static int compare_queue(php_http_client_enqueue_t
*e
, void *handle
)
599 return handle
== ((php_http_client_curl_handler_t
*) e
->opaque
)->handle
;
602 static php_http_message_t
*php_http_curlm_responseparser(php_http_client_curl_handler_t
*h TSRMLS_DC
)
604 php_http_message_t
*response
;
605 php_http_header_parser_t parser
;
608 response
= php_http_message_init(NULL
, 0, h
->response
.body TSRMLS_CC
);
609 php_http_header_parser_init(&parser TSRMLS_CC
);
610 while (h
->response
.headers
.used
) {
611 php_http_header_parser_state_t st
= php_http_header_parser_parse(&parser
,
612 &h
->response
.headers
, PHP_HTTP_HEADER_PARSER_CLEANUP
, &response
->hdrs
,
613 (php_http_info_callback_t
) php_http_message_info_callback
, (void *) &response
);
614 if (PHP_HTTP_HEADER_PARSER_STATE_FAILURE
== st
) {
618 php_http_header_parser_dtor(&parser
);
620 /* move body to right message */
621 if (response
->body
!= h
->response
.body
) {
622 php_http_message_t
*ptr
= response
;
624 while (ptr
->parent
) {
627 php_http_message_body_free(&response
->body
);
628 response
->body
= ptr
->body
;
631 php_http_message_body_addref(h
->response
.body
);
633 /* let's update the response headers */
634 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Length"), 1))) {
635 zend_hash_update(&response
->hdrs
, "X-Original-Content-Length", sizeof("X-Original-Content-Length"), &zh
, sizeof(zval
*), NULL
);
637 if ((zh
= php_http_message_header(response
, ZEND_STRL("Transfer-Encoding"), 0))) {
638 zend_hash_update(&response
->hdrs
, "X-Original-Transfer-Encoding", sizeof("X-Original-Transfer-Encoding"), (void *) &zh
, sizeof(zval
*), NULL
);
639 zend_hash_del(&response
->hdrs
, "Transfer-Encoding", sizeof("Transfer-Encoding"));
641 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Range"), 0))) {
642 zend_hash_update(&response
->hdrs
, "X-Original-Content-Range", sizeof("X-Original-Content-Range"), &zh
, sizeof(zval
*), NULL
);
643 zend_hash_del(&response
->hdrs
, "Content-Range", sizeof("Content-Range"));
645 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Encoding"), 0))) {
646 zend_hash_update(&response
->hdrs
, "X-Original-Content-Encoding", sizeof("X-Original-Content-Encoding"), &zh
, sizeof(zval
*), NULL
);
647 zend_hash_del(&response
->hdrs
, "Content-Encoding", sizeof("Content-Encoding"));
649 php_http_message_update_headers(response
);
654 static void php_http_curlm_responsehandler(php_http_client_t
*context
)
656 int err_count
= 0, remaining
= 0;
657 php_http_curle_storage_t
*st
, *err
= NULL
;
658 php_http_client_enqueue_t
*enqueue
;
659 php_http_client_curl_t
*curl
= context
->ctx
;
660 TSRMLS_FETCH_FROM_CTX(context
->ts
);
663 CURLMsg
*msg
= curl_multi_info_read(curl
->handle
->multi
, &remaining
);
665 if (msg
&& CURLMSG_DONE
== msg
->msg
) {
666 if (CURLE_OK
!= msg
->data
.result
) {
667 st
= php_http_curle_get_storage(msg
->easy_handle
);
668 st
->errorcode
= msg
->data
.result
;
670 /* defer the warnings/exceptions, so the callback is still called for this request */
672 err
= ecalloc(remaining
+ 1, sizeof(*err
));
674 memcpy(&err
[err_count
], st
, sizeof(*st
));
676 err
[err_count
].url
= estrdup(st
->url
);
681 if ((enqueue
= php_http_client_enqueued(context
, msg
->easy_handle
, compare_queue
))) {
682 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
683 php_http_message_t
*response
= php_http_curlm_responseparser(handler TSRMLS_CC
);
686 context
->callback
.response
.func(context
->callback
.response
.arg
, context
, &handler
->queue
, &response
);
687 php_http_message_free(&response
);
697 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "%s; %s (%s)", curl_easy_strerror(err
[i
].errorcode
), err
[i
].errorbuffer
, STR_PTR(err
[i
].url
));
701 } while (++i
< err_count
);
707 #if PHP_HTTP_HAVE_EVENT
709 typedef struct php_http_curlm_event
{
711 php_http_client_t
*context
;
712 } php_http_curlm_event_t
;
714 static inline int etoca(short action
) {
715 switch (action
& (EV_READ
|EV_WRITE
)) {
717 return CURL_CSELECT_IN
;
720 return CURL_CSELECT_OUT
;
722 case EV_READ
|EV_WRITE
:
723 return CURL_CSELECT_IN
|CURL_CSELECT_OUT
;
730 static void php_http_curlm_timeout_callback(int socket
, short action
, void *event_data
)
732 php_http_client_t
*context
= event_data
;
733 php_http_client_curl_t
*curl
= context
->ctx
;
736 fprintf(stderr
, "T");
738 if (curl
->useevents
) {
740 TSRMLS_FETCH_FROM_CTX(context
->ts
);
742 /* ignore and use -1,0 on timeout */
746 while (CURLM_CALL_MULTI_PERFORM
== (rc
= curl_multi_socket_action(curl
->handle
->multi
, CURL_SOCKET_TIMEOUT
, 0, &curl
->unfinished
)));
748 if (CURLM_OK
!= rc
) {
749 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "%s", curl_multi_strerror(rc
));
752 php_http_curlm_responsehandler(context
);
756 static void php_http_curlm_event_callback(int socket
, short action
, void *event_data
)
758 php_http_client_t
*context
= event_data
;
759 php_http_client_curl_t
*curl
= context
->ctx
;
762 fprintf(stderr
, "E");
764 if (curl
->useevents
) {
765 CURLMcode rc
= CURLM_OK
;
766 TSRMLS_FETCH_FROM_CTX(context
->ts
);
768 while (CURLM_CALL_MULTI_PERFORM
== (rc
= curl_multi_socket_action(curl
->handle
->multi
, socket
, etoca(action
), &curl
->unfinished
)));
770 if (CURLM_OK
!= rc
) {
771 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "%s", curl_multi_strerror(rc
));
774 php_http_curlm_responsehandler(context
);
776 /* remove timeout if there are no transfers left */
777 if (!curl
->unfinished
&& event_initialized(curl
->timeout
) && event_pending(curl
->timeout
, EV_TIMEOUT
, NULL
)) {
778 event_del(curl
->timeout
);
783 static int php_http_curlm_socket_callback(CURL
*easy
, curl_socket_t sock
, int action
, void *socket_data
, void *assign_data
)
785 php_http_client_t
*context
= socket_data
;
786 php_http_client_curl_t
*curl
= context
->ctx
;
789 fprintf(stderr
, "S");
791 if (curl
->useevents
) {
792 int events
= EV_PERSIST
;
793 php_http_curlm_event_t
*ev
= assign_data
;
794 TSRMLS_FETCH_FROM_CTX(context
->ts
);
797 ev
= ecalloc(1, sizeof(php_http_curlm_event_t
));
798 ev
->context
= context
;
799 curl_multi_assign(curl
->handle
->multi
, sock
, ev
);
801 event_del(&ev
->evnt
);
811 case CURL_POLL_INOUT
:
812 events
|= EV_READ
|EV_WRITE
;
815 case CURL_POLL_REMOVE
:
822 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Unknown socket action %d", action
);
826 event_assign(&ev
->evnt
, curl
->evbase
, sock
, events
, php_http_curlm_event_callback
, context
);
827 event_add(&ev
->evnt
, NULL
);
833 static void php_http_curlm_timer_callback(CURLM
*multi
, long timeout_ms
, void *timer_data
)
835 php_http_client_t
*context
= timer_data
;
836 php_http_client_curl_t
*curl
= context
->ctx
;
839 fprintf(stderr
, "\ntimer <- timeout_ms: %ld\n", timeout_ms
);
841 if (curl
->useevents
) {
843 if (timeout_ms
< 0) {
844 php_http_curlm_timeout_callback(CURL_SOCKET_TIMEOUT
, /*EV_READ|EV_WRITE*/0, context
);
845 } else if (timeout_ms
> 0 || !event_initialized(curl
->timeout
) || !event_pending(curl
->timeout
, EV_TIMEOUT
, NULL
)) {
846 struct timeval timeout
;
848 if (!event_initialized(curl
->timeout
)) {
849 event_assign(curl
->timeout
, curl
->evbase
, CURL_SOCKET_TIMEOUT
, 0, php_http_curlm_timeout_callback
, context
);
852 timeout
.tv_sec
= timeout_ms
/ 1000;
853 timeout
.tv_usec
= (timeout_ms
% 1000) * 1000;
855 event_add(curl
->timeout
, &timeout
);
860 #endif /* HAVE_EVENT */
864 static php_http_options_t php_http_curle_options
, php_http_curlm_options
;
866 #define PHP_HTTP_CURLE_OPTION_CHECK_STRLEN 0x0001
867 #define PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR 0x0002
868 #define PHP_HTTP_CURLE_OPTION_TRANSFORM_MS 0x0004
870 static ZEND_RESULT_CODE
php_http_curle_option_set_ssl_verifyhost(php_http_option_t
*opt
, zval
*val
, void *userdata
)
872 php_http_client_curl_handler_t
*curl
= userdata
;
873 CURL
*ch
= curl
->handle
;
875 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_SSL_VERIFYHOST
, Z_BVAL_P(val
) ? 2 : 0)) {
881 static ZEND_RESULT_CODE
php_http_curle_option_set_cookiestore(php_http_option_t
*opt
, zval
*val
, void *userdata
)
883 php_http_client_curl_handler_t
*curl
= userdata
;
884 CURL
*ch
= curl
->handle
;
885 php_http_curle_storage_t
*storage
= php_http_curle_get_storage(curl
->handle
);
887 if (storage
->cookiestore
) {
888 pefree(storage
->cookiestore
, 1);
890 if (val
&& Z_STRLEN_P(val
)) {
891 storage
->cookiestore
= pestrndup(Z_STRVAL_P(val
), Z_STRLEN_P(val
), 1);
893 storage
->cookiestore
= NULL
;
895 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIEFILE
, storage
->cookiestore
)
896 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIEJAR
, storage
->cookiestore
)
904 static ZEND_RESULT_CODE
php_http_curle_option_set_cookies(php_http_option_t
*opt
, zval
*val
, void *userdata
)
906 php_http_client_curl_handler_t
*curl
= userdata
;
907 CURL
*ch
= curl
->handle
;
908 TSRMLS_FETCH_FROM_CTX(curl
->client
->ts
);
910 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
911 if (curl
->options
.encode_cookies
) {
912 if (SUCCESS
== php_http_url_encode_hash_ex(HASH_OF(val
), &curl
->options
.cookies
, ZEND_STRL(";"), ZEND_STRL("="), NULL
, 0 TSRMLS_CC
)) {
913 php_http_buffer_fix(&curl
->options
.cookies
);
914 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, curl
->options
.cookies
.data
)) {
922 php_http_array_hashkey_t cookie_key
= php_http_array_hashkey_init(0);
925 FOREACH_KEYVAL(pos
, val
, cookie_key
, cookie_val
) {
926 zval
*zv
= php_http_ztyp(IS_STRING
, *cookie_val
);
928 php_http_array_hashkey_stringify(&cookie_key
);
929 php_http_buffer_appendf(&curl
->options
.cookies
, "%s=%s; ", cookie_key
.str
, Z_STRVAL_P(zv
));
930 php_http_array_hashkey_stringfree(&cookie_key
);
935 php_http_buffer_fix(&curl
->options
.cookies
);
936 if (curl
->options
.cookies
.used
) {
937 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, curl
->options
.cookies
.data
)) {
943 php_http_buffer_reset(&curl
->options
.cookies
);
944 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, NULL
)) {
951 static ZEND_RESULT_CODE
php_http_curle_option_set_encodecookies(php_http_option_t
*opt
, zval
*val
, void *userdata
)
953 php_http_client_curl_handler_t
*curl
= userdata
;
955 curl
->options
.encode_cookies
= Z_BVAL_P(val
);
959 static ZEND_RESULT_CODE
php_http_curle_option_set_lastmodified(php_http_option_t
*opt
, zval
*val
, void *userdata
)
961 php_http_client_curl_handler_t
*curl
= userdata
;
962 CURL
*ch
= curl
->handle
;
963 TSRMLS_FETCH_FROM_CTX(curl
->client
->ts
);
966 if (Z_LVAL_P(val
) > 0) {
967 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, Z_LVAL_P(val
))) {
971 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, (long) sapi_get_request_time(TSRMLS_C
) + Z_LVAL_P(val
))) {
975 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMECONDITION
, (long) (curl
->options
.range_request
? CURL_TIMECOND_IFUNMODSINCE
: CURL_TIMECOND_IFMODSINCE
))) {
979 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, 0)
980 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMECONDITION
, 0)
988 static ZEND_RESULT_CODE
php_http_curle_option_set_compress(php_http_option_t
*opt
, zval
*val
, void *userdata
)
990 php_http_client_curl_handler_t
*curl
= userdata
;
991 CURL
*ch
= curl
->handle
;
993 #if !PHP_HTTP_CURL_VERSION(7,21,6)
994 # define CURLOPT_ACCEPT_ENCODING CURLOPT_ENCODING
996 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_ACCEPT_ENCODING
, Z_BVAL_P(val
) ? "" : NULL
)) {
1002 static ZEND_RESULT_CODE
php_http_curle_option_set_etag(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1004 php_http_client_curl_handler_t
*curl
= userdata
;
1005 php_http_buffer_t header
;
1007 if (Z_STRLEN_P(val
)) {
1008 zend_bool is_quoted
= !((Z_STRVAL_P(val
)[0] != '"') || (Z_STRVAL_P(val
)[Z_STRLEN_P(val
)-1] != '"'));
1009 php_http_buffer_init(&header
);
1010 php_http_buffer_appendf(&header
, is_quoted
?"%s: %s":"%s: \"%s\"", curl
->options
.range_request
?"If-Match":"If-None-Match", Z_STRVAL_P(val
));
1011 php_http_buffer_fix(&header
);
1012 curl
->options
.headers
= curl_slist_append(curl
->options
.headers
, header
.data
);
1013 php_http_buffer_dtor(&header
);
1018 static ZEND_RESULT_CODE
php_http_curle_option_set_range(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1020 php_http_client_curl_handler_t
*curl
= userdata
;
1021 CURL
*ch
= curl
->handle
;
1022 TSRMLS_FETCH_FROM_CTX(curl
->client
->ts
);
1024 php_http_buffer_reset(&curl
->options
.ranges
);
1026 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1028 zval
**rr
, **rb
, **re
;
1030 FOREACH_VAL(pos
, val
, rr
) {
1031 if (Z_TYPE_PP(rr
) == IS_ARRAY
) {
1032 if (2 == php_http_array_list(Z_ARRVAL_PP(rr
) TSRMLS_CC
, 2, &rb
, &re
)) {
1033 if ( ((Z_TYPE_PP(rb
) == IS_LONG
) || ((Z_TYPE_PP(rb
) == IS_STRING
) && is_numeric_string(Z_STRVAL_PP(rb
), Z_STRLEN_PP(rb
), NULL
, NULL
, 1))) &&
1034 ((Z_TYPE_PP(re
) == IS_LONG
) || ((Z_TYPE_PP(re
) == IS_STRING
) && is_numeric_string(Z_STRVAL_PP(re
), Z_STRLEN_PP(re
), NULL
, NULL
, 1)))) {
1035 zval
*rbl
= php_http_ztyp(IS_LONG
, *rb
);
1036 zval
*rel
= php_http_ztyp(IS_LONG
, *re
);
1038 if ((Z_LVAL_P(rbl
) >= 0) && (Z_LVAL_P(rel
) >= 0)) {
1039 php_http_buffer_appendf(&curl
->options
.ranges
, "%ld-%ld,", Z_LVAL_P(rbl
), Z_LVAL_P(rel
));
1041 zval_ptr_dtor(&rbl
);
1042 zval_ptr_dtor(&rel
);
1049 if (curl
->options
.ranges
.used
) {
1050 curl
->options
.range_request
= 1;
1051 /* ditch last comma */
1052 curl
->options
.ranges
.data
[curl
->options
.ranges
.used
- 1] = '\0';
1056 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RANGE
, curl
->options
.ranges
.data
)) {
1062 static ZEND_RESULT_CODE
php_http_curle_option_set_resume(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1064 php_http_client_curl_handler_t
*curl
= userdata
;
1065 CURL
*ch
= curl
->handle
;
1067 if (Z_LVAL_P(val
) > 0) {
1068 curl
->options
.range_request
= 1;
1070 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESUME_FROM
, Z_LVAL_P(val
))) {
1076 static ZEND_RESULT_CODE
php_http_curle_option_set_retrydelay(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1078 php_http_client_curl_handler_t
*curl
= userdata
;
1080 curl
->options
.retry
.delay
= Z_DVAL_P(val
);
1084 static ZEND_RESULT_CODE
php_http_curle_option_set_retrycount(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1086 php_http_client_curl_handler_t
*curl
= userdata
;
1088 curl
->options
.retry
.count
= Z_LVAL_P(val
);
1092 static ZEND_RESULT_CODE
php_http_curle_option_set_redirect(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1094 php_http_client_curl_handler_t
*curl
= userdata
;
1095 CURL
*ch
= curl
->handle
;
1097 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, Z_LVAL_P(val
) ? 1L : 0L)
1098 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_MAXREDIRS
, curl
->options
.redirects
= Z_LVAL_P(val
))
1105 static ZEND_RESULT_CODE
php_http_curle_option_set_portrange(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1107 php_http_client_curl_handler_t
*curl
= userdata
;
1108 CURL
*ch
= curl
->handle
;
1109 long localport
= 0, localportrange
= 0;
1110 TSRMLS_FETCH_FROM_CTX(curl
->client
->ts
);
1112 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1113 zval
**z_port_start
, *zps_copy
= NULL
, **z_port_end
, *zpe_copy
= NULL
;
1115 switch (php_http_array_list(Z_ARRVAL_P(val
) TSRMLS_CC
, 2, &z_port_start
, &z_port_end
)) {
1117 zps_copy
= php_http_ztyp(IS_LONG
, *z_port_start
);
1118 zpe_copy
= php_http_ztyp(IS_LONG
, *z_port_end
);
1119 localportrange
= labs(Z_LVAL_P(zps_copy
)-Z_LVAL_P(zpe_copy
))+1L;
1123 zps_copy
= php_http_ztyp(IS_LONG
, *z_port_start
);
1125 localport
= (zpe_copy
&& Z_LVAL_P(zpe_copy
) > 0) ? MIN(Z_LVAL_P(zps_copy
), Z_LVAL_P(zpe_copy
)) : Z_LVAL_P(zps_copy
);
1126 zval_ptr_dtor(&zps_copy
);
1128 zval_ptr_dtor(&zpe_copy
);
1135 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_LOCALPORT
, localport
)
1136 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_LOCALPORTRANGE
, localportrange
)
1143 #if PHP_HTTP_CURL_VERSION(7,37,0)
1144 static ZEND_RESULT_CODE
php_http_curle_option_set_proxyheader(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1146 php_http_client_curl_handler_t
*curl
= userdata
;
1147 TSRMLS_FETCH_FROM_CTX(curl
->client
->ts
);
1149 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1150 php_http_array_hashkey_t header_key
= php_http_array_hashkey_init(0);
1151 zval
**header_val
, *header_cpy
;
1153 php_http_buffer_t header
;
1155 php_http_buffer_init(&header
);
1156 FOREACH_KEYVAL(pos
, val
, header_key
, header_val
) {
1157 if (header_key
.type
== HASH_KEY_IS_STRING
) {
1158 header_cpy
= php_http_ztyp(IS_STRING
, *header_val
);
1159 php_http_buffer_appendf(&header
, "%s: %s", header_key
.str
, Z_STRVAL_P(header_cpy
));
1160 php_http_buffer_fix(&header
);
1161 curl
->options
.proxyheaders
= curl_slist_append(curl
->options
.proxyheaders
, header
.data
);
1162 php_http_buffer_reset(&header
);
1164 zval_ptr_dtor(&header_cpy
);
1167 php_http_buffer_dtor(&header
);
1169 if (CURLE_OK
!= curl_easy_setopt(curl
->handle
, CURLOPT_PROXYHEADER
, curl
->options
.proxyheaders
)) {
1172 if (CURLE_OK
!= curl_easy_setopt(curl
->handle
, CURLOPT_HEADEROPT
, CURLHEADER_SEPARATE
)) {
1173 curl_easy_setopt(curl
->handle
, CURLOPT_PROXYHEADER
, NULL
);
1180 #if PHP_HTTP_CURL_VERSION(7,21,3)
1181 static ZEND_RESULT_CODE
php_http_curle_option_set_resolve(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1183 php_http_client_curl_handler_t
*curl
= userdata
;
1184 CURL
*ch
= curl
->handle
;
1185 TSRMLS_FETCH_FROM_CTX(curl
->client
->ts
);
1187 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1188 php_http_array_hashkey_t key
= php_http_array_hashkey_init(0);
1192 FOREACH_KEYVAL(pos
, val
, key
, data
) {
1193 zval
*cpy
= php_http_ztyp(IS_STRING
, *data
);
1194 curl
->options
.resolve
= curl_slist_append(curl
->options
.resolve
, Z_STRVAL_P(cpy
));
1195 zval_ptr_dtor(&cpy
);
1198 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESOLVE
, curl
->options
.resolve
)) {
1202 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESOLVE
, NULL
)) {
1210 #if PHP_HTTP_CURL_VERSION(7,21,4) && defined(PHP_HTTP_CURL_TLSAUTH_SRP)
1211 static ZEND_RESULT_CODE
php_http_curle_option_set_ssl_tlsauthtype(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1213 php_http_client_curl_handler_t
*curl
= userdata
;
1214 CURL
*ch
= curl
->handle
;
1216 if (val
&& Z_LVAL_P(val
)) {
1217 switch (Z_LVAL_P(val
)) {
1218 case CURL_TLSAUTH_SRP
:
1219 if (CURLE_OK
== curl_easy_setopt(ch
, CURLOPT_TLSAUTH_TYPE
, PHP_HTTP_CURL_TLSAUTH_SRP
)) {
1227 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TLSAUTH_TYPE
, PHP_HTTP_CURL_TLSAUTH_DEF
)) {
1234 static void php_http_curle_options_init(php_http_options_t
*registry TSRMLS_DC
)
1236 php_http_option_t
*opt
;
1239 #if PHP_HTTP_CURL_VERSION(7,42,0)
1240 php_http_option_register(registry
, ZEND_STRL("path_as_is"), CURLOPT_PATH_AS_IS
, IS_BOOL
);
1244 php_http_option_register(registry
, ZEND_STRL("proxyhost"), CURLOPT_PROXY
, IS_STRING
);
1245 php_http_option_register(registry
, ZEND_STRL("proxytype"), CURLOPT_PROXYTYPE
, IS_LONG
);
1246 php_http_option_register(registry
, ZEND_STRL("proxyport"), CURLOPT_PROXYPORT
, IS_LONG
);
1247 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyauth"), CURLOPT_PROXYUSERPWD
, IS_STRING
))) {
1248 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1250 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyauthtype"), CURLOPT_PROXYAUTH
, IS_LONG
))) {
1251 Z_LVAL(opt
->defval
) = CURLAUTH_ANYSAFE
;
1253 php_http_option_register(registry
, ZEND_STRL("proxytunnel"), CURLOPT_HTTPPROXYTUNNEL
, IS_BOOL
);
1254 #if PHP_HTTP_CURL_VERSION(7,19,4)
1255 php_http_option_register(registry
, ZEND_STRL("noproxy"), CURLOPT_NOPROXY
, IS_STRING
);
1258 #if PHP_HTTP_CURL_VERSION(7,37,0)
1259 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyheader"), CURLOPT_PROXYHEADER
, IS_ARRAY
))) {
1260 opt
->setter
= php_http_curle_option_set_proxyheader
;
1263 #if PHP_HTTP_CURL_VERSION(7,43,0)
1264 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_GSSAPI
)
1265 && (opt
= php_http_option_register(registry
, ZEND_STRL("proxy_service_name"), CURLOPT_PROXY_SERVICE_NAME
, IS_STRING
))
1267 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1271 #if PHP_HTTP_CURL_VERSION(7,40,0)
1272 if ((opt
= php_http_option_register(registry
, ZEND_STRL("unix_socket_path"), CURLOPT_UNIX_SOCKET_PATH
, IS_STRING
))) {
1273 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1274 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1279 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_cache_timeout"), CURLOPT_DNS_CACHE_TIMEOUT
, IS_LONG
))) {
1280 Z_LVAL(opt
->defval
) = 60;
1282 php_http_option_register(registry
, ZEND_STRL("ipresolve"), CURLOPT_IPRESOLVE
, IS_LONG
);
1283 #if PHP_HTTP_CURL_VERSION(7,21,3)
1284 if ((opt
= php_http_option_register(registry
, ZEND_STRL("resolve"), CURLOPT_RESOLVE
, IS_ARRAY
))) {
1285 opt
->setter
= php_http_curle_option_set_resolve
;
1288 #if PHP_HTTP_HAVE_ARES
1289 # if PHP_HTTP_CURL_VERSION(7,24,0)
1290 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_servers"), CURLOPT_DNS_SERVERS
, IS_STRING
))) {
1291 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1294 # if PHP_HTTP_CURL_VERSION(7,33,0)
1295 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_interface"), CURLOPT_DNS_INTERFACE
, IS_STRING
))) {
1296 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1298 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_local_ip4"), CURLOPT_DNS_LOCAL_IP4
, IS_STRING
))) {
1299 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1301 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_local_ip6"), CURLOPT_DNS_LOCAL_IP6
, IS_STRING
))) {
1302 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1308 php_http_option_register(registry
, ZEND_STRL("low_speed_limit"), CURLOPT_LOW_SPEED_LIMIT
, IS_LONG
);
1309 php_http_option_register(registry
, ZEND_STRL("low_speed_time"), CURLOPT_LOW_SPEED_TIME
, IS_LONG
);
1312 php_http_option_register(registry, ZEND_STRL("max_send_speed"), CURLOPT_MAX_SEND_SPEED_LARGE, IS_LONG);
1313 php_http_option_register(registry, ZEND_STRL("max_recv_speed"), CURLOPT_MAX_RECV_SPEED_LARGE, IS_LONG);
1316 /* connection handling */
1318 if ((opt = php_http_option_register(registry, ZEND_STRL("maxconnects"), CURLOPT_MAXCONNECTS, IS_LONG))) {
1319 Z_LVAL(opt->defval) = 5;
1322 php_http_option_register(registry
, ZEND_STRL("fresh_connect"), CURLOPT_FRESH_CONNECT
, IS_BOOL
);
1323 php_http_option_register(registry
, ZEND_STRL("forbid_reuse"), CURLOPT_FORBID_REUSE
, IS_BOOL
);
1325 /* outgoing interface */
1326 php_http_option_register(registry
, ZEND_STRL("interface"), CURLOPT_INTERFACE
, IS_STRING
);
1327 if ((opt
= php_http_option_register(registry
, ZEND_STRL("portrange"), CURLOPT_LOCALPORT
, IS_ARRAY
))) {
1328 opt
->setter
= php_http_curle_option_set_portrange
;
1331 /* another endpoint port */
1332 php_http_option_register(registry
, ZEND_STRL("port"), CURLOPT_PORT
, IS_LONG
);
1334 /* RFC4007 zone_id */
1335 #if PHP_HTTP_CURL_VERSION(7,19,0)
1336 php_http_option_register(registry
, ZEND_STRL("address_scope"), CURLOPT_ADDRESS_SCOPE
, IS_LONG
);
1340 if ((opt
= php_http_option_register(registry
, ZEND_STRL("httpauth"), CURLOPT_USERPWD
, IS_STRING
))) {
1341 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1343 if ((opt
= php_http_option_register(registry
, ZEND_STRL("httpauthtype"), CURLOPT_HTTPAUTH
, IS_LONG
))) {
1344 Z_LVAL(opt
->defval
) = CURLAUTH_ANYSAFE
;
1346 #if PHP_HTTP_CURL_VERSION(7,43,0)
1347 if ((opt
= php_http_option_register(registry
, ZEND_STRL("service_name"), CURLOPT_SERVICE_NAME
, IS_STRING
))) {
1348 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1353 if ((opt
= php_http_option_register(registry
, ZEND_STRL("redirect"), CURLOPT_FOLLOWLOCATION
, IS_LONG
))) {
1354 opt
->setter
= php_http_curle_option_set_redirect
;
1356 php_http_option_register(registry
, ZEND_STRL("unrestricted_auth"), CURLOPT_UNRESTRICTED_AUTH
, IS_BOOL
);
1357 #if PHP_HTTP_CURL_VERSION(7,19,1)
1358 php_http_option_register(registry
, ZEND_STRL("postredir"), CURLOPT_POSTREDIR
, IS_LONG
);
1362 if ((opt
= php_http_option_register(registry
, ZEND_STRL("retrycount"), 0, IS_LONG
))) {
1363 opt
->setter
= php_http_curle_option_set_retrycount
;
1365 if ((opt
= php_http_option_register(registry
, ZEND_STRL("retrydelay"), 0, IS_DOUBLE
))) {
1366 opt
->setter
= php_http_curle_option_set_retrydelay
;
1370 if ((opt
= php_http_option_register(registry
, ZEND_STRL("referer"), CURLOPT_REFERER
, IS_STRING
))) {
1371 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1373 if ((opt
= php_http_option_register(registry
, ZEND_STRL("autoreferer"), CURLOPT_AUTOREFERER
, IS_BOOL
))) {
1374 ZVAL_BOOL(&opt
->defval
, 1);
1378 if ((opt
= php_http_option_register(registry
, ZEND_STRL("useragent"), CURLOPT_USERAGENT
, IS_STRING
))) {
1379 /* don't check strlen, to allow sending no useragent at all */
1380 ZVAL_STRING(&opt
->defval
,
1381 "PECL_HTTP/" PHP_PECL_HTTP_VERSION
" "
1382 "PHP/" PHP_VERSION
" "
1383 "libcurl/" LIBCURL_VERSION
1388 if ((opt
= php_http_option_register(registry
, ZEND_STRL("resume"), CURLOPT_RESUME_FROM
, IS_LONG
))) {
1389 opt
->setter
= php_http_curle_option_set_resume
;
1392 if ((opt
= php_http_option_register(registry
, ZEND_STRL("range"), CURLOPT_RANGE
, IS_ARRAY
))) {
1393 opt
->setter
= php_http_curle_option_set_range
;
1397 if ((opt
= php_http_option_register(registry
, ZEND_STRL("etag"), 0, IS_STRING
))) {
1398 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1399 opt
->setter
= php_http_curle_option_set_etag
;
1403 if ((opt
= php_http_option_register(registry
, ZEND_STRL("compress"), 0, IS_BOOL
))) {
1404 opt
->setter
= php_http_curle_option_set_compress
;
1408 if ((opt
= php_http_option_register(registry
, ZEND_STRL("lastmodified"), 0, IS_LONG
))) {
1409 opt
->setter
= php_http_curle_option_set_lastmodified
;
1413 if ((opt
= php_http_option_register(registry
, ZEND_STRL("encodecookies"), 0, IS_BOOL
))) {
1414 opt
->setter
= php_http_curle_option_set_encodecookies
;
1415 ZVAL_BOOL(&opt
->defval
, 1);
1417 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookies"), 0, IS_ARRAY
))) {
1418 opt
->setter
= php_http_curle_option_set_cookies
;
1421 /* cookiesession, don't load session cookies from cookiestore */
1422 php_http_option_register(registry
, ZEND_STRL("cookiesession"), CURLOPT_COOKIESESSION
, IS_BOOL
);
1423 /* cookiestore, read initial cookies from that file and store cookies back into that file */
1424 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookiestore"), 0, IS_STRING
))) {
1425 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1426 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1427 opt
->setter
= php_http_curle_option_set_cookiestore
;
1431 php_http_option_register(registry
, ZEND_STRL("maxfilesize"), CURLOPT_MAXFILESIZE
, IS_LONG
);
1433 /* http protocol version */
1434 php_http_option_register(registry
, ZEND_STRL("protocol"), CURLOPT_HTTP_VERSION
, IS_LONG
);
1437 if ((opt
= php_http_option_register(registry
, ZEND_STRL("timeout"), CURLOPT_TIMEOUT_MS
, IS_DOUBLE
))) {
1438 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1440 if ((opt
= php_http_option_register(registry
, ZEND_STRL("connecttimeout"), CURLOPT_CONNECTTIMEOUT_MS
, IS_DOUBLE
))) {
1441 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1442 Z_DVAL(opt
->defval
) = 3;
1444 #if PHP_HTTP_CURL_VERSION(7,36,0)
1445 if ((opt
= php_http_option_register(registry
, ZEND_STRL("expect_100_timeout"), CURLOPT_EXPECT_100_TIMEOUT_MS
, IS_DOUBLE
))) {
1446 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1447 Z_DVAL(opt
->defval
) = 1;
1452 php_http_option_register(registry
, ZEND_STRL("tcp_nodelay"), CURLOPT_TCP_NODELAY
, IS_BOOL
);
1453 #if PHP_HTTP_CURL_VERSION(7,25,0)
1454 php_http_option_register(registry
, ZEND_STRL("tcp_keepalive"), CURLOPT_TCP_KEEPALIVE
, IS_BOOL
);
1455 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tcp_keepidle"), CURLOPT_TCP_KEEPIDLE
, IS_LONG
))) {
1456 Z_LVAL(opt
->defval
) = 60;
1458 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tcp_keepintvl"), CURLOPT_TCP_KEEPINTVL
, IS_LONG
))) {
1459 Z_LVAL(opt
->defval
) = 60;
1464 if ((opt
= php_http_option_register(registry
, ZEND_STRL("ssl"), 0, IS_ARRAY
))) {
1465 registry
= &opt
->suboptions
;
1467 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cert"), CURLOPT_SSLCERT
, IS_STRING
))) {
1468 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1469 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1471 if ((opt
= php_http_option_register(registry
, ZEND_STRL("certtype"), CURLOPT_SSLCERTTYPE
, IS_STRING
))) {
1472 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1473 ZVAL_STRING(&opt
->defval
, "PEM", 0);
1475 if ((opt
= php_http_option_register(registry
, ZEND_STRL("key"), CURLOPT_SSLKEY
, IS_STRING
))) {
1476 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1477 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1479 if ((opt
= php_http_option_register(registry
, ZEND_STRL("keytype"), CURLOPT_SSLKEYTYPE
, IS_STRING
))) {
1480 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1481 ZVAL_STRING(&opt
->defval
, "PEM", 0);
1483 if ((opt
= php_http_option_register(registry
, ZEND_STRL("keypasswd"), CURLOPT_SSLKEYPASSWD
, IS_STRING
))) {
1484 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1486 php_http_option_register(registry
, ZEND_STRL("engine"), CURLOPT_SSLENGINE
, IS_STRING
);
1487 php_http_option_register(registry
, ZEND_STRL("version"), CURLOPT_SSLVERSION
, IS_LONG
);
1488 if ((opt
= php_http_option_register(registry
, ZEND_STRL("verifypeer"), CURLOPT_SSL_VERIFYPEER
, IS_BOOL
))) {
1489 ZVAL_BOOL(&opt
->defval
, 1);
1491 if ((opt
= php_http_option_register(registry
, ZEND_STRL("verifyhost"), CURLOPT_SSL_VERIFYHOST
, IS_BOOL
))) {
1492 ZVAL_BOOL(&opt
->defval
, 1);
1493 opt
->setter
= php_http_curle_option_set_ssl_verifyhost
;
1495 #if PHP_HTTP_CURL_VERSION(7,41,0) && (defined(PHP_HTTP_HAVE_OPENSSL) || defined(PHP_HTTP_HAVE_NSS) || defined(PHP_HTTP_HAVE_GNUTLS))
1496 php_http_option_register(registry
, ZEND_STRL("verifystatus"), CURLOPT_SSL_VERIFYSTATUS
, IS_BOOL
);
1498 php_http_option_register(registry
, ZEND_STRL("cipher_list"), CURLOPT_SSL_CIPHER_LIST
, IS_STRING
);
1499 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cainfo"), CURLOPT_CAINFO
, IS_STRING
))) {
1500 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1501 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1502 #ifdef PHP_HTTP_CURL_CAINFO
1503 ZVAL_STRING(&opt
->defval
, PHP_HTTP_CURL_CAINFO
, 0);
1506 if ((opt
= php_http_option_register(registry
, ZEND_STRL("capath"), CURLOPT_CAPATH
, IS_STRING
))) {
1507 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1508 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1509 #ifdef PHP_HTTP_CURL_CAPATH
1510 ZVAL_STRING(&opt
->defval
, PHP_HTTP_CURL_CAPATH
, 0);
1513 if ((opt
= php_http_option_register(registry
, ZEND_STRL("random_file"), CURLOPT_RANDOM_FILE
, IS_STRING
))) {
1514 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1515 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1517 if ((opt
= php_http_option_register(registry
, ZEND_STRL("egdsocket"), CURLOPT_EGDSOCKET
, IS_STRING
))) {
1518 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1519 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1521 #if PHP_HTTP_CURL_VERSION(7,19,0)
1522 if ((opt
= php_http_option_register(registry
, ZEND_STRL("issuercert"), CURLOPT_ISSUERCERT
, IS_STRING
))) {
1523 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1524 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1526 # ifdef PHP_HTTP_HAVE_OPENSSL
1527 if ((opt
= php_http_option_register(registry
, ZEND_STRL("crlfile"), CURLOPT_CRLFILE
, IS_STRING
))) {
1528 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1529 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1533 #if (PHP_HTTP_CURL_VERSION(7,19,1) && defined(PHP_HTTP_HAVE_OPENSSL)) || (PHP_HTTP_CURL_VERSION(7,34,0) && defined(PHP_HTTP_HAVE_NSS)) || (PHP_HTTP_CURL_VERSION(7,42,0) && defined(PHP_HTTP_HAVE_GNUTLS)) || (PHP_HTTP_CURL_VERSION(7,39,0) && defined(PHP_HTTP_HAVE_GSKIT))
1534 php_http_option_register(registry
, ZEND_STRL("certinfo"), CURLOPT_CERTINFO
, IS_BOOL
);
1536 #if PHP_HTTP_CURL_VERSION(7,36,0)
1537 if ((opt
= php_http_option_register(registry
, ZEND_STRL("enable_npn"), CURLOPT_SSL_ENABLE_NPN
, IS_BOOL
))) {
1538 ZVAL_BOOL(&opt
->defval
, 1);
1540 if ((opt
= php_http_option_register(registry
, ZEND_STRL("enable_alpn"), CURLOPT_SSL_ENABLE_ALPN
, IS_BOOL
))) {
1541 ZVAL_BOOL(&opt
->defval
, 1);
1544 #if PHP_HTTP_CURL_VERSION(7,39,0)
1545 /* FIXME: see http://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html#AVAILABILITY */
1546 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pinned_publickey"), CURLOPT_PINNEDPUBLICKEY
, IS_STRING
))) {
1547 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1548 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1551 #if PHP_HTTP_CURL_VERSION(7,21,4) && defined(PHP_HTTP_CURL_TLSAUTH_SRP)
1552 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tlsauthtype"), CURLOPT_TLSAUTH_TYPE
, IS_LONG
))) {
1553 opt
->setter
= php_http_curle_option_set_ssl_tlsauthtype
;
1555 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tlsauthuser"), CURLOPT_TLSAUTH_USERNAME
, IS_STRING
))) {
1556 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1558 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tlsauthpass"), CURLOPT_TLSAUTH_PASSWORD
, IS_STRING
))) {
1559 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1562 #if PHP_HTTP_CURL_VERSION(7,42,0) && (defined(PHP_HTTP_HAVE_NSS) || defined(PHP_HTTP_HAVE_DARWINSSL))
1563 php_http_option_register(registry
, ZEND_STRL("falsestart"), CURLOPT_SSL_FALSESTART
, IS_BOOL
);
1568 static zval
*php_http_curle_get_option(php_http_option_t
*opt
, HashTable
*options
, void *userdata
)
1570 php_http_client_curl_handler_t
*curl
= userdata
;
1573 if ((option
= php_http_option_get(opt
, options
, NULL
))) {
1574 option
= php_http_ztyp(opt
->type
, option
);
1575 zend_hash_quick_update(&curl
->options
.cache
, opt
->name
.s
, opt
->name
.l
, opt
->name
.h
, &option
, sizeof(zval
*), NULL
);
1580 static ZEND_RESULT_CODE
php_http_curle_set_option(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1582 php_http_client_curl_handler_t
*curl
= userdata
;
1583 CURL
*ch
= curl
->handle
;
1585 CURLcode rc
= CURLE_OK
;
1586 ZEND_RESULT_CODE rv
= SUCCESS
;
1587 TSRMLS_FETCH_FROM_CTX(curl
->client
->ts
);
1593 switch (opt
->type
) {
1596 rv
= opt
->setter(opt
, val
, curl
);
1597 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, (long) Z_BVAL_P(val
))) {
1604 rv
= opt
->setter(opt
, val
, curl
);
1605 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, Z_LVAL_P(val
))) {
1612 rv
= opt
->setter(opt
, val
, curl
);
1613 } else if ((opt
->flags
& PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
) && !Z_STRLEN_P(val
)) {
1614 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1617 } else if ((opt
->flags
& PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
) && Z_STRVAL_P(val
) && SUCCESS
!= php_check_open_basedir(Z_STRVAL_P(val
) TSRMLS_CC
)) {
1618 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1621 } else if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, Z_STRVAL_P(val
)))) {
1627 if (opt
->flags
& PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
) {
1629 Z_DVAL(tmp
) *= 1000;
1633 rv
= opt
->setter(opt
, val
, curl
);
1634 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, (long) Z_DVAL_P(val
))) {
1641 rv
= opt
->setter(opt
, val
, curl
);
1642 } else if (Z_TYPE_P(val
) != IS_NULL
) {
1643 rv
= php_http_options_apply(&opt
->suboptions
, Z_ARRVAL_P(val
), curl
);
1649 rv
= opt
->setter(opt
, val
, curl
);
1655 if (rv
!= SUCCESS
) {
1656 php_error_docref(NULL TSRMLS_CC
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
.s
, curl_easy_strerror(rc
));
1661 #if PHP_HTTP_CURL_VERSION(7,30,0)
1662 static ZEND_RESULT_CODE
php_http_curlm_option_set_pipelining_bl(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1664 php_http_client_t
*client
= userdata
;
1665 php_http_client_curl_t
*curl
= client
->ctx
;
1666 CURLM
*ch
= curl
->handle
->multi
;
1669 TSRMLS_FETCH_FROM_CTX(client
->ts
);
1671 /* array of char *, ending with a NULL */
1672 if (value
&& Z_TYPE_P(value
) != IS_NULL
) {
1675 HashTable
*ht
= HASH_OF(value
);
1676 int c
= zend_hash_num_elements(ht
);
1677 char **ptr
= ecalloc(c
+ 1, sizeof(char *));
1681 zend_hash_init(&tmp_ht
, c
, NULL
, ZVAL_PTR_DTOR
, 0);
1682 array_join(ht
, &tmp_ht
, 0, ARRAY_JOIN_STRINGIFY
);
1684 FOREACH_HASH_VAL(pos
, &tmp_ht
, entry
) {
1685 *ptr
++ = Z_STRVAL_PP(entry
);
1689 if (CURLM_OK
!= curl_multi_setopt(ch
, opt
->option
, bl
)) {
1692 zend_hash_destroy(&tmp_ht
);
1699 zend_hash_destroy(&tmp_ht
);
1705 #if PHP_HTTP_HAVE_EVENT
1706 static inline ZEND_RESULT_CODE
php_http_curlm_use_eventloop(php_http_client_t
*h
, zend_bool enable
)
1708 php_http_client_curl_t
*curl
= h
->ctx
;
1710 if ((curl
->useevents
= enable
)) {
1711 if (!curl
->evbase
) {
1712 curl
->evbase
= event_base_new();
1714 if (!curl
->timeout
) {
1715 curl
->timeout
= ecalloc(1, sizeof(struct event
));
1717 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_SOCKETDATA
, h
);
1718 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_SOCKETFUNCTION
, php_http_curlm_socket_callback
);
1719 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_TIMERDATA
, h
);
1720 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_TIMERFUNCTION
, php_http_curlm_timer_callback
);
1722 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_SOCKETDATA
, NULL
);
1723 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_SOCKETFUNCTION
, NULL
);
1724 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_TIMERDATA
, NULL
);
1725 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_TIMERFUNCTION
, NULL
);
1731 static ZEND_RESULT_CODE
php_http_curlm_option_set_use_eventloop(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1733 php_http_client_t
*client
= userdata
;
1735 return php_http_curlm_use_eventloop(client
, value
&& Z_BVAL_P(value
));
1739 static void php_http_curlm_options_init(php_http_options_t
*registry TSRMLS_DC
)
1741 php_http_option_t
*opt
;
1743 /* set size of connection cache */
1744 if ((opt
= php_http_option_register(registry
, ZEND_STRL("maxconnects"), CURLMOPT_MAXCONNECTS
, IS_LONG
))) {
1745 /* -1 == default, 0 == unlimited */
1746 ZVAL_LONG(&opt
->defval
, -1);
1748 /* set max number of connections to a single host */
1749 #if PHP_HTTP_CURL_VERSION(7,30,0)
1750 php_http_option_register(registry
, ZEND_STRL("max_host_connections"), CURLMOPT_MAX_HOST_CONNECTIONS
, IS_LONG
);
1752 /* maximum number of requests in a pipeline */
1753 #if PHP_HTTP_CURL_VERSION(7,30,0)
1754 if ((opt
= php_http_option_register(registry
, ZEND_STRL("max_pipeline_length"), CURLMOPT_MAX_PIPELINE_LENGTH
, IS_LONG
))) {
1755 ZVAL_LONG(&opt
->defval
, 5);
1758 /* max simultaneously open connections */
1759 #if PHP_HTTP_CURL_VERSION(7,30,0)
1760 php_http_option_register(registry
, ZEND_STRL("max_total_connections"), CURLMOPT_MAX_TOTAL_CONNECTIONS
, IS_LONG
);
1762 /* enable/disable HTTP pipelining */
1763 php_http_option_register(registry
, ZEND_STRL("pipelining"), CURLMOPT_PIPELINING
, IS_BOOL
);
1764 /* chunk length threshold for pipelining */
1765 #if PHP_HTTP_CURL_VERSION(7,30,0)
1766 php_http_option_register(registry
, ZEND_STRL("chunk_length_penalty_size"), CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE
, IS_LONG
);
1768 /* size threshold for pipelining penalty */
1769 #if PHP_HTTP_CURL_VERSION(7,30,0)
1770 php_http_option_register(registry
, ZEND_STRL("content_length_penalty_size"), CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE
, IS_LONG
);
1772 /* pipelining server blacklist */
1773 #if PHP_HTTP_CURL_VERSION(7,30,0)
1774 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pipelining_server_bl"), CURLMOPT_PIPELINING_SERVER_BL
, IS_ARRAY
))) {
1775 opt
->setter
= php_http_curlm_option_set_pipelining_bl
;
1778 /* pipelining host blacklist */
1779 #if PHP_HTTP_CURL_VERSION(7,30,0)
1780 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pipelining_site_bl"), CURLMOPT_PIPELINING_SITE_BL
, IS_ARRAY
))) {
1781 opt
->setter
= php_http_curlm_option_set_pipelining_bl
;
1785 #if PHP_HTTP_HAVE_EVENT
1786 if ((opt
= php_http_option_register(registry
, ZEND_STRL("use_eventloop"), 0, IS_BOOL
))) {
1787 opt
->setter
= php_http_curlm_option_set_use_eventloop
;
1792 static ZEND_RESULT_CODE
php_http_curlm_set_option(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1794 php_http_client_t
*client
= userdata
;
1795 php_http_client_curl_t
*curl
= client
->ctx
;
1796 CURLM
*ch
= curl
->handle
->multi
;
1798 CURLMcode rc
= CURLM_UNKNOWN_OPTION
;
1799 ZEND_RESULT_CODE rv
= SUCCESS
;
1800 TSRMLS_FETCH_FROM_CTX(client
->ts
);
1804 } else if (opt
->type
&& Z_TYPE_P(val
) != opt
->type
&& !(Z_TYPE_P(val
) == IS_NULL
&& opt
->type
== IS_ARRAY
)) {
1805 val
= php_http_ztyp(opt
->type
, val
);
1809 rv
= opt
->setter(opt
, val
, client
);
1811 switch (opt
->type
) {
1813 if (CURLM_OK
!= (rc
= curl_multi_setopt(ch
, opt
->option
, (long) Z_BVAL_P(val
)))) {
1818 if (CURLM_OK
!= (rc
= curl_multi_setopt(ch
, opt
->option
, Z_LVAL_P(val
)))) {
1828 if (val
&& val
!= orig
&& val
!= &opt
->defval
) {
1829 zval_ptr_dtor(&val
);
1832 if (rv
!= SUCCESS
) {
1833 php_error_docref(NULL TSRMLS_CC
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
.s
, curl_easy_strerror(rc
));
1840 static ZEND_RESULT_CODE
php_http_client_curl_handler_reset(php_http_client_curl_handler_t
*curl
)
1842 CURL
*ch
= curl
->handle
;
1843 php_http_curle_storage_t
*st
;
1845 if ((st
= php_http_curle_get_storage(ch
))) {
1850 if (st
->cookiestore
) {
1851 pefree(st
->cookiestore
, 1);
1852 st
->cookiestore
= NULL
;
1854 st
->errorbuffer
[0] = '\0';
1858 curl_easy_setopt(ch
, CURLOPT_URL
, NULL
);
1859 curl_easy_setopt(ch
, CURLOPT_CUSTOMREQUEST
, NULL
);
1860 curl_easy_setopt(ch
, CURLOPT_HTTPGET
, 1L);
1861 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 0L);
1862 /* libcurl < 7.19.6 does not clear auth info with USERPWD set to NULL */
1863 #if PHP_HTTP_CURL_VERSION(7,19,1)
1864 curl_easy_setopt(ch
, CURLOPT_PROXYUSERNAME
, NULL
);
1865 curl_easy_setopt(ch
, CURLOPT_PROXYPASSWORD
, NULL
);
1866 curl_easy_setopt(ch
, CURLOPT_USERNAME
, NULL
);
1867 curl_easy_setopt(ch
, CURLOPT_PASSWORD
, NULL
);
1870 #if PHP_HTTP_CURL_VERSION(7,21,3)
1871 if (curl
->options
.resolve
) {
1872 curl_slist_free_all(curl
->options
.resolve
);
1873 curl
->options
.resolve
= NULL
;
1876 curl
->options
.retry
.count
= 0;
1877 curl
->options
.retry
.delay
= 0;
1878 curl
->options
.redirects
= 0;
1879 curl
->options
.encode_cookies
= 1;
1881 if (curl
->options
.headers
) {
1882 curl_slist_free_all(curl
->options
.headers
);
1883 curl
->options
.headers
= NULL
;
1885 if (curl
->options
.proxyheaders
) {
1886 curl_slist_free_all(curl
->options
.proxyheaders
);
1887 curl
->options
.proxyheaders
= NULL
;
1890 php_http_buffer_reset(&curl
->options
.cookies
);
1891 php_http_buffer_reset(&curl
->options
.ranges
);
1896 static php_http_client_curl_handler_t
*php_http_client_curl_handler_init(php_http_client_t
*h
, php_resource_factory_t
*rf
)
1899 php_http_client_curl_t
*curl
= h
->ctx
;
1900 php_http_client_curl_handler_t
*handler
;
1901 TSRMLS_FETCH_FROM_CTX(h
->ts
);
1903 if (!(handle
= php_resource_factory_handle_ctor(rf
, NULL TSRMLS_CC
))) {
1904 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to initialize curl handle->multi");
1908 handler
= ecalloc(1, sizeof(*handler
));
1910 handler
->client
= h
;
1911 handler
->handle
= handle
;
1912 handler
->response
.body
= php_http_message_body_init(NULL
, NULL TSRMLS_CC
);
1913 php_http_buffer_init(&handler
->response
.headers
);
1914 php_http_buffer_init(&handler
->options
.cookies
);
1915 php_http_buffer_init(&handler
->options
.ranges
);
1916 zend_hash_init(&handler
->options
.cache
, 0, NULL
, ZVAL_PTR_DTOR
, 0);
1919 curl_easy_setopt(handle
, CURLOPT_NOSIGNAL
, 1L);
1921 curl_easy_setopt(handle
, CURLOPT_HEADER
, 0L);
1922 curl_easy_setopt(handle
, CURLOPT_FILETIME
, 1L);
1923 curl_easy_setopt(handle
, CURLOPT_AUTOREFERER
, 1L);
1924 curl_easy_setopt(handle
, CURLOPT_VERBOSE
, 1L);
1925 curl_easy_setopt(handle
, CURLOPT_NOPROGRESS
, 0L);
1926 curl_easy_setopt(handle
, CURLOPT_HEADERFUNCTION
, php_http_curle_header_callback
);
1927 curl_easy_setopt(handle
, CURLOPT_WRITEFUNCTION
, php_http_curle_body_callback
);
1928 curl_easy_setopt(handle
, CURLOPT_DEBUGFUNCTION
, php_http_curle_raw_callback
);
1929 curl_easy_setopt(handle
, CURLOPT_READFUNCTION
, php_http_curle_read_callback
);
1930 curl_easy_setopt(handle
, CURLOPT_SEEKFUNCTION
, php_http_curle_seek_callback
);
1931 #if PHP_HTTP_CURL_VERSION(7,32,0)
1932 curl_easy_setopt(handle
, CURLOPT_XFERINFOFUNCTION
, php_http_curle_xferinfo_callback
);
1933 curl_easy_setopt(handle
, CURLOPT_XFERINFODATA
, handler
);
1935 curl_easy_setopt(handle
, CURLOPT_PROGRESSFUNCTION
, php_http_curle_progress_callback
);
1936 curl_easy_setopt(handle
, CURLOPT_PROGRESSDATA
, handler
);
1938 curl_easy_setopt(handle
, CURLOPT_DEBUGDATA
, handler
);
1939 curl_easy_setopt(handle
, CURLOPT_WRITEDATA
, handler
);
1940 curl_easy_setopt(handle
, CURLOPT_HEADERDATA
, handler
);
1941 curl_easy_setopt(handle
, CURLOPT_SHARE
, curl
->handle
->share
);
1943 php_http_client_curl_handler_reset(handler
);
1949 static ZEND_RESULT_CODE
php_http_client_curl_handler_prepare(php_http_client_curl_handler_t
*curl
, php_http_client_enqueue_t
*enqueue
)
1952 php_http_message_t
*msg
= enqueue
->request
;
1953 php_http_curle_storage_t
*storage
= php_http_curle_get_storage(curl
->handle
);
1954 TSRMLS_FETCH_FROM_CTX(curl
->client
->ts
);
1957 if (!PHP_HTTP_INFO(msg
).request
.url
) {
1958 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Cannot request empty URL");
1961 storage
->errorbuffer
[0] = '\0';
1963 pefree(storage
->url
, 1);
1965 php_http_url_to_string(PHP_HTTP_INFO(msg
).request
.url
, &storage
->url
, NULL
, 1);
1966 curl_easy_setopt(curl
->handle
, CURLOPT_URL
, storage
->url
);
1969 php_http_options_apply(&php_http_curle_options
, enqueue
->options
, curl
);
1971 /* request headers */
1972 php_http_message_update_headers(msg
);
1973 if (zend_hash_num_elements(&msg
->hdrs
)) {
1974 php_http_array_hashkey_t header_key
= php_http_array_hashkey_init(0);
1975 zval
**header_val
, *header_cpy
;
1977 php_http_buffer_t header
;
1978 #if !PHP_HTTP_CURL_VERSION(7,23,0)
1981 zend_hash_find(&msg
->hdrs
, ZEND_STRS("Content-Length"), (void *) &ct
);
1984 php_http_buffer_init(&header
);
1985 FOREACH_HASH_KEYVAL(pos
, &msg
->hdrs
, header_key
, header_val
) {
1986 if (header_key
.type
== HASH_KEY_IS_STRING
) {
1987 #if !PHP_HTTP_CURL_VERSION(7,23,0)
1988 /* avoid duplicate content-length header */
1989 if (ct
&& *ct
== *header_val
) {
1993 header_cpy
= php_http_ztyp(IS_STRING
, *header_val
);
1994 php_http_buffer_appendf(&header
, "%s: %s", header_key
.str
, Z_STRVAL_P(header_cpy
));
1995 php_http_buffer_fix(&header
);
1996 curl
->options
.headers
= curl_slist_append(curl
->options
.headers
, header
.data
);
1997 php_http_buffer_reset(&header
);
1999 zval_ptr_dtor(&header_cpy
);
2002 php_http_buffer_dtor(&header
);
2004 curl_easy_setopt(curl
->handle
, CURLOPT_HTTPHEADER
, curl
->options
.headers
);
2006 /* attach request body */
2007 if ((body_size
= php_http_message_body_size(msg
->body
))) {
2008 /* RFC2616, section 4.3 (para. 4) states that »a message-body MUST NOT be included in a request if the
2009 * specification of the request method (section 5.1.1) does not allow sending an entity-body in request.«
2010 * Following the clause in section 5.1.1 (para. 2) that request methods »MUST be implemented with the
2011 * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method
2012 * does not allow a request body.
2014 php_stream_rewind(php_http_message_body_stream(msg
->body
));
2015 curl_easy_setopt(curl
->handle
, CURLOPT_SEEKDATA
, msg
->body
);
2016 curl_easy_setopt(curl
->handle
, CURLOPT_READDATA
, msg
->body
);
2017 curl_easy_setopt(curl
->handle
, CURLOPT_INFILESIZE
, body_size
);
2018 curl_easy_setopt(curl
->handle
, CURLOPT_POSTFIELDSIZE
, body_size
);
2019 curl_easy_setopt(curl
->handle
, CURLOPT_POST
, 1L);
2021 curl_easy_setopt(curl
->handle
, CURLOPT_SEEKDATA
, NULL
);
2022 curl_easy_setopt(curl
->handle
, CURLOPT_READDATA
, NULL
);
2023 curl_easy_setopt(curl
->handle
, CURLOPT_INFILESIZE
, 0L);
2024 curl_easy_setopt(curl
->handle
, CURLOPT_POSTFIELDSIZE
, 0L);
2028 * Always use CUSTOMREQUEST, else curl won't send any request body for GET etc.
2029 * See e.g. bug #69313.
2031 * Here's what curl does:
2032 * - CURLOPT_HTTPGET: ignore request body
2033 * - CURLOPT_UPLOAD: set "Expect: 100-continue" header
2034 * - CURLOPT_POST: set "Content-Type: application/x-www-form-urlencoded" header
2035 * Now select the least bad.
2037 * See also https://tools.ietf.org/html/rfc7231#section-5.1.1
2039 if (PHP_HTTP_INFO(msg
).request
.method
) {
2040 switch(php_http_select_str(PHP_HTTP_INFO(msg
).request
.method
, 2, "HEAD", "PUT")) {
2042 curl_easy_setopt(curl
->handle
, CURLOPT_NOBODY
, 1L);
2045 curl_easy_setopt(curl
->handle
, CURLOPT_UPLOAD
, 1L);
2048 curl_easy_setopt(curl
->handle
, CURLOPT_CUSTOMREQUEST
, PHP_HTTP_INFO(msg
).request
.method
);
2051 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Cannot use empty request method");
2058 static void php_http_client_curl_handler_clear(php_http_client_curl_handler_t
*handler
)
2060 curl_easy_setopt(handler
->handle
, CURLOPT_NOPROGRESS
, 1L);
2061 #if PHP_HTTP_CURL_VERSION(7,32,0)
2062 curl_easy_setopt(handler
->handle
, CURLOPT_XFERINFOFUNCTION
, NULL
);
2064 curl_easy_setopt(handler
->handle
, CURLOPT_PROGRESSFUNCTION
, NULL
);
2066 curl_easy_setopt(handler
->handle
, CURLOPT_VERBOSE
, 0L);
2067 curl_easy_setopt(handler
->handle
, CURLOPT_DEBUGFUNCTION
, NULL
);
2068 curl_easy_setopt(handler
->handle
, CURLOPT_COOKIELIST
, "FLUSH");
2069 curl_easy_setopt(handler
->handle
, CURLOPT_SHARE
, NULL
);
2072 static void php_http_client_curl_handler_dtor(php_http_client_curl_handler_t
*handler
)
2074 TSRMLS_FETCH_FROM_CTX(handler
->client
->ts
);
2076 php_http_client_curl_handler_clear(handler
);
2078 php_resource_factory_handle_dtor(handler
->rf
, handler
->handle TSRMLS_CC
);
2079 php_resource_factory_free(&handler
->rf
);
2081 php_http_message_body_free(&handler
->response
.body
);
2082 php_http_buffer_dtor(&handler
->response
.headers
);
2083 php_http_buffer_dtor(&handler
->options
.ranges
);
2084 php_http_buffer_dtor(&handler
->options
.cookies
);
2085 zend_hash_destroy(&handler
->options
.cache
);
2087 if (handler
->options
.headers
) {
2088 curl_slist_free_all(handler
->options
.headers
);
2089 handler
->options
.headers
= NULL
;
2095 static php_http_client_t
*php_http_client_curl_init(php_http_client_t
*h
, void *handle
)
2097 php_http_client_curl_t
*curl
;
2098 TSRMLS_FETCH_FROM_CTX(h
->ts
);
2100 if (!handle
&& !(handle
= php_resource_factory_handle_ctor(h
->rf
, NULL TSRMLS_CC
))) {
2101 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to initialize curl handle->multi");
2105 curl
= ecalloc(1, sizeof(*curl
));
2106 curl
->handle
= handle
;
2107 curl
->unfinished
= 0;
2113 static void php_http_client_curl_dtor(php_http_client_t
*h
)
2115 php_http_client_curl_t
*curl
= h
->ctx
;
2116 TSRMLS_FETCH_FROM_CTX(h
->ts
);
2118 #if PHP_HTTP_HAVE_EVENT
2119 if (curl
->timeout
) {
2120 if (event_initialized(curl
->timeout
) && event_pending(curl
->timeout
, EV_TIMEOUT
, NULL
)) {
2121 event_del(curl
->timeout
);
2123 efree(curl
->timeout
);
2124 curl
->timeout
= NULL
;
2127 event_base_free(curl
->evbase
);
2128 curl
->evbase
= NULL
;
2131 curl
->unfinished
= 0;
2133 php_resource_factory_handle_dtor(h
->rf
, curl
->handle TSRMLS_CC
);
2139 static void queue_dtor(php_http_client_enqueue_t
*e
)
2141 php_http_client_curl_handler_t
*handler
= e
->opaque
;
2143 if (handler
->queue
.dtor
) {
2144 e
->opaque
= handler
->queue
.opaque
;
2145 handler
->queue
.dtor(e
);
2147 php_http_client_curl_handler_dtor(handler
);
2150 static php_resource_factory_t
*create_rf(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue TSRMLS_DC
)
2152 php_persistent_handle_factory_t
*pf
= NULL
;
2153 php_resource_factory_t
*rf
= NULL
;
2154 php_http_url_t
*url
= enqueue
->request
->http
.info
.request
.url
;
2156 if (!url
|| (!url
->host
&& !url
->path
)) {
2157 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Cannot request empty URL");
2161 /* only if the client itself is setup for persistence */
2162 if (php_resource_factory_is_persistent(h
->rf
)) {
2163 char *id_str
= NULL
;
2165 int port
= url
->port
? url
->port
: 80;
2167 php_persistent_handle_factory_t
*phf
= h
->rf
->data
;
2169 if (SUCCESS
== zend_hash_find(enqueue
->options
, ZEND_STRS("port"), (void *) &zport
)) {
2170 zval
*zcpy
= php_http_ztyp(IS_LONG
, *zport
);
2172 if (Z_LVAL_P(zcpy
)) {
2173 port
= Z_LVAL_P(zcpy
);
2175 zval_ptr_dtor(&zcpy
);
2178 id_len
= spprintf(&id_str
, 0, "%.*s:%s:%d", (int) phf
->ident
.len
, phf
->ident
.str
, STR_PTR(url
->host
), port
);
2179 pf
= php_persistent_handle_concede(NULL
, ZEND_STRL("http\\Client\\Curl\\Request"), id_str
, id_len
, NULL
, NULL TSRMLS_CC
);
2184 rf
= php_persistent_handle_resource_factory_init(NULL
, pf
);
2186 rf
= php_resource_factory_init(NULL
, &php_http_curle_resource_factory_ops
, NULL
, NULL
);
2192 static ZEND_RESULT_CODE
php_http_client_curl_enqueue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2195 php_http_client_curl_t
*curl
= h
->ctx
;
2196 php_http_client_curl_handler_t
*handler
;
2197 php_http_client_progress_state_t
*progress
;
2198 php_resource_factory_t
*rf
;
2199 TSRMLS_FETCH_FROM_CTX(h
->ts
);
2201 rf
= create_rf(h
, enqueue TSRMLS_CC
);
2206 handler
= php_http_client_curl_handler_init(h
, rf
);
2211 if (SUCCESS
!= php_http_client_curl_handler_prepare(handler
, enqueue
)) {
2212 php_http_client_curl_handler_dtor(handler
);
2216 handler
->queue
= *enqueue
;
2217 enqueue
->opaque
= handler
;
2218 enqueue
->dtor
= queue_dtor
;
2220 if (CURLM_OK
!= (rs
= curl_multi_add_handle(curl
->handle
->multi
, handler
->handle
))) {
2221 php_http_client_curl_handler_dtor(handler
);
2222 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not enqueue request: %s", curl_multi_strerror(rs
));
2226 zend_llist_add_element(&h
->requests
, enqueue
);
2229 if (h
->callback
.progress
.func
&& SUCCESS
== php_http_client_getopt(h
, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
, enqueue
->request
, &progress
)) {
2230 progress
->info
= "start";
2231 h
->callback
.progress
.func(h
->callback
.progress
.arg
, h
, &handler
->queue
, progress
);
2232 progress
->started
= 1;
2238 static ZEND_RESULT_CODE
php_http_client_curl_dequeue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2241 php_http_client_curl_t
*curl
= h
->ctx
;
2242 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2243 TSRMLS_FETCH_FROM_CTX(h
->ts
);
2245 php_http_client_curl_handler_clear(handler
);
2246 if (CURLM_OK
== (rs
= curl_multi_remove_handle(curl
->handle
->multi
, handler
->handle
))) {
2247 zend_llist_del_element(&h
->requests
, handler
->handle
, (int (*)(void *, void *)) compare_queue
);
2250 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not dequeue request: %s", curl_multi_strerror(rs
));
2256 static void php_http_client_curl_reset(php_http_client_t
*h
)
2258 zend_llist_element
*next_el
, *this_el
;
2260 for (this_el
= h
->requests
.head
; this_el
; this_el
= next_el
) {
2261 next_el
= this_el
->next
;
2262 php_http_client_curl_dequeue(h
, (void *) this_el
->data
);
2266 static inline void php_http_client_curl_get_timeout(php_http_client_curl_t
*curl
, long max_tout
, struct timeval
*timeout
)
2268 if ((CURLM_OK
== curl_multi_timeout(curl
->handle
->multi
, &max_tout
)) && (max_tout
> 0)) {
2269 timeout
->tv_sec
= max_tout
/ 1000;
2270 timeout
->tv_usec
= (max_tout
% 1000) * 1000;
2272 timeout
->tv_sec
= 0;
2273 timeout
->tv_usec
= 1000;
2278 # define SELECT_ERROR SOCKET_ERROR
2280 # define SELECT_ERROR -1
2283 static ZEND_RESULT_CODE
php_http_client_curl_wait(php_http_client_t
*h
, struct timeval
*custom_timeout
)
2287 struct timeval timeout
;
2288 php_http_client_curl_t
*curl
= h
->ctx
;
2290 #if PHP_HTTP_HAVE_EVENT
2291 if (curl
->useevents
) {
2292 if (!event_initialized(curl
->timeout
)) {
2293 event_assign(curl
->timeout
, curl
->evbase
, CURL_SOCKET_TIMEOUT
, 0, php_http_curlm_timeout_callback
, h
);
2294 } else if (custom_timeout
&& timerisset(custom_timeout
)) {
2295 event_add(curl
->timeout
, custom_timeout
);
2296 } else if (!event_pending(curl
->timeout
, EV_TIMEOUT
, NULL
)) {
2297 php_http_client_curl_get_timeout(curl
, 1000, &timeout
);
2298 event_add(curl
->timeout
, &timeout
);
2301 event_base_loop(curl
->evbase
, EVLOOP_ONCE
);
2311 if (CURLM_OK
== curl_multi_fdset(curl
->handle
->multi
, &R
, &W
, &E
, &MAX
)) {
2312 if (custom_timeout
&& timerisset(custom_timeout
)) {
2313 timeout
= *custom_timeout
;
2315 php_http_client_curl_get_timeout(curl
, 1000, &timeout
);
2319 php_http_sleep((double) timeout
.tv_sec
+ (double) (timeout
.tv_usec
/ PHP_HTTP_MCROSEC
));
2321 } else if (SELECT_ERROR
!= select(MAX
+ 1, &R
, &W
, &E
, &timeout
)) {
2328 static int php_http_client_curl_once(php_http_client_t
*h
)
2330 php_http_client_curl_t
*curl
= h
->ctx
;
2332 #if PHP_HTTP_HAVE_EVENT
2333 if (curl
->useevents
) {
2334 event_base_loop(curl
->evbase
, EVLOOP_NONBLOCK
);
2337 while (CURLM_CALL_MULTI_PERFORM
== curl_multi_perform(curl
->handle
->multi
, &curl
->unfinished
));
2339 php_http_curlm_responsehandler(h
);
2341 return curl
->unfinished
;
2345 static ZEND_RESULT_CODE
php_http_client_curl_exec(php_http_client_t
*h
)
2347 #if PHP_HTTP_HAVE_EVENT
2348 php_http_client_curl_t
*curl
= h
->ctx
;
2350 TSRMLS_FETCH_FROM_CTX(h
->ts
);
2352 #if PHP_HTTP_HAVE_EVENT
2353 if (curl
->useevents
) {
2354 php_http_curlm_timeout_callback(CURL_SOCKET_TIMEOUT
, /*EV_READ|EV_WRITE*/0, h
);
2356 int ev_rc
= event_base_dispatch(curl
->evbase
);
2359 fprintf(stderr
, "%c", "X.0"[ev_rc
+1]);
2363 php_error_docref(NULL TSRMLS_CC
, E_ERROR
, "Error in event_base_dispatch()");
2366 } while (curl
->unfinished
&& !EG(exception
));
2370 while (php_http_client_curl_once(h
) && !EG(exception
)) {
2371 if (SUCCESS
!= php_http_client_curl_wait(h
, NULL
)) {
2373 /* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */
2374 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "WinSock error: %d", WSAGetLastError());
2376 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "%s", strerror(errno
));
2386 static ZEND_RESULT_CODE
php_http_client_curl_setopt(php_http_client_t
*h
, php_http_client_setopt_opt_t opt
, void *arg
)
2388 php_http_client_curl_t
*curl
= h
->ctx
;
2391 case PHP_HTTP_CLIENT_OPT_CONFIGURATION
:
2392 return php_http_options_apply(&php_http_curlm_options
, (HashTable
*) arg
, h
);
2395 case PHP_HTTP_CLIENT_OPT_ENABLE_PIPELINING
:
2396 if (CURLM_OK
!= curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_PIPELINING
, (long) *((zend_bool
*) arg
))) {
2401 case PHP_HTTP_CLIENT_OPT_USE_EVENTS
:
2402 #if PHP_HTTP_HAVE_EVENT
2403 return php_http_curlm_use_eventloop(h
, *(zend_bool
*) arg
);
2413 static int apply_available_options(void *pDest TSRMLS_DC
, int num_args
, va_list args
, zend_hash_key
*hash_key
)
2415 php_http_option_t
*opt
= pDest
;
2420 ht
= va_arg(args
, HashTable
*);
2422 MAKE_STD_ZVAL(entry
);
2424 if ((c
= zend_hash_num_elements(&opt
->suboptions
.options
))) {
2425 array_init_size(entry
, c
);
2426 zend_hash_apply_with_arguments(&opt
->suboptions
.options TSRMLS_CC
, apply_available_options
, 1, Z_ARRVAL_P(entry
));
2428 /* catch deliberate NULL options */
2429 if (Z_TYPE(opt
->defval
) == IS_STRING
&& !Z_STRVAL(opt
->defval
)) {
2432 ZVAL_COPY_VALUE(entry
, &opt
->defval
);
2433 zval_copy_ctor(entry
);
2437 if (hash_key
->nKeyLength
) {
2438 zend_hash_quick_update(ht
, hash_key
->arKey
, hash_key
->nKeyLength
, hash_key
->h
, (void *) &entry
, sizeof(zval
*), NULL
);
2440 zend_hash_index_update(ht
, hash_key
->h
, (void *) &entry
, sizeof(zval
*), NULL
);
2443 return ZEND_HASH_APPLY_KEEP
;
2446 static ZEND_RESULT_CODE
php_http_client_curl_getopt(php_http_client_t
*h
, php_http_client_getopt_opt_t opt
, void *arg
, void **res
)
2448 php_http_client_enqueue_t
*enqueue
;
2449 TSRMLS_FETCH_FROM_CTX(h
->ts
);
2452 case PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
:
2453 if ((enqueue
= php_http_client_enqueued(h
, arg
, NULL
))) {
2454 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2456 *((php_http_client_progress_state_t
**) res
) = &handler
->progress
;
2461 case PHP_HTTP_CLIENT_OPT_TRANSFER_INFO
:
2462 if ((enqueue
= php_http_client_enqueued(h
, arg
, NULL
))) {
2463 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2465 php_http_curle_get_info(handler
->handle
, *(HashTable
**) res
);
2470 case PHP_HTTP_CLIENT_OPT_AVAILABLE_OPTIONS
:
2471 zend_hash_apply_with_arguments(&php_http_curle_options
.options TSRMLS_CC
, apply_available_options
, 1, *(HashTable
**) res
);
2474 case PHP_HTTP_CLIENT_OPT_AVAILABLE_CONFIGURATION
:
2475 zend_hash_apply_with_arguments(&php_http_curlm_options
.options TSRMLS_CC
, apply_available_options
, 1, *(HashTable
**) res
);
2485 static php_http_client_ops_t php_http_client_curl_ops
= {
2486 &php_http_curlm_resource_factory_ops
,
2487 php_http_client_curl_init
,
2489 php_http_client_curl_dtor
,
2490 php_http_client_curl_reset
,
2491 php_http_client_curl_exec
,
2492 php_http_client_curl_wait
,
2493 php_http_client_curl_once
,
2494 php_http_client_curl_enqueue
,
2495 php_http_client_curl_dequeue
,
2496 php_http_client_curl_setopt
,
2497 php_http_client_curl_getopt
2500 php_http_client_ops_t
*php_http_client_curl_get_ops(void)
2502 return &php_http_client_curl_ops
;
2505 PHP_MINIT_FUNCTION(http_client_curl
)
2507 curl_version_info_data
*info
;
2508 php_http_options_t
*options
;
2509 php_http_client_driver_t driver
= {
2511 &php_http_client_curl_ops
2514 if (SUCCESS
!= php_http_client_driver_add(&driver
)) {
2518 if (SUCCESS
!= php_persistent_handle_provide(ZEND_STRL("http\\Client\\Curl"), &php_http_curlm_resource_factory_ops
, NULL
, NULL TSRMLS_CC
)) {
2521 if (SUCCESS
!= php_persistent_handle_provide(ZEND_STRL("http\\Client\\Curl\\Request"), &php_http_curle_resource_factory_ops
, NULL
, NULL TSRMLS_CC
)) {
2525 if ((options
= php_http_options_init(&php_http_curle_options
, 1))) {
2526 options
->getter
= php_http_curle_get_option
;
2527 options
->setter
= php_http_curle_set_option
;
2529 php_http_curle_options_init(options TSRMLS_CC
);
2531 if ((options
= php_http_options_init(&php_http_curlm_options
, 1))) {
2532 options
->getter
= php_http_option_get
;
2533 options
->setter
= php_http_curlm_set_option
;
2535 php_http_curlm_options_init(options TSRMLS_CC
);
2538 if ((info
= curl_version_info(CURLVERSION_NOW
))) {
2542 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "FEATURES", info
->features
, CONST_CS
|CONST_PERSISTENT
);
2544 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "IPV6", CURL_VERSION_IPV6
, CONST_CS
|CONST_PERSISTENT
);
2545 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "KERBEROS4", CURL_VERSION_KERBEROS4
, CONST_CS
|CONST_PERSISTENT
);
2546 #if PHP_HTTP_CURL_VERSION(7,40,0)
2547 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "KERBEROS5", CURL_VERSION_KERBEROS5
, CONST_CS
|CONST_PERSISTENT
);
2549 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SSL", CURL_VERSION_SSL
, CONST_CS
|CONST_PERSISTENT
);
2550 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "LIBZ", CURL_VERSION_LIBZ
, CONST_CS
|CONST_PERSISTENT
);
2551 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "NTLM", CURL_VERSION_NTLM
, CONST_CS
|CONST_PERSISTENT
);
2552 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "GSSNEGOTIATE", CURL_VERSION_GSSNEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2553 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ASYNCHDNS", CURL_VERSION_ASYNCHDNS
, CONST_CS
|CONST_PERSISTENT
);
2554 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SPNEGO", CURL_VERSION_SPNEGO
, CONST_CS
|CONST_PERSISTENT
);
2555 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "LARGEFILE", CURL_VERSION_LARGEFILE
, CONST_CS
|CONST_PERSISTENT
);
2556 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "IDN", CURL_VERSION_IDN
, CONST_CS
|CONST_PERSISTENT
);
2557 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SSPI", CURL_VERSION_SSPI
, CONST_CS
|CONST_PERSISTENT
);
2558 #if PHP_HTTP_CURL_VERSION(7,38,0)
2559 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "GSSAPI", CURL_VERSION_GSSAPI
, CONST_CS
|CONST_PERSISTENT
);
2561 #if PHP_HTTP_CURL_VERSION(7,21,4)
2562 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "TLSAUTH_SRP", CURL_VERSION_TLSAUTH_SRP
, CONST_CS
|CONST_PERSISTENT
);
2564 #if PHP_HTTP_CURL_VERSION(7,22,0)
2565 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "NTLM_WB", CURL_VERSION_NTLM_WB
, CONST_CS
|CONST_PERSISTENT
);
2567 #if PHP_HTTP_CURL_VERSION(7,33,0)
2568 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTP2", CURL_VERSION_HTTP2
, CONST_CS
|CONST_PERSISTENT
);
2570 #if PHP_HTTP_CURL_VERSION(7,40,0)
2571 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "UNIX_SOCKETS", CURL_VERSION_UNIX_SOCKETS
, CONST_CS
|CONST_PERSISTENT
);
2573 #if PHP_HTTP_CURL_VERSION(7,47,0)
2574 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "PSL", CURL_VERSION_PSL
, CONST_CS
|CONST_PERSISTENT
);
2580 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl", "VERSIONS", curl_version(), CONST_CS
|CONST_PERSISTENT
);
2581 #if CURLVERSION_NOW >= 0
2582 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "CURL", (char *) info
->version
, CONST_CS
|CONST_PERSISTENT
);
2583 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "SSL", (char *) info
->ssl_version
, CONST_CS
|CONST_PERSISTENT
);
2584 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "LIBZ", (char *) info
->libz_version
, CONST_CS
|CONST_PERSISTENT
);
2585 # if CURLVERSION_NOW >= 1
2586 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "ARES", (char *) info
->ares
, CONST_CS
|CONST_PERSISTENT
);
2587 # if CURLVERSION_NOW >= 2
2588 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "IDN", (char *) info
->libidn
, CONST_CS
|CONST_PERSISTENT
);
2595 * HTTP Protocol Version Constants
2597 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_1_0", CURL_HTTP_VERSION_1_0
, CONST_CS
|CONST_PERSISTENT
);
2598 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_1_1", CURL_HTTP_VERSION_1_1
, CONST_CS
|CONST_PERSISTENT
);
2599 #if PHP_HTTP_CURL_VERSION(7,33,0)
2600 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2_0", CURL_HTTP_VERSION_2_0
, CONST_CS
|CONST_PERSISTENT
);
2602 #if PHP_HTTP_CURL_VERSION(7,47,0)
2603 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2TLS", CURL_HTTP_VERSION_2TLS
, CONST_CS
|CONST_PERSISTENT
);
2605 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_ANY", CURL_HTTP_VERSION_NONE
, CONST_CS
|CONST_PERSISTENT
);
2608 * SSL Version Constants
2610 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1", CURL_SSLVERSION_TLSv1
, CONST_CS
|CONST_PERSISTENT
);
2611 #if PHP_HTTP_CURL_VERSION(7,34,0)
2612 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_0", CURL_SSLVERSION_TLSv1_0
, CONST_CS
|CONST_PERSISTENT
);
2613 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_1", CURL_SSLVERSION_TLSv1_1
, CONST_CS
|CONST_PERSISTENT
);
2614 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_2", CURL_SSLVERSION_TLSv1_2
, CONST_CS
|CONST_PERSISTENT
);
2616 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv2", CURL_SSLVERSION_SSLv2
, CONST_CS
|CONST_PERSISTENT
);
2617 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv3", CURL_SSLVERSION_SSLv3
, CONST_CS
|CONST_PERSISTENT
);
2618 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_ANY", CURL_SSLVERSION_DEFAULT
, CONST_CS
|CONST_PERSISTENT
);
2619 #if PHP_HTTP_CURL_VERSION(7,21,4) && defined(PHP_HTTP_CURL_TLSAUTH_SRP)
2620 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "TLSAUTH_SRP", CURL_TLSAUTH_SRP
, CONST_CS
|CONST_PERSISTENT
);
2624 * DNS IPvX resolving
2626 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_V4", CURL_IPRESOLVE_V4
, CONST_CS
|CONST_PERSISTENT
);
2627 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_V6", CURL_IPRESOLVE_V6
, CONST_CS
|CONST_PERSISTENT
);
2628 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_ANY", CURL_IPRESOLVE_WHATEVER
, CONST_CS
|CONST_PERSISTENT
);
2633 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_BASIC", CURLAUTH_BASIC
, CONST_CS
|CONST_PERSISTENT
);
2634 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_DIGEST", CURLAUTH_DIGEST
, CONST_CS
|CONST_PERSISTENT
);
2635 #if PHP_HTTP_CURL_VERSION(7,19,3)
2636 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_DIGEST_IE", CURLAUTH_DIGEST_IE
, CONST_CS
|CONST_PERSISTENT
);
2638 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_NTLM", CURLAUTH_NTLM
, CONST_CS
|CONST_PERSISTENT
);
2639 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_GSSNEG", CURLAUTH_GSSNEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2640 #if PHP_HTTP_CURL_VERSION(7,38,0)
2641 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_SPNEGO", CURLAUTH_NEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2643 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_ANY", CURLAUTH_ANY
, CONST_CS
|CONST_PERSISTENT
);
2646 * Proxy Type Constants
2648 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS4", CURLPROXY_SOCKS4
, CONST_CS
|CONST_PERSISTENT
);
2649 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS4A", CURLPROXY_SOCKS5
, CONST_CS
|CONST_PERSISTENT
);
2650 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS5_HOSTNAME", CURLPROXY_SOCKS5
, CONST_CS
|CONST_PERSISTENT
);
2651 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS5", CURLPROXY_SOCKS5
, CONST_CS
|CONST_PERSISTENT
);
2652 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_HTTP", CURLPROXY_HTTP
, CONST_CS
|CONST_PERSISTENT
);
2653 #if PHP_HTTP_CURL_VERSION(7,19,4)
2654 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_HTTP_1_0", CURLPROXY_HTTP_1_0
, CONST_CS
|CONST_PERSISTENT
);
2658 * Post Redirection Constants
2660 #if PHP_HTTP_CURL_VERSION(7,19,1)
2661 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_301", CURL_REDIR_POST_301
, CONST_CS
|CONST_PERSISTENT
);
2662 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_302", CURL_REDIR_POST_302
, CONST_CS
|CONST_PERSISTENT
);
2663 #if PHP_HTTP_CURL_VERSION(7,26,0)
2664 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_303", CURL_REDIR_POST_303
, CONST_CS
|CONST_PERSISTENT
);
2666 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_ALL", CURL_REDIR_POST_ALL
, CONST_CS
|CONST_PERSISTENT
);
2672 PHP_MSHUTDOWN_FUNCTION(http_client_curl
)
2674 php_persistent_handle_cleanup(ZEND_STRL("http\\Client\\Curl"), NULL
, 0 TSRMLS_CC
);
2675 php_persistent_handle_cleanup(ZEND_STRL("http\\Client\\Curl\\Request"), NULL
, 0 TSRMLS_CC
);
2677 php_http_options_dtor(&php_http_curle_options
);
2678 php_http_options_dtor(&php_http_curlm_options
);
2683 #endif /* PHP_HTTP_HAVE_CURL */
2690 * vim600: noet sw=4 ts=4 fdm=marker
2691 * vim<600: noet sw=4 ts=4