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
)
334 struct curl_slist
*s
= NULL
, *p
= NULL
;
339 /* BEGIN::CURLINFO */
340 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_EFFECTIVE_URL
, &c
)) {
341 ZVAL_STRING(&tmp
, STR_PTR(c
));
342 zend_hash_str_update(info
, "effective_url", lenof("effective_url"), &tmp
);
344 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_RESPONSE_CODE
, &l
)) {
346 zend_hash_str_update(info
, "response_code", lenof("response_code"), &tmp
);
348 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TOTAL_TIME
, &d
)) {
349 ZVAL_DOUBLE(&tmp
, d
);
350 zend_hash_str_update(info
, "total_time", lenof("total_time"), &tmp
);
352 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_NAMELOOKUP_TIME
, &d
)) {
353 ZVAL_DOUBLE(&tmp
, d
);
354 zend_hash_str_update(info
, "namelookup_time", lenof("namelookup_time"), &tmp
);
356 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONNECT_TIME
, &d
)) {
357 ZVAL_DOUBLE(&tmp
, d
);
358 zend_hash_str_update(info
, "connect_time", lenof("connect_time"), &tmp
);
360 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRETRANSFER_TIME
, &d
)) {
361 ZVAL_DOUBLE(&tmp
, d
);
362 zend_hash_str_update(info
, "pretransfer_time", lenof("pretransfer_time"), &tmp
);
364 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SIZE_UPLOAD
, &d
)) {
365 ZVAL_DOUBLE(&tmp
, d
);
366 zend_hash_str_update(info
, "size_upload", lenof("size_upload"), &tmp
);
368 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SIZE_DOWNLOAD
, &d
)) {
369 ZVAL_DOUBLE(&tmp
, d
);
370 zend_hash_str_update(info
, "size_download", lenof("size_download"), &tmp
);
372 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_DOWNLOAD
, &d
)) {
373 ZVAL_DOUBLE(&tmp
, d
);
374 zend_hash_str_update(info
, "speed_download", lenof("speed_download"), &tmp
);
376 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_UPLOAD
, &d
)) {
377 ZVAL_DOUBLE(&tmp
, d
);
378 zend_hash_str_update(info
, "speed_upload", lenof("speed_upload"), &tmp
);
380 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HEADER_SIZE
, &l
)) {
382 zend_hash_str_update(info
, "header_size", lenof("header_size"), &tmp
);
384 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REQUEST_SIZE
, &l
)) {
386 zend_hash_str_update(info
, "request_size", lenof("request_size"), &tmp
);
388 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SSL_VERIFYRESULT
, &l
)) {
390 zend_hash_str_update(info
, "ssl_verifyresult", lenof("ssl_verifyresult"), &tmp
);
392 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_FILETIME
, &l
)) {
394 zend_hash_str_update(info
, "filetime", lenof("filetime"), &tmp
);
396 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_DOWNLOAD
, &d
)) {
397 ZVAL_DOUBLE(&tmp
, d
);
398 zend_hash_str_update(info
, "content_length_download", lenof("content_length_download"), &tmp
);
400 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_UPLOAD
, &d
)) {
401 ZVAL_DOUBLE(&tmp
, d
);
402 zend_hash_str_update(info
, "content_length_upload", lenof("content_length_upload"), &tmp
);
404 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_STARTTRANSFER_TIME
, &d
)) {
405 ZVAL_DOUBLE(&tmp
, d
);
406 zend_hash_str_update(info
, "starttransfer_time", lenof("starttransfer_time"), &tmp
);
408 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_TYPE
, &c
)) {
409 ZVAL_STRING(&tmp
, STR_PTR(c
));
410 zend_hash_str_update(info
, "content_type", lenof("content_type"), &tmp
);
412 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_TIME
, &d
)) {
413 ZVAL_DOUBLE(&tmp
, d
);
414 zend_hash_str_update(info
, "redirect_time", lenof("redirect_time"), &tmp
);
416 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_COUNT
, &l
)) {
418 zend_hash_str_update(info
, "redirect_count", lenof("redirect_count"), &tmp
);
420 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTP_CONNECTCODE
, &l
)) {
422 zend_hash_str_update(info
, "connect_code", lenof("connect_code"), &tmp
);
424 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTPAUTH_AVAIL
, &l
)) {
426 zend_hash_str_update(info
, "httpauth_avail", lenof("httpauth_avail"), &tmp
);
428 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXYAUTH_AVAIL
, &l
)) {
430 zend_hash_str_update(info
, "proxyauth_avail", lenof("proxyauth_avail"), &tmp
);
432 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_OS_ERRNO
, &l
)) {
434 zend_hash_str_update(info
, "os_errno", lenof("os_errno"), &tmp
);
436 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_NUM_CONNECTS
, &l
)) {
438 zend_hash_str_update(info
, "num_connects", lenof("num_connects"), &tmp
);
440 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SSL_ENGINES
, &s
)) {
442 for (p
= s
; p
; p
= p
->next
) {
444 add_next_index_string(&tmp
, p
->data
);
447 zend_hash_str_update(info
, "ssl_engines", lenof("ssl_engines"), &tmp
);
448 curl_slist_free_all(s
);
450 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_URL
, &c
)) {
451 ZVAL_STRING(&tmp
, STR_PTR(c
));
452 zend_hash_str_update(info
, "redirect_url", lenof("redirect_url"), &tmp
);
454 #if PHP_HTTP_CURL_VERSION(7,19,0)
455 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRIMARY_IP
, &c
)) {
456 ZVAL_STRING(&tmp
, STR_PTR(c
));
457 zend_hash_str_update(info
, "primary_ip", lenof("primary_ip"), &tmp
);
460 #if PHP_HTTP_CURL_VERSION(7,19,0)
461 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_APPCONNECT_TIME
, &d
)) {
462 ZVAL_DOUBLE(&tmp
, d
);
463 zend_hash_str_update(info
, "appconnect_time", lenof("appconnect_time"), &tmp
);
466 #if PHP_HTTP_CURL_VERSION(7,19,4)
467 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONDITION_UNMET
, &l
)) {
469 zend_hash_str_update(info
, "condition_unmet", lenof("condition_unmet"), &tmp
);
472 #if PHP_HTTP_CURL_VERSION(7,21,0)
473 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRIMARY_PORT
, &l
)) {
475 zend_hash_str_update(info
, "primary_port", lenof("primary_port"), &tmp
);
478 #if PHP_HTTP_CURL_VERSION(7,21,0)
479 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_LOCAL_IP
, &c
)) {
480 ZVAL_STRING(&tmp
, STR_PTR(c
));
481 zend_hash_str_update(info
, "local_ip", lenof("local_ip"), &tmp
);
484 #if PHP_HTTP_CURL_VERSION(7,21,0)
485 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_LOCAL_PORT
, &l
)) {
487 zend_hash_str_update(info
, "local_port", lenof("local_port"), &tmp
);
490 #if PHP_HTTP_CURL_VERSION(7,50,0)
491 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTP_VERSION
, &l
)) {
493 zend_hash_str_update(info
, "http_version", lenof("http_version"), &tmp
);
496 #if PHP_HTTP_CURL_VERSION(7,52,0)
497 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXY_SSL_VERIFYRESULT
, &l
)) {
499 zend_hash_str_update(info
, "proxy_ssl_verifyresult", lenof("proxy_ssl_verifyresult"), &tmp
);
502 #if PHP_HTTP_CURL_VERSION(7,52,0)
503 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROTOCOL
, &l
)) {
505 zend_hash_str_update(info
, "protocol", lenof("protocol"), &tmp
);
508 #if PHP_HTTP_CURL_VERSION(7,52,0)
509 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SCHEME
, &c
)) {
510 ZVAL_STRING(&tmp
, STR_PTR(c
));
511 zend_hash_str_update(info
, "scheme", lenof("scheme"), &tmp
);
514 #if PHP_HTTP_CURL_VERSION(7,66,0)
515 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_RETRY_AFTER
, &o
)) {
517 zend_hash_str_update(info
, "retry_after", lenof("retry_after"), &tmp
);
520 #if PHP_HTTP_CURL_VERSION(7,72,0)
521 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_EFFECTIVE_METHOD
, &c
)) {
522 ZVAL_STRING(&tmp
, STR_PTR(c
));
523 zend_hash_str_update(info
, "effective_method", lenof("effective_method"), &tmp
);
526 #if PHP_HTTP_CURL_VERSION(7,73,0)
527 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXY_ERROR
, &l
)) {
529 zend_hash_str_update(info
, "proxy_error", lenof("proxy_error"), &tmp
);
535 #if PHP_HTTP_CURL_VERSION(7,34,0)
537 zval ti_array
, subarray
;
538 struct curl_tlssessioninfo
*ti
;
540 #if PHP_HTTP_CURL_VERSION(7,48,0)
541 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TLS_SSL_PTR
, &ti
)) {
543 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TLS_SESSION
, &ti
)) {
547 ZVAL_NULL(&subarray
);
548 array_init(&ti_array
);
550 switch (ti
->backend
) {
551 case CURLSSLBACKEND_NONE
:
554 case CURLSSLBACKEND_OPENSSL
:
556 #if PHP_HTTP_HAVE_LIBCURL_OPENSSL
558 #if PHP_HTTP_CURL_VERSION(7,48,0)
559 SSL
*ssl
= ti
->internals
;
560 SSL_CTX
*ctx
= ssl
? SSL_get_SSL_CTX(ssl
) : NULL
;
562 SSL_CTX
*ctx
= ti
->internals
;
565 array_init(&subarray
);
567 add_assoc_long_ex(&subarray
, ZEND_STRL("number"), SSL_CTX_sess_number(ctx
));
568 add_assoc_long_ex(&subarray
, ZEND_STRL("connect"), SSL_CTX_sess_connect(ctx
));
569 add_assoc_long_ex(&subarray
, ZEND_STRL("connect_good"), SSL_CTX_sess_connect_good(ctx
));
570 add_assoc_long_ex(&subarray
, ZEND_STRL("connect_renegotiate"), SSL_CTX_sess_connect_renegotiate(ctx
));
571 add_assoc_long_ex(&subarray
, ZEND_STRL("hits"), SSL_CTX_sess_hits(ctx
));
572 add_assoc_long_ex(&subarray
, ZEND_STRL("cache_full"), SSL_CTX_sess_cache_full(ctx
));
577 case CURLSSLBACKEND_GNUTLS
:
579 #if PHP_HTTP_HAVE_LIBCURL_GNUTLS
581 gnutls_session_t sess
= ti
->internals
;
584 array_init(&subarray
);
586 if ((desc
= gnutls_session_get_desc(sess
))) {
587 add_assoc_string_ex(&subarray
, ZEND_STRL("desc"), desc
);
590 add_assoc_bool_ex(&subarray
, ZEND_STRL("resumed"), gnutls_session_is_resumed(sess
));
595 case CURLSSLBACKEND_NSS
:
598 #if !PHP_HTTP_CURL_VERSION(7,39,0)
599 case CURLSSLBACKEND_QSOSSL
:
603 case CURLSSLBACKEND_GSKIT
:
607 case CURLSSLBACKEND_POLARSSL
:
608 backend
= "polarssl";
610 case CURLSSLBACKEND_CYASSL
:
613 case CURLSSLBACKEND_SCHANNEL
:
614 backend
= "schannel";
616 case CURLSSLBACKEND_DARWINSSL
:
617 backend
= "darwinssl";
622 add_assoc_string_ex(&ti_array
, ZEND_STRL("backend"), backend
);
623 add_assoc_zval_ex(&ti_array
, ZEND_STRL("internals"), &subarray
);
624 zend_hash_str_update(info
, "tls_session", lenof("tls_session"), &ti_array
);
629 #if (PHP_HTTP_CURL_VERSION(7,19,1) && PHP_HTTP_HAVE_LIBCURL_OPENSSL) || \
630 (PHP_HTTP_CURL_VERSION(7,34,0) && PHP_HTTP_HAVE_LIBCURL_NSS) || \
631 (PHP_HTTP_CURL_VERSION(7,42,0) && PHP_HTTP_HAVE_LIBCURL_GNUTLS) || \
632 (PHP_HTTP_CURL_VERSION(7,39,0) && PHP_HTTP_HAVE_LIBCURL_GSKIT)
635 zval ci_array
, subarray
;
636 struct curl_certinfo
*ci
;
637 char *colon
, *keyname
;
639 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CERTINFO
, &ci
)) {
640 array_init(&ci_array
);
642 for (i
= 0; i
< ci
->num_of_certs
; ++i
) {
645 array_init(&subarray
);
646 for (p
= s
; p
; p
= p
->next
) {
648 if ((colon
= strchr(p
->data
, ':'))) {
649 keyname
= estrndup(p
->data
, colon
- p
->data
);
650 add_assoc_string_ex(&subarray
, keyname
, colon
- p
->data
, colon
+ 1);
653 add_next_index_string(&subarray
, p
->data
);
657 add_next_index_zval(&ci_array
, &subarray
);
659 zend_hash_str_update(info
, "certinfo", lenof("certinfo"), &ci_array
);
664 php_http_curle_storage_t
*st
= php_http_curle_get_storage(ch
);
666 ZVAL_LONG(&tmp
, st
->errorcode
);
667 zend_hash_str_update(info
, "curlcode", lenof("curlcode"), &tmp
);
668 ZVAL_STRING(&tmp
, st
->errorbuffer
);
669 zend_hash_str_update(info
, "error", lenof("error"), &tmp
);
675 static int compare_queue(php_http_client_enqueue_t
*e
, void *handle
)
677 return handle
== ((php_http_client_curl_handler_t
*) e
->opaque
)->handle
;
680 static php_http_message_t
*php_http_curlm_responseparser(php_http_client_curl_handler_t
*h
)
682 php_http_message_t
*response
;
683 php_http_header_parser_t parser
;
686 response
= php_http_message_init(NULL
, 0, h
->response
.body
);
687 php_http_header_parser_init(&parser
);
688 while (h
->response
.headers
.used
) {
689 php_http_header_parser_state_t st
= php_http_header_parser_parse(&parser
,
690 &h
->response
.headers
, PHP_HTTP_HEADER_PARSER_CLEANUP
, &response
->hdrs
,
691 (php_http_info_callback_t
) php_http_message_info_callback
, (void *) &response
);
692 if (PHP_HTTP_HEADER_PARSER_STATE_FAILURE
== st
) {
696 php_http_header_parser_dtor(&parser
);
698 /* move body to right message */
699 if (response
->body
!= h
->response
.body
) {
700 php_http_message_t
*ptr
= response
;
702 while (ptr
->parent
) {
705 php_http_message_body_free(&response
->body
);
706 response
->body
= ptr
->body
;
709 php_http_message_body_addref(h
->response
.body
);
711 /* let's update the response headers */
712 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Length")))) {
714 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Length", lenof("X-Original-Content-Length"), &tmp
);
716 if ((zh
= php_http_message_header(response
, ZEND_STRL("Transfer-Encoding")))) {
718 zend_hash_str_del(&response
->hdrs
, "Transfer-Encoding", lenof("Transfer-Encoding"));
719 zend_hash_str_update(&response
->hdrs
, "X-Original-Transfer-Encoding", lenof("X-Original-Transfer-Encoding"), &tmp
);
721 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Range")))) {
723 zend_hash_str_del(&response
->hdrs
, "Content-Range", lenof("Content-Range"));
724 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Range", lenof("X-Original-Content-Range"), &tmp
);
726 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Encoding")))) {
728 zend_hash_str_del(&response
->hdrs
, "Content-Encoding", lenof("Content-Encoding"));
729 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Encoding", lenof("X-Original-Content-Encoding"), &tmp
);
731 php_http_message_update_headers(response
);
736 void php_http_client_curl_responsehandler(php_http_client_t
*context
)
738 int err_count
= 0, remaining
= 0;
739 php_http_curle_storage_t
*st
, *err
= NULL
;
740 php_http_client_enqueue_t
*enqueue
;
741 php_http_client_curl_t
*curl
= context
->ctx
;
744 CURLMsg
*msg
= curl_multi_info_read(curl
->handle
->multi
, &remaining
);
746 if (msg
&& CURLMSG_DONE
== msg
->msg
) {
747 if (CURLE_OK
!= msg
->data
.result
) {
748 st
= php_http_curle_get_storage(msg
->easy_handle
);
749 st
->errorcode
= msg
->data
.result
;
751 /* defer the warnings/exceptions, so the callback is still called for this request */
753 err
= ecalloc(remaining
+ 1, sizeof(*err
));
755 memcpy(&err
[err_count
], st
, sizeof(*st
));
757 err
[err_count
].url
= estrdup(st
->url
);
762 if ((enqueue
= php_http_client_enqueued(context
, msg
->easy_handle
, compare_queue
))) {
763 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
764 php_http_message_t
*response
= php_http_curlm_responseparser(handler
);
767 context
->callback
.response
.func(context
->callback
.response
.arg
, context
, &handler
->queue
, &response
);
768 php_http_message_free(&response
);
778 php_error_docref(NULL
, E_WARNING
, "%s; %s (%s)", curl_easy_strerror(err
[i
].errorcode
), err
[i
].errorbuffer
, STR_PTR(err
[i
].url
));
782 } while (++i
< err_count
);
788 void php_http_client_curl_loop(php_http_client_t
*client
, curl_socket_t s
, int curl_action
)
791 php_http_client_curl_t
*curl
= client
->ctx
;
794 fprintf(stderr
, "H");
798 rc
= curl_multi_socket_action(curl
->handle
->multi
, s
, curl_action
, &curl
->unfinished
);
799 } while (CURLM_CALL_MULTI_PERFORM
== rc
);
801 if (CURLM_OK
!= rc
) {
802 php_error_docref(NULL
, E_WARNING
, "%s", curl_multi_strerror(rc
));
805 php_http_client_curl_responsehandler(client
);
810 static php_http_options_t php_http_curle_options
, php_http_curlm_options
;
812 #define PHP_HTTP_CURLE_OPTION_CHECK_STRLEN 0x0001
813 #define PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR 0x0002
814 #define PHP_HTTP_CURLE_OPTION_TRANSFORM_MS 0x0004
815 #define PHP_HTTP_CURLE_OPTION_IGNORE_RC 0x0008
817 static ZEND_RESULT_CODE
php_http_curle_option_set_ssl_verifyhost(php_http_option_t
*opt
, zval
*val
, void *userdata
)
819 php_http_client_curl_handler_t
*curl
= userdata
;
820 CURL
*ch
= curl
->handle
;
822 if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, Z_TYPE_P(val
) == IS_TRUE
? 2 : 0)) {
828 static ZEND_RESULT_CODE
php_http_curle_option_set_cookiesession(php_http_option_t
*opt
, zval
*val
, void *userdata
)
830 php_http_client_curl_handler_t
*curl
= userdata
;
831 CURL
*ch
= curl
->handle
;
833 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIESESSION
, (long) (Z_TYPE_P(val
) == IS_TRUE
))) {
836 if (Z_TYPE_P(val
) == IS_TRUE
) {
837 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIELIST
, "SESS")) {
845 static ZEND_RESULT_CODE
php_http_curle_option_set_cookiestore(php_http_option_t
*opt
, zval
*val
, void *userdata
)
847 php_http_client_curl_handler_t
*curl
= userdata
;
848 CURL
*ch
= curl
->handle
;
849 php_http_curle_storage_t
*storage
= php_http_curle_get_storage(curl
->handle
);
851 if (storage
->cookiestore
) {
852 pefree(storage
->cookiestore
, 1);
854 if (val
&& Z_TYPE_P(val
) == IS_STRING
&& Z_STRLEN_P(val
)) {
855 storage
->cookiestore
= pestrndup(Z_STRVAL_P(val
), Z_STRLEN_P(val
), 1);
857 storage
->cookiestore
= NULL
;
859 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIEFILE
, storage
->cookiestore
? storage
->cookiestore
: "")
860 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIEJAR
, storage
->cookiestore
)
868 static ZEND_RESULT_CODE
php_http_curle_option_set_cookies(php_http_option_t
*opt
, zval
*val
, void *userdata
)
870 php_http_client_curl_handler_t
*curl
= userdata
;
871 CURL
*ch
= curl
->handle
;
873 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
874 HashTable
*ht
= HASH_OF(val
);
876 if (curl
->options
.encode_cookies
) {
877 if (SUCCESS
== php_http_url_encode_hash_ex(ht
, &curl
->options
.cookies
, ZEND_STRL(";"), ZEND_STRL("="), NULL
, 0)) {
878 php_http_buffer_fix(&curl
->options
.cookies
);
879 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, curl
->options
.cookies
.data
)) {
886 php_http_arrkey_t cookie_key
;
889 ZEND_HASH_FOREACH_KEY_VAL(ht
, cookie_key
.h
, cookie_key
.key
, cookie_val
)
891 zend_string
*zs
= zval_get_string(cookie_val
);
893 php_http_arrkey_stringify(&cookie_key
, NULL
);
894 php_http_buffer_appendf(&curl
->options
.cookies
, "%s=%s; ", cookie_key
.key
->val
, zs
->val
);
895 php_http_arrkey_dtor(&cookie_key
);
897 zend_string_release(zs
);
899 ZEND_HASH_FOREACH_END();
901 php_http_buffer_fix(&curl
->options
.cookies
);
902 if (curl
->options
.cookies
.used
) {
903 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, curl
->options
.cookies
.data
)) {
909 php_http_buffer_reset(&curl
->options
.cookies
);
910 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, NULL
)) {
917 static ZEND_RESULT_CODE
php_http_curle_option_set_encodecookies(php_http_option_t
*opt
, zval
*val
, void *userdata
)
919 php_http_client_curl_handler_t
*curl
= userdata
;
921 curl
->options
.encode_cookies
= Z_TYPE_P(val
) == IS_TRUE
;
925 static ZEND_RESULT_CODE
php_http_curle_option_set_lastmodified(php_http_option_t
*opt
, zval
*val
, void *userdata
)
927 php_http_client_curl_handler_t
*curl
= userdata
;
928 CURL
*ch
= curl
->handle
;
931 if (Z_LVAL_P(val
) > 0) {
932 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, Z_LVAL_P(val
))) {
936 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, (long) sapi_get_request_time() + Z_LVAL_P(val
))) {
940 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMECONDITION
, (long) (curl
->options
.range_request
? CURL_TIMECOND_IFUNMODSINCE
: CURL_TIMECOND_IFMODSINCE
))) {
944 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, 0)
945 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMECONDITION
, 0)
953 #if PHP_HTTP_CURL_VERSION(7,64,1)
954 static ZEND_RESULT_CODE
php_http_curle_option_set_altsvc_ctrl(php_http_option_t
*opt
, zval
*val
, void *userdata
)
956 php_http_client_curl_handler_t
*curl
= userdata
;
957 CURL
*ch
= curl
->handle
;
960 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_ALTSVC_CTRL
, Z_LVAL_P(val
))) {
968 static ZEND_RESULT_CODE
php_http_curle_option_set_compress(php_http_option_t
*opt
, zval
*val
, void *userdata
)
970 php_http_client_curl_handler_t
*curl
= userdata
;
971 CURL
*ch
= curl
->handle
;
973 #if !PHP_HTTP_CURL_VERSION(7,21,6)
974 # define CURLOPT_ACCEPT_ENCODING CURLOPT_ENCODING
976 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_ACCEPT_ENCODING
, Z_TYPE_P(val
) == IS_TRUE
? "" : NULL
)) {
982 static ZEND_RESULT_CODE
php_http_curle_option_set_etag(php_http_option_t
*opt
, zval
*val
, void *userdata
)
984 php_http_client_curl_handler_t
*curl
= userdata
;
985 php_http_buffer_t header
;
987 if (val
&& Z_TYPE_P(val
) == IS_STRING
&& Z_STRLEN_P(val
)) {
988 zend_bool is_quoted
= !((Z_STRVAL_P(val
)[0] != '"') || (Z_STRVAL_P(val
)[Z_STRLEN_P(val
)-1] != '"'));
989 php_http_buffer_init(&header
);
990 php_http_buffer_appendf(&header
, is_quoted
?"%s: %s":"%s: \"%s\"", curl
->options
.range_request
?"If-Match":"If-None-Match", Z_STRVAL_P(val
));
991 php_http_buffer_fix(&header
);
992 curl
->options
.headers
= curl_slist_append(curl
->options
.headers
, header
.data
);
993 php_http_buffer_dtor(&header
);
998 static ZEND_RESULT_CODE
php_http_curle_option_set_range(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1000 php_http_client_curl_handler_t
*curl
= userdata
;
1001 CURL
*ch
= curl
->handle
;
1003 php_http_buffer_reset(&curl
->options
.ranges
);
1005 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1007 HashTable
*ht
= HASH_OF(val
);
1009 ZEND_HASH_FOREACH_VAL(ht
, rr
)
1011 if (Z_TYPE_P(rr
) == IS_ARRAY
) {
1012 if (2 == php_http_array_list(Z_ARRVAL_P(rr
), 2, &rb
, &re
)) {
1013 zend_long rbl
= zval_get_long(rb
), rel
= zval_get_long(re
);
1017 php_http_buffer_appendf(&curl
->options
.ranges
, "%ld-%ld,", rbl
, rel
);
1019 php_http_buffer_appendf(&curl
->options
.ranges
, "%ld-", rbl
);
1021 } else if (rel
> 0) {
1022 php_http_buffer_appendf(&curl
->options
.ranges
, "-%ld", rel
);
1027 ZEND_HASH_FOREACH_END();
1029 if (curl
->options
.ranges
.used
) {
1030 curl
->options
.range_request
= 1;
1031 /* ditch last comma */
1032 curl
->options
.ranges
.data
[curl
->options
.ranges
.used
- 1] = '\0';
1036 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RANGE
, curl
->options
.ranges
.data
)) {
1042 static ZEND_RESULT_CODE
php_http_curle_option_set_resume(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1044 php_http_client_curl_handler_t
*curl
= userdata
;
1045 CURL
*ch
= curl
->handle
;
1047 if (Z_LVAL_P(val
) > 0) {
1048 curl
->options
.range_request
= 1;
1050 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESUME_FROM
, Z_LVAL_P(val
))) {
1056 static ZEND_RESULT_CODE
php_http_curle_option_set_retrydelay(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1058 php_http_client_curl_handler_t
*curl
= userdata
;
1060 curl
->options
.retry
.delay
= Z_DVAL_P(val
);
1064 static ZEND_RESULT_CODE
php_http_curle_option_set_retrycount(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1066 php_http_client_curl_handler_t
*curl
= userdata
;
1068 curl
->options
.retry
.count
= Z_LVAL_P(val
);
1072 static ZEND_RESULT_CODE
php_http_curle_option_set_redirect(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1074 php_http_client_curl_handler_t
*curl
= userdata
;
1075 CURL
*ch
= curl
->handle
;
1077 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, Z_LVAL_P(val
) ? 1L : 0L)
1078 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_MAXREDIRS
, curl
->options
.redirects
= Z_LVAL_P(val
))
1085 static ZEND_RESULT_CODE
php_http_curle_option_set_portrange(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1087 php_http_client_curl_handler_t
*curl
= userdata
;
1088 CURL
*ch
= curl
->handle
;
1089 long localport
= 0, localportrange
= 0;
1091 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1094 switch (php_http_array_list(Z_ARRVAL_P(val
), 2, &zps
, &zpe
)) {
1096 localportrange
= labs(zval_get_long(zps
)-zval_get_long(zpe
))+1L;
1099 localport
= (zval_get_long(zpe
) > 0) ? MIN(zval_get_long(zps
), zval_get_long(zpe
)) : zval_get_long(zps
);
1105 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_LOCALPORT
, localport
)
1106 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_LOCALPORTRANGE
, localportrange
)
1113 #if PHP_HTTP_CURL_VERSION(7,37,0)
1114 static ZEND_RESULT_CODE
php_http_curle_option_set_proxyheader(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1116 php_http_client_curl_handler_t
*curl
= userdata
;
1118 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1119 php_http_arrkey_t header_key
;
1121 php_http_buffer_t header
;
1123 php_http_buffer_init(&header
);
1124 ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(val
), header_key
.h
, header_key
.key
, header_val
)
1126 if (header_key
.key
) {
1127 zend_string
*zs
= zval_get_string(header_val
);
1129 php_http_buffer_appendf(&header
, "%s: %s", header_key
.key
->val
, zs
->val
);
1130 zend_string_release(zs
);
1132 php_http_buffer_fix(&header
);
1133 curl
->options
.proxyheaders
= curl_slist_append(curl
->options
.proxyheaders
, header
.data
);
1134 php_http_buffer_reset(&header
);
1138 ZEND_HASH_FOREACH_END();
1139 php_http_buffer_dtor(&header
);
1141 if (CURLE_OK
!= curl_easy_setopt(curl
->handle
, CURLOPT_PROXYHEADER
, curl
->options
.proxyheaders
)) {
1144 if (CURLE_OK
!= curl_easy_setopt(curl
->handle
, CURLOPT_HEADEROPT
, CURLHEADER_SEPARATE
)) {
1145 curl_easy_setopt(curl
->handle
, CURLOPT_PROXYHEADER
, NULL
);
1152 #if PHP_HTTP_CURL_VERSION(7,21,3)
1153 static ZEND_RESULT_CODE
php_http_curle_option_set_resolve(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1155 php_http_client_curl_handler_t
*curl
= userdata
;
1156 CURL
*ch
= curl
->handle
;
1158 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1159 HashTable
*ht
= HASH_OF(val
);
1162 ZEND_HASH_FOREACH_VAL(ht
, data
)
1164 zend_string
*zs
= zval_get_string(data
);
1165 curl
->options
.resolve
= curl_slist_append(curl
->options
.resolve
, zs
->val
);
1166 zend_string_release(zs
);
1168 ZEND_HASH_FOREACH_END();
1170 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESOLVE
, curl
->options
.resolve
)) {
1174 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESOLVE
, NULL
)) {
1182 #if PHP_HTTP_CURL_VERSION(7,21,4) && PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
1183 static ZEND_RESULT_CODE
php_http_curle_option_set_ssl_tlsauthtype(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1185 php_http_client_curl_handler_t
*curl
= userdata
;
1186 CURL
*ch
= curl
->handle
;
1188 if (val
&& Z_LVAL_P(val
)) {
1189 switch (Z_LVAL_P(val
)) {
1190 case CURL_TLSAUTH_SRP
:
1191 if (CURLE_OK
== curl_easy_setopt(ch
, opt
->option
, PHP_HTTP_LIBCURL_TLSAUTH_SRP
)) {
1199 if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, PHP_HTTP_LIBCURL_TLSAUTH_DEF
)) {
1206 static void php_http_curle_options_init(php_http_options_t
*registry
)
1208 php_http_option_t
*opt
;
1211 #if PHP_HTTP_CURL_VERSION(7,42,0)
1212 php_http_option_register(registry
, ZEND_STRL("path_as_is"), CURLOPT_PATH_AS_IS
, _IS_BOOL
);
1216 php_http_option_register(registry
, ZEND_STRL("proxyhost"), CURLOPT_PROXY
, IS_STRING
);
1217 php_http_option_register(registry
, ZEND_STRL("proxytype"), CURLOPT_PROXYTYPE
, IS_LONG
);
1218 php_http_option_register(registry
, ZEND_STRL("proxyport"), CURLOPT_PROXYPORT
, IS_LONG
);
1219 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyauth"), CURLOPT_PROXYUSERPWD
, IS_STRING
))) {
1220 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1222 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyauthtype"), CURLOPT_PROXYAUTH
, IS_LONG
))) {
1223 Z_LVAL(opt
->defval
) = CURLAUTH_ANYSAFE
;
1225 php_http_option_register(registry
, ZEND_STRL("proxytunnel"), CURLOPT_HTTPPROXYTUNNEL
, _IS_BOOL
);
1226 #if PHP_HTTP_CURL_VERSION(7,19,4)
1227 php_http_option_register(registry
, ZEND_STRL("noproxy"), CURLOPT_NOPROXY
, IS_STRING
);
1229 #if PHP_HTTP_CURL_VERSION(7,55,0)
1230 php_http_option_register(registry
, ZEND_STRL("socks5_auth"), CURLOPT_SOCKS5_AUTH
, IS_LONG
);
1233 #if PHP_HTTP_CURL_VERSION(7,37,0)
1234 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyheader"), CURLOPT_PROXYHEADER
, IS_ARRAY
))) {
1235 opt
->setter
= php_http_curle_option_set_proxyheader
;
1238 #if PHP_HTTP_CURL_VERSION(7,43,0)
1239 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_GSSAPI
)
1240 && (opt
= php_http_option_register(registry
, ZEND_STRL("proxy_service_name"), CURLOPT_PROXY_SERVICE_NAME
, IS_STRING
))
1242 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1245 #if PHP_HTTP_CURL_VERSION(7,60,0)
1246 php_http_option_register(registry
, ZEND_STRL("haproxy_protocol"), CURLOPT_HAPROXYPROTOCOL
, _IS_BOOL
);
1250 #if PHP_HTTP_CURL_VERSION(7,40,0)
1251 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_UNIX_SOCKETS
)) {
1252 if ((opt
= php_http_option_register(registry
, ZEND_STRL("unix_socket_path"), CURLOPT_UNIX_SOCKET_PATH
, IS_STRING
))) {
1253 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1254 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1256 #if PHP_HTTP_CURL_VERSION(7,53,0)
1257 if ((opt
= php_http_option_register(registry
, ZEND_STRL("abstract_unix_socket"), CURLOPT_ABSTRACT_UNIX_SOCKET
, IS_STRING
))) {
1258 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1265 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_cache_timeout"), CURLOPT_DNS_CACHE_TIMEOUT
, IS_LONG
))) {
1266 Z_LVAL(opt
->defval
) = 60;
1268 php_http_option_register(registry
, ZEND_STRL("ipresolve"), CURLOPT_IPRESOLVE
, IS_LONG
);
1269 #if PHP_HTTP_CURL_VERSION(7,21,3)
1270 if ((opt
= php_http_option_register(registry
, ZEND_STRL("resolve"), CURLOPT_RESOLVE
, IS_ARRAY
))) {
1271 opt
->setter
= php_http_curle_option_set_resolve
;
1274 #if PHP_HTTP_HAVE_LIBCURL_ARES
1275 # if PHP_HTTP_CURL_VERSION(7,24,0)
1276 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_servers"), CURLOPT_DNS_SERVERS
, IS_STRING
))) {
1277 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1280 # if PHP_HTTP_CURL_VERSION(7,33,0)
1281 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_interface"), CURLOPT_DNS_INTERFACE
, IS_STRING
))) {
1282 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1284 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_local_ip4"), CURLOPT_DNS_LOCAL_IP4
, IS_STRING
))) {
1285 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1287 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_local_ip6"), CURLOPT_DNS_LOCAL_IP6
, IS_STRING
))) {
1288 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1292 #if PHP_HTTP_CURL_VERSION(7,60,0)
1293 php_http_option_register(registry
, ZEND_STRL("dns_shuffle_addresses"), CURLOPT_DNS_SHUFFLE_ADDRESSES
, _IS_BOOL
);
1295 #if PHP_HTTP_CURL_VERSION(7,62,0)
1296 php_http_option_register(registry
, ZEND_STRL("doh_url"), CURLOPT_DOH_URL
, IS_STRING
);
1301 php_http_option_register(registry
, ZEND_STRL("low_speed_limit"), CURLOPT_LOW_SPEED_LIMIT
, IS_LONG
);
1302 php_http_option_register(registry
, ZEND_STRL("low_speed_time"), CURLOPT_LOW_SPEED_TIME
, IS_LONG
);
1305 php_http_option_register(registry, ZEND_STRL("max_send_speed"), CURLOPT_MAX_SEND_SPEED_LARGE, IS_LONG);
1306 php_http_option_register(registry, ZEND_STRL("max_recv_speed"), CURLOPT_MAX_RECV_SPEED_LARGE, IS_LONG);
1309 /* connection handling */
1311 if ((opt = php_http_option_register(registry, ZEND_STRL("maxconnects"), CURLOPT_MAXCONNECTS, IS_LONG))) {
1312 Z_LVAL(opt->defval) = 5;
1315 php_http_option_register(registry
, ZEND_STRL("fresh_connect"), CURLOPT_FRESH_CONNECT
, _IS_BOOL
);
1316 php_http_option_register(registry
, ZEND_STRL("forbid_reuse"), CURLOPT_FORBID_REUSE
, _IS_BOOL
);
1317 #if PHP_HTTP_CURL_VERSION(7,65,0)
1318 if ((opt
= php_http_option_register(registry
, ZEND_STRL("maxage_conn"), CURLOPT_MAXAGE_CONN
, IS_LONG
))) {
1319 ZVAL_LONG(&opt
->defval
, 118);
1323 /* outgoing interface */
1324 php_http_option_register(registry
, ZEND_STRL("interface"), CURLOPT_INTERFACE
, IS_STRING
);
1325 if ((opt
= php_http_option_register(registry
, ZEND_STRL("portrange"), CURLOPT_LOCALPORT
, IS_ARRAY
))) {
1326 opt
->setter
= php_http_curle_option_set_portrange
;
1329 /* another endpoint port */
1330 php_http_option_register(registry
, ZEND_STRL("port"), CURLOPT_PORT
, IS_LONG
);
1332 /* RFC4007 zone_id */
1333 #if PHP_HTTP_CURL_VERSION(7,19,0)
1334 php_http_option_register(registry
, ZEND_STRL("address_scope"), CURLOPT_ADDRESS_SCOPE
, IS_LONG
);
1338 if ((opt
= php_http_option_register(registry
, ZEND_STRL("httpauth"), CURLOPT_USERPWD
, IS_STRING
))) {
1339 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1341 if ((opt
= php_http_option_register(registry
, ZEND_STRL("httpauthtype"), CURLOPT_HTTPAUTH
, IS_LONG
))) {
1342 Z_LVAL(opt
->defval
) = CURLAUTH_ANYSAFE
;
1344 #if PHP_HTTP_CURL_VERSION(7,43,0)
1345 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_SSPI
) || PHP_HTTP_CURL_FEATURE(CURL_VERSION_GSSAPI
))
1346 if ((opt
= php_http_option_register(registry
, ZEND_STRL("service_name"), CURLOPT_SERVICE_NAME
, IS_STRING
))) {
1347 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1350 #if PHP_HTTP_CURL_VERSION(7,61,0)
1351 if ((opt
= php_http_option_register(registry
, ZEND_STRL("xoauth2_bearer"), CURLOPT_XOAUTH2_BEARER
, IS_STRING
))) {
1352 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1355 #if PHP_HTTP_CURL_VERSION(7,75,0)
1356 php_http_option_register(registry
, ZEND_STRL("aws_sigv4"), CURLOPT_AWS_SIGV4
, IS_STRING
);
1360 if ((opt
= php_http_option_register(registry
, ZEND_STRL("redirect"), CURLOPT_FOLLOWLOCATION
, IS_LONG
))) {
1361 opt
->setter
= php_http_curle_option_set_redirect
;
1363 php_http_option_register(registry
, ZEND_STRL("unrestricted_auth"), CURLOPT_UNRESTRICTED_AUTH
, _IS_BOOL
);
1364 #if PHP_HTTP_CURL_VERSION(7,19,1)
1365 php_http_option_register(registry
, ZEND_STRL("postredir"), CURLOPT_POSTREDIR
, IS_LONG
);
1369 if ((opt
= php_http_option_register(registry
, ZEND_STRL("retrycount"), 0, IS_LONG
))) {
1370 opt
->setter
= php_http_curle_option_set_retrycount
;
1372 if ((opt
= php_http_option_register(registry
, ZEND_STRL("retrydelay"), 0, IS_DOUBLE
))) {
1373 opt
->setter
= php_http_curle_option_set_retrydelay
;
1377 if ((opt
= php_http_option_register(registry
, ZEND_STRL("referer"), CURLOPT_REFERER
, IS_STRING
))) {
1378 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1380 if ((opt
= php_http_option_register(registry
, ZEND_STRL("autoreferer"), CURLOPT_AUTOREFERER
, _IS_BOOL
))) {
1381 ZVAL_BOOL(&opt
->defval
, 1);
1385 if ((opt
= php_http_option_register(registry
, ZEND_STRL("useragent"), CURLOPT_USERAGENT
, IS_STRING
))) {
1386 /* don't check strlen, to allow sending no useragent at all */
1387 ZVAL_PSTRING(&opt
->defval
,
1388 "PECL_HTTP/" PHP_PECL_HTTP_VERSION
" "
1389 "PHP/" PHP_VERSION
" "
1390 "libcurl/" LIBCURL_VERSION
);
1394 if ((opt
= php_http_option_register(registry
, ZEND_STRL("resume"), CURLOPT_RESUME_FROM
, IS_LONG
))) {
1395 opt
->setter
= php_http_curle_option_set_resume
;
1398 if ((opt
= php_http_option_register(registry
, ZEND_STRL("range"), CURLOPT_RANGE
, IS_ARRAY
))) {
1399 opt
->setter
= php_http_curle_option_set_range
;
1403 if ((opt
= php_http_option_register(registry
, ZEND_STRL("etag"), 0, IS_STRING
))) {
1404 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1405 opt
->setter
= php_http_curle_option_set_etag
;
1409 if ((opt
= php_http_option_register(registry
, ZEND_STRL("compress"), 0, _IS_BOOL
))) {
1410 opt
->setter
= php_http_curle_option_set_compress
;
1414 if ((opt
= php_http_option_register(registry
, ZEND_STRL("lastmodified"), 0, IS_LONG
))) {
1415 opt
->setter
= php_http_curle_option_set_lastmodified
;
1419 if ((opt
= php_http_option_register(registry
, ZEND_STRL("encodecookies"), 0, _IS_BOOL
))) {
1420 opt
->setter
= php_http_curle_option_set_encodecookies
;
1421 ZVAL_BOOL(&opt
->defval
, 1);
1423 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookies"), 0, IS_ARRAY
))) {
1424 opt
->setter
= php_http_curle_option_set_cookies
;
1427 /* cookiesession, don't load session cookies from cookiestore */
1428 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookiesession"), CURLOPT_COOKIESESSION
, _IS_BOOL
))) {
1429 opt
->setter
= php_http_curle_option_set_cookiesession
;
1431 /* cookiestore, read initial cookies from that file and store cookies back into that file */
1432 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookiestore"), 0, IS_STRING
))) {
1433 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1434 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1435 opt
->setter
= php_http_curle_option_set_cookiestore
;
1439 php_http_option_register(registry
, ZEND_STRL("maxfilesize"), CURLOPT_MAXFILESIZE
, IS_LONG
);
1441 /* http protocol version */
1442 php_http_option_register(registry
, ZEND_STRL("protocol"), CURLOPT_HTTP_VERSION
, IS_LONG
);
1443 #if PHP_HTTP_CURL_VERSION(7,64,0)
1444 php_http_option_register(registry
, ZEND_STRL("http09_allowed"), CURLOPT_HTTP09_ALLOWED
, _IS_BOOL
);
1448 if ((opt
= php_http_option_register(registry
, ZEND_STRL("timeout"), CURLOPT_TIMEOUT_MS
, IS_DOUBLE
))) {
1449 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1451 if ((opt
= php_http_option_register(registry
, ZEND_STRL("connecttimeout"), CURLOPT_CONNECTTIMEOUT_MS
, IS_DOUBLE
))) {
1452 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1453 Z_DVAL(opt
->defval
) = 3;
1455 #if PHP_HTTP_CURL_VERSION(7,36,0)
1456 if ((opt
= php_http_option_register(registry
, ZEND_STRL("expect_100_timeout"), CURLOPT_EXPECT_100_TIMEOUT_MS
, IS_DOUBLE
))) {
1457 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1458 Z_DVAL(opt
->defval
) = 1;
1463 php_http_option_register(registry
, ZEND_STRL("tcp_nodelay"), CURLOPT_TCP_NODELAY
, _IS_BOOL
);
1464 #if PHP_HTTP_CURL_VERSION(7,25,0)
1465 php_http_option_register(registry
, ZEND_STRL("tcp_keepalive"), CURLOPT_TCP_KEEPALIVE
, _IS_BOOL
);
1466 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tcp_keepidle"), CURLOPT_TCP_KEEPIDLE
, IS_LONG
))) {
1467 Z_LVAL(opt
->defval
) = 60;
1469 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tcp_keepintvl"), CURLOPT_TCP_KEEPINTVL
, IS_LONG
))) {
1470 Z_LVAL(opt
->defval
) = 60;
1473 #if PHP_HTTP_CURL_VERSION(7,49,0)
1474 php_http_option_register(registry
, ZEND_STRL("tcp_fastopen"), CURLOPT_TCP_FASTOPEN
, _IS_BOOL
);
1478 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_SSL
)) {
1479 php_http_option_t
*ssl_opt
, *proxy_opt
;
1481 if ((ssl_opt
= php_http_option_register(registry
, ZEND_STRL("ssl"), 0, IS_ARRAY
))) {
1482 php_http_options_t
*ssl_registry
= &ssl_opt
->suboptions
;
1484 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("cert"), CURLOPT_SSLCERT
, IS_STRING
))) {
1485 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1486 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1488 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("certtype"), CURLOPT_SSLCERTTYPE
, IS_STRING
))) {
1489 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1490 ZVAL_PSTRING(&opt
->defval
, "PEM");
1492 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("key"), CURLOPT_SSLKEY
, IS_STRING
))) {
1493 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1494 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1496 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("keytype"), CURLOPT_SSLKEYTYPE
, IS_STRING
))) {
1497 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1498 ZVAL_PSTRING(&opt
->defval
, "PEM");
1500 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("keypasswd"), CURLOPT_SSLKEYPASSWD
, IS_STRING
))) {
1501 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1503 php_http_option_register(ssl_registry
, ZEND_STRL("engine"), CURLOPT_SSLENGINE
, IS_STRING
);
1504 php_http_option_register(ssl_registry
, ZEND_STRL("version"), CURLOPT_SSLVERSION
, IS_LONG
);
1505 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("verifypeer"), CURLOPT_SSL_VERIFYPEER
, _IS_BOOL
))) {
1506 ZVAL_BOOL(&opt
->defval
, 1);
1508 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("verifyhost"), CURLOPT_SSL_VERIFYHOST
, _IS_BOOL
))) {
1509 ZVAL_BOOL(&opt
->defval
, 1);
1510 opt
->setter
= php_http_curle_option_set_ssl_verifyhost
;
1512 #if PHP_HTTP_CURL_VERSION(7,41,0) && (PHP_HTTP_HAVE_LIBCURL_OPENSSL || PHP_HTTP_HAVE_LIBCURL_NSS || PHP_HTTP_HAVE_LIBCURL_GNUTLS)
1513 php_http_option_register(ssl_registry
, ZEND_STRL("verifystatus"), CURLOPT_SSL_VERIFYSTATUS
, _IS_BOOL
);
1515 php_http_option_register(ssl_registry
, ZEND_STRL("cipher_list"), CURLOPT_SSL_CIPHER_LIST
, IS_STRING
);
1516 #if PHP_HTTP_HAVE_LIBCURL_CAINFO
1517 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("cainfo"), CURLOPT_CAINFO
, IS_STRING
))) {
1518 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1519 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1520 # ifdef PHP_HTTP_CAINFO
1521 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAINFO
);
1525 #if PHP_HTTP_HAVE_LIBCURL_CAPATH
1526 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("capath"), CURLOPT_CAPATH
, IS_STRING
))) {
1527 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1528 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1529 # ifdef PHP_HTTP_CAPATH
1530 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAPATH
);
1534 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("random_file"), CURLOPT_RANDOM_FILE
, IS_STRING
))) {
1535 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1536 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1538 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("egdsocket"), CURLOPT_EGDSOCKET
, IS_STRING
))) {
1539 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1540 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1542 #if PHP_HTTP_CURL_VERSION(7,19,0)
1543 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("issuercert"), CURLOPT_ISSUERCERT
, IS_STRING
))) {
1544 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1545 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1547 # if PHP_HTTP_HAVE_LIBCURL_OPENSSL
1548 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("crlfile"), CURLOPT_CRLFILE
, IS_STRING
))) {
1549 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1550 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1554 #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))
1555 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("certinfo"), CURLOPT_CERTINFO
, _IS_BOOL
))) {
1556 ZVAL_FALSE(&opt
->defval
);
1559 #if PHP_HTTP_CURL_VERSION(7,36,0)
1560 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("enable_npn"), CURLOPT_SSL_ENABLE_NPN
, _IS_BOOL
))) {
1561 ZVAL_BOOL(&opt
->defval
, 1);
1563 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("enable_alpn"), CURLOPT_SSL_ENABLE_ALPN
, _IS_BOOL
))) {
1564 ZVAL_BOOL(&opt
->defval
, 1);
1567 #if PHP_HTTP_CURL_VERSION(7,39,0)
1568 /* FIXME: see http://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html#AVAILABILITY */
1569 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("pinned_publickey"), CURLOPT_PINNEDPUBLICKEY
, IS_STRING
))) {
1570 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1571 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1574 #if PHP_HTTP_CURL_VERSION(7,21,4) && PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
1575 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tlsauthtype"), CURLOPT_TLSAUTH_TYPE
, IS_LONG
))) {
1576 opt
->setter
= php_http_curle_option_set_ssl_tlsauthtype
;
1578 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tlsauthuser"), CURLOPT_TLSAUTH_USERNAME
, IS_STRING
))) {
1579 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1581 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tlsauthpass"), CURLOPT_TLSAUTH_PASSWORD
, IS_STRING
))) {
1582 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1585 #if PHP_HTTP_CURL_VERSION(7,42,0) && (PHP_HTTP_HAVE_LIBCURL_NSS || PHP_HTTP_HAVE_LIBCURL_SECURETRANSPORT)
1586 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("falsestart"), CURLOPT_SSL_FALSESTART
, _IS_BOOL
))) {
1587 opt
->flags
|= PHP_HTTP_CURLE_OPTION_IGNORE_RC
;
1590 #if PHP_HTTP_CURL_VERSION(7,61,0)
1591 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tls13_ciphers"), CURLOPT_TLS13_CIPHERS
, IS_STRING
))) {
1592 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1597 #if PHP_HTTP_CURL_VERSION(7,52,0)
1599 if ((proxy_opt
= php_http_option_register(registry
, ZEND_STRL("proxy_ssl"), 0, IS_ARRAY
))) {
1600 php_http_options_t
*proxy_registry
= &proxy_opt
->suboptions
;
1602 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("cert"), CURLOPT_PROXY_SSLCERT
, IS_STRING
))) {
1603 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1604 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1606 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("certtype"), CURLOPT_PROXY_SSLCERTTYPE
, IS_STRING
))) {
1607 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1608 ZVAL_PSTRING(&opt
->defval
, "PEM");
1610 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("key"), CURLOPT_PROXY_SSLKEY
, IS_STRING
))) {
1611 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1612 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1614 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("keytype"), CURLOPT_PROXY_SSLKEYTYPE
, IS_STRING
))) {
1615 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1616 ZVAL_PSTRING(&opt
->defval
, "PEM");
1618 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("keypasswd"), CURLOPT_PROXY_KEYPASSWD
, IS_STRING
))) {
1619 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1621 php_http_option_register(proxy_registry
, ZEND_STRL("version"), CURLOPT_PROXY_SSLVERSION
, IS_LONG
);
1622 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("verifypeer"), CURLOPT_PROXY_SSL_VERIFYPEER
, _IS_BOOL
))) {
1623 ZVAL_BOOL(&opt
->defval
, 1);
1625 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("verifyhost"), CURLOPT_PROXY_SSL_VERIFYHOST
, _IS_BOOL
))) {
1626 ZVAL_BOOL(&opt
->defval
, 1);
1627 opt
->setter
= php_http_curle_option_set_ssl_verifyhost
;
1629 php_http_option_register(proxy_registry
, ZEND_STRL("cipher_list"), CURLOPT_PROXY_SSL_CIPHER_LIST
, IS_STRING
);
1630 # if PHP_HTTP_CURL_VERSION(7,71,0)
1631 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("issuercert"), CURLOPT_PROXY_ISSUERCERT
, IS_STRING
))) {
1632 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1633 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1636 # if PHP_HTTP_HAVE_LIBCURL_OPENSSL
1637 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("crlfile"), CURLOPT_PROXY_CRLFILE
, IS_STRING
))) {
1638 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1639 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1642 # if PHP_HTTP_HAVE_LIBCURL_CAINFO
1643 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("cainfo"), CURLOPT_PROXY_CAINFO
, IS_STRING
))) {
1644 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1645 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1646 # ifdef PHP_HTTP_CAINFO
1647 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAINFO
);
1651 # if PHP_HTTP_HAVE_LIBCURL_CAPATH
1652 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("capath"), CURLOPT_PROXY_CAPATH
, IS_STRING
))) {
1653 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1654 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1655 # ifdef PHP_HTTP_CAPATH
1656 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAPATH
);
1661 # if PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
1662 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tlsauthtype"), CURLOPT_PROXY_TLSAUTH_TYPE
, IS_LONG
))) {
1663 opt
->setter
= php_http_curle_option_set_ssl_tlsauthtype
;
1665 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tlsauthuser"), CURLOPT_PROXY_TLSAUTH_USERNAME
, IS_STRING
))) {
1666 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1668 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tlsauthpass"), CURLOPT_PROXY_TLSAUTH_PASSWORD
, IS_STRING
))) {
1669 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1672 # if PHP_HTTP_CURL_VERSION(7,59,0)
1673 /* FIXME: see http://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html#AVAILABILITY */
1674 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("pinned_publickey"), CURLOPT_PROXY_PINNEDPUBLICKEY
, IS_STRING
))) {
1675 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1676 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1679 # if PHP_HTTP_CURL_VERSION(7,61,0)
1680 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tls13_ciphers"), CURLOPT_PROXY_TLS13_CIPHERS
, IS_STRING
))) {
1681 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1688 #if PHP_HTTP_CURL_VERSION(7,64,1)
1689 # if !PHP_HTTP_HAVE_LIBCURL_ALT_SVC
1690 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_ALTSVC
)) {
1692 if ((opt
= php_http_option_register(registry
, ZEND_STRL("altsvc_ctrl"), CURLOPT_ALTSVC_CTRL
, IS_LONG
))) {
1693 opt
->setter
= php_http_curle_option_set_altsvc_ctrl
;
1695 if ((opt
= php_http_option_register(registry
, ZEND_STRL("altsvc"), CURLOPT_ALTSVC
, IS_STRING
))) {
1696 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1698 # if !PHP_HTTP_HAVE_LIBCURL_ALT_SVC
1702 #if PHP_HTTP_CURL_VERSION(7,74,0)
1703 # if !PHP_HTTP_HAVE_LIBCURL_HSTS
1704 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_HSTS
)) {
1706 php_http_option_register(registry
, ZEND_STRL("hsts_ctrl"), CURLOPT_HSTS_CTRL
, IS_LONG
);
1707 if ((opt
= php_http_option_register(registry
, ZEND_STRL("hsts"), CURLOPT_HSTS
, IS_STRING
))) {
1708 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1710 # if !PHP_HTTP_HAVE_LIBCURL_HSTS
1716 static zval
*php_http_curle_get_option(php_http_option_t
*opt
, HashTable
*options
, void *userdata
)
1718 php_http_client_curl_handler_t
*curl
= userdata
;
1721 if ((option
= php_http_option_get(opt
, options
, NULL
))) {
1724 ZVAL_DUP(&zopt
, option
);
1725 convert_to_explicit_type(&zopt
, opt
->type
);
1726 zend_hash_update(&curl
->options
.cache
, opt
->name
, &zopt
);
1727 return zend_hash_find(&curl
->options
.cache
, opt
->name
);
1732 static ZEND_RESULT_CODE
php_http_curle_set_option(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1734 php_http_client_curl_handler_t
*curl
= userdata
;
1735 CURL
*ch
= curl
->handle
;
1737 CURLcode rc
= CURLE_UNKNOWN_OPTION
;
1738 ZEND_RESULT_CODE rv
= SUCCESS
;
1744 switch (opt
->type
) {
1747 rv
= opt
->setter(opt
, val
, curl
);
1748 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, (long) (Z_TYPE_P(val
) == IS_TRUE
))) {
1755 rv
= opt
->setter(opt
, val
, curl
);
1756 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, Z_LVAL_P(val
))) {
1763 rv
= opt
->setter(opt
, val
, curl
);
1764 } else if (!val
|| Z_TYPE_P(val
) == IS_NULL
) {
1765 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1768 } else if ((opt
->flags
& PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
) && !Z_STRLEN_P(val
)) {
1769 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1772 } else if ((opt
->flags
& PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
) && Z_STRVAL_P(val
) && SUCCESS
!= php_check_open_basedir(Z_STRVAL_P(val
))) {
1773 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1776 } else if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, Z_STRVAL_P(val
)))) {
1782 if (opt
->flags
& PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
) {
1784 Z_DVAL(tmp
) *= 1000;
1788 rv
= opt
->setter(opt
, val
, curl
);
1789 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, (long) Z_DVAL_P(val
))) {
1796 rv
= opt
->setter(opt
, val
, curl
);
1797 } else if (Z_TYPE_P(val
) != IS_NULL
) {
1798 rv
= php_http_options_apply(&opt
->suboptions
, Z_ARRVAL_P(val
), curl
);
1804 rv
= opt
->setter(opt
, val
, curl
);
1810 if (rv
!= SUCCESS
) {
1811 if (opt
->flags
& PHP_HTTP_CURLE_OPTION_IGNORE_RC
) {
1814 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_easy_strerror(rc
));
1820 #if PHP_HTTP_CURL_VERSION(7,30,0) && !PHP_HTTP_CURL_VERSION(7,62,0)
1821 static ZEND_RESULT_CODE
php_http_curlm_option_set_pipelining_bl(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1823 php_http_client_t
*client
= userdata
;
1824 php_http_client_curl_t
*curl
= client
->ctx
;
1825 CURLM
*ch
= curl
->handle
->multi
;
1829 /* array of char *, ending with a NULL */
1830 if (value
&& Z_TYPE_P(value
) != IS_NULL
) {
1832 HashTable
*ht
= HASH_OF(value
);
1833 int c
= zend_hash_num_elements(ht
);
1834 char **ptr
= ecalloc(c
+ 1, sizeof(char *));
1838 zend_hash_init(&tmp_ht
, c
, NULL
, ZVAL_PTR_DTOR
, 0);
1839 array_join(ht
, &tmp_ht
, 0, ARRAY_JOIN_STRINGIFY
);
1841 ZEND_HASH_FOREACH_VAL(&tmp_ht
, entry
)
1843 *ptr
++ = Z_STRVAL_P(entry
);
1845 ZEND_HASH_FOREACH_END();
1848 if (CURLM_OK
!= curl_multi_setopt(ch
, opt
->option
, bl
)) {
1851 zend_hash_destroy(&tmp_ht
);
1858 zend_hash_destroy(&tmp_ht
);
1864 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
)
1866 php_http_client_curl_t
*curl
= h
->ctx
;
1870 if (!(ev_ctx
= ev_ops
->init(h
, init_data
))) {
1873 curl
->ev_ctx
= ev_ctx
;
1874 curl
->ev_ops
= ev_ops
;
1878 curl
->ev_ops
->dtor(&curl
->ev_ctx
);
1880 curl
->ev_ops
= NULL
;
1887 static ZEND_RESULT_CODE
php_http_curlm_option_set_use_eventloop(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1889 php_http_client_t
*client
= userdata
;
1890 php_http_client_curl_ops_t
*ev_ops
= NULL
;
1892 if (value
&& Z_TYPE_P(value
) == IS_OBJECT
&& instanceof_function(Z_OBJCE_P(value
), php_http_client_curl_user_get_class_entry())) {
1893 ev_ops
= php_http_client_curl_user_ops_get();
1894 #if PHP_HTTP_HAVE_LIBEVENT
1895 } else if (value
&& zend_is_true(value
)) {
1896 ev_ops
= php_http_client_curl_event_ops_get();
1900 return php_http_curlm_use_eventloop(client
, ev_ops
, value
);
1903 static ZEND_RESULT_CODE
php_http_curlm_option_set_share_cookies(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1905 php_http_client_t
*client
= userdata
;
1906 php_http_client_curl_t
*curl
= client
->ctx
;
1909 if (Z_TYPE_P(value
) == IS_TRUE
) {
1910 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_COOKIE
);
1912 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_UNSHARE
, CURL_LOCK_DATA_COOKIE
);
1915 if (CURLSHE_OK
!= rc
) {
1916 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_share_strerror(rc
));
1922 #if PHP_HTTP_CURL_VERSION(7,23,0)
1923 static ZEND_RESULT_CODE
php_http_curlm_option_set_share_ssl(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1925 php_http_client_t
*client
= userdata
;
1926 php_http_client_curl_t
*curl
= client
->ctx
;
1929 if (Z_TYPE_P(value
) == IS_TRUE
) {
1930 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_SSL_SESSION
);
1932 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_UNSHARE
, CURL_LOCK_DATA_SSL_SESSION
);
1935 if (CURLSHE_OK
!= rc
) {
1936 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_share_strerror(rc
));
1943 static void php_http_curlm_options_init(php_http_options_t
*registry
)
1945 php_http_option_t
*opt
;
1947 /* set size of connection cache */
1948 if ((opt
= php_http_option_register(registry
, ZEND_STRL("maxconnects"), CURLMOPT_MAXCONNECTS
, IS_LONG
))) {
1949 /* -1 == default, 0 == unlimited */
1950 ZVAL_LONG(&opt
->defval
, -1);
1952 /* set max number of connections to a single host */
1953 #if PHP_HTTP_CURL_VERSION(7,30,0)
1954 php_http_option_register(registry
, ZEND_STRL("max_host_connections"), CURLMOPT_MAX_HOST_CONNECTIONS
, IS_LONG
);
1956 /* max simultaneously open connections */
1957 #if PHP_HTTP_CURL_VERSION(7,30,0)
1958 php_http_option_register(registry
, ZEND_STRL("max_total_connections"), CURLMOPT_MAX_TOTAL_CONNECTIONS
, IS_LONG
);
1960 #if PHP_HTTP_CURL_VERSION(7,67,0)
1961 if ((opt
= php_http_option_register(registry
, ZEND_STRL("max_concurrent_streams"), CURLMOPT_MAX_CONCURRENT_STREAMS
, IS_LONG
))) {
1962 ZVAL_LONG(&opt
->defval
, 100);
1966 #if !PHP_HTTP_CURL_VERSION(7,62,0)
1967 /* enable/disable HTTP pipelining */
1968 php_http_option_register(registry
, ZEND_STRL("pipelining"), CURLMOPT_PIPELINING
, _IS_BOOL
);
1969 # if PHP_HTTP_CURL_VERSION(7,30,0)
1970 /* maximum number of requests in a pipeline */
1971 if ((opt
= php_http_option_register(registry
, ZEND_STRL("max_pipeline_length"), CURLMOPT_MAX_PIPELINE_LENGTH
, IS_LONG
))) {
1972 ZVAL_LONG(&opt
->defval
, 5);
1974 /* chunk length threshold for pipelining */
1975 php_http_option_register(registry
, ZEND_STRL("chunk_length_penalty_size"), CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE
, IS_LONG
);
1976 /* size threshold for pipelining penalty */
1977 php_http_option_register(registry
, ZEND_STRL("content_length_penalty_size"), CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE
, IS_LONG
);
1978 /* pipelining server blacklist */
1979 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pipelining_server_bl"), CURLMOPT_PIPELINING_SERVER_BL
, IS_ARRAY
))) {
1980 opt
->setter
= php_http_curlm_option_set_pipelining_bl
;
1982 /* pipelining host blacklist */
1983 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pipelining_site_bl"), CURLMOPT_PIPELINING_SITE_BL
, IS_ARRAY
))) {
1984 opt
->setter
= php_http_curlm_option_set_pipelining_bl
;
1989 if ((opt
= php_http_option_register(registry
, ZEND_STRL("use_eventloop"), 0, 0))) {
1990 opt
->setter
= php_http_curlm_option_set_use_eventloop
;
1993 if ((opt
= php_http_option_register(registry
, ZEND_STRL("share_cookies"), 0, _IS_BOOL
))) {
1994 opt
->setter
= php_http_curlm_option_set_share_cookies
;
1995 ZVAL_TRUE(&opt
->defval
);
1997 #if PHP_HTTP_CURL_VERSION(7,23,0)
1998 if ((opt
= php_http_option_register(registry
, ZEND_STRL("share_ssl"), 0, _IS_BOOL
))) {
1999 opt
->setter
= php_http_curlm_option_set_share_ssl
;
2000 ZVAL_TRUE(&opt
->defval
);
2005 static ZEND_RESULT_CODE
php_http_curlm_set_option(php_http_option_t
*opt
, zval
*val
, void *userdata
)
2007 php_http_client_t
*client
= userdata
;
2008 php_http_client_curl_t
*curl
= client
->ctx
;
2009 CURLM
*ch
= curl
->handle
->multi
;
2010 zval zopt
, *orig
= val
;
2011 CURLMcode rc
= CURLM_UNKNOWN_OPTION
;
2012 ZEND_RESULT_CODE rv
= SUCCESS
;
2016 } else if (opt
->type
&& Z_TYPE_P(val
) != opt
->type
&& !(Z_TYPE_P(val
) == IS_NULL
&& opt
->type
== IS_ARRAY
)) {
2017 ZVAL_DUP(&zopt
, val
);
2018 convert_to_explicit_type(&zopt
, opt
->type
);
2024 rv
= opt
->setter(opt
, val
, client
);
2026 switch (opt
->type
) {
2028 if (CURLM_OK
!= (rc
= curl_multi_setopt(ch
, opt
->option
, (long) zend_is_true(val
)))) {
2030 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_multi_strerror(rc
));
2034 if (CURLM_OK
!= (rc
= curl_multi_setopt(ch
, opt
->option
, Z_LVAL_P(val
)))) {
2036 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_multi_strerror(rc
));
2041 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s", opt
->name
->val
);
2046 if (val
&& val
!= orig
&& val
!= &opt
->defval
) {
2055 static ZEND_RESULT_CODE
php_http_client_curl_handler_reset(php_http_client_curl_handler_t
*curl
)
2057 CURL
*ch
= curl
->handle
;
2058 php_http_curle_storage_t
*st
;
2060 if ((st
= php_http_curle_get_storage(ch
))) {
2065 if (st
->cookiestore
) {
2066 pefree(st
->cookiestore
, 1);
2067 st
->cookiestore
= NULL
;
2069 st
->errorbuffer
[0] = '\0';
2073 curl_easy_setopt(ch
, CURLOPT_URL
, NULL
);
2074 curl_easy_setopt(ch
, CURLOPT_CUSTOMREQUEST
, NULL
);
2075 curl_easy_setopt(ch
, CURLOPT_HTTPGET
, 1L);
2076 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 0L);
2077 /* libcurl < 7.19.6 does not clear auth info with USERPWD set to NULL */
2078 #if PHP_HTTP_CURL_VERSION(7,19,1)
2079 curl_easy_setopt(ch
, CURLOPT_PROXYUSERNAME
, NULL
);
2080 curl_easy_setopt(ch
, CURLOPT_PROXYPASSWORD
, NULL
);
2081 curl_easy_setopt(ch
, CURLOPT_USERNAME
, NULL
);
2082 curl_easy_setopt(ch
, CURLOPT_PASSWORD
, NULL
);
2085 #if PHP_HTTP_CURL_VERSION(7,21,3)
2086 if (curl
->options
.resolve
) {
2087 curl_slist_free_all(curl
->options
.resolve
);
2088 curl
->options
.resolve
= NULL
;
2091 curl
->options
.retry
.count
= 0;
2092 curl
->options
.retry
.delay
= 0;
2093 curl
->options
.redirects
= 0;
2094 curl
->options
.encode_cookies
= 1;
2096 if (curl
->options
.headers
) {
2097 curl_slist_free_all(curl
->options
.headers
);
2098 curl
->options
.headers
= NULL
;
2100 if (curl
->options
.proxyheaders
) {
2101 curl_slist_free_all(curl
->options
.proxyheaders
);
2102 curl
->options
.proxyheaders
= NULL
;
2105 php_http_buffer_reset(&curl
->options
.cookies
);
2106 php_http_buffer_reset(&curl
->options
.ranges
);
2111 static php_http_client_curl_handler_t
*php_http_client_curl_handler_init(php_http_client_t
*h
, php_resource_factory_t
*rf
)
2114 php_http_client_curl_t
*curl
= h
->ctx
;
2115 php_http_client_curl_handler_t
*handler
;
2117 if (!(handle
= php_resource_factory_handle_ctor(rf
, NULL
))) {
2118 php_error_docref(NULL
, E_WARNING
, "Failed to initialize curl handle");
2122 handler
= ecalloc(1, sizeof(*handler
));
2124 handler
->client
= h
;
2125 handler
->handle
= handle
;
2126 handler
->response
.body
= php_http_message_body_init(NULL
, NULL
);
2127 php_http_buffer_init(&handler
->response
.headers
);
2128 php_http_buffer_init(&handler
->options
.cookies
);
2129 php_http_buffer_init(&handler
->options
.ranges
);
2130 zend_hash_init(&handler
->options
.cache
, 0, NULL
, ZVAL_PTR_DTOR
, 0);
2133 curl_easy_setopt(handle
, CURLOPT_NOSIGNAL
, 1L);
2135 curl_easy_setopt(handle
, CURLOPT_HEADER
, 0L);
2136 curl_easy_setopt(handle
, CURLOPT_FILETIME
, 1L);
2137 curl_easy_setopt(handle
, CURLOPT_AUTOREFERER
, 1L);
2138 curl_easy_setopt(handle
, CURLOPT_VERBOSE
, 1L);
2139 curl_easy_setopt(handle
, CURLOPT_NOPROGRESS
, 0L);
2140 curl_easy_setopt(handle
, CURLOPT_HEADERFUNCTION
, php_http_curle_header_callback
);
2141 curl_easy_setopt(handle
, CURLOPT_WRITEFUNCTION
, php_http_curle_body_callback
);
2142 curl_easy_setopt(handle
, CURLOPT_DEBUGFUNCTION
, php_http_curle_raw_callback
);
2143 curl_easy_setopt(handle
, CURLOPT_READFUNCTION
, php_http_curle_read_callback
);
2144 curl_easy_setopt(handle
, CURLOPT_SEEKFUNCTION
, php_http_curle_seek_callback
);
2145 #if PHP_HTTP_CURL_VERSION(7,32,0)
2146 curl_easy_setopt(handle
, CURLOPT_XFERINFOFUNCTION
, php_http_curle_xferinfo_callback
);
2147 curl_easy_setopt(handle
, CURLOPT_XFERINFODATA
, handler
);
2149 curl_easy_setopt(handle
, CURLOPT_PROGRESSFUNCTION
, php_http_curle_progress_callback
);
2150 curl_easy_setopt(handle
, CURLOPT_PROGRESSDATA
, handler
);
2152 curl_easy_setopt(handle
, CURLOPT_DEBUGDATA
, handler
);
2153 curl_easy_setopt(handle
, CURLOPT_WRITEDATA
, handler
);
2154 curl_easy_setopt(handle
, CURLOPT_HEADERDATA
, handler
);
2155 curl_easy_setopt(handle
, CURLOPT_SHARE
, curl
->handle
->share
);
2157 php_http_client_curl_handler_reset(handler
);
2163 static ZEND_RESULT_CODE
php_http_client_curl_handler_prepare(php_http_client_curl_handler_t
*curl
, php_http_client_enqueue_t
*enqueue
)
2166 php_http_message_t
*msg
= enqueue
->request
;
2167 php_http_curle_storage_t
*storage
= php_http_curle_get_storage(curl
->handle
);
2170 if (!PHP_HTTP_INFO(msg
).request
.url
) {
2171 php_error_docref(NULL
, E_WARNING
, "Cannot request empty URL");
2174 storage
->errorbuffer
[0] = '\0';
2176 pefree(storage
->url
, 1);
2178 php_http_url_to_string(PHP_HTTP_INFO(msg
).request
.url
, &storage
->url
, NULL
, 1);
2179 curl_easy_setopt(curl
->handle
, CURLOPT_URL
, storage
->url
);
2182 php_http_options_apply(&php_http_curle_options
, enqueue
->options
, curl
);
2184 /* request headers */
2185 php_http_message_update_headers(msg
);
2186 if (zend_hash_num_elements(&msg
->hdrs
)) {
2187 php_http_arrkey_t header_key
;
2189 zend_string
*header_str
;
2190 php_http_buffer_t header
;
2191 #if !PHP_HTTP_CURL_VERSION(7,23,0)
2192 zval
*ct
= zend_hash_str_find(&msg
->hdrs
, ZEND_STRL("Content-Length"));
2195 php_http_buffer_init(&header
);
2196 ZEND_HASH_FOREACH_KEY_VAL(&msg
->hdrs
, header_key
.h
, header_key
.key
, header_val
)
2198 if (header_key
.key
) {
2199 #if !PHP_HTTP_CURL_VERSION(7,23,0)
2200 /* avoid duplicate content-length header */
2201 if (ct
&& ct
== header_val
) {
2205 header_str
= zval_get_string(header_val
);
2206 php_http_buffer_appendf(&header
, "%s: %s", header_key
.key
->val
, header_str
->val
);
2207 php_http_buffer_fix(&header
);
2208 curl
->options
.headers
= curl_slist_append(curl
->options
.headers
, header
.data
);
2209 php_http_buffer_reset(&header
);
2210 zend_string_release(header_str
);
2213 ZEND_HASH_FOREACH_END();
2214 php_http_buffer_dtor(&header
);
2216 curl_easy_setopt(curl
->handle
, CURLOPT_HTTPHEADER
, curl
->options
.headers
);
2218 /* attach request body */
2219 if ((body_size
= php_http_message_body_size(msg
->body
))) {
2220 /* RFC2616, section 4.3 (para. 4) states that »a message-body MUST NOT be included in a request if the
2221 * specification of the request method (section 5.1.1) does not allow sending an entity-body in request.«
2222 * Following the clause in section 5.1.1 (para. 2) that request methods »MUST be implemented with the
2223 * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method
2224 * does not allow a request body.
2226 php_stream_rewind(php_http_message_body_stream(msg
->body
));
2227 curl_easy_setopt(curl
->handle
, CURLOPT_SEEKDATA
, msg
->body
);
2228 curl_easy_setopt(curl
->handle
, CURLOPT_READDATA
, msg
->body
);
2229 curl_easy_setopt(curl
->handle
, CURLOPT_INFILESIZE
, body_size
);
2230 curl_easy_setopt(curl
->handle
, CURLOPT_POSTFIELDSIZE
, body_size
);
2231 curl_easy_setopt(curl
->handle
, CURLOPT_POST
, 1L);
2233 curl_easy_setopt(curl
->handle
, CURLOPT_SEEKDATA
, NULL
);
2234 curl_easy_setopt(curl
->handle
, CURLOPT_READDATA
, NULL
);
2235 curl_easy_setopt(curl
->handle
, CURLOPT_INFILESIZE
, 0L);
2236 curl_easy_setopt(curl
->handle
, CURLOPT_POSTFIELDSIZE
, 0L);
2240 * Always use CUSTOMREQUEST, else curl won't send any request body for GET etc.
2241 * See e.g. bug #69313.
2243 * Here's what curl does:
2244 * - CURLOPT_HTTPGET: ignore request body
2245 * - CURLOPT_UPLOAD: set "Expect: 100-continue" header
2246 * - CURLOPT_POST: set "Content-Type: application/x-www-form-urlencoded" header
2247 * Now select the least bad.
2249 * See also https://tools.ietf.org/html/rfc7231#section-5.1.1
2251 if (PHP_HTTP_INFO(msg
).request
.method
) {
2252 switch(php_http_select_str(PHP_HTTP_INFO(msg
).request
.method
, 2, "HEAD", "PUT")) {
2254 curl_easy_setopt(curl
->handle
, CURLOPT_NOBODY
, 1L);
2257 curl_easy_setopt(curl
->handle
, CURLOPT_UPLOAD
, 1L);
2260 curl_easy_setopt(curl
->handle
, CURLOPT_CUSTOMREQUEST
, PHP_HTTP_INFO(msg
).request
.method
);
2263 php_error_docref(NULL
, E_WARNING
, "Cannot use empty request method");
2270 static void php_http_client_curl_handler_clear(php_http_client_curl_handler_t
*handler
)
2272 curl_easy_setopt(handler
->handle
, CURLOPT_NOPROGRESS
, 1L);
2273 #if PHP_HTTP_CURL_VERSION(7,32,0)
2274 curl_easy_setopt(handler
->handle
, CURLOPT_XFERINFOFUNCTION
, NULL
);
2276 curl_easy_setopt(handler
->handle
, CURLOPT_PROGRESSFUNCTION
, NULL
);
2278 curl_easy_setopt(handler
->handle
, CURLOPT_VERBOSE
, 0L);
2279 curl_easy_setopt(handler
->handle
, CURLOPT_DEBUGFUNCTION
, NULL
);
2280 curl_easy_setopt(handler
->handle
, CURLOPT_COOKIELIST
, "FLUSH");
2281 curl_easy_setopt(handler
->handle
, CURLOPT_SHARE
, NULL
);
2282 /* see gh issue #84 */
2283 #if PHP_HTTP_CURL_VERSION(7,63,0) && !PHP_HTTP_CURL_VERSION(7,65,0)
2284 curl_easy_setopt(handler
->handle
, CURLOPT_COOKIEJAR
, NULL
);
2288 static void php_http_client_curl_handler_dtor(php_http_client_curl_handler_t
*handler
)
2290 php_http_client_curl_handler_clear(handler
);
2292 php_resource_factory_handle_dtor(handler
->rf
, handler
->handle
);
2293 php_resource_factory_free(&handler
->rf
);
2295 php_http_message_body_free(&handler
->response
.body
);
2296 php_http_buffer_dtor(&handler
->response
.headers
);
2297 php_http_buffer_dtor(&handler
->options
.ranges
);
2298 php_http_buffer_dtor(&handler
->options
.cookies
);
2299 zend_hash_destroy(&handler
->options
.cache
);
2301 #if PHP_HTTP_CURL_VERSION(7,21,3)
2302 if (handler
->options
.resolve
) {
2303 curl_slist_free_all(handler
->options
.resolve
);
2304 handler
->options
.resolve
= NULL
;
2308 if (handler
->options
.headers
) {
2309 curl_slist_free_all(handler
->options
.headers
);
2310 handler
->options
.headers
= NULL
;
2313 if (handler
->options
.proxyheaders
) {
2314 curl_slist_free_all(handler
->options
.proxyheaders
);
2315 handler
->options
.proxyheaders
= NULL
;
2321 static php_http_client_t
*php_http_client_curl_init(php_http_client_t
*h
, void *handle
)
2323 php_http_client_curl_t
*curl
;
2325 if (!handle
&& !(handle
= php_resource_factory_handle_ctor(h
->rf
, NULL
))) {
2326 php_error_docref(NULL
, E_WARNING
, "Failed to initialize curl handle");
2330 curl
= ecalloc(1, sizeof(*curl
));
2331 curl
->handle
= handle
;
2332 curl
->unfinished
= 0;
2338 static void php_http_client_curl_dtor(php_http_client_t
*h
)
2340 php_http_client_curl_t
*curl
= h
->ctx
;
2343 curl
->ev_ops
->dtor(&curl
->ev_ctx
);
2344 curl
->ev_ops
= NULL
;
2346 curl
->unfinished
= 0;
2348 php_resource_factory_handle_dtor(h
->rf
, curl
->handle
);
2354 static void queue_dtor(php_http_client_enqueue_t
*e
)
2356 php_http_client_curl_handler_t
*handler
= e
->opaque
;
2358 if (handler
->queue
.dtor
) {
2359 e
->opaque
= handler
->queue
.opaque
;
2360 handler
->queue
.dtor(e
);
2362 php_http_client_curl_handler_dtor(handler
);
2365 static php_resource_factory_t
*create_rf(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2367 php_persistent_handle_factory_t
*pf
= NULL
;
2368 php_resource_factory_t
*rf
= NULL
;
2369 php_http_url_t
*url
= enqueue
->request
->http
.info
.request
.url
;
2371 if (!url
|| (!url
->host
&& !url
->path
)) {
2372 php_error_docref(NULL
, E_WARNING
, "Cannot request empty URL");
2376 /* only if the client itself is setup for persistence */
2377 if (php_resource_factory_is_persistent(h
->rf
)) {
2379 char *id_str
= NULL
;
2381 int port
= url
->port
? url
->port
: 80;
2383 php_persistent_handle_factory_t
*phf
= h
->rf
->data
;
2385 if ((zport
= zend_hash_str_find(enqueue
->options
, ZEND_STRL("port")))) {
2386 zend_long lport
= zval_get_long(zport
);
2393 id_len
= spprintf(&id_str
, 0, "%.*s:%s:%d", (int) phf
->ident
->len
, phf
->ident
->val
, STR_PTR(url
->host
), port
);
2394 id
= php_http_cs2zs(id_str
, id_len
);
2395 pf
= php_persistent_handle_concede(NULL
, PHP_HTTP_G
->client
.curl
.driver
.request_name
, id
, NULL
, NULL
);
2396 zend_string_release(id
);
2400 rf
= php_persistent_handle_resource_factory_init(NULL
, pf
);
2402 rf
= php_resource_factory_init(NULL
, &php_http_curle_resource_factory_ops
, NULL
, NULL
);
2408 static ZEND_RESULT_CODE
php_http_client_curl_enqueue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2411 php_http_client_curl_t
*curl
= h
->ctx
;
2412 php_http_client_curl_handler_t
*handler
;
2413 php_http_client_progress_state_t
*progress
;
2414 php_resource_factory_t
*rf
;
2416 rf
= create_rf(h
, enqueue
);
2421 handler
= php_http_client_curl_handler_init(h
, rf
);
2426 if (SUCCESS
!= php_http_client_curl_handler_prepare(handler
, enqueue
)) {
2427 php_http_client_curl_handler_dtor(handler
);
2431 handler
->queue
= *enqueue
;
2432 enqueue
->opaque
= handler
;
2433 enqueue
->dtor
= queue_dtor
;
2435 if (CURLM_OK
!= (rs
= curl_multi_add_handle(curl
->handle
->multi
, handler
->handle
))) {
2436 php_http_client_curl_handler_dtor(handler
);
2437 php_error_docref(NULL
, E_WARNING
, "Could not enqueue request: %s", curl_multi_strerror(rs
));
2441 zend_llist_add_element(&h
->requests
, enqueue
);
2444 if (h
->callback
.progress
.func
&& SUCCESS
== php_http_client_getopt(h
, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
, enqueue
->request
, &progress
)) {
2445 progress
->info
= "start";
2446 h
->callback
.progress
.func(h
->callback
.progress
.arg
, h
, &handler
->queue
, progress
);
2447 progress
->started
= 1;
2453 static ZEND_RESULT_CODE
php_http_client_curl_dequeue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2456 php_http_client_curl_t
*curl
= h
->ctx
;
2457 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2459 if (h
->callback
.depth
&& !CG(unclean_shutdown
)) {
2460 php_error_docref(NULL
, E_WARNING
, "Could not dequeue request while executing callbacks");
2464 php_http_client_curl_handler_clear(handler
);
2465 if (CURLM_OK
== (rs
= curl_multi_remove_handle(curl
->handle
->multi
, handler
->handle
))) {
2466 zend_llist_del_element(&h
->requests
, handler
->handle
, (int (*)(void *, void *)) compare_queue
);
2469 php_error_docref(NULL
, E_WARNING
, "Could not dequeue request: %s", curl_multi_strerror(rs
));
2475 static void php_http_client_curl_reset(php_http_client_t
*h
)
2477 zend_llist_element
*next_el
, *this_el
;
2479 for (this_el
= h
->requests
.head
; this_el
; this_el
= next_el
) {
2480 next_el
= this_el
->next
;
2481 php_http_client_curl_dequeue(h
, (void *) this_el
->data
);
2486 # define SELECT_ERROR SOCKET_ERROR
2488 # define SELECT_ERROR -1
2491 static ZEND_RESULT_CODE
php_http_client_curl_wait(php_http_client_t
*h
, struct timeval
*custom_timeout
)
2495 struct timeval timeout
;
2496 php_http_client_curl_t
*curl
= h
->ctx
;
2499 return curl
->ev_ops
->wait(curl
->ev_ctx
, custom_timeout
);
2506 if (CURLM_OK
== curl_multi_fdset(curl
->handle
->multi
, &R
, &W
, &E
, &MAX
)) {
2507 if (custom_timeout
&& timerisset(custom_timeout
)) {
2508 timeout
= *custom_timeout
;
2510 php_http_client_curl_get_timeout(curl
, 1000, &timeout
);
2514 php_http_sleep((double) timeout
.tv_sec
+ (double) (timeout
.tv_usec
/ PHP_HTTP_MCROSEC
));
2516 } else if (SELECT_ERROR
!= select(MAX
+ 1, &R
, &W
, &E
, &timeout
)) {
2523 static int php_http_client_curl_once(php_http_client_t
*h
)
2525 php_http_client_curl_t
*curl
= h
->ctx
;
2527 if (!h
->callback
.depth
) {
2529 curl
->ev_ops
->once(curl
->ev_ctx
);
2531 while (CURLM_CALL_MULTI_PERFORM
== curl_multi_perform(curl
->handle
->multi
, &curl
->unfinished
));
2534 php_http_client_curl_responsehandler(h
);
2537 return curl
->unfinished
;
2540 static ZEND_RESULT_CODE
php_http_client_curl_exec(php_http_client_t
*h
)
2542 php_http_client_curl_t
*curl
= h
->ctx
;
2544 if (!h
->callback
.depth
) {
2546 return curl
->ev_ops
->exec(curl
->ev_ctx
);
2549 while (php_http_client_curl_once(h
) && !EG(exception
)) {
2550 if (SUCCESS
!= php_http_client_curl_wait(h
, NULL
)) {
2552 /* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */
2553 php_error_docref(NULL
, E_WARNING
, "WinSock error: %d", WSAGetLastError());
2555 php_error_docref(NULL
, E_WARNING
, "%s", strerror(errno
));
2565 static ZEND_RESULT_CODE
php_http_client_curl_setopt(php_http_client_t
*h
, php_http_client_setopt_opt_t opt
, void *arg
)
2567 php_http_client_curl_t
*curl
= h
->ctx
;
2570 case PHP_HTTP_CLIENT_OPT_CONFIGURATION
:
2571 return php_http_options_apply(&php_http_curlm_options
, (HashTable
*) arg
, h
);
2573 #if !PHP_HTTP_CURL_VERSION(7,62,0)
2574 case PHP_HTTP_CLIENT_OPT_ENABLE_PIPELINING
:
2575 if (CURLM_OK
!= curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_PIPELINING
, (long) *((zend_bool
*) arg
))) {
2580 case PHP_HTTP_CLIENT_OPT_USE_EVENTS
:
2581 #if PHP_HTTP_HAVE_LIBEVENT
2582 return php_http_curlm_use_eventloop(h
, (*(zend_bool
*) arg
)
2583 ? php_http_client_curl_event_ops_get()
2594 static int apply_available_options(zval
*pDest
, int num_args
, va_list args
, zend_hash_key
*hash_key
)
2596 php_http_option_t
*opt
= Z_PTR_P(pDest
);
2601 ht
= va_arg(args
, HashTable
*);
2603 if ((c
= zend_hash_num_elements(&opt
->suboptions
.options
))) {
2604 array_init_size(&entry
, c
);
2605 zend_hash_apply_with_arguments(&opt
->suboptions
.options
, apply_available_options
, 1, Z_ARRVAL(entry
));
2607 /* catch deliberate NULL options */
2608 if (Z_TYPE(opt
->defval
) == IS_STRING
&& !Z_STRVAL(opt
->defval
)) {
2611 ZVAL_ZVAL(&entry
, &opt
->defval
, 1, 0);
2615 if (hash_key
->key
) {
2616 zend_hash_update(ht
, hash_key
->key
, &entry
);
2618 zend_hash_index_update(ht
, hash_key
->h
, &entry
);
2621 return ZEND_HASH_APPLY_KEEP
;
2624 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
)
2626 php_http_client_enqueue_t
*enqueue
;
2629 case PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
:
2630 if ((enqueue
= php_http_client_enqueued(h
, arg
, NULL
))) {
2631 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2633 *((php_http_client_progress_state_t
**) res
) = &handler
->progress
;
2638 case PHP_HTTP_CLIENT_OPT_TRANSFER_INFO
:
2639 if ((enqueue
= php_http_client_enqueued(h
, arg
, NULL
))) {
2640 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2642 php_http_curle_get_info(handler
->handle
, *(HashTable
**) res
);
2647 case PHP_HTTP_CLIENT_OPT_AVAILABLE_OPTIONS
:
2648 zend_hash_apply_with_arguments(&php_http_curle_options
.options
, apply_available_options
, 1, *(HashTable
**) res
);
2651 case PHP_HTTP_CLIENT_OPT_AVAILABLE_CONFIGURATION
:
2652 zend_hash_apply_with_arguments(&php_http_curlm_options
.options
, apply_available_options
, 1, *(HashTable
**) res
);
2662 static php_http_client_ops_t php_http_client_curl_ops
= {
2663 &php_http_curlm_resource_factory_ops
,
2664 php_http_client_curl_init
,
2666 php_http_client_curl_dtor
,
2667 php_http_client_curl_reset
,
2668 php_http_client_curl_exec
,
2669 php_http_client_curl_wait
,
2670 php_http_client_curl_once
,
2671 php_http_client_curl_enqueue
,
2672 php_http_client_curl_dequeue
,
2673 php_http_client_curl_setopt
,
2674 php_http_client_curl_getopt
2677 php_http_client_ops_t
*php_http_client_curl_get_ops(void)
2679 return &php_http_client_curl_ops
;
2682 #define REGISTER_NS_STRING_OR_NULL_CONSTANT(ns, name, str, flags) \
2684 if ((str) != NULL) { \
2685 REGISTER_NS_STRING_CONSTANT(ns, name, str, flags); \
2687 REGISTER_NS_NULL_CONSTANT(ns, name, flags); \
2691 PHP_MINIT_FUNCTION(http_client_curl
)
2693 curl_version_info_data
*info
;
2694 php_http_options_t
*options
;
2696 PHP_HTTP_G
->client
.curl
.driver
.driver_name
= zend_string_init(ZEND_STRL("curl"), 1);
2697 PHP_HTTP_G
->client
.curl
.driver
.client_name
= zend_string_init(ZEND_STRL("http\\Client\\Curl"), 1);
2698 PHP_HTTP_G
->client
.curl
.driver
.request_name
= zend_string_init(ZEND_STRL("http\\Client\\Curl\\Request"), 1);
2699 PHP_HTTP_G
->client
.curl
.driver
.client_ops
= &php_http_client_curl_ops
;
2701 if (SUCCESS
!= php_http_client_driver_add(&PHP_HTTP_G
->client
.curl
.driver
)) {
2705 if (SUCCESS
!= php_persistent_handle_provide(PHP_HTTP_G
->client
.curl
.driver
.client_name
, &php_http_curlm_resource_factory_ops
, NULL
, NULL
)) {
2708 if (SUCCESS
!= php_persistent_handle_provide(PHP_HTTP_G
->client
.curl
.driver
.request_name
, &php_http_curle_resource_factory_ops
, NULL
, NULL
)) {
2712 if ((options
= php_http_options_init(&php_http_curle_options
, 1))) {
2713 options
->getter
= php_http_curle_get_option
;
2714 options
->setter
= php_http_curle_set_option
;
2716 php_http_curle_options_init(options
);
2718 if ((options
= php_http_options_init(&php_http_curlm_options
, 1))) {
2719 options
->getter
= php_http_option_get
;
2720 options
->setter
= php_http_curlm_set_option
;
2722 php_http_curlm_options_init(options
);
2725 if ((info
= curl_version_info(CURLVERSION_NOW
))) {
2726 char tmp_ver
[0x20], *tmp_ptr
, *tmp_end
;
2727 #define tmp_ver_init() do {\
2729 tmp_ptr = &tmp_ver[0]; \
2730 tmp_end = &tmp_ver[sizeof(tmp_ver) - 1]; \
2736 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "FEATURES", info
->features
, CONST_CS
|CONST_PERSISTENT
);
2738 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "IPV6", CURL_VERSION_IPV6
, CONST_CS
|CONST_PERSISTENT
);
2739 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "KERBEROS4", CURL_VERSION_KERBEROS4
, CONST_CS
|CONST_PERSISTENT
);
2740 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SSL", CURL_VERSION_SSL
, CONST_CS
|CONST_PERSISTENT
);
2741 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "LIBZ", CURL_VERSION_LIBZ
, CONST_CS
|CONST_PERSISTENT
);
2742 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "NTLM", CURL_VERSION_NTLM
, CONST_CS
|CONST_PERSISTENT
);
2743 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "GSSNEGOTIATE", CURL_VERSION_GSSNEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2744 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ASYNCHDNS", CURL_VERSION_ASYNCHDNS
, CONST_CS
|CONST_PERSISTENT
);
2745 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SPNEGO", CURL_VERSION_SPNEGO
, CONST_CS
|CONST_PERSISTENT
);
2746 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "LARGEFILE", CURL_VERSION_LARGEFILE
, CONST_CS
|CONST_PERSISTENT
);
2747 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "IDN", CURL_VERSION_IDN
, CONST_CS
|CONST_PERSISTENT
);
2748 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SSPI", CURL_VERSION_SSPI
, CONST_CS
|CONST_PERSISTENT
);
2749 #if PHP_HTTP_CURL_VERSION(7,21,4)
2750 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "TLSAUTH_SRP", CURL_VERSION_TLSAUTH_SRP
, CONST_CS
|CONST_PERSISTENT
);
2752 #if PHP_HTTP_CURL_VERSION(7,22,0)
2753 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "NTLM_WB", CURL_VERSION_NTLM_WB
, CONST_CS
|CONST_PERSISTENT
);
2755 #if PHP_HTTP_CURL_VERSION(7,33,0)
2756 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTP2", CURL_VERSION_HTTP2
, CONST_CS
|CONST_PERSISTENT
);
2758 #if PHP_HTTP_CURL_VERSION(7,38,0)
2759 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "GSSAPI", CURL_VERSION_GSSAPI
, CONST_CS
|CONST_PERSISTENT
);
2761 #if PHP_HTTP_CURL_VERSION(7,40,0)
2762 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "KERBEROS5", CURL_VERSION_KERBEROS5
, CONST_CS
|CONST_PERSISTENT
);
2763 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "UNIX_SOCKETS", CURL_VERSION_UNIX_SOCKETS
, CONST_CS
|CONST_PERSISTENT
);
2765 #if PHP_HTTP_CURL_VERSION(7,47,0)
2766 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "PSL", CURL_VERSION_PSL
, CONST_CS
|CONST_PERSISTENT
);
2768 #if PHP_HTTP_CURL_VERSION(7,52,0)
2769 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTPS_PROXY", CURL_VERSION_HTTPS_PROXY
, CONST_CS
|CONST_PERSISTENT
);
2771 #if PHP_HTTP_CURL_VERSION(7,56,0)
2772 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "MULTI_SSL", CURL_VERSION_MULTI_SSL
, CONST_CS
|CONST_PERSISTENT
);
2774 #if PHP_HTTP_CURL_VERSION(7,57,0)
2775 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "BROTLI", CURL_VERSION_BROTLI
, CONST_CS
|CONST_PERSISTENT
);
2777 #if PHP_HTTP_CURL_VERSION(7,64,1)
2778 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ALTSVC", CURL_VERSION_ALTSVC
, CONST_CS
|CONST_PERSISTENT
);
2780 #if PHP_HTTP_CURL_VERSION(7,66,0)
2781 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTP3", CURL_VERSION_HTTP3
, CONST_CS
|CONST_PERSISTENT
);
2783 #if PHP_HTTP_CURL_VERSION(7,72,0)
2784 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ZSTD", CURL_VERSION_ZSTD
, CONST_CS
|CONST_PERSISTENT
);
2785 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "UNICODE", CURL_VERSION_UNICODE
, CONST_CS
|CONST_PERSISTENT
);
2787 #if PHP_HTTP_CURL_VERSION(7,74,0)
2788 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HSTS", CURL_VERSION_HSTS
, CONST_CS
|CONST_PERSISTENT
);
2795 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl", "VERSIONS", curl_version(), CONST_CS
|CONST_PERSISTENT
);
2796 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "CURL", info
->version
, CONST_CS
|CONST_PERSISTENT
);
2797 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "SSL", info
->ssl_version
, CONST_CS
|CONST_PERSISTENT
);
2798 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "LIBZ", info
->libz_version
, CONST_CS
|CONST_PERSISTENT
);
2799 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ARES", info
->ares
, CONST_CS
|CONST_PERSISTENT
);
2800 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "IDN", info
->libidn
, CONST_CS
|CONST_PERSISTENT
);
2802 if (info
->iconv_ver_num
) {
2803 tmp_ptr
= zend_print_ulong_to_buf(tmp_end
, info
->iconv_ver_num
& 0xf);
2804 tmp_end
= tmp_ptr
- 1;
2805 tmp_ptr
= zend_print_ulong_to_buf(tmp_end
, info
->iconv_ver_num
>> 8);
2808 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ICONV", *tmp_ptr
? tmp_ptr
: NULL
, CONST_CS
|CONST_PERSISTENT
);
2809 #if PHP_HTTP_CURL_VERSION(7,57,0)
2810 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "BROTLI", info
->brotli_version
, CONST_CS
|CONST_PERSISTENT
);
2812 #if PHP_HTTP_CURL_VERSION(7,66,0)
2813 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "NGHTTP2", info
->nghttp2_version
, CONST_CS
|CONST_PERSISTENT
);
2814 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "QUIC", info
->quic_version
, CONST_CS
|CONST_PERSISTENT
);
2816 #if PHP_HTTP_CURL_VERSION(7,70,0)
2817 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "CAINFO", info
->cainfo
, CONST_CS
|CONST_PERSISTENT
);
2818 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "CAPATH", info
->capath
, CONST_CS
|CONST_PERSISTENT
);
2820 #if PHP_HTTP_CURL_VERSION(7,72,0)
2821 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ZSTD", info
->zstd_version
, CONST_CS
|CONST_PERSISTENT
);
2823 #if PHP_HTTP_CURL_VERSION(7,75,0)
2824 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "HYPER", info
->hyper_version
, CONST_CS
|CONST_PERSISTENT
);
2830 * HTTP Protocol Version Constants
2832 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_1_0", CURL_HTTP_VERSION_1_0
, CONST_CS
|CONST_PERSISTENT
);
2833 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_1_1", CURL_HTTP_VERSION_1_1
, CONST_CS
|CONST_PERSISTENT
);
2834 #if PHP_HTTP_CURL_VERSION(7,33,0)
2835 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2_0", CURL_HTTP_VERSION_2_0
, CONST_CS
|CONST_PERSISTENT
);
2837 #if PHP_HTTP_CURL_VERSION(7,47,0)
2838 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2TLS", CURL_HTTP_VERSION_2TLS
, CONST_CS
|CONST_PERSISTENT
);
2840 #if PHP_HTTP_CURL_VERSION(7,49,0)
2841 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2_PRIOR_KNOWLEDGE", CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE
, CONST_CS
|CONST_PERSISTENT
);
2843 #if PHP_HTTP_CURL_VERSION(7,66,0)
2844 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_3", CURL_HTTP_VERSION_3
, CONST_CS
|CONST_PERSISTENT
);
2846 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_ANY", CURL_HTTP_VERSION_NONE
, CONST_CS
|CONST_PERSISTENT
);
2849 * SSL Version Constants
2851 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1", CURL_SSLVERSION_TLSv1
, CONST_CS
|CONST_PERSISTENT
);
2852 #if PHP_HTTP_CURL_VERSION(7,34,0)
2853 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_0", CURL_SSLVERSION_TLSv1_0
, CONST_CS
|CONST_PERSISTENT
);
2854 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_1", CURL_SSLVERSION_TLSv1_1
, CONST_CS
|CONST_PERSISTENT
);
2855 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_2", CURL_SSLVERSION_TLSv1_2
, CONST_CS
|CONST_PERSISTENT
);
2857 #if PHP_HTTP_CURL_VERSION(7,52,0)
2858 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_3", CURL_SSLVERSION_TLSv1_3
, CONST_CS
|CONST_PERSISTENT
);
2860 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv2", CURL_SSLVERSION_SSLv2
, CONST_CS
|CONST_PERSISTENT
);
2861 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv3", CURL_SSLVERSION_SSLv3
, CONST_CS
|CONST_PERSISTENT
);
2862 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_ANY", CURL_SSLVERSION_DEFAULT
, CONST_CS
|CONST_PERSISTENT
);
2863 #if PHP_HTTP_CURL_VERSION(7,21,4) && PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
2864 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "TLSAUTH_SRP", CURL_TLSAUTH_SRP
, CONST_CS
|CONST_PERSISTENT
);
2867 #if PHP_HTTP_CURL_VERSION(7,54,0)
2868 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_DEFAULT", CURL_SSLVERSION_MAX_DEFAULT
, CONST_CS
|CONST_PERSISTENT
);
2869 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_0", CURL_SSLVERSION_MAX_TLSv1_0
, CONST_CS
|CONST_PERSISTENT
);
2870 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_1", CURL_SSLVERSION_MAX_TLSv1_1
, CONST_CS
|CONST_PERSISTENT
);
2871 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_2", CURL_SSLVERSION_MAX_TLSv1_2
, CONST_CS
|CONST_PERSISTENT
);
2872 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_3", CURL_SSLVERSION_MAX_TLSv1_3
, CONST_CS
|CONST_PERSISTENT
);
2876 * DNS IPvX resolving
2878 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_V4", CURL_IPRESOLVE_V4
, CONST_CS
|CONST_PERSISTENT
);
2879 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_V6", CURL_IPRESOLVE_V6
, CONST_CS
|CONST_PERSISTENT
);
2880 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_ANY", CURL_IPRESOLVE_WHATEVER
, CONST_CS
|CONST_PERSISTENT
);
2885 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_NONE", CURLAUTH_NONE
, CONST_CS
|CONST_PERSISTENT
);
2886 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_BASIC", CURLAUTH_BASIC
, CONST_CS
|CONST_PERSISTENT
);
2887 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_DIGEST", CURLAUTH_DIGEST
, CONST_CS
|CONST_PERSISTENT
);
2888 #if PHP_HTTP_CURL_VERSION(7,19,3)
2889 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_DIGEST_IE", CURLAUTH_DIGEST_IE
, CONST_CS
|CONST_PERSISTENT
);
2891 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_NTLM", CURLAUTH_NTLM
, CONST_CS
|CONST_PERSISTENT
);
2892 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_GSSNEG", CURLAUTH_GSSNEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2893 #if PHP_HTTP_CURL_VERSION(7,38,0)
2894 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_SPNEGO", CURLAUTH_NEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2896 #if PHP_HTTP_CURL_VERSION(7,61,0)
2897 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_BEARER", CURLAUTH_BEARER
, CONST_CS
|CONST_PERSISTENT
);
2899 #if PHP_HTTP_CURL_VERSION(7,75,0)
2900 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AWS_SIGV4", CURLAUTH_AWS_SIGV4
, CONST_CS
|CONST_PERSISTENT
);
2902 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_ANY", CURLAUTH_ANY
, CONST_CS
|CONST_PERSISTENT
);
2905 * Proxy Type Constants
2907 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS4", CURLPROXY_SOCKS4
, CONST_CS
|CONST_PERSISTENT
);
2908 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS4A", CURLPROXY_SOCKS4A
, CONST_CS
|CONST_PERSISTENT
);
2909 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS5_HOSTNAME", CURLPROXY_SOCKS5_HOSTNAME
, CONST_CS
|CONST_PERSISTENT
);
2910 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS5", CURLPROXY_SOCKS5
, CONST_CS
|CONST_PERSISTENT
);
2911 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_HTTP", CURLPROXY_HTTP
, CONST_CS
|CONST_PERSISTENT
);
2912 #if PHP_HTTP_CURL_VERSION(7,19,4)
2913 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_HTTP_1_0", CURLPROXY_HTTP_1_0
, CONST_CS
|CONST_PERSISTENT
);
2917 * Post Redirection Constants
2919 #if PHP_HTTP_CURL_VERSION(7,19,1)
2920 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_301", CURL_REDIR_POST_301
, CONST_CS
|CONST_PERSISTENT
);
2921 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_302", CURL_REDIR_POST_302
, CONST_CS
|CONST_PERSISTENT
);
2922 #if PHP_HTTP_CURL_VERSION(7,26,0)
2923 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_303", CURL_REDIR_POST_303
, CONST_CS
|CONST_PERSISTENT
);
2925 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_ALL", CURL_REDIR_POST_ALL
, CONST_CS
|CONST_PERSISTENT
);
2928 #if PHP_HTTP_CURL_VERSION(7,64,1)
2929 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_READONLYFILE", CURLALTSVC_READONLYFILE
, CONST_CS
|CONST_PERSISTENT
);
2930 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_H1", CURLALTSVC_H1
, CONST_CS
|CONST_PERSISTENT
);
2931 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_H2", CURLALTSVC_H2
, CONST_CS
|CONST_PERSISTENT
);
2932 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_H3", CURLALTSVC_H3
, CONST_CS
|CONST_PERSISTENT
);
2934 #if PHP_HTTP_CURL_VERSION(7,74,0)
2935 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HSTS_ENABLE", CURLHSTS_ENABLE
, CONST_CS
|CONST_PERSISTENT
);
2936 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HSTS_READONLYFILE", CURLHSTS_READONLYFILE
, CONST_CS
|CONST_PERSISTENT
);
2941 PHP_MSHUTDOWN_FUNCTION(http_client_curl
)
2943 php_persistent_handle_cleanup(PHP_HTTP_G
->client
.curl
.driver
.client_name
, NULL
);
2944 php_persistent_handle_cleanup(PHP_HTTP_G
->client
.curl
.driver
.request_name
, NULL
);
2945 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.client_name
);
2946 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.request_name
);
2947 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.driver_name
);
2949 php_http_options_dtor(&php_http_curle_options
);
2950 php_http_options_dtor(&php_http_curlm_options
);
2955 #endif /* PHP_HTTP_HAVE_LIBCURL */
2962 * vim600: noet sw=4 ts=4 fdm=marker
2963 * vim<600: noet sw=4 ts=4