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"
15 #include "php_http_client_curl_event.h"
16 #include "php_http_client_curl_user.h"
18 #if PHP_HTTP_HAVE_LIBCURL
20 #if PHP_HTTP_HAVE_LIBCURL_OPENSSL
21 # include <openssl/ssl.h>
23 #if PHP_HTTP_HAVE_LIBCURL_GNUTLS
24 # include <gnutls/gnutls.h>
27 typedef struct php_http_client_curl_handler
{
29 php_resource_factory_t
*rf
;
30 php_http_client_t
*client
;
31 php_http_client_progress_state_t progress
;
32 php_http_client_enqueue_t queue
;
35 php_http_buffer_t headers
;
36 php_http_message_body_t
*body
;
42 struct curl_slist
*proxyheaders
;
43 struct curl_slist
*headers
;
44 struct curl_slist
*resolve
;
45 php_http_buffer_t cookies
;
46 php_http_buffer_t ranges
;
54 unsigned range_request
:1;
55 unsigned encode_cookies
:1;
59 } php_http_client_curl_handler_t
;
61 typedef struct php_http_curle_storage
{
65 char errorbuffer
[0x100];
66 } php_http_curle_storage_t
;
68 static inline php_http_curle_storage_t
*php_http_curle_get_storage(CURL
*ch
) {
69 php_http_curle_storage_t
*st
= NULL
;
71 curl_easy_getinfo(ch
, CURLINFO_PRIVATE
, &st
);
74 st
= pecalloc(1, sizeof(*st
), 1);
75 curl_easy_setopt(ch
, CURLOPT_PRIVATE
, st
);
76 curl_easy_setopt(ch
, CURLOPT_ERRORBUFFER
, st
->errorbuffer
);
82 static void *php_http_curle_ctor(void *opaque
, void *init_arg
)
86 if ((ch
= curl_easy_init())) {
87 php_http_curle_get_storage(ch
);
93 static void *php_http_curle_copy(void *opaque
, void *handle
)
97 if ((ch
= curl_easy_duphandle(handle
))) {
99 php_http_curle_get_storage(ch
);
105 static void php_http_curle_dtor(void *opaque
, void *handle
)
107 php_http_curle_storage_t
*st
= php_http_curle_get_storage(handle
);
109 curl_easy_cleanup(handle
);
115 if (st
->cookiestore
) {
116 pefree(st
->cookiestore
, 1);
122 static php_resource_factory_ops_t php_http_curle_resource_factory_ops
= {
128 static void *php_http_curlm_ctor(void *opaque
, void *init_arg
)
130 php_http_client_curl_handle_t
*curl
= calloc(1, sizeof(*curl
));
132 if (!(curl
->multi
= curl_multi_init())) {
136 if (!(curl
->share
= curl_share_init())) {
137 curl_multi_cleanup(curl
->multi
);
141 curl_share_setopt(curl
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_COOKIE
);
142 curl_share_setopt(curl
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_SSL_SESSION
);
146 static void php_http_curlm_dtor(void *opaque
, void *handle
)
148 php_http_client_curl_handle_t
*curl
= handle
;
150 curl_share_cleanup(curl
->share
);
151 curl_multi_cleanup(curl
->multi
);
155 static php_resource_factory_ops_t php_http_curlm_resource_factory_ops
= {
163 static size_t php_http_curle_read_callback(void *data
, size_t len
, size_t n
, void *ctx
)
165 php_stream
*s
= php_http_message_body_stream(ctx
);
168 return php_stream_read(s
, data
, len
* n
);
173 #if PHP_HTTP_CURL_VERSION(7,32,0)
174 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
)
176 static int php_http_curle_progress_callback(void *ctx
, double dltotal
, double dlnow
, double ultotal
, double ulnow
)
179 php_http_client_curl_handler_t
*h
= ctx
;
181 if (h
->progress
.dl
.total
!= dltotal
182 || h
->progress
.dl
.now
!= dlnow
183 || h
->progress
.ul
.total
!= ultotal
184 || h
->progress
.ul
.now
!= ulnow
186 h
->progress
.dl
.total
= dltotal
;
187 h
->progress
.dl
.now
= dlnow
;
188 h
->progress
.ul
.total
= ultotal
;
189 h
->progress
.ul
.now
= ulnow
;
192 if (h
->client
->callback
.progress
.func
) {
193 h
->client
->callback
.progress
.func(h
->client
->callback
.progress
.arg
, h
->client
, &h
->queue
, &h
->progress
);
199 static int php_http_curle_seek_callback(void *userdata
, curl_off_t offset
, int origin
)
201 php_http_message_body_t
*body
= userdata
;
206 if (0 == php_stream_seek(php_http_message_body_stream(body
), offset
, origin
)) {
212 static int php_http_curle_raw_callback(CURL
*ch
, curl_infotype type
, char *data
, size_t length
, void *ctx
)
214 php_http_client_curl_handler_t
*h
= ctx
;
215 unsigned utype
= PHP_HTTP_CLIENT_DEBUG_INFO
;
220 if (data
[0] == '-') {
222 } else if (php_memnstr(data
, ZEND_STRL("Adding handle:"), data
+ length
)) {
223 h
->progress
.info
= "setup";
224 } else if (php_memnstr(data
, ZEND_STRL("addHandle"), data
+ length
)) {
225 h
->progress
.info
= "setup";
226 } else if (php_memnstr(data
, ZEND_STRL("About to connect"), data
+ length
)) {
227 h
->progress
.info
= "resolve";
228 } else if (php_memnstr(data
, ZEND_STRL("Trying"), data
+ length
)) {
229 h
->progress
.info
= "connect";
230 } else if (php_memnstr(data
, ZEND_STRL("Found bundle for host"), data
+ length
)) {
231 h
->progress
.info
= "connect";
232 } else if (php_memnstr(data
, ZEND_STRL("Connected"), data
+ length
)) {
233 h
->progress
.info
= "connected";
234 } else if (php_memnstr(data
, ZEND_STRL("Re-using existing connection!"), data
+ length
)) {
235 h
->progress
.info
= "connected";
236 } else if (php_memnstr(data
, ZEND_STRL("blacklisted"), data
+ length
)) {
237 h
->progress
.info
= "blacklist check";
238 } else if (php_memnstr(data
, ZEND_STRL("TLS"), data
+ length
)) {
239 h
->progress
.info
= "ssl negotiation";
240 } else if (php_memnstr(data
, ZEND_STRL("SSL"), data
+ length
)) {
241 h
->progress
.info
= "ssl negotiation";
242 } else if (php_memnstr(data
, ZEND_STRL("certificate"), data
+ length
)) {
243 h
->progress
.info
= "ssl negotiation";
244 } else if (php_memnstr(data
, ZEND_STRL("ALPN"), data
+ length
)) {
245 h
->progress
.info
= "alpn";
246 } else if (php_memnstr(data
, ZEND_STRL("NPN"), data
+ length
)) {
247 h
->progress
.info
= "npn";
248 } else if (php_memnstr(data
, ZEND_STRL("upload"), data
+ length
)) {
249 h
->progress
.info
= "uploaded";
250 } else if (php_memnstr(data
, ZEND_STRL("left intact"), data
+ length
)) {
251 h
->progress
.info
= "not disconnected";
252 } else if (php_memnstr(data
, ZEND_STRL("closed"), data
+ length
)) {
253 h
->progress
.info
= "disconnected";
254 } else if (php_memnstr(data
, ZEND_STRL("Issue another request"), data
+ length
)) {
255 h
->progress
.info
= "redirect";
256 } else if (php_memnstr(data
, ZEND_STRL("Operation timed out"), data
+ length
)) {
257 h
->progress
.info
= "timeout";
261 h
->progress
.info
= data
;
262 data
[length
- 1] = '\0';
265 if (h
->client
->callback
.progress
.func
) {
266 h
->client
->callback
.progress
.func(h
->client
->callback
.progress
.arg
, h
->client
, &h
->queue
, &h
->progress
);
270 case CURLINFO_HEADER_OUT
:
271 utype
|= PHP_HTTP_CLIENT_DEBUG_HEADER
;
274 case CURLINFO_SSL_DATA_OUT
:
275 utype
|= PHP_HTTP_CLIENT_DEBUG_SSL
;
278 case CURLINFO_DATA_OUT
:
280 utype
|= PHP_HTTP_CLIENT_DEBUG_OUT
;
281 h
->progress
.info
= "send";
284 case CURLINFO_HEADER_IN
:
285 utype
|= PHP_HTTP_CLIENT_DEBUG_HEADER
;
288 case CURLINFO_SSL_DATA_IN
:
289 utype
|= PHP_HTTP_CLIENT_DEBUG_SSL
;
292 case CURLINFO_DATA_IN
:
294 utype
|= PHP_HTTP_CLIENT_DEBUG_IN
;
295 h
->progress
.info
= "receive";
302 if (h
->client
->callback
.debug
.func
) {
303 h
->client
->callback
.debug
.func(h
->client
->callback
.debug
.arg
, h
->client
, &h
->queue
, utype
, data
, length
);
308 _dpf(type
, data
, length
);
314 static int php_http_curle_header_callback(char *data
, size_t n
, size_t l
, void *arg
)
316 php_http_client_curl_handler_t
*h
= arg
;
318 return php_http_buffer_append(&h
->response
.headers
, data
, n
* l
);
321 static int php_http_curle_body_callback(char *data
, size_t n
, size_t l
, void *arg
)
323 php_http_client_curl_handler_t
*h
= arg
;
325 return php_http_message_body_append(h
->response
.body
, data
, n
*l
);
328 static ZEND_RESULT_CODE
php_http_curle_get_info(CURL
*ch
, HashTable
*info
)
333 struct curl_slist
*s
= NULL
, *p
= NULL
;
338 /* BEGIN::CURLINFO */
339 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_EFFECTIVE_URL
, &c
)) {
340 ZVAL_STRING(&tmp
, STR_PTR(c
));
341 zend_hash_str_update(info
, "effective_url", lenof("effective_url"), &tmp
);
343 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_RESPONSE_CODE
, &l
)) {
345 zend_hash_str_update(info
, "response_code", lenof("response_code"), &tmp
);
347 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TOTAL_TIME
, &d
)) {
348 ZVAL_DOUBLE(&tmp
, d
);
349 zend_hash_str_update(info
, "total_time", lenof("total_time"), &tmp
);
351 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_NAMELOOKUP_TIME
, &d
)) {
352 ZVAL_DOUBLE(&tmp
, d
);
353 zend_hash_str_update(info
, "namelookup_time", lenof("namelookup_time"), &tmp
);
355 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONNECT_TIME
, &d
)) {
356 ZVAL_DOUBLE(&tmp
, d
);
357 zend_hash_str_update(info
, "connect_time", lenof("connect_time"), &tmp
);
359 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRETRANSFER_TIME
, &d
)) {
360 ZVAL_DOUBLE(&tmp
, d
);
361 zend_hash_str_update(info
, "pretransfer_time", lenof("pretransfer_time"), &tmp
);
363 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SIZE_UPLOAD
, &d
)) {
364 ZVAL_DOUBLE(&tmp
, d
);
365 zend_hash_str_update(info
, "size_upload", lenof("size_upload"), &tmp
);
367 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SIZE_DOWNLOAD
, &d
)) {
368 ZVAL_DOUBLE(&tmp
, d
);
369 zend_hash_str_update(info
, "size_download", lenof("size_download"), &tmp
);
371 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_DOWNLOAD
, &d
)) {
372 ZVAL_DOUBLE(&tmp
, d
);
373 zend_hash_str_update(info
, "speed_download", lenof("speed_download"), &tmp
);
375 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_UPLOAD
, &d
)) {
376 ZVAL_DOUBLE(&tmp
, d
);
377 zend_hash_str_update(info
, "speed_upload", lenof("speed_upload"), &tmp
);
379 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HEADER_SIZE
, &l
)) {
381 zend_hash_str_update(info
, "header_size", lenof("header_size"), &tmp
);
383 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REQUEST_SIZE
, &l
)) {
385 zend_hash_str_update(info
, "request_size", lenof("request_size"), &tmp
);
387 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SSL_VERIFYRESULT
, &l
)) {
389 zend_hash_str_update(info
, "ssl_verifyresult", lenof("ssl_verifyresult"), &tmp
);
391 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_FILETIME
, &l
)) {
393 zend_hash_str_update(info
, "filetime", lenof("filetime"), &tmp
);
395 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_DOWNLOAD
, &d
)) {
396 ZVAL_DOUBLE(&tmp
, d
);
397 zend_hash_str_update(info
, "content_length_download", lenof("content_length_download"), &tmp
);
399 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_UPLOAD
, &d
)) {
400 ZVAL_DOUBLE(&tmp
, d
);
401 zend_hash_str_update(info
, "content_length_upload", lenof("content_length_upload"), &tmp
);
403 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_STARTTRANSFER_TIME
, &d
)) {
404 ZVAL_DOUBLE(&tmp
, d
);
405 zend_hash_str_update(info
, "starttransfer_time", lenof("starttransfer_time"), &tmp
);
407 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_TYPE
, &c
)) {
408 ZVAL_STRING(&tmp
, STR_PTR(c
));
409 zend_hash_str_update(info
, "content_type", lenof("content_type"), &tmp
);
411 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_TIME
, &d
)) {
412 ZVAL_DOUBLE(&tmp
, d
);
413 zend_hash_str_update(info
, "redirect_time", lenof("redirect_time"), &tmp
);
415 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_COUNT
, &l
)) {
417 zend_hash_str_update(info
, "redirect_count", lenof("redirect_count"), &tmp
);
419 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTP_CONNECTCODE
, &l
)) {
421 zend_hash_str_update(info
, "connect_code", lenof("connect_code"), &tmp
);
423 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTPAUTH_AVAIL
, &l
)) {
425 zend_hash_str_update(info
, "httpauth_avail", lenof("httpauth_avail"), &tmp
);
427 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXYAUTH_AVAIL
, &l
)) {
429 zend_hash_str_update(info
, "proxyauth_avail", lenof("proxyauth_avail"), &tmp
);
431 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_OS_ERRNO
, &l
)) {
433 zend_hash_str_update(info
, "os_errno", lenof("os_errno"), &tmp
);
435 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_NUM_CONNECTS
, &l
)) {
437 zend_hash_str_update(info
, "num_connects", lenof("num_connects"), &tmp
);
439 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SSL_ENGINES
, &s
)) {
441 for (p
= s
; p
; p
= p
->next
) {
443 add_next_index_string(&tmp
, p
->data
);
446 zend_hash_str_update(info
, "ssl_engines", lenof("ssl_engines"), &tmp
);
447 curl_slist_free_all(s
);
449 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_URL
, &c
)) {
450 ZVAL_STRING(&tmp
, STR_PTR(c
));
451 zend_hash_str_update(info
, "redirect_url", lenof("redirect_url"), &tmp
);
453 #if PHP_HTTP_CURL_VERSION(7,19,0)
454 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRIMARY_IP
, &c
)) {
455 ZVAL_STRING(&tmp
, STR_PTR(c
));
456 zend_hash_str_update(info
, "primary_ip", lenof("primary_ip"), &tmp
);
459 #if PHP_HTTP_CURL_VERSION(7,19,0)
460 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_APPCONNECT_TIME
, &d
)) {
461 ZVAL_DOUBLE(&tmp
, d
);
462 zend_hash_str_update(info
, "appconnect_time", lenof("appconnect_time"), &tmp
);
465 #if PHP_HTTP_CURL_VERSION(7,19,4)
466 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONDITION_UNMET
, &l
)) {
468 zend_hash_str_update(info
, "condition_unmet", lenof("condition_unmet"), &tmp
);
471 #if PHP_HTTP_CURL_VERSION(7,21,0)
472 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRIMARY_PORT
, &l
)) {
474 zend_hash_str_update(info
, "primary_port", lenof("primary_port"), &tmp
);
477 #if PHP_HTTP_CURL_VERSION(7,21,0)
478 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_LOCAL_IP
, &c
)) {
479 ZVAL_STRING(&tmp
, STR_PTR(c
));
480 zend_hash_str_update(info
, "local_ip", lenof("local_ip"), &tmp
);
483 #if PHP_HTTP_CURL_VERSION(7,21,0)
484 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_LOCAL_PORT
, &l
)) {
486 zend_hash_str_update(info
, "local_port", lenof("local_port"), &tmp
);
489 #if PHP_HTTP_CURL_VERSION(7,50,0)
490 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTP_VERSION
, &l
)) {
492 zend_hash_str_update(info
, "http_version", lenof("http_version"), &tmp
);
495 #if PHP_HTTP_CURL_VERSION(7,52,0)
496 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXY_SSL_VERIFYRESULT
, &l
)) {
498 zend_hash_str_update(info
, "proxy_ssl_verifyresult", lenof("proxy_ssl_verifyresult"), &tmp
);
501 #if PHP_HTTP_CURL_VERSION(7,52,0)
502 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROTOCOL
, &l
)) {
504 zend_hash_str_update(info
, "protocol", lenof("protocol"), &tmp
);
507 #if PHP_HTTP_CURL_VERSION(7,52,0)
508 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SCHEME
, &c
)) {
509 ZVAL_STRING(&tmp
, STR_PTR(c
));
510 zend_hash_str_update(info
, "scheme", lenof("scheme"), &tmp
);
513 #if PHP_HTTP_CURL_VERSION(7,72,0)
514 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_EFFECTIVE_METHOD
, &c
)) {
515 ZVAL_STRING(&tmp
, STR_PTR(c
));
516 zend_hash_str_update(info
, "effective_method", lenof("effective_method"), &tmp
);
519 #if PHP_HTTP_CURL_VERSION(7,73,0)
520 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXY_ERROR
, &l
)) {
522 zend_hash_str_update(info
, "proxy_error", lenof("proxy_error"), &tmp
);
528 #if PHP_HTTP_CURL_VERSION(7,34,0)
530 zval ti_array
, subarray
;
531 struct curl_tlssessioninfo
*ti
;
533 #if PHP_HTTP_CURL_VERSION(7,48,0)
534 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TLS_SSL_PTR
, &ti
)) {
536 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TLS_SESSION
, &ti
)) {
540 ZVAL_NULL(&subarray
);
541 array_init(&ti_array
);
543 switch (ti
->backend
) {
544 case CURLSSLBACKEND_NONE
:
547 case CURLSSLBACKEND_OPENSSL
:
549 #if PHP_HTTP_HAVE_LIBCURL_OPENSSL
551 #if PHP_HTTP_CURL_VERSION(7,48,0)
552 SSL
*ssl
= ti
->internals
;
553 SSL_CTX
*ctx
= ssl
? SSL_get_SSL_CTX(ssl
) : NULL
;
555 SSL_CTX
*ctx
= ti
->internals
;
558 array_init(&subarray
);
560 add_assoc_long_ex(&subarray
, ZEND_STRL("number"), SSL_CTX_sess_number(ctx
));
561 add_assoc_long_ex(&subarray
, ZEND_STRL("connect"), SSL_CTX_sess_connect(ctx
));
562 add_assoc_long_ex(&subarray
, ZEND_STRL("connect_good"), SSL_CTX_sess_connect_good(ctx
));
563 add_assoc_long_ex(&subarray
, ZEND_STRL("connect_renegotiate"), SSL_CTX_sess_connect_renegotiate(ctx
));
564 add_assoc_long_ex(&subarray
, ZEND_STRL("hits"), SSL_CTX_sess_hits(ctx
));
565 add_assoc_long_ex(&subarray
, ZEND_STRL("cache_full"), SSL_CTX_sess_cache_full(ctx
));
570 case CURLSSLBACKEND_GNUTLS
:
572 #if PHP_HTTP_HAVE_LIBCURL_GNUTLS
574 gnutls_session_t sess
= ti
->internals
;
577 array_init(&subarray
);
579 if ((desc
= gnutls_session_get_desc(sess
))) {
580 add_assoc_string_ex(&subarray
, ZEND_STRL("desc"), desc
);
583 add_assoc_bool_ex(&subarray
, ZEND_STRL("resumed"), gnutls_session_is_resumed(sess
));
588 case CURLSSLBACKEND_NSS
:
591 #if !PHP_HTTP_CURL_VERSION(7,39,0)
592 case CURLSSLBACKEND_QSOSSL
:
596 case CURLSSLBACKEND_GSKIT
:
600 case CURLSSLBACKEND_POLARSSL
:
601 backend
= "polarssl";
603 case CURLSSLBACKEND_CYASSL
:
606 case CURLSSLBACKEND_SCHANNEL
:
607 backend
= "schannel";
609 case CURLSSLBACKEND_DARWINSSL
:
610 backend
= "darwinssl";
615 add_assoc_string_ex(&ti_array
, ZEND_STRL("backend"), backend
);
616 add_assoc_zval_ex(&ti_array
, ZEND_STRL("internals"), &subarray
);
617 zend_hash_str_update(info
, "tls_session", lenof("tls_session"), &ti_array
);
622 #if (PHP_HTTP_CURL_VERSION(7,19,1) && PHP_HTTP_HAVE_LIBCURL_OPENSSL) || \
623 (PHP_HTTP_CURL_VERSION(7,34,0) && PHP_HTTP_HAVE_LIBCURL_NSS) || \
624 (PHP_HTTP_CURL_VERSION(7,42,0) && PHP_HTTP_HAVE_LIBCURL_GNUTLS) || \
625 (PHP_HTTP_CURL_VERSION(7,39,0) && PHP_HTTP_HAVE_LIBCURL_GSKIT)
628 zval ci_array
, subarray
;
629 struct curl_certinfo
*ci
;
630 char *colon
, *keyname
;
632 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CERTINFO
, &ci
)) {
633 array_init(&ci_array
);
635 for (i
= 0; i
< ci
->num_of_certs
; ++i
) {
638 array_init(&subarray
);
639 for (p
= s
; p
; p
= p
->next
) {
641 if ((colon
= strchr(p
->data
, ':'))) {
642 keyname
= estrndup(p
->data
, colon
- p
->data
);
643 add_assoc_string_ex(&subarray
, keyname
, colon
- p
->data
, colon
+ 1);
646 add_next_index_string(&subarray
, p
->data
);
650 add_next_index_zval(&ci_array
, &subarray
);
652 zend_hash_str_update(info
, "certinfo", lenof("certinfo"), &ci_array
);
657 php_http_curle_storage_t
*st
= php_http_curle_get_storage(ch
);
659 ZVAL_LONG(&tmp
, st
->errorcode
);
660 zend_hash_str_update(info
, "curlcode", lenof("curlcode"), &tmp
);
661 ZVAL_STRING(&tmp
, st
->errorbuffer
);
662 zend_hash_str_update(info
, "error", lenof("error"), &tmp
);
668 static int compare_queue(php_http_client_enqueue_t
*e
, void *handle
)
670 return handle
== ((php_http_client_curl_handler_t
*) e
->opaque
)->handle
;
673 static php_http_message_t
*php_http_curlm_responseparser(php_http_client_curl_handler_t
*h
)
675 php_http_message_t
*response
;
676 php_http_header_parser_t parser
;
679 response
= php_http_message_init(NULL
, 0, h
->response
.body
);
680 php_http_header_parser_init(&parser
);
681 while (h
->response
.headers
.used
) {
682 php_http_header_parser_state_t st
= php_http_header_parser_parse(&parser
,
683 &h
->response
.headers
, PHP_HTTP_HEADER_PARSER_CLEANUP
, &response
->hdrs
,
684 (php_http_info_callback_t
) php_http_message_info_callback
, (void *) &response
);
685 if (PHP_HTTP_HEADER_PARSER_STATE_FAILURE
== st
) {
689 php_http_header_parser_dtor(&parser
);
691 /* move body to right message */
692 if (response
->body
!= h
->response
.body
) {
693 php_http_message_t
*ptr
= response
;
695 while (ptr
->parent
) {
698 php_http_message_body_free(&response
->body
);
699 response
->body
= ptr
->body
;
702 php_http_message_body_addref(h
->response
.body
);
704 /* let's update the response headers */
705 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Length")))) {
707 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Length", lenof("X-Original-Content-Length"), &tmp
);
709 if ((zh
= php_http_message_header(response
, ZEND_STRL("Transfer-Encoding")))) {
711 zend_hash_str_del(&response
->hdrs
, "Transfer-Encoding", lenof("Transfer-Encoding"));
712 zend_hash_str_update(&response
->hdrs
, "X-Original-Transfer-Encoding", lenof("X-Original-Transfer-Encoding"), &tmp
);
714 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Range")))) {
716 zend_hash_str_del(&response
->hdrs
, "Content-Range", lenof("Content-Range"));
717 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Range", lenof("X-Original-Content-Range"), &tmp
);
719 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Encoding")))) {
721 zend_hash_str_del(&response
->hdrs
, "Content-Encoding", lenof("Content-Encoding"));
722 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Encoding", lenof("X-Original-Content-Encoding"), &tmp
);
724 php_http_message_update_headers(response
);
729 void php_http_client_curl_responsehandler(php_http_client_t
*context
)
731 int err_count
= 0, remaining
= 0;
732 php_http_curle_storage_t
*st
, *err
= NULL
;
733 php_http_client_enqueue_t
*enqueue
;
734 php_http_client_curl_t
*curl
= context
->ctx
;
737 CURLMsg
*msg
= curl_multi_info_read(curl
->handle
->multi
, &remaining
);
739 if (msg
&& CURLMSG_DONE
== msg
->msg
) {
740 if (CURLE_OK
!= msg
->data
.result
) {
741 st
= php_http_curle_get_storage(msg
->easy_handle
);
742 st
->errorcode
= msg
->data
.result
;
744 /* defer the warnings/exceptions, so the callback is still called for this request */
746 err
= ecalloc(remaining
+ 1, sizeof(*err
));
748 memcpy(&err
[err_count
], st
, sizeof(*st
));
750 err
[err_count
].url
= estrdup(st
->url
);
755 if ((enqueue
= php_http_client_enqueued(context
, msg
->easy_handle
, compare_queue
))) {
756 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
757 php_http_message_t
*response
= php_http_curlm_responseparser(handler
);
760 context
->callback
.response
.func(context
->callback
.response
.arg
, context
, &handler
->queue
, &response
);
761 php_http_message_free(&response
);
771 php_error_docref(NULL
, E_WARNING
, "%s; %s (%s)", curl_easy_strerror(err
[i
].errorcode
), err
[i
].errorbuffer
, STR_PTR(err
[i
].url
));
775 } while (++i
< err_count
);
781 void php_http_client_curl_loop(php_http_client_t
*client
, curl_socket_t s
, int curl_action
)
784 php_http_client_curl_t
*curl
= client
->ctx
;
787 fprintf(stderr
, "H");
791 rc
= curl_multi_socket_action(curl
->handle
->multi
, s
, curl_action
, &curl
->unfinished
);
792 } while (CURLM_CALL_MULTI_PERFORM
== rc
);
794 if (CURLM_OK
!= rc
) {
795 php_error_docref(NULL
, E_WARNING
, "%s", curl_multi_strerror(rc
));
798 php_http_client_curl_responsehandler(client
);
803 static php_http_options_t php_http_curle_options
, php_http_curlm_options
;
805 #define PHP_HTTP_CURLE_OPTION_CHECK_STRLEN 0x0001
806 #define PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR 0x0002
807 #define PHP_HTTP_CURLE_OPTION_TRANSFORM_MS 0x0004
809 static ZEND_RESULT_CODE
php_http_curle_option_set_ssl_verifyhost(php_http_option_t
*opt
, zval
*val
, void *userdata
)
811 php_http_client_curl_handler_t
*curl
= userdata
;
812 CURL
*ch
= curl
->handle
;
814 if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, Z_TYPE_P(val
) == IS_TRUE
? 2 : 0)) {
820 static ZEND_RESULT_CODE
php_http_curle_option_set_cookiesession(php_http_option_t
*opt
, zval
*val
, void *userdata
)
822 php_http_client_curl_handler_t
*curl
= userdata
;
823 CURL
*ch
= curl
->handle
;
825 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIESESSION
, (long) (Z_TYPE_P(val
) == IS_TRUE
))) {
828 if (Z_TYPE_P(val
) == IS_TRUE
) {
829 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIELIST
, "SESS")) {
837 static ZEND_RESULT_CODE
php_http_curle_option_set_cookiestore(php_http_option_t
*opt
, zval
*val
, void *userdata
)
839 php_http_client_curl_handler_t
*curl
= userdata
;
840 CURL
*ch
= curl
->handle
;
841 php_http_curle_storage_t
*storage
= php_http_curle_get_storage(curl
->handle
);
843 if (storage
->cookiestore
) {
844 pefree(storage
->cookiestore
, 1);
846 if (val
&& Z_TYPE_P(val
) == IS_STRING
&& Z_STRLEN_P(val
)) {
847 storage
->cookiestore
= pestrndup(Z_STRVAL_P(val
), Z_STRLEN_P(val
), 1);
849 storage
->cookiestore
= NULL
;
851 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIEFILE
, storage
->cookiestore
)
852 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIEJAR
, storage
->cookiestore
)
860 static ZEND_RESULT_CODE
php_http_curle_option_set_cookies(php_http_option_t
*opt
, zval
*val
, void *userdata
)
862 php_http_client_curl_handler_t
*curl
= userdata
;
863 CURL
*ch
= curl
->handle
;
865 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
866 HashTable
*ht
= HASH_OF(val
);
868 if (curl
->options
.encode_cookies
) {
869 if (SUCCESS
== php_http_url_encode_hash_ex(ht
, &curl
->options
.cookies
, ZEND_STRL(";"), ZEND_STRL("="), NULL
, 0)) {
870 php_http_buffer_fix(&curl
->options
.cookies
);
871 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, curl
->options
.cookies
.data
)) {
878 php_http_arrkey_t cookie_key
;
881 ZEND_HASH_FOREACH_KEY_VAL(ht
, cookie_key
.h
, cookie_key
.key
, cookie_val
)
883 zend_string
*zs
= zval_get_string(cookie_val
);
885 php_http_arrkey_stringify(&cookie_key
, NULL
);
886 php_http_buffer_appendf(&curl
->options
.cookies
, "%s=%s; ", cookie_key
.key
->val
, zs
->val
);
887 php_http_arrkey_dtor(&cookie_key
);
889 zend_string_release(zs
);
891 ZEND_HASH_FOREACH_END();
893 php_http_buffer_fix(&curl
->options
.cookies
);
894 if (curl
->options
.cookies
.used
) {
895 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, curl
->options
.cookies
.data
)) {
901 php_http_buffer_reset(&curl
->options
.cookies
);
902 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, NULL
)) {
909 static ZEND_RESULT_CODE
php_http_curle_option_set_encodecookies(php_http_option_t
*opt
, zval
*val
, void *userdata
)
911 php_http_client_curl_handler_t
*curl
= userdata
;
913 curl
->options
.encode_cookies
= Z_TYPE_P(val
) == IS_TRUE
;
917 static ZEND_RESULT_CODE
php_http_curle_option_set_lastmodified(php_http_option_t
*opt
, zval
*val
, void *userdata
)
919 php_http_client_curl_handler_t
*curl
= userdata
;
920 CURL
*ch
= curl
->handle
;
923 if (Z_LVAL_P(val
) > 0) {
924 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, Z_LVAL_P(val
))) {
928 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, (long) sapi_get_request_time() + Z_LVAL_P(val
))) {
932 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMECONDITION
, (long) (curl
->options
.range_request
? CURL_TIMECOND_IFUNMODSINCE
: CURL_TIMECOND_IFMODSINCE
))) {
936 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, 0)
937 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMECONDITION
, 0)
945 #if PHP_HTTP_CURL_VERSION(7,64,1)
946 static ZEND_RESULT_CODE
php_http_curle_option_set_altsvc_ctrl(php_http_option_t
*opt
, zval
*val
, void *userdata
)
948 php_http_client_curl_handler_t
*curl
= userdata
;
949 CURL
*ch
= curl
->handle
;
952 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_ALTSVC_CTRL
, Z_LVAL_P(val
))) {
960 static ZEND_RESULT_CODE
php_http_curle_option_set_compress(php_http_option_t
*opt
, zval
*val
, void *userdata
)
962 php_http_client_curl_handler_t
*curl
= userdata
;
963 CURL
*ch
= curl
->handle
;
965 #if !PHP_HTTP_CURL_VERSION(7,21,6)
966 # define CURLOPT_ACCEPT_ENCODING CURLOPT_ENCODING
968 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_ACCEPT_ENCODING
, Z_TYPE_P(val
) == IS_TRUE
? "" : NULL
)) {
974 static ZEND_RESULT_CODE
php_http_curle_option_set_etag(php_http_option_t
*opt
, zval
*val
, void *userdata
)
976 php_http_client_curl_handler_t
*curl
= userdata
;
977 php_http_buffer_t header
;
979 if (val
&& Z_TYPE_P(val
) == IS_STRING
&& Z_STRLEN_P(val
)) {
980 zend_bool is_quoted
= !((Z_STRVAL_P(val
)[0] != '"') || (Z_STRVAL_P(val
)[Z_STRLEN_P(val
)-1] != '"'));
981 php_http_buffer_init(&header
);
982 php_http_buffer_appendf(&header
, is_quoted
?"%s: %s":"%s: \"%s\"", curl
->options
.range_request
?"If-Match":"If-None-Match", Z_STRVAL_P(val
));
983 php_http_buffer_fix(&header
);
984 curl
->options
.headers
= curl_slist_append(curl
->options
.headers
, header
.data
);
985 php_http_buffer_dtor(&header
);
990 static ZEND_RESULT_CODE
php_http_curle_option_set_range(php_http_option_t
*opt
, zval
*val
, void *userdata
)
992 php_http_client_curl_handler_t
*curl
= userdata
;
993 CURL
*ch
= curl
->handle
;
995 php_http_buffer_reset(&curl
->options
.ranges
);
997 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
999 HashTable
*ht
= HASH_OF(val
);
1001 ZEND_HASH_FOREACH_VAL(ht
, rr
)
1003 if (Z_TYPE_P(rr
) == IS_ARRAY
) {
1004 if (2 == php_http_array_list(Z_ARRVAL_P(rr
), 2, &rb
, &re
)) {
1005 zend_long rbl
= zval_get_long(rb
), rel
= zval_get_long(re
);
1009 php_http_buffer_appendf(&curl
->options
.ranges
, "%ld-%ld,", rbl
, rel
);
1011 php_http_buffer_appendf(&curl
->options
.ranges
, "%ld-", rbl
);
1013 } else if (rel
> 0) {
1014 php_http_buffer_appendf(&curl
->options
.ranges
, "-%ld", rel
);
1019 ZEND_HASH_FOREACH_END();
1021 if (curl
->options
.ranges
.used
) {
1022 curl
->options
.range_request
= 1;
1023 /* ditch last comma */
1024 curl
->options
.ranges
.data
[curl
->options
.ranges
.used
- 1] = '\0';
1028 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RANGE
, curl
->options
.ranges
.data
)) {
1034 static ZEND_RESULT_CODE
php_http_curle_option_set_resume(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1036 php_http_client_curl_handler_t
*curl
= userdata
;
1037 CURL
*ch
= curl
->handle
;
1039 if (Z_LVAL_P(val
) > 0) {
1040 curl
->options
.range_request
= 1;
1042 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESUME_FROM
, Z_LVAL_P(val
))) {
1048 static ZEND_RESULT_CODE
php_http_curle_option_set_retrydelay(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1050 php_http_client_curl_handler_t
*curl
= userdata
;
1052 curl
->options
.retry
.delay
= Z_DVAL_P(val
);
1056 static ZEND_RESULT_CODE
php_http_curle_option_set_retrycount(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1058 php_http_client_curl_handler_t
*curl
= userdata
;
1060 curl
->options
.retry
.count
= Z_LVAL_P(val
);
1064 static ZEND_RESULT_CODE
php_http_curle_option_set_redirect(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1066 php_http_client_curl_handler_t
*curl
= userdata
;
1067 CURL
*ch
= curl
->handle
;
1069 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, Z_LVAL_P(val
) ? 1L : 0L)
1070 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_MAXREDIRS
, curl
->options
.redirects
= Z_LVAL_P(val
))
1077 static ZEND_RESULT_CODE
php_http_curle_option_set_portrange(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1079 php_http_client_curl_handler_t
*curl
= userdata
;
1080 CURL
*ch
= curl
->handle
;
1081 long localport
= 0, localportrange
= 0;
1083 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1086 switch (php_http_array_list(Z_ARRVAL_P(val
), 2, &zps
, &zpe
)) {
1088 localportrange
= labs(zval_get_long(zps
)-zval_get_long(zpe
))+1L;
1091 localport
= (zval_get_long(zpe
) > 0) ? MIN(zval_get_long(zps
), zval_get_long(zpe
)) : zval_get_long(zps
);
1097 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_LOCALPORT
, localport
)
1098 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_LOCALPORTRANGE
, localportrange
)
1105 #if PHP_HTTP_CURL_VERSION(7,37,0)
1106 static ZEND_RESULT_CODE
php_http_curle_option_set_proxyheader(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1108 php_http_client_curl_handler_t
*curl
= userdata
;
1110 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1111 php_http_arrkey_t header_key
;
1113 php_http_buffer_t header
;
1115 php_http_buffer_init(&header
);
1116 ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(val
), header_key
.h
, header_key
.key
, header_val
)
1118 if (header_key
.key
) {
1119 zend_string
*zs
= zval_get_string(header_val
);
1121 php_http_buffer_appendf(&header
, "%s: %s", header_key
.key
->val
, zs
->val
);
1122 zend_string_release(zs
);
1124 php_http_buffer_fix(&header
);
1125 curl
->options
.proxyheaders
= curl_slist_append(curl
->options
.proxyheaders
, header
.data
);
1126 php_http_buffer_reset(&header
);
1130 ZEND_HASH_FOREACH_END();
1131 php_http_buffer_dtor(&header
);
1133 if (CURLE_OK
!= curl_easy_setopt(curl
->handle
, CURLOPT_PROXYHEADER
, curl
->options
.proxyheaders
)) {
1136 if (CURLE_OK
!= curl_easy_setopt(curl
->handle
, CURLOPT_HEADEROPT
, CURLHEADER_SEPARATE
)) {
1137 curl_easy_setopt(curl
->handle
, CURLOPT_PROXYHEADER
, NULL
);
1144 #if PHP_HTTP_CURL_VERSION(7,21,3)
1145 static ZEND_RESULT_CODE
php_http_curle_option_set_resolve(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1147 php_http_client_curl_handler_t
*curl
= userdata
;
1148 CURL
*ch
= curl
->handle
;
1150 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1151 HashTable
*ht
= HASH_OF(val
);
1154 ZEND_HASH_FOREACH_VAL(ht
, data
)
1156 zend_string
*zs
= zval_get_string(data
);
1157 curl
->options
.resolve
= curl_slist_append(curl
->options
.resolve
, zs
->val
);
1158 zend_string_release(zs
);
1160 ZEND_HASH_FOREACH_END();
1162 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESOLVE
, curl
->options
.resolve
)) {
1166 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESOLVE
, NULL
)) {
1174 #if PHP_HTTP_CURL_VERSION(7,21,4) && PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
1175 static ZEND_RESULT_CODE
php_http_curle_option_set_ssl_tlsauthtype(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1177 php_http_client_curl_handler_t
*curl
= userdata
;
1178 CURL
*ch
= curl
->handle
;
1180 if (val
&& Z_LVAL_P(val
)) {
1181 switch (Z_LVAL_P(val
)) {
1182 case CURL_TLSAUTH_SRP
:
1183 if (CURLE_OK
== curl_easy_setopt(ch
, opt
->option
, PHP_HTTP_LIBCURL_TLSAUTH_SRP
)) {
1191 if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, PHP_HTTP_LIBCURL_TLSAUTH_DEF
)) {
1198 static void php_http_curle_options_init(php_http_options_t
*registry
)
1200 php_http_option_t
*opt
;
1203 #if PHP_HTTP_CURL_VERSION(7,42,0)
1204 php_http_option_register(registry
, ZEND_STRL("path_as_is"), CURLOPT_PATH_AS_IS
, _IS_BOOL
);
1208 php_http_option_register(registry
, ZEND_STRL("proxyhost"), CURLOPT_PROXY
, IS_STRING
);
1209 php_http_option_register(registry
, ZEND_STRL("proxytype"), CURLOPT_PROXYTYPE
, IS_LONG
);
1210 php_http_option_register(registry
, ZEND_STRL("proxyport"), CURLOPT_PROXYPORT
, IS_LONG
);
1211 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyauth"), CURLOPT_PROXYUSERPWD
, IS_STRING
))) {
1212 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1214 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyauthtype"), CURLOPT_PROXYAUTH
, IS_LONG
))) {
1215 Z_LVAL(opt
->defval
) = CURLAUTH_ANYSAFE
;
1217 php_http_option_register(registry
, ZEND_STRL("proxytunnel"), CURLOPT_HTTPPROXYTUNNEL
, _IS_BOOL
);
1218 #if PHP_HTTP_CURL_VERSION(7,19,4)
1219 php_http_option_register(registry
, ZEND_STRL("noproxy"), CURLOPT_NOPROXY
, IS_STRING
);
1221 #if PHP_HTTP_CURL_VERSION(7,55,0)
1222 php_http_option_register(registry
, ZEND_STRL("socks5_auth"), CURLOPT_SOCKS5_AUTH
, IS_LONG
);
1225 #if PHP_HTTP_CURL_VERSION(7,37,0)
1226 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyheader"), CURLOPT_PROXYHEADER
, IS_ARRAY
))) {
1227 opt
->setter
= php_http_curle_option_set_proxyheader
;
1230 #if PHP_HTTP_CURL_VERSION(7,43,0)
1231 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_GSSAPI
)
1232 && (opt
= php_http_option_register(registry
, ZEND_STRL("proxy_service_name"), CURLOPT_PROXY_SERVICE_NAME
, IS_STRING
))
1234 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1237 #if PHP_HTTP_CURL_VERSION(7,60,0)
1238 php_http_option_register(registry
, ZEND_STRL("haproxy_protocol"), CURLOPT_HAPROXYPROTOCOL
, _IS_BOOL
);
1242 #if PHP_HTTP_CURL_VERSION(7,40,0)
1243 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_UNIX_SOCKETS
)) {
1244 if ((opt
= php_http_option_register(registry
, ZEND_STRL("unix_socket_path"), CURLOPT_UNIX_SOCKET_PATH
, IS_STRING
))) {
1245 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1246 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1248 #if PHP_HTTP_CURL_VERSION(7,53,0)
1249 if ((opt
= php_http_option_register(registry
, ZEND_STRL("abstract_unix_socket"), CURLOPT_ABSTRACT_UNIX_SOCKET
, IS_STRING
))) {
1250 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1257 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_cache_timeout"), CURLOPT_DNS_CACHE_TIMEOUT
, IS_LONG
))) {
1258 Z_LVAL(opt
->defval
) = 60;
1260 php_http_option_register(registry
, ZEND_STRL("ipresolve"), CURLOPT_IPRESOLVE
, IS_LONG
);
1261 #if PHP_HTTP_CURL_VERSION(7,21,3)
1262 if ((opt
= php_http_option_register(registry
, ZEND_STRL("resolve"), CURLOPT_RESOLVE
, IS_ARRAY
))) {
1263 opt
->setter
= php_http_curle_option_set_resolve
;
1266 #if PHP_HTTP_HAVE_LIBCURL_ARES
1267 # if PHP_HTTP_CURL_VERSION(7,24,0)
1268 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_servers"), CURLOPT_DNS_SERVERS
, IS_STRING
))) {
1269 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1272 # if PHP_HTTP_CURL_VERSION(7,33,0)
1273 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_interface"), CURLOPT_DNS_INTERFACE
, IS_STRING
))) {
1274 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1276 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_local_ip4"), CURLOPT_DNS_LOCAL_IP4
, IS_STRING
))) {
1277 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1279 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_local_ip6"), CURLOPT_DNS_LOCAL_IP6
, IS_STRING
))) {
1280 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1284 #if PHP_HTTP_CURL_VERSION(7,60,0)
1285 php_http_option_register(registry
, ZEND_STRL("dns_shuffle_addresses"), CURLOPT_DNS_SHUFFLE_ADDRESSES
, _IS_BOOL
);
1287 #if PHP_HTTP_CURL_VERSION(7,62,0)
1288 php_http_option_register(registry
, ZEND_STRL("doh_url"), CURLOPT_DOH_URL
, IS_STRING
);
1293 php_http_option_register(registry
, ZEND_STRL("low_speed_limit"), CURLOPT_LOW_SPEED_LIMIT
, IS_LONG
);
1294 php_http_option_register(registry
, ZEND_STRL("low_speed_time"), CURLOPT_LOW_SPEED_TIME
, IS_LONG
);
1297 php_http_option_register(registry, ZEND_STRL("max_send_speed"), CURLOPT_MAX_SEND_SPEED_LARGE, IS_LONG);
1298 php_http_option_register(registry, ZEND_STRL("max_recv_speed"), CURLOPT_MAX_RECV_SPEED_LARGE, IS_LONG);
1301 /* connection handling */
1303 if ((opt = php_http_option_register(registry, ZEND_STRL("maxconnects"), CURLOPT_MAXCONNECTS, IS_LONG))) {
1304 Z_LVAL(opt->defval) = 5;
1307 php_http_option_register(registry
, ZEND_STRL("fresh_connect"), CURLOPT_FRESH_CONNECT
, _IS_BOOL
);
1308 php_http_option_register(registry
, ZEND_STRL("forbid_reuse"), CURLOPT_FORBID_REUSE
, _IS_BOOL
);
1309 #if PHP_HTTP_CURL_VERSION(7,65,0)
1310 if ((opt
= php_http_option_register(registry
, ZEND_STRL("maxage_conn"), CURLOPT_MAXAGE_CONN
, IS_LONG
))) {
1311 ZVAL_LONG(&opt
->defval
, 118);
1315 /* outgoing interface */
1316 php_http_option_register(registry
, ZEND_STRL("interface"), CURLOPT_INTERFACE
, IS_STRING
);
1317 if ((opt
= php_http_option_register(registry
, ZEND_STRL("portrange"), CURLOPT_LOCALPORT
, IS_ARRAY
))) {
1318 opt
->setter
= php_http_curle_option_set_portrange
;
1321 /* another endpoint port */
1322 php_http_option_register(registry
, ZEND_STRL("port"), CURLOPT_PORT
, IS_LONG
);
1324 /* RFC4007 zone_id */
1325 #if PHP_HTTP_CURL_VERSION(7,19,0)
1326 php_http_option_register(registry
, ZEND_STRL("address_scope"), CURLOPT_ADDRESS_SCOPE
, IS_LONG
);
1330 if ((opt
= php_http_option_register(registry
, ZEND_STRL("httpauth"), CURLOPT_USERPWD
, IS_STRING
))) {
1331 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1333 if ((opt
= php_http_option_register(registry
, ZEND_STRL("httpauthtype"), CURLOPT_HTTPAUTH
, IS_LONG
))) {
1334 Z_LVAL(opt
->defval
) = CURLAUTH_ANYSAFE
;
1336 #if PHP_HTTP_CURL_VERSION(7,43,0)
1337 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_SSPI
) || PHP_HTTP_CURL_FEATURE(CURL_VERSION_GSSAPI
))
1338 if ((opt
= php_http_option_register(registry
, ZEND_STRL("service_name"), CURLOPT_SERVICE_NAME
, IS_STRING
))) {
1339 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1342 #if PHP_HTTP_CURL_VERSION(7,61,0)
1343 if ((opt
= php_http_option_register(registry
, ZEND_STRL("xoauth2_bearer"), CURLOPT_XOAUTH2_BEARER
, IS_STRING
))) {
1344 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1349 if ((opt
= php_http_option_register(registry
, ZEND_STRL("redirect"), CURLOPT_FOLLOWLOCATION
, IS_LONG
))) {
1350 opt
->setter
= php_http_curle_option_set_redirect
;
1352 php_http_option_register(registry
, ZEND_STRL("unrestricted_auth"), CURLOPT_UNRESTRICTED_AUTH
, _IS_BOOL
);
1353 #if PHP_HTTP_CURL_VERSION(7,19,1)
1354 php_http_option_register(registry
, ZEND_STRL("postredir"), CURLOPT_POSTREDIR
, IS_LONG
);
1358 if ((opt
= php_http_option_register(registry
, ZEND_STRL("retrycount"), 0, IS_LONG
))) {
1359 opt
->setter
= php_http_curle_option_set_retrycount
;
1361 if ((opt
= php_http_option_register(registry
, ZEND_STRL("retrydelay"), 0, IS_DOUBLE
))) {
1362 opt
->setter
= php_http_curle_option_set_retrydelay
;
1366 if ((opt
= php_http_option_register(registry
, ZEND_STRL("referer"), CURLOPT_REFERER
, IS_STRING
))) {
1367 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1369 if ((opt
= php_http_option_register(registry
, ZEND_STRL("autoreferer"), CURLOPT_AUTOREFERER
, _IS_BOOL
))) {
1370 ZVAL_BOOL(&opt
->defval
, 1);
1374 if ((opt
= php_http_option_register(registry
, ZEND_STRL("useragent"), CURLOPT_USERAGENT
, IS_STRING
))) {
1375 /* don't check strlen, to allow sending no useragent at all */
1376 ZVAL_PSTRING(&opt
->defval
,
1377 "PECL_HTTP/" PHP_PECL_HTTP_VERSION
" "
1378 "PHP/" PHP_VERSION
" "
1379 "libcurl/" LIBCURL_VERSION
);
1383 if ((opt
= php_http_option_register(registry
, ZEND_STRL("resume"), CURLOPT_RESUME_FROM
, IS_LONG
))) {
1384 opt
->setter
= php_http_curle_option_set_resume
;
1387 if ((opt
= php_http_option_register(registry
, ZEND_STRL("range"), CURLOPT_RANGE
, IS_ARRAY
))) {
1388 opt
->setter
= php_http_curle_option_set_range
;
1392 if ((opt
= php_http_option_register(registry
, ZEND_STRL("etag"), 0, IS_STRING
))) {
1393 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1394 opt
->setter
= php_http_curle_option_set_etag
;
1398 if ((opt
= php_http_option_register(registry
, ZEND_STRL("compress"), 0, _IS_BOOL
))) {
1399 opt
->setter
= php_http_curle_option_set_compress
;
1403 if ((opt
= php_http_option_register(registry
, ZEND_STRL("lastmodified"), 0, IS_LONG
))) {
1404 opt
->setter
= php_http_curle_option_set_lastmodified
;
1408 if ((opt
= php_http_option_register(registry
, ZEND_STRL("encodecookies"), 0, _IS_BOOL
))) {
1409 opt
->setter
= php_http_curle_option_set_encodecookies
;
1410 ZVAL_BOOL(&opt
->defval
, 1);
1412 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookies"), 0, IS_ARRAY
))) {
1413 opt
->setter
= php_http_curle_option_set_cookies
;
1416 /* cookiesession, don't load session cookies from cookiestore */
1417 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookiesession"), CURLOPT_COOKIESESSION
, _IS_BOOL
))) {
1418 opt
->setter
= php_http_curle_option_set_cookiesession
;
1420 /* cookiestore, read initial cookies from that file and store cookies back into that file */
1421 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookiestore"), 0, IS_STRING
))) {
1422 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1423 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1424 opt
->setter
= php_http_curle_option_set_cookiestore
;
1428 php_http_option_register(registry
, ZEND_STRL("maxfilesize"), CURLOPT_MAXFILESIZE
, IS_LONG
);
1430 /* http protocol version */
1431 php_http_option_register(registry
, ZEND_STRL("protocol"), CURLOPT_HTTP_VERSION
, IS_LONG
);
1432 #if PHP_HTTP_CURL_VERSION(7,64,0)
1433 php_http_option_register(registry
, ZEND_STRL("http09_allowed"), CURLOPT_HTTP09_ALLOWED
, _IS_BOOL
);
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;
1462 #if PHP_HTTP_CURL_VERSION(7,49,0)
1463 php_http_option_register(registry
, ZEND_STRL("tcp_fastopen"), CURLOPT_TCP_FASTOPEN
, _IS_BOOL
);
1467 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_SSL
)) {
1468 php_http_option_t
*ssl_opt
, *proxy_opt
;
1470 if ((ssl_opt
= php_http_option_register(registry
, ZEND_STRL("ssl"), 0, IS_ARRAY
))) {
1471 php_http_options_t
*ssl_registry
= &ssl_opt
->suboptions
;
1473 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("cert"), CURLOPT_SSLCERT
, IS_STRING
))) {
1474 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1475 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1477 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("certtype"), CURLOPT_SSLCERTTYPE
, IS_STRING
))) {
1478 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1479 ZVAL_PSTRING(&opt
->defval
, "PEM");
1481 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("key"), CURLOPT_SSLKEY
, IS_STRING
))) {
1482 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1483 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1485 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("keytype"), CURLOPT_SSLKEYTYPE
, IS_STRING
))) {
1486 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1487 ZVAL_PSTRING(&opt
->defval
, "PEM");
1489 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("keypasswd"), CURLOPT_SSLKEYPASSWD
, IS_STRING
))) {
1490 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1492 php_http_option_register(ssl_registry
, ZEND_STRL("engine"), CURLOPT_SSLENGINE
, IS_STRING
);
1493 php_http_option_register(ssl_registry
, ZEND_STRL("version"), CURLOPT_SSLVERSION
, IS_LONG
);
1494 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("verifypeer"), CURLOPT_SSL_VERIFYPEER
, _IS_BOOL
))) {
1495 ZVAL_BOOL(&opt
->defval
, 1);
1497 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("verifyhost"), CURLOPT_SSL_VERIFYHOST
, _IS_BOOL
))) {
1498 ZVAL_BOOL(&opt
->defval
, 1);
1499 opt
->setter
= php_http_curle_option_set_ssl_verifyhost
;
1501 #if PHP_HTTP_CURL_VERSION(7,41,0) && (PHP_HTTP_HAVE_LIBCURL_OPENSSL || PHP_HTTP_HAVE_LIBCURL_NSS || PHP_HTTP_HAVE_LIBCURL_GNUTLS)
1502 php_http_option_register(ssl_registry
, ZEND_STRL("verifystatus"), CURLOPT_SSL_VERIFYSTATUS
, _IS_BOOL
);
1504 php_http_option_register(ssl_registry
, ZEND_STRL("cipher_list"), CURLOPT_SSL_CIPHER_LIST
, IS_STRING
);
1505 #if PHP_HTTP_HAVE_LIBCURL_CAINFO
1506 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("cainfo"), CURLOPT_CAINFO
, IS_STRING
))) {
1507 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1508 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1509 # ifdef PHP_HTTP_CAINFO
1510 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAINFO
);
1514 #if PHP_HTTP_HAVE_LIBCURL_CAPATH
1515 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("capath"), CURLOPT_CAPATH
, IS_STRING
))) {
1516 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1517 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1518 # ifdef PHP_HTTP_CAPATH
1519 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAPATH
);
1523 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("random_file"), CURLOPT_RANDOM_FILE
, IS_STRING
))) {
1524 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1525 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1527 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("egdsocket"), CURLOPT_EGDSOCKET
, IS_STRING
))) {
1528 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1529 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1531 #if PHP_HTTP_CURL_VERSION(7,19,0)
1532 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("issuercert"), CURLOPT_ISSUERCERT
, IS_STRING
))) {
1533 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1534 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1536 # if PHP_HTTP_HAVE_LIBCURL_OPENSSL
1537 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("crlfile"), CURLOPT_CRLFILE
, IS_STRING
))) {
1538 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1539 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1543 #if (PHP_HTTP_CURL_VERSION(7,19,1) && PHP_HTTP_HAVE_LIBCURL_OPENSSL) || (PHP_HTTP_CURL_VERSION(7,34,0) && PHP_HTTP_HAVE_LIBCURL_NSS) || (PHP_HTTP_CURL_VERSION(7,42,0) && defined(PHP_HTTP_HAVE_LIBCURL_GNUTLS)) || (PHP_HTTP_CURL_VERSION(7,39,0) && defined(PHP_HTTP_HAVE_LIBCURL_GSKIT))
1544 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("certinfo"), CURLOPT_CERTINFO
, _IS_BOOL
))) {
1545 ZVAL_FALSE(&opt
->defval
);
1548 #if PHP_HTTP_CURL_VERSION(7,36,0)
1549 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("enable_npn"), CURLOPT_SSL_ENABLE_NPN
, _IS_BOOL
))) {
1550 ZVAL_BOOL(&opt
->defval
, 1);
1552 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("enable_alpn"), CURLOPT_SSL_ENABLE_ALPN
, _IS_BOOL
))) {
1553 ZVAL_BOOL(&opt
->defval
, 1);
1556 #if PHP_HTTP_CURL_VERSION(7,39,0)
1557 /* FIXME: see http://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html#AVAILABILITY */
1558 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("pinned_publickey"), CURLOPT_PINNEDPUBLICKEY
, IS_STRING
))) {
1559 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1560 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1563 #if PHP_HTTP_CURL_VERSION(7,21,4) && PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
1564 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tlsauthtype"), CURLOPT_TLSAUTH_TYPE
, IS_LONG
))) {
1565 opt
->setter
= php_http_curle_option_set_ssl_tlsauthtype
;
1567 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tlsauthuser"), CURLOPT_TLSAUTH_USERNAME
, IS_STRING
))) {
1568 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1570 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tlsauthpass"), CURLOPT_TLSAUTH_PASSWORD
, IS_STRING
))) {
1571 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1574 #if PHP_HTTP_CURL_VERSION(7,42,0) && (PHP_HTTP_HAVE_LIBCURL_NSS || PHP_HTTP_HAVE_LIBCURL_SECURETRANSPORT)
1575 php_http_option_register(ssl_registry
, ZEND_STRL("falsestart"), CURLOPT_SSL_FALSESTART
, _IS_BOOL
);
1577 #if PHP_HTTP_CURL_VERSION(7,61,0)
1578 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tls13_ciphers"), CURLOPT_TLS13_CIPHERS
, IS_STRING
))) {
1579 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1584 #if PHP_HTTP_CURL_VERSION(7,52,0)
1586 if ((proxy_opt
= php_http_option_register(registry
, ZEND_STRL("proxy_ssl"), 0, IS_ARRAY
))) {
1587 php_http_options_t
*proxy_registry
= &proxy_opt
->suboptions
;
1589 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("cert"), CURLOPT_PROXY_SSLCERT
, IS_STRING
))) {
1590 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1591 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1593 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("certtype"), CURLOPT_PROXY_SSLCERTTYPE
, IS_STRING
))) {
1594 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1595 ZVAL_PSTRING(&opt
->defval
, "PEM");
1597 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("key"), CURLOPT_PROXY_SSLKEY
, IS_STRING
))) {
1598 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1599 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1601 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("keytype"), CURLOPT_PROXY_SSLKEYTYPE
, IS_STRING
))) {
1602 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1603 ZVAL_PSTRING(&opt
->defval
, "PEM");
1605 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("keypasswd"), CURLOPT_PROXY_KEYPASSWD
, IS_STRING
))) {
1606 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1608 php_http_option_register(proxy_registry
, ZEND_STRL("version"), CURLOPT_PROXY_SSLVERSION
, IS_LONG
);
1609 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("verifypeer"), CURLOPT_PROXY_SSL_VERIFYPEER
, _IS_BOOL
))) {
1610 ZVAL_BOOL(&opt
->defval
, 1);
1612 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("verifyhost"), CURLOPT_PROXY_SSL_VERIFYHOST
, _IS_BOOL
))) {
1613 ZVAL_BOOL(&opt
->defval
, 1);
1614 opt
->setter
= php_http_curle_option_set_ssl_verifyhost
;
1616 php_http_option_register(proxy_registry
, ZEND_STRL("cipher_list"), CURLOPT_PROXY_SSL_CIPHER_LIST
, IS_STRING
);
1617 # if PHP_HTTP_HAVE_LIBCURL_OPENSSL
1618 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("crlfile"), CURLOPT_PROXY_CRLFILE
, IS_STRING
))) {
1619 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1620 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1623 # if PHP_HTTP_HAVE_LIBCURL_CAINFO
1624 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("cainfo"), CURLOPT_PROXY_CAINFO
, IS_STRING
))) {
1625 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1626 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1627 # ifdef PHP_HTTP_CAINFO
1628 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAINFO
);
1632 # if PHP_HTTP_HAVE_LIBCURL_CAPATH
1633 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("capath"), CURLOPT_PROXY_CAPATH
, IS_STRING
))) {
1634 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1635 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1636 # ifdef PHP_HTTP_CAPATH
1637 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAPATH
);
1642 # if PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
1643 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tlsauthtype"), CURLOPT_PROXY_TLSAUTH_TYPE
, IS_LONG
))) {
1644 opt
->setter
= php_http_curle_option_set_ssl_tlsauthtype
;
1646 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tlsauthuser"), CURLOPT_PROXY_TLSAUTH_USERNAME
, IS_STRING
))) {
1647 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1649 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tlsauthpass"), CURLOPT_PROXY_TLSAUTH_PASSWORD
, IS_STRING
))) {
1650 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1653 # if PHP_HTTP_CURL_VERSION(7,59,0)
1654 /* FIXME: see http://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html#AVAILABILITY */
1655 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("pinned_publickey"), CURLOPT_PROXY_PINNEDPUBLICKEY
, IS_STRING
))) {
1656 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1657 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1660 # if PHP_HTTP_CURL_VERSION(7,61,0)
1661 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tls13_ciphers"), CURLOPT_PROXY_TLS13_CIPHERS
, IS_STRING
))) {
1662 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1669 #if PHP_HTTP_CURL_VERSION(7,64,1)
1670 if ((opt
= php_http_option_register(registry
, ZEND_STRL("altsvc_ctrl"), CURLOPT_ALTSVC_CTRL
, IS_LONG
))) {
1671 opt
->setter
= php_http_curle_option_set_altsvc_ctrl
;
1673 if ((opt
= php_http_option_register(registry
, ZEND_STRL("altsvc"), CURLOPT_ALTSVC
, IS_STRING
))) {
1674 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1679 static zval
*php_http_curle_get_option(php_http_option_t
*opt
, HashTable
*options
, void *userdata
)
1681 php_http_client_curl_handler_t
*curl
= userdata
;
1684 if ((option
= php_http_option_get(opt
, options
, NULL
))) {
1687 ZVAL_DUP(&zopt
, option
);
1688 convert_to_explicit_type(&zopt
, opt
->type
);
1689 zend_hash_update(&curl
->options
.cache
, opt
->name
, &zopt
);
1690 return zend_hash_find(&curl
->options
.cache
, opt
->name
);
1695 static ZEND_RESULT_CODE
php_http_curle_set_option(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1697 php_http_client_curl_handler_t
*curl
= userdata
;
1698 CURL
*ch
= curl
->handle
;
1700 CURLcode rc
= CURLE_UNKNOWN_OPTION
;
1701 ZEND_RESULT_CODE rv
= SUCCESS
;
1707 switch (opt
->type
) {
1710 rv
= opt
->setter(opt
, val
, curl
);
1711 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, (long) (Z_TYPE_P(val
) == IS_TRUE
))) {
1718 rv
= opt
->setter(opt
, val
, curl
);
1719 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, Z_LVAL_P(val
))) {
1726 rv
= opt
->setter(opt
, val
, curl
);
1727 } else if (!val
|| Z_TYPE_P(val
) == IS_NULL
) {
1728 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1731 } else if ((opt
->flags
& PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
) && !Z_STRLEN_P(val
)) {
1732 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1735 } else if ((opt
->flags
& PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
) && Z_STRVAL_P(val
) && SUCCESS
!= php_check_open_basedir(Z_STRVAL_P(val
))) {
1736 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1739 } else if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, Z_STRVAL_P(val
)))) {
1745 if (opt
->flags
& PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
) {
1747 Z_DVAL(tmp
) *= 1000;
1751 rv
= opt
->setter(opt
, val
, curl
);
1752 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, (long) Z_DVAL_P(val
))) {
1759 rv
= opt
->setter(opt
, val
, curl
);
1760 } else if (Z_TYPE_P(val
) != IS_NULL
) {
1761 rv
= php_http_options_apply(&opt
->suboptions
, Z_ARRVAL_P(val
), curl
);
1767 rv
= opt
->setter(opt
, val
, curl
);
1773 if (rv
!= SUCCESS
) {
1774 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_easy_strerror(rc
));
1779 #if PHP_HTTP_CURL_VERSION(7,30,0) && !PHP_HTTP_CURL_VERSION(7,62,0)
1780 static ZEND_RESULT_CODE
php_http_curlm_option_set_pipelining_bl(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1782 php_http_client_t
*client
= userdata
;
1783 php_http_client_curl_t
*curl
= client
->ctx
;
1784 CURLM
*ch
= curl
->handle
->multi
;
1788 /* array of char *, ending with a NULL */
1789 if (value
&& Z_TYPE_P(value
) != IS_NULL
) {
1791 HashTable
*ht
= HASH_OF(value
);
1792 int c
= zend_hash_num_elements(ht
);
1793 char **ptr
= ecalloc(c
+ 1, sizeof(char *));
1797 zend_hash_init(&tmp_ht
, c
, NULL
, ZVAL_PTR_DTOR
, 0);
1798 array_join(ht
, &tmp_ht
, 0, ARRAY_JOIN_STRINGIFY
);
1800 ZEND_HASH_FOREACH_VAL(&tmp_ht
, entry
)
1802 *ptr
++ = Z_STRVAL_P(entry
);
1804 ZEND_HASH_FOREACH_END();
1807 if (CURLM_OK
!= curl_multi_setopt(ch
, opt
->option
, bl
)) {
1810 zend_hash_destroy(&tmp_ht
);
1817 zend_hash_destroy(&tmp_ht
);
1823 static inline ZEND_RESULT_CODE
php_http_curlm_use_eventloop(php_http_client_t
*h
, php_http_client_curl_ops_t
*ev_ops
, zval
*init_data
)
1825 php_http_client_curl_t
*curl
= h
->ctx
;
1829 if (!(ev_ctx
= ev_ops
->init(h
, init_data
))) {
1832 curl
->ev_ctx
= ev_ctx
;
1833 curl
->ev_ops
= ev_ops
;
1837 curl
->ev_ops
->dtor(&curl
->ev_ctx
);
1839 curl
->ev_ops
= NULL
;
1846 static ZEND_RESULT_CODE
php_http_curlm_option_set_use_eventloop(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1848 php_http_client_t
*client
= userdata
;
1849 php_http_client_curl_ops_t
*ev_ops
= NULL
;
1851 if (value
&& Z_TYPE_P(value
) == IS_OBJECT
&& instanceof_function(Z_OBJCE_P(value
), php_http_client_curl_user_get_class_entry())) {
1852 ev_ops
= php_http_client_curl_user_ops_get();
1853 #if PHP_HTTP_HAVE_LIBEVENT
1854 } else if (value
&& zend_is_true(value
)) {
1855 ev_ops
= php_http_client_curl_event_ops_get();
1859 return php_http_curlm_use_eventloop(client
, ev_ops
, value
);
1862 static ZEND_RESULT_CODE
php_http_curlm_option_set_share_cookies(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1864 php_http_client_t
*client
= userdata
;
1865 php_http_client_curl_t
*curl
= client
->ctx
;
1868 if (Z_TYPE_P(value
) == IS_TRUE
) {
1869 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_COOKIE
);
1871 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_UNSHARE
, CURL_LOCK_DATA_COOKIE
);
1874 if (CURLSHE_OK
!= rc
) {
1875 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_share_strerror(rc
));
1881 #if PHP_HTTP_CURL_VERSION(7,23,0)
1882 static ZEND_RESULT_CODE
php_http_curlm_option_set_share_ssl(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1884 php_http_client_t
*client
= userdata
;
1885 php_http_client_curl_t
*curl
= client
->ctx
;
1888 if (Z_TYPE_P(value
) == IS_TRUE
) {
1889 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_SSL_SESSION
);
1891 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_UNSHARE
, CURL_LOCK_DATA_SSL_SESSION
);
1894 if (CURLSHE_OK
!= rc
) {
1895 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_share_strerror(rc
));
1902 static void php_http_curlm_options_init(php_http_options_t
*registry
)
1904 php_http_option_t
*opt
;
1906 /* set size of connection cache */
1907 if ((opt
= php_http_option_register(registry
, ZEND_STRL("maxconnects"), CURLMOPT_MAXCONNECTS
, IS_LONG
))) {
1908 /* -1 == default, 0 == unlimited */
1909 ZVAL_LONG(&opt
->defval
, -1);
1911 /* set max number of connections to a single host */
1912 #if PHP_HTTP_CURL_VERSION(7,30,0)
1913 php_http_option_register(registry
, ZEND_STRL("max_host_connections"), CURLMOPT_MAX_HOST_CONNECTIONS
, IS_LONG
);
1915 /* max simultaneously open connections */
1916 #if PHP_HTTP_CURL_VERSION(7,30,0)
1917 php_http_option_register(registry
, ZEND_STRL("max_total_connections"), CURLMOPT_MAX_TOTAL_CONNECTIONS
, IS_LONG
);
1919 #if !PHP_HTTP_CURL_VERSION(7,62,0)
1920 /* enable/disable HTTP pipelining */
1921 php_http_option_register(registry
, ZEND_STRL("pipelining"), CURLMOPT_PIPELINING
, _IS_BOOL
);
1922 # if PHP_HTTP_CURL_VERSION(7,30,0)
1923 /* maximum number of requests in a pipeline */
1924 if ((opt
= php_http_option_register(registry
, ZEND_STRL("max_pipeline_length"), CURLMOPT_MAX_PIPELINE_LENGTH
, IS_LONG
))) {
1925 ZVAL_LONG(&opt
->defval
, 5);
1927 /* chunk length threshold for pipelining */
1928 php_http_option_register(registry
, ZEND_STRL("chunk_length_penalty_size"), CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE
, IS_LONG
);
1929 /* size threshold for pipelining penalty */
1930 php_http_option_register(registry
, ZEND_STRL("content_length_penalty_size"), CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE
, IS_LONG
);
1931 /* pipelining server blacklist */
1932 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pipelining_server_bl"), CURLMOPT_PIPELINING_SERVER_BL
, IS_ARRAY
))) {
1933 opt
->setter
= php_http_curlm_option_set_pipelining_bl
;
1935 /* pipelining host blacklist */
1936 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pipelining_site_bl"), CURLMOPT_PIPELINING_SITE_BL
, IS_ARRAY
))) {
1937 opt
->setter
= php_http_curlm_option_set_pipelining_bl
;
1942 if ((opt
= php_http_option_register(registry
, ZEND_STRL("use_eventloop"), 0, 0))) {
1943 opt
->setter
= php_http_curlm_option_set_use_eventloop
;
1946 if ((opt
= php_http_option_register(registry
, ZEND_STRL("share_cookies"), 0, _IS_BOOL
))) {
1947 opt
->setter
= php_http_curlm_option_set_share_cookies
;
1948 ZVAL_TRUE(&opt
->defval
);
1950 #if PHP_HTTP_CURL_VERSION(7,23,0)
1951 if ((opt
= php_http_option_register(registry
, ZEND_STRL("share_ssl"), 0, _IS_BOOL
))) {
1952 opt
->setter
= php_http_curlm_option_set_share_ssl
;
1953 ZVAL_TRUE(&opt
->defval
);
1958 static ZEND_RESULT_CODE
php_http_curlm_set_option(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1960 php_http_client_t
*client
= userdata
;
1961 php_http_client_curl_t
*curl
= client
->ctx
;
1962 CURLM
*ch
= curl
->handle
->multi
;
1963 zval zopt
, *orig
= val
;
1964 CURLMcode rc
= CURLM_UNKNOWN_OPTION
;
1965 ZEND_RESULT_CODE rv
= SUCCESS
;
1969 } else if (opt
->type
&& Z_TYPE_P(val
) != opt
->type
&& !(Z_TYPE_P(val
) == IS_NULL
&& opt
->type
== IS_ARRAY
)) {
1970 ZVAL_DUP(&zopt
, val
);
1971 convert_to_explicit_type(&zopt
, opt
->type
);
1977 rv
= opt
->setter(opt
, val
, client
);
1979 switch (opt
->type
) {
1981 if (CURLM_OK
!= (rc
= curl_multi_setopt(ch
, opt
->option
, (long) zend_is_true(val
)))) {
1983 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_multi_strerror(rc
));
1987 if (CURLM_OK
!= (rc
= curl_multi_setopt(ch
, opt
->option
, Z_LVAL_P(val
)))) {
1989 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_multi_strerror(rc
));
1994 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s", opt
->name
->val
);
1999 if (val
&& val
!= orig
&& val
!= &opt
->defval
) {
2008 static ZEND_RESULT_CODE
php_http_client_curl_handler_reset(php_http_client_curl_handler_t
*curl
)
2010 CURL
*ch
= curl
->handle
;
2011 php_http_curle_storage_t
*st
;
2013 if ((st
= php_http_curle_get_storage(ch
))) {
2018 if (st
->cookiestore
) {
2019 pefree(st
->cookiestore
, 1);
2020 st
->cookiestore
= NULL
;
2022 st
->errorbuffer
[0] = '\0';
2026 curl_easy_setopt(ch
, CURLOPT_URL
, NULL
);
2027 curl_easy_setopt(ch
, CURLOPT_CUSTOMREQUEST
, NULL
);
2028 curl_easy_setopt(ch
, CURLOPT_HTTPGET
, 1L);
2029 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 0L);
2030 /* libcurl < 7.19.6 does not clear auth info with USERPWD set to NULL */
2031 #if PHP_HTTP_CURL_VERSION(7,19,1)
2032 curl_easy_setopt(ch
, CURLOPT_PROXYUSERNAME
, NULL
);
2033 curl_easy_setopt(ch
, CURLOPT_PROXYPASSWORD
, NULL
);
2034 curl_easy_setopt(ch
, CURLOPT_USERNAME
, NULL
);
2035 curl_easy_setopt(ch
, CURLOPT_PASSWORD
, NULL
);
2038 #if PHP_HTTP_CURL_VERSION(7,21,3)
2039 if (curl
->options
.resolve
) {
2040 curl_slist_free_all(curl
->options
.resolve
);
2041 curl
->options
.resolve
= NULL
;
2044 curl
->options
.retry
.count
= 0;
2045 curl
->options
.retry
.delay
= 0;
2046 curl
->options
.redirects
= 0;
2047 curl
->options
.encode_cookies
= 1;
2049 if (curl
->options
.headers
) {
2050 curl_slist_free_all(curl
->options
.headers
);
2051 curl
->options
.headers
= NULL
;
2053 if (curl
->options
.proxyheaders
) {
2054 curl_slist_free_all(curl
->options
.proxyheaders
);
2055 curl
->options
.proxyheaders
= NULL
;
2058 php_http_buffer_reset(&curl
->options
.cookies
);
2059 php_http_buffer_reset(&curl
->options
.ranges
);
2064 static php_http_client_curl_handler_t
*php_http_client_curl_handler_init(php_http_client_t
*h
, php_resource_factory_t
*rf
)
2067 php_http_client_curl_t
*curl
= h
->ctx
;
2068 php_http_client_curl_handler_t
*handler
;
2070 if (!(handle
= php_resource_factory_handle_ctor(rf
, NULL
))) {
2071 php_error_docref(NULL
, E_WARNING
, "Failed to initialize curl handle");
2075 handler
= ecalloc(1, sizeof(*handler
));
2077 handler
->client
= h
;
2078 handler
->handle
= handle
;
2079 handler
->response
.body
= php_http_message_body_init(NULL
, NULL
);
2080 php_http_buffer_init(&handler
->response
.headers
);
2081 php_http_buffer_init(&handler
->options
.cookies
);
2082 php_http_buffer_init(&handler
->options
.ranges
);
2083 zend_hash_init(&handler
->options
.cache
, 0, NULL
, ZVAL_PTR_DTOR
, 0);
2086 curl_easy_setopt(handle
, CURLOPT_NOSIGNAL
, 1L);
2088 curl_easy_setopt(handle
, CURLOPT_HEADER
, 0L);
2089 curl_easy_setopt(handle
, CURLOPT_FILETIME
, 1L);
2090 curl_easy_setopt(handle
, CURLOPT_AUTOREFERER
, 1L);
2091 curl_easy_setopt(handle
, CURLOPT_VERBOSE
, 1L);
2092 curl_easy_setopt(handle
, CURLOPT_NOPROGRESS
, 0L);
2093 curl_easy_setopt(handle
, CURLOPT_HEADERFUNCTION
, php_http_curle_header_callback
);
2094 curl_easy_setopt(handle
, CURLOPT_WRITEFUNCTION
, php_http_curle_body_callback
);
2095 curl_easy_setopt(handle
, CURLOPT_DEBUGFUNCTION
, php_http_curle_raw_callback
);
2096 curl_easy_setopt(handle
, CURLOPT_READFUNCTION
, php_http_curle_read_callback
);
2097 curl_easy_setopt(handle
, CURLOPT_SEEKFUNCTION
, php_http_curle_seek_callback
);
2098 #if PHP_HTTP_CURL_VERSION(7,32,0)
2099 curl_easy_setopt(handle
, CURLOPT_XFERINFOFUNCTION
, php_http_curle_xferinfo_callback
);
2100 curl_easy_setopt(handle
, CURLOPT_XFERINFODATA
, handler
);
2102 curl_easy_setopt(handle
, CURLOPT_PROGRESSFUNCTION
, php_http_curle_progress_callback
);
2103 curl_easy_setopt(handle
, CURLOPT_PROGRESSDATA
, handler
);
2105 curl_easy_setopt(handle
, CURLOPT_DEBUGDATA
, handler
);
2106 curl_easy_setopt(handle
, CURLOPT_WRITEDATA
, handler
);
2107 curl_easy_setopt(handle
, CURLOPT_HEADERDATA
, handler
);
2108 curl_easy_setopt(handle
, CURLOPT_SHARE
, curl
->handle
->share
);
2110 php_http_client_curl_handler_reset(handler
);
2116 static ZEND_RESULT_CODE
php_http_client_curl_handler_prepare(php_http_client_curl_handler_t
*curl
, php_http_client_enqueue_t
*enqueue
)
2119 php_http_message_t
*msg
= enqueue
->request
;
2120 php_http_curle_storage_t
*storage
= php_http_curle_get_storage(curl
->handle
);
2123 if (!PHP_HTTP_INFO(msg
).request
.url
) {
2124 php_error_docref(NULL
, E_WARNING
, "Cannot request empty URL");
2127 storage
->errorbuffer
[0] = '\0';
2129 pefree(storage
->url
, 1);
2131 php_http_url_to_string(PHP_HTTP_INFO(msg
).request
.url
, &storage
->url
, NULL
, 1);
2132 curl_easy_setopt(curl
->handle
, CURLOPT_URL
, storage
->url
);
2135 php_http_options_apply(&php_http_curle_options
, enqueue
->options
, curl
);
2137 /* request headers */
2138 php_http_message_update_headers(msg
);
2139 if (zend_hash_num_elements(&msg
->hdrs
)) {
2140 php_http_arrkey_t header_key
;
2142 zend_string
*header_str
;
2143 php_http_buffer_t header
;
2144 #if !PHP_HTTP_CURL_VERSION(7,23,0)
2145 zval
*ct
= zend_hash_str_find(&msg
->hdrs
, ZEND_STRL("Content-Length"));
2148 php_http_buffer_init(&header
);
2149 ZEND_HASH_FOREACH_KEY_VAL(&msg
->hdrs
, header_key
.h
, header_key
.key
, header_val
)
2151 if (header_key
.key
) {
2152 #if !PHP_HTTP_CURL_VERSION(7,23,0)
2153 /* avoid duplicate content-length header */
2154 if (ct
&& ct
== header_val
) {
2158 header_str
= zval_get_string(header_val
);
2159 php_http_buffer_appendf(&header
, "%s: %s", header_key
.key
->val
, header_str
->val
);
2160 php_http_buffer_fix(&header
);
2161 curl
->options
.headers
= curl_slist_append(curl
->options
.headers
, header
.data
);
2162 php_http_buffer_reset(&header
);
2163 zend_string_release(header_str
);
2166 ZEND_HASH_FOREACH_END();
2167 php_http_buffer_dtor(&header
);
2169 curl_easy_setopt(curl
->handle
, CURLOPT_HTTPHEADER
, curl
->options
.headers
);
2171 /* attach request body */
2172 if ((body_size
= php_http_message_body_size(msg
->body
))) {
2173 /* RFC2616, section 4.3 (para. 4) states that »a message-body MUST NOT be included in a request if the
2174 * specification of the request method (section 5.1.1) does not allow sending an entity-body in request.«
2175 * Following the clause in section 5.1.1 (para. 2) that request methods »MUST be implemented with the
2176 * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method
2177 * does not allow a request body.
2179 php_stream_rewind(php_http_message_body_stream(msg
->body
));
2180 curl_easy_setopt(curl
->handle
, CURLOPT_SEEKDATA
, msg
->body
);
2181 curl_easy_setopt(curl
->handle
, CURLOPT_READDATA
, msg
->body
);
2182 curl_easy_setopt(curl
->handle
, CURLOPT_INFILESIZE
, body_size
);
2183 curl_easy_setopt(curl
->handle
, CURLOPT_POSTFIELDSIZE
, body_size
);
2184 curl_easy_setopt(curl
->handle
, CURLOPT_POST
, 1L);
2186 curl_easy_setopt(curl
->handle
, CURLOPT_SEEKDATA
, NULL
);
2187 curl_easy_setopt(curl
->handle
, CURLOPT_READDATA
, NULL
);
2188 curl_easy_setopt(curl
->handle
, CURLOPT_INFILESIZE
, 0L);
2189 curl_easy_setopt(curl
->handle
, CURLOPT_POSTFIELDSIZE
, 0L);
2193 * Always use CUSTOMREQUEST, else curl won't send any request body for GET etc.
2194 * See e.g. bug #69313.
2196 * Here's what curl does:
2197 * - CURLOPT_HTTPGET: ignore request body
2198 * - CURLOPT_UPLOAD: set "Expect: 100-continue" header
2199 * - CURLOPT_POST: set "Content-Type: application/x-www-form-urlencoded" header
2200 * Now select the least bad.
2202 * See also https://tools.ietf.org/html/rfc7231#section-5.1.1
2204 if (PHP_HTTP_INFO(msg
).request
.method
) {
2205 switch(php_http_select_str(PHP_HTTP_INFO(msg
).request
.method
, 2, "HEAD", "PUT")) {
2207 curl_easy_setopt(curl
->handle
, CURLOPT_NOBODY
, 1L);
2210 curl_easy_setopt(curl
->handle
, CURLOPT_UPLOAD
, 1L);
2213 curl_easy_setopt(curl
->handle
, CURLOPT_CUSTOMREQUEST
, PHP_HTTP_INFO(msg
).request
.method
);
2216 php_error_docref(NULL
, E_WARNING
, "Cannot use empty request method");
2223 static void php_http_client_curl_handler_clear(php_http_client_curl_handler_t
*handler
)
2225 curl_easy_setopt(handler
->handle
, CURLOPT_NOPROGRESS
, 1L);
2226 #if PHP_HTTP_CURL_VERSION(7,32,0)
2227 curl_easy_setopt(handler
->handle
, CURLOPT_XFERINFOFUNCTION
, NULL
);
2229 curl_easy_setopt(handler
->handle
, CURLOPT_PROGRESSFUNCTION
, NULL
);
2231 curl_easy_setopt(handler
->handle
, CURLOPT_VERBOSE
, 0L);
2232 curl_easy_setopt(handler
->handle
, CURLOPT_DEBUGFUNCTION
, NULL
);
2233 curl_easy_setopt(handler
->handle
, CURLOPT_COOKIELIST
, "FLUSH");
2234 curl_easy_setopt(handler
->handle
, CURLOPT_SHARE
, NULL
);
2235 /* see gh issue #84 */
2236 #if PHP_HTTP_CURL_VERSION(7,63,0) && !PHP_HTTP_CURL_VERSION(7,65,0)
2237 curl_easy_setopt(handler
->handle
, CURLOPT_COOKIEJAR
, NULL
);
2241 static void php_http_client_curl_handler_dtor(php_http_client_curl_handler_t
*handler
)
2243 php_http_client_curl_handler_clear(handler
);
2245 php_resource_factory_handle_dtor(handler
->rf
, handler
->handle
);
2246 php_resource_factory_free(&handler
->rf
);
2248 php_http_message_body_free(&handler
->response
.body
);
2249 php_http_buffer_dtor(&handler
->response
.headers
);
2250 php_http_buffer_dtor(&handler
->options
.ranges
);
2251 php_http_buffer_dtor(&handler
->options
.cookies
);
2252 zend_hash_destroy(&handler
->options
.cache
);
2254 #if PHP_HTTP_CURL_VERSION(7,21,3)
2255 if (handler
->options
.resolve
) {
2256 curl_slist_free_all(handler
->options
.resolve
);
2257 handler
->options
.resolve
= NULL
;
2261 if (handler
->options
.headers
) {
2262 curl_slist_free_all(handler
->options
.headers
);
2263 handler
->options
.headers
= NULL
;
2266 if (handler
->options
.proxyheaders
) {
2267 curl_slist_free_all(handler
->options
.proxyheaders
);
2268 handler
->options
.proxyheaders
= NULL
;
2274 static php_http_client_t
*php_http_client_curl_init(php_http_client_t
*h
, void *handle
)
2276 php_http_client_curl_t
*curl
;
2278 if (!handle
&& !(handle
= php_resource_factory_handle_ctor(h
->rf
, NULL
))) {
2279 php_error_docref(NULL
, E_WARNING
, "Failed to initialize curl handle");
2283 curl
= ecalloc(1, sizeof(*curl
));
2284 curl
->handle
= handle
;
2285 curl
->unfinished
= 0;
2291 static void php_http_client_curl_dtor(php_http_client_t
*h
)
2293 php_http_client_curl_t
*curl
= h
->ctx
;
2296 curl
->ev_ops
->dtor(&curl
->ev_ctx
);
2297 curl
->ev_ops
= NULL
;
2299 curl
->unfinished
= 0;
2301 php_resource_factory_handle_dtor(h
->rf
, curl
->handle
);
2307 static void queue_dtor(php_http_client_enqueue_t
*e
)
2309 php_http_client_curl_handler_t
*handler
= e
->opaque
;
2311 if (handler
->queue
.dtor
) {
2312 e
->opaque
= handler
->queue
.opaque
;
2313 handler
->queue
.dtor(e
);
2315 php_http_client_curl_handler_dtor(handler
);
2318 static php_resource_factory_t
*create_rf(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2320 php_persistent_handle_factory_t
*pf
= NULL
;
2321 php_resource_factory_t
*rf
= NULL
;
2322 php_http_url_t
*url
= enqueue
->request
->http
.info
.request
.url
;
2324 if (!url
|| (!url
->host
&& !url
->path
)) {
2325 php_error_docref(NULL
, E_WARNING
, "Cannot request empty URL");
2329 /* only if the client itself is setup for persistence */
2330 if (php_resource_factory_is_persistent(h
->rf
)) {
2332 char *id_str
= NULL
;
2334 int port
= url
->port
? url
->port
: 80;
2336 php_persistent_handle_factory_t
*phf
= h
->rf
->data
;
2338 if ((zport
= zend_hash_str_find(enqueue
->options
, ZEND_STRL("port")))) {
2339 zend_long lport
= zval_get_long(zport
);
2346 id_len
= spprintf(&id_str
, 0, "%.*s:%s:%d", (int) phf
->ident
->len
, phf
->ident
->val
, STR_PTR(url
->host
), port
);
2347 id
= php_http_cs2zs(id_str
, id_len
);
2348 pf
= php_persistent_handle_concede(NULL
, PHP_HTTP_G
->client
.curl
.driver
.request_name
, id
, NULL
, NULL
);
2349 zend_string_release(id
);
2353 rf
= php_persistent_handle_resource_factory_init(NULL
, pf
);
2355 rf
= php_resource_factory_init(NULL
, &php_http_curle_resource_factory_ops
, NULL
, NULL
);
2361 static ZEND_RESULT_CODE
php_http_client_curl_enqueue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2364 php_http_client_curl_t
*curl
= h
->ctx
;
2365 php_http_client_curl_handler_t
*handler
;
2366 php_http_client_progress_state_t
*progress
;
2367 php_resource_factory_t
*rf
;
2369 rf
= create_rf(h
, enqueue
);
2374 handler
= php_http_client_curl_handler_init(h
, rf
);
2379 if (SUCCESS
!= php_http_client_curl_handler_prepare(handler
, enqueue
)) {
2380 php_http_client_curl_handler_dtor(handler
);
2384 handler
->queue
= *enqueue
;
2385 enqueue
->opaque
= handler
;
2386 enqueue
->dtor
= queue_dtor
;
2388 if (CURLM_OK
!= (rs
= curl_multi_add_handle(curl
->handle
->multi
, handler
->handle
))) {
2389 php_http_client_curl_handler_dtor(handler
);
2390 php_error_docref(NULL
, E_WARNING
, "Could not enqueue request: %s", curl_multi_strerror(rs
));
2394 zend_llist_add_element(&h
->requests
, enqueue
);
2397 if (h
->callback
.progress
.func
&& SUCCESS
== php_http_client_getopt(h
, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
, enqueue
->request
, &progress
)) {
2398 progress
->info
= "start";
2399 h
->callback
.progress
.func(h
->callback
.progress
.arg
, h
, &handler
->queue
, progress
);
2400 progress
->started
= 1;
2406 static ZEND_RESULT_CODE
php_http_client_curl_dequeue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2409 php_http_client_curl_t
*curl
= h
->ctx
;
2410 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2412 if (h
->callback
.depth
&& !CG(unclean_shutdown
)) {
2413 php_error_docref(NULL
, E_WARNING
, "Could not dequeue request while executing callbacks");
2417 php_http_client_curl_handler_clear(handler
);
2418 if (CURLM_OK
== (rs
= curl_multi_remove_handle(curl
->handle
->multi
, handler
->handle
))) {
2419 zend_llist_del_element(&h
->requests
, handler
->handle
, (int (*)(void *, void *)) compare_queue
);
2422 php_error_docref(NULL
, E_WARNING
, "Could not dequeue request: %s", curl_multi_strerror(rs
));
2428 static void php_http_client_curl_reset(php_http_client_t
*h
)
2430 zend_llist_element
*next_el
, *this_el
;
2432 for (this_el
= h
->requests
.head
; this_el
; this_el
= next_el
) {
2433 next_el
= this_el
->next
;
2434 php_http_client_curl_dequeue(h
, (void *) this_el
->data
);
2439 # define SELECT_ERROR SOCKET_ERROR
2441 # define SELECT_ERROR -1
2444 static ZEND_RESULT_CODE
php_http_client_curl_wait(php_http_client_t
*h
, struct timeval
*custom_timeout
)
2448 struct timeval timeout
;
2449 php_http_client_curl_t
*curl
= h
->ctx
;
2452 return curl
->ev_ops
->wait(curl
->ev_ctx
, custom_timeout
);
2459 if (CURLM_OK
== curl_multi_fdset(curl
->handle
->multi
, &R
, &W
, &E
, &MAX
)) {
2460 if (custom_timeout
&& timerisset(custom_timeout
)) {
2461 timeout
= *custom_timeout
;
2463 php_http_client_curl_get_timeout(curl
, 1000, &timeout
);
2467 php_http_sleep((double) timeout
.tv_sec
+ (double) (timeout
.tv_usec
/ PHP_HTTP_MCROSEC
));
2469 } else if (SELECT_ERROR
!= select(MAX
+ 1, &R
, &W
, &E
, &timeout
)) {
2476 static int php_http_client_curl_once(php_http_client_t
*h
)
2478 php_http_client_curl_t
*curl
= h
->ctx
;
2480 if (!h
->callback
.depth
) {
2482 curl
->ev_ops
->once(curl
->ev_ctx
);
2484 while (CURLM_CALL_MULTI_PERFORM
== curl_multi_perform(curl
->handle
->multi
, &curl
->unfinished
));
2487 php_http_client_curl_responsehandler(h
);
2490 return curl
->unfinished
;
2493 static ZEND_RESULT_CODE
php_http_client_curl_exec(php_http_client_t
*h
)
2495 php_http_client_curl_t
*curl
= h
->ctx
;
2497 if (!h
->callback
.depth
) {
2499 return curl
->ev_ops
->exec(curl
->ev_ctx
);
2502 while (php_http_client_curl_once(h
) && !EG(exception
)) {
2503 if (SUCCESS
!= php_http_client_curl_wait(h
, NULL
)) {
2505 /* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */
2506 php_error_docref(NULL
, E_WARNING
, "WinSock error: %d", WSAGetLastError());
2508 php_error_docref(NULL
, E_WARNING
, "%s", strerror(errno
));
2518 static ZEND_RESULT_CODE
php_http_client_curl_setopt(php_http_client_t
*h
, php_http_client_setopt_opt_t opt
, void *arg
)
2520 php_http_client_curl_t
*curl
= h
->ctx
;
2523 case PHP_HTTP_CLIENT_OPT_CONFIGURATION
:
2524 return php_http_options_apply(&php_http_curlm_options
, (HashTable
*) arg
, h
);
2526 #if !PHP_HTTP_CURL_VERSION(7,62,0)
2527 case PHP_HTTP_CLIENT_OPT_ENABLE_PIPELINING
:
2528 if (CURLM_OK
!= curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_PIPELINING
, (long) *((zend_bool
*) arg
))) {
2533 case PHP_HTTP_CLIENT_OPT_USE_EVENTS
:
2534 #if PHP_HTTP_HAVE_LIBEVENT
2535 return php_http_curlm_use_eventloop(h
, (*(zend_bool
*) arg
)
2536 ? php_http_client_curl_event_ops_get()
2547 static int apply_available_options(zval
*pDest
, int num_args
, va_list args
, zend_hash_key
*hash_key
)
2549 php_http_option_t
*opt
= Z_PTR_P(pDest
);
2554 ht
= va_arg(args
, HashTable
*);
2556 if ((c
= zend_hash_num_elements(&opt
->suboptions
.options
))) {
2557 array_init_size(&entry
, c
);
2558 zend_hash_apply_with_arguments(&opt
->suboptions
.options
, apply_available_options
, 1, Z_ARRVAL(entry
));
2560 /* catch deliberate NULL options */
2561 if (Z_TYPE(opt
->defval
) == IS_STRING
&& !Z_STRVAL(opt
->defval
)) {
2564 ZVAL_ZVAL(&entry
, &opt
->defval
, 1, 0);
2568 if (hash_key
->key
) {
2569 zend_hash_update(ht
, hash_key
->key
, &entry
);
2571 zend_hash_index_update(ht
, hash_key
->h
, &entry
);
2574 return ZEND_HASH_APPLY_KEEP
;
2577 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
)
2579 php_http_client_enqueue_t
*enqueue
;
2582 case PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
:
2583 if ((enqueue
= php_http_client_enqueued(h
, arg
, NULL
))) {
2584 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2586 *((php_http_client_progress_state_t
**) res
) = &handler
->progress
;
2591 case PHP_HTTP_CLIENT_OPT_TRANSFER_INFO
:
2592 if ((enqueue
= php_http_client_enqueued(h
, arg
, NULL
))) {
2593 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2595 php_http_curle_get_info(handler
->handle
, *(HashTable
**) res
);
2600 case PHP_HTTP_CLIENT_OPT_AVAILABLE_OPTIONS
:
2601 zend_hash_apply_with_arguments(&php_http_curle_options
.options
, apply_available_options
, 1, *(HashTable
**) res
);
2604 case PHP_HTTP_CLIENT_OPT_AVAILABLE_CONFIGURATION
:
2605 zend_hash_apply_with_arguments(&php_http_curlm_options
.options
, apply_available_options
, 1, *(HashTable
**) res
);
2615 static php_http_client_ops_t php_http_client_curl_ops
= {
2616 &php_http_curlm_resource_factory_ops
,
2617 php_http_client_curl_init
,
2619 php_http_client_curl_dtor
,
2620 php_http_client_curl_reset
,
2621 php_http_client_curl_exec
,
2622 php_http_client_curl_wait
,
2623 php_http_client_curl_once
,
2624 php_http_client_curl_enqueue
,
2625 php_http_client_curl_dequeue
,
2626 php_http_client_curl_setopt
,
2627 php_http_client_curl_getopt
2630 php_http_client_ops_t
*php_http_client_curl_get_ops(void)
2632 return &php_http_client_curl_ops
;
2635 #define REGISTER_NS_STRING_OR_NULL_CONSTANT(ns, name, str, flags) \
2637 if ((str) != NULL) { \
2638 REGISTER_NS_STRING_CONSTANT(ns, name, str, flags); \
2640 REGISTER_NS_NULL_CONSTANT(ns, name, flags); \
2644 PHP_MINIT_FUNCTION(http_client_curl
)
2646 curl_version_info_data
*info
;
2647 php_http_options_t
*options
;
2649 PHP_HTTP_G
->client
.curl
.driver
.driver_name
= zend_string_init(ZEND_STRL("curl"), 1);
2650 PHP_HTTP_G
->client
.curl
.driver
.client_name
= zend_string_init(ZEND_STRL("http\\Client\\Curl"), 1);
2651 PHP_HTTP_G
->client
.curl
.driver
.request_name
= zend_string_init(ZEND_STRL("http\\Client\\Curl\\Request"), 1);
2652 PHP_HTTP_G
->client
.curl
.driver
.client_ops
= &php_http_client_curl_ops
;
2654 if (SUCCESS
!= php_http_client_driver_add(&PHP_HTTP_G
->client
.curl
.driver
)) {
2658 if (SUCCESS
!= php_persistent_handle_provide(PHP_HTTP_G
->client
.curl
.driver
.client_name
, &php_http_curlm_resource_factory_ops
, NULL
, NULL
)) {
2661 if (SUCCESS
!= php_persistent_handle_provide(PHP_HTTP_G
->client
.curl
.driver
.request_name
, &php_http_curle_resource_factory_ops
, NULL
, NULL
)) {
2665 if ((options
= php_http_options_init(&php_http_curle_options
, 1))) {
2666 options
->getter
= php_http_curle_get_option
;
2667 options
->setter
= php_http_curle_set_option
;
2669 php_http_curle_options_init(options
);
2671 if ((options
= php_http_options_init(&php_http_curlm_options
, 1))) {
2672 options
->getter
= php_http_option_get
;
2673 options
->setter
= php_http_curlm_set_option
;
2675 php_http_curlm_options_init(options
);
2678 if ((info
= curl_version_info(CURLVERSION_NOW
))) {
2679 char tmp_ver
[0x20], *tmp_ptr
, *tmp_end
;
2680 #define tmp_ver_init() do {\
2682 tmp_ptr = &tmp_ver[0]; \
2683 tmp_end = &tmp_ver[sizeof(tmp_ver) - 1]; \
2689 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "FEATURES", info
->features
, CONST_CS
|CONST_PERSISTENT
);
2691 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "IPV6", CURL_VERSION_IPV6
, CONST_CS
|CONST_PERSISTENT
);
2692 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "KERBEROS4", CURL_VERSION_KERBEROS4
, CONST_CS
|CONST_PERSISTENT
);
2693 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SSL", CURL_VERSION_SSL
, CONST_CS
|CONST_PERSISTENT
);
2694 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "LIBZ", CURL_VERSION_LIBZ
, CONST_CS
|CONST_PERSISTENT
);
2695 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "NTLM", CURL_VERSION_NTLM
, CONST_CS
|CONST_PERSISTENT
);
2696 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "GSSNEGOTIATE", CURL_VERSION_GSSNEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2697 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ASYNCHDNS", CURL_VERSION_ASYNCHDNS
, CONST_CS
|CONST_PERSISTENT
);
2698 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SPNEGO", CURL_VERSION_SPNEGO
, CONST_CS
|CONST_PERSISTENT
);
2699 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "LARGEFILE", CURL_VERSION_LARGEFILE
, CONST_CS
|CONST_PERSISTENT
);
2700 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "IDN", CURL_VERSION_IDN
, CONST_CS
|CONST_PERSISTENT
);
2701 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SSPI", CURL_VERSION_SSPI
, CONST_CS
|CONST_PERSISTENT
);
2702 #if PHP_HTTP_CURL_VERSION(7,21,4)
2703 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "TLSAUTH_SRP", CURL_VERSION_TLSAUTH_SRP
, CONST_CS
|CONST_PERSISTENT
);
2705 #if PHP_HTTP_CURL_VERSION(7,22,0)
2706 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "NTLM_WB", CURL_VERSION_NTLM_WB
, CONST_CS
|CONST_PERSISTENT
);
2708 #if PHP_HTTP_CURL_VERSION(7,33,0)
2709 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTP2", CURL_VERSION_HTTP2
, CONST_CS
|CONST_PERSISTENT
);
2711 #if PHP_HTTP_CURL_VERSION(7,38,0)
2712 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "GSSAPI", CURL_VERSION_GSSAPI
, CONST_CS
|CONST_PERSISTENT
);
2714 #if PHP_HTTP_CURL_VERSION(7,40,0)
2715 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "KERBEROS5", CURL_VERSION_KERBEROS5
, CONST_CS
|CONST_PERSISTENT
);
2716 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "UNIX_SOCKETS", CURL_VERSION_UNIX_SOCKETS
, CONST_CS
|CONST_PERSISTENT
);
2718 #if PHP_HTTP_CURL_VERSION(7,47,0)
2719 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "PSL", CURL_VERSION_PSL
, CONST_CS
|CONST_PERSISTENT
);
2721 #if PHP_HTTP_CURL_VERSION(7,52,0)
2722 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTPS_PROXY", CURL_VERSION_HTTPS_PROXY
, CONST_CS
|CONST_PERSISTENT
);
2724 #if PHP_HTTP_CURL_VERSION(7,56,0)
2725 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "MULTI_SSL", CURL_VERSION_MULTI_SSL
, CONST_CS
|CONST_PERSISTENT
);
2727 #if PHP_HTTP_CURL_VERSION(7,57,0)
2728 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "BROTLI", CURL_VERSION_BROTLI
, CONST_CS
|CONST_PERSISTENT
);
2730 #if PHP_HTTP_CURL_VERSION(7,64,1)
2731 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ALTSVC", CURL_VERSION_ALTSVC
, CONST_CS
|CONST_PERSISTENT
);
2733 #if PHP_HTTP_CURL_VERSION(7,66,0)
2734 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTP3", CURL_VERSION_HTTP3
, CONST_CS
|CONST_PERSISTENT
);
2736 #if PHP_HTTP_CURL_VERSION(7,72,0)
2737 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ZSTD", CURL_VERSION_ZSTD
, CONST_CS
|CONST_PERSISTENT
);
2738 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "UNICODE", CURL_VERSION_UNICODE
, CONST_CS
|CONST_PERSISTENT
);
2740 #if PHP_HTTP_CURL_VERSION(7,74,0)
2741 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HSTS", CURL_VERSION_HSTS
, CONST_CS
|CONST_PERSISTENT
);
2748 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl", "VERSIONS", curl_version(), CONST_CS
|CONST_PERSISTENT
);
2749 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "CURL", info
->version
, CONST_CS
|CONST_PERSISTENT
);
2750 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "SSL", info
->ssl_version
, CONST_CS
|CONST_PERSISTENT
);
2751 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "LIBZ", info
->libz_version
, CONST_CS
|CONST_PERSISTENT
);
2752 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ARES", info
->ares
, CONST_CS
|CONST_PERSISTENT
);
2753 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "IDN", info
->libidn
, CONST_CS
|CONST_PERSISTENT
);
2755 tmp_ptr
= zend_print_ulong_to_buf(tmp_end
, info
->iconv_ver_num
& 0xf);
2756 tmp_end
= tmp_ptr
- 1;
2757 tmp_ptr
= zend_print_ulong_to_buf(tmp_end
, info
->iconv_ver_num
>> 8);
2759 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ICONV", tmp_ptr
, CONST_CS
|CONST_PERSISTENT
);
2760 #if PHP_HTTP_CURL_VERSION(7,57,0)
2761 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "BROTLI", info
->brotli_version
, CONST_CS
|CONST_PERSISTENT
);
2763 #if PHP_HTTP_CURL_VERSION(7,66,0)
2764 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "NGHTTP2", info
->nghttp2_version
, CONST_CS
|CONST_PERSISTENT
);
2765 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "QUIC", info
->quic_version
, CONST_CS
|CONST_PERSISTENT
);
2767 #if PHP_HTTP_CURL_VERSION(7,70,0)
2768 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "CAINFO", info
->cainfo
, CONST_CS
|CONST_PERSISTENT
);
2769 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "CAPATH", info
->capath
, CONST_CS
|CONST_PERSISTENT
);
2771 #if PHP_HTTP_CURL_VERSION(7,72,0)
2772 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ZSTD", info
->zstd_version
, CONST_CS
|CONST_PERSISTENT
);
2774 #if PHP_HTTP_CURL_VERSION(7,75,0)
2775 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "HYPER", info
->hyper_version
, CONST_CS
|CONST_PERSISTENT
);
2781 * HTTP Protocol Version Constants
2783 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_1_0", CURL_HTTP_VERSION_1_0
, CONST_CS
|CONST_PERSISTENT
);
2784 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_1_1", CURL_HTTP_VERSION_1_1
, CONST_CS
|CONST_PERSISTENT
);
2785 #if PHP_HTTP_CURL_VERSION(7,33,0)
2786 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2_0", CURL_HTTP_VERSION_2_0
, CONST_CS
|CONST_PERSISTENT
);
2788 #if PHP_HTTP_CURL_VERSION(7,47,0)
2789 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2TLS", CURL_HTTP_VERSION_2TLS
, CONST_CS
|CONST_PERSISTENT
);
2791 #if PHP_HTTP_CURL_VERSION(7,49,0)
2792 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2_PRIOR_KNOWLEDGE", CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE
, CONST_CS
|CONST_PERSISTENT
);
2794 #if PHP_HTTP_CURL_VERSION(7,66,0)
2795 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_3", CURL_HTTP_VERSION_3
, CONST_CS
|CONST_PERSISTENT
);
2797 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_ANY", CURL_HTTP_VERSION_NONE
, CONST_CS
|CONST_PERSISTENT
);
2800 * SSL Version Constants
2802 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1", CURL_SSLVERSION_TLSv1
, CONST_CS
|CONST_PERSISTENT
);
2803 #if PHP_HTTP_CURL_VERSION(7,34,0)
2804 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_0", CURL_SSLVERSION_TLSv1_0
, CONST_CS
|CONST_PERSISTENT
);
2805 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_1", CURL_SSLVERSION_TLSv1_1
, CONST_CS
|CONST_PERSISTENT
);
2806 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_2", CURL_SSLVERSION_TLSv1_2
, CONST_CS
|CONST_PERSISTENT
);
2808 #if PHP_HTTP_CURL_VERSION(7,52,0)
2809 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_3", CURL_SSLVERSION_TLSv1_3
, CONST_CS
|CONST_PERSISTENT
);
2811 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv2", CURL_SSLVERSION_SSLv2
, CONST_CS
|CONST_PERSISTENT
);
2812 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv3", CURL_SSLVERSION_SSLv3
, CONST_CS
|CONST_PERSISTENT
);
2813 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_ANY", CURL_SSLVERSION_DEFAULT
, CONST_CS
|CONST_PERSISTENT
);
2814 #if PHP_HTTP_CURL_VERSION(7,21,4) && PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
2815 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "TLSAUTH_SRP", CURL_TLSAUTH_SRP
, CONST_CS
|CONST_PERSISTENT
);
2818 #if PHP_HTTP_CURL_VERSION(7,54,0)
2819 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_DEFAULT", CURL_SSLVERSION_MAX_DEFAULT
, CONST_CS
|CONST_PERSISTENT
);
2820 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_0", CURL_SSLVERSION_MAX_TLSv1_0
, CONST_CS
|CONST_PERSISTENT
);
2821 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_1", CURL_SSLVERSION_MAX_TLSv1_1
, CONST_CS
|CONST_PERSISTENT
);
2822 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_2", CURL_SSLVERSION_MAX_TLSv1_2
, CONST_CS
|CONST_PERSISTENT
);
2823 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_3", CURL_SSLVERSION_MAX_TLSv1_3
, CONST_CS
|CONST_PERSISTENT
);
2827 * DNS IPvX resolving
2829 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_V4", CURL_IPRESOLVE_V4
, CONST_CS
|CONST_PERSISTENT
);
2830 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_V6", CURL_IPRESOLVE_V6
, CONST_CS
|CONST_PERSISTENT
);
2831 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_ANY", CURL_IPRESOLVE_WHATEVER
, CONST_CS
|CONST_PERSISTENT
);
2836 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_NONE", CURLAUTH_NONE
, CONST_CS
|CONST_PERSISTENT
);
2837 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_BASIC", CURLAUTH_BASIC
, CONST_CS
|CONST_PERSISTENT
);
2838 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_DIGEST", CURLAUTH_DIGEST
, CONST_CS
|CONST_PERSISTENT
);
2839 #if PHP_HTTP_CURL_VERSION(7,19,3)
2840 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_DIGEST_IE", CURLAUTH_DIGEST_IE
, CONST_CS
|CONST_PERSISTENT
);
2842 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_NTLM", CURLAUTH_NTLM
, CONST_CS
|CONST_PERSISTENT
);
2843 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_GSSNEG", CURLAUTH_GSSNEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2844 #if PHP_HTTP_CURL_VERSION(7,38,0)
2845 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_SPNEGO", CURLAUTH_NEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2847 #if PHP_HTTP_CURL_VERSION(7,61,0)
2848 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_BEARER", CURLAUTH_BEARER
, CONST_CS
|CONST_PERSISTENT
);
2850 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_ANY", CURLAUTH_ANY
, CONST_CS
|CONST_PERSISTENT
);
2853 * Proxy Type Constants
2855 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS4", CURLPROXY_SOCKS4
, CONST_CS
|CONST_PERSISTENT
);
2856 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS4A", CURLPROXY_SOCKS4A
, CONST_CS
|CONST_PERSISTENT
);
2857 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS5_HOSTNAME", CURLPROXY_SOCKS5_HOSTNAME
, CONST_CS
|CONST_PERSISTENT
);
2858 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS5", CURLPROXY_SOCKS5
, CONST_CS
|CONST_PERSISTENT
);
2859 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_HTTP", CURLPROXY_HTTP
, CONST_CS
|CONST_PERSISTENT
);
2860 #if PHP_HTTP_CURL_VERSION(7,19,4)
2861 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_HTTP_1_0", CURLPROXY_HTTP_1_0
, CONST_CS
|CONST_PERSISTENT
);
2865 * Post Redirection Constants
2867 #if PHP_HTTP_CURL_VERSION(7,19,1)
2868 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_301", CURL_REDIR_POST_301
, CONST_CS
|CONST_PERSISTENT
);
2869 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_302", CURL_REDIR_POST_302
, CONST_CS
|CONST_PERSISTENT
);
2870 #if PHP_HTTP_CURL_VERSION(7,26,0)
2871 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_303", CURL_REDIR_POST_303
, CONST_CS
|CONST_PERSISTENT
);
2873 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_ALL", CURL_REDIR_POST_ALL
, CONST_CS
|CONST_PERSISTENT
);
2876 #if PHP_HTTP_CURL_VERSION(7,64,1)
2877 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_READONLYFILE", CURLALTSVC_READONLYFILE
, CONST_CS
|CONST_PERSISTENT
);
2878 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_H1", CURLALTSVC_H1
, CONST_CS
|CONST_PERSISTENT
);
2879 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_H2", CURLALTSVC_H2
, CONST_CS
|CONST_PERSISTENT
);
2880 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_H3", CURLALTSVC_H3
, CONST_CS
|CONST_PERSISTENT
);
2885 PHP_MSHUTDOWN_FUNCTION(http_client_curl
)
2887 php_persistent_handle_cleanup(PHP_HTTP_G
->client
.curl
.driver
.client_name
, NULL
);
2888 php_persistent_handle_cleanup(PHP_HTTP_G
->client
.curl
.driver
.request_name
, NULL
);
2889 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.client_name
);
2890 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.request_name
);
2891 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.driver_name
);
2893 php_http_options_dtor(&php_http_curle_options
);
2894 php_http_options_dtor(&php_http_curlm_options
);
2899 #endif /* PHP_HTTP_HAVE_LIBCURL */
2906 * vim600: noet sw=4 ts=4 fdm=marker
2907 * vim<600: noet sw=4 ts=4