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_UPLOAD_T
, &o
)) {
372 zend_hash_str_update(info
, "size_upload_t", lenof("size_upload_t"), &tmp
);
374 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SIZE_DOWNLOAD
, &d
)) {
375 ZVAL_DOUBLE(&tmp
, d
);
376 zend_hash_str_update(info
, "size_download", lenof("size_download"), &tmp
);
378 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SIZE_DOWNLOAD_T
, &o
)) {
380 zend_hash_str_update(info
, "size_download_t", lenof("size_download_t"), &tmp
);
382 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_DOWNLOAD
, &d
)) {
383 ZVAL_DOUBLE(&tmp
, d
);
384 zend_hash_str_update(info
, "speed_download", lenof("speed_download"), &tmp
);
386 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_DOWNLOAD_T
, &o
)) {
388 zend_hash_str_update(info
, "speed_download_t", lenof("speed_download_t"), &tmp
);
390 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_UPLOAD
, &d
)) {
391 ZVAL_DOUBLE(&tmp
, d
);
392 zend_hash_str_update(info
, "speed_upload", lenof("speed_upload"), &tmp
);
394 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_UPLOAD_T
, &o
)) {
396 zend_hash_str_update(info
, "speed_upload_t", lenof("speed_upload_t"), &tmp
);
398 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HEADER_SIZE
, &l
)) {
400 zend_hash_str_update(info
, "header_size", lenof("header_size"), &tmp
);
402 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REQUEST_SIZE
, &l
)) {
404 zend_hash_str_update(info
, "request_size", lenof("request_size"), &tmp
);
406 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SSL_VERIFYRESULT
, &l
)) {
408 zend_hash_str_update(info
, "ssl_verifyresult", lenof("ssl_verifyresult"), &tmp
);
410 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_FILETIME
, &l
)) {
412 zend_hash_str_update(info
, "filetime", lenof("filetime"), &tmp
);
414 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_FILETIME_T
, &o
)) {
416 zend_hash_str_update(info
, "filetime_t", lenof("filetime_t"), &tmp
);
418 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_DOWNLOAD
, &d
)) {
419 ZVAL_DOUBLE(&tmp
, d
);
420 zend_hash_str_update(info
, "content_length_download", lenof("content_length_download"), &tmp
);
422 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T
, &o
)) {
424 zend_hash_str_update(info
, "content_length_download_t", lenof("content_length_download_t"), &tmp
);
426 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_UPLOAD
, &d
)) {
427 ZVAL_DOUBLE(&tmp
, d
);
428 zend_hash_str_update(info
, "content_length_upload", lenof("content_length_upload"), &tmp
);
430 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_UPLOAD_T
, &o
)) {
432 zend_hash_str_update(info
, "content_length_upload_t", lenof("content_length_upload_t"), &tmp
);
434 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_STARTTRANSFER_TIME
, &d
)) {
435 ZVAL_DOUBLE(&tmp
, d
);
436 zend_hash_str_update(info
, "starttransfer_time", lenof("starttransfer_time"), &tmp
);
438 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_TYPE
, &c
)) {
439 ZVAL_STRING(&tmp
, STR_PTR(c
));
440 zend_hash_str_update(info
, "content_type", lenof("content_type"), &tmp
);
442 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_TIME
, &d
)) {
443 ZVAL_DOUBLE(&tmp
, d
);
444 zend_hash_str_update(info
, "redirect_time", lenof("redirect_time"), &tmp
);
446 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_COUNT
, &l
)) {
448 zend_hash_str_update(info
, "redirect_count", lenof("redirect_count"), &tmp
);
450 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTP_CONNECTCODE
, &l
)) {
452 zend_hash_str_update(info
, "connect_code", lenof("connect_code"), &tmp
);
454 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTPAUTH_AVAIL
, &l
)) {
456 zend_hash_str_update(info
, "httpauth_avail", lenof("httpauth_avail"), &tmp
);
458 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXYAUTH_AVAIL
, &l
)) {
460 zend_hash_str_update(info
, "proxyauth_avail", lenof("proxyauth_avail"), &tmp
);
462 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_OS_ERRNO
, &l
)) {
464 zend_hash_str_update(info
, "os_errno", lenof("os_errno"), &tmp
);
466 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_NUM_CONNECTS
, &l
)) {
468 zend_hash_str_update(info
, "num_connects", lenof("num_connects"), &tmp
);
470 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SSL_ENGINES
, &s
)) {
472 for (p
= s
; p
; p
= p
->next
) {
474 add_next_index_string(&tmp
, p
->data
);
477 zend_hash_str_update(info
, "ssl_engines", lenof("ssl_engines"), &tmp
);
478 curl_slist_free_all(s
);
480 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_URL
, &c
)) {
481 ZVAL_STRING(&tmp
, STR_PTR(c
));
482 zend_hash_str_update(info
, "redirect_url", lenof("redirect_url"), &tmp
);
484 #if PHP_HTTP_CURL_VERSION(7,19,0)
485 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRIMARY_IP
, &c
)) {
486 ZVAL_STRING(&tmp
, STR_PTR(c
));
487 zend_hash_str_update(info
, "primary_ip", lenof("primary_ip"), &tmp
);
490 #if PHP_HTTP_CURL_VERSION(7,19,0)
491 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_APPCONNECT_TIME
, &d
)) {
492 ZVAL_DOUBLE(&tmp
, d
);
493 zend_hash_str_update(info
, "appconnect_time", lenof("appconnect_time"), &tmp
);
496 #if PHP_HTTP_CURL_VERSION(7,19,4)
497 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONDITION_UNMET
, &l
)) {
499 zend_hash_str_update(info
, "condition_unmet", lenof("condition_unmet"), &tmp
);
502 #if PHP_HTTP_CURL_VERSION(7,21,0)
503 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRIMARY_PORT
, &l
)) {
505 zend_hash_str_update(info
, "primary_port", lenof("primary_port"), &tmp
);
508 #if PHP_HTTP_CURL_VERSION(7,21,0)
509 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_LOCAL_IP
, &c
)) {
510 ZVAL_STRING(&tmp
, STR_PTR(c
));
511 zend_hash_str_update(info
, "local_ip", lenof("local_ip"), &tmp
);
514 #if PHP_HTTP_CURL_VERSION(7,21,0)
515 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_LOCAL_PORT
, &l
)) {
517 zend_hash_str_update(info
, "local_port", lenof("local_port"), &tmp
);
520 #if PHP_HTTP_CURL_VERSION(7,50,0)
521 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTP_VERSION
, &l
)) {
523 zend_hash_str_update(info
, "http_version", lenof("http_version"), &tmp
);
526 #if PHP_HTTP_CURL_VERSION(7,52,0)
527 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXY_SSL_VERIFYRESULT
, &l
)) {
529 zend_hash_str_update(info
, "proxy_ssl_verifyresult", lenof("proxy_ssl_verifyresult"), &tmp
);
532 #if PHP_HTTP_CURL_VERSION(7,52,0)
533 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROTOCOL
, &l
)) {
535 zend_hash_str_update(info
, "protocol", lenof("protocol"), &tmp
);
538 #if PHP_HTTP_CURL_VERSION(7,52,0)
539 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SCHEME
, &c
)) {
540 ZVAL_STRING(&tmp
, STR_PTR(c
));
541 zend_hash_str_update(info
, "scheme", lenof("scheme"), &tmp
);
544 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TOTAL_TIME_T
, &o
)) {
546 zend_hash_str_update(info
, "total_time_t", lenof("total_time_t"), &tmp
);
548 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_NAMELOOKUP_TIME_T
, &o
)) {
550 zend_hash_str_update(info
, "namelookup_time_t", lenof("namelookup_time_t"), &tmp
);
552 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONNECT_TIME_T
, &o
)) {
554 zend_hash_str_update(info
, "connect_time_t", lenof("connect_time_t"), &tmp
);
556 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRETRANSFER_TIME_T
, &o
)) {
558 zend_hash_str_update(info
, "pretransfer_time_t", lenof("pretransfer_time_t"), &tmp
);
560 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_STARTTRANSFER_TIME_T
, &o
)) {
562 zend_hash_str_update(info
, "starttransfer_time_t", lenof("starttransfer_time_t"), &tmp
);
564 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_TIME_T
, &o
)) {
566 zend_hash_str_update(info
, "redirect_time_t", lenof("redirect_time_t"), &tmp
);
568 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_APPCONNECT_TIME_T
, &o
)) {
570 zend_hash_str_update(info
, "appconnect_time_t", lenof("appconnect_time_t"), &tmp
);
572 #if PHP_HTTP_CURL_VERSION(7,66,0)
573 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_RETRY_AFTER
, &o
)) {
575 zend_hash_str_update(info
, "retry_after", lenof("retry_after"), &tmp
);
578 #if PHP_HTTP_CURL_VERSION(7,72,0)
579 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_EFFECTIVE_METHOD
, &c
)) {
580 ZVAL_STRING(&tmp
, STR_PTR(c
));
581 zend_hash_str_update(info
, "effective_method", lenof("effective_method"), &tmp
);
584 #if PHP_HTTP_CURL_VERSION(7,73,0)
585 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXY_ERROR
, &l
)) {
587 zend_hash_str_update(info
, "proxy_error", lenof("proxy_error"), &tmp
);
590 #if PHP_HTTP_CURL_VERSION(7,76,0)
591 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REFERER
, &c
)) {
592 ZVAL_STRING(&tmp
, STR_PTR(c
));
593 zend_hash_str_update(info
, "referer", lenof("referer"), &tmp
);
596 #if PHP_HTTP_CURL_VERSION(7,84,0)
597 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CAINFO
, &c
)) {
598 ZVAL_STRING(&tmp
, STR_PTR(c
));
599 zend_hash_str_update(info
, "cainfo", lenof("cainfo"), &tmp
);
602 #if PHP_HTTP_CURL_VERSION(7,84,0)
603 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CAPATH
, &c
)) {
604 ZVAL_STRING(&tmp
, STR_PTR(c
));
605 zend_hash_str_update(info
, "capath", lenof("capath"), &tmp
);
611 #if PHP_HTTP_CURL_VERSION(7,34,0)
613 zval ti_array
, subarray
;
614 struct curl_tlssessioninfo
*ti
;
616 #if PHP_HTTP_CURL_VERSION(7,48,0)
617 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TLS_SSL_PTR
, &ti
)) {
619 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TLS_SESSION
, &ti
)) {
623 ZVAL_NULL(&subarray
);
624 array_init(&ti_array
);
626 switch (ti
->backend
) {
627 case CURLSSLBACKEND_NONE
:
630 case CURLSSLBACKEND_OPENSSL
:
632 #if PHP_HTTP_HAVE_LIBCURL_OPENSSL
634 #if PHP_HTTP_CURL_VERSION(7,48,0)
635 SSL
*ssl
= ti
->internals
;
636 SSL_CTX
*ctx
= ssl
? SSL_get_SSL_CTX(ssl
) : NULL
;
638 SSL_CTX
*ctx
= ti
->internals
;
641 array_init(&subarray
);
643 add_assoc_long_ex(&subarray
, ZEND_STRL("number"), SSL_CTX_sess_number(ctx
));
644 add_assoc_long_ex(&subarray
, ZEND_STRL("connect"), SSL_CTX_sess_connect(ctx
));
645 add_assoc_long_ex(&subarray
, ZEND_STRL("connect_good"), SSL_CTX_sess_connect_good(ctx
));
646 add_assoc_long_ex(&subarray
, ZEND_STRL("connect_renegotiate"), SSL_CTX_sess_connect_renegotiate(ctx
));
647 add_assoc_long_ex(&subarray
, ZEND_STRL("hits"), SSL_CTX_sess_hits(ctx
));
648 add_assoc_long_ex(&subarray
, ZEND_STRL("cache_full"), SSL_CTX_sess_cache_full(ctx
));
653 case CURLSSLBACKEND_GNUTLS
:
655 #if PHP_HTTP_HAVE_LIBCURL_GNUTLS
657 gnutls_session_t sess
= ti
->internals
;
660 array_init(&subarray
);
662 if ((desc
= gnutls_session_get_desc(sess
))) {
663 add_assoc_string_ex(&subarray
, ZEND_STRL("desc"), desc
);
666 add_assoc_bool_ex(&subarray
, ZEND_STRL("resumed"), gnutls_session_is_resumed(sess
));
671 case CURLSSLBACKEND_NSS
:
674 #if !PHP_HTTP_CURL_VERSION(7,39,0)
675 case CURLSSLBACKEND_QSOSSL
:
679 case CURLSSLBACKEND_GSKIT
:
683 case CURLSSLBACKEND_POLARSSL
:
684 backend
= "polarssl";
686 case CURLSSLBACKEND_CYASSL
:
689 case CURLSSLBACKEND_SCHANNEL
:
690 backend
= "schannel";
692 case CURLSSLBACKEND_DARWINSSL
:
693 backend
= "darwinssl";
698 add_assoc_string_ex(&ti_array
, ZEND_STRL("backend"), backend
);
699 add_assoc_zval_ex(&ti_array
, ZEND_STRL("internals"), &subarray
);
700 zend_hash_str_update(info
, "tls_session", lenof("tls_session"), &ti_array
);
705 #if (PHP_HTTP_CURL_VERSION(7,19,1) && PHP_HTTP_HAVE_LIBCURL_OPENSSL) || \
706 (PHP_HTTP_CURL_VERSION(7,34,0) && PHP_HTTP_HAVE_LIBCURL_NSS) || \
707 (PHP_HTTP_CURL_VERSION(7,39,0) && PHP_HTTP_HAVE_LIBCURL_GSKIT) || \
708 (PHP_HTTP_CURL_VERSION(7,42,0) && PHP_HTTP_HAVE_LIBCURL_GNUTLS) || \
709 (PHP_HTTP_CURL_VERSION(7,79,0) && PHP_HTTP_HAVE_LIBCURL_SECURETRANSPORT)
712 zval ci_array
, subarray
;
713 struct curl_certinfo
*ci
;
714 char *colon
, *keyname
;
716 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CERTINFO
, &ci
)) {
717 array_init(&ci_array
);
719 for (i
= 0; i
< ci
->num_of_certs
; ++i
) {
722 array_init(&subarray
);
723 for (p
= s
; p
; p
= p
->next
) {
725 if ((colon
= strchr(p
->data
, ':'))) {
726 keyname
= estrndup(p
->data
, colon
- p
->data
);
727 add_assoc_string_ex(&subarray
, keyname
, colon
- p
->data
, colon
+ 1);
730 add_next_index_string(&subarray
, p
->data
);
734 add_next_index_zval(&ci_array
, &subarray
);
736 zend_hash_str_update(info
, "certinfo", lenof("certinfo"), &ci_array
);
741 php_http_curle_storage_t
*st
= php_http_curle_get_storage(ch
);
743 ZVAL_LONG(&tmp
, st
->errorcode
);
744 zend_hash_str_update(info
, "curlcode", lenof("curlcode"), &tmp
);
745 ZVAL_STRING(&tmp
, st
->errorbuffer
);
746 zend_hash_str_update(info
, "error", lenof("error"), &tmp
);
752 static int compare_queue(php_http_client_enqueue_t
*e
, void *handle
)
754 return handle
== ((php_http_client_curl_handler_t
*) e
->opaque
)->handle
;
757 static php_http_message_t
*php_http_curlm_responseparser(php_http_client_curl_handler_t
*h
)
759 php_http_message_t
*response
;
760 php_http_header_parser_t parser
;
763 response
= php_http_message_init(NULL
, 0, h
->response
.body
);
764 php_http_header_parser_init(&parser
);
765 while (h
->response
.headers
.used
) {
766 php_http_header_parser_state_t st
= php_http_header_parser_parse(&parser
,
767 &h
->response
.headers
, PHP_HTTP_HEADER_PARSER_CLEANUP
, &response
->hdrs
,
768 (php_http_info_callback_t
) php_http_message_info_callback
, (void *) &response
);
769 if (PHP_HTTP_HEADER_PARSER_STATE_FAILURE
== st
) {
773 php_http_header_parser_dtor(&parser
);
775 /* move body to right message */
776 if (response
->body
!= h
->response
.body
) {
777 php_http_message_t
*ptr
= response
;
779 while (ptr
->parent
) {
782 php_http_message_body_free(&response
->body
);
783 response
->body
= ptr
->body
;
786 php_http_message_body_addref(h
->response
.body
);
788 /* let's update the response headers */
789 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Length")))) {
791 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Length", lenof("X-Original-Content-Length"), &tmp
);
793 if ((zh
= php_http_message_header(response
, ZEND_STRL("Transfer-Encoding")))) {
795 zend_hash_str_del(&response
->hdrs
, "Transfer-Encoding", lenof("Transfer-Encoding"));
796 zend_hash_str_update(&response
->hdrs
, "X-Original-Transfer-Encoding", lenof("X-Original-Transfer-Encoding"), &tmp
);
798 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Range")))) {
800 zend_hash_str_del(&response
->hdrs
, "Content-Range", lenof("Content-Range"));
801 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Range", lenof("X-Original-Content-Range"), &tmp
);
803 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Encoding")))) {
805 zend_hash_str_del(&response
->hdrs
, "Content-Encoding", lenof("Content-Encoding"));
806 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Encoding", lenof("X-Original-Content-Encoding"), &tmp
);
808 php_http_message_update_headers(response
);
813 void php_http_client_curl_responsehandler(php_http_client_t
*context
)
815 int err_count
= 0, remaining
= 0;
816 php_http_curle_storage_t
*st
, *err
= NULL
;
817 php_http_client_enqueue_t
*enqueue
;
818 php_http_client_curl_t
*curl
= context
->ctx
;
821 CURLMsg
*msg
= curl_multi_info_read(curl
->handle
->multi
, &remaining
);
823 if (msg
&& CURLMSG_DONE
== msg
->msg
) {
824 if (CURLE_OK
!= msg
->data
.result
) {
825 st
= php_http_curle_get_storage(msg
->easy_handle
);
826 st
->errorcode
= msg
->data
.result
;
828 /* defer the warnings/exceptions, so the callback is still called for this request */
830 err
= ecalloc(remaining
+ 1, sizeof(*err
));
832 memcpy(&err
[err_count
], st
, sizeof(*st
));
834 err
[err_count
].url
= estrdup(st
->url
);
839 if ((enqueue
= php_http_client_enqueued(context
, msg
->easy_handle
, compare_queue
))) {
840 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
841 php_http_message_t
*response
= php_http_curlm_responseparser(handler
);
844 context
->callback
.response
.func(context
->callback
.response
.arg
, context
, &handler
->queue
, &response
);
845 php_http_message_free(&response
);
855 php_error_docref(NULL
, E_WARNING
, "%s; %s (%s)", curl_easy_strerror(err
[i
].errorcode
), err
[i
].errorbuffer
, STR_PTR(err
[i
].url
));
859 } while (++i
< err_count
);
865 void php_http_client_curl_loop(php_http_client_t
*client
, curl_socket_t s
, int curl_action
)
868 php_http_client_curl_t
*curl
= client
->ctx
;
871 fprintf(stderr
, "H");
875 rc
= curl_multi_socket_action(curl
->handle
->multi
, s
, curl_action
, &curl
->unfinished
);
876 } while (CURLM_CALL_MULTI_PERFORM
== rc
);
878 if (CURLM_OK
!= rc
) {
879 php_error_docref(NULL
, E_WARNING
, "%s", curl_multi_strerror(rc
));
882 php_http_client_curl_responsehandler(client
);
887 static php_http_options_t php_http_curle_options
, php_http_curlm_options
;
889 #define PHP_HTTP_CURLE_OPTION_CHECK_STRLEN 0x0001
890 #define PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR 0x0002
891 #define PHP_HTTP_CURLE_OPTION_TRANSFORM_MS 0x0004
892 #define PHP_HTTP_CURLE_OPTION_IGNORE_RC 0x0008
894 static ZEND_RESULT_CODE
php_http_curle_option_set_ssl_verifyhost(php_http_option_t
*opt
, zval
*val
, void *userdata
)
896 php_http_client_curl_handler_t
*curl
= userdata
;
897 CURL
*ch
= curl
->handle
;
899 if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, Z_TYPE_P(val
) == IS_TRUE
? 2 : 0)) {
905 static ZEND_RESULT_CODE
php_http_curle_option_set_cookiesession(php_http_option_t
*opt
, zval
*val
, void *userdata
)
907 php_http_client_curl_handler_t
*curl
= userdata
;
908 CURL
*ch
= curl
->handle
;
910 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIESESSION
, (long) (Z_TYPE_P(val
) == IS_TRUE
))) {
913 if (Z_TYPE_P(val
) == IS_TRUE
) {
915 fprintf(stderr
, "CURLOPT_COOKIELIST: SESS\n");
917 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIELIST
, "SESS")) {
925 static ZEND_RESULT_CODE
php_http_curle_option_set_cookiestore(php_http_option_t
*opt
, zval
*val
, void *userdata
)
927 php_http_client_curl_handler_t
*curl
= userdata
;
928 CURL
*ch
= curl
->handle
;
929 php_http_curle_storage_t
*storage
= php_http_curle_get_storage(curl
->handle
);
931 if (storage
->cookiestore
) {
932 pefree(storage
->cookiestore
, 1);
934 if (val
&& Z_TYPE_P(val
) == IS_STRING
&& Z_STRLEN_P(val
)) {
935 storage
->cookiestore
= pestrndup(Z_STRVAL_P(val
), Z_STRLEN_P(val
), 1);
937 storage
->cookiestore
= NULL
;
941 fprintf(stderr
, "CURLOPT_COOKIEFILE: %s\n", storage
->cookiestore
);
943 // does NOT enable ch->data.cookies until transfer; adds to ch->stsate.cookielist
944 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIEFILE
, storage
->cookiestore
? storage
->cookiestore
: "")) {
948 fprintf(stderr
, "CURLOPT_COOKIEJAR: %s\n", storage
->cookiestore
);
950 // enables ch->data.cookies
951 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIEJAR
, storage
->cookiestore
)) {
958 static ZEND_RESULT_CODE
php_http_curle_option_set_cookies(php_http_option_t
*opt
, zval
*val
, void *userdata
)
960 php_http_client_curl_handler_t
*curl
= userdata
;
961 CURL
*ch
= curl
->handle
;
963 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
964 HashTable
*ht
= HASH_OF(val
);
966 if (curl
->options
.encode_cookies
) {
967 if (SUCCESS
== php_http_url_encode_hash_ex(ht
, &curl
->options
.cookies
, ZEND_STRL(";"), ZEND_STRL("="), NULL
, 0)) {
968 php_http_buffer_fix(&curl
->options
.cookies
);
969 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, curl
->options
.cookies
.data
)) {
976 php_http_arrkey_t cookie_key
;
979 ZEND_HASH_FOREACH_KEY_VAL(ht
, cookie_key
.h
, cookie_key
.key
, cookie_val
)
981 zend_string
*zs
= zval_get_string(cookie_val
);
983 php_http_arrkey_stringify(&cookie_key
, NULL
);
984 php_http_buffer_appendf(&curl
->options
.cookies
, "%s=%s; ", cookie_key
.key
->val
, zs
->val
);
985 php_http_arrkey_dtor(&cookie_key
);
987 zend_string_release(zs
);
989 ZEND_HASH_FOREACH_END();
991 php_http_buffer_fix(&curl
->options
.cookies
);
992 if (curl
->options
.cookies
.used
) {
993 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, curl
->options
.cookies
.data
)) {
999 php_http_buffer_reset(&curl
->options
.cookies
);
1000 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, NULL
)) {
1007 static ZEND_RESULT_CODE
php_http_curle_option_set_encodecookies(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1009 php_http_client_curl_handler_t
*curl
= userdata
;
1011 curl
->options
.encode_cookies
= Z_TYPE_P(val
) == IS_TRUE
;
1015 static ZEND_RESULT_CODE
php_http_curle_option_set_lastmodified(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1017 php_http_client_curl_handler_t
*curl
= userdata
;
1018 CURL
*ch
= curl
->handle
;
1020 if (Z_LVAL_P(val
)) {
1021 if (Z_LVAL_P(val
) > 0) {
1022 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, Z_LVAL_P(val
))) {
1026 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, (long) sapi_get_request_time() + Z_LVAL_P(val
))) {
1030 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMECONDITION
, (long) (curl
->options
.range_request
? CURL_TIMECOND_IFUNMODSINCE
: CURL_TIMECOND_IFMODSINCE
))) {
1034 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, 0)
1035 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMECONDITION
, 0)
1043 #if PHP_HTTP_CURL_VERSION(7,64,1)
1044 static ZEND_RESULT_CODE
php_http_curle_option_set_altsvc_ctrl(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1046 php_http_client_curl_handler_t
*curl
= userdata
;
1047 CURL
*ch
= curl
->handle
;
1049 if (Z_LVAL_P(val
)) {
1050 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_ALTSVC_CTRL
, Z_LVAL_P(val
))) {
1058 static ZEND_RESULT_CODE
php_http_curle_option_set_compress(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1060 php_http_client_curl_handler_t
*curl
= userdata
;
1061 CURL
*ch
= curl
->handle
;
1063 #if !PHP_HTTP_CURL_VERSION(7,21,6)
1064 # define CURLOPT_ACCEPT_ENCODING CURLOPT_ENCODING
1066 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_ACCEPT_ENCODING
, Z_TYPE_P(val
) == IS_TRUE
? "" : NULL
)) {
1072 static ZEND_RESULT_CODE
php_http_curle_option_set_etag(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1074 php_http_client_curl_handler_t
*curl
= userdata
;
1075 php_http_buffer_t header
;
1077 if (val
&& Z_TYPE_P(val
) == IS_STRING
&& Z_STRLEN_P(val
)) {
1078 zend_bool is_quoted
= !((Z_STRVAL_P(val
)[0] != '"') || (Z_STRVAL_P(val
)[Z_STRLEN_P(val
)-1] != '"'));
1079 php_http_buffer_init(&header
);
1080 php_http_buffer_appendf(&header
, is_quoted
?"%s: %s":"%s: \"%s\"", curl
->options
.range_request
?"If-Match":"If-None-Match", Z_STRVAL_P(val
));
1081 php_http_buffer_fix(&header
);
1082 curl
->options
.headers
= curl_slist_append(curl
->options
.headers
, header
.data
);
1083 php_http_buffer_dtor(&header
);
1088 static ZEND_RESULT_CODE
php_http_curle_option_set_range(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1090 php_http_client_curl_handler_t
*curl
= userdata
;
1091 CURL
*ch
= curl
->handle
;
1093 php_http_buffer_reset(&curl
->options
.ranges
);
1095 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1097 HashTable
*ht
= HASH_OF(val
);
1099 ZEND_HASH_FOREACH_VAL(ht
, rr
)
1101 if (Z_TYPE_P(rr
) == IS_ARRAY
) {
1102 if (2 == php_http_array_list(Z_ARRVAL_P(rr
), 2, &rb
, &re
)) {
1103 zend_long rbl
= zval_get_long(rb
), rel
= zval_get_long(re
);
1107 php_http_buffer_appendf(&curl
->options
.ranges
, "%ld-%ld,", rbl
, rel
);
1109 php_http_buffer_appendf(&curl
->options
.ranges
, "%ld-", rbl
);
1111 } else if (rel
> 0) {
1112 php_http_buffer_appendf(&curl
->options
.ranges
, "-%ld", rel
);
1117 ZEND_HASH_FOREACH_END();
1119 if (curl
->options
.ranges
.used
) {
1120 curl
->options
.range_request
= 1;
1121 /* ditch last comma */
1122 curl
->options
.ranges
.data
[curl
->options
.ranges
.used
- 1] = '\0';
1126 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RANGE
, curl
->options
.ranges
.data
)) {
1132 static ZEND_RESULT_CODE
php_http_curle_option_set_resume(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1134 php_http_client_curl_handler_t
*curl
= userdata
;
1135 CURL
*ch
= curl
->handle
;
1137 if (Z_LVAL_P(val
) > 0) {
1138 curl
->options
.range_request
= 1;
1140 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESUME_FROM
, Z_LVAL_P(val
))) {
1146 static ZEND_RESULT_CODE
php_http_curle_option_set_retrydelay(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1148 php_http_client_curl_handler_t
*curl
= userdata
;
1150 curl
->options
.retry
.delay
= Z_DVAL_P(val
);
1154 static ZEND_RESULT_CODE
php_http_curle_option_set_retrycount(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1156 php_http_client_curl_handler_t
*curl
= userdata
;
1158 curl
->options
.retry
.count
= Z_LVAL_P(val
);
1162 static ZEND_RESULT_CODE
php_http_curle_option_set_redirect(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1164 php_http_client_curl_handler_t
*curl
= userdata
;
1165 CURL
*ch
= curl
->handle
;
1167 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, Z_LVAL_P(val
) ? 1L : 0L)
1168 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_MAXREDIRS
, curl
->options
.redirects
= Z_LVAL_P(val
))
1175 static ZEND_RESULT_CODE
php_http_curle_option_set_portrange(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1177 php_http_client_curl_handler_t
*curl
= userdata
;
1178 CURL
*ch
= curl
->handle
;
1179 long localport
= 0, localportrange
= 0;
1181 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1184 switch (php_http_array_list(Z_ARRVAL_P(val
), 2, &zps
, &zpe
)) {
1186 localportrange
= labs(zval_get_long(zps
)-zval_get_long(zpe
))+1L;
1189 localport
= (zval_get_long(zpe
) > 0) ? MIN(zval_get_long(zps
), zval_get_long(zpe
)) : zval_get_long(zps
);
1195 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_LOCALPORT
, localport
)
1196 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_LOCALPORTRANGE
, localportrange
)
1203 #if PHP_HTTP_CURL_VERSION(7,37,0)
1204 static ZEND_RESULT_CODE
php_http_curle_option_set_proxyheader(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1206 php_http_client_curl_handler_t
*curl
= userdata
;
1208 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1209 php_http_arrkey_t header_key
;
1211 php_http_buffer_t header
;
1213 php_http_buffer_init(&header
);
1214 ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(val
), header_key
.h
, header_key
.key
, header_val
)
1216 if (header_key
.key
) {
1217 zend_string
*zs
= zval_get_string(header_val
);
1219 php_http_buffer_appendf(&header
, "%s: %s", header_key
.key
->val
, zs
->val
);
1220 zend_string_release(zs
);
1222 php_http_buffer_fix(&header
);
1223 curl
->options
.proxyheaders
= curl_slist_append(curl
->options
.proxyheaders
, header
.data
);
1224 php_http_buffer_reset(&header
);
1228 ZEND_HASH_FOREACH_END();
1229 php_http_buffer_dtor(&header
);
1231 if (CURLE_OK
!= curl_easy_setopt(curl
->handle
, CURLOPT_PROXYHEADER
, curl
->options
.proxyheaders
)) {
1234 if (CURLE_OK
!= curl_easy_setopt(curl
->handle
, CURLOPT_HEADEROPT
, CURLHEADER_SEPARATE
)) {
1235 curl_easy_setopt(curl
->handle
, CURLOPT_PROXYHEADER
, NULL
);
1242 #if PHP_HTTP_CURL_VERSION(7,21,3)
1243 static ZEND_RESULT_CODE
php_http_curle_option_set_resolve(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1245 php_http_client_curl_handler_t
*curl
= userdata
;
1246 CURL
*ch
= curl
->handle
;
1248 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1249 HashTable
*ht
= HASH_OF(val
);
1252 ZEND_HASH_FOREACH_VAL(ht
, data
)
1254 zend_string
*zs
= zval_get_string(data
);
1255 curl
->options
.resolve
= curl_slist_append(curl
->options
.resolve
, zs
->val
);
1256 zend_string_release(zs
);
1258 ZEND_HASH_FOREACH_END();
1260 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESOLVE
, curl
->options
.resolve
)) {
1264 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESOLVE
, NULL
)) {
1272 #if PHP_HTTP_CURL_VERSION(7,21,4) && PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
1273 static ZEND_RESULT_CODE
php_http_curle_option_set_ssl_tlsauthtype(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1275 php_http_client_curl_handler_t
*curl
= userdata
;
1276 CURL
*ch
= curl
->handle
;
1278 if (val
&& Z_LVAL_P(val
)) {
1279 switch (Z_LVAL_P(val
)) {
1280 case CURL_TLSAUTH_NONE
:
1282 case CURL_TLSAUTH_SRP
:
1283 if (CURLE_OK
== curl_easy_setopt(ch
, opt
->option
, "SRP")) {
1291 if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, "NONE")) {
1298 static void php_http_curle_options_init(php_http_options_t
*registry
)
1300 php_http_option_t
*opt
;
1303 #if PHP_HTTP_CURL_VERSION(7,42,0)
1304 php_http_option_register(registry
, ZEND_STRL("path_as_is"), CURLOPT_PATH_AS_IS
, _IS_BOOL
);
1308 php_http_option_register(registry
, ZEND_STRL("proxyhost"), CURLOPT_PROXY
, IS_STRING
);
1309 php_http_option_register(registry
, ZEND_STRL("proxytype"), CURLOPT_PROXYTYPE
, IS_LONG
);
1310 php_http_option_register(registry
, ZEND_STRL("proxyport"), CURLOPT_PROXYPORT
, IS_LONG
);
1311 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyauth"), CURLOPT_PROXYUSERPWD
, IS_STRING
))) {
1312 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1314 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyauthtype"), CURLOPT_PROXYAUTH
, IS_LONG
))) {
1315 Z_LVAL(opt
->defval
) = CURLAUTH_ANYSAFE
;
1317 php_http_option_register(registry
, ZEND_STRL("proxytunnel"), CURLOPT_HTTPPROXYTUNNEL
, _IS_BOOL
);
1318 #if PHP_HTTP_CURL_VERSION(7,19,4)
1319 php_http_option_register(registry
, ZEND_STRL("noproxy"), CURLOPT_NOPROXY
, IS_STRING
);
1321 #if PHP_HTTP_CURL_VERSION(7,55,0)
1322 php_http_option_register(registry
, ZEND_STRL("socks5_auth"), CURLOPT_SOCKS5_AUTH
, IS_LONG
);
1325 #if PHP_HTTP_CURL_VERSION(7,37,0)
1326 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyheader"), CURLOPT_PROXYHEADER
, IS_ARRAY
))) {
1327 opt
->setter
= php_http_curle_option_set_proxyheader
;
1330 #if PHP_HTTP_CURL_VERSION(7,43,0)
1331 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_GSSAPI
)
1332 && (opt
= php_http_option_register(registry
, ZEND_STRL("proxy_service_name"), CURLOPT_PROXY_SERVICE_NAME
, IS_STRING
))
1334 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1337 #if PHP_HTTP_CURL_VERSION(7,60,0)
1338 php_http_option_register(registry
, ZEND_STRL("haproxy_protocol"), CURLOPT_HAPROXYPROTOCOL
, _IS_BOOL
);
1342 #if PHP_HTTP_CURL_VERSION(7,40,0)
1343 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_UNIX_SOCKETS
)) {
1344 if ((opt
= php_http_option_register(registry
, ZEND_STRL("unix_socket_path"), CURLOPT_UNIX_SOCKET_PATH
, IS_STRING
))) {
1345 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1346 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1348 #if PHP_HTTP_CURL_VERSION(7,53,0)
1349 if ((opt
= php_http_option_register(registry
, ZEND_STRL("abstract_unix_socket"), CURLOPT_ABSTRACT_UNIX_SOCKET
, IS_STRING
))) {
1350 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1357 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_cache_timeout"), CURLOPT_DNS_CACHE_TIMEOUT
, IS_LONG
))) {
1358 Z_LVAL(opt
->defval
) = 60;
1360 php_http_option_register(registry
, ZEND_STRL("ipresolve"), CURLOPT_IPRESOLVE
, IS_LONG
);
1361 #if PHP_HTTP_CURL_VERSION(7,21,3)
1362 if ((opt
= php_http_option_register(registry
, ZEND_STRL("resolve"), CURLOPT_RESOLVE
, IS_ARRAY
))) {
1363 opt
->setter
= php_http_curle_option_set_resolve
;
1366 #if PHP_HTTP_HAVE_LIBCURL_ARES
1367 # if PHP_HTTP_CURL_VERSION(7,24,0)
1368 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_servers"), CURLOPT_DNS_SERVERS
, IS_STRING
))) {
1369 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1372 # if PHP_HTTP_CURL_VERSION(7,33,0)
1373 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_interface"), CURLOPT_DNS_INTERFACE
, IS_STRING
))) {
1374 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1376 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_local_ip4"), CURLOPT_DNS_LOCAL_IP4
, IS_STRING
))) {
1377 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1379 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_local_ip6"), CURLOPT_DNS_LOCAL_IP6
, IS_STRING
))) {
1380 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1384 #if PHP_HTTP_CURL_VERSION(7,60,0)
1385 php_http_option_register(registry
, ZEND_STRL("dns_shuffle_addresses"), CURLOPT_DNS_SHUFFLE_ADDRESSES
, _IS_BOOL
);
1387 #if PHP_HTTP_CURL_VERSION(7,62,0)
1388 php_http_option_register(registry
, ZEND_STRL("doh_url"), CURLOPT_DOH_URL
, IS_STRING
);
1393 php_http_option_register(registry
, ZEND_STRL("low_speed_limit"), CURLOPT_LOW_SPEED_LIMIT
, IS_LONG
);
1394 php_http_option_register(registry
, ZEND_STRL("low_speed_time"), CURLOPT_LOW_SPEED_TIME
, IS_LONG
);
1397 php_http_option_register(registry, ZEND_STRL("max_send_speed"), CURLOPT_MAX_SEND_SPEED_LARGE, IS_LONG);
1398 php_http_option_register(registry, ZEND_STRL("max_recv_speed"), CURLOPT_MAX_RECV_SPEED_LARGE, IS_LONG);
1401 /* connection handling */
1403 if ((opt = php_http_option_register(registry, ZEND_STRL("maxconnects"), CURLOPT_MAXCONNECTS, IS_LONG))) {
1404 Z_LVAL(opt->defval) = 5;
1407 php_http_option_register(registry
, ZEND_STRL("fresh_connect"), CURLOPT_FRESH_CONNECT
, _IS_BOOL
);
1408 php_http_option_register(registry
, ZEND_STRL("forbid_reuse"), CURLOPT_FORBID_REUSE
, _IS_BOOL
);
1409 #if PHP_HTTP_CURL_VERSION(7,65,0)
1410 if ((opt
= php_http_option_register(registry
, ZEND_STRL("maxage_conn"), CURLOPT_MAXAGE_CONN
, IS_LONG
))) {
1411 ZVAL_LONG(&opt
->defval
, 118);
1415 /* outgoing interface */
1416 php_http_option_register(registry
, ZEND_STRL("interface"), CURLOPT_INTERFACE
, IS_STRING
);
1417 if ((opt
= php_http_option_register(registry
, ZEND_STRL("portrange"), CURLOPT_LOCALPORT
, IS_ARRAY
))) {
1418 opt
->setter
= php_http_curle_option_set_portrange
;
1421 /* another endpoint port */
1422 php_http_option_register(registry
, ZEND_STRL("port"), CURLOPT_PORT
, IS_LONG
);
1424 /* RFC4007 zone_id */
1425 #if PHP_HTTP_CURL_VERSION(7,19,0)
1426 php_http_option_register(registry
, ZEND_STRL("address_scope"), CURLOPT_ADDRESS_SCOPE
, IS_LONG
);
1430 if ((opt
= php_http_option_register(registry
, ZEND_STRL("httpauth"), CURLOPT_USERPWD
, IS_STRING
))) {
1431 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1433 if ((opt
= php_http_option_register(registry
, ZEND_STRL("httpauthtype"), CURLOPT_HTTPAUTH
, IS_LONG
))) {
1434 Z_LVAL(opt
->defval
) = CURLAUTH_ANYSAFE
;
1436 #if PHP_HTTP_CURL_VERSION(7,43,0)
1437 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_SSPI
) || PHP_HTTP_CURL_FEATURE(CURL_VERSION_GSSAPI
))
1438 if ((opt
= php_http_option_register(registry
, ZEND_STRL("service_name"), CURLOPT_SERVICE_NAME
, IS_STRING
))) {
1439 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1442 #if PHP_HTTP_CURL_VERSION(7,61,0)
1443 if ((opt
= php_http_option_register(registry
, ZEND_STRL("xoauth2_bearer"), CURLOPT_XOAUTH2_BEARER
, IS_STRING
))) {
1444 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1447 #if PHP_HTTP_CURL_VERSION(7,75,0)
1448 php_http_option_register(registry
, ZEND_STRL("aws_sigv4"), CURLOPT_AWS_SIGV4
, IS_STRING
);
1452 if ((opt
= php_http_option_register(registry
, ZEND_STRL("redirect"), CURLOPT_FOLLOWLOCATION
, IS_LONG
))) {
1453 opt
->setter
= php_http_curle_option_set_redirect
;
1455 php_http_option_register(registry
, ZEND_STRL("unrestricted_auth"), CURLOPT_UNRESTRICTED_AUTH
, _IS_BOOL
);
1456 #if PHP_HTTP_CURL_VERSION(7,19,1)
1457 php_http_option_register(registry
, ZEND_STRL("postredir"), CURLOPT_POSTREDIR
, IS_LONG
);
1461 if ((opt
= php_http_option_register(registry
, ZEND_STRL("retrycount"), 0, IS_LONG
))) {
1462 opt
->setter
= php_http_curle_option_set_retrycount
;
1464 if ((opt
= php_http_option_register(registry
, ZEND_STRL("retrydelay"), 0, IS_DOUBLE
))) {
1465 opt
->setter
= php_http_curle_option_set_retrydelay
;
1469 if ((opt
= php_http_option_register(registry
, ZEND_STRL("referer"), CURLOPT_REFERER
, IS_STRING
))) {
1470 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1472 if ((opt
= php_http_option_register(registry
, ZEND_STRL("autoreferer"), CURLOPT_AUTOREFERER
, _IS_BOOL
))) {
1473 ZVAL_BOOL(&opt
->defval
, 1);
1477 if ((opt
= php_http_option_register(registry
, ZEND_STRL("useragent"), CURLOPT_USERAGENT
, IS_STRING
))) {
1478 /* don't check strlen, to allow sending no useragent at all */
1479 ZVAL_PSTRING(&opt
->defval
,
1480 "PECL_HTTP/" PHP_PECL_HTTP_VERSION
" "
1481 "PHP/" PHP_VERSION
" "
1482 "libcurl/" LIBCURL_VERSION
);
1486 if ((opt
= php_http_option_register(registry
, ZEND_STRL("resume"), CURLOPT_RESUME_FROM
, IS_LONG
))) {
1487 opt
->setter
= php_http_curle_option_set_resume
;
1490 if ((opt
= php_http_option_register(registry
, ZEND_STRL("range"), CURLOPT_RANGE
, IS_ARRAY
))) {
1491 opt
->setter
= php_http_curle_option_set_range
;
1495 if ((opt
= php_http_option_register(registry
, ZEND_STRL("etag"), 0, IS_STRING
))) {
1496 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1497 opt
->setter
= php_http_curle_option_set_etag
;
1501 if ((opt
= php_http_option_register(registry
, ZEND_STRL("compress"), 0, _IS_BOOL
))) {
1502 opt
->setter
= php_http_curle_option_set_compress
;
1506 if ((opt
= php_http_option_register(registry
, ZEND_STRL("lastmodified"), 0, IS_LONG
))) {
1507 opt
->setter
= php_http_curle_option_set_lastmodified
;
1511 if ((opt
= php_http_option_register(registry
, ZEND_STRL("encodecookies"), 0, _IS_BOOL
))) {
1512 opt
->setter
= php_http_curle_option_set_encodecookies
;
1513 ZVAL_BOOL(&opt
->defval
, 1);
1515 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookies"), 0, IS_ARRAY
))) {
1516 opt
->setter
= php_http_curle_option_set_cookies
;
1519 /* cookiesession, don't load session cookies from cookiestore */
1520 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookiesession"), CURLOPT_COOKIESESSION
, _IS_BOOL
))) {
1521 opt
->setter
= php_http_curle_option_set_cookiesession
;
1523 /* cookiestore, read initial cookies from that file and store cookies back into that file */
1524 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookiestore"), 0, IS_STRING
))) {
1525 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1526 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1527 opt
->setter
= php_http_curle_option_set_cookiestore
;
1531 php_http_option_register(registry
, ZEND_STRL("maxfilesize"), CURLOPT_MAXFILESIZE
, IS_LONG
);
1533 /* http protocol version */
1534 php_http_option_register(registry
, ZEND_STRL("protocol"), CURLOPT_HTTP_VERSION
, IS_LONG
);
1535 #if PHP_HTTP_CURL_VERSION(7,64,0)
1536 php_http_option_register(registry
, ZEND_STRL("http09_allowed"), CURLOPT_HTTP09_ALLOWED
, _IS_BOOL
);
1540 if ((opt
= php_http_option_register(registry
, ZEND_STRL("timeout"), CURLOPT_TIMEOUT_MS
, IS_DOUBLE
))) {
1541 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1543 if ((opt
= php_http_option_register(registry
, ZEND_STRL("connecttimeout"), CURLOPT_CONNECTTIMEOUT_MS
, IS_DOUBLE
))) {
1544 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1545 Z_DVAL(opt
->defval
) = 3;
1547 #if PHP_HTTP_CURL_VERSION(7,36,0)
1548 if ((opt
= php_http_option_register(registry
, ZEND_STRL("expect_100_timeout"), CURLOPT_EXPECT_100_TIMEOUT_MS
, IS_DOUBLE
))) {
1549 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1550 Z_DVAL(opt
->defval
) = 1;
1555 php_http_option_register(registry
, ZEND_STRL("tcp_nodelay"), CURLOPT_TCP_NODELAY
, _IS_BOOL
);
1556 #if PHP_HTTP_CURL_VERSION(7,25,0)
1557 php_http_option_register(registry
, ZEND_STRL("tcp_keepalive"), CURLOPT_TCP_KEEPALIVE
, _IS_BOOL
);
1558 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tcp_keepidle"), CURLOPT_TCP_KEEPIDLE
, IS_LONG
))) {
1559 Z_LVAL(opt
->defval
) = 60;
1561 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tcp_keepintvl"), CURLOPT_TCP_KEEPINTVL
, IS_LONG
))) {
1562 Z_LVAL(opt
->defval
) = 60;
1565 #if PHP_HTTP_CURL_VERSION(7,49,0)
1566 # if defined(linux) || defined(__APPLE__)
1567 /* CURLOPT_TCP_FASTOPEN is not supported (yet) on Windows */
1568 php_http_option_register(registry
, ZEND_STRL("tcp_fastopen"), CURLOPT_TCP_FASTOPEN
, _IS_BOOL
);
1573 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_SSL
)) {
1574 php_http_option_t
*ssl_opt
, *proxy_opt
;
1576 if ((ssl_opt
= php_http_option_register(registry
, ZEND_STRL("ssl"), 0, IS_ARRAY
))) {
1577 php_http_options_t
*ssl_registry
= &ssl_opt
->suboptions
;
1579 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("cert"), CURLOPT_SSLCERT
, IS_STRING
))) {
1580 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1581 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1583 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("certtype"), CURLOPT_SSLCERTTYPE
, IS_STRING
))) {
1584 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1585 ZVAL_PSTRING(&opt
->defval
, "PEM");
1587 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("key"), CURLOPT_SSLKEY
, IS_STRING
))) {
1588 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1589 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1591 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("keytype"), CURLOPT_SSLKEYTYPE
, IS_STRING
))) {
1592 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1593 ZVAL_PSTRING(&opt
->defval
, "PEM");
1595 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("keypasswd"), CURLOPT_SSLKEYPASSWD
, IS_STRING
))) {
1596 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1598 php_http_option_register(ssl_registry
, ZEND_STRL("engine"), CURLOPT_SSLENGINE
, IS_STRING
);
1599 php_http_option_register(ssl_registry
, ZEND_STRL("version"), CURLOPT_SSLVERSION
, IS_LONG
);
1600 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("verifypeer"), CURLOPT_SSL_VERIFYPEER
, _IS_BOOL
))) {
1601 ZVAL_BOOL(&opt
->defval
, 1);
1603 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("verifyhost"), CURLOPT_SSL_VERIFYHOST
, _IS_BOOL
))) {
1604 ZVAL_BOOL(&opt
->defval
, 1);
1605 opt
->setter
= php_http_curle_option_set_ssl_verifyhost
;
1607 #if PHP_HTTP_CURL_VERSION(7,41,0) && (PHP_HTTP_HAVE_LIBCURL_OPENSSL || PHP_HTTP_HAVE_LIBCURL_NSS || PHP_HTTP_HAVE_LIBCURL_GNUTLS)
1608 php_http_option_register(ssl_registry
, ZEND_STRL("verifystatus"), CURLOPT_SSL_VERIFYSTATUS
, _IS_BOOL
);
1610 php_http_option_register(ssl_registry
, ZEND_STRL("cipher_list"), CURLOPT_SSL_CIPHER_LIST
, IS_STRING
);
1611 #if PHP_HTTP_HAVE_LIBCURL_CAINFO
1612 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("cainfo"), CURLOPT_CAINFO
, IS_STRING
))) {
1613 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1614 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1615 # ifdef PHP_HTTP_CAINFO
1616 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAINFO
);
1620 #if PHP_HTTP_HAVE_LIBCURL_CAPATH
1621 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("capath"), CURLOPT_CAPATH
, IS_STRING
))) {
1622 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1623 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1624 # ifdef PHP_HTTP_CAPATH
1625 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAPATH
);
1629 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("random_file"), CURLOPT_RANDOM_FILE
, IS_STRING
))) {
1630 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1631 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1633 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("egdsocket"), CURLOPT_EGDSOCKET
, IS_STRING
))) {
1634 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1635 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1637 #if PHP_HTTP_CURL_VERSION(7,19,0)
1638 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("issuercert"), CURLOPT_ISSUERCERT
, IS_STRING
))) {
1639 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1640 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1642 # if PHP_HTTP_HAVE_LIBCURL_OPENSSL
1643 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("crlfile"), CURLOPT_CRLFILE
, IS_STRING
))) {
1644 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1645 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1649 #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))
1650 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("certinfo"), CURLOPT_CERTINFO
, _IS_BOOL
))) {
1651 ZVAL_FALSE(&opt
->defval
);
1654 #if PHP_HTTP_CURL_VERSION(7,36,0)
1655 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("enable_npn"), CURLOPT_SSL_ENABLE_NPN
, _IS_BOOL
))) {
1656 ZVAL_BOOL(&opt
->defval
, 1);
1658 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("enable_alpn"), CURLOPT_SSL_ENABLE_ALPN
, _IS_BOOL
))) {
1659 ZVAL_BOOL(&opt
->defval
, 1);
1662 #if PHP_HTTP_CURL_VERSION(7,39,0)
1663 /* FIXME: see http://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html#AVAILABILITY */
1664 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("pinned_publickey"), CURLOPT_PINNEDPUBLICKEY
, IS_STRING
))) {
1665 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1666 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1669 #if PHP_HTTP_CURL_VERSION(7,21,4) && PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
1670 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tlsauthtype"), CURLOPT_TLSAUTH_TYPE
, IS_LONG
))) {
1671 opt
->setter
= php_http_curle_option_set_ssl_tlsauthtype
;
1673 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tlsauthuser"), CURLOPT_TLSAUTH_USERNAME
, IS_STRING
))) {
1674 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1676 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tlsauthpass"), CURLOPT_TLSAUTH_PASSWORD
, IS_STRING
))) {
1677 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1680 #if PHP_HTTP_CURL_VERSION(7,42,0) && (PHP_HTTP_HAVE_LIBCURL_NSS || PHP_HTTP_HAVE_LIBCURL_SECURETRANSPORT)
1681 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("falsestart"), CURLOPT_SSL_FALSESTART
, _IS_BOOL
))) {
1682 opt
->flags
|= PHP_HTTP_CURLE_OPTION_IGNORE_RC
;
1685 #if PHP_HTTP_CURL_VERSION(7,61,0) && PHP_HTTP_HAVE_LIBCURL_TLS13_CIPHERS
1686 if ((opt
= php_http_option_register(ssl_registry
, ZEND_STRL("tls13_ciphers"), CURLOPT_TLS13_CIPHERS
, IS_STRING
))) {
1687 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1692 #if PHP_HTTP_CURL_VERSION(7,52,0)
1694 if ((proxy_opt
= php_http_option_register(registry
, ZEND_STRL("proxy_ssl"), 0, IS_ARRAY
))) {
1695 php_http_options_t
*proxy_registry
= &proxy_opt
->suboptions
;
1697 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("cert"), CURLOPT_PROXY_SSLCERT
, IS_STRING
))) {
1698 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1699 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1701 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("certtype"), CURLOPT_PROXY_SSLCERTTYPE
, IS_STRING
))) {
1702 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1703 ZVAL_PSTRING(&opt
->defval
, "PEM");
1705 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("key"), CURLOPT_PROXY_SSLKEY
, IS_STRING
))) {
1706 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1707 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1709 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("keytype"), CURLOPT_PROXY_SSLKEYTYPE
, IS_STRING
))) {
1710 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1711 ZVAL_PSTRING(&opt
->defval
, "PEM");
1713 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("keypasswd"), CURLOPT_PROXY_KEYPASSWD
, IS_STRING
))) {
1714 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1716 php_http_option_register(proxy_registry
, ZEND_STRL("version"), CURLOPT_PROXY_SSLVERSION
, IS_LONG
);
1717 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("verifypeer"), CURLOPT_PROXY_SSL_VERIFYPEER
, _IS_BOOL
))) {
1718 ZVAL_BOOL(&opt
->defval
, 1);
1720 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("verifyhost"), CURLOPT_PROXY_SSL_VERIFYHOST
, _IS_BOOL
))) {
1721 ZVAL_BOOL(&opt
->defval
, 1);
1722 opt
->setter
= php_http_curle_option_set_ssl_verifyhost
;
1724 php_http_option_register(proxy_registry
, ZEND_STRL("cipher_list"), CURLOPT_PROXY_SSL_CIPHER_LIST
, IS_STRING
);
1725 # if PHP_HTTP_CURL_VERSION(7,71,0)
1726 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("issuercert"), CURLOPT_PROXY_ISSUERCERT
, IS_STRING
))) {
1727 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1728 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1731 # if PHP_HTTP_HAVE_LIBCURL_OPENSSL
1732 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("crlfile"), CURLOPT_PROXY_CRLFILE
, IS_STRING
))) {
1733 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1734 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1737 # if PHP_HTTP_HAVE_LIBCURL_CAINFO
1738 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("cainfo"), CURLOPT_PROXY_CAINFO
, IS_STRING
))) {
1739 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1740 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1741 # ifdef PHP_HTTP_CAINFO
1742 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAINFO
);
1746 # if PHP_HTTP_HAVE_LIBCURL_CAPATH
1747 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("capath"), CURLOPT_PROXY_CAPATH
, IS_STRING
))) {
1748 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1749 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1750 # ifdef PHP_HTTP_CAPATH
1751 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CAPATH
);
1756 # if PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
1757 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tlsauthtype"), CURLOPT_PROXY_TLSAUTH_TYPE
, IS_LONG
))) {
1758 opt
->setter
= php_http_curle_option_set_ssl_tlsauthtype
;
1760 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tlsauthuser"), CURLOPT_PROXY_TLSAUTH_USERNAME
, IS_STRING
))) {
1761 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1763 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tlsauthpass"), CURLOPT_PROXY_TLSAUTH_PASSWORD
, IS_STRING
))) {
1764 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1767 # if PHP_HTTP_CURL_VERSION(7,59,0)
1768 /* FIXME: see http://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html#AVAILABILITY */
1769 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("pinned_publickey"), CURLOPT_PROXY_PINNEDPUBLICKEY
, IS_STRING
))) {
1770 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1771 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1774 # if PHP_HTTP_CURL_VERSION(7,61,0) && PHP_HTTP_HAVE_LIBCURL_TLS13_CIPHERS
1775 if ((opt
= php_http_option_register(proxy_registry
, ZEND_STRL("tls13_ciphers"), CURLOPT_PROXY_TLS13_CIPHERS
, IS_STRING
))) {
1776 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1783 #if PHP_HTTP_CURL_VERSION(7,64,1)
1784 # if !PHP_HTTP_HAVE_LIBCURL_ALT_SVC
1785 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_ALTSVC
)) {
1787 if ((opt
= php_http_option_register(registry
, ZEND_STRL("altsvc_ctrl"), CURLOPT_ALTSVC_CTRL
, IS_LONG
))) {
1788 opt
->setter
= php_http_curle_option_set_altsvc_ctrl
;
1790 if ((opt
= php_http_option_register(registry
, ZEND_STRL("altsvc"), CURLOPT_ALTSVC
, IS_STRING
))) {
1791 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1793 # if !PHP_HTTP_HAVE_LIBCURL_ALT_SVC
1797 #if PHP_HTTP_CURL_VERSION(7,74,0)
1798 # if !PHP_HTTP_HAVE_LIBCURL_HSTS
1799 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_HSTS
)) {
1801 php_http_option_register(registry
, ZEND_STRL("hsts_ctrl"), CURLOPT_HSTS_CTRL
, IS_LONG
);
1802 if ((opt
= php_http_option_register(registry
, ZEND_STRL("hsts"), CURLOPT_HSTS
, IS_STRING
))) {
1803 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1805 # if !PHP_HTTP_HAVE_LIBCURL_HSTS
1811 static zval
*php_http_curle_get_option(php_http_option_t
*opt
, HashTable
*options
, void *userdata
)
1813 php_http_client_curl_handler_t
*curl
= userdata
;
1816 if ((option
= php_http_option_get(opt
, options
, NULL
))) {
1819 ZVAL_DUP(&zopt
, option
);
1820 convert_to_explicit_type(&zopt
, opt
->type
);
1821 zend_hash_update(&curl
->options
.cache
, opt
->name
, &zopt
);
1822 return zend_hash_find(&curl
->options
.cache
, opt
->name
);
1827 static ZEND_RESULT_CODE
php_http_curle_set_option(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1829 php_http_client_curl_handler_t
*curl
= userdata
;
1830 CURL
*ch
= curl
->handle
;
1832 CURLcode rc
= CURLE_UNKNOWN_OPTION
;
1833 ZEND_RESULT_CODE rv
= SUCCESS
;
1839 switch (opt
->type
) {
1842 rv
= opt
->setter(opt
, val
, curl
);
1843 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, (long) (Z_TYPE_P(val
) == IS_TRUE
))) {
1850 rv
= opt
->setter(opt
, val
, curl
);
1851 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, Z_LVAL_P(val
))) {
1858 rv
= opt
->setter(opt
, val
, curl
);
1859 } else if (!val
|| Z_TYPE_P(val
) == IS_NULL
) {
1860 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1863 } else if ((opt
->flags
& PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
) && !Z_STRLEN_P(val
)) {
1864 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1867 } else if ((opt
->flags
& PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
) && Z_STRVAL_P(val
) && SUCCESS
!= php_check_open_basedir(Z_STRVAL_P(val
))) {
1868 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1871 } else if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, Z_STRVAL_P(val
)))) {
1877 if (opt
->flags
& PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
) {
1879 Z_DVAL(tmp
) *= 1000;
1883 rv
= opt
->setter(opt
, val
, curl
);
1884 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, (long) Z_DVAL_P(val
))) {
1891 rv
= opt
->setter(opt
, val
, curl
);
1892 } else if (Z_TYPE_P(val
) != IS_NULL
) {
1893 rv
= php_http_options_apply(&opt
->suboptions
, Z_ARRVAL_P(val
), curl
);
1899 rv
= opt
->setter(opt
, val
, curl
);
1905 if (rv
!= SUCCESS
) {
1906 if (opt
->flags
& PHP_HTTP_CURLE_OPTION_IGNORE_RC
) {
1909 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_easy_strerror(rc
));
1915 #if PHP_HTTP_CURL_VERSION(7,30,0) && !PHP_HTTP_CURL_VERSION(7,62,0)
1916 static ZEND_RESULT_CODE
php_http_curlm_option_set_pipelining_bl(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1918 php_http_client_t
*client
= userdata
;
1919 php_http_client_curl_t
*curl
= client
->ctx
;
1920 CURLM
*ch
= curl
->handle
->multi
;
1924 /* array of char *, ending with a NULL */
1925 if (value
&& Z_TYPE_P(value
) != IS_NULL
) {
1927 HashTable
*ht
= HASH_OF(value
);
1928 int c
= zend_hash_num_elements(ht
);
1929 char **ptr
= ecalloc(c
+ 1, sizeof(char *));
1933 zend_hash_init(&tmp_ht
, c
, NULL
, ZVAL_PTR_DTOR
, 0);
1934 array_join(ht
, &tmp_ht
, 0, ARRAY_JOIN_STRINGIFY
);
1936 ZEND_HASH_FOREACH_VAL(&tmp_ht
, entry
)
1938 *ptr
++ = Z_STRVAL_P(entry
);
1940 ZEND_HASH_FOREACH_END();
1943 if (CURLM_OK
!= curl_multi_setopt(ch
, opt
->option
, bl
)) {
1946 zend_hash_destroy(&tmp_ht
);
1953 zend_hash_destroy(&tmp_ht
);
1959 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
)
1961 php_http_client_curl_t
*curl
= h
->ctx
;
1965 if (!(ev_ctx
= ev_ops
->init(h
, init_data
))) {
1968 curl
->ev_ctx
= ev_ctx
;
1969 curl
->ev_ops
= ev_ops
;
1973 curl
->ev_ops
->dtor(&curl
->ev_ctx
);
1975 curl
->ev_ops
= NULL
;
1982 static ZEND_RESULT_CODE
php_http_curlm_option_set_use_eventloop(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1984 php_http_client_t
*client
= userdata
;
1985 php_http_client_curl_ops_t
*ev_ops
= NULL
;
1987 if (value
&& Z_TYPE_P(value
) == IS_OBJECT
&& instanceof_function(Z_OBJCE_P(value
), php_http_client_curl_user_get_class_entry())) {
1988 ev_ops
= php_http_client_curl_user_ops_get();
1989 #if PHP_HTTP_HAVE_LIBEVENT
1990 } else if (value
&& zend_is_true(value
)) {
1991 ev_ops
= php_http_client_curl_event_ops_get();
1995 return php_http_curlm_use_eventloop(client
, ev_ops
, value
);
1998 static ZEND_RESULT_CODE
php_http_curlm_option_set_share_cookies(php_http_option_t
*opt
, zval
*value
, void *userdata
)
2000 php_http_client_t
*client
= userdata
;
2001 php_http_client_curl_t
*curl
= client
->ctx
;
2004 if (Z_TYPE_P(value
) == IS_TRUE
) {
2005 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_COOKIE
);
2007 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_UNSHARE
, CURL_LOCK_DATA_COOKIE
);
2010 if (CURLSHE_OK
!= rc
) {
2011 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_share_strerror(rc
));
2017 #if PHP_HTTP_HAVE_LIBCURL_SHARE_SSL
2018 static ZEND_RESULT_CODE
php_http_curlm_option_set_share_ssl(php_http_option_t
*opt
, zval
*value
, void *userdata
)
2020 php_http_client_t
*client
= userdata
;
2021 php_http_client_curl_t
*curl
= client
->ctx
;
2024 if (Z_TYPE_P(value
) == IS_TRUE
) {
2025 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_SSL_SESSION
);
2027 rc
= curl_share_setopt(curl
->handle
->share
, CURLSHOPT_UNSHARE
, CURL_LOCK_DATA_SSL_SESSION
);
2030 if (CURLSHE_OK
!= rc
) {
2031 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_share_strerror(rc
));
2038 static void php_http_curlm_options_init(php_http_options_t
*registry
)
2040 php_http_option_t
*opt
;
2042 /* set size of connection cache */
2043 if ((opt
= php_http_option_register(registry
, ZEND_STRL("maxconnects"), CURLMOPT_MAXCONNECTS
, IS_LONG
))) {
2044 /* -1 == default, 0 == unlimited */
2045 ZVAL_LONG(&opt
->defval
, -1);
2047 /* set max number of connections to a single host */
2048 #if PHP_HTTP_CURL_VERSION(7,30,0)
2049 php_http_option_register(registry
, ZEND_STRL("max_host_connections"), CURLMOPT_MAX_HOST_CONNECTIONS
, IS_LONG
);
2051 /* max simultaneously open connections */
2052 #if PHP_HTTP_CURL_VERSION(7,30,0)
2053 php_http_option_register(registry
, ZEND_STRL("max_total_connections"), CURLMOPT_MAX_TOTAL_CONNECTIONS
, IS_LONG
);
2055 #if PHP_HTTP_CURL_VERSION(7,67,0)
2056 if ((opt
= php_http_option_register(registry
, ZEND_STRL("max_concurrent_streams"), CURLMOPT_MAX_CONCURRENT_STREAMS
, IS_LONG
))) {
2057 ZVAL_LONG(&opt
->defval
, 100);
2061 #if !PHP_HTTP_CURL_VERSION(7,62,0)
2062 /* enable/disable HTTP pipelining */
2063 php_http_option_register(registry
, ZEND_STRL("pipelining"), CURLMOPT_PIPELINING
, _IS_BOOL
);
2064 # if PHP_HTTP_CURL_VERSION(7,30,0)
2065 /* maximum number of requests in a pipeline */
2066 if ((opt
= php_http_option_register(registry
, ZEND_STRL("max_pipeline_length"), CURLMOPT_MAX_PIPELINE_LENGTH
, IS_LONG
))) {
2067 ZVAL_LONG(&opt
->defval
, 5);
2069 /* chunk length threshold for pipelining */
2070 php_http_option_register(registry
, ZEND_STRL("chunk_length_penalty_size"), CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE
, IS_LONG
);
2071 /* size threshold for pipelining penalty */
2072 php_http_option_register(registry
, ZEND_STRL("content_length_penalty_size"), CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE
, IS_LONG
);
2073 /* pipelining server blacklist */
2074 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pipelining_server_bl"), CURLMOPT_PIPELINING_SERVER_BL
, IS_ARRAY
))) {
2075 opt
->setter
= php_http_curlm_option_set_pipelining_bl
;
2077 /* pipelining host blacklist */
2078 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pipelining_site_bl"), CURLMOPT_PIPELINING_SITE_BL
, IS_ARRAY
))) {
2079 opt
->setter
= php_http_curlm_option_set_pipelining_bl
;
2084 if ((opt
= php_http_option_register(registry
, ZEND_STRL("use_eventloop"), 0, 0))) {
2085 opt
->setter
= php_http_curlm_option_set_use_eventloop
;
2088 if ((opt
= php_http_option_register(registry
, ZEND_STRL("share_cookies"), 0, _IS_BOOL
))) {
2089 opt
->setter
= php_http_curlm_option_set_share_cookies
;
2090 ZVAL_TRUE(&opt
->defval
);
2092 #if PHP_HTTP_HAVE_LIBCURL_SHARE_SSL
2093 if ((opt
= php_http_option_register(registry
, ZEND_STRL("share_ssl"), 0, _IS_BOOL
))) {
2094 opt
->setter
= php_http_curlm_option_set_share_ssl
;
2095 ZVAL_TRUE(&opt
->defval
);
2100 static ZEND_RESULT_CODE
php_http_curlm_set_option(php_http_option_t
*opt
, zval
*val
, void *userdata
)
2102 php_http_client_t
*client
= userdata
;
2103 php_http_client_curl_t
*curl
= client
->ctx
;
2104 CURLM
*ch
= curl
->handle
->multi
;
2105 zval zopt
, *orig
= val
;
2106 CURLMcode rc
= CURLM_UNKNOWN_OPTION
;
2107 ZEND_RESULT_CODE rv
= SUCCESS
;
2111 } else if (opt
->type
&& Z_TYPE_P(val
) != opt
->type
&& !(Z_TYPE_P(val
) == IS_NULL
&& opt
->type
== IS_ARRAY
)) {
2112 ZVAL_DUP(&zopt
, val
);
2113 convert_to_explicit_type(&zopt
, opt
->type
);
2119 rv
= opt
->setter(opt
, val
, client
);
2121 switch (opt
->type
) {
2123 if (CURLM_OK
!= (rc
= curl_multi_setopt(ch
, opt
->option
, (long) zend_is_true(val
)))) {
2125 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_multi_strerror(rc
));
2129 if (CURLM_OK
!= (rc
= curl_multi_setopt(ch
, opt
->option
, Z_LVAL_P(val
)))) {
2131 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_multi_strerror(rc
));
2136 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s", opt
->name
->val
);
2141 if (val
&& val
!= orig
&& val
!= &opt
->defval
) {
2150 static ZEND_RESULT_CODE
php_http_client_curl_handler_reset(php_http_client_curl_handler_t
*handler
)
2152 php_http_client_curl_t
*curl
= handler
->client
->ctx
;
2153 CURL
*ch
= handler
->handle
;
2154 php_http_curle_storage_t
*st
;
2156 if ((st
= php_http_curle_get_storage(ch
))) {
2161 if (st
->cookiestore
) {
2162 pefree(st
->cookiestore
, 1);
2163 st
->cookiestore
= NULL
;
2165 st
->errorbuffer
[0] = '\0';
2169 curl_easy_setopt(ch
, CURLOPT_URL
, NULL
);
2170 curl_easy_setopt(ch
, CURLOPT_CUSTOMREQUEST
, NULL
);
2171 curl_easy_setopt(ch
, CURLOPT_HTTPGET
, 1L);
2172 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 0L);
2173 /* libcurl < 7.19.6 does not clear auth info with USERPWD set to NULL */
2174 #if PHP_HTTP_CURL_VERSION(7,19,1)
2175 curl_easy_setopt(ch
, CURLOPT_PROXYUSERNAME
, NULL
);
2176 curl_easy_setopt(ch
, CURLOPT_PROXYPASSWORD
, NULL
);
2177 curl_easy_setopt(ch
, CURLOPT_USERNAME
, NULL
);
2178 curl_easy_setopt(ch
, CURLOPT_PASSWORD
, NULL
);
2181 #if PHP_HTTP_CURL_VERSION(7,21,3)
2182 if (handler
->options
.resolve
) {
2183 curl_slist_free_all(handler
->options
.resolve
);
2184 handler
->options
.resolve
= NULL
;
2187 handler
->options
.retry
.count
= 0;
2188 handler
->options
.retry
.delay
= 0;
2189 handler
->options
.redirects
= 0;
2190 handler
->options
.encode_cookies
= 1;
2192 if (handler
->options
.headers
) {
2193 curl_slist_free_all(handler
->options
.headers
);
2194 handler
->options
.headers
= NULL
;
2196 if (handler
->options
.proxyheaders
) {
2197 curl_slist_free_all(handler
->options
.proxyheaders
);
2198 handler
->options
.proxyheaders
= NULL
;
2201 php_http_buffer_reset(&handler
->options
.cookies
);
2202 php_http_buffer_reset(&handler
->options
.ranges
);
2204 if (php_http_message_body_size(handler
->response
.body
)) {
2205 php_http_message_body_free(&handler
->response
.body
);
2206 handler
->response
.body
= php_http_message_body_init(NULL
, NULL
);
2208 php_http_buffer_reset(&handler
->response
.headers
);
2211 curl_easy_setopt(ch
, CURLOPT_NOSIGNAL
, 1L);
2213 curl_easy_setopt(ch
, CURLOPT_HEADER
, 0L);
2214 curl_easy_setopt(ch
, CURLOPT_FILETIME
, 1L);
2215 curl_easy_setopt(ch
, CURLOPT_AUTOREFERER
, 1L);
2216 curl_easy_setopt(ch
, CURLOPT_VERBOSE
, 1L);
2217 curl_easy_setopt(ch
, CURLOPT_NOPROGRESS
, 0L);
2218 curl_easy_setopt(ch
, CURLOPT_HEADERFUNCTION
, php_http_curle_header_callback
);
2219 curl_easy_setopt(ch
, CURLOPT_WRITEFUNCTION
, php_http_curle_body_callback
);
2220 curl_easy_setopt(ch
, CURLOPT_DEBUGFUNCTION
, php_http_curle_raw_callback
);
2221 curl_easy_setopt(ch
, CURLOPT_READFUNCTION
, php_http_curle_read_callback
);
2222 curl_easy_setopt(ch
, CURLOPT_SEEKFUNCTION
, php_http_curle_seek_callback
);
2223 #if PHP_HTTP_CURL_VERSION(7,32,0)
2224 curl_easy_setopt(ch
, CURLOPT_XFERINFOFUNCTION
, php_http_curle_xferinfo_callback
);
2225 curl_easy_setopt(ch
, CURLOPT_XFERINFODATA
, handler
);
2227 curl_easy_setopt(ch
, CURLOPT_PROGRESSFUNCTION
, php_http_curle_progress_callback
);
2228 curl_easy_setopt(ch
, CURLOPT_PROGRESSDATA
, handler
);
2230 curl_easy_setopt(ch
, CURLOPT_DEBUGDATA
, handler
);
2231 curl_easy_setopt(ch
, CURLOPT_WRITEDATA
, handler
);
2232 curl_easy_setopt(ch
, CURLOPT_HEADERDATA
, handler
);
2234 fprintf(stderr
, "CURLOPT_SHARE: %p\n", curl
->handle
->share
);
2236 curl_easy_setopt(ch
, CURLOPT_SHARE
, curl
->handle
->share
);
2241 static php_http_client_curl_handler_t
*php_http_client_curl_handler_init(php_http_client_t
*h
, php_resource_factory_t
*rf
)
2244 php_http_client_curl_handler_t
*handler
;
2246 if (!(handle
= php_resource_factory_handle_ctor(rf
, NULL
))) {
2247 php_error_docref(NULL
, E_WARNING
, "Failed to initialize curl handle");
2251 handler
= ecalloc(1, sizeof(*handler
));
2253 handler
->client
= h
;
2254 handler
->handle
= handle
;
2255 handler
->response
.body
= php_http_message_body_init(NULL
, NULL
);
2256 php_http_buffer_init(&handler
->response
.headers
);
2257 php_http_buffer_init(&handler
->options
.cookies
);
2258 php_http_buffer_init(&handler
->options
.ranges
);
2259 zend_hash_init(&handler
->options
.cache
, 0, NULL
, ZVAL_PTR_DTOR
, 0);
2261 php_http_client_curl_handler_reset(handler
);
2267 static ZEND_RESULT_CODE
php_http_client_curl_handler_prepare(php_http_client_curl_handler_t
*curl
, php_http_client_enqueue_t
*enqueue
)
2270 php_http_message_t
*msg
= enqueue
->request
;
2271 php_http_curle_storage_t
*storage
= php_http_curle_get_storage(curl
->handle
);
2274 if (!PHP_HTTP_INFO(msg
).request
.url
) {
2275 php_error_docref(NULL
, E_WARNING
, "Cannot request empty URL");
2278 storage
->errorbuffer
[0] = '\0';
2280 pefree(storage
->url
, 1);
2282 php_http_url_to_string(PHP_HTTP_INFO(msg
).request
.url
, &storage
->url
, NULL
, 1);
2283 curl_easy_setopt(curl
->handle
, CURLOPT_URL
, storage
->url
);
2286 if (SUCCESS
!= php_http_options_apply(&php_http_curle_options
, enqueue
->options
, curl
)) {
2290 /* request headers */
2291 php_http_message_update_headers(msg
);
2292 if (zend_hash_num_elements(&msg
->hdrs
)) {
2293 php_http_arrkey_t header_key
;
2295 zend_string
*header_str
;
2296 php_http_buffer_t header
;
2297 #if !PHP_HTTP_CURL_VERSION(7,23,0)
2298 zval
*ct
= zend_hash_str_find(&msg
->hdrs
, ZEND_STRL("Content-Length"));
2301 php_http_buffer_init(&header
);
2302 ZEND_HASH_FOREACH_KEY_VAL(&msg
->hdrs
, header_key
.h
, header_key
.key
, header_val
)
2304 if (header_key
.key
) {
2305 #if !PHP_HTTP_CURL_VERSION(7,23,0)
2306 /* avoid duplicate content-length header */
2307 if (ct
&& ct
== header_val
) {
2311 header_str
= zval_get_string(header_val
);
2312 php_http_buffer_appendf(&header
, "%s: %s", header_key
.key
->val
, header_str
->val
);
2313 php_http_buffer_fix(&header
);
2314 curl
->options
.headers
= curl_slist_append(curl
->options
.headers
, header
.data
);
2315 php_http_buffer_reset(&header
);
2316 zend_string_release(header_str
);
2319 ZEND_HASH_FOREACH_END();
2320 php_http_buffer_dtor(&header
);
2322 curl_easy_setopt(curl
->handle
, CURLOPT_HTTPHEADER
, curl
->options
.headers
);
2324 /* attach request body */
2325 if ((body_size
= php_http_message_body_size(msg
->body
))) {
2326 /* RFC2616, section 4.3 (para. 4) states that »a message-body MUST NOT be included in a request if the
2327 * specification of the request method (section 5.1.1) does not allow sending an entity-body in request.«
2328 * Following the clause in section 5.1.1 (para. 2) that request methods »MUST be implemented with the
2329 * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method
2330 * does not allow a request body.
2332 php_stream_rewind(php_http_message_body_stream(msg
->body
));
2333 curl_easy_setopt(curl
->handle
, CURLOPT_SEEKDATA
, msg
->body
);
2334 curl_easy_setopt(curl
->handle
, CURLOPT_READDATA
, msg
->body
);
2335 curl_easy_setopt(curl
->handle
, CURLOPT_INFILESIZE
, body_size
);
2336 curl_easy_setopt(curl
->handle
, CURLOPT_POSTFIELDSIZE
, body_size
);
2337 curl_easy_setopt(curl
->handle
, CURLOPT_POST
, 1L);
2339 curl_easy_setopt(curl
->handle
, CURLOPT_SEEKDATA
, NULL
);
2340 curl_easy_setopt(curl
->handle
, CURLOPT_READDATA
, NULL
);
2341 curl_easy_setopt(curl
->handle
, CURLOPT_INFILESIZE
, 0L);
2342 curl_easy_setopt(curl
->handle
, CURLOPT_POSTFIELDSIZE
, 0L);
2346 * Always use CUSTOMREQUEST, else curl won't send any request body for GET etc.
2347 * See e.g. bug #69313.
2349 * Here's what curl does:
2350 * - CURLOPT_HTTPGET: ignore request body
2351 * - CURLOPT_UPLOAD: set "Expect: 100-continue" header
2352 * - CURLOPT_POST: set "Content-Type: application/x-www-form-urlencoded" header
2353 * Now select the least bad.
2355 * See also https://tools.ietf.org/html/rfc7231#section-5.1.1
2357 if (PHP_HTTP_INFO(msg
).request
.method
) {
2358 switch(php_http_select_str(PHP_HTTP_INFO(msg
).request
.method
, 2, "HEAD", "PUT")) {
2360 curl_easy_setopt(curl
->handle
, CURLOPT_NOBODY
, 1L);
2363 curl_easy_setopt(curl
->handle
, CURLOPT_UPLOAD
, 1L);
2366 curl_easy_setopt(curl
->handle
, CURLOPT_CUSTOMREQUEST
, PHP_HTTP_INFO(msg
).request
.method
);
2369 php_error_docref(NULL
, E_WARNING
, "Cannot use empty request method");
2376 static void php_http_client_curl_handler_clear(php_http_client_curl_handler_t
*handler
)
2378 curl_easy_setopt(handler
->handle
, CURLOPT_NOPROGRESS
, 1L);
2379 #if PHP_HTTP_CURL_VERSION(7,32,0)
2380 curl_easy_setopt(handler
->handle
, CURLOPT_XFERINFOFUNCTION
, NULL
);
2382 curl_easy_setopt(handler
->handle
, CURLOPT_PROGRESSFUNCTION
, NULL
);
2384 curl_easy_setopt(handler
->handle
, CURLOPT_VERBOSE
, 0L);
2385 curl_easy_setopt(handler
->handle
, CURLOPT_DEBUGFUNCTION
, NULL
);
2386 /* see gh issue #84 */
2388 fprintf(stderr
, "CURLOPT_COOKIELIST: FLUSH\n");
2389 fprintf(stderr
, "CURLOPT_SHARE: (null)\n");
2391 curl_easy_setopt(handler
->handle
, CURLOPT_COOKIELIST
, "FLUSH");
2392 curl_easy_setopt(handler
->handle
, CURLOPT_SHARE
, NULL
);
2393 #if PHP_HTTP_CURL_VERSION(7,63,0) && !PHP_HTTP_CURL_VERSION(7,65,0)
2395 php_http_curle_storage_t
*st
= php_http_curle_get_storage(handler
->handle
);
2396 curl_easy_setopt(handler
->handle
, CURLOPT_COOKIEJAR
, st
? st
->cookiestore
: NULL
);
2401 static void php_http_client_curl_handler_dtor(php_http_client_curl_handler_t
*handler
)
2403 php_http_client_curl_handler_clear(handler
);
2405 php_resource_factory_handle_dtor(handler
->rf
, handler
->handle
);
2406 php_resource_factory_free(&handler
->rf
);
2408 php_http_message_body_free(&handler
->response
.body
);
2409 php_http_buffer_dtor(&handler
->response
.headers
);
2410 php_http_buffer_dtor(&handler
->options
.ranges
);
2411 php_http_buffer_dtor(&handler
->options
.cookies
);
2412 zend_hash_destroy(&handler
->options
.cache
);
2414 #if PHP_HTTP_CURL_VERSION(7,21,3)
2415 if (handler
->options
.resolve
) {
2416 curl_slist_free_all(handler
->options
.resolve
);
2417 handler
->options
.resolve
= NULL
;
2421 if (handler
->options
.headers
) {
2422 curl_slist_free_all(handler
->options
.headers
);
2423 handler
->options
.headers
= NULL
;
2426 if (handler
->options
.proxyheaders
) {
2427 curl_slist_free_all(handler
->options
.proxyheaders
);
2428 handler
->options
.proxyheaders
= NULL
;
2434 static php_http_client_t
*php_http_client_curl_init(php_http_client_t
*h
, void *handle
)
2436 php_http_client_curl_t
*curl
;
2438 if (!handle
&& !(handle
= php_resource_factory_handle_ctor(h
->rf
, NULL
))) {
2439 php_error_docref(NULL
, E_WARNING
, "Failed to initialize curl handle");
2443 curl
= ecalloc(1, sizeof(*curl
));
2444 curl
->handle
= handle
;
2445 curl
->unfinished
= 0;
2451 static void php_http_client_curl_dtor(php_http_client_t
*h
)
2453 php_http_client_curl_t
*curl
= h
->ctx
;
2456 curl
->ev_ops
->dtor(&curl
->ev_ctx
);
2457 curl
->ev_ops
= NULL
;
2459 curl
->unfinished
= 0;
2461 php_resource_factory_handle_dtor(h
->rf
, curl
->handle
);
2467 static void queue_dtor(php_http_client_enqueue_t
*e
)
2469 php_http_client_curl_handler_t
*handler
= e
->opaque
;
2471 if (handler
->queue
.dtor
) {
2472 e
->opaque
= handler
->queue
.opaque
;
2473 handler
->queue
.dtor(e
);
2475 php_http_client_curl_handler_dtor(handler
);
2478 static void retire_ch(php_persistent_handle_factory_t
*f
, void **handle
)
2481 /* erase all cookies */
2483 curl_easy_reset(ch
);
2484 curl_easy_setopt(ch
, CURLOPT_COOKIELIST
, "ALL");
2485 curl_easy_setopt(ch
, CURLOPT_COOKIEFILE
, NULL
);
2489 static php_resource_factory_t
*create_rf(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2491 php_persistent_handle_factory_t
*pf
= NULL
;
2492 php_resource_factory_t
*rf
= NULL
;
2493 php_http_url_t
*url
= enqueue
->request
->http
.info
.request
.url
;
2495 if (!url
|| (!url
->host
&& !url
->path
)) {
2496 php_error_docref(NULL
, E_WARNING
, "Cannot request empty URL");
2500 /* only if the client itself is setup for persistence */
2501 if (php_resource_factory_is_persistent(h
->rf
)) {
2503 char *id_str
= NULL
;
2505 int port
= url
->port
? url
->port
: 80;
2507 php_persistent_handle_factory_t
*phf
= h
->rf
->data
;
2509 if ((zport
= zend_hash_str_find(enqueue
->options
, ZEND_STRL("port")))) {
2510 zend_long lport
= zval_get_long(zport
);
2517 id_len
= spprintf(&id_str
, 0, "%.*s:%s:%d", (int) phf
->ident
->len
, phf
->ident
->val
, STR_PTR(url
->host
), port
);
2518 id
= php_http_cs2zs(id_str
, id_len
);
2519 pf
= php_persistent_handle_concede(NULL
, PHP_HTTP_G
->client
.curl
.driver
.request_name
, id
, NULL
, retire_ch
);
2520 zend_string_release(id
);
2524 rf
= php_persistent_handle_resource_factory_init(NULL
, pf
);
2526 rf
= php_resource_factory_init(NULL
, &php_http_curle_resource_factory_ops
, NULL
, NULL
);
2532 static ZEND_RESULT_CODE
php_http_client_curl_enqueue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2535 php_http_client_curl_t
*curl
= h
->ctx
;
2536 php_http_client_curl_handler_t
*handler
;
2537 php_http_client_progress_state_t
*progress
;
2538 php_resource_factory_t
*rf
;
2540 rf
= create_rf(h
, enqueue
);
2545 handler
= php_http_client_curl_handler_init(h
, rf
);
2550 if (SUCCESS
!= php_http_client_curl_handler_prepare(handler
, enqueue
)) {
2551 php_http_client_curl_handler_dtor(handler
);
2555 handler
->queue
= *enqueue
;
2556 enqueue
->opaque
= handler
;
2557 enqueue
->dtor
= queue_dtor
;
2559 if (CURLM_OK
!= (rs
= curl_multi_add_handle(curl
->handle
->multi
, handler
->handle
))) {
2560 php_http_client_curl_handler_dtor(handler
);
2561 php_error_docref(NULL
, E_WARNING
, "Could not enqueue request: %s", curl_multi_strerror(rs
));
2565 zend_llist_add_element(&h
->requests
, enqueue
);
2568 if (h
->callback
.progress
.func
&& SUCCESS
== php_http_client_getopt(h
, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
, enqueue
->request
, &progress
)) {
2569 progress
->info
= "start";
2570 h
->callback
.progress
.func(h
->callback
.progress
.arg
, h
, &handler
->queue
, progress
);
2571 progress
->started
= 1;
2577 static ZEND_RESULT_CODE
php_http_client_curl_requeue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2580 php_http_client_curl_t
*curl
= h
->ctx
;
2581 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2582 php_http_client_progress_state_t
*progress
;
2584 if (SUCCESS
!= php_http_client_curl_handler_reset(handler
)) {
2588 if (SUCCESS
!= php_http_client_curl_handler_prepare(handler
, enqueue
)) {
2592 if (CURLM_OK
!= (rs
= curl_multi_remove_handle(curl
->handle
->multi
, handler
->handle
))) {
2593 php_error_docref(NULL
, E_WARNING
, "Could not dequeue request: %s", curl_multi_strerror(rs
));
2597 if (CURLM_OK
!= (rs
= curl_multi_add_handle(curl
->handle
->multi
, handler
->handle
))) {
2598 zend_llist_del_element(&h
->requests
, handler
->handle
, (int (*)(void *, void *)) compare_queue
);
2599 php_error_docref(NULL
, E_WARNING
, "Could not enqueue request: %s", curl_multi_strerror(rs
));
2605 if (h
->callback
.progress
.func
&& SUCCESS
== php_http_client_getopt(h
, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
, enqueue
->request
, &progress
)) {
2606 progress
->info
= "start";
2607 h
->callback
.progress
.func(h
->callback
.progress
.arg
, h
, &handler
->queue
, progress
);
2608 progress
->started
= 1;
2614 static ZEND_RESULT_CODE
php_http_client_curl_dequeue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2617 php_http_client_curl_t
*curl
= h
->ctx
;
2618 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2620 if (h
->callback
.depth
&& !CG(unclean_shutdown
)) {
2621 php_error_docref(NULL
, E_WARNING
, "Could not dequeue request while executing callbacks");
2625 php_http_client_curl_handler_clear(handler
);
2626 if (CURLM_OK
== (rs
= curl_multi_remove_handle(curl
->handle
->multi
, handler
->handle
))) {
2627 zend_llist_del_element(&h
->requests
, handler
->handle
, (int (*)(void *, void *)) compare_queue
);
2630 php_error_docref(NULL
, E_WARNING
, "Could not dequeue request: %s", curl_multi_strerror(rs
));
2636 static void php_http_client_curl_reset(php_http_client_t
*h
)
2638 zend_llist_element
*next_el
, *this_el
;
2640 for (this_el
= h
->requests
.head
; this_el
; this_el
= next_el
) {
2641 next_el
= this_el
->next
;
2642 php_http_client_curl_dequeue(h
, (void *) this_el
->data
);
2647 # define SELECT_ERROR SOCKET_ERROR
2649 # define SELECT_ERROR -1
2652 static ZEND_RESULT_CODE
php_http_client_curl_wait(php_http_client_t
*h
, struct timeval
*custom_timeout
)
2656 struct timeval timeout
;
2657 php_http_client_curl_t
*curl
= h
->ctx
;
2660 return curl
->ev_ops
->wait(curl
->ev_ctx
, custom_timeout
);
2667 if (CURLM_OK
== curl_multi_fdset(curl
->handle
->multi
, &R
, &W
, &E
, &MAX
)) {
2668 if (custom_timeout
&& timerisset(custom_timeout
)) {
2669 timeout
= *custom_timeout
;
2671 php_http_client_curl_get_timeout(curl
, 1000, &timeout
);
2675 php_http_sleep((double) timeout
.tv_sec
+ (double) (timeout
.tv_usec
/ PHP_HTTP_MCROSEC
));
2677 } else if (SELECT_ERROR
!= select(MAX
+ 1, &R
, &W
, &E
, &timeout
)) {
2684 static int php_http_client_curl_once(php_http_client_t
*h
)
2686 php_http_client_curl_t
*curl
= h
->ctx
;
2688 if (!h
->callback
.depth
) {
2690 curl
->ev_ops
->once(curl
->ev_ctx
);
2692 while (CURLM_CALL_MULTI_PERFORM
== curl_multi_perform(curl
->handle
->multi
, &curl
->unfinished
));
2695 php_http_client_curl_responsehandler(h
);
2698 return curl
->unfinished
;
2701 static ZEND_RESULT_CODE
php_http_client_curl_exec(php_http_client_t
*h
)
2703 php_http_client_curl_t
*curl
= h
->ctx
;
2705 if (!h
->callback
.depth
) {
2707 return curl
->ev_ops
->exec(curl
->ev_ctx
);
2710 while (php_http_client_curl_once(h
) && !EG(exception
)) {
2711 if (SUCCESS
!= php_http_client_curl_wait(h
, NULL
)) {
2713 /* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */
2714 php_error_docref(NULL
, E_WARNING
, "WinSock error: %d", WSAGetLastError());
2716 php_error_docref(NULL
, E_WARNING
, "%s", strerror(errno
));
2726 static ZEND_RESULT_CODE
php_http_client_curl_setopt(php_http_client_t
*h
, php_http_client_setopt_opt_t opt
, void *arg
)
2728 php_http_client_curl_t
*curl
= h
->ctx
;
2733 case PHP_HTTP_CLIENT_OPT_CONFIGURATION
:
2734 return php_http_options_apply(&php_http_curlm_options
, (HashTable
*) arg
, h
);
2736 #if !PHP_HTTP_CURL_VERSION(7,62,0)
2737 case PHP_HTTP_CLIENT_OPT_ENABLE_PIPELINING
:
2738 if (CURLM_OK
!= curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_PIPELINING
, (long) *((zend_bool
*) arg
))) {
2743 case PHP_HTTP_CLIENT_OPT_USE_EVENTS
:
2744 #if PHP_HTTP_HAVE_LIBEVENT
2745 return php_http_curlm_use_eventloop(h
, (*(zend_bool
*) arg
)
2746 ? php_http_client_curl_event_ops_get()
2757 static int apply_available_options(zval
*pDest
, int num_args
, va_list args
, zend_hash_key
*hash_key
)
2759 php_http_option_t
*opt
= Z_PTR_P(pDest
);
2764 ht
= va_arg(args
, HashTable
*);
2766 if ((c
= zend_hash_num_elements(&opt
->suboptions
.options
))) {
2767 array_init_size(&entry
, c
);
2768 zend_hash_apply_with_arguments(&opt
->suboptions
.options
, apply_available_options
, 1, Z_ARRVAL(entry
));
2770 /* catch deliberate NULL options */
2771 if (Z_TYPE(opt
->defval
) == IS_STRING
&& !Z_STRVAL(opt
->defval
)) {
2774 ZVAL_ZVAL(&entry
, &opt
->defval
, 1, 0);
2778 if (hash_key
->key
) {
2779 zend_hash_update(ht
, hash_key
->key
, &entry
);
2781 zend_hash_index_update(ht
, hash_key
->h
, &entry
);
2784 return ZEND_HASH_APPLY_KEEP
;
2787 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
)
2789 php_http_client_enqueue_t
*enqueue
;
2792 case PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
:
2793 if ((enqueue
= php_http_client_enqueued(h
, arg
, NULL
))) {
2794 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2796 *((php_http_client_progress_state_t
**) res
) = &handler
->progress
;
2801 case PHP_HTTP_CLIENT_OPT_TRANSFER_INFO
:
2802 if ((enqueue
= php_http_client_enqueued(h
, arg
, NULL
))) {
2803 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2805 php_http_curle_get_info(handler
->handle
, *(HashTable
**) res
);
2810 case PHP_HTTP_CLIENT_OPT_AVAILABLE_OPTIONS
:
2811 zend_hash_apply_with_arguments(&php_http_curle_options
.options
, apply_available_options
, 1, *(HashTable
**) res
);
2814 case PHP_HTTP_CLIENT_OPT_AVAILABLE_CONFIGURATION
:
2815 zend_hash_apply_with_arguments(&php_http_curlm_options
.options
, apply_available_options
, 1, *(HashTable
**) res
);
2825 static php_http_client_ops_t php_http_client_curl_ops
= {
2826 &php_http_curlm_resource_factory_ops
,
2827 php_http_client_curl_init
,
2829 php_http_client_curl_dtor
,
2830 php_http_client_curl_reset
,
2831 php_http_client_curl_exec
,
2832 php_http_client_curl_wait
,
2833 php_http_client_curl_once
,
2834 php_http_client_curl_enqueue
,
2835 php_http_client_curl_dequeue
,
2836 php_http_client_curl_requeue
,
2837 php_http_client_curl_setopt
,
2838 php_http_client_curl_getopt
2841 php_http_client_ops_t
*php_http_client_curl_get_ops(void)
2843 return &php_http_client_curl_ops
;
2846 #define REGISTER_NS_STRING_OR_NULL_CONSTANT(ns, name, str, flags) \
2848 if ((str) != NULL) { \
2849 REGISTER_NS_STRING_CONSTANT(ns, name, str, flags); \
2851 REGISTER_NS_NULL_CONSTANT(ns, name, flags); \
2855 PHP_MINIT_FUNCTION(http_client_curl
)
2857 curl_version_info_data
*info
;
2858 php_http_options_t
*options
;
2860 PHP_HTTP_G
->client
.curl
.driver
.driver_name
= zend_string_init(ZEND_STRL("curl"), 1);
2861 PHP_HTTP_G
->client
.curl
.driver
.client_name
= zend_string_init(ZEND_STRL("http\\Client\\Curl"), 1);
2862 PHP_HTTP_G
->client
.curl
.driver
.request_name
= zend_string_init(ZEND_STRL("http\\Client\\Curl\\Request"), 1);
2863 PHP_HTTP_G
->client
.curl
.driver
.client_ops
= &php_http_client_curl_ops
;
2865 if (SUCCESS
!= php_http_client_driver_add(&PHP_HTTP_G
->client
.curl
.driver
)) {
2869 if (SUCCESS
!= php_persistent_handle_provide(PHP_HTTP_G
->client
.curl
.driver
.client_name
, &php_http_curlm_resource_factory_ops
, NULL
, NULL
)) {
2872 if (SUCCESS
!= php_persistent_handle_provide(PHP_HTTP_G
->client
.curl
.driver
.request_name
, &php_http_curle_resource_factory_ops
, NULL
, NULL
)) {
2876 if ((options
= php_http_options_init(&php_http_curle_options
, 1))) {
2877 options
->getter
= php_http_curle_get_option
;
2878 options
->setter
= php_http_curle_set_option
;
2880 php_http_curle_options_init(options
);
2882 if ((options
= php_http_options_init(&php_http_curlm_options
, 1))) {
2883 options
->getter
= php_http_option_get
;
2884 options
->setter
= php_http_curlm_set_option
;
2886 php_http_curlm_options_init(options
);
2889 if ((info
= curl_version_info(CURLVERSION_NOW
))) {
2890 char tmp_ver
[0x20], *tmp_ptr
, *tmp_end
;
2891 #define tmp_ver_init() do {\
2893 tmp_ptr = &tmp_ver[0]; \
2894 tmp_end = &tmp_ver[sizeof(tmp_ver) - 1]; \
2900 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "FEATURES", info
->features
, CONST_CS
|CONST_PERSISTENT
);
2902 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "IPV6", CURL_VERSION_IPV6
, CONST_CS
|CONST_PERSISTENT
);
2903 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "KERBEROS4", CURL_VERSION_KERBEROS4
, CONST_CS
|CONST_PERSISTENT
);
2904 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SSL", CURL_VERSION_SSL
, CONST_CS
|CONST_PERSISTENT
);
2905 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "LIBZ", CURL_VERSION_LIBZ
, CONST_CS
|CONST_PERSISTENT
);
2906 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "NTLM", CURL_VERSION_NTLM
, CONST_CS
|CONST_PERSISTENT
);
2907 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "GSSNEGOTIATE", CURL_VERSION_GSSNEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2908 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ASYNCHDNS", CURL_VERSION_ASYNCHDNS
, CONST_CS
|CONST_PERSISTENT
);
2909 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SPNEGO", CURL_VERSION_SPNEGO
, CONST_CS
|CONST_PERSISTENT
);
2910 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "LARGEFILE", CURL_VERSION_LARGEFILE
, CONST_CS
|CONST_PERSISTENT
);
2911 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "IDN", CURL_VERSION_IDN
, CONST_CS
|CONST_PERSISTENT
);
2912 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SSPI", CURL_VERSION_SSPI
, CONST_CS
|CONST_PERSISTENT
);
2913 #if PHP_HTTP_CURL_VERSION(7,21,4)
2914 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "TLSAUTH_SRP", CURL_VERSION_TLSAUTH_SRP
, CONST_CS
|CONST_PERSISTENT
);
2916 #if PHP_HTTP_CURL_VERSION(7,22,0)
2917 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "NTLM_WB", CURL_VERSION_NTLM_WB
, CONST_CS
|CONST_PERSISTENT
);
2919 #if PHP_HTTP_CURL_VERSION(7,33,0)
2920 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTP2", CURL_VERSION_HTTP2
, CONST_CS
|CONST_PERSISTENT
);
2922 #if PHP_HTTP_CURL_VERSION(7,38,0)
2923 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "GSSAPI", CURL_VERSION_GSSAPI
, CONST_CS
|CONST_PERSISTENT
);
2925 #if PHP_HTTP_CURL_VERSION(7,40,0)
2926 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "KERBEROS5", CURL_VERSION_KERBEROS5
, CONST_CS
|CONST_PERSISTENT
);
2927 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "UNIX_SOCKETS", CURL_VERSION_UNIX_SOCKETS
, CONST_CS
|CONST_PERSISTENT
);
2929 #if PHP_HTTP_CURL_VERSION(7,47,0)
2930 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "PSL", CURL_VERSION_PSL
, CONST_CS
|CONST_PERSISTENT
);
2932 #if PHP_HTTP_CURL_VERSION(7,52,0)
2933 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTPS_PROXY", CURL_VERSION_HTTPS_PROXY
, CONST_CS
|CONST_PERSISTENT
);
2935 #if PHP_HTTP_CURL_VERSION(7,56,0)
2936 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "MULTI_SSL", CURL_VERSION_MULTI_SSL
, CONST_CS
|CONST_PERSISTENT
);
2938 #if PHP_HTTP_CURL_VERSION(7,57,0)
2939 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "BROTLI", CURL_VERSION_BROTLI
, CONST_CS
|CONST_PERSISTENT
);
2941 #if PHP_HTTP_CURL_VERSION(7,64,1)
2942 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ALTSVC", CURL_VERSION_ALTSVC
, CONST_CS
|CONST_PERSISTENT
);
2944 #if PHP_HTTP_CURL_VERSION(7,66,0)
2945 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTP3", CURL_VERSION_HTTP3
, CONST_CS
|CONST_PERSISTENT
);
2947 #if PHP_HTTP_CURL_VERSION(7,72,0)
2948 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ZSTD", CURL_VERSION_ZSTD
, CONST_CS
|CONST_PERSISTENT
);
2949 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "UNICODE", CURL_VERSION_UNICODE
, CONST_CS
|CONST_PERSISTENT
);
2951 #if PHP_HTTP_CURL_VERSION(7,74,0)
2952 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HSTS", CURL_VERSION_HSTS
, CONST_CS
|CONST_PERSISTENT
);
2959 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl", "VERSIONS", curl_version(), CONST_CS
|CONST_PERSISTENT
);
2960 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "CURL", info
->version
, CONST_CS
|CONST_PERSISTENT
);
2961 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "SSL", info
->ssl_version
, CONST_CS
|CONST_PERSISTENT
);
2962 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "LIBZ", info
->libz_version
, CONST_CS
|CONST_PERSISTENT
);
2963 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ARES", info
->ares
, CONST_CS
|CONST_PERSISTENT
);
2964 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "IDN", info
->libidn
, CONST_CS
|CONST_PERSISTENT
);
2966 if (info
->iconv_ver_num
) {
2967 tmp_ptr
= zend_print_ulong_to_buf(tmp_end
, info
->iconv_ver_num
& 0xf);
2968 tmp_end
= tmp_ptr
- 1;
2969 tmp_ptr
= zend_print_ulong_to_buf(tmp_end
, info
->iconv_ver_num
>> 8);
2972 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ICONV", *tmp_ptr
? tmp_ptr
: NULL
, CONST_CS
|CONST_PERSISTENT
);
2973 #if PHP_HTTP_CURL_VERSION(7,57,0)
2974 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "BROTLI", info
->brotli_version
, CONST_CS
|CONST_PERSISTENT
);
2976 #if PHP_HTTP_CURL_VERSION(7,66,0)
2977 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "NGHTTP2", info
->nghttp2_version
, CONST_CS
|CONST_PERSISTENT
);
2978 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "QUIC", info
->quic_version
, CONST_CS
|CONST_PERSISTENT
);
2980 #if PHP_HTTP_CURL_VERSION(7,70,0)
2981 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "CAINFO", info
->cainfo
, CONST_CS
|CONST_PERSISTENT
);
2982 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "CAPATH", info
->capath
, CONST_CS
|CONST_PERSISTENT
);
2984 #if PHP_HTTP_CURL_VERSION(7,72,0)
2985 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ZSTD", info
->zstd_version
, CONST_CS
|CONST_PERSISTENT
);
2987 #if PHP_HTTP_CURL_VERSION(7,75,0)
2988 REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "HYPER", info
->hyper_version
, CONST_CS
|CONST_PERSISTENT
);
2994 * HTTP Protocol Version Constants
2996 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_1_0", CURL_HTTP_VERSION_1_0
, CONST_CS
|CONST_PERSISTENT
);
2997 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_1_1", CURL_HTTP_VERSION_1_1
, CONST_CS
|CONST_PERSISTENT
);
2998 #if PHP_HTTP_CURL_VERSION(7,33,0)
2999 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2_0", CURL_HTTP_VERSION_2_0
, CONST_CS
|CONST_PERSISTENT
);
3001 #if PHP_HTTP_CURL_VERSION(7,47,0)
3002 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2TLS", CURL_HTTP_VERSION_2TLS
, CONST_CS
|CONST_PERSISTENT
);
3004 #if PHP_HTTP_CURL_VERSION(7,49,0)
3005 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2_PRIOR_KNOWLEDGE", CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE
, CONST_CS
|CONST_PERSISTENT
);
3007 #if PHP_HTTP_CURL_VERSION(7,66,0)
3008 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_3", CURL_HTTP_VERSION_3
, CONST_CS
|CONST_PERSISTENT
);
3010 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_ANY", CURL_HTTP_VERSION_NONE
, CONST_CS
|CONST_PERSISTENT
);
3013 * SSL Version Constants
3015 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1", CURL_SSLVERSION_TLSv1
, CONST_CS
|CONST_PERSISTENT
);
3016 #if PHP_HTTP_CURL_VERSION(7,34,0)
3017 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_0", CURL_SSLVERSION_TLSv1_0
, CONST_CS
|CONST_PERSISTENT
);
3018 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_1", CURL_SSLVERSION_TLSv1_1
, CONST_CS
|CONST_PERSISTENT
);
3019 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_2", CURL_SSLVERSION_TLSv1_2
, CONST_CS
|CONST_PERSISTENT
);
3021 #if PHP_HTTP_CURL_VERSION(7,52,0)
3022 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_3", CURL_SSLVERSION_TLSv1_3
, CONST_CS
|CONST_PERSISTENT
);
3024 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv2", CURL_SSLVERSION_SSLv2
, CONST_CS
|CONST_PERSISTENT
);
3025 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv3", CURL_SSLVERSION_SSLv3
, CONST_CS
|CONST_PERSISTENT
);
3026 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_ANY", CURL_SSLVERSION_DEFAULT
, CONST_CS
|CONST_PERSISTENT
);
3027 #if PHP_HTTP_CURL_VERSION(7,21,4) && PHP_HTTP_HAVE_LIBCURL_TLSAUTH_TYPE
3028 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "TLSAUTH_SRP", CURL_TLSAUTH_SRP
, CONST_CS
|CONST_PERSISTENT
);
3031 #if PHP_HTTP_CURL_VERSION(7,54,0)
3032 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_DEFAULT", CURL_SSLVERSION_MAX_DEFAULT
, CONST_CS
|CONST_PERSISTENT
);
3033 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_0", CURL_SSLVERSION_MAX_TLSv1_0
, CONST_CS
|CONST_PERSISTENT
);
3034 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_1", CURL_SSLVERSION_MAX_TLSv1_1
, CONST_CS
|CONST_PERSISTENT
);
3035 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_2", CURL_SSLVERSION_MAX_TLSv1_2
, CONST_CS
|CONST_PERSISTENT
);
3036 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_MAX_TLSv1_3", CURL_SSLVERSION_MAX_TLSv1_3
, CONST_CS
|CONST_PERSISTENT
);
3040 * DNS IPvX resolving
3042 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_V4", CURL_IPRESOLVE_V4
, CONST_CS
|CONST_PERSISTENT
);
3043 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_V6", CURL_IPRESOLVE_V6
, CONST_CS
|CONST_PERSISTENT
);
3044 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_ANY", CURL_IPRESOLVE_WHATEVER
, CONST_CS
|CONST_PERSISTENT
);
3049 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_NONE", CURLAUTH_NONE
, CONST_CS
|CONST_PERSISTENT
);
3050 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_BASIC", CURLAUTH_BASIC
, CONST_CS
|CONST_PERSISTENT
);
3051 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_DIGEST", CURLAUTH_DIGEST
, CONST_CS
|CONST_PERSISTENT
);
3052 #if PHP_HTTP_CURL_VERSION(7,19,3)
3053 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_DIGEST_IE", CURLAUTH_DIGEST_IE
, CONST_CS
|CONST_PERSISTENT
);
3055 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_NTLM", CURLAUTH_NTLM
, CONST_CS
|CONST_PERSISTENT
);
3056 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_GSSNEG", CURLAUTH_GSSNEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
3057 #if PHP_HTTP_CURL_VERSION(7,38,0)
3058 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_SPNEGO", CURLAUTH_NEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
3060 #if PHP_HTTP_CURL_VERSION(7,61,0)
3061 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_BEARER", CURLAUTH_BEARER
, CONST_CS
|CONST_PERSISTENT
);
3063 #if PHP_HTTP_CURL_VERSION(7,75,0)
3064 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AWS_SIGV4", CURLAUTH_AWS_SIGV4
, CONST_CS
|CONST_PERSISTENT
);
3066 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_ANY", CURLAUTH_ANY
, CONST_CS
|CONST_PERSISTENT
);
3069 * Proxy Type Constants
3071 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS4", CURLPROXY_SOCKS4
, CONST_CS
|CONST_PERSISTENT
);
3072 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS4A", CURLPROXY_SOCKS4A
, CONST_CS
|CONST_PERSISTENT
);
3073 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS5_HOSTNAME", CURLPROXY_SOCKS5_HOSTNAME
, CONST_CS
|CONST_PERSISTENT
);
3074 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS5", CURLPROXY_SOCKS5
, CONST_CS
|CONST_PERSISTENT
);
3075 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_HTTP", CURLPROXY_HTTP
, CONST_CS
|CONST_PERSISTENT
);
3076 #if PHP_HTTP_CURL_VERSION(7,19,4)
3077 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_HTTP_1_0", CURLPROXY_HTTP_1_0
, CONST_CS
|CONST_PERSISTENT
);
3081 * Post Redirection Constants
3083 #if PHP_HTTP_CURL_VERSION(7,19,1)
3084 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_301", CURL_REDIR_POST_301
, CONST_CS
|CONST_PERSISTENT
);
3085 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_302", CURL_REDIR_POST_302
, CONST_CS
|CONST_PERSISTENT
);
3086 #if PHP_HTTP_CURL_VERSION(7,26,0)
3087 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_303", CURL_REDIR_POST_303
, CONST_CS
|CONST_PERSISTENT
);
3089 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_ALL", CURL_REDIR_POST_ALL
, CONST_CS
|CONST_PERSISTENT
);
3092 #if PHP_HTTP_CURL_VERSION(7,64,1)
3093 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_READONLYFILE", CURLALTSVC_READONLYFILE
, CONST_CS
|CONST_PERSISTENT
);
3094 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_H1", CURLALTSVC_H1
, CONST_CS
|CONST_PERSISTENT
);
3095 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_H2", CURLALTSVC_H2
, CONST_CS
|CONST_PERSISTENT
);
3096 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "ALTSVC_H3", CURLALTSVC_H3
, CONST_CS
|CONST_PERSISTENT
);
3098 #if PHP_HTTP_CURL_VERSION(7,74,0)
3099 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HSTS_ENABLE", CURLHSTS_ENABLE
, CONST_CS
|CONST_PERSISTENT
);
3100 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HSTS_READONLYFILE", CURLHSTS_READONLYFILE
, CONST_CS
|CONST_PERSISTENT
);
3105 PHP_MSHUTDOWN_FUNCTION(http_client_curl
)
3107 php_persistent_handle_cleanup(PHP_HTTP_G
->client
.curl
.driver
.client_name
, NULL
);
3108 php_persistent_handle_cleanup(PHP_HTTP_G
->client
.curl
.driver
.request_name
, NULL
);
3109 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.client_name
);
3110 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.request_name
);
3111 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.driver_name
);
3113 php_http_options_dtor(&php_http_curle_options
);
3114 php_http_options_dtor(&php_http_curlm_options
);
3119 #endif /* PHP_HTTP_HAVE_LIBCURL */
3126 * vim600: noet sw=4 ts=4 fdm=marker
3127 * vim<600: noet sw=4 ts=4