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 #define DEBUG_COOKIES 0
22 #if PHP_HTTP_HAVE_LIBCURL_OPENSSL
23 # include <openssl/ssl.h>
25 #if PHP_HTTP_HAVE_LIBCURL_GNUTLS
26 # include <gnutls/gnutls.h>
29 typedef struct php_http_client_curl_handler
{
31 php_resource_factory_t
*rf
;
32 php_http_client_t
*client
;
33 php_http_client_progress_state_t progress
;
34 php_http_client_enqueue_t queue
;
37 php_http_buffer_t headers
;
38 php_http_message_body_t
*body
;
44 struct curl_slist
*proxyheaders
;
45 struct curl_slist
*headers
;
46 struct curl_slist
*resolve
;
47 php_http_buffer_t cookies
;
48 php_http_buffer_t ranges
;
56 unsigned range_request
:1;
57 unsigned encode_cookies
:1;
61 } php_http_client_curl_handler_t
;
63 typedef struct php_http_curle_storage
{
67 char errorbuffer
[0x100];
68 } php_http_curle_storage_t
;
70 static inline php_http_curle_storage_t
*php_http_curle_get_storage(CURL
*ch
) {
71 php_http_curle_storage_t
*st
= NULL
;
73 curl_easy_getinfo(ch
, CURLINFO_PRIVATE
, &st
);
76 st
= pecalloc(1, sizeof(*st
), 1);
77 curl_easy_setopt(ch
, CURLOPT_PRIVATE
, st
);
78 curl_easy_setopt(ch
, CURLOPT_ERRORBUFFER
, st
->errorbuffer
);
84 static void *php_http_curle_ctor(void *opaque
, void *init_arg
)
88 if ((ch
= curl_easy_init())) {
89 php_http_curle_get_storage(ch
);
95 static void *php_http_curle_copy(void *opaque
, void *handle
)
99 if ((ch
= curl_easy_duphandle(handle
))) {
101 php_http_curle_get_storage(ch
);
107 static void php_http_curle_dtor(void *opaque
, void *handle
)
109 php_http_curle_storage_t
*st
= php_http_curle_get_storage(handle
);
111 curl_easy_cleanup(handle
);
117 if (st
->cookiestore
) {
118 pefree(st
->cookiestore
, 1);
124 static php_resource_factory_ops_t php_http_curle_resource_factory_ops
= {
130 static void *php_http_curlm_ctor(void *opaque
, void *init_arg
)
132 php_http_client_curl_handle_t
*curl
= calloc(1, sizeof(*curl
));
134 if (!(curl
->multi
= curl_multi_init())) {
138 if (!(curl
->share
= curl_share_init())) {
139 curl_multi_cleanup(curl
->multi
);
143 curl_share_setopt(curl
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_COOKIE
);
144 curl_share_setopt(curl
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_SSL_SESSION
);
148 static void php_http_curlm_dtor(void *opaque
, void *handle
)
150 php_http_client_curl_handle_t
*curl
= handle
;
152 curl_share_cleanup(curl
->share
);
153 curl_multi_cleanup(curl
->multi
);
157 static php_resource_factory_ops_t php_http_curlm_resource_factory_ops
= {
165 static size_t php_http_curle_read_callback(void *data
, size_t len
, size_t n
, void *ctx
)
167 php_stream
*s
= php_http_message_body_stream(ctx
);
170 return php_stream_read(s
, data
, len
* n
);
175 #if PHP_HTTP_CURL_VERSION(7,32,0)
176 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
)
178 static int php_http_curle_progress_callback(void *ctx
, double dltotal
, double dlnow
, double ultotal
, double ulnow
)
181 php_http_client_curl_handler_t
*h
= ctx
;
183 if (h
->progress
.dl
.total
!= dltotal
184 || h
->progress
.dl
.now
!= dlnow
185 || h
->progress
.ul
.total
!= ultotal
186 || h
->progress
.ul
.now
!= ulnow
188 h
->progress
.dl
.total
= dltotal
;
189 h
->progress
.dl
.now
= dlnow
;
190 h
->progress
.ul
.total
= ultotal
;
191 h
->progress
.ul
.now
= ulnow
;
194 if (h
->client
->callback
.progress
.func
) {
195 h
->client
->callback
.progress
.func(h
->client
->callback
.progress
.arg
, h
->client
, &h
->queue
, &h
->progress
);
201 static int php_http_curle_seek_callback(void *userdata
, curl_off_t offset
, int origin
)
203 php_http_message_body_t
*body
= userdata
;
208 if (0 == php_stream_seek(php_http_message_body_stream(body
), offset
, origin
)) {
214 static int php_http_curle_raw_callback(CURL
*ch
, curl_infotype type
, char *data
, size_t length
, void *ctx
)
216 php_http_client_curl_handler_t
*h
= ctx
;
217 unsigned utype
= PHP_HTTP_CLIENT_DEBUG_INFO
;
222 if (data
[0] == '-') {
224 } else if (php_memnstr(data
, ZEND_STRL("Adding handle:"), data
+ length
)) {
225 h
->progress
.info
= "setup";
226 } else if (php_memnstr(data
, ZEND_STRL("addHandle"), data
+ length
)) {
227 h
->progress
.info
= "setup";
228 } else if (php_memnstr(data
, ZEND_STRL("About to connect"), data
+ length
)) {
229 h
->progress
.info
= "resolve";
230 } else if (php_memnstr(data
, ZEND_STRL("Trying"), data
+ length
)) {
231 h
->progress
.info
= "connect";
232 } else if (php_memnstr(data
, ZEND_STRL("Found bundle for host"), data
+ length
)) {
233 h
->progress
.info
= "connect";
234 } else if (php_memnstr(data
, ZEND_STRL("Connected"), data
+ length
)) {
235 h
->progress
.info
= "connected";
236 } else if (php_memnstr(data
, ZEND_STRL("Re-using existing connection!"), data
+ length
)) {
237 h
->progress
.info
= "connected";
238 } else if (php_memnstr(data
, ZEND_STRL("blacklisted"), data
+ length
)) {
239 h
->progress
.info
= "blacklist check";
240 } else if (php_memnstr(data
, ZEND_STRL("TLS"), data
+ length
)) {
241 h
->progress
.info
= "ssl negotiation";
242 } else if (php_memnstr(data
, ZEND_STRL("SSL"), data
+ length
)) {
243 h
->progress
.info
= "ssl negotiation";
244 } else if (php_memnstr(data
, ZEND_STRL("certificate"), data
+ length
)) {
245 h
->progress
.info
= "ssl negotiation";
246 } else if (php_memnstr(data
, ZEND_STRL("ALPN"), data
+ length
)) {
247 h
->progress
.info
= "alpn";
248 } else if (php_memnstr(data
, ZEND_STRL("NPN"), data
+ length
)) {
249 h
->progress
.info
= "npn";
250 } else if (php_memnstr(data
, ZEND_STRL("upload"), data
+ length
)) {
251 h
->progress
.info
= "uploaded";
252 } else if (php_memnstr(data
, ZEND_STRL("left intact"), data
+ length
)) {
253 h
->progress
.info
= "not disconnected";
254 } else if (php_memnstr(data
, ZEND_STRL("closed"), data
+ length
)) {
255 h
->progress
.info
= "disconnected";
256 } else if (php_memnstr(data
, ZEND_STRL("Issue another request"), data
+ length
)) {
257 h
->progress
.info
= "redirect";
258 } else if (php_memnstr(data
, ZEND_STRL("Operation timed out"), data
+ length
)) {
259 h
->progress
.info
= "timeout";
263 h
->progress
.info
= data
;
264 data
[length
- 1] = '\0';
267 if (h
->client
->callback
.progress
.func
) {
268 h
->client
->callback
.progress
.func(h
->client
->callback
.progress
.arg
, h
->client
, &h
->queue
, &h
->progress
);
272 case CURLINFO_HEADER_OUT
:
273 utype
|= PHP_HTTP_CLIENT_DEBUG_HEADER
;
276 case CURLINFO_SSL_DATA_OUT
:
277 utype
|= PHP_HTTP_CLIENT_DEBUG_SSL
;
280 case CURLINFO_DATA_OUT
:
282 utype
|= PHP_HTTP_CLIENT_DEBUG_OUT
;
283 h
->progress
.info
= "send";
286 case CURLINFO_HEADER_IN
:
287 utype
|= PHP_HTTP_CLIENT_DEBUG_HEADER
;
290 case CURLINFO_SSL_DATA_IN
:
291 utype
|= PHP_HTTP_CLIENT_DEBUG_SSL
;
294 case CURLINFO_DATA_IN
:
296 utype
|= PHP_HTTP_CLIENT_DEBUG_IN
;
297 h
->progress
.info
= "receive";
304 if (h
->client
->callback
.debug
.func
) {
305 h
->client
->callback
.debug
.func(h
->client
->callback
.debug
.arg
, h
->client
, &h
->queue
, utype
, data
, length
);
310 _dpf(type
, data
, length
);
316 static size_t php_http_curle_header_callback(char *data
, size_t n
, size_t l
, void *arg
)
318 php_http_client_curl_handler_t
*h
= arg
;
320 return php_http_buffer_append(&h
->response
.headers
, data
, n
* l
);
323 static size_t php_http_curle_body_callback(char *data
, size_t n
, size_t l
, void *arg
)
325 php_http_client_curl_handler_t
*h
= arg
;
327 return php_http_message_body_append(h
->response
.body
, data
, n
*l
);
330 static ZEND_RESULT_CODE
php_http_curle_get_info(CURL
*ch
, HashTable
*info
)
336 struct curl_slist
*s
= NULL
, *p
= NULL
;
341 /* BEGIN::CURLINFO */
342 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_EFFECTIVE_URL
, &c
)) {
343 ZVAL_STRING(&tmp
, STR_PTR(c
));
344 zend_hash_str_update(info
, "effective_url", lenof("effective_url"), &tmp
);
346 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_RESPONSE_CODE
, &l
)) {
348 zend_hash_str_update(info
, "response_code", lenof("response_code"), &tmp
);
350 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TOTAL_TIME
, &d
)) {
351 ZVAL_DOUBLE(&tmp
, d
);
352 zend_hash_str_update(info
, "total_time", lenof("total_time"), &tmp
);
354 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_NAMELOOKUP_TIME
, &d
)) {
355 ZVAL_DOUBLE(&tmp
, d
);
356 zend_hash_str_update(info
, "namelookup_time", lenof("namelookup_time"), &tmp
);
358 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONNECT_TIME
, &d
)) {
359 ZVAL_DOUBLE(&tmp
, d
);
360 zend_hash_str_update(info
, "connect_time", lenof("connect_time"), &tmp
);
362 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRETRANSFER_TIME
, &d
)) {
363 ZVAL_DOUBLE(&tmp
, d
);
364 zend_hash_str_update(info
, "pretransfer_time", lenof("pretransfer_time"), &tmp
);
366 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SIZE_UPLOAD
, &d
)) {
367 ZVAL_DOUBLE(&tmp
, d
);
368 zend_hash_str_update(info
, "size_upload", lenof("size_upload"), &tmp
);
370 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SIZE_DOWNLOAD
, &d
)) {
371 ZVAL_DOUBLE(&tmp
, d
);
372 zend_hash_str_update(info
, "size_download", lenof("size_download"), &tmp
);
374 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_DOWNLOAD
, &d
)) {
375 ZVAL_DOUBLE(&tmp
, d
);
376 zend_hash_str_update(info
, "speed_download", lenof("speed_download"), &tmp
);
378 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_UPLOAD
, &d
)) {
379 ZVAL_DOUBLE(&tmp
, d
);
380 zend_hash_str_update(info
, "speed_upload", lenof("speed_upload"), &tmp
);
382 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HEADER_SIZE
, &l
)) {
384 zend_hash_str_update(info
, "header_size", lenof("header_size"), &tmp
);
386 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REQUEST_SIZE
, &l
)) {
388 zend_hash_str_update(info
, "request_size", lenof("request_size"), &tmp
);
390 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SSL_VERIFYRESULT
, &l
)) {
392 zend_hash_str_update(info
, "ssl_verifyresult", lenof("ssl_verifyresult"), &tmp
);
394 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_FILETIME
, &l
)) {
396 zend_hash_str_update(info
, "filetime", lenof("filetime"), &tmp
);
398 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_DOWNLOAD
, &d
)) {
399 ZVAL_DOUBLE(&tmp
, d
);
400 zend_hash_str_update(info
, "content_length_download", lenof("content_length_download"), &tmp
);
402 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_UPLOAD
, &d
)) {
403 ZVAL_DOUBLE(&tmp
, d
);
404 zend_hash_str_update(info
, "content_length_upload", lenof("content_length_upload"), &tmp
);
406 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_STARTTRANSFER_TIME
, &d
)) {
407 ZVAL_DOUBLE(&tmp
, d
);
408 zend_hash_str_update(info
, "starttransfer_time", lenof("starttransfer_time"), &tmp
);
410 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_TYPE
, &c
)) {
411 ZVAL_STRING(&tmp
, STR_PTR(c
));
412 zend_hash_str_update(info
, "content_type", lenof("content_type"), &tmp
);
414 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_TIME
, &d
)) {
415 ZVAL_DOUBLE(&tmp
, d
);
416 zend_hash_str_update(info
, "redirect_time", lenof("redirect_time"), &tmp
);
418 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_COUNT
, &l
)) {
420 zend_hash_str_update(info
, "redirect_count", lenof("redirect_count"), &tmp
);
422 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTP_CONNECTCODE
, &l
)) {
424 zend_hash_str_update(info
, "connect_code", lenof("connect_code"), &tmp
);
426 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTPAUTH_AVAIL
, &l
)) {
428 zend_hash_str_update(info
, "httpauth_avail", lenof("httpauth_avail"), &tmp
);
430 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXYAUTH_AVAIL
, &l
)) {
432 zend_hash_str_update(info
, "proxyauth_avail", lenof("proxyauth_avail"), &tmp
);
434 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_OS_ERRNO
, &l
)) {
436 zend_hash_str_update(info
, "os_errno", lenof("os_errno"), &tmp
);
438 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_NUM_CONNECTS
, &l
)) {
440 zend_hash_str_update(info
, "num_connects", lenof("num_connects"), &tmp
);
442 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SSL_ENGINES
, &s
)) {
444 for (p
= s
; p
; p
= p
->next
) {
446 add_next_index_string(&tmp
, p
->data
);
449 zend_hash_str_update(info
, "ssl_engines", lenof("ssl_engines"), &tmp
);
450 curl_slist_free_all(s
);
452 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_URL
, &c
)) {
453 ZVAL_STRING(&tmp
, STR_PTR(c
));
454 zend_hash_str_update(info
, "redirect_url", lenof("redirect_url"), &tmp
);
456 #if PHP_HTTP_CURL_VERSION(7,19,0)
457 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRIMARY_IP
, &c
)) {
458 ZVAL_STRING(&tmp
, STR_PTR(c
));
459 zend_hash_str_update(info
, "primary_ip", lenof("primary_ip"), &tmp
);
462 #if PHP_HTTP_CURL_VERSION(7,19,0)
463 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_APPCONNECT_TIME
, &d
)) {
464 ZVAL_DOUBLE(&tmp
, d
);
465 zend_hash_str_update(info
, "appconnect_time", lenof("appconnect_time"), &tmp
);
468 #if PHP_HTTP_CURL_VERSION(7,19,4)
469 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONDITION_UNMET
, &l
)) {
471 zend_hash_str_update(info
, "condition_unmet", lenof("condition_unmet"), &tmp
);
474 #if PHP_HTTP_CURL_VERSION(7,21,0)
475 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRIMARY_PORT
, &l
)) {
477 zend_hash_str_update(info
, "primary_port", lenof("primary_port"), &tmp
);
480 #if PHP_HTTP_CURL_VERSION(7,21,0)
481 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_LOCAL_IP
, &c
)) {
482 ZVAL_STRING(&tmp
, STR_PTR(c
));
483 zend_hash_str_update(info
, "local_ip", lenof("local_ip"), &tmp
);
486 #if PHP_HTTP_CURL_VERSION(7,21,0)
487 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_LOCAL_PORT
, &l
)) {
489 zend_hash_str_update(info
, "local_port", lenof("local_port"), &tmp
);
492 #if PHP_HTTP_CURL_VERSION(7,50,0)
493 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTP_VERSION
, &l
)) {
495 zend_hash_str_update(info
, "http_version", lenof("http_version"), &tmp
);
498 #if PHP_HTTP_CURL_VERSION(7,52,0)
499 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXY_SSL_VERIFYRESULT
, &l
)) {
501 zend_hash_str_update(info
, "proxy_ssl_verifyresult", lenof("proxy_ssl_verifyresult"), &tmp
);
504 #if PHP_HTTP_CURL_VERSION(7,52,0)
505 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROTOCOL
, &l
)) {
507 zend_hash_str_update(info
, "protocol", lenof("protocol"), &tmp
);
510 #if PHP_HTTP_CURL_VERSION(7,52,0)
511 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SCHEME
, &c
)) {
512 ZVAL_STRING(&tmp
, STR_PTR(c
));
513 zend_hash_str_update(info
, "scheme", lenof("scheme"), &tmp
);
516 #if PHP_HTTP_CURL_VERSION(7,66,0)
517 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_RETRY_AFTER
, &o
)) {
519 zend_hash_str_update(info
, "retry_after", lenof("retry_after"), &tmp
);
522 #if PHP_HTTP_CURL_VERSION(7,72,0)
523 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_EFFECTIVE_METHOD
, &c
)) {
524 ZVAL_STRING(&tmp
, STR_PTR(c
));
525 zend_hash_str_update(info
, "effective_method", lenof("effective_method"), &tmp
);
528 #if PHP_HTTP_CURL_VERSION(7,73,0)
529 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXY_ERROR
, &l
)) {
531 zend_hash_str_update(info
, "proxy_error", lenof("proxy_error"), &tmp
);
537 #if PHP_HTTP_CURL_VERSION(7,34,0)
539 zval ti_array
, subarray
;
540 struct curl_tlssessioninfo
*ti
;
542 #if PHP_HTTP_CURL_VERSION(7,48,0)
543 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TLS_SSL_PTR
, &ti
)) {
545 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TLS_SESSION
, &ti
)) {
549 ZVAL_NULL(&subarray
);
550 array_init(&ti_array
);
552 switch (ti
->backend
) {
553 case CURLSSLBACKEND_NONE
:
556 case CURLSSLBACKEND_OPENSSL
:
558 #if PHP_HTTP_HAVE_LIBCURL_OPENSSL
560 #if PHP_HTTP_CURL_VERSION(7,48,0)
561 SSL
*ssl
= ti
->internals
;
562 SSL_CTX
*ctx
= ssl
? SSL_get_SSL_CTX(ssl
) : NULL
;
564 SSL_CTX
*ctx
= ti
->internals
;
567 array_init(&subarray
);
569 add_assoc_long_ex(&subarray
, ZEND_STRL("number"), SSL_CTX_sess_number(ctx
));
570 add_assoc_long_ex(&subarray
, ZEND_STRL("connect"), SSL_CTX_sess_connect(ctx
));
571 add_assoc_long_ex(&subarray
, ZEND_STRL("connect_good"), SSL_CTX_sess_connect_good(ctx
));
572 add_assoc_long_ex(&subarray
, ZEND_STRL("connect_renegotiate"), SSL_CTX_sess_connect_renegotiate(ctx
));
573 add_assoc_long_ex(&subarray
, ZEND_STRL("hits"), SSL_CTX_sess_hits(ctx
));
574 add_assoc_long_ex(&subarray
, ZEND_STRL("cache_full"), SSL_CTX_sess_cache_full(ctx
));
579 case CURLSSLBACKEND_GNUTLS
:
581 #if PHP_HTTP_HAVE_LIBCURL_GNUTLS
583 gnutls_session_t sess
= ti
->internals
;
586 array_init(&subarray
);
588 if ((desc
= gnutls_session_get_desc(sess
))) {
589 add_assoc_string_ex(&subarray
, ZEND_STRL("desc"), desc
);
592 add_assoc_bool_ex(&subarray
, ZEND_STRL("resumed"), gnutls_session_is_resumed(sess
));
597 case CURLSSLBACKEND_NSS
:
600 #if !PHP_HTTP_CURL_VERSION(7,39,0)
601 case CURLSSLBACKEND_QSOSSL
:
605 case CURLSSLBACKEND_GSKIT
:
609 case CURLSSLBACKEND_POLARSSL
:
610 backend
= "polarssl";
612 case CURLSSLBACKEND_CYASSL
:
615 case CURLSSLBACKEND_SCHANNEL
:
616 backend
= "schannel";
618 case CURLSSLBACKEND_DARWINSSL
:
619 backend
= "darwinssl";
624 add_assoc_string_ex(&ti_array
, ZEND_STRL("backend"), backend
);
625 add_assoc_zval_ex(&ti_array
, ZEND_STRL("internals"), &subarray
);
626 zend_hash_str_update(info
, "tls_session", lenof("tls_session"), &ti_array
);
631 #if (PHP_HTTP_CURL_VERSION(7,19,1) && PHP_HTTP_HAVE_LIBCURL_OPENSSL) || \
632 (PHP_HTTP_CURL_VERSION(7,34,0) && PHP_HTTP_HAVE_LIBCURL_NSS) || \
633 (PHP_HTTP_CURL_VERSION(7,42,0) && PHP_HTTP_HAVE_LIBCURL_GNUTLS) || \
634 (PHP_HTTP_CURL_VERSION(7,39,0) && PHP_HTTP_HAVE_LIBCURL_GSKIT)
637 zval ci_array
, subarray
;
638 struct curl_certinfo
*ci
;
639 char *colon
, *keyname
;
641 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CERTINFO
, &ci
)) {
642 array_init(&ci_array
);
644 for (i
= 0; i
< ci
->num_of_certs
; ++i
) {
647 array_init(&subarray
);
648 for (p
= s
; p
; p
= p
->next
) {
650 if ((colon
= strchr(p
->data
, ':'))) {
651 keyname
= estrndup(p
->data
, colon
- p
->data
);
652 add_assoc_string_ex(&subarray
, keyname
, colon
- p
->data
, colon
+ 1);
655 add_next_index_string(&subarray
, p
->data
);
659 add_next_index_zval(&ci_array
, &subarray
);
661 zend_hash_str_update(info
, "certinfo", lenof("certinfo"), &ci_array
);
666 php_http_curle_storage_t
*st
= php_http_curle_get_storage(ch
);
668 ZVAL_LONG(&tmp
, st
->errorcode
);
669 zend_hash_str_update(info
, "curlcode", lenof("curlcode"), &tmp
);
670 ZVAL_STRING(&tmp
, st
->errorbuffer
);
671 zend_hash_str_update(info
, "error", lenof("error"), &tmp
);
677 static int compare_queue(php_http_client_enqueue_t
*e
, void *handle
)
679 return handle
== ((php_http_client_curl_handler_t
*) e
->opaque
)->handle
;
682 static php_http_message_t
*php_http_curlm_responseparser(php_http_client_curl_handler_t
*h
)
684 php_http_message_t
*response
;
685 php_http_header_parser_t parser
;
688 response
= php_http_message_init(NULL
, 0, h
->response
.body
);
689 php_http_header_parser_init(&parser
);
690 while (h
->response
.headers
.used
) {
691 php_http_header_parser_state_t st
= php_http_header_parser_parse(&parser
,
692 &h
->response
.headers
, PHP_HTTP_HEADER_PARSER_CLEANUP
, &response
->hdrs
,
693 (php_http_info_callback_t
) php_http_message_info_callback
, (void *) &response
);
694 if (PHP_HTTP_HEADER_PARSER_STATE_FAILURE
== st
) {
698 php_http_header_parser_dtor(&parser
);
700 /* move body to right message */
701 if (response
->body
!= h
->response
.body
) {
702 php_http_message_t
*ptr
= response
;
704 while (ptr
->parent
) {
707 php_http_message_body_free(&response
->body
);
708 response
->body
= ptr
->body
;
711 php_http_message_body_addref(h
->response
.body
);
713 /* let's update the response headers */
714 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Length")))) {
716 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Length", lenof("X-Original-Content-Length"), &tmp
);
718 if ((zh
= php_http_message_header(response
, ZEND_STRL("Transfer-Encoding")))) {
720 zend_hash_str_del(&response
->hdrs
, "Transfer-Encoding", lenof("Transfer-Encoding"));
721 zend_hash_str_update(&response
->hdrs
, "X-Original-Transfer-Encoding", lenof("X-Original-Transfer-Encoding"), &tmp
);
723 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Range")))) {
725 zend_hash_str_del(&response
->hdrs
, "Content-Range", lenof("Content-Range"));
726 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Range", lenof("X-Original-Content-Range"), &tmp
);
728 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Encoding")))) {
730 zend_hash_str_del(&response
->hdrs
, "Content-Encoding", lenof("Content-Encoding"));
731 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Encoding", lenof("X-Original-Content-Encoding"), &tmp
);
733 php_http_message_update_headers(response
);
738 void php_http_client_curl_responsehandler(php_http_client_t
*context
)
740 int err_count
= 0, remaining
= 0;
741 php_http_curle_storage_t
*st
, *err
= NULL
;
742 php_http_client_enqueue_t
*enqueue
;
743 php_http_client_curl_t
*curl
= context
->ctx
;
746 CURLMsg
*msg
= curl_multi_info_read(curl
->handle
->multi
, &remaining
);
748 if (msg
&& CURLMSG_DONE
== msg
->msg
) {
749 if (CURLE_OK
!= msg
->data
.result
) {
750 st
= php_http_curle_get_storage(msg
->easy_handle
);
751 st
->errorcode
= msg
->data
.result
;
753 /* defer the warnings/exceptions, so the callback is still called for this request */
755 err
= ecalloc(remaining
+ 1, sizeof(*err
));
757 memcpy(&err
[err_count
], st
, sizeof(*st
));
759 err
[err_count
].url
= estrdup(st
->url
);
764 if ((enqueue
= php_http_client_enqueued(context
, msg
->easy_handle
, compare_queue
))) {
765 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
766 php_http_message_t
*response
= php_http_curlm_responseparser(handler
);
769 context
->callback
.response
.func(context
->callback
.response
.arg
, context
, &handler
->queue
, &response
);
770 php_http_message_free(&response
);
780 php_error_docref(NULL
, E_WARNING
, "%s; %s (%s)", curl_easy_strerror(err
[i
].errorcode
), err
[i
].errorbuffer
, STR_PTR(err
[i
].url
));
784 } while (++i
< err_count
);
790 void php_http_client_curl_loop(php_http_client_t
*client
, curl_socket_t s
, int curl_action
)
793 php_http_client_curl_t
*curl
= client
->ctx
;
796 fprintf(stderr
, "H");
800 rc
= curl_multi_socket_action(curl
->handle
->multi
, s
, curl_action
, &curl
->unfinished
);
801 } while (CURLM_CALL_MULTI_PERFORM
== rc
);
803 if (CURLM_OK
!= rc
) {
804 php_error_docref(NULL
, E_WARNING
, "%s", curl_multi_strerror(rc
));
807 php_http_client_curl_responsehandler(client
);
812 static php_http_options_t php_http_curle_options
, php_http_curlm_options
;
814 #define PHP_HTTP_CURLE_OPTION_CHECK_STRLEN 0x0001
815 #define PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR 0x0002
816 #define PHP_HTTP_CURLE_OPTION_TRANSFORM_MS 0x0004
817 #define PHP_HTTP_CURLE_OPTION_IGNORE_RC 0x0008
819 static ZEND_RESULT_CODE
php_http_curle_option_set_ssl_verifyhost(php_http_option_t
*opt
, zval
*val
, void *userdata
)
821 php_http_client_curl_handler_t
*curl
= userdata
;
822 CURL
*ch
= curl
->handle
;
824 if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, Z_TYPE_P(val
) == IS_TRUE
? 2 : 0)) {
830 static ZEND_RESULT_CODE
php_http_curle_option_set_cookiesession(php_http_option_t
*opt
, zval
*val
, void *userdata
)
832 php_http_client_curl_handler_t
*curl
= userdata
;
833 CURL
*ch
= curl
->handle
;
835 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIESESSION
, (long) (Z_TYPE_P(val
) == IS_TRUE
))) {
838 if (Z_TYPE_P(val
) == IS_TRUE
) {
840 fprintf(stderr
, "CURLOPT_COOKIELIST: SESS\n");
842 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIELIST
, "SESS")) {
850 static ZEND_RESULT_CODE
php_http_curle_option_set_cookiestore(php_http_option_t
*opt
, zval
*val
, void *userdata
)
852 php_http_client_curl_handler_t
*curl
= userdata
;
853 CURL
*ch
= curl
->handle
;
854 php_http_curle_storage_t
*storage
= php_http_curle_get_storage(curl
->handle
);
856 if (storage
->cookiestore
) {
857 pefree(storage
->cookiestore
, 1);
859 if (val
&& Z_TYPE_P(val
) == IS_STRING
&& Z_STRLEN_P(val
)) {
860 storage
->cookiestore
= pestrndup(Z_STRVAL_P(val
), Z_STRLEN_P(val
), 1);
862 storage
->cookiestore
= NULL
;
866 fprintf(stderr
, "CURLOPT_COOKIEFILE: %s\n", storage
->cookiestore
);
868 // does NOT enable ch->data.cookies until transfer; adds to ch->stsate.cookielist
869 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIEFILE
, storage
->cookiestore
? storage
->cookiestore
: "")) {
873 fprintf(stderr
, "CURLOPT_COOKIEJAR: %s\n", storage
->cookiestore
);
875 // enables ch->data.cookies
876 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIEJAR
, storage
->cookiestore
)) {
883 static ZEND_RESULT_CODE
php_http_curle_option_set_cookies(php_http_option_t
*opt
, zval
*val
, void *userdata
)
885 php_http_client_curl_handler_t
*curl
= userdata
;
886 CURL
*ch
= curl
->handle
;
888 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
889 HashTable
*ht
= HASH_OF(val
);
891 if (curl
->options
.encode_cookies
) {
892 if (SUCCESS
== php_http_url_encode_hash_ex(ht
, &curl
->options
.cookies
, ZEND_STRL(";"), ZEND_STRL("="), NULL
, 0)) {
893 php_http_buffer_fix(&curl
->options
.cookies
);
894 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, curl
->options
.cookies
.data
)) {
901 php_http_arrkey_t cookie_key
;
904 ZEND_HASH_FOREACH_KEY_VAL(ht
, cookie_key
.h
, cookie_key
.key
, cookie_val
)
906 zend_string
*zs
= zval_get_string(cookie_val
);
908 php_http_arrkey_stringify(&cookie_key
, NULL
);
909 php_http_buffer_appendf(&curl
->options
.cookies
, "%s=%s; ", cookie_key
.key
->val
, zs
->val
);
910 php_http_arrkey_dtor(&cookie_key
);
912 zend_string_release(zs
);
914 ZEND_HASH_FOREACH_END();
916 php_http_buffer_fix(&curl
->options
.cookies
);
917 if (curl
->options
.cookies
.used
) {
918 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, curl
->options
.cookies
.data
)) {
924 php_http_buffer_reset(&curl
->options
.cookies
);
925 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, NULL
)) {
932 static ZEND_RESULT_CODE
php_http_curle_option_set_encodecookies(php_http_option_t
*opt
, zval
*val
, void *userdata
)
934 php_http_client_curl_handler_t
*curl
= userdata
;
936 curl
->options
.encode_cookies
= Z_TYPE_P(val
) == IS_TRUE
;
940 static ZEND_RESULT_CODE
php_http_curle_option_set_lastmodified(php_http_option_t
*opt
, zval
*val
, void *userdata
)
942 php_http_client_curl_handler_t
*curl
= userdata
;
943 CURL
*ch
= curl
->handle
;
946 if (Z_LVAL_P(val
) > 0) {
947 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, Z_LVAL_P(val
))) {
951 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, (long) sapi_get_request_time() + Z_LVAL_P(val
))) {
955 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMECONDITION
, (long) (curl
->options
.range_request
? CURL_TIMECOND_IFUNMODSINCE
: CURL_TIMECOND_IFMODSINCE
))) {
959 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, 0)
960 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMECONDITION
, 0)
968 #if PHP_HTTP_CURL_VERSION(7,64,1)
969 static ZEND_RESULT_CODE
php_http_curle_option_set_altsvc_ctrl(php_http_option_t
*opt
, zval
*val
, void *userdata
)
971 php_http_client_curl_handler_t
*curl
= userdata
;
972 CURL
*ch
= curl
->handle
;
975 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_ALTSVC_CTRL
, Z_LVAL_P(val
))) {
983 static ZEND_RESULT_CODE
php_http_curle_option_set_compress(php_http_option_t
*opt
, zval
*val
, void *userdata
)
985 php_http_client_curl_handler_t
*curl
= userdata
;
986 CURL
*ch
= curl
->handle
;
988 #if !PHP_HTTP_CURL_VERSION(7,21,6)
989 # define CURLOPT_ACCEPT_ENCODING CURLOPT_ENCODING
991 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_ACCEPT_ENCODING
, Z_TYPE_P(val
) == IS_TRUE
? "" : NULL
)) {
997 static ZEND_RESULT_CODE
php_http_curle_option_set_etag(php_http_option_t
*opt
, zval
*val
, void *userdata
)
999 php_http_client_curl_handler_t
*curl
= userdata
;
1000 php_http_buffer_t header
;
1002 if (val
&& Z_TYPE_P(val
) == IS_STRING
&& Z_STRLEN_P(val
)) {
1003 zend_bool is_quoted
= !((Z_STRVAL_P(val
)[0] != '"') || (Z_STRVAL_P(val
)[Z_STRLEN_P(val
)-1] != '"'));
1004 php_http_buffer_init(&header
);
1005 php_http_buffer_appendf(&header
, is_quoted
?"%s: %s":"%s: \"%s\"", curl
->options
.range_request
?"If-Match":"If-None-Match", Z_STRVAL_P(val
));
1006 php_http_buffer_fix(&header
);
1007 curl
->options
.headers
= curl_slist_append(curl
->options
.headers
, header
.data
);
1008 php_http_buffer_dtor(&header
);
1013 static ZEND_RESULT_CODE
php_http_curle_option_set_range(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1015 php_http_client_curl_handler_t
*curl
= userdata
;
1016 CURL
*ch
= curl
->handle
;
1018 php_http_buffer_reset(&curl
->options
.ranges
);
1020 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1022 HashTable
*ht
= HASH_OF(val
);
1024 ZEND_HASH_FOREACH_VAL(ht
, rr
)
1026 if (Z_TYPE_P(rr
) == IS_ARRAY
) {
1027 if (2 == php_http_array_list(Z_ARRVAL_P(rr
), 2, &rb
, &re
)) {
1028 zend_long rbl
= zval_get_long(rb
), rel
= zval_get_long(re
);
1032 php_http_buffer_appendf(&curl
->options
.ranges
, "%ld-%ld,", rbl
, rel
);
1034 php_http_buffer_appendf(&curl
->options
.ranges
, "%ld-", rbl
);
1036 } else if (rel
> 0) {
1037 php_http_buffer_appendf(&curl
->options
.ranges
, "-%ld", rel
);
1042 ZEND_HASH_FOREACH_END();
1044 if (curl
->options
.ranges
.used
) {
1045 curl
->options
.range_request
= 1;
1046 /* ditch last comma */
1047 curl
->options
.ranges
.data
[curl
->options
.ranges
.used
- 1] = '\0';
1051 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RANGE
, curl
->options
.ranges
.data
)) {
1057 static ZEND_RESULT_CODE
php_http_curle_option_set_resume(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1059 php_http_client_curl_handler_t
*curl
= userdata
;
1060 CURL
*ch
= curl
->handle
;
1062 if (Z_LVAL_P(val
) > 0) {
1063 curl
->options
.range_request
= 1;
1065 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESUME_FROM
, Z_LVAL_P(val
))) {
1071 static ZEND_RESULT_CODE
php_http_curle_option_set_retrydelay(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1073 php_http_client_curl_handler_t
*curl
= userdata
;
1075 curl
->options
.retry
.delay
= Z_DVAL_P(val
);
1079 static ZEND_RESULT_CODE
php_http_curle_option_set_retrycount(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1081 php_http_client_curl_handler_t
*curl
= userdata
;
1083 curl
->options
.retry
.count
= Z_LVAL_P(val
);
1087 static ZEND_RESULT_CODE
php_http_curle_option_set_redirect(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1089 php_http_client_curl_handler_t
*curl
= userdata
;
1090 CURL
*ch
= curl
->handle
;
1092 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, Z_LVAL_P(val
) ? 1L : 0L)
1093 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_MAXREDIRS
, curl
->options
.redirects
= Z_LVAL_P(val
))
1100 static ZEND_RESULT_CODE
php_http_curle_option_set_portrange(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1102 php_http_client_curl_handler_t
*curl
= userdata
;
1103 CURL
*ch
= curl
->handle
;
1104 long localport
= 0, localportrange
= 0;
1106 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1109 switch (php_http_array_list(Z_ARRVAL_P(val
), 2, &zps
, &zpe
)) {
1111 localportrange
= labs(zval_get_long(zps
)-zval_get_long(zpe
))+1L;
1114 localport
= (zval_get_long(zpe
) > 0) ? MIN(zval_get_long(zps
), zval_get_long(zpe
)) : zval_get_long(zps
);
1120 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_LOCALPORT
, localport
)
1121 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_LOCALPORTRANGE
, localportrange
)
1128 #if PHP_HTTP_CURL_VERSION(7,37,0)
1129 static ZEND_RESULT_CODE
php_http_curle_option_set_proxyheader(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1131 php_http_client_curl_handler_t
*curl
= userdata
;
1133 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1134 php_http_arrkey_t header_key
;
1136 php_http_buffer_t header
;
1138 php_http_buffer_init(&header
);
1139 ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(val
), header_key
.h
, header_key
.key
, header_val
)
1141 if (header_key
.key
) {
1142 zend_string
*zs
= zval_get_string(header_val
);
1144 php_http_buffer_appendf(&header
, "%s: %s", header_key
.key
->val
, zs
->val
);
1145 zend_string_release(zs
);
1147 php_http_buffer_fix(&header
);
1148 curl
->options
.proxyheaders
= curl_slist_append(curl
->options
.proxyheaders
, header
.data
);
1149 php_http_buffer_reset(&header
);
1153 ZEND_HASH_FOREACH_END();
1154 php_http_buffer_dtor(&header
);
1156 if (CURLE_OK
!= curl_easy_setopt(curl
->handle
, CURLOPT_PROXYHEADER
, curl
->options
.proxyheaders
)) {
1159 if (CURLE_OK
!= curl_easy_setopt(curl
->handle
, CURLOPT_HEADEROPT
, CURLHEADER_SEPARATE
)) {
1160 curl_easy_setopt(curl
->handle
, CURLOPT_PROXYHEADER
, NULL
);
1167 #if PHP_HTTP_CURL_VERSION(7,21,3)
1168 static ZEND_RESULT_CODE
php_http_curle_option_set_resolve(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1170 php_http_client_curl_handler_t
*curl
= userdata
;
1171 CURL
*ch
= curl
->handle
;
1173 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1174 HashTable
*ht
= HASH_OF(val
);
1177 ZEND_HASH_FOREACH_VAL(ht
, data
)
1179 zend_string
*zs
= zval_get_string(data
);
1180 curl
->options
.resolve
= curl_slist_append(curl
->options
.resolve
, zs
->val
);
1181 zend_string_release(zs
);
1183 ZEND_HASH_FOREACH_END();
1185 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESOLVE
, curl
->options
.resolve
)) {
1189 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESOLVE
, NULL
)) {
1197 #if PHP_HTTP_CURL_VERSION(7,21,4) && PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
1198 static ZEND_RESULT_CODE
php_http_curle_option_set_ssl_tlsauthtype(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1200 php_http_client_curl_handler_t
*curl
= userdata
;
1201 CURL
*ch
= curl
->handle
;
1203 if (val
&& Z_LVAL_P(val
)) {
1204 switch (Z_LVAL_P(val
)) {
1205 case CURL_TLSAUTH_NONE
:
1207 case CURL_TLSAUTH_SRP
:
1208 if (CURLE_OK
== curl_easy_setopt(ch
, opt
->option
, "SRP")) {
1216 if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, "NONE")) {
1223 static void php_http_curle_options_init(php_http_options_t
*registry
)
1225 php_http_option_t
*opt
;
1228 #if PHP_HTTP_CURL_VERSION(7,42,0)
1229 php_http_option_register(registry
, ZEND_STRL("path_as_is"), CURLOPT_PATH_AS_IS
, _IS_BOOL
);
1233 php_http_option_register(registry
, ZEND_STRL("proxyhost"), CURLOPT_PROXY
, IS_STRING
);
1234 php_http_option_register(registry
, ZEND_STRL("proxytype"), CURLOPT_PROXYTYPE
, IS_LONG
);
1235 php_http_option_register(registry
, ZEND_STRL("proxyport"), CURLOPT_PROXYPORT
, IS_LONG
);
1236 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyauth"), CURLOPT_PROXYUSERPWD
, IS_STRING
))) {
1237 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1239 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyauthtype"), CURLOPT_PROXYAUTH
, IS_LONG
))) {
1240 Z_LVAL(opt
->defval
) = CURLAUTH_ANYSAFE
;
1242 php_http_option_register(registry
, ZEND_STRL("proxytunnel"), CURLOPT_HTTPPROXYTUNNEL
, _IS_BOOL
);
1243 #if PHP_HTTP_CURL_VERSION(7,19,4)
1244 php_http_option_register(registry
, ZEND_STRL("noproxy"), CURLOPT_NOPROXY
, IS_STRING
);
1246 #if PHP_HTTP_CURL_VERSION(7,55,0)
1247 php_http_option_register(registry
, ZEND_STRL("socks5_auth"), CURLOPT_SOCKS5_AUTH
, IS_LONG
);
1250 #if PHP_HTTP_CURL_VERSION(7,37,0)
1251 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyheader"), CURLOPT_PROXYHEADER
, IS_ARRAY
))) {
1252 opt
->setter
= php_http_curle_option_set_proxyheader
;
1255 #if PHP_HTTP_CURL_VERSION(7,43,0)
1256 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_GSSAPI
)
1257 && (opt
= php_http_option_register(registry
, ZEND_STRL("proxy_service_name"), CURLOPT_PROXY_SERVICE_NAME
, IS_STRING
))
1259 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1262 #if PHP_HTTP_CURL_VERSION(7,60,0)
1263 php_http_option_register(registry
, ZEND_STRL("haproxy_protocol"), CURLOPT_HAPROXYPROTOCOL
, _IS_BOOL
);
1267 #if PHP_HTTP_CURL_VERSION(7,40,0)
1268 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_UNIX_SOCKETS
)) {
1269 if ((opt
= php_http_option_register(registry
, ZEND_STRL("unix_socket_path"), CURLOPT_UNIX_SOCKET_PATH
, IS_STRING
))) {
1270 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1271 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1273 #if PHP_HTTP_CURL_VERSION(7,53,0)
1274 if ((opt
= php_http_option_register(registry
, ZEND_STRL("abstract_unix_socket"), CURLOPT_ABSTRACT_UNIX_SOCKET
, IS_STRING
))) {
1275 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1282 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_cache_timeout"), CURLOPT_DNS_CACHE_TIMEOUT
, IS_LONG
))) {
1283 Z_LVAL(opt
->defval
) = 60;
1285 php_http_option_register(registry
, ZEND_STRL("ipresolve"), CURLOPT_IPRESOLVE
, IS_LONG
);
1286 #if PHP_HTTP_CURL_VERSION(7,21,3)
1287 if ((opt
= php_http_option_register(registry
, ZEND_STRL("resolve"), CURLOPT_RESOLVE
, IS_ARRAY
))) {
1288 opt
->setter
= php_http_curle_option_set_resolve
;
1291 #if PHP_HTTP_HAVE_LIBCURL_ARES
1292 # if PHP_HTTP_CURL_VERSION(7,24,0)
1293 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_servers"), CURLOPT_DNS_SERVERS
, IS_STRING
))) {
1294 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1297 # if PHP_HTTP_CURL_VERSION(7,33,0)
1298 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_interface"), CURLOPT_DNS_INTERFACE
, IS_STRING
))) {
1299 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1301 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_local_ip4"), CURLOPT_DNS_LOCAL_IP4
, IS_STRING
))) {
1302 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1304 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_local_ip6"), CURLOPT_DNS_LOCAL_IP6
, IS_STRING
))) {
1305 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1309 #if PHP_HTTP_CURL_VERSION(7,60,0)
1310 php_http_option_register(registry
, ZEND_STRL("dns_shuffle_addresses"), CURLOPT_DNS_SHUFFLE_ADDRESSES
, _IS_BOOL
);
1312 #if PHP_HTTP_CURL_VERSION(7,62,0)
1313 php_http_option_register(registry
, ZEND_STRL("doh_url"), CURLOPT_DOH_URL
, IS_STRING
);
1318 php_http_option_register(registry
, ZEND_STRL("low_speed_limit"), CURLOPT_LOW_SPEED_LIMIT
, IS_LONG
);
1319 php_http_option_register(registry
, ZEND_STRL("low_speed_time"), CURLOPT_LOW_SPEED_TIME
, IS_LONG
);
1322 php_http_option_register(registry, ZEND_STRL("max_send_speed"), CURLOPT_MAX_SEND_SPEED_LARGE, IS_LONG);
1323 php_http_option_register(registry, ZEND_STRL("max_recv_speed"), CURLOPT_MAX_RECV_SPEED_LARGE, IS_LONG);
1326 /* connection handling */
1328 if ((opt = php_http_option_register(registry, ZEND_STRL("maxconnects"), CURLOPT_MAXCONNECTS, IS_LONG))) {
1329 Z_LVAL(opt->defval) = 5;
1332 php_http_option_register(registry
, ZEND_STRL("fresh_connect"), CURLOPT_FRESH_CONNECT
, _IS_BOOL
);
1333 php_http_option_register(registry
, ZEND_STRL("forbid_reuse"), CURLOPT_FORBID_REUSE
, _IS_BOOL
);
1334 #if PHP_HTTP_CURL_VERSION(7,65,0)
1335 if ((opt
= php_http_option_register(registry
, ZEND_STRL("maxage_conn"), CURLOPT_MAXAGE_CONN
, IS_LONG
))) {
1336 ZVAL_LONG(&opt
->defval
, 118);
1340 /* outgoing interface */
1341 php_http_option_register(registry
, ZEND_STRL("interface"), CURLOPT_INTERFACE
, IS_STRING
);
1342 if ((opt
= php_http_option_register(registry
, ZEND_STRL("portrange"), CURLOPT_LOCALPORT
, IS_ARRAY
))) {
1343 opt
->setter
= php_http_curle_option_set_portrange
;
1346 /* another endpoint port */
1347 php_http_option_register(registry
, ZEND_STRL("port"), CURLOPT_PORT
, IS_LONG
);
1349 /* RFC4007 zone_id */
1350 #if PHP_HTTP_CURL_VERSION(7,19,0)
1351 php_http_option_register(registry
, ZEND_STRL("address_scope"), CURLOPT_ADDRESS_SCOPE
, IS_LONG
);
1355 if ((opt
= php_http_option_register(registry
, ZEND_STRL("httpauth"), CURLOPT_USERPWD
, IS_STRING
))) {
1356 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1358 if ((opt
= php_http_option_register(registry
, ZEND_STRL("httpauthtype"), CURLOPT_HTTPAUTH
, IS_LONG
))) {
1359 Z_LVAL(opt
->defval
) = CURLAUTH_ANYSAFE
;
1361 #if PHP_HTTP_CURL_VERSION(7,43,0)
1362 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_SSPI
) || PHP_HTTP_CURL_FEATURE(CURL_VERSION_GSSAPI
))
1363 if ((opt
= php_http_option_register(registry
, ZEND_STRL("service_name"), CURLOPT_SERVICE_NAME
, IS_STRING
))) {
1364 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1367 #if PHP_HTTP_CURL_VERSION(7,61,0)
1368 if ((opt
= php_http_option_register(registry
, ZEND_STRL("xoauth2_bearer"), CURLOPT_XOAUTH2_BEARER
, IS_STRING
))) {
1369 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1372 #if PHP_HTTP_CURL_VERSION(7,75,0)
1373 php_http_option_register(registry
, ZEND_STRL("aws_sigv4"), CURLOPT_AWS_SIGV4
, IS_STRING
);
1377 if ((opt
= php_http_option_register(registry
, ZEND_STRL("redirect"), CURLOPT_FOLLOWLOCATION
, IS_LONG
))) {
1378 opt
->setter
= php_http_curle_option_set_redirect
;
1380 php_http_option_register(registry
, ZEND_STRL("unrestricted_auth"), CURLOPT_UNRESTRICTED_AUTH
, _IS_BOOL
);
1381 #if PHP_HTTP_CURL_VERSION(7,19,1)
1382 php_http_option_register(registry
, ZEND_STRL("postredir"), CURLOPT_POSTREDIR
, IS_LONG
);
1386 if ((opt
= php_http_option_register(registry
, ZEND_STRL("retrycount"), 0, IS_LONG
))) {
1387 opt
->setter
= php_http_curle_option_set_retrycount
;
1389 if ((opt
= php_http_option_register(registry
, ZEND_STRL("retrydelay"), 0, IS_DOUBLE
))) {
1390 opt
->setter
= php_http_curle_option_set_retrydelay
;
1394 if ((opt
= php_http_option_register(registry
, ZEND_STRL("referer"), CURLOPT_REFERER
, IS_STRING
))) {
1395 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1397 if ((opt
= php_http_option_register(registry
, ZEND_STRL("autoreferer"), CURLOPT_AUTOREFERER
, _IS_BOOL
))) {
1398 ZVAL_BOOL(&opt
->defval
, 1);
1402 if ((opt
= php_http_option_register(registry
, ZEND_STRL("useragent"), CURLOPT_USERAGENT
, IS_STRING
))) {
1403 /* don't check strlen, to allow sending no useragent at all */
1404 ZVAL_PSTRING(&opt
->defval
,
1405 "PECL_HTTP/" PHP_PECL_HTTP_VERSION
" "
1406 "PHP/" PHP_VERSION
" "
1407 "libcurl/" LIBCURL_VERSION
);
1411 if ((opt
= php_http_option_register(registry
, ZEND_STRL("resume"), CURLOPT_RESUME_FROM
, IS_LONG
))) {
1412 opt
->setter
= php_http_curle_option_set_resume
;
1415 if ((opt
= php_http_option_register(registry
, ZEND_STRL("range"), CURLOPT_RANGE
, IS_ARRAY
))) {
1416 opt
->setter
= php_http_curle_option_set_range
;
1420 if ((opt
= php_http_option_register(registry
, ZEND_STRL("etag"), 0, IS_STRING
))) {
1421 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1422 opt
->setter
= php_http_curle_option_set_etag
;
1426 if ((opt
= php_http_option_register(registry
, ZEND_STRL("compress"), 0, _IS_BOOL
))) {
1427 opt
->setter
= php_http_curle_option_set_compress
;
1431 if ((opt
= php_http_option_register(registry
, ZEND_STRL("lastmodified"), 0, IS_LONG
))) {
1432 opt
->setter
= php_http_curle_option_set_lastmodified
;
1436 if ((opt
= php_http_option_register(registry
, ZEND_STRL("encodecookies"), 0, _IS_BOOL
))) {
1437 opt
->setter
= php_http_curle_option_set_encodecookies
;
1438 ZVAL_BOOL(&opt
->defval
, 1);
1440 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookies"), 0, IS_ARRAY
))) {
1441 opt
->setter
= php_http_curle_option_set_cookies
;
1444 /* cookiesession, don't load session cookies from cookiestore */
1445 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookiesession"), CURLOPT_COOKIESESSION
, _IS_BOOL
))) {
1446 opt
->setter
= php_http_curle_option_set_cookiesession
;
1448 /* cookiestore, read initial cookies from that file and store cookies back into that file */
1449 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookiestore"), 0, IS_STRING
))) {
1450 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1451 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1452 opt
->setter
= php_http_curle_option_set_cookiestore
;
1456 php_http_option_register(registry
, ZEND_STRL("maxfilesize"), CURLOPT_MAXFILESIZE
, IS_LONG
);
1458 /* http protocol version */
1459 php_http_option_register(registry
, ZEND_STRL("protocol"), CURLOPT_HTTP_VERSION
, IS_LONG
);
1460 #if PHP_HTTP_CURL_VERSION(7,64,0)
1461 php_http_option_register(registry
, ZEND_STRL("http09_allowed"), CURLOPT_HTTP09_ALLOWED
, _IS_BOOL
);
1465 if ((opt
= php_http_option_register(registry
, ZEND_STRL("timeout"), CURLOPT_TIMEOUT_MS
, IS_DOUBLE
))) {
1466 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1468 if ((opt
= php_http_option_register(registry
, ZEND_STRL("connecttimeout"), CURLOPT_CONNECTTIMEOUT_MS
, IS_DOUBLE
))) {
1469 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1470 Z_DVAL(opt
->defval
) = 3;
1472 #if PHP_HTTP_CURL_VERSION(7,36,0)
1473 if ((opt
= php_http_option_register(registry
, ZEND_STRL("expect_100_timeout"), CURLOPT_EXPECT_100_TIMEOUT_MS
, IS_DOUBLE
))) {
1474 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1475 Z_DVAL(opt
->defval
) = 1;
1480 php_http_option_register(registry
, ZEND_STRL("tcp_nodelay"), CURLOPT_TCP_NODELAY
, _IS_BOOL
);
1481 #if PHP_HTTP_CURL_VERSION(7,25,0)
1482 php_http_option_register(registry
, ZEND_STRL("tcp_keepalive"), CURLOPT_TCP_KEEPALIVE
, _IS_BOOL
);
1483 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tcp_keepidle"), CURLOPT_TCP_KEEPIDLE
, IS_LONG
))) {
1484 Z_LVAL(opt
->defval
) = 60;
1486 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tcp_keepintvl"), CURLOPT_TCP_KEEPINTVL
, IS_LONG
))) {
1487 Z_LVAL(opt
->defval
) = 60;
1490 #if PHP_HTTP_CURL_VERSION(7,49,0)
1491 # if defined(linux) || defined(__APPLE__)
1492 /* CURLOPT_TCP_FASTOPEN is not supported (yet) on Windows */
1493 php_http_option_register(registry
, ZEND_STRL("tcp_fastopen"), CURLOPT_TCP_FASTOPEN
, _IS_BOOL
);
1498 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_SSL
)) {
1499 php_http_option_t
*ssl_opt
, *proxy_opt
;
1501 if ((ssl_opt
= php_http_option_register(registry
, ZEND_STRL("ssl"), 0, IS_ARRAY
))) {
1502 php_http_options_t
*ssl_registry
= &ssl_opt
->suboptions
;
1504 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("cert"), CURLOPT_SSLCERT
, IS_STRING
))) {
1505 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1506 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1508 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("certtype"), CURLOPT_SSLCERTTYPE
, IS_STRING
))) {
1509 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1510 ZVAL_PSTRING(&opt
->defval
, "PEM");
1512 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("key"), CURLOPT_SSLKEY
, IS_STRING
))) {
1513 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1514 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1516 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("keytype"), CURLOPT_SSLKEYTYPE
, IS_STRING
))) {
1517 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1518 ZVAL_PSTRING(&opt
->defval
, "PEM");
1520 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("keypasswd"), CURLOPT_SSLKEYPASSWD
, IS_STRING
))) {
1521 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1523 php_http_option_register(ssl_registry
, ZEND_STRL("engine"), CURLOPT_SSLENGINE
, IS_STRING
);
1524 php_http_option_register(ssl_registry
, ZEND_STRL("version"), CURLOPT_SSLVERSION
, IS_LONG
);
1525 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("verifypeer"), CURLOPT_SSL_VERIFYPEER
, _IS_BOOL
))) {
1526 ZVAL_BOOL(&opt
->defval
, 1);
1528 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("verifyhost"), CURLOPT_SSL_VERIFYHOST
, _IS_BOOL
))) {
1529 ZVAL_BOOL(&opt
->defval
, 1);
1530 opt
->setter
= php_http_curle_option_set_ssl_verifyhost
;
1532 #if PHP_HTTP_CURL_VERSION(7,41,0) && (PHP_HTTP_HAVE_LIBCURL_OPENSSL || PHP_HTTP_HAVE_LIBCURL_NSS || PHP_HTTP_HAVE_LIBCURL_GNUTLS)
1533 php_http_option_register(ssl_registry
, ZEND_STRL("verifystatus"), CURLOPT_SSL_VERIFYSTATUS
, _IS_BOOL
);
1535 php_http_option_register(ssl_registry
, ZEND_STRL("cipher_list"), CURLOPT_SSL_CIPHER_LIST
, IS_STRING
);
1536 #if PHP_HTTP_HAVE_LIBCURL_CAINFO
1537 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("cainfo"), CURLOPT_CAINFO
, IS_STRING
))) {
1538 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1539 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1540 # ifdef PHP_HTTP_CAINFO
1541 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAINFO
);
1545 #if PHP_HTTP_HAVE_LIBCURL_CAPATH
1546 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("capath"), CURLOPT_CAPATH
, IS_STRING
))) {
1547 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1548 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1549 # ifdef PHP_HTTP_CAPATH
1550 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAPATH
);
1554 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("random_file"), CURLOPT_RANDOM_FILE
, IS_STRING
))) {
1555 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1556 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1558 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("egdsocket"), CURLOPT_EGDSOCKET
, IS_STRING
))) {
1559 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1560 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1562 #if PHP_HTTP_CURL_VERSION(7,19,0)
1563 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("issuercert"), CURLOPT_ISSUERCERT
, IS_STRING
))) {
1564 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1565 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1567 # if PHP_HTTP_HAVE_LIBCURL_OPENSSL
1568 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("crlfile"), CURLOPT_CRLFILE
, IS_STRING
))) {
1569 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1570 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1574 #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))
1575 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("certinfo"), CURLOPT_CERTINFO
, _IS_BOOL
))) {
1576 ZVAL_FALSE(&opt
->defval
);
1579 #if PHP_HTTP_CURL_VERSION(7,36,0)
1580 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("enable_npn"), CURLOPT_SSL_ENABLE_NPN
, _IS_BOOL
))) {
1581 ZVAL_BOOL(&opt
->defval
, 1);
1583 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("enable_alpn"), CURLOPT_SSL_ENABLE_ALPN
, _IS_BOOL
))) {
1584 ZVAL_BOOL(&opt
->defval
, 1);
1587 #if PHP_HTTP_CURL_VERSION(7,39,0)
1588 /* FIXME: see http://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html#AVAILABILITY */
1589 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("pinned_publickey"), CURLOPT_PINNEDPUBLICKEY
, IS_STRING
))) {
1590 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1591 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1594 #if PHP_HTTP_CURL_VERSION(7,21,4) && PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
1595 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tlsauthtype"), CURLOPT_TLSAUTH_TYPE
, IS_LONG
))) {
1596 opt
->setter
= php_http_curle_option_set_ssl_tlsauthtype
;
1598 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tlsauthuser"), CURLOPT_TLSAUTH_USERNAME
, IS_STRING
))) {
1599 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1601 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tlsauthpass"), CURLOPT_TLSAUTH_PASSWORD
, IS_STRING
))) {
1602 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1605 #if PHP_HTTP_CURL_VERSION(7,42,0) && (PHP_HTTP_HAVE_LIBCURL_NSS || PHP_HTTP_HAVE_LIBCURL_SECURETRANSPORT)
1606 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("falsestart"), CURLOPT_SSL_FALSESTART
, _IS_BOOL
))) {
1607 opt
->flags
|= PHP_HTTP_CURLE_OPTION_IGNORE_RC
;
1610 #if PHP_HTTP_CURL_VERSION(7,61,0) && PHP_HTTP_HAVE_LIBCURL_TLS13_CIPHERS
1611 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tls13_ciphers"), CURLOPT_TLS13_CIPHERS
, IS_STRING
))) {
1612 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1617 #if PHP_HTTP_CURL_VERSION(7,52,0)
1619 if ((proxy_opt
= php_http_option_register(registry
, ZEND_STRL("proxy_ssl"), 0, IS_ARRAY
))) {
1620 php_http_options_t
*proxy_registry
= &proxy_opt
->suboptions
;
1622 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("cert"), CURLOPT_PROXY_SSLCERT
, IS_STRING
))) {
1623 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1624 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1626 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("certtype"), CURLOPT_PROXY_SSLCERTTYPE
, IS_STRING
))) {
1627 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1628 ZVAL_PSTRING(&opt
->defval
, "PEM");
1630 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("key"), CURLOPT_PROXY_SSLKEY
, IS_STRING
))) {
1631 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1632 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1634 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("keytype"), CURLOPT_PROXY_SSLKEYTYPE
, IS_STRING
))) {
1635 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1636 ZVAL_PSTRING(&opt
->defval
, "PEM");
1638 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("keypasswd"), CURLOPT_PROXY_KEYPASSWD
, IS_STRING
))) {
1639 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1641 php_http_option_register(proxy_registry
, ZEND_STRL("version"), CURLOPT_PROXY_SSLVERSION
, IS_LONG
);
1642 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("verifypeer"), CURLOPT_PROXY_SSL_VERIFYPEER
, _IS_BOOL
))) {
1643 ZVAL_BOOL(&opt
->defval
, 1);
1645 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("verifyhost"), CURLOPT_PROXY_SSL_VERIFYHOST
, _IS_BOOL
))) {
1646 ZVAL_BOOL(&opt
->defval
, 1);
1647 opt
->setter
= php_http_curle_option_set_ssl_verifyhost
;
1649 php_http_option_register(proxy_registry
, ZEND_STRL("cipher_list"), CURLOPT_PROXY_SSL_CIPHER_LIST
, IS_STRING
);
1650 # if PHP_HTTP_CURL_VERSION(7,71,0)
1651 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("issuercert"), CURLOPT_PROXY_ISSUERCERT
, IS_STRING
))) {
1652 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1653 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1656 # if PHP_HTTP_HAVE_LIBCURL_OPENSSL
1657 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("crlfile"), CURLOPT_PROXY_CRLFILE
, IS_STRING
))) {
1658 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1659 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1662 # if PHP_HTTP_HAVE_LIBCURL_CAINFO
1663 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("cainfo"), CURLOPT_PROXY_CAINFO
, IS_STRING
))) {
1664 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1665 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1666 # ifdef PHP_HTTP_CAINFO
1667 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAINFO
);
1671 # if PHP_HTTP_HAVE_LIBCURL_CAPATH
1672 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("capath"), CURLOPT_PROXY_CAPATH
, IS_STRING
))) {
1673 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1674 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1675 # ifdef PHP_HTTP_CAPATH
1676 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAPATH
);
1681 # if PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
1682 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tlsauthtype"), CURLOPT_PROXY_TLSAUTH_TYPE
, IS_LONG
))) {
1683 opt
->setter
= php_http_curle_option_set_ssl_tlsauthtype
;
1685 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tlsauthuser"), CURLOPT_PROXY_TLSAUTH_USERNAME
, IS_STRING
))) {
1686 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1688 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tlsauthpass"), CURLOPT_PROXY_TLSAUTH_PASSWORD
, IS_STRING
))) {
1689 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1692 # if PHP_HTTP_CURL_VERSION(7,59,0)
1693 /* FIXME: see http://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html#AVAILABILITY */
1694 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("pinned_publickey"), CURLOPT_PROXY_PINNEDPUBLICKEY
, IS_STRING
))) {
1695 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1696 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1699 # if PHP_HTTP_CURL_VERSION(7,61,0) && PHP_HTTP_HAVE_LIBCURL_TLS13_CIPHERS
1700 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tls13_ciphers"), CURLOPT_PROXY_TLS13_CIPHERS
, IS_STRING
))) {
1701 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1708 #if PHP_HTTP_CURL_VERSION(7,64,1)
1709 # if !PHP_HTTP_HAVE_LIBCURL_ALT_SVC
1710 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_ALTSVC
)) {
1712 if ((opt
= php_http_option_register(registry
, ZEND_STRL("altsvc_ctrl"), CURLOPT_ALTSVC_CTRL
, IS_LONG
))) {
1713 opt
->setter
= php_http_curle_option_set_altsvc_ctrl
;
1715 if ((opt
= php_http_option_register(registry
, ZEND_STRL("altsvc"), CURLOPT_ALTSVC
, IS_STRING
))) {
1716 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1718 # if !PHP_HTTP_HAVE_LIBCURL_ALT_SVC
1722 #if PHP_HTTP_CURL_VERSION(7,74,0)
1723 # if !PHP_HTTP_HAVE_LIBCURL_HSTS
1724 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_HSTS
)) {
1726 php_http_option_register(registry
, ZEND_STRL("hsts_ctrl"), CURLOPT_HSTS_CTRL
, IS_LONG
);
1727 if ((opt
= php_http_option_register(registry
, ZEND_STRL("hsts"), CURLOPT_HSTS
, IS_STRING
))) {
1728 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1730 # if !PHP_HTTP_HAVE_LIBCURL_HSTS
1736 static zval
*php_http_curle_get_option(php_http_option_t
*opt
, HashTable
*options
, void *userdata
)
1738 php_http_client_curl_handler_t
*curl
= userdata
;
1741 if ((option
= php_http_option_get(opt
, options
, NULL
))) {
1744 ZVAL_DUP(&zopt
, option
);
1745 convert_to_explicit_type(&zopt
, opt
->type
);
1746 zend_hash_update(&curl
->options
.cache
, opt
->name
, &zopt
);
1747 return zend_hash_find(&curl
->options
.cache
, opt
->name
);
1752 static ZEND_RESULT_CODE
php_http_curle_set_option(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1754 php_http_client_curl_handler_t
*curl
= userdata
;
1755 CURL
*ch
= curl
->handle
;
1757 CURLcode rc
= CURLE_UNKNOWN_OPTION
;
1758 ZEND_RESULT_CODE rv
= SUCCESS
;
1764 switch (opt
->type
) {
1767 rv
= opt
->setter(opt
, val
, curl
);
1768 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, (long) (Z_TYPE_P(val
) == IS_TRUE
))) {
1775 rv
= opt
->setter(opt
, val
, curl
);
1776 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, Z_LVAL_P(val
))) {
1783 rv
= opt
->setter(opt
, val
, curl
);
1784 } else if (!val
|| Z_TYPE_P(val
) == IS_NULL
) {
1785 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1788 } else if ((opt
->flags
& PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
) && !Z_STRLEN_P(val
)) {
1789 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1792 } else if ((opt
->flags
& PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
) && Z_STRVAL_P(val
) && SUCCESS
!= php_check_open_basedir(Z_STRVAL_P(val
))) {
1793 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1796 } else if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, Z_STRVAL_P(val
)))) {
1802 if (opt
->flags
& PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
) {
1804 Z_DVAL(tmp
) *= 1000;
1808 rv
= opt
->setter(opt
, val
, curl
);
1809 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, (long) Z_DVAL_P(val
))) {
1816 rv
= opt
->setter(opt
, val
, curl
);
1817 } else if (Z_TYPE_P(val
) != IS_NULL
) {
1818 rv
= php_http_options_apply(&opt
->suboptions
, Z_ARRVAL_P(val
), curl
);
1824 rv
= opt
->setter(opt
, val
, curl
);
1830 if (rv
!= SUCCESS
) {
1831 if (opt
->flags
& PHP_HTTP_CURLE_OPTION_IGNORE_RC
) {
1834 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_easy_strerror(rc
));
1840 #if PHP_HTTP_CURL_VERSION(7,30,0) && !PHP_HTTP_CURL_VERSION(7,62,0)
1841 static ZEND_RESULT_CODE
php_http_curlm_option_set_pipelining_bl(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1843 php_http_client_t
*client
= userdata
;
1844 php_http_client_curl_t
*curl
= client
->ctx
;
1845 CURLM
*ch
= curl
->handle
->multi
;
1849 /* array of char *, ending with a NULL */
1850 if (value
&& Z_TYPE_P(value
) != IS_NULL
) {
1852 HashTable
*ht
= HASH_OF(value
);
1853 int c
= zend_hash_num_elements(ht
);
1854 char **ptr
= ecalloc(c
+ 1, sizeof(char *));
1858 zend_hash_init(&tmp_ht
, c
, NULL
, ZVAL_PTR_DTOR
, 0);
1859 array_join(ht
, &tmp_ht
, 0, ARRAY_JOIN_STRINGIFY
);
1861 ZEND_HASH_FOREACH_VAL(&tmp_ht
, entry
)
1863 *ptr
++ = Z_STRVAL_P(entry
);
1865 ZEND_HASH_FOREACH_END();
1868 if (CURLM_OK
!= curl_multi_setopt(ch
, opt
->option
, bl
)) {
1871 zend_hash_destroy(&tmp_ht
);
1878 zend_hash_destroy(&tmp_ht
);
1884 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
)
1886 php_http_client_curl_t
*curl
= h
->ctx
;
1890 if (!(ev_ctx
= ev_ops
->init(h
, init_data
))) {
1893 curl
->ev_ctx
= ev_ctx
;
1894 curl
->ev_ops
= ev_ops
;
1898 curl
->ev_ops
->dtor(&curl
->ev_ctx
);
1900 curl
->ev_ops
= NULL
;
1907 static ZEND_RESULT_CODE
php_http_curlm_option_set_use_eventloop(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1909 php_http_client_t
*client
= userdata
;
1910 php_http_client_curl_ops_t
*ev_ops
= NULL
;
1912 if (value
&& Z_TYPE_P(value
) == IS_OBJECT
&& instanceof_function(Z_OBJCE_P(value
), php_http_client_curl_user_get_class_entry())) {
1913 ev_ops
= php_http_client_curl_user_ops_get();
1914 #if PHP_HTTP_HAVE_LIBEVENT
1915 } else if (value
&& zend_is_true(value
)) {
1916 ev_ops
= php_http_client_curl_event_ops_get();
1920 return php_http_curlm_use_eventloop(client
, ev_ops
, value
);
1923 static ZEND_RESULT_CODE
php_http_curlm_option_set_share_cookies(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_COOKIE
);
1932 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_UNSHARE
, CURL_LOCK_DATA_COOKIE
);
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
));
1942 #if PHP_HTTP_HAVE_LIBCURL_SHARE_SSL
1943 static ZEND_RESULT_CODE
php_http_curlm_option_set_share_ssl(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1945 php_http_client_t
*client
= userdata
;
1946 php_http_client_curl_t
*curl
= client
->ctx
;
1949 if (Z_TYPE_P(value
) == IS_TRUE
) {
1950 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_SSL_SESSION
);
1952 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_UNSHARE
, CURL_LOCK_DATA_SSL_SESSION
);
1955 if (CURLSHE_OK
!= rc
) {
1956 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_share_strerror(rc
));
1963 static void php_http_curlm_options_init(php_http_options_t
*registry
)
1965 php_http_option_t
*opt
;
1967 /* set size of connection cache */
1968 if ((opt
= php_http_option_register(registry
, ZEND_STRL("maxconnects"), CURLMOPT_MAXCONNECTS
, IS_LONG
))) {
1969 /* -1 == default, 0 == unlimited */
1970 ZVAL_LONG(&opt
->defval
, -1);
1972 /* set max number of connections to a single host */
1973 #if PHP_HTTP_CURL_VERSION(7,30,0)
1974 php_http_option_register(registry
, ZEND_STRL("max_host_connections"), CURLMOPT_MAX_HOST_CONNECTIONS
, IS_LONG
);
1976 /* max simultaneously open connections */
1977 #if PHP_HTTP_CURL_VERSION(7,30,0)
1978 php_http_option_register(registry
, ZEND_STRL("max_total_connections"), CURLMOPT_MAX_TOTAL_CONNECTIONS
, IS_LONG
);
1980 #if PHP_HTTP_CURL_VERSION(7,67,0)
1981 if ((opt
= php_http_option_register(registry
, ZEND_STRL("max_concurrent_streams"), CURLMOPT_MAX_CONCURRENT_STREAMS
, IS_LONG
))) {
1982 ZVAL_LONG(&opt
->defval
, 100);
1986 #if !PHP_HTTP_CURL_VERSION(7,62,0)
1987 /* enable/disable HTTP pipelining */
1988 php_http_option_register(registry
, ZEND_STRL("pipelining"), CURLMOPT_PIPELINING
, _IS_BOOL
);
1989 # if PHP_HTTP_CURL_VERSION(7,30,0)
1990 /* maximum number of requests in a pipeline */
1991 if ((opt
= php_http_option_register(registry
, ZEND_STRL("max_pipeline_length"), CURLMOPT_MAX_PIPELINE_LENGTH
, IS_LONG
))) {
1992 ZVAL_LONG(&opt
->defval
, 5);
1994 /* chunk length threshold for pipelining */
1995 php_http_option_register(registry
, ZEND_STRL("chunk_length_penalty_size"), CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE
, IS_LONG
);
1996 /* size threshold for pipelining penalty */
1997 php_http_option_register(registry
, ZEND_STRL("content_length_penalty_size"), CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE
, IS_LONG
);
1998 /* pipelining server blacklist */
1999 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pipelining_server_bl"), CURLMOPT_PIPELINING_SERVER_BL
, IS_ARRAY
))) {
2000 opt
->setter
= php_http_curlm_option_set_pipelining_bl
;
2002 /* pipelining host blacklist */
2003 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pipelining_site_bl"), CURLMOPT_PIPELINING_SITE_BL
, IS_ARRAY
))) {
2004 opt
->setter
= php_http_curlm_option_set_pipelining_bl
;
2009 if ((opt
= php_http_option_register(registry
, ZEND_STRL("use_eventloop"), 0, 0))) {
2010 opt
->setter
= php_http_curlm_option_set_use_eventloop
;
2013 if ((opt
= php_http_option_register(registry
, ZEND_STRL("share_cookies"), 0, _IS_BOOL
))) {
2014 opt
->setter
= php_http_curlm_option_set_share_cookies
;
2015 ZVAL_TRUE(&opt
->defval
);
2017 #if PHP_HTTP_HAVE_LIBCURL_SHARE_SSL
2018 if ((opt
= php_http_option_register(registry
, ZEND_STRL("share_ssl"), 0, _IS_BOOL
))) {
2019 opt
->setter
= php_http_curlm_option_set_share_ssl
;
2020 ZVAL_TRUE(&opt
->defval
);
2025 static ZEND_RESULT_CODE
php_http_curlm_set_option(php_http_option_t
*opt
, zval
*val
, void *userdata
)
2027 php_http_client_t
*client
= userdata
;
2028 php_http_client_curl_t
*curl
= client
->ctx
;
2029 CURLM
*ch
= curl
->handle
->multi
;
2030 zval zopt
, *orig
= val
;
2031 CURLMcode rc
= CURLM_UNKNOWN_OPTION
;
2032 ZEND_RESULT_CODE rv
= SUCCESS
;
2036 } else if (opt
->type
&& Z_TYPE_P(val
) != opt
->type
&& !(Z_TYPE_P(val
) == IS_NULL
&& opt
->type
== IS_ARRAY
)) {
2037 ZVAL_DUP(&zopt
, val
);
2038 convert_to_explicit_type(&zopt
, opt
->type
);
2044 rv
= opt
->setter(opt
, val
, client
);
2046 switch (opt
->type
) {
2048 if (CURLM_OK
!= (rc
= curl_multi_setopt(ch
, opt
->option
, (long) zend_is_true(val
)))) {
2050 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_multi_strerror(rc
));
2054 if (CURLM_OK
!= (rc
= curl_multi_setopt(ch
, opt
->option
, Z_LVAL_P(val
)))) {
2056 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_multi_strerror(rc
));
2061 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s", opt
->name
->val
);
2066 if (val
&& val
!= orig
&& val
!= &opt
->defval
) {
2075 static ZEND_RESULT_CODE
php_http_client_curl_handler_reset(php_http_client_curl_handler_t
*handler
)
2077 php_http_client_curl_t
*curl
= handler
->client
->ctx
;
2078 CURL
*ch
= handler
->handle
;
2079 php_http_curle_storage_t
*st
;
2081 if ((st
= php_http_curle_get_storage(ch
))) {
2086 if (st
->cookiestore
) {
2087 pefree(st
->cookiestore
, 1);
2088 st
->cookiestore
= NULL
;
2090 st
->errorbuffer
[0] = '\0';
2094 curl_easy_setopt(ch
, CURLOPT_URL
, NULL
);
2095 curl_easy_setopt(ch
, CURLOPT_CUSTOMREQUEST
, NULL
);
2096 curl_easy_setopt(ch
, CURLOPT_HTTPGET
, 1L);
2097 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 0L);
2098 /* libcurl < 7.19.6 does not clear auth info with USERPWD set to NULL */
2099 #if PHP_HTTP_CURL_VERSION(7,19,1)
2100 curl_easy_setopt(ch
, CURLOPT_PROXYUSERNAME
, NULL
);
2101 curl_easy_setopt(ch
, CURLOPT_PROXYPASSWORD
, NULL
);
2102 curl_easy_setopt(ch
, CURLOPT_USERNAME
, NULL
);
2103 curl_easy_setopt(ch
, CURLOPT_PASSWORD
, NULL
);
2106 #if PHP_HTTP_CURL_VERSION(7,21,3)
2107 if (handler
->options
.resolve
) {
2108 curl_slist_free_all(handler
->options
.resolve
);
2109 handler
->options
.resolve
= NULL
;
2112 handler
->options
.retry
.count
= 0;
2113 handler
->options
.retry
.delay
= 0;
2114 handler
->options
.redirects
= 0;
2115 handler
->options
.encode_cookies
= 1;
2117 if (handler
->options
.headers
) {
2118 curl_slist_free_all(handler
->options
.headers
);
2119 handler
->options
.headers
= NULL
;
2121 if (handler
->options
.proxyheaders
) {
2122 curl_slist_free_all(handler
->options
.proxyheaders
);
2123 handler
->options
.proxyheaders
= NULL
;
2126 php_http_buffer_reset(&handler
->options
.cookies
);
2127 php_http_buffer_reset(&handler
->options
.ranges
);
2129 if (php_http_message_body_size(handler
->response
.body
)) {
2130 php_http_message_body_free(&handler
->response
.body
);
2131 handler
->response
.body
= php_http_message_body_init(NULL
, NULL
);
2133 php_http_buffer_reset(&handler
->response
.headers
);
2136 curl_easy_setopt(ch
, CURLOPT_NOSIGNAL
, 1L);
2138 curl_easy_setopt(ch
, CURLOPT_HEADER
, 0L);
2139 curl_easy_setopt(ch
, CURLOPT_FILETIME
, 1L);
2140 curl_easy_setopt(ch
, CURLOPT_AUTOREFERER
, 1L);
2141 curl_easy_setopt(ch
, CURLOPT_VERBOSE
, 1L);
2142 curl_easy_setopt(ch
, CURLOPT_NOPROGRESS
, 0L);
2143 curl_easy_setopt(ch
, CURLOPT_HEADERFUNCTION
, php_http_curle_header_callback
);
2144 curl_easy_setopt(ch
, CURLOPT_WRITEFUNCTION
, php_http_curle_body_callback
);
2145 curl_easy_setopt(ch
, CURLOPT_DEBUGFUNCTION
, php_http_curle_raw_callback
);
2146 curl_easy_setopt(ch
, CURLOPT_READFUNCTION
, php_http_curle_read_callback
);
2147 curl_easy_setopt(ch
, CURLOPT_SEEKFUNCTION
, php_http_curle_seek_callback
);
2148 #if PHP_HTTP_CURL_VERSION(7,32,0)
2149 curl_easy_setopt(ch
, CURLOPT_XFERINFOFUNCTION
, php_http_curle_xferinfo_callback
);
2150 curl_easy_setopt(ch
, CURLOPT_XFERINFODATA
, handler
);
2152 curl_easy_setopt(ch
, CURLOPT_PROGRESSFUNCTION
, php_http_curle_progress_callback
);
2153 curl_easy_setopt(ch
, CURLOPT_PROGRESSDATA
, handler
);
2155 curl_easy_setopt(ch
, CURLOPT_DEBUGDATA
, handler
);
2156 curl_easy_setopt(ch
, CURLOPT_WRITEDATA
, handler
);
2157 curl_easy_setopt(ch
, CURLOPT_HEADERDATA
, handler
);
2159 fprintf(stderr
, "CURLOPT_SHARE: %p\n", curl
->handle
->share
);
2161 curl_easy_setopt(ch
, CURLOPT_SHARE
, curl
->handle
->share
);
2166 static php_http_client_curl_handler_t
*php_http_client_curl_handler_init(php_http_client_t
*h
, php_resource_factory_t
*rf
)
2169 php_http_client_curl_handler_t
*handler
;
2171 if (!(handle
= php_resource_factory_handle_ctor(rf
, NULL
))) {
2172 php_error_docref(NULL
, E_WARNING
, "Failed to initialize curl handle");
2176 handler
= ecalloc(1, sizeof(*handler
));
2178 handler
->client
= h
;
2179 handler
->handle
= handle
;
2180 handler
->response
.body
= php_http_message_body_init(NULL
, NULL
);
2181 php_http_buffer_init(&handler
->response
.headers
);
2182 php_http_buffer_init(&handler
->options
.cookies
);
2183 php_http_buffer_init(&handler
->options
.ranges
);
2184 zend_hash_init(&handler
->options
.cache
, 0, NULL
, ZVAL_PTR_DTOR
, 0);
2186 php_http_client_curl_handler_reset(handler
);
2192 static ZEND_RESULT_CODE
php_http_client_curl_handler_prepare(php_http_client_curl_handler_t
*curl
, php_http_client_enqueue_t
*enqueue
)
2195 php_http_message_t
*msg
= enqueue
->request
;
2196 php_http_curle_storage_t
*storage
= php_http_curle_get_storage(curl
->handle
);
2199 if (!PHP_HTTP_INFO(msg
).request
.url
) {
2200 php_error_docref(NULL
, E_WARNING
, "Cannot request empty URL");
2203 storage
->errorbuffer
[0] = '\0';
2205 pefree(storage
->url
, 1);
2207 php_http_url_to_string(PHP_HTTP_INFO(msg
).request
.url
, &storage
->url
, NULL
, 1);
2208 curl_easy_setopt(curl
->handle
, CURLOPT_URL
, storage
->url
);
2211 if (SUCCESS
!= php_http_options_apply(&php_http_curle_options
, enqueue
->options
, curl
)) {
2215 /* request headers */
2216 php_http_message_update_headers(msg
);
2217 if (zend_hash_num_elements(&msg
->hdrs
)) {
2218 php_http_arrkey_t header_key
;
2220 zend_string
*header_str
;
2221 php_http_buffer_t header
;
2222 #if !PHP_HTTP_CURL_VERSION(7,23,0)
2223 zval
*ct
= zend_hash_str_find(&msg
->hdrs
, ZEND_STRL("Content-Length"));
2226 php_http_buffer_init(&header
);
2227 ZEND_HASH_FOREACH_KEY_VAL(&msg
->hdrs
, header_key
.h
, header_key
.key
, header_val
)
2229 if (header_key
.key
) {
2230 #if !PHP_HTTP_CURL_VERSION(7,23,0)
2231 /* avoid duplicate content-length header */
2232 if (ct
&& ct
== header_val
) {
2236 header_str
= zval_get_string(header_val
);
2237 php_http_buffer_appendf(&header
, "%s: %s", header_key
.key
->val
, header_str
->val
);
2238 php_http_buffer_fix(&header
);
2239 curl
->options
.headers
= curl_slist_append(curl
->options
.headers
, header
.data
);
2240 php_http_buffer_reset(&header
);
2241 zend_string_release(header_str
);
2244 ZEND_HASH_FOREACH_END();
2245 php_http_buffer_dtor(&header
);
2247 curl_easy_setopt(curl
->handle
, CURLOPT_HTTPHEADER
, curl
->options
.headers
);
2249 /* attach request body */
2250 if ((body_size
= php_http_message_body_size(msg
->body
))) {
2251 /* RFC2616, section 4.3 (para. 4) states that »a message-body MUST NOT be included in a request if the
2252 * specification of the request method (section 5.1.1) does not allow sending an entity-body in request.«
2253 * Following the clause in section 5.1.1 (para. 2) that request methods »MUST be implemented with the
2254 * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method
2255 * does not allow a request body.
2257 php_stream_rewind(php_http_message_body_stream(msg
->body
));
2258 curl_easy_setopt(curl
->handle
, CURLOPT_SEEKDATA
, msg
->body
);
2259 curl_easy_setopt(curl
->handle
, CURLOPT_READDATA
, msg
->body
);
2260 curl_easy_setopt(curl
->handle
, CURLOPT_INFILESIZE
, body_size
);
2261 curl_easy_setopt(curl
->handle
, CURLOPT_POSTFIELDSIZE
, body_size
);
2262 curl_easy_setopt(curl
->handle
, CURLOPT_POST
, 1L);
2264 curl_easy_setopt(curl
->handle
, CURLOPT_SEEKDATA
, NULL
);
2265 curl_easy_setopt(curl
->handle
, CURLOPT_READDATA
, NULL
);
2266 curl_easy_setopt(curl
->handle
, CURLOPT_INFILESIZE
, 0L);
2267 curl_easy_setopt(curl
->handle
, CURLOPT_POSTFIELDSIZE
, 0L);
2271 * Always use CUSTOMREQUEST, else curl won't send any request body for GET etc.
2272 * See e.g. bug #69313.
2274 * Here's what curl does:
2275 * - CURLOPT_HTTPGET: ignore request body
2276 * - CURLOPT_UPLOAD: set "Expect: 100-continue" header
2277 * - CURLOPT_POST: set "Content-Type: application/x-www-form-urlencoded" header
2278 * Now select the least bad.
2280 * See also https://tools.ietf.org/html/rfc7231#section-5.1.1
2282 if (PHP_HTTP_INFO(msg
).request
.method
) {
2283 switch(php_http_select_str(PHP_HTTP_INFO(msg
).request
.method
, 2, "HEAD", "PUT")) {
2285 curl_easy_setopt(curl
->handle
, CURLOPT_NOBODY
, 1L);
2288 curl_easy_setopt(curl
->handle
, CURLOPT_UPLOAD
, 1L);
2291 curl_easy_setopt(curl
->handle
, CURLOPT_CUSTOMREQUEST
, PHP_HTTP_INFO(msg
).request
.method
);
2294 php_error_docref(NULL
, E_WARNING
, "Cannot use empty request method");
2301 static void php_http_client_curl_handler_clear(php_http_client_curl_handler_t
*handler
)
2303 curl_easy_setopt(handler
->handle
, CURLOPT_NOPROGRESS
, 1L);
2304 #if PHP_HTTP_CURL_VERSION(7,32,0)
2305 curl_easy_setopt(handler
->handle
, CURLOPT_XFERINFOFUNCTION
, NULL
);
2307 curl_easy_setopt(handler
->handle
, CURLOPT_PROGRESSFUNCTION
, NULL
);
2309 curl_easy_setopt(handler
->handle
, CURLOPT_VERBOSE
, 0L);
2310 curl_easy_setopt(handler
->handle
, CURLOPT_DEBUGFUNCTION
, NULL
);
2311 /* see gh issue #84 */
2313 fprintf(stderr
, "CURLOPT_COOKIELIST: FLUSH\n");
2314 fprintf(stderr
, "CURLOPT_SHARE: (null)\n");
2316 curl_easy_setopt(handler
->handle
, CURLOPT_COOKIELIST
, "FLUSH");
2317 curl_easy_setopt(handler
->handle
, CURLOPT_SHARE
, NULL
);
2318 #if PHP_HTTP_CURL_VERSION(7,63,0) && !PHP_HTTP_CURL_VERSION(7,65,0)
2320 php_http_curle_storage_t
*st
= php_http_curle_get_storage(handler
->handle
);
2321 curl_easy_setopt(handler
->handle
, CURLOPT_COOKIEJAR
, st
? st
->cookiestore
: NULL
);
2326 static void php_http_client_curl_handler_dtor(php_http_client_curl_handler_t
*handler
)
2328 php_http_client_curl_handler_clear(handler
);
2330 php_resource_factory_handle_dtor(handler
->rf
, handler
->handle
);
2331 php_resource_factory_free(&handler
->rf
);
2333 php_http_message_body_free(&handler
->response
.body
);
2334 php_http_buffer_dtor(&handler
->response
.headers
);
2335 php_http_buffer_dtor(&handler
->options
.ranges
);
2336 php_http_buffer_dtor(&handler
->options
.cookies
);
2337 zend_hash_destroy(&handler
->options
.cache
);
2339 #if PHP_HTTP_CURL_VERSION(7,21,3)
2340 if (handler
->options
.resolve
) {
2341 curl_slist_free_all(handler
->options
.resolve
);
2342 handler
->options
.resolve
= NULL
;
2346 if (handler
->options
.headers
) {
2347 curl_slist_free_all(handler
->options
.headers
);
2348 handler
->options
.headers
= NULL
;
2351 if (handler
->options
.proxyheaders
) {
2352 curl_slist_free_all(handler
->options
.proxyheaders
);
2353 handler
->options
.proxyheaders
= NULL
;
2359 static php_http_client_t
*php_http_client_curl_init(php_http_client_t
*h
, void *handle
)
2361 php_http_client_curl_t
*curl
;
2363 if (!handle
&& !(handle
= php_resource_factory_handle_ctor(h
->rf
, NULL
))) {
2364 php_error_docref(NULL
, E_WARNING
, "Failed to initialize curl handle");
2368 curl
= ecalloc(1, sizeof(*curl
));
2369 curl
->handle
= handle
;
2370 curl
->unfinished
= 0;
2376 static void php_http_client_curl_dtor(php_http_client_t
*h
)
2378 php_http_client_curl_t
*curl
= h
->ctx
;
2381 curl
->ev_ops
->dtor(&curl
->ev_ctx
);
2382 curl
->ev_ops
= NULL
;
2384 curl
->unfinished
= 0;
2386 php_resource_factory_handle_dtor(h
->rf
, curl
->handle
);
2392 static void queue_dtor(php_http_client_enqueue_t
*e
)
2394 php_http_client_curl_handler_t
*handler
= e
->opaque
;
2396 if (handler
->queue
.dtor
) {
2397 e
->opaque
= handler
->queue
.opaque
;
2398 handler
->queue
.dtor(e
);
2400 php_http_client_curl_handler_dtor(handler
);
2403 static void retire_ch(php_persistent_handle_factory_t
*f
, void **handle
)
2406 /* erase all cookies */
2408 curl_easy_reset(ch
);
2409 curl_easy_setopt(ch
, CURLOPT_COOKIELIST
, "ALL");
2410 curl_easy_setopt(ch
, CURLOPT_COOKIEFILE
, NULL
);
2414 static php_resource_factory_t
*create_rf(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2416 php_persistent_handle_factory_t
*pf
= NULL
;
2417 php_resource_factory_t
*rf
= NULL
;
2418 php_http_url_t
*url
= enqueue
->request
->http
.info
.request
.url
;
2420 if (!url
|| (!url
->host
&& !url
->path
)) {
2421 php_error_docref(NULL
, E_WARNING
, "Cannot request empty URL");
2425 /* only if the client itself is setup for persistence */
2426 if (php_resource_factory_is_persistent(h
->rf
)) {
2428 char *id_str
= NULL
;
2430 int port
= url
->port
? url
->port
: 80;
2432 php_persistent_handle_factory_t
*phf
= h
->rf
->data
;
2434 if ((zport
= zend_hash_str_find(enqueue
->options
, ZEND_STRL("port")))) {
2435 zend_long lport
= zval_get_long(zport
);
2442 id_len
= spprintf(&id_str
, 0, "%.*s:%s:%d", (int) phf
->ident
->len
, phf
->ident
->val
, STR_PTR(url
->host
), port
);
2443 id
= php_http_cs2zs(id_str
, id_len
);
2444 pf
= php_persistent_handle_concede(NULL
, PHP_HTTP_G
->client
.curl
.driver
.request_name
, id
, NULL
, retire_ch
);
2445 zend_string_release(id
);
2449 rf
= php_persistent_handle_resource_factory_init(NULL
, pf
);
2451 rf
= php_resource_factory_init(NULL
, &php_http_curle_resource_factory_ops
, NULL
, NULL
);
2457 static ZEND_RESULT_CODE
php_http_client_curl_enqueue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2460 php_http_client_curl_t
*curl
= h
->ctx
;
2461 php_http_client_curl_handler_t
*handler
;
2462 php_http_client_progress_state_t
*progress
;
2463 php_resource_factory_t
*rf
;
2465 rf
= create_rf(h
, enqueue
);
2470 handler
= php_http_client_curl_handler_init(h
, rf
);
2475 if (SUCCESS
!= php_http_client_curl_handler_prepare(handler
, enqueue
)) {
2476 php_http_client_curl_handler_dtor(handler
);
2480 handler
->queue
= *enqueue
;
2481 enqueue
->opaque
= handler
;
2482 enqueue
->dtor
= queue_dtor
;
2484 if (CURLM_OK
!= (rs
= curl_multi_add_handle(curl
->handle
->multi
, handler
->handle
))) {
2485 php_http_client_curl_handler_dtor(handler
);
2486 php_error_docref(NULL
, E_WARNING
, "Could not enqueue request: %s", curl_multi_strerror(rs
));
2490 zend_llist_add_element(&h
->requests
, enqueue
);
2493 if (h
->callback
.progress
.func
&& SUCCESS
== php_http_client_getopt(h
, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
, enqueue
->request
, &progress
)) {
2494 progress
->info
= "start";
2495 h
->callback
.progress
.func(h
->callback
.progress
.arg
, h
, &handler
->queue
, progress
);
2496 progress
->started
= 1;
2502 static ZEND_RESULT_CODE
php_http_client_curl_requeue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2505 php_http_client_curl_t
*curl
= h
->ctx
;
2506 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2507 php_http_client_progress_state_t
*progress
;
2509 if (SUCCESS
!= php_http_client_curl_handler_reset(handler
)) {
2513 if (SUCCESS
!= php_http_client_curl_handler_prepare(handler
, enqueue
)) {
2517 if (CURLM_OK
!= (rs
= curl_multi_remove_handle(curl
->handle
->multi
, handler
->handle
))) {
2518 php_error_docref(NULL
, E_WARNING
, "Could not dequeue request: %s", curl_multi_strerror(rs
));
2522 if (CURLM_OK
!= (rs
= curl_multi_add_handle(curl
->handle
->multi
, handler
->handle
))) {
2523 zend_llist_del_element(&h
->requests
, handler
->handle
, (int (*)(void *, void *)) compare_queue
);
2524 php_error_docref(NULL
, E_WARNING
, "Could not enqueue request: %s", curl_multi_strerror(rs
));
2530 if (h
->callback
.progress
.func
&& SUCCESS
== php_http_client_getopt(h
, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
, enqueue
->request
, &progress
)) {
2531 progress
->info
= "start";
2532 h
->callback
.progress
.func(h
->callback
.progress
.arg
, h
, &handler
->queue
, progress
);
2533 progress
->started
= 1;
2539 static ZEND_RESULT_CODE
php_http_client_curl_dequeue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2542 php_http_client_curl_t
*curl
= h
->ctx
;
2543 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2545 if (h
->callback
.depth
&& !CG(unclean_shutdown
)) {
2546 php_error_docref(NULL
, E_WARNING
, "Could not dequeue request while executing callbacks");
2550 php_http_client_curl_handler_clear(handler
);
2551 if (CURLM_OK
== (rs
= curl_multi_remove_handle(curl
->handle
->multi
, handler
->handle
))) {
2552 zend_llist_del_element(&h
->requests
, handler
->handle
, (int (*)(void *, void *)) compare_queue
);
2555 php_error_docref(NULL
, E_WARNING
, "Could not dequeue request: %s", curl_multi_strerror(rs
));
2561 static void php_http_client_curl_reset(php_http_client_t
*h
)
2563 zend_llist_element
*next_el
, *this_el
;
2565 for (this_el
= h
->requests
.head
; this_el
; this_el
= next_el
) {
2566 next_el
= this_el
->next
;
2567 php_http_client_curl_dequeue(h
, (void *) this_el
->data
);
2572 # define SELECT_ERROR SOCKET_ERROR
2574 # define SELECT_ERROR -1
2577 static ZEND_RESULT_CODE
php_http_client_curl_wait(php_http_client_t
*h
, struct timeval
*custom_timeout
)
2581 struct timeval timeout
;
2582 php_http_client_curl_t
*curl
= h
->ctx
;
2585 return curl
->ev_ops
->wait(curl
->ev_ctx
, custom_timeout
);
2592 if (CURLM_OK
== curl_multi_fdset(curl
->handle
->multi
, &R
, &W
, &E
, &MAX
)) {
2593 if (custom_timeout
&& timerisset(custom_timeout
)) {
2594 timeout
= *custom_timeout
;
2596 php_http_client_curl_get_timeout(curl
, 1000, &timeout
);
2600 php_http_sleep((double) timeout
.tv_sec
+ (double) (timeout
.tv_usec
/ PHP_HTTP_MCROSEC
));
2602 } else if (SELECT_ERROR
!= select(MAX
+ 1, &R
, &W
, &E
, &timeout
)) {
2609 static int php_http_client_curl_once(php_http_client_t
*h
)
2611 php_http_client_curl_t
*curl
= h
->ctx
;
2613 if (!h
->callback
.depth
) {
2615 curl
->ev_ops
->once(curl
->ev_ctx
);
2617 while (CURLM_CALL_MULTI_PERFORM
== curl_multi_perform(curl
->handle
->multi
, &curl
->unfinished
));
2620 php_http_client_curl_responsehandler(h
);
2623 return curl
->unfinished
;
2626 static ZEND_RESULT_CODE
php_http_client_curl_exec(php_http_client_t
*h
)
2628 php_http_client_curl_t
*curl
= h
->ctx
;
2630 if (!h
->callback
.depth
) {
2632 return curl
->ev_ops
->exec(curl
->ev_ctx
);
2635 while (php_http_client_curl_once(h
) && !EG(exception
)) {
2636 if (SUCCESS
!= php_http_client_curl_wait(h
, NULL
)) {
2638 /* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */
2639 php_error_docref(NULL
, E_WARNING
, "WinSock error: %d", WSAGetLastError());
2641 php_error_docref(NULL
, E_WARNING
, "%s", strerror(errno
));
2651 static ZEND_RESULT_CODE
php_http_client_curl_setopt(php_http_client_t
*h
, php_http_client_setopt_opt_t opt
, void *arg
)
2653 php_http_client_curl_t
*curl
= h
->ctx
;
2658 case PHP_HTTP_CLIENT_OPT_CONFIGURATION
:
2659 return php_http_options_apply(&php_http_curlm_options
, (HashTable
*) arg
, h
);
2661 #if !PHP_HTTP_CURL_VERSION(7,62,0)
2662 case PHP_HTTP_CLIENT_OPT_ENABLE_PIPELINING
:
2663 if (CURLM_OK
!= curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_PIPELINING
, (long) *((zend_bool
*) arg
))) {
2668 case PHP_HTTP_CLIENT_OPT_USE_EVENTS
:
2669 #if PHP_HTTP_HAVE_LIBEVENT
2670 return php_http_curlm_use_eventloop(h
, (*(zend_bool
*) arg
)
2671 ? php_http_client_curl_event_ops_get()
2682 static int apply_available_options(zval
*pDest
, int num_args
, va_list args
, zend_hash_key
*hash_key
)
2684 php_http_option_t
*opt
= Z_PTR_P(pDest
);
2689 ht
= va_arg(args
, HashTable
*);
2691 if ((c
= zend_hash_num_elements(&opt
->suboptions
.options
))) {
2692 array_init_size(&entry
, c
);
2693 zend_hash_apply_with_arguments(&opt
->suboptions
.options
, apply_available_options
, 1, Z_ARRVAL(entry
));
2695 /* catch deliberate NULL options */
2696 if (Z_TYPE(opt
->defval
) == IS_STRING
&& !Z_STRVAL(opt
->defval
)) {
2699 ZVAL_ZVAL(&entry
, &opt
->defval
, 1, 0);
2703 if (hash_key
->key
) {
2704 zend_hash_update(ht
, hash_key
->key
, &entry
);
2706 zend_hash_index_update(ht
, hash_key
->h
, &entry
);
2709 return ZEND_HASH_APPLY_KEEP
;
2712 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
)
2714 php_http_client_enqueue_t
*enqueue
;
2717 case PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
:
2718 if ((enqueue
= php_http_client_enqueued(h
, arg
, NULL
))) {
2719 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2721 *((php_http_client_progress_state_t
**) res
) = &handler
->progress
;
2726 case PHP_HTTP_CLIENT_OPT_TRANSFER_INFO
:
2727 if ((enqueue
= php_http_client_enqueued(h
, arg
, NULL
))) {
2728 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2730 php_http_curle_get_info(handler
->handle
, *(HashTable
**) res
);
2735 case PHP_HTTP_CLIENT_OPT_AVAILABLE_OPTIONS
:
2736 zend_hash_apply_with_arguments(&php_http_curle_options
.options
, apply_available_options
, 1, *(HashTable
**) res
);
2739 case PHP_HTTP_CLIENT_OPT_AVAILABLE_CONFIGURATION
:
2740 zend_hash_apply_with_arguments(&php_http_curlm_options
.options
, apply_available_options
, 1, *(HashTable
**) res
);
2750 static php_http_client_ops_t php_http_client_curl_ops
= {
2751 &php_http_curlm_resource_factory_ops
,
2752 php_http_client_curl_init
,
2754 php_http_client_curl_dtor
,
2755 php_http_client_curl_reset
,
2756 php_http_client_curl_exec
,
2757 php_http_client_curl_wait
,
2758 php_http_client_curl_once
,
2759 php_http_client_curl_enqueue
,
2760 php_http_client_curl_dequeue
,
2761 php_http_client_curl_requeue
,
2762 php_http_client_curl_setopt
,
2763 php_http_client_curl_getopt
2766 php_http_client_ops_t
*php_http_client_curl_get_ops(void)
2768 return &php_http_client_curl_ops
;
2771 #define REGISTER_NS_STRING_OR_NULL_CONSTANT(ns, name, str, flags) \
2773 if ((str) != NULL) { \
2774 REGISTER_NS_STRING_CONSTANT(ns, name, str, flags); \
2776 REGISTER_NS_NULL_CONSTANT(ns, name, flags); \
2780 PHP_MINIT_FUNCTION(http_client_curl
)
2782 curl_version_info_data
*info
;
2783 php_http_options_t
*options
;
2785 PHP_HTTP_G
->client
.curl
.driver
.driver_name
= zend_string_init(ZEND_STRL("curl"), 1);
2786 PHP_HTTP_G
->client
.curl
.driver
.client_name
= zend_string_init(ZEND_STRL("http\\Client\\Curl"), 1);
2787 PHP_HTTP_G
->client
.curl
.driver
.request_name
= zend_string_init(ZEND_STRL("http\\Client\\Curl\\Request"), 1);
2788 PHP_HTTP_G
->client
.curl
.driver
.client_ops
= &php_http_client_curl_ops
;
2790 if (SUCCESS
!= php_http_client_driver_add(&PHP_HTTP_G
->client
.curl
.driver
)) {
2794 if (SUCCESS
!= php_persistent_handle_provide(PHP_HTTP_G
->client
.curl
.driver
.client_name
, &php_http_curlm_resource_factory_ops
, NULL
, NULL
)) {
2797 if (SUCCESS
!= php_persistent_handle_provide(PHP_HTTP_G
->client
.curl
.driver
.request_name
, &php_http_curle_resource_factory_ops
, NULL
, NULL
)) {
2801 if ((options
= php_http_options_init(&php_http_curle_options
, 1))) {
2802 options
->getter
= php_http_curle_get_option
;
2803 options
->setter
= php_http_curle_set_option
;
2805 php_http_curle_options_init(options
);
2807 if ((options
= php_http_options_init(&php_http_curlm_options
, 1))) {
2808 options
->getter
= php_http_option_get
;
2809 options
->setter
= php_http_curlm_set_option
;
2811 php_http_curlm_options_init(options
);
2814 if ((info
= curl_version_info(CURLVERSION_NOW
))) {
2815 char tmp_ver
[0x20], *tmp_ptr
, *tmp_end
;
2816 #define tmp_ver_init() do {\
2818 tmp_ptr = &tmp_ver[0]; \
2819 tmp_end = &tmp_ver[sizeof(tmp_ver) - 1]; \
2825 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "FEATURES", info
->features
, CONST_CS
|CONST_PERSISTENT
);
2827 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "IPV6", CURL_VERSION_IPV6
, CONST_CS
|CONST_PERSISTENT
);
2828 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "KERBEROS4", CURL_VERSION_KERBEROS4
, CONST_CS
|CONST_PERSISTENT
);
2829 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SSL", CURL_VERSION_SSL
, CONST_CS
|CONST_PERSISTENT
);
2830 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "LIBZ", CURL_VERSION_LIBZ
, CONST_CS
|CONST_PERSISTENT
);
2831 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "NTLM", CURL_VERSION_NTLM
, CONST_CS
|CONST_PERSISTENT
);
2832 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "GSSNEGOTIATE", CURL_VERSION_GSSNEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2833 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ASYNCHDNS", CURL_VERSION_ASYNCHDNS
, CONST_CS
|CONST_PERSISTENT
);
2834 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SPNEGO", CURL_VERSION_SPNEGO
, CONST_CS
|CONST_PERSISTENT
);
2835 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "LARGEFILE", CURL_VERSION_LARGEFILE
, CONST_CS
|CONST_PERSISTENT
);
2836 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "IDN", CURL_VERSION_IDN
, CONST_CS
|CONST_PERSISTENT
);
2837 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SSPI", CURL_VERSION_SSPI
, CONST_CS
|CONST_PERSISTENT
);
2838 #if PHP_HTTP_CURL_VERSION(7,21,4)
2839 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "TLSAUTH_SRP", CURL_VERSION_TLSAUTH_SRP
, CONST_CS
|CONST_PERSISTENT
);
2841 #if PHP_HTTP_CURL_VERSION(7,22,0)
2842 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "NTLM_WB", CURL_VERSION_NTLM_WB
, CONST_CS
|CONST_PERSISTENT
);
2844 #if PHP_HTTP_CURL_VERSION(7,33,0)
2845 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTP2", CURL_VERSION_HTTP2
, CONST_CS
|CONST_PERSISTENT
);
2847 #if PHP_HTTP_CURL_VERSION(7,38,0)
2848 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "GSSAPI", CURL_VERSION_GSSAPI
, CONST_CS
|CONST_PERSISTENT
);
2850 #if PHP_HTTP_CURL_VERSION(7,40,0)
2851 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "KERBEROS5", CURL_VERSION_KERBEROS5
, CONST_CS
|CONST_PERSISTENT
);
2852 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "UNIX_SOCKETS", CURL_VERSION_UNIX_SOCKETS
, CONST_CS
|CONST_PERSISTENT
);
2854 #if PHP_HTTP_CURL_VERSION(7,47,0)
2855 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "PSL", CURL_VERSION_PSL
, CONST_CS
|CONST_PERSISTENT
);
2857 #if PHP_HTTP_CURL_VERSION(7,52,0)
2858 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTPS_PROXY", CURL_VERSION_HTTPS_PROXY
, CONST_CS
|CONST_PERSISTENT
);
2860 #if PHP_HTTP_CURL_VERSION(7,56,0)
2861 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "MULTI_SSL", CURL_VERSION_MULTI_SSL
, CONST_CS
|CONST_PERSISTENT
);
2863 #if PHP_HTTP_CURL_VERSION(7,57,0)
2864 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "BROTLI", CURL_VERSION_BROTLI
, CONST_CS
|CONST_PERSISTENT
);
2866 #if PHP_HTTP_CURL_VERSION(7,64,1)
2867 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ALTSVC", CURL_VERSION_ALTSVC
, CONST_CS
|CONST_PERSISTENT
);
2869 #if PHP_HTTP_CURL_VERSION(7,66,0)
2870 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTP3", CURL_VERSION_HTTP3
, CONST_CS
|CONST_PERSISTENT
);
2872 #if PHP_HTTP_CURL_VERSION(7,72,0)
2873 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ZSTD", CURL_VERSION_ZSTD
, CONST_CS
|CONST_PERSISTENT
);
2874 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "UNICODE", CURL_VERSION_UNICODE
, CONST_CS
|CONST_PERSISTENT
);
2876 #if PHP_HTTP_CURL_VERSION(7,74,0)
2877 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HSTS", CURL_VERSION_HSTS
, CONST_CS
|CONST_PERSISTENT
);
2884 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl", "VERSIONS", curl_version(), CONST_CS
|CONST_PERSISTENT
);
2885 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "CURL", info
->version
, CONST_CS
|CONST_PERSISTENT
);
2886 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "SSL", info
->ssl_version
, CONST_CS
|CONST_PERSISTENT
);
2887 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "LIBZ", info
->libz_version
, CONST_CS
|CONST_PERSISTENT
);
2888 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ARES", info
->ares
, CONST_CS
|CONST_PERSISTENT
);
2889 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "IDN", info
->libidn
, CONST_CS
|CONST_PERSISTENT
);
2891 if (info
->iconv_ver_num
) {
2892 tmp_ptr
= zend_print_ulong_to_buf(tmp_end
, info
->iconv_ver_num
& 0xf);
2893 tmp_end
= tmp_ptr
- 1;
2894 tmp_ptr
= zend_print_ulong_to_buf(tmp_end
, info
->iconv_ver_num
>> 8);
2897 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ICONV", *tmp_ptr
? tmp_ptr
: NULL
, CONST_CS
|CONST_PERSISTENT
);
2898 #if PHP_HTTP_CURL_VERSION(7,57,0)
2899 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "BROTLI", info
->brotli_version
, CONST_CS
|CONST_PERSISTENT
);
2901 #if PHP_HTTP_CURL_VERSION(7,66,0)
2902 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "NGHTTP2", info
->nghttp2_version
, CONST_CS
|CONST_PERSISTENT
);
2903 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "QUIC", info
->quic_version
, CONST_CS
|CONST_PERSISTENT
);
2905 #if PHP_HTTP_CURL_VERSION(7,70,0)
2906 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "CAINFO", info
->cainfo
, CONST_CS
|CONST_PERSISTENT
);
2907 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "CAPATH", info
->capath
, CONST_CS
|CONST_PERSISTENT
);
2909 #if PHP_HTTP_CURL_VERSION(7,72,0)
2910 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ZSTD", info
->zstd_version
, CONST_CS
|CONST_PERSISTENT
);
2912 #if PHP_HTTP_CURL_VERSION(7,75,0)
2913 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "HYPER", info
->hyper_version
, CONST_CS
|CONST_PERSISTENT
);
2919 * HTTP Protocol Version Constants
2921 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_1_0", CURL_HTTP_VERSION_1_0
, CONST_CS
|CONST_PERSISTENT
);
2922 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_1_1", CURL_HTTP_VERSION_1_1
, CONST_CS
|CONST_PERSISTENT
);
2923 #if PHP_HTTP_CURL_VERSION(7,33,0)
2924 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2_0", CURL_HTTP_VERSION_2_0
, CONST_CS
|CONST_PERSISTENT
);
2926 #if PHP_HTTP_CURL_VERSION(7,47,0)
2927 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2TLS", CURL_HTTP_VERSION_2TLS
, CONST_CS
|CONST_PERSISTENT
);
2929 #if PHP_HTTP_CURL_VERSION(7,49,0)
2930 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2_PRIOR_KNOWLEDGE", CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE
, CONST_CS
|CONST_PERSISTENT
);
2932 #if PHP_HTTP_CURL_VERSION(7,66,0)
2933 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_3", CURL_HTTP_VERSION_3
, CONST_CS
|CONST_PERSISTENT
);
2935 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_ANY", CURL_HTTP_VERSION_NONE
, CONST_CS
|CONST_PERSISTENT
);
2938 * SSL Version Constants
2940 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1", CURL_SSLVERSION_TLSv1
, CONST_CS
|CONST_PERSISTENT
);
2941 #if PHP_HTTP_CURL_VERSION(7,34,0)
2942 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_0", CURL_SSLVERSION_TLSv1_0
, CONST_CS
|CONST_PERSISTENT
);
2943 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_1", CURL_SSLVERSION_TLSv1_1
, CONST_CS
|CONST_PERSISTENT
);
2944 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_2", CURL_SSLVERSION_TLSv1_2
, CONST_CS
|CONST_PERSISTENT
);
2946 #if PHP_HTTP_CURL_VERSION(7,52,0)
2947 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_3", CURL_SSLVERSION_TLSv1_3
, CONST_CS
|CONST_PERSISTENT
);
2949 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv2", CURL_SSLVERSION_SSLv2
, CONST_CS
|CONST_PERSISTENT
);
2950 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv3", CURL_SSLVERSION_SSLv3
, CONST_CS
|CONST_PERSISTENT
);
2951 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_ANY", CURL_SSLVERSION_DEFAULT
, CONST_CS
|CONST_PERSISTENT
);
2952 #if PHP_HTTP_CURL_VERSION(7,21,4) && PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
2953 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "TLSAUTH_SRP", CURL_TLSAUTH_SRP
, CONST_CS
|CONST_PERSISTENT
);
2956 #if PHP_HTTP_CURL_VERSION(7,54,0)
2957 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_DEFAULT", CURL_SSLVERSION_MAX_DEFAULT
, CONST_CS
|CONST_PERSISTENT
);
2958 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_0", CURL_SSLVERSION_MAX_TLSv1_0
, CONST_CS
|CONST_PERSISTENT
);
2959 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_1", CURL_SSLVERSION_MAX_TLSv1_1
, CONST_CS
|CONST_PERSISTENT
);
2960 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_2", CURL_SSLVERSION_MAX_TLSv1_2
, CONST_CS
|CONST_PERSISTENT
);
2961 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_3", CURL_SSLVERSION_MAX_TLSv1_3
, CONST_CS
|CONST_PERSISTENT
);
2965 * DNS IPvX resolving
2967 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_V4", CURL_IPRESOLVE_V4
, CONST_CS
|CONST_PERSISTENT
);
2968 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_V6", CURL_IPRESOLVE_V6
, CONST_CS
|CONST_PERSISTENT
);
2969 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_ANY", CURL_IPRESOLVE_WHATEVER
, CONST_CS
|CONST_PERSISTENT
);
2974 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_NONE", CURLAUTH_NONE
, CONST_CS
|CONST_PERSISTENT
);
2975 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_BASIC", CURLAUTH_BASIC
, CONST_CS
|CONST_PERSISTENT
);
2976 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_DIGEST", CURLAUTH_DIGEST
, CONST_CS
|CONST_PERSISTENT
);
2977 #if PHP_HTTP_CURL_VERSION(7,19,3)
2978 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_DIGEST_IE", CURLAUTH_DIGEST_IE
, CONST_CS
|CONST_PERSISTENT
);
2980 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_NTLM", CURLAUTH_NTLM
, CONST_CS
|CONST_PERSISTENT
);
2981 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_GSSNEG", CURLAUTH_GSSNEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2982 #if PHP_HTTP_CURL_VERSION(7,38,0)
2983 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_SPNEGO", CURLAUTH_NEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2985 #if PHP_HTTP_CURL_VERSION(7,61,0)
2986 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_BEARER", CURLAUTH_BEARER
, CONST_CS
|CONST_PERSISTENT
);
2988 #if PHP_HTTP_CURL_VERSION(7,75,0)
2989 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AWS_SIGV4", CURLAUTH_AWS_SIGV4
, CONST_CS
|CONST_PERSISTENT
);
2991 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_ANY", CURLAUTH_ANY
, CONST_CS
|CONST_PERSISTENT
);
2994 * Proxy Type Constants
2996 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS4", CURLPROXY_SOCKS4
, CONST_CS
|CONST_PERSISTENT
);
2997 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS4A", CURLPROXY_SOCKS4A
, CONST_CS
|CONST_PERSISTENT
);
2998 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS5_HOSTNAME", CURLPROXY_SOCKS5_HOSTNAME
, CONST_CS
|CONST_PERSISTENT
);
2999 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS5", CURLPROXY_SOCKS5
, CONST_CS
|CONST_PERSISTENT
);
3000 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_HTTP", CURLPROXY_HTTP
, CONST_CS
|CONST_PERSISTENT
);
3001 #if PHP_HTTP_CURL_VERSION(7,19,4)
3002 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_HTTP_1_0", CURLPROXY_HTTP_1_0
, CONST_CS
|CONST_PERSISTENT
);
3006 * Post Redirection Constants
3008 #if PHP_HTTP_CURL_VERSION(7,19,1)
3009 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_301", CURL_REDIR_POST_301
, CONST_CS
|CONST_PERSISTENT
);
3010 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_302", CURL_REDIR_POST_302
, CONST_CS
|CONST_PERSISTENT
);
3011 #if PHP_HTTP_CURL_VERSION(7,26,0)
3012 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_303", CURL_REDIR_POST_303
, CONST_CS
|CONST_PERSISTENT
);
3014 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_ALL", CURL_REDIR_POST_ALL
, CONST_CS
|CONST_PERSISTENT
);
3017 #if PHP_HTTP_CURL_VERSION(7,64,1)
3018 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_READONLYFILE", CURLALTSVC_READONLYFILE
, CONST_CS
|CONST_PERSISTENT
);
3019 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_H1", CURLALTSVC_H1
, CONST_CS
|CONST_PERSISTENT
);
3020 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_H2", CURLALTSVC_H2
, CONST_CS
|CONST_PERSISTENT
);
3021 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_H3", CURLALTSVC_H3
, CONST_CS
|CONST_PERSISTENT
);
3023 #if PHP_HTTP_CURL_VERSION(7,74,0)
3024 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HSTS_ENABLE", CURLHSTS_ENABLE
, CONST_CS
|CONST_PERSISTENT
);
3025 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HSTS_READONLYFILE", CURLHSTS_READONLYFILE
, CONST_CS
|CONST_PERSISTENT
);
3030 PHP_MSHUTDOWN_FUNCTION(http_client_curl
)
3032 php_persistent_handle_cleanup(PHP_HTTP_G
->client
.curl
.driver
.client_name
, NULL
);
3033 php_persistent_handle_cleanup(PHP_HTTP_G
->client
.curl
.driver
.request_name
, NULL
);
3034 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.client_name
);
3035 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.request_name
);
3036 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.driver_name
);
3038 php_http_options_dtor(&php_http_curle_options
);
3039 php_http_options_dtor(&php_http_curlm_options
);
3044 #endif /* PHP_HTTP_HAVE_LIBCURL */
3051 * vim600: noet sw=4 ts=4 fdm=marker
3052 * vim<600: noet sw=4 ts=4