2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
14 #include "php_http_client.h"
16 #if PHP_HTTP_HAVE_CURL
18 #if PHP_HTTP_HAVE_EVENT
19 # if !PHP_HTTP_HAVE_EVENT2 && /* just be really sure */ !(LIBEVENT_VERSION_NUMBER >= 0x02000000)
21 # define event_base_new event_init
22 # define event_assign(e, b, s, a, cb, d) do {\
23 event_set(e, s, a, cb, d); \
24 event_base_set(b, e); \
27 # if PHP_HTTP_HAVE_EVENT2
28 # include <event2/event.h>
29 # include <event2/event_struct.h>
31 # error "libevent presence is unknown"
39 #ifdef PHP_HTTP_HAVE_OPENSSL
40 # include <openssl/ssl.h>
42 #ifdef PHP_HTTP_HAVE_GNUTLS
46 typedef struct php_http_client_curl_handle
{
49 } php_http_client_curl_handle_t
;
51 typedef struct php_http_client_curl
{
52 php_http_client_curl_handle_t
*handle
;
54 int unfinished
; /* int because of curl_multi_perform() */
56 #if PHP_HTTP_HAVE_EVENT
57 struct event_base
*evbase
;
58 struct event
*timeout
;
61 } php_http_client_curl_t
;
63 typedef struct php_http_client_curl_handler
{
65 php_resource_factory_t
*rf
;
66 php_http_client_t
*client
;
67 php_http_client_progress_state_t progress
;
68 php_http_client_enqueue_t queue
;
71 php_http_buffer_t headers
;
72 php_http_message_body_t
*body
;
78 struct curl_slist
*proxyheaders
;
79 struct curl_slist
*headers
;
80 struct curl_slist
*resolve
;
81 php_http_buffer_t cookies
;
82 php_http_buffer_t ranges
;
90 unsigned range_request
:1;
91 unsigned encode_cookies
:1;
95 } php_http_client_curl_handler_t
;
97 typedef struct php_http_curle_storage
{
101 char errorbuffer
[0x100];
102 } php_http_curle_storage_t
;
104 static inline php_http_curle_storage_t
*php_http_curle_get_storage(CURL
*ch
) {
105 php_http_curle_storage_t
*st
= NULL
;
107 curl_easy_getinfo(ch
, CURLINFO_PRIVATE
, &st
);
110 st
= pecalloc(1, sizeof(*st
), 1);
111 curl_easy_setopt(ch
, CURLOPT_PRIVATE
, st
);
112 curl_easy_setopt(ch
, CURLOPT_ERRORBUFFER
, st
->errorbuffer
);
118 static void *php_http_curle_ctor(void *opaque
, void *init_arg
)
122 if ((ch
= curl_easy_init())) {
123 php_http_curle_get_storage(ch
);
129 static void *php_http_curle_copy(void *opaque
, void *handle
)
133 if ((ch
= curl_easy_duphandle(handle
))) {
135 php_http_curle_get_storage(ch
);
141 static void php_http_curle_dtor(void *opaque
, void *handle
)
143 php_http_curle_storage_t
*st
= php_http_curle_get_storage(handle
);
145 curl_easy_cleanup(handle
);
151 if (st
->cookiestore
) {
152 pefree(st
->cookiestore
, 1);
158 static php_resource_factory_ops_t php_http_curle_resource_factory_ops
= {
164 static void *php_http_curlm_ctor(void *opaque
, void *init_arg
)
166 php_http_client_curl_handle_t
*curl
= calloc(1, sizeof(*curl
));
168 if (!(curl
->multi
= curl_multi_init())) {
172 if (!(curl
->share
= curl_share_init())) {
173 curl_multi_cleanup(curl
->multi
);
177 curl_share_setopt(curl
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_COOKIE
);
178 curl_share_setopt(curl
->share
, CURLSHOPT_SHARE
, CURL_LOCK_DATA_SSL_SESSION
);
182 static void php_http_curlm_dtor(void *opaque
, void *handle
)
184 php_http_client_curl_handle_t
*curl
= handle
;
186 curl_share_cleanup(curl
->share
);
187 curl_multi_cleanup(curl
->multi
);
191 static php_resource_factory_ops_t php_http_curlm_resource_factory_ops
= {
199 static size_t php_http_curle_read_callback(void *data
, size_t len
, size_t n
, void *ctx
)
201 php_http_message_body_t
*body
= ctx
;
203 if (body
&& body
->res
) {
204 php_stream
*s
= php_http_message_body_stream(body
);
207 return php_stream_read(s
, data
, len
* n
);
213 #if PHP_HTTP_CURL_VERSION(7,32,0)
214 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
)
216 static int php_http_curle_progress_callback(void *ctx
, double dltotal
, double dlnow
, double ultotal
, double ulnow
)
219 php_http_client_curl_handler_t
*h
= ctx
;
220 zend_bool update
= 0;
222 if (h
->progress
.dl
.total
!= dltotal
223 || h
->progress
.dl
.now
!= dlnow
224 || h
->progress
.ul
.total
!= ultotal
225 || h
->progress
.ul
.now
!= ulnow
229 h
->progress
.dl
.total
= dltotal
;
230 h
->progress
.dl
.now
= dlnow
;
231 h
->progress
.ul
.total
= ultotal
;
232 h
->progress
.ul
.now
= ulnow
;
235 if (update
&& h
->client
->callback
.progress
.func
) {
236 h
->client
->callback
.progress
.func(h
->client
->callback
.progress
.arg
, h
->client
, &h
->queue
, &h
->progress
);
242 static int php_http_curle_seek_callback(void *userdata
, curl_off_t offset
, int origin
)
244 php_http_message_body_t
*body
= userdata
;
249 if (0 == php_stream_seek(php_http_message_body_stream(body
), offset
, origin
)) {
255 static int php_http_curle_raw_callback(CURL
*ch
, curl_infotype type
, char *data
, size_t length
, void *ctx
)
257 php_http_client_curl_handler_t
*h
= ctx
;
262 if (data
[0] == '-') {
263 } else if (php_memnstr(data
, ZEND_STRL("Adding handle:"), data
+ length
)) {
264 h
->progress
.info
= "setup";
265 } else if (php_memnstr(data
, ZEND_STRL("addHandle"), data
+ length
)) {
266 h
->progress
.info
= "setup";
267 } else if (php_memnstr(data
, ZEND_STRL("About to connect"), data
+ length
)) {
268 h
->progress
.info
= "resolve";
269 } else if (php_memnstr(data
, ZEND_STRL("Trying"), data
+ length
)) {
270 h
->progress
.info
= "connect";
271 } else if (php_memnstr(data
, ZEND_STRL("Found bundle for host"), data
+ length
)) {
272 h
->progress
.info
= "connect";
273 } else if (php_memnstr(data
, ZEND_STRL("Connected"), data
+ length
)) {
274 h
->progress
.info
= "connected";
275 } else if (php_memnstr(data
, ZEND_STRL("Re-using existing connection!"), data
+ length
)) {
276 h
->progress
.info
= "connected";
277 } else if (php_memnstr(data
, ZEND_STRL("blacklisted"), data
+ length
)) {
278 h
->progress
.info
= "blacklist check";
279 } else if (php_memnstr(data
, ZEND_STRL("SSL"), data
+ length
)) {
280 h
->progress
.info
= "ssl negotiation";
281 } else if (php_memnstr(data
, ZEND_STRL("upload"), data
+ length
)) {
282 h
->progress
.info
= "uploaded";
283 } else if (php_memnstr(data
, ZEND_STRL("left intact"), data
+ length
)) {
284 h
->progress
.info
= "not disconnected";
285 } else if (php_memnstr(data
, ZEND_STRL("closed"), data
+ length
)) {
286 h
->progress
.info
= "disconnected";
287 } else if (php_memnstr(data
, ZEND_STRL("Issue another request"), data
+ length
)) {
288 h
->progress
.info
= "redirect";
289 } else if (php_memnstr(data
, ZEND_STRL("Operation timed out"), data
+ length
)) {
290 h
->progress
.info
= "timeout";
293 h
->progress
.info
= data
;
294 data
[length
- 1] = '\0';
297 if (h
->client
->callback
.progress
.func
) {
298 h
->client
->callback
.progress
.func(h
->client
->callback
.progress
.arg
, h
->client
, &h
->queue
, &h
->progress
);
301 case CURLINFO_HEADER_OUT
:
302 case CURLINFO_DATA_OUT
:
303 case CURLINFO_SSL_DATA_OUT
:
304 h
->progress
.info
= "send";
306 case CURLINFO_HEADER_IN
:
307 case CURLINFO_DATA_IN
:
308 case CURLINFO_SSL_DATA_IN
:
309 h
->progress
.info
= "receive";
317 _dpf(type
, data
, length
);
323 static int php_http_curle_header_callback(char *data
, size_t n
, size_t l
, void *arg
)
325 php_http_client_curl_handler_t
*h
= arg
;
327 return php_http_buffer_append(&h
->response
.headers
, data
, n
* l
);
330 static int php_http_curle_body_callback(char *data
, size_t n
, size_t l
, void *arg
)
332 php_http_client_curl_handler_t
*h
= arg
;
334 return php_http_message_body_append(h
->response
.body
, data
, n
*l
);
337 static ZEND_RESULT_CODE
php_http_curle_get_info(CURL
*ch
, HashTable
*info
)
342 struct curl_slist
*s
= NULL
, *p
= NULL
;
345 /* BEGIN::CURLINFO */
346 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_EFFECTIVE_URL
, &c
)) {
347 ZVAL_STRING(&tmp
, STR_PTR(c
));
348 zend_hash_str_update(info
, "effective_url", lenof("effective_url"), &tmp
);
350 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_RESPONSE_CODE
, &l
)) {
352 zend_hash_str_update(info
, "response_code", lenof("response_code"), &tmp
);
354 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TOTAL_TIME
, &d
)) {
355 ZVAL_DOUBLE(&tmp
, d
);
356 zend_hash_str_update(info
, "total_time", lenof("total_time"), &tmp
);
358 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_NAMELOOKUP_TIME
, &d
)) {
359 ZVAL_DOUBLE(&tmp
, d
);
360 zend_hash_str_update(info
, "namelookup_time", lenof("namelookup_time"), &tmp
);
362 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONNECT_TIME
, &d
)) {
363 ZVAL_DOUBLE(&tmp
, d
);
364 zend_hash_str_update(info
, "connect_time", lenof("connect_time"), &tmp
);
366 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRETRANSFER_TIME
, &d
)) {
367 ZVAL_DOUBLE(&tmp
, d
);
368 zend_hash_str_update(info
, "pretransfer_time", lenof("pretransfer_time"), &tmp
);
370 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SIZE_UPLOAD
, &d
)) {
371 ZVAL_DOUBLE(&tmp
, d
);
372 zend_hash_str_update(info
, "size_upload", lenof("size_upload"), &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_SPEED_DOWNLOAD
, &d
)) {
379 ZVAL_DOUBLE(&tmp
, d
);
380 zend_hash_str_update(info
, "speed_download", lenof("speed_download"), &tmp
);
382 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SPEED_UPLOAD
, &d
)) {
383 ZVAL_DOUBLE(&tmp
, d
);
384 zend_hash_str_update(info
, "speed_upload", lenof("speed_upload"), &tmp
);
386 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HEADER_SIZE
, &l
)) {
388 zend_hash_str_update(info
, "header_size", lenof("header_size"), &tmp
);
390 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REQUEST_SIZE
, &l
)) {
392 zend_hash_str_update(info
, "request_size", lenof("request_size"), &tmp
);
394 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SSL_VERIFYRESULT
, &l
)) {
396 zend_hash_str_update(info
, "ssl_verifyresult", lenof("ssl_verifyresult"), &tmp
);
398 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_FILETIME
, &l
)) {
400 zend_hash_str_update(info
, "filetime", lenof("filetime"), &tmp
);
402 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_DOWNLOAD
, &d
)) {
403 ZVAL_DOUBLE(&tmp
, d
);
404 zend_hash_str_update(info
, "content_length_download", lenof("content_length_download"), &tmp
);
406 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_LENGTH_UPLOAD
, &d
)) {
407 ZVAL_DOUBLE(&tmp
, d
);
408 zend_hash_str_update(info
, "content_length_upload", lenof("content_length_upload"), &tmp
);
410 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_STARTTRANSFER_TIME
, &d
)) {
411 ZVAL_DOUBLE(&tmp
, d
);
412 zend_hash_str_update(info
, "starttransfer_time", lenof("starttransfer_time"), &tmp
);
414 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONTENT_TYPE
, &c
)) {
415 ZVAL_STRING(&tmp
, STR_PTR(c
));
416 zend_hash_str_update(info
, "content_type", lenof("content_type"), &tmp
);
418 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_TIME
, &d
)) {
419 ZVAL_DOUBLE(&tmp
, d
);
420 zend_hash_str_update(info
, "redirect_time", lenof("redirect_time"), &tmp
);
422 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_COUNT
, &l
)) {
424 zend_hash_str_update(info
, "redirect_count", lenof("redirect_count"), &tmp
);
426 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTP_CONNECTCODE
, &l
)) {
428 zend_hash_str_update(info
, "connect_code", lenof("connect_code"), &tmp
);
430 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_HTTPAUTH_AVAIL
, &l
)) {
432 zend_hash_str_update(info
, "httpauth_avail", lenof("httpauth_avail"), &tmp
);
434 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PROXYAUTH_AVAIL
, &l
)) {
436 zend_hash_str_update(info
, "proxyauth_avail", lenof("proxyauth_avail"), &tmp
);
438 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_OS_ERRNO
, &l
)) {
440 zend_hash_str_update(info
, "os_errno", lenof("os_errno"), &tmp
);
442 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_NUM_CONNECTS
, &l
)) {
444 zend_hash_str_update(info
, "num_connects", lenof("num_connects"), &tmp
);
446 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_SSL_ENGINES
, &s
)) {
448 for (p
= s
; p
; p
= p
->next
) {
450 add_next_index_string(&tmp
, p
->data
);
453 zend_hash_str_update(info
, "ssl_engines", lenof("ssl_engines"), &tmp
);
454 curl_slist_free_all(s
);
456 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_REDIRECT_URL
, &c
)) {
457 ZVAL_STRING(&tmp
, STR_PTR(c
));
458 zend_hash_str_update(info
, "redirect_url", lenof("redirect_url"), &tmp
);
460 #if PHP_HTTP_CURL_VERSION(7,19,0)
461 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRIMARY_IP
, &c
)) {
462 ZVAL_STRING(&tmp
, STR_PTR(c
));
463 zend_hash_str_update(info
, "primary_ip", lenof("primary_ip"), &tmp
);
466 #if PHP_HTTP_CURL_VERSION(7,19,0)
467 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_APPCONNECT_TIME
, &d
)) {
468 ZVAL_DOUBLE(&tmp
, d
);
469 zend_hash_str_update(info
, "appconnect_time", lenof("appconnect_time"), &tmp
);
472 #if PHP_HTTP_CURL_VERSION(7,19,4)
473 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CONDITION_UNMET
, &l
)) {
475 zend_hash_str_update(info
, "condition_unmet", lenof("condition_unmet"), &tmp
);
478 #if PHP_HTTP_CURL_VERSION(7,21,0)
479 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_PRIMARY_PORT
, &l
)) {
481 zend_hash_str_update(info
, "primary_port", lenof("primary_port"), &tmp
);
484 #if PHP_HTTP_CURL_VERSION(7,21,0)
485 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_LOCAL_IP
, &c
)) {
486 ZVAL_STRING(&tmp
, STR_PTR(c
));
487 zend_hash_str_update(info
, "local_ip", lenof("local_ip"), &tmp
);
490 #if PHP_HTTP_CURL_VERSION(7,21,0)
491 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_LOCAL_PORT
, &l
)) {
493 zend_hash_str_update(info
, "local_port", lenof("local_port"), &tmp
);
499 #if PHP_HTTP_CURL_VERSION(7,34,0)
501 zval ti_array
, subarray
;
502 struct curl_tlssessioninfo
*ti
;
504 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_TLS_SESSION
, &ti
)) {
507 ZVAL_NULL(&subarray
);
508 array_init(&ti_array
);
510 switch (ti
->backend
) {
511 case CURLSSLBACKEND_NONE
:
514 case CURLSSLBACKEND_OPENSSL
:
516 #ifdef PHP_HTTP_HAVE_OPENSSL
518 SSL_CTX
*ctx
= ti
->internals
;
520 array_init(&subarray
);
521 add_assoc_long_ex(&subarray
, ZEND_STRL("number"), SSL_CTX_sess_number(ctx
));
522 add_assoc_long_ex(&subarray
, ZEND_STRL("connect"), SSL_CTX_sess_connect(ctx
));
523 add_assoc_long_ex(&subarray
, ZEND_STRL("connect_good"), SSL_CTX_sess_connect_good(ctx
));
524 add_assoc_long_ex(&subarray
, ZEND_STRL("connect_renegotiate"), SSL_CTX_sess_connect_renegotiate(ctx
));
525 add_assoc_long_ex(&subarray
, ZEND_STRL("hits"), SSL_CTX_sess_hits(ctx
));
526 add_assoc_long_ex(&subarray
, ZEND_STRL("cache_full"), SSL_CTX_sess_cache_full(ctx
));
530 case CURLSSLBACKEND_GNUTLS
:
532 #ifdef PHP_HTTP_HAVE_GNUTLS
534 gnutls_session_t sess
= ti
->internals
;
537 array_init(&subarray
);
538 if ((desc
= gnutls_session_get_desc(sess
))) {
539 add_assoc_string_ex(&subarray
, ZEND_STRL("desc"), desc
);
542 add_assoc_bool_ex(&subarray
, ZEND_STRL("resumed"), gnutls_session_is_resumed(sess
));
546 case CURLSSLBACKEND_NSS
:
549 #if !PHP_HTTP_CURL_VERSION(7,39,0)
550 case CURLSSLBACKEND_QSOSSL
:
554 case CURLSSLBACKEND_GSKIT
:
558 case CURLSSLBACKEND_POLARSSL
:
559 backend
= "polarssl";
561 case CURLSSLBACKEND_CYASSL
:
564 case CURLSSLBACKEND_SCHANNEL
:
565 backend
= "schannel";
567 case CURLSSLBACKEND_DARWINSSL
:
568 backend
= "darwinssl";
573 add_assoc_string_ex(&ti_array
, ZEND_STRL("backend"), backend
);
574 add_assoc_zval_ex(&ti_array
, ZEND_STRL("internals"), &subarray
);
575 zend_hash_str_update(info
, "tls_session", lenof("tls_session"), &ti_array
);
580 #if (PHP_HTTP_CURL_VERSION(7,19,1) && defined(PHP_HTTP_HAVE_OPENSSL)) || (PHP_HTTP_CURL_VERSION(7,34,0) && defined(PHP_HTTP_HAVE_NSS)) || (PHP_HTTP_CURL_VERSION(7,42,0) && defined(PHP_HTTP_HAVE_GNUTLS)) || (PHP_HTTP_CURL_VERSION(7,39,0) && defined(PHP_HTTP_HAVE_GSKIT))
583 zval ci_array
, subarray
;
584 struct curl_certinfo
*ci
;
585 char *colon
, *keyname
;
587 if (CURLE_OK
== curl_easy_getinfo(ch
, CURLINFO_CERTINFO
, &ci
)) {
588 array_init(&ci_array
);
590 for (i
= 0; i
< ci
->num_of_certs
; ++i
) {
593 array_init(&subarray
);
594 for (p
= s
; p
; p
= p
->next
) {
596 if ((colon
= strchr(p
->data
, ':'))) {
597 keyname
= estrndup(p
->data
, colon
- p
->data
);
598 add_assoc_string_ex(&subarray
, keyname
, colon
- p
->data
, colon
+ 1);
601 add_next_index_string(&subarray
, p
->data
);
605 add_next_index_zval(&ci_array
, &subarray
);
607 zend_hash_str_update(info
, "certinfo", lenof("certinfo"), &ci_array
);
612 php_http_curle_storage_t
*st
= php_http_curle_get_storage(ch
);
614 ZVAL_LONG(&tmp
, st
->errorcode
);
615 zend_hash_str_update(info
, "curlcode", lenof("curlcode"), &tmp
);
616 ZVAL_STRING(&tmp
, st
->errorbuffer
);
617 zend_hash_str_update(info
, "error", lenof("error"), &tmp
);
623 static int compare_queue(php_http_client_enqueue_t
*e
, void *handle
)
625 return handle
== ((php_http_client_curl_handler_t
*) e
->opaque
)->handle
;
628 static php_http_message_t
*php_http_curlm_responseparser(php_http_client_curl_handler_t
*h
)
630 php_http_message_t
*response
;
631 php_http_header_parser_t parser
;
634 response
= php_http_message_init(NULL
, 0, h
->response
.body
);
635 php_http_header_parser_init(&parser
);
636 while (h
->response
.headers
.used
) {
637 php_http_header_parser_state_t st
= php_http_header_parser_parse(&parser
,
638 &h
->response
.headers
, PHP_HTTP_HEADER_PARSER_CLEANUP
, &response
->hdrs
,
639 (php_http_info_callback_t
) php_http_message_info_callback
, (void *) &response
);
640 if (PHP_HTTP_HEADER_PARSER_STATE_FAILURE
== st
) {
644 php_http_header_parser_dtor(&parser
);
646 /* move body to right message */
647 if (response
->body
!= h
->response
.body
) {
648 php_http_message_t
*ptr
= response
;
650 while (ptr
->parent
) {
653 php_http_message_body_free(&response
->body
);
654 response
->body
= ptr
->body
;
657 php_http_message_body_addref(h
->response
.body
);
659 /* let's update the response headers */
660 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Length")))) {
662 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Length", lenof("X-Original-Content-Length"), zh
);
664 if ((zh
= php_http_message_header(response
, ZEND_STRL("Transfer-Encoding")))) {
666 zend_hash_str_update(&response
->hdrs
, "X-Original-Transfer-Encoding", lenof("X-Original-Transfer-Encoding"), zh
);
667 zend_hash_str_del(&response
->hdrs
, "Transfer-Encoding", lenof("Transfer-Encoding"));
669 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Range")))) {
671 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Range", lenof("X-Original-Content-Range"), zh
);
672 zend_hash_str_del(&response
->hdrs
, "Content-Range", lenof("Content-Range"));
674 if ((zh
= php_http_message_header(response
, ZEND_STRL("Content-Encoding")))) {
676 zend_hash_str_update(&response
->hdrs
, "X-Original-Content-Encoding", lenof("X-Original-Content-Encoding"), zh
);
677 zend_hash_str_del(&response
->hdrs
, "Content-Encoding", lenof("Content-Encoding"));
679 php_http_message_update_headers(response
);
684 static void php_http_curlm_responsehandler(php_http_client_t
*context
)
686 int err_count
= 0, remaining
= 0;
687 php_http_curle_storage_t
*st
, *err
= NULL
;
688 php_http_client_enqueue_t
*enqueue
;
689 php_http_client_curl_t
*curl
= context
->ctx
;
692 CURLMsg
*msg
= curl_multi_info_read(curl
->handle
->multi
, &remaining
);
694 if (msg
&& CURLMSG_DONE
== msg
->msg
) {
695 if (CURLE_OK
!= msg
->data
.result
) {
696 st
= php_http_curle_get_storage(msg
->easy_handle
);
697 st
->errorcode
= msg
->data
.result
;
699 /* defer the warnings/exceptions, so the callback is still called for this request */
701 err
= ecalloc(remaining
+ 1, sizeof(*err
));
703 memcpy(&err
[err_count
], st
, sizeof(*st
));
705 err
[err_count
].url
= estrdup(st
->url
);
710 if ((enqueue
= php_http_client_enqueued(context
, msg
->easy_handle
, compare_queue
))) {
711 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
712 php_http_message_t
*response
= php_http_curlm_responseparser(handler
);
715 context
->callback
.response
.func(context
->callback
.response
.arg
, context
, &handler
->queue
, &response
);
716 php_http_message_free(&response
);
726 php_error_docref(NULL
, E_WARNING
, "%s; %s (%s)", curl_easy_strerror(err
[i
].errorcode
), err
[i
].errorbuffer
, STR_PTR(err
[i
].url
));
730 } while (++i
< err_count
);
736 #if PHP_HTTP_HAVE_EVENT
738 typedef struct php_http_curlm_event
{
740 php_http_client_t
*context
;
741 } php_http_curlm_event_t
;
743 static inline int etoca(short action
) {
744 switch (action
& (EV_READ
|EV_WRITE
)) {
746 return CURL_CSELECT_IN
;
749 return CURL_CSELECT_OUT
;
751 case EV_READ
|EV_WRITE
:
752 return CURL_CSELECT_IN
|CURL_CSELECT_OUT
;
759 static void php_http_curlm_timeout_callback(int socket
, short action
, void *event_data
)
761 php_http_client_t
*context
= event_data
;
762 php_http_client_curl_t
*curl
= context
->ctx
;
765 fprintf(stderr
, "T");
767 if (curl
->useevents
) {
770 /* ignore and use -1,0 on timeout */
774 while (CURLM_CALL_MULTI_PERFORM
== (rc
= curl_multi_socket_action(curl
->handle
->multi
, CURL_SOCKET_TIMEOUT
, 0, &curl
->unfinished
)));
776 if (CURLM_OK
!= rc
) {
777 php_error_docref(NULL
, E_WARNING
, "%s", curl_multi_strerror(rc
));
780 php_http_curlm_responsehandler(context
);
784 static void php_http_curlm_event_callback(int socket
, short action
, void *event_data
)
786 php_http_client_t
*context
= event_data
;
787 php_http_client_curl_t
*curl
= context
->ctx
;
790 fprintf(stderr
, "E");
792 if (curl
->useevents
) {
793 CURLMcode rc
= CURLM_OK
;
795 while (CURLM_CALL_MULTI_PERFORM
== (rc
= curl_multi_socket_action(curl
->handle
->multi
, socket
, etoca(action
), &curl
->unfinished
)));
797 if (CURLM_OK
!= rc
) {
798 php_error_docref(NULL
, E_WARNING
, "%s", curl_multi_strerror(rc
));
801 php_http_curlm_responsehandler(context
);
803 /* remove timeout if there are no transfers left */
804 if (!curl
->unfinished
&& event_initialized(curl
->timeout
) && event_pending(curl
->timeout
, EV_TIMEOUT
, NULL
)) {
805 event_del(curl
->timeout
);
810 static int php_http_curlm_socket_callback(CURL
*easy
, curl_socket_t sock
, int action
, void *socket_data
, void *assign_data
)
812 php_http_client_t
*context
= socket_data
;
813 php_http_client_curl_t
*curl
= context
->ctx
;
816 fprintf(stderr
, "S");
818 if (curl
->useevents
) {
819 int events
= EV_PERSIST
;
820 php_http_curlm_event_t
*ev
= assign_data
;
823 ev
= ecalloc(1, sizeof(php_http_curlm_event_t
));
824 ev
->context
= context
;
825 curl_multi_assign(curl
->handle
->multi
, sock
, ev
);
827 event_del(&ev
->evnt
);
837 case CURL_POLL_INOUT
:
838 events
|= EV_READ
|EV_WRITE
;
841 case CURL_POLL_REMOVE
:
848 php_error_docref(NULL
, E_WARNING
, "Unknown socket action %d", action
);
852 event_assign(&ev
->evnt
, curl
->evbase
, sock
, events
, php_http_curlm_event_callback
, context
);
853 event_add(&ev
->evnt
, NULL
);
859 static void php_http_curlm_timer_callback(CURLM
*multi
, long timeout_ms
, void *timer_data
)
861 php_http_client_t
*context
= timer_data
;
862 php_http_client_curl_t
*curl
= context
->ctx
;
865 fprintf(stderr
, "\ntimer <- timeout_ms: %ld\n", timeout_ms
);
867 if (curl
->useevents
) {
869 if (timeout_ms
< 0) {
870 php_http_curlm_timeout_callback(CURL_SOCKET_TIMEOUT
, /*EV_READ|EV_WRITE*/0, context
);
871 } else if (timeout_ms
> 0 || !event_initialized(curl
->timeout
) || !event_pending(curl
->timeout
, EV_TIMEOUT
, NULL
)) {
872 struct timeval timeout
;
874 if (!event_initialized(curl
->timeout
)) {
875 event_assign(curl
->timeout
, curl
->evbase
, CURL_SOCKET_TIMEOUT
, 0, php_http_curlm_timeout_callback
, context
);
878 timeout
.tv_sec
= timeout_ms
/ 1000;
879 timeout
.tv_usec
= (timeout_ms
% 1000) * 1000;
881 event_add(curl
->timeout
, &timeout
);
886 #endif /* HAVE_EVENT */
890 static php_http_options_t php_http_curle_options
, php_http_curlm_options
;
892 #define PHP_HTTP_CURLE_OPTION_CHECK_STRLEN 0x0001
893 #define PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR 0x0002
894 #define PHP_HTTP_CURLE_OPTION_TRANSFORM_MS 0x0004
896 static ZEND_RESULT_CODE
php_http_curle_option_set_ssl_verifyhost(php_http_option_t
*opt
, zval
*val
, void *userdata
)
898 php_http_client_curl_handler_t
*curl
= userdata
;
899 CURL
*ch
= curl
->handle
;
901 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_SSL_VERIFYHOST
, Z_TYPE_P(val
) == IS_TRUE
? 2 : 0)) {
907 static ZEND_RESULT_CODE
php_http_curle_option_set_cookiestore(php_http_option_t
*opt
, zval
*val
, void *userdata
)
909 php_http_client_curl_handler_t
*curl
= userdata
;
910 CURL
*ch
= curl
->handle
;
911 php_http_curle_storage_t
*storage
= php_http_curle_get_storage(curl
->handle
);
913 if (storage
->cookiestore
) {
914 pefree(storage
->cookiestore
, 1);
916 if (val
&& Z_TYPE_P(val
) == IS_STRING
&& Z_STRLEN_P(val
)) {
917 storage
->cookiestore
= pestrndup(Z_STRVAL_P(val
), Z_STRLEN_P(val
), 1);
919 storage
->cookiestore
= NULL
;
921 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIEFILE
, storage
->cookiestore
)
922 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIEJAR
, storage
->cookiestore
)
930 static ZEND_RESULT_CODE
php_http_curle_option_set_cookies(php_http_option_t
*opt
, zval
*val
, void *userdata
)
932 php_http_client_curl_handler_t
*curl
= userdata
;
933 CURL
*ch
= curl
->handle
;
935 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
936 HashTable
*ht
= HASH_OF(val
);
938 if (curl
->options
.encode_cookies
) {
939 if (SUCCESS
== php_http_url_encode_hash_ex(ht
, &curl
->options
.cookies
, ZEND_STRL(";"), ZEND_STRL("="), NULL
, 0)) {
940 php_http_buffer_fix(&curl
->options
.cookies
);
941 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, curl
->options
.cookies
.data
)) {
948 php_http_arrkey_t cookie_key
;
951 ZEND_HASH_FOREACH_KEY_VAL(ht
, cookie_key
.h
, cookie_key
.key
, cookie_val
)
953 zend_string
*zs
= zval_get_string(cookie_val
);
955 php_http_arrkey_stringify(&cookie_key
, NULL
);
956 php_http_buffer_appendf(&curl
->options
.cookies
, "%s=%s; ", cookie_key
.key
->val
, zs
->val
);
957 php_http_arrkey_dtor(&cookie_key
);
959 zend_string_release(zs
);
961 ZEND_HASH_FOREACH_END();
963 php_http_buffer_fix(&curl
->options
.cookies
);
964 if (curl
->options
.cookies
.used
) {
965 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, curl
->options
.cookies
.data
)) {
971 php_http_buffer_reset(&curl
->options
.cookies
);
972 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_COOKIE
, NULL
)) {
979 static ZEND_RESULT_CODE
php_http_curle_option_set_encodecookies(php_http_option_t
*opt
, zval
*val
, void *userdata
)
981 php_http_client_curl_handler_t
*curl
= userdata
;
983 curl
->options
.encode_cookies
= Z_TYPE_P(val
) == IS_TRUE
;
987 static ZEND_RESULT_CODE
php_http_curle_option_set_lastmodified(php_http_option_t
*opt
, zval
*val
, void *userdata
)
989 php_http_client_curl_handler_t
*curl
= userdata
;
990 CURL
*ch
= curl
->handle
;
993 if (Z_LVAL_P(val
) > 0) {
994 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, Z_LVAL_P(val
))) {
998 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, (long) sapi_get_request_time() + Z_LVAL_P(val
))) {
1002 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMECONDITION
, (long) (curl
->options
.range_request
? CURL_TIMECOND_IFUNMODSINCE
: CURL_TIMECOND_IFMODSINCE
))) {
1006 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMEVALUE
, 0)
1007 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TIMECONDITION
, 0)
1015 static ZEND_RESULT_CODE
php_http_curle_option_set_compress(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 !PHP_HTTP_CURL_VERSION(7,21,6)
1021 # define CURLOPT_ACCEPT_ENCODING CURLOPT_ENCODING
1023 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_ACCEPT_ENCODING
, Z_TYPE_P(val
) == IS_TRUE
? "" : NULL
)) {
1029 static ZEND_RESULT_CODE
php_http_curle_option_set_etag(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1031 php_http_client_curl_handler_t
*curl
= userdata
;
1032 php_http_buffer_t header
;
1034 if (val
&& Z_TYPE_P(val
) == IS_STRING
&& Z_STRLEN_P(val
)) {
1035 zend_bool is_quoted
= !((Z_STRVAL_P(val
)[0] != '"') || (Z_STRVAL_P(val
)[Z_STRLEN_P(val
)-1] != '"'));
1036 php_http_buffer_init(&header
);
1037 php_http_buffer_appendf(&header
, is_quoted
?"%s: %s":"%s: \"%s\"", curl
->options
.range_request
?"If-Match":"If-None-Match", Z_STRVAL_P(val
));
1038 php_http_buffer_fix(&header
);
1039 curl
->options
.headers
= curl_slist_append(curl
->options
.headers
, header
.data
);
1040 php_http_buffer_dtor(&header
);
1045 static ZEND_RESULT_CODE
php_http_curle_option_set_range(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1047 php_http_client_curl_handler_t
*curl
= userdata
;
1048 CURL
*ch
= curl
->handle
;
1050 php_http_buffer_reset(&curl
->options
.ranges
);
1052 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1055 HashTable
*ht
= HASH_OF(val
);
1057 ZEND_HASH_FOREACH_VAL(ht
, rr
)
1059 if (Z_TYPE_P(rr
) == IS_ARRAY
) {
1060 if (2 == php_http_array_list(Z_ARRVAL_P(rr
), 2, &rb
, &re
)) {
1061 if ( ((Z_TYPE_P(rb
) == IS_LONG
) || ((Z_TYPE_P(rb
) == IS_STRING
) && is_numeric_string(Z_STRVAL_P(rb
), Z_STRLEN_P(rb
), &rbl
, NULL
, 1))) &&
1062 ((Z_TYPE_P(re
) == IS_LONG
) || ((Z_TYPE_P(re
) == IS_STRING
) && is_numeric_string(Z_STRVAL_P(re
), Z_STRLEN_P(re
), &rel
, NULL
, 1)))) {
1063 if ((rbl
>= 0) && (rel
>= 0)) {
1064 php_http_buffer_appendf(&curl
->options
.ranges
, "%ld-%ld,", rbl
, rel
);
1071 ZEND_HASH_FOREACH_END();
1073 if (curl
->options
.ranges
.used
) {
1074 curl
->options
.range_request
= 1;
1075 /* ditch last comma */
1076 curl
->options
.ranges
.data
[curl
->options
.ranges
.used
- 1] = '\0';
1080 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RANGE
, curl
->options
.ranges
.data
)) {
1086 static ZEND_RESULT_CODE
php_http_curle_option_set_resume(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1088 php_http_client_curl_handler_t
*curl
= userdata
;
1089 CURL
*ch
= curl
->handle
;
1091 if (Z_LVAL_P(val
) > 0) {
1092 curl
->options
.range_request
= 1;
1094 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESUME_FROM
, Z_LVAL_P(val
))) {
1100 static ZEND_RESULT_CODE
php_http_curle_option_set_retrydelay(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1102 php_http_client_curl_handler_t
*curl
= userdata
;
1104 curl
->options
.retry
.delay
= Z_DVAL_P(val
);
1108 static ZEND_RESULT_CODE
php_http_curle_option_set_retrycount(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1110 php_http_client_curl_handler_t
*curl
= userdata
;
1112 curl
->options
.retry
.count
= Z_LVAL_P(val
);
1116 static ZEND_RESULT_CODE
php_http_curle_option_set_redirect(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1118 php_http_client_curl_handler_t
*curl
= userdata
;
1119 CURL
*ch
= curl
->handle
;
1121 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, Z_LVAL_P(val
) ? 1L : 0L)
1122 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_MAXREDIRS
, curl
->options
.redirects
= Z_LVAL_P(val
))
1129 static ZEND_RESULT_CODE
php_http_curle_option_set_portrange(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1131 php_http_client_curl_handler_t
*curl
= userdata
;
1132 CURL
*ch
= curl
->handle
;
1133 long localport
= 0, localportrange
= 0;
1135 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1138 switch (php_http_array_list(Z_ARRVAL_P(val
), 2, &zps
, &zpe
)) {
1140 localportrange
= labs(zval_get_long(zps
)-zval_get_long(zpe
))+1L;
1143 localport
= (zval_get_long(zpe
) > 0) ? MIN(zval_get_long(zps
), zval_get_long(zpe
)) : zval_get_long(zps
);
1149 if ( CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_LOCALPORT
, localport
)
1150 || CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_LOCALPORTRANGE
, localportrange
)
1157 #if PHP_HTTP_CURL_VERSION(7,37,0)
1158 static ZEND_RESULT_CODE
php_http_curle_option_set_proxyheader(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1160 php_http_client_curl_handler_t
*curl
= userdata
;
1162 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1163 php_http_arrkey_t header_key
;
1165 php_http_buffer_t header
;
1167 php_http_buffer_init(&header
);
1168 ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(val
), header_key
.h
, header_key
.key
, header_val
)
1170 if (header_key
.key
) {
1171 zend_string
*zs
= zval_get_string(header_val
);
1173 php_http_buffer_appendf(&header
, "%s: %s", header_key
.key
->val
, zs
->val
);
1174 zend_string_release(zs
);
1176 php_http_buffer_fix(&header
);
1177 curl
->options
.proxyheaders
= curl_slist_append(curl
->options
.proxyheaders
, header
.data
);
1178 php_http_buffer_reset(&header
);
1182 ZEND_HASH_FOREACH_END();
1183 php_http_buffer_dtor(&header
);
1185 if (CURLE_OK
!= curl_easy_setopt(curl
->handle
, CURLOPT_PROXYHEADER
, curl
->options
.proxyheaders
)) {
1188 if (CURLE_OK
!= curl_easy_setopt(curl
->handle
, CURLOPT_HEADEROPT
, CURLHEADER_SEPARATE
)) {
1189 curl_easy_setopt(curl
->handle
, CURLOPT_PROXYHEADER
, NULL
);
1196 #if PHP_HTTP_CURL_VERSION(7,21,3)
1197 static ZEND_RESULT_CODE
php_http_curle_option_set_resolve(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1199 php_http_client_curl_handler_t
*curl
= userdata
;
1200 CURL
*ch
= curl
->handle
;
1202 if (val
&& Z_TYPE_P(val
) != IS_NULL
) {
1203 HashTable
*ht
= HASH_OF(val
);
1206 ZEND_HASH_FOREACH_VAL(ht
, data
)
1208 zend_string
*zs
= zval_get_string(data
);
1209 curl
->options
.resolve
= curl_slist_append(curl
->options
.resolve
, zs
->val
);
1210 zend_string_release(zs
);
1212 ZEND_HASH_FOREACH_END();
1214 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESOLVE
, curl
->options
.resolve
)) {
1218 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_RESOLVE
, NULL
)) {
1226 #if PHP_HTTP_CURL_VERSION(7,21,4) && defined(PHP_HTTP_CURL_TLSAUTH_SRP)
1227 static ZEND_RESULT_CODE
php_http_curle_option_set_ssl_tlsauthtype(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1229 php_http_client_curl_handler_t
*curl
= userdata
;
1230 CURL
*ch
= curl
->handle
;
1232 if (val
&& Z_LVAL_P(val
)) {
1233 switch (Z_LVAL_P(val
)) {
1234 case CURL_TLSAUTH_SRP
:
1235 if (CURLE_OK
== curl_easy_setopt(ch
, CURLOPT_TLSAUTH_TYPE
, PHP_HTTP_CURL_TLSAUTH_SRP
)) {
1243 if (CURLE_OK
!= curl_easy_setopt(ch
, CURLOPT_TLSAUTH_TYPE
, PHP_HTTP_CURL_TLSAUTH_DEF
)) {
1250 static void php_http_curle_options_init(php_http_options_t
*registry
)
1252 php_http_option_t
*opt
;
1255 #if PHP_HTTP_CURL_VERSION(7,42,0)
1256 php_http_option_register(registry
, ZEND_STRL("path_as_is"), CURLOPT_PATH_AS_IS
, _IS_BOOL
);
1260 php_http_option_register(registry
, ZEND_STRL("proxyhost"), CURLOPT_PROXY
, IS_STRING
);
1261 php_http_option_register(registry
, ZEND_STRL("proxytype"), CURLOPT_PROXYTYPE
, IS_LONG
);
1262 php_http_option_register(registry
, ZEND_STRL("proxyport"), CURLOPT_PROXYPORT
, IS_LONG
);
1263 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyauth"), CURLOPT_PROXYUSERPWD
, IS_STRING
))) {
1264 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1266 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyauthtype"), CURLOPT_PROXYAUTH
, IS_LONG
))) {
1267 Z_LVAL(opt
->defval
) = CURLAUTH_ANYSAFE
;
1269 php_http_option_register(registry
, ZEND_STRL("proxytunnel"), CURLOPT_HTTPPROXYTUNNEL
, _IS_BOOL
);
1270 #if PHP_HTTP_CURL_VERSION(7,19,4)
1271 php_http_option_register(registry
, ZEND_STRL("noproxy"), CURLOPT_NOPROXY
, IS_STRING
);
1274 #if PHP_HTTP_CURL_VERSION(7,37,0)
1275 if ((opt
= php_http_option_register(registry
, ZEND_STRL("proxyheader"), CURLOPT_PROXYHEADER
, IS_ARRAY
))) {
1276 opt
->setter
= php_http_curle_option_set_proxyheader
;
1279 #if PHP_HTTP_CURL_VERSION(7,43,0)
1280 if (PHP_HTTP_CURL_FEATURE(CURL_VERSION_GSSAPI
)
1281 && (opt
= php_http_option_register(registry
, ZEND_STRL("proxy_service_name"), CURLOPT_PROXY_SERVICE_NAME
, IS_STRING
))
1283 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1287 #if PHP_HTTP_CURL_VERSION(7,40,0)
1288 if ((opt
= php_http_option_register(registry
, ZEND_STRL("unix_socket_path"), CURLOPT_UNIX_SOCKET_PATH
, IS_STRING
))) {
1289 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1290 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1295 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_cache_timeout"), CURLOPT_DNS_CACHE_TIMEOUT
, IS_LONG
))) {
1296 Z_LVAL(opt
->defval
) = 60;
1298 php_http_option_register(registry
, ZEND_STRL("ipresolve"), CURLOPT_IPRESOLVE
, IS_LONG
);
1299 #if PHP_HTTP_CURL_VERSION(7,21,3)
1300 if ((opt
= php_http_option_register(registry
, ZEND_STRL("resolve"), CURLOPT_RESOLVE
, IS_ARRAY
))) {
1301 opt
->setter
= php_http_curle_option_set_resolve
;
1304 #if PHP_HTTP_HAVE_ARES
1305 # if PHP_HTTP_CURL_VERSION(7,24,0)
1306 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_servers"), CURLOPT_DNS_SERVERS
, IS_STRING
))) {
1307 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1310 # if PHP_HTTP_CURL_VERSION(7,33,0)
1311 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_interface"), CURLOPT_DNS_INTERFACE
, IS_STRING
))) {
1312 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1314 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_local_ip4"), CURLOPT_DNS_LOCAL_IP4
, IS_STRING
))) {
1315 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1317 if ((opt
= php_http_option_register(registry
, ZEND_STRL("dns_local_ip6"), CURLOPT_DNS_LOCAL_IP6
, IS_STRING
))) {
1318 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1324 php_http_option_register(registry
, ZEND_STRL("low_speed_limit"), CURLOPT_LOW_SPEED_LIMIT
, IS_LONG
);
1325 php_http_option_register(registry
, ZEND_STRL("low_speed_time"), CURLOPT_LOW_SPEED_TIME
, IS_LONG
);
1328 php_http_option_register(registry, ZEND_STRL("max_send_speed"), CURLOPT_MAX_SEND_SPEED_LARGE, IS_LONG);
1329 php_http_option_register(registry, ZEND_STRL("max_recv_speed"), CURLOPT_MAX_RECV_SPEED_LARGE, IS_LONG);
1332 /* connection handling */
1334 if ((opt = php_http_option_register(registry, ZEND_STRL("maxconnects"), CURLOPT_MAXCONNECTS, IS_LONG))) {
1335 Z_LVAL(opt->defval) = 5;
1338 php_http_option_register(registry
, ZEND_STRL("fresh_connect"), CURLOPT_FRESH_CONNECT
, _IS_BOOL
);
1339 php_http_option_register(registry
, ZEND_STRL("forbid_reuse"), CURLOPT_FORBID_REUSE
, _IS_BOOL
);
1341 /* outgoing interface */
1342 php_http_option_register(registry
, ZEND_STRL("interface"), CURLOPT_INTERFACE
, IS_STRING
);
1343 if ((opt
= php_http_option_register(registry
, ZEND_STRL("portrange"), CURLOPT_LOCALPORT
, IS_ARRAY
))) {
1344 opt
->setter
= php_http_curle_option_set_portrange
;
1347 /* another endpoint port */
1348 php_http_option_register(registry
, ZEND_STRL("port"), CURLOPT_PORT
, IS_LONG
);
1350 /* RFC4007 zone_id */
1351 #if PHP_HTTP_CURL_VERSION(7,19,0)
1352 php_http_option_register(registry
, ZEND_STRL("address_scope"), CURLOPT_ADDRESS_SCOPE
, IS_LONG
);
1356 if ((opt
= php_http_option_register(registry
, ZEND_STRL("httpauth"), CURLOPT_USERPWD
, IS_STRING
))) {
1357 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1359 if ((opt
= php_http_option_register(registry
, ZEND_STRL("httpauthtype"), CURLOPT_HTTPAUTH
, IS_LONG
))) {
1360 Z_LVAL(opt
->defval
) = CURLAUTH_ANYSAFE
;
1362 #if PHP_HTTP_CURL_VERSION(7,43,0)
1363 if ((opt
= php_http_option_register(registry
, ZEND_STRL("service_name"), CURLOPT_SERVICE_NAME
, IS_STRING
))) {
1364 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1369 if ((opt
= php_http_option_register(registry
, ZEND_STRL("redirect"), CURLOPT_FOLLOWLOCATION
, IS_LONG
))) {
1370 opt
->setter
= php_http_curle_option_set_redirect
;
1372 php_http_option_register(registry
, ZEND_STRL("unrestricted_auth"), CURLOPT_UNRESTRICTED_AUTH
, _IS_BOOL
);
1373 #if PHP_HTTP_CURL_VERSION(7,19,1)
1374 php_http_option_register(registry
, ZEND_STRL("postredir"), CURLOPT_POSTREDIR
, IS_LONG
);
1378 if ((opt
= php_http_option_register(registry
, ZEND_STRL("retrycount"), 0, IS_LONG
))) {
1379 opt
->setter
= php_http_curle_option_set_retrycount
;
1381 if ((opt
= php_http_option_register(registry
, ZEND_STRL("retrydelay"), 0, IS_DOUBLE
))) {
1382 opt
->setter
= php_http_curle_option_set_retrydelay
;
1386 if ((opt
= php_http_option_register(registry
, ZEND_STRL("referer"), CURLOPT_REFERER
, IS_STRING
))) {
1387 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1389 if ((opt
= php_http_option_register(registry
, ZEND_STRL("autoreferer"), CURLOPT_AUTOREFERER
, _IS_BOOL
))) {
1390 ZVAL_BOOL(&opt
->defval
, 1);
1394 if ((opt
= php_http_option_register(registry
, ZEND_STRL("useragent"), CURLOPT_USERAGENT
, IS_STRING
))) {
1395 /* don't check strlen, to allow sending no useragent at all */
1396 ZVAL_PSTRING(&opt
->defval
,
1397 "PECL_HTTP/" PHP_PECL_HTTP_VERSION
" "
1398 "PHP/" PHP_VERSION
" "
1399 "libcurl/" LIBCURL_VERSION
);
1403 if ((opt
= php_http_option_register(registry
, ZEND_STRL("resume"), CURLOPT_RESUME_FROM
, IS_LONG
))) {
1404 opt
->setter
= php_http_curle_option_set_resume
;
1407 if ((opt
= php_http_option_register(registry
, ZEND_STRL("range"), CURLOPT_RANGE
, IS_ARRAY
))) {
1408 opt
->setter
= php_http_curle_option_set_range
;
1412 if ((opt
= php_http_option_register(registry
, ZEND_STRL("etag"), 0, IS_STRING
))) {
1413 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1414 opt
->setter
= php_http_curle_option_set_etag
;
1418 if ((opt
= php_http_option_register(registry
, ZEND_STRL("compress"), 0, _IS_BOOL
))) {
1419 opt
->setter
= php_http_curle_option_set_compress
;
1423 if ((opt
= php_http_option_register(registry
, ZEND_STRL("lastmodified"), 0, IS_LONG
))) {
1424 opt
->setter
= php_http_curle_option_set_lastmodified
;
1428 if ((opt
= php_http_option_register(registry
, ZEND_STRL("encodecookies"), 0, _IS_BOOL
))) {
1429 opt
->setter
= php_http_curle_option_set_encodecookies
;
1430 ZVAL_BOOL(&opt
->defval
, 1);
1432 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookies"), 0, IS_ARRAY
))) {
1433 opt
->setter
= php_http_curle_option_set_cookies
;
1436 /* cookiesession, don't load session cookies from cookiestore */
1437 php_http_option_register(registry
, ZEND_STRL("cookiesession"), CURLOPT_COOKIESESSION
, _IS_BOOL
);
1438 /* cookiestore, read initial cookies from that file and store cookies back into that file */
1439 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cookiestore"), 0, IS_STRING
))) {
1440 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1441 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1442 opt
->setter
= php_http_curle_option_set_cookiestore
;
1446 php_http_option_register(registry
, ZEND_STRL("maxfilesize"), CURLOPT_MAXFILESIZE
, IS_LONG
);
1448 /* http protocol version */
1449 php_http_option_register(registry
, ZEND_STRL("protocol"), CURLOPT_HTTP_VERSION
, IS_LONG
);
1452 if ((opt
= php_http_option_register(registry
, ZEND_STRL("timeout"), CURLOPT_TIMEOUT_MS
, IS_DOUBLE
))) {
1453 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1455 if ((opt
= php_http_option_register(registry
, ZEND_STRL("connecttimeout"), CURLOPT_CONNECTTIMEOUT_MS
, IS_DOUBLE
))) {
1456 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1457 Z_DVAL(opt
->defval
) = 3;
1459 #if PHP_HTTP_CURL_VERSION(7,36,0)
1460 if ((opt
= php_http_option_register(registry
, ZEND_STRL("expect_100_timeout"), CURLOPT_EXPECT_100_TIMEOUT_MS
, IS_DOUBLE
))) {
1461 opt
->flags
|= PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
;
1462 Z_DVAL(opt
->defval
) = 1;
1467 php_http_option_register(registry
, ZEND_STRL("tcp_nodelay"), CURLOPT_TCP_NODELAY
, _IS_BOOL
);
1468 #if PHP_HTTP_CURL_VERSION(7,25,0)
1469 php_http_option_register(registry
, ZEND_STRL("tcp_keepalive"), CURLOPT_TCP_KEEPALIVE
, _IS_BOOL
);
1470 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tcp_keepidle"), CURLOPT_TCP_KEEPIDLE
, IS_LONG
))) {
1471 Z_LVAL(opt
->defval
) = 60;
1473 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tcp_keepintvl"), CURLOPT_TCP_KEEPINTVL
, IS_LONG
))) {
1474 Z_LVAL(opt
->defval
) = 60;
1479 if ((opt
= php_http_option_register(registry
, ZEND_STRL("ssl"), 0, IS_ARRAY
))) {
1480 registry
= &opt
->suboptions
;
1482 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cert"), CURLOPT_SSLCERT
, IS_STRING
))) {
1483 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1484 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1486 if ((opt
= php_http_option_register(registry
, ZEND_STRL("certtype"), CURLOPT_SSLCERTTYPE
, IS_STRING
))) {
1487 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1488 ZVAL_PSTRING(&opt
->defval
, "PEM");
1490 if ((opt
= php_http_option_register(registry
, ZEND_STRL("key"), CURLOPT_SSLKEY
, IS_STRING
))) {
1491 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1492 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1494 if ((opt
= php_http_option_register(registry
, ZEND_STRL("keytype"), CURLOPT_SSLKEYTYPE
, IS_STRING
))) {
1495 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1496 ZVAL_PSTRING(&opt
->defval
, "PEM");
1498 if ((opt
= php_http_option_register(registry
, ZEND_STRL("keypasswd"), CURLOPT_SSLKEYPASSWD
, IS_STRING
))) {
1499 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1501 php_http_option_register(registry
, ZEND_STRL("engine"), CURLOPT_SSLENGINE
, IS_STRING
);
1502 php_http_option_register(registry
, ZEND_STRL("version"), CURLOPT_SSLVERSION
, IS_LONG
);
1503 if ((opt
= php_http_option_register(registry
, ZEND_STRL("verifypeer"), CURLOPT_SSL_VERIFYPEER
, _IS_BOOL
))) {
1504 ZVAL_BOOL(&opt
->defval
, 1);
1506 if ((opt
= php_http_option_register(registry
, ZEND_STRL("verifyhost"), CURLOPT_SSL_VERIFYHOST
, _IS_BOOL
))) {
1507 ZVAL_BOOL(&opt
->defval
, 1);
1508 opt
->setter
= php_http_curle_option_set_ssl_verifyhost
;
1510 #if PHP_HTTP_CURL_VERSION(7,41,0) && (defined(PHP_HTTP_HAVE_OPENSSL) || defined(PHP_HTTP_HAVE_NSS) || defined(PHP_HTTP_HAVE_GNUTLS))
1511 php_http_option_register(registry
, ZEND_STRL("verifystatus"), CURLOPT_SSL_VERIFYSTATUS
, _IS_BOOL
);
1513 php_http_option_register(registry
, ZEND_STRL("cipher_list"), CURLOPT_SSL_CIPHER_LIST
, IS_STRING
);
1514 if ((opt
= php_http_option_register(registry
, ZEND_STRL("cainfo"), CURLOPT_CAINFO
, IS_STRING
))) {
1515 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1516 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1517 #ifdef PHP_HTTP_CURL_CAINFO
1518 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CURL_CAINFO
);
1521 if ((opt
= php_http_option_register(registry
, ZEND_STRL("capath"), CURLOPT_CAPATH
, IS_STRING
))) {
1522 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1523 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1524 #ifdef PHP_HTTP_CURL_CAPATH
1525 ZVAL_PSTRING(&opt
->defval
, PHP_HTTP_CURL_CAPATH
);
1528 if ((opt
= php_http_option_register(registry
, ZEND_STRL("random_file"), CURLOPT_RANDOM_FILE
, IS_STRING
))) {
1529 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1530 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1532 if ((opt
= php_http_option_register(registry
, ZEND_STRL("egdsocket"), CURLOPT_EGDSOCKET
, IS_STRING
))) {
1533 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1534 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1536 #if PHP_HTTP_CURL_VERSION(7,19,0)
1537 if ((opt
= php_http_option_register(registry
, ZEND_STRL("issuercert"), CURLOPT_ISSUERCERT
, IS_STRING
))) {
1538 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1539 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1541 # ifdef PHP_HTTP_HAVE_OPENSSL
1542 if ((opt
= php_http_option_register(registry
, ZEND_STRL("crlfile"), CURLOPT_CRLFILE
, IS_STRING
))) {
1543 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1544 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1548 #if (PHP_HTTP_CURL_VERSION(7,19,1) && defined(PHP_HTTP_HAVE_OPENSSL)) || (PHP_HTTP_CURL_VERSION(7,34,0) && defined(PHP_HTTP_HAVE_NSS)) || (PHP_HTTP_CURL_VERSION(7,42,0) && defined(PHP_HTTP_HAVE_GNUTLS)) || (PHP_HTTP_CURL_VERSION(7,39,0) && defined(PHP_HTTP_HAVE_GSKIT))
1549 if ((opt
= php_http_option_register(registry
, ZEND_STRL("certinfo"), CURLOPT_CERTINFO
, _IS_BOOL
))) {
1550 ZVAL_FALSE(&opt
->defval
);
1553 #if PHP_HTTP_CURL_VERSION(7,36,0)
1554 if ((opt
= php_http_option_register(registry
, ZEND_STRL("enable_npn"), CURLOPT_SSL_ENABLE_NPN
, _IS_BOOL
))) {
1555 ZVAL_BOOL(&opt
->defval
, 1);
1557 if ((opt
= php_http_option_register(registry
, ZEND_STRL("enable_alpn"), CURLOPT_SSL_ENABLE_ALPN
, _IS_BOOL
))) {
1558 ZVAL_BOOL(&opt
->defval
, 1);
1561 #if PHP_HTTP_CURL_VERSION(7,39,0)
1562 /* FIXME: see http://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html#AVAILABILITY */
1563 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pinned_publickey"), CURLOPT_PINNEDPUBLICKEY
, IS_STRING
))) {
1564 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1565 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
;
1568 #if PHP_HTTP_CURL_VERSION(7,21,4) && defined(PHP_HTTP_CURL_TLSAUTH_SRP)
1569 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tlsauthtype"), CURLOPT_TLSAUTH_TYPE
, IS_LONG
))) {
1570 opt
->setter
= php_http_curle_option_set_ssl_tlsauthtype
;
1572 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tlsauthuser"), CURLOPT_TLSAUTH_USERNAME
, IS_STRING
))) {
1573 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1575 if ((opt
= php_http_option_register(registry
, ZEND_STRL("tlsauthpass"), CURLOPT_TLSAUTH_PASSWORD
, IS_STRING
))) {
1576 opt
->flags
|= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
;
1579 #if PHP_HTTP_CURL_VERSION(7,42,0) && (defined(PHP_HTTP_HAVE_NSS) || defined(PHP_HTTP_HAVE_DARWINSSL))
1580 php_http_option_register(registry
, ZEND_STRL("falsestart"), CURLOPT_SSL_FALSESTART
, _IS_BOOL
);
1585 static zval
*php_http_curle_get_option(php_http_option_t
*opt
, HashTable
*options
, void *userdata
)
1587 php_http_client_curl_handler_t
*curl
= userdata
;
1590 if ((option
= php_http_option_get(opt
, options
, NULL
))) {
1593 ZVAL_DUP(&zopt
, option
);
1594 convert_to_explicit_type(&zopt
, opt
->type
);
1595 zend_hash_update(&curl
->options
.cache
, opt
->name
, &zopt
);
1596 return zend_hash_find(&curl
->options
.cache
, opt
->name
);
1601 static ZEND_RESULT_CODE
php_http_curle_set_option(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1603 php_http_client_curl_handler_t
*curl
= userdata
;
1604 CURL
*ch
= curl
->handle
;
1606 CURLcode rc
= CURLE_OK
;
1607 ZEND_RESULT_CODE rv
= SUCCESS
;
1613 switch (opt
->type
) {
1616 rv
= opt
->setter(opt
, val
, curl
);
1617 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, (long) (Z_TYPE_P(val
) == IS_TRUE
))) {
1624 rv
= opt
->setter(opt
, val
, curl
);
1625 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, Z_LVAL_P(val
))) {
1632 rv
= opt
->setter(opt
, val
, curl
);
1633 } else if (!val
|| Z_TYPE_P(val
) == IS_NULL
) {
1634 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1637 } else if ((opt
->flags
& PHP_HTTP_CURLE_OPTION_CHECK_STRLEN
) && !Z_STRLEN_P(val
)) {
1638 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1641 } else if ((opt
->flags
& PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR
) && Z_STRVAL_P(val
) && SUCCESS
!= php_check_open_basedir(Z_STRVAL_P(val
))) {
1642 if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, NULL
))) {
1645 } else if (CURLE_OK
!= (rc
= curl_easy_setopt(ch
, opt
->option
, Z_STRVAL_P(val
)))) {
1651 if (opt
->flags
& PHP_HTTP_CURLE_OPTION_TRANSFORM_MS
) {
1653 Z_DVAL(tmp
) *= 1000;
1657 rv
= opt
->setter(opt
, val
, curl
);
1658 } else if (CURLE_OK
!= curl_easy_setopt(ch
, opt
->option
, (long) Z_DVAL_P(val
))) {
1665 rv
= opt
->setter(opt
, val
, curl
);
1666 } else if (Z_TYPE_P(val
) != IS_NULL
) {
1667 rv
= php_http_options_apply(&opt
->suboptions
, Z_ARRVAL_P(val
), curl
);
1673 rv
= opt
->setter(opt
, val
, curl
);
1679 if (rv
!= SUCCESS
) {
1680 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_easy_strerror(rc
));
1685 #if PHP_HTTP_CURL_VERSION(7,30,0)
1686 static ZEND_RESULT_CODE
php_http_curlm_option_set_pipelining_bl(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1688 php_http_client_t
*client
= userdata
;
1689 php_http_client_curl_t
*curl
= client
->ctx
;
1690 CURLM
*ch
= curl
->handle
->multi
;
1694 /* array of char *, ending with a NULL */
1695 if (value
&& Z_TYPE_P(value
) != IS_NULL
) {
1697 HashTable
*ht
= HASH_OF(value
);
1698 int c
= zend_hash_num_elements(ht
);
1699 char **ptr
= ecalloc(c
+ 1, sizeof(char *));
1703 zend_hash_init(&tmp_ht
, c
, NULL
, ZVAL_PTR_DTOR
, 0);
1704 array_join(ht
, &tmp_ht
, 0, ARRAY_JOIN_STRINGIFY
);
1706 ZEND_HASH_FOREACH_VAL(&tmp_ht
, entry
)
1708 *ptr
++ = Z_STRVAL_P(entry
);
1710 ZEND_HASH_FOREACH_END();
1713 if (CURLM_OK
!= curl_multi_setopt(ch
, opt
->option
, bl
)) {
1716 zend_hash_destroy(&tmp_ht
);
1723 zend_hash_destroy(&tmp_ht
);
1729 #if PHP_HTTP_HAVE_EVENT
1730 static inline ZEND_RESULT_CODE
php_http_curlm_use_eventloop(php_http_client_t
*h
, zend_bool enable
)
1732 php_http_client_curl_t
*curl
= h
->ctx
;
1734 if ((curl
->useevents
= enable
)) {
1735 if (!curl
->evbase
) {
1736 curl
->evbase
= event_base_new();
1738 if (!curl
->timeout
) {
1739 curl
->timeout
= ecalloc(1, sizeof(struct event
));
1741 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_SOCKETDATA
, h
);
1742 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_SOCKETFUNCTION
, php_http_curlm_socket_callback
);
1743 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_TIMERDATA
, h
);
1744 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_TIMERFUNCTION
, php_http_curlm_timer_callback
);
1746 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_SOCKETDATA
, NULL
);
1747 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_SOCKETFUNCTION
, NULL
);
1748 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_TIMERDATA
, NULL
);
1749 curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_TIMERFUNCTION
, NULL
);
1755 static ZEND_RESULT_CODE
php_http_curlm_option_set_use_eventloop(php_http_option_t
*opt
, zval
*value
, void *userdata
)
1757 php_http_client_t
*client
= userdata
;
1759 return php_http_curlm_use_eventloop(client
, value
&& Z_TYPE_P(value
) == IS_TRUE
);
1763 static void php_http_curlm_options_init(php_http_options_t
*registry
)
1765 php_http_option_t
*opt
;
1767 /* set size of connection cache */
1768 if ((opt
= php_http_option_register(registry
, ZEND_STRL("maxconnects"), CURLMOPT_MAXCONNECTS
, IS_LONG
))) {
1769 /* -1 == default, 0 == unlimited */
1770 ZVAL_LONG(&opt
->defval
, -1);
1772 /* set max number of connections to a single host */
1773 #if PHP_HTTP_CURL_VERSION(7,30,0)
1774 php_http_option_register(registry
, ZEND_STRL("max_host_connections"), CURLMOPT_MAX_HOST_CONNECTIONS
, IS_LONG
);
1776 /* maximum number of requests in a pipeline */
1777 #if PHP_HTTP_CURL_VERSION(7,30,0)
1778 if ((opt
= php_http_option_register(registry
, ZEND_STRL("max_pipeline_length"), CURLMOPT_MAX_PIPELINE_LENGTH
, IS_LONG
))) {
1779 ZVAL_LONG(&opt
->defval
, 5);
1782 /* max simultaneously open connections */
1783 #if PHP_HTTP_CURL_VERSION(7,30,0)
1784 php_http_option_register(registry
, ZEND_STRL("max_total_connections"), CURLMOPT_MAX_TOTAL_CONNECTIONS
, IS_LONG
);
1786 /* enable/disable HTTP pipelining */
1787 php_http_option_register(registry
, ZEND_STRL("pipelining"), CURLMOPT_PIPELINING
, _IS_BOOL
);
1788 /* chunk length threshold for pipelining */
1789 #if PHP_HTTP_CURL_VERSION(7,30,0)
1790 php_http_option_register(registry
, ZEND_STRL("chunk_length_penalty_size"), CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE
, IS_LONG
);
1792 /* size threshold for pipelining penalty */
1793 #if PHP_HTTP_CURL_VERSION(7,30,0)
1794 php_http_option_register(registry
, ZEND_STRL("content_length_penalty_size"), CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE
, IS_LONG
);
1796 /* pipelining server blacklist */
1797 #if PHP_HTTP_CURL_VERSION(7,30,0)
1798 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pipelining_server_bl"), CURLMOPT_PIPELINING_SERVER_BL
, IS_ARRAY
))) {
1799 opt
->setter
= php_http_curlm_option_set_pipelining_bl
;
1802 /* pipelining host blacklist */
1803 #if PHP_HTTP_CURL_VERSION(7,30,0)
1804 if ((opt
= php_http_option_register(registry
, ZEND_STRL("pipelining_site_bl"), CURLMOPT_PIPELINING_SITE_BL
, IS_ARRAY
))) {
1805 opt
->setter
= php_http_curlm_option_set_pipelining_bl
;
1809 #if PHP_HTTP_HAVE_EVENT
1810 if ((opt
= php_http_option_register(registry
, ZEND_STRL("use_eventloop"), 0, _IS_BOOL
))) {
1811 opt
->setter
= php_http_curlm_option_set_use_eventloop
;
1816 static ZEND_RESULT_CODE
php_http_curlm_set_option(php_http_option_t
*opt
, zval
*val
, void *userdata
)
1818 php_http_client_t
*client
= userdata
;
1819 php_http_client_curl_t
*curl
= client
->ctx
;
1820 CURLM
*ch
= curl
->handle
->multi
;
1822 CURLMcode rc
= CURLM_UNKNOWN_OPTION
;
1823 ZEND_RESULT_CODE rv
= SUCCESS
;
1827 } else if (opt
->type
&& Z_TYPE_P(val
) != opt
->type
&& !(Z_TYPE_P(val
) == IS_NULL
&& opt
->type
== IS_ARRAY
)) {
1830 ZVAL_DUP(&zopt
, val
);
1831 convert_to_explicit_type(&zopt
, opt
->type
);
1837 rv
= opt
->setter(opt
, val
, client
);
1839 switch (opt
->type
) {
1841 if (CURLM_OK
!= (rc
= curl_multi_setopt(ch
, opt
->option
, (long) zend_is_true(val
)))) {
1846 if (CURLM_OK
!= (rc
= curl_multi_setopt(ch
, opt
->option
, Z_LVAL_P(val
)))) {
1856 if (val
&& val
!= orig
&& val
!= &opt
->defval
) {
1860 if (rv
!= SUCCESS
) {
1861 php_error_docref(NULL
, E_NOTICE
, "Could not set option %s (%s)", opt
->name
->val
, curl_easy_strerror(rc
));
1868 static ZEND_RESULT_CODE
php_http_client_curl_handler_reset(php_http_client_curl_handler_t
*curl
)
1870 CURL
*ch
= curl
->handle
;
1871 php_http_curle_storage_t
*st
;
1873 if ((st
= php_http_curle_get_storage(ch
))) {
1878 if (st
->cookiestore
) {
1879 pefree(st
->cookiestore
, 1);
1880 st
->cookiestore
= NULL
;
1882 st
->errorbuffer
[0] = '\0';
1886 curl_easy_setopt(ch
, CURLOPT_URL
, NULL
);
1887 curl_easy_setopt(ch
, CURLOPT_CUSTOMREQUEST
, NULL
);
1888 curl_easy_setopt(ch
, CURLOPT_HTTPGET
, 1L);
1889 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 0L);
1890 /* libcurl < 7.19.6 does not clear auth info with USERPWD set to NULL */
1891 #if PHP_HTTP_CURL_VERSION(7,19,1)
1892 curl_easy_setopt(ch
, CURLOPT_PROXYUSERNAME
, NULL
);
1893 curl_easy_setopt(ch
, CURLOPT_PROXYPASSWORD
, NULL
);
1894 curl_easy_setopt(ch
, CURLOPT_USERNAME
, NULL
);
1895 curl_easy_setopt(ch
, CURLOPT_PASSWORD
, NULL
);
1898 #if PHP_HTTP_CURL_VERSION(7,21,3)
1899 if (curl
->options
.resolve
) {
1900 curl_slist_free_all(curl
->options
.resolve
);
1901 curl
->options
.resolve
= NULL
;
1904 curl
->options
.retry
.count
= 0;
1905 curl
->options
.retry
.delay
= 0;
1906 curl
->options
.redirects
= 0;
1907 curl
->options
.encode_cookies
= 1;
1909 if (curl
->options
.headers
) {
1910 curl_slist_free_all(curl
->options
.headers
);
1911 curl
->options
.headers
= NULL
;
1913 if (curl
->options
.proxyheaders
) {
1914 curl_slist_free_all(curl
->options
.proxyheaders
);
1915 curl
->options
.proxyheaders
= NULL
;
1918 php_http_buffer_reset(&curl
->options
.cookies
);
1919 php_http_buffer_reset(&curl
->options
.ranges
);
1924 static php_http_client_curl_handler_t
*php_http_client_curl_handler_init(php_http_client_t
*h
, php_resource_factory_t
*rf
)
1927 php_http_client_curl_t
*curl
= h
->ctx
;
1928 php_http_client_curl_handler_t
*handler
;
1930 if (!(handle
= php_resource_factory_handle_ctor(rf
, NULL
))) {
1931 php_error_docref(NULL
, E_WARNING
, "Failed to initialize curl handle");
1935 handler
= ecalloc(1, sizeof(*handler
));
1937 handler
->client
= h
;
1938 handler
->handle
= handle
;
1939 handler
->response
.body
= php_http_message_body_init(NULL
, NULL
);
1940 php_http_buffer_init(&handler
->response
.headers
);
1941 php_http_buffer_init(&handler
->options
.cookies
);
1942 php_http_buffer_init(&handler
->options
.ranges
);
1943 zend_hash_init(&handler
->options
.cache
, 0, NULL
, ZVAL_PTR_DTOR
, 0);
1946 curl_easy_setopt(handle
, CURLOPT_NOSIGNAL
, 1L);
1948 curl_easy_setopt(handle
, CURLOPT_HEADER
, 0L);
1949 curl_easy_setopt(handle
, CURLOPT_FILETIME
, 1L);
1950 curl_easy_setopt(handle
, CURLOPT_AUTOREFERER
, 1L);
1951 curl_easy_setopt(handle
, CURLOPT_VERBOSE
, 1L);
1952 curl_easy_setopt(handle
, CURLOPT_NOPROGRESS
, 0L);
1953 curl_easy_setopt(handle
, CURLOPT_HEADERFUNCTION
, php_http_curle_header_callback
);
1954 curl_easy_setopt(handle
, CURLOPT_WRITEFUNCTION
, php_http_curle_body_callback
);
1955 curl_easy_setopt(handle
, CURLOPT_DEBUGFUNCTION
, php_http_curle_raw_callback
);
1956 curl_easy_setopt(handle
, CURLOPT_READFUNCTION
, php_http_curle_read_callback
);
1957 curl_easy_setopt(handle
, CURLOPT_SEEKFUNCTION
, php_http_curle_seek_callback
);
1958 #if PHP_HTTP_CURL_VERSION(7,32,0)
1959 curl_easy_setopt(handle
, CURLOPT_XFERINFOFUNCTION
, php_http_curle_xferinfo_callback
);
1960 curl_easy_setopt(handle
, CURLOPT_XFERINFODATA
, handler
);
1962 curl_easy_setopt(handle
, CURLOPT_PROGRESSFUNCTION
, php_http_curle_progress_callback
);
1963 curl_easy_setopt(handle
, CURLOPT_PROGRESSDATA
, handler
);
1965 curl_easy_setopt(handle
, CURLOPT_DEBUGDATA
, handler
);
1966 curl_easy_setopt(handle
, CURLOPT_WRITEDATA
, handler
);
1967 curl_easy_setopt(handle
, CURLOPT_HEADERDATA
, handler
);
1968 curl_easy_setopt(handle
, CURLOPT_SHARE
, curl
->handle
->share
);
1970 php_http_client_curl_handler_reset(handler
);
1976 static ZEND_RESULT_CODE
php_http_client_curl_handler_prepare(php_http_client_curl_handler_t
*curl
, php_http_client_enqueue_t
*enqueue
)
1979 php_http_message_t
*msg
= enqueue
->request
;
1980 php_http_curle_storage_t
*storage
= php_http_curle_get_storage(curl
->handle
);
1983 if (!PHP_HTTP_INFO(msg
).request
.url
) {
1984 php_error_docref(NULL
, E_WARNING
, "Cannot request empty URL");
1987 storage
->errorbuffer
[0] = '\0';
1989 pefree(storage
->url
, 1);
1991 php_http_url_to_string(PHP_HTTP_INFO(msg
).request
.url
, &storage
->url
, NULL
, 1);
1992 curl_easy_setopt(curl
->handle
, CURLOPT_URL
, storage
->url
);
1995 php_http_options_apply(&php_http_curle_options
, enqueue
->options
, curl
);
1997 /* request headers */
1998 php_http_message_update_headers(msg
);
1999 if (zend_hash_num_elements(&msg
->hdrs
)) {
2000 php_http_arrkey_t header_key
;
2002 zend_string
*header_str
;
2003 php_http_buffer_t header
;
2004 #if !PHP_HTTP_CURL_VERSION(7,23,0)
2005 zval
*ct
= zend_hash_str_find(&msg
->hdrs
, ZEND_STRL("Content-Length"));
2008 php_http_buffer_init(&header
);
2009 ZEND_HASH_FOREACH_KEY_VAL(&msg
->hdrs
, header_key
.h
, header_key
.key
, header_val
)
2011 if (header_key
.key
) {
2012 #if !PHP_HTTP_CURL_VERSION(7,23,0)
2013 /* avoid duplicate content-length header */
2014 if (ct
&& ct
== header_val
) {
2018 header_str
= zval_get_string(header_val
);
2019 php_http_buffer_appendf(&header
, "%s: %s", header_key
.key
->val
, header_str
->val
);
2020 php_http_buffer_fix(&header
);
2021 curl
->options
.headers
= curl_slist_append(curl
->options
.headers
, header
.data
);
2022 php_http_buffer_reset(&header
);
2023 zend_string_release(header_str
);
2026 ZEND_HASH_FOREACH_END();
2027 php_http_buffer_dtor(&header
);
2029 curl_easy_setopt(curl
->handle
, CURLOPT_HTTPHEADER
, curl
->options
.headers
);
2031 /* attach request body */
2032 if ((body_size
= php_http_message_body_size(msg
->body
))) {
2033 /* RFC2616, section 4.3 (para. 4) states that »a message-body MUST NOT be included in a request if the
2034 * specification of the request method (section 5.1.1) does not allow sending an entity-body in request.«
2035 * Following the clause in section 5.1.1 (para. 2) that request methods »MUST be implemented with the
2036 * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method
2037 * does not allow a request body.
2039 php_stream_rewind(php_http_message_body_stream(msg
->body
));
2040 curl_easy_setopt(curl
->handle
, CURLOPT_SEEKDATA
, msg
->body
);
2041 curl_easy_setopt(curl
->handle
, CURLOPT_READDATA
, msg
->body
);
2042 curl_easy_setopt(curl
->handle
, CURLOPT_INFILESIZE
, body_size
);
2043 curl_easy_setopt(curl
->handle
, CURLOPT_POSTFIELDSIZE
, body_size
);
2044 curl_easy_setopt(curl
->handle
, CURLOPT_POST
, 1L);
2046 curl_easy_setopt(curl
->handle
, CURLOPT_SEEKDATA
, NULL
);
2047 curl_easy_setopt(curl
->handle
, CURLOPT_READDATA
, NULL
);
2048 curl_easy_setopt(curl
->handle
, CURLOPT_INFILESIZE
, 0L);
2049 curl_easy_setopt(curl
->handle
, CURLOPT_POSTFIELDSIZE
, 0L);
2053 * Always use CUSTOMREQUEST, else curl won't send any request body for GET etc.
2054 * See e.g. bug #69313.
2056 * Here's what curl does:
2057 * - CURLOPT_HTTPGET: ignore request body
2058 * - CURLOPT_UPLOAD: set "Expect: 100-continue" header
2059 * - CURLOPT_POST: set "Content-Type: application/x-www-form-urlencoded" header
2060 * Now select the least bad.
2062 * See also https://tools.ietf.org/html/rfc7231#section-5.1.1
2064 if (PHP_HTTP_INFO(msg
).request
.method
) {
2065 switch(php_http_select_str(PHP_HTTP_INFO(msg
).request
.method
, 2, "HEAD", "PUT")) {
2067 curl_easy_setopt(curl
->handle
, CURLOPT_NOBODY
, 1L);
2070 curl_easy_setopt(curl
->handle
, CURLOPT_UPLOAD
, 1L);
2073 curl_easy_setopt(curl
->handle
, CURLOPT_CUSTOMREQUEST
, PHP_HTTP_INFO(msg
).request
.method
);
2076 php_error_docref(NULL
, E_WARNING
, "Cannot use empty request method");
2083 static void php_http_client_curl_handler_clear(php_http_client_curl_handler_t
*handler
)
2085 curl_easy_setopt(handler
->handle
, CURLOPT_NOPROGRESS
, 1L);
2086 #if PHP_HTTP_CURL_VERSION(7,32,0)
2087 curl_easy_setopt(handler
->handle
, CURLOPT_XFERINFOFUNCTION
, NULL
);
2089 curl_easy_setopt(handler
->handle
, CURLOPT_PROGRESSFUNCTION
, NULL
);
2091 curl_easy_setopt(handler
->handle
, CURLOPT_VERBOSE
, 0L);
2092 curl_easy_setopt(handler
->handle
, CURLOPT_DEBUGFUNCTION
, NULL
);
2093 curl_easy_setopt(handler
->handle
, CURLOPT_COOKIELIST
, "FLUSH");
2094 curl_easy_setopt(handler
->handle
, CURLOPT_SHARE
, NULL
);
2097 static void php_http_client_curl_handler_dtor(php_http_client_curl_handler_t
*handler
)
2099 php_http_client_curl_handler_clear(handler
);
2101 php_resource_factory_handle_dtor(handler
->rf
, handler
->handle
);
2102 php_resource_factory_free(&handler
->rf
);
2104 php_http_message_body_free(&handler
->response
.body
);
2105 php_http_buffer_dtor(&handler
->response
.headers
);
2106 php_http_buffer_dtor(&handler
->options
.ranges
);
2107 php_http_buffer_dtor(&handler
->options
.cookies
);
2108 zend_hash_destroy(&handler
->options
.cache
);
2110 #if PHP_HTTP_CURL_VERSION(7,21,3)
2111 if (handler
->options
.resolve
) {
2112 curl_slist_free_all(handler
->options
.resolve
);
2113 handler
->options
.resolve
= NULL
;
2117 if (handler
->options
.headers
) {
2118 curl_slist_free_all(handler
->options
.headers
);
2119 handler
->options
.headers
= NULL
;
2122 if (handler
->options
.proxyheaders
) {
2123 curl_slist_free_all(handler
->options
.proxyheaders
);
2124 handler
->options
.proxyheaders
= NULL
;
2130 static php_http_client_t
*php_http_client_curl_init(php_http_client_t
*h
, void *handle
)
2132 php_http_client_curl_t
*curl
;
2134 if (!handle
&& !(handle
= php_resource_factory_handle_ctor(h
->rf
, NULL
))) {
2135 php_error_docref(NULL
, E_WARNING
, "Failed to initialize curl handle");
2139 curl
= ecalloc(1, sizeof(*curl
));
2140 curl
->handle
= handle
;
2141 curl
->unfinished
= 0;
2147 static void php_http_client_curl_dtor(php_http_client_t
*h
)
2149 php_http_client_curl_t
*curl
= h
->ctx
;
2151 #if PHP_HTTP_HAVE_EVENT
2152 if (curl
->timeout
) {
2153 if (event_initialized(curl
->timeout
) && event_pending(curl
->timeout
, EV_TIMEOUT
, NULL
)) {
2154 event_del(curl
->timeout
);
2156 efree(curl
->timeout
);
2157 curl
->timeout
= NULL
;
2160 event_base_free(curl
->evbase
);
2161 curl
->evbase
= NULL
;
2164 curl
->unfinished
= 0;
2166 php_resource_factory_handle_dtor(h
->rf
, curl
->handle
);
2172 static void queue_dtor(php_http_client_enqueue_t
*e
)
2174 php_http_client_curl_handler_t
*handler
= e
->opaque
;
2176 if (handler
->queue
.dtor
) {
2177 e
->opaque
= handler
->queue
.opaque
;
2178 handler
->queue
.dtor(e
);
2180 php_http_client_curl_handler_dtor(handler
);
2183 static php_resource_factory_t
*create_rf(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2185 php_persistent_handle_factory_t
*pf
= NULL
;
2186 php_resource_factory_t
*rf
= NULL
;
2187 php_http_url_t
*url
= enqueue
->request
->http
.info
.request
.url
;
2189 if (!url
|| (!url
->host
&& !url
->path
)) {
2190 php_error_docref(NULL
, E_WARNING
, "Cannot request empty URL");
2194 /* only if the client itself is setup for persistence */
2195 if (php_resource_factory_is_persistent(h
->rf
)) {
2197 char *id_str
= NULL
;
2199 int port
= url
->port
? url
->port
: 80;
2201 php_persistent_handle_factory_t
*phf
= h
->rf
->data
;
2203 if ((zport
= zend_hash_str_find(enqueue
->options
, ZEND_STRL("port")))) {
2204 zend_long lport
= zval_get_long(zport
);
2211 id_len
= spprintf(&id_str
, 0, "%.*s:%s:%d", (int) phf
->ident
->len
, phf
->ident
->val
, STR_PTR(url
->host
), port
);
2212 id
= php_http_cs2zs(id_str
, id_len
);
2213 pf
= php_persistent_handle_concede(NULL
, PHP_HTTP_G
->client
.curl
.driver
.request_name
, id
, NULL
, NULL
);
2214 zend_string_release(id
);
2218 rf
= php_persistent_handle_resource_factory_init(NULL
, pf
);
2220 rf
= php_resource_factory_init(NULL
, &php_http_curle_resource_factory_ops
, NULL
, NULL
);
2226 static ZEND_RESULT_CODE
php_http_client_curl_enqueue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2229 php_http_client_curl_t
*curl
= h
->ctx
;
2230 php_http_client_curl_handler_t
*handler
;
2231 php_http_client_progress_state_t
*progress
;
2232 php_resource_factory_t
*rf
;
2234 rf
= create_rf(h
, enqueue
);
2239 handler
= php_http_client_curl_handler_init(h
, rf
);
2244 if (SUCCESS
!= php_http_client_curl_handler_prepare(handler
, enqueue
)) {
2245 php_http_client_curl_handler_dtor(handler
);
2249 handler
->queue
= *enqueue
;
2250 enqueue
->opaque
= handler
;
2251 enqueue
->dtor
= queue_dtor
;
2253 if (CURLM_OK
!= (rs
= curl_multi_add_handle(curl
->handle
->multi
, handler
->handle
))) {
2254 php_http_client_curl_handler_dtor(handler
);
2255 php_error_docref(NULL
, E_WARNING
, "Could not enqueue request: %s", curl_multi_strerror(rs
));
2259 zend_llist_add_element(&h
->requests
, enqueue
);
2262 if (h
->callback
.progress
.func
&& SUCCESS
== php_http_client_getopt(h
, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
, enqueue
->request
, &progress
)) {
2263 progress
->info
= "start";
2264 h
->callback
.progress
.func(h
->callback
.progress
.arg
, h
, &handler
->queue
, progress
);
2265 progress
->started
= 1;
2271 static ZEND_RESULT_CODE
php_http_client_curl_dequeue(php_http_client_t
*h
, php_http_client_enqueue_t
*enqueue
)
2274 php_http_client_curl_t
*curl
= h
->ctx
;
2275 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2277 php_http_client_curl_handler_clear(handler
);
2278 if (CURLM_OK
== (rs
= curl_multi_remove_handle(curl
->handle
->multi
, handler
->handle
))) {
2279 zend_llist_del_element(&h
->requests
, handler
->handle
, (int (*)(void *, void *)) compare_queue
);
2282 php_error_docref(NULL
, E_WARNING
, "Could not dequeue request: %s", curl_multi_strerror(rs
));
2288 static void php_http_client_curl_reset(php_http_client_t
*h
)
2290 zend_llist_element
*next_el
, *this_el
;
2292 for (this_el
= h
->requests
.head
; this_el
; this_el
= next_el
) {
2293 next_el
= this_el
->next
;
2294 php_http_client_curl_dequeue(h
, (void *) this_el
->data
);
2298 static inline void php_http_client_curl_get_timeout(php_http_client_curl_t
*curl
, long max_tout
, struct timeval
*timeout
)
2300 if ((CURLM_OK
== curl_multi_timeout(curl
->handle
->multi
, &max_tout
)) && (max_tout
> 0)) {
2301 timeout
->tv_sec
= max_tout
/ 1000;
2302 timeout
->tv_usec
= (max_tout
% 1000) * 1000;
2304 timeout
->tv_sec
= 0;
2305 timeout
->tv_usec
= 1000;
2310 # define SELECT_ERROR SOCKET_ERROR
2312 # define SELECT_ERROR -1
2315 static ZEND_RESULT_CODE
php_http_client_curl_wait(php_http_client_t
*h
, struct timeval
*custom_timeout
)
2319 struct timeval timeout
;
2320 php_http_client_curl_t
*curl
= h
->ctx
;
2322 #if PHP_HTTP_HAVE_EVENT
2323 if (curl
->useevents
) {
2324 if (!event_initialized(curl
->timeout
)) {
2325 event_assign(curl
->timeout
, curl
->evbase
, CURL_SOCKET_TIMEOUT
, 0, php_http_curlm_timeout_callback
, h
);
2326 } else if (custom_timeout
&& timerisset(custom_timeout
)) {
2327 event_add(curl
->timeout
, custom_timeout
);
2328 } else if (!event_pending(curl
->timeout
, EV_TIMEOUT
, NULL
)) {
2329 php_http_client_curl_get_timeout(curl
, 1000, &timeout
);
2330 event_add(curl
->timeout
, &timeout
);
2333 event_base_loop(curl
->evbase
, EVLOOP_ONCE
);
2343 if (CURLM_OK
== curl_multi_fdset(curl
->handle
->multi
, &R
, &W
, &E
, &MAX
)) {
2344 if (custom_timeout
&& timerisset(custom_timeout
)) {
2345 timeout
= *custom_timeout
;
2347 php_http_client_curl_get_timeout(curl
, 1000, &timeout
);
2351 php_http_sleep((double) timeout
.tv_sec
+ (double) (timeout
.tv_usec
/ PHP_HTTP_MCROSEC
));
2353 } else if (SELECT_ERROR
!= select(MAX
+ 1, &R
, &W
, &E
, &timeout
)) {
2360 static int php_http_client_curl_once(php_http_client_t
*h
)
2362 php_http_client_curl_t
*curl
= h
->ctx
;
2364 #if PHP_HTTP_HAVE_EVENT
2365 if (curl
->useevents
) {
2366 event_base_loop(curl
->evbase
, EVLOOP_NONBLOCK
);
2369 while (CURLM_CALL_MULTI_PERFORM
== curl_multi_perform(curl
->handle
->multi
, &curl
->unfinished
));
2371 php_http_curlm_responsehandler(h
);
2373 return curl
->unfinished
;
2377 static ZEND_RESULT_CODE
php_http_client_curl_exec(php_http_client_t
*h
)
2379 #if PHP_HTTP_HAVE_EVENT
2380 php_http_client_curl_t
*curl
= h
->ctx
;
2382 if (curl
->useevents
) {
2383 php_http_curlm_timeout_callback(CURL_SOCKET_TIMEOUT
, /*EV_READ|EV_WRITE*/0, h
);
2385 int ev_rc
= event_base_dispatch(curl
->evbase
);
2388 fprintf(stderr
, "%c", "X.0"[ev_rc
+1]);
2392 php_error_docref(NULL
, E_ERROR
, "Error in event_base_dispatch()");
2395 } while (curl
->unfinished
&& !EG(exception
));
2399 while (php_http_client_curl_once(h
) && !EG(exception
)) {
2400 if (SUCCESS
!= php_http_client_curl_wait(h
, NULL
)) {
2402 /* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */
2403 php_error_docref(NULL
, E_WARNING
, "WinSock error: %d", WSAGetLastError());
2405 php_error_docref(NULL
, E_WARNING
, "%s", strerror(errno
));
2415 static ZEND_RESULT_CODE
php_http_client_curl_setopt(php_http_client_t
*h
, php_http_client_setopt_opt_t opt
, void *arg
)
2417 php_http_client_curl_t
*curl
= h
->ctx
;
2420 case PHP_HTTP_CLIENT_OPT_CONFIGURATION
:
2421 return php_http_options_apply(&php_http_curlm_options
, (HashTable
*) arg
, h
);
2424 case PHP_HTTP_CLIENT_OPT_ENABLE_PIPELINING
:
2425 if (CURLM_OK
!= curl_multi_setopt(curl
->handle
->multi
, CURLMOPT_PIPELINING
, (long) *((zend_bool
*) arg
))) {
2430 case PHP_HTTP_CLIENT_OPT_USE_EVENTS
:
2431 #if PHP_HTTP_HAVE_EVENT
2432 return php_http_curlm_use_eventloop(h
, *(zend_bool
*) arg
);
2442 static int apply_available_options(zval
*pDest
, int num_args
, va_list args
, zend_hash_key
*hash_key
)
2444 php_http_option_t
*opt
= Z_PTR_P(pDest
);
2449 ht
= va_arg(args
, HashTable
*);
2451 if ((c
= zend_hash_num_elements(&opt
->suboptions
.options
))) {
2452 array_init_size(&entry
, c
);
2453 zend_hash_apply_with_arguments(&opt
->suboptions
.options
, apply_available_options
, 1, Z_ARRVAL(entry
));
2455 /* catch deliberate NULL options */
2456 if (Z_TYPE(opt
->defval
) == IS_STRING
&& !Z_STRVAL(opt
->defval
)) {
2459 ZVAL_ZVAL(&entry
, &opt
->defval
, 1, 0);
2463 if (hash_key
->key
) {
2464 zend_hash_update(ht
, hash_key
->key
, &entry
);
2466 zend_hash_index_update(ht
, hash_key
->h
, &entry
);
2469 return ZEND_HASH_APPLY_KEEP
;
2472 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
)
2474 php_http_client_enqueue_t
*enqueue
;
2477 case PHP_HTTP_CLIENT_OPT_PROGRESS_INFO
:
2478 if ((enqueue
= php_http_client_enqueued(h
, arg
, NULL
))) {
2479 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2481 *((php_http_client_progress_state_t
**) res
) = &handler
->progress
;
2486 case PHP_HTTP_CLIENT_OPT_TRANSFER_INFO
:
2487 if ((enqueue
= php_http_client_enqueued(h
, arg
, NULL
))) {
2488 php_http_client_curl_handler_t
*handler
= enqueue
->opaque
;
2490 php_http_curle_get_info(handler
->handle
, *(HashTable
**) res
);
2495 case PHP_HTTP_CLIENT_OPT_AVAILABLE_OPTIONS
:
2496 zend_hash_apply_with_arguments(&php_http_curle_options
.options
, apply_available_options
, 1, *(HashTable
**) res
);
2499 case PHP_HTTP_CLIENT_OPT_AVAILABLE_CONFIGURATION
:
2500 zend_hash_apply_with_arguments(&php_http_curlm_options
.options
, apply_available_options
, 1, *(HashTable
**) res
);
2510 static php_http_client_ops_t php_http_client_curl_ops
= {
2511 &php_http_curlm_resource_factory_ops
,
2512 php_http_client_curl_init
,
2514 php_http_client_curl_dtor
,
2515 php_http_client_curl_reset
,
2516 php_http_client_curl_exec
,
2517 php_http_client_curl_wait
,
2518 php_http_client_curl_once
,
2519 php_http_client_curl_enqueue
,
2520 php_http_client_curl_dequeue
,
2521 php_http_client_curl_setopt
,
2522 php_http_client_curl_getopt
2525 php_http_client_ops_t
*php_http_client_curl_get_ops(void)
2527 return &php_http_client_curl_ops
;
2530 PHP_MINIT_FUNCTION(http_client_curl
)
2532 curl_version_info_data
*info
;
2533 php_http_options_t
*options
;
2535 PHP_HTTP_G
->client
.curl
.driver
.driver_name
= zend_string_init(ZEND_STRL("curl"), 1);
2536 PHP_HTTP_G
->client
.curl
.driver
.client_name
= zend_string_init(ZEND_STRL("http\\Client\\Curl"), 1);
2537 PHP_HTTP_G
->client
.curl
.driver
.request_name
= zend_string_init(ZEND_STRL("http\\Client\\Curl\\Request"), 1);
2538 PHP_HTTP_G
->client
.curl
.driver
.client_ops
= &php_http_client_curl_ops
;
2540 if (SUCCESS
!= php_http_client_driver_add(&PHP_HTTP_G
->client
.curl
.driver
)) {
2544 if (SUCCESS
!= php_persistent_handle_provide(PHP_HTTP_G
->client
.curl
.driver
.client_name
, &php_http_curlm_resource_factory_ops
, NULL
, NULL
)) {
2547 if (SUCCESS
!= php_persistent_handle_provide(PHP_HTTP_G
->client
.curl
.driver
.request_name
, &php_http_curle_resource_factory_ops
, NULL
, NULL
)) {
2551 if ((options
= php_http_options_init(&php_http_curle_options
, 1))) {
2552 options
->getter
= php_http_curle_get_option
;
2553 options
->setter
= php_http_curle_set_option
;
2555 php_http_curle_options_init(options
);
2557 if ((options
= php_http_options_init(&php_http_curlm_options
, 1))) {
2558 options
->getter
= php_http_option_get
;
2559 options
->setter
= php_http_curlm_set_option
;
2561 php_http_curlm_options_init(options
);
2564 if ((info
= curl_version_info(CURLVERSION_NOW
))) {
2568 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "FEATURES", info
->features
, CONST_CS
|CONST_PERSISTENT
);
2570 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "IPV6", CURL_VERSION_IPV6
, CONST_CS
|CONST_PERSISTENT
);
2571 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "KERBEROS4", CURL_VERSION_KERBEROS4
, CONST_CS
|CONST_PERSISTENT
);
2572 #if PHP_HTTP_CURL_VERSION(7,40,0)
2573 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "KERBEROS5", CURL_VERSION_KERBEROS5
, CONST_CS
|CONST_PERSISTENT
);
2575 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SSL", CURL_VERSION_SSL
, CONST_CS
|CONST_PERSISTENT
);
2576 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "LIBZ", CURL_VERSION_LIBZ
, CONST_CS
|CONST_PERSISTENT
);
2577 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "NTLM", CURL_VERSION_NTLM
, CONST_CS
|CONST_PERSISTENT
);
2578 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "GSSNEGOTIATE", CURL_VERSION_GSSNEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2579 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "ASYNCHDNS", CURL_VERSION_ASYNCHDNS
, CONST_CS
|CONST_PERSISTENT
);
2580 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SPNEGO", CURL_VERSION_SPNEGO
, CONST_CS
|CONST_PERSISTENT
);
2581 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "LARGEFILE", CURL_VERSION_LARGEFILE
, CONST_CS
|CONST_PERSISTENT
);
2582 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "IDN", CURL_VERSION_IDN
, CONST_CS
|CONST_PERSISTENT
);
2583 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "SSPI", CURL_VERSION_SSPI
, CONST_CS
|CONST_PERSISTENT
);
2584 #if PHP_HTTP_CURL_VERSION(7,38,0)
2585 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "GSSAPI", CURL_VERSION_GSSAPI
, CONST_CS
|CONST_PERSISTENT
);
2587 #if PHP_HTTP_CURL_VERSION(7,21,4)
2588 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "TLSAUTH_SRP", CURL_VERSION_TLSAUTH_SRP
, CONST_CS
|CONST_PERSISTENT
);
2590 #if PHP_HTTP_CURL_VERSION(7,22,0)
2591 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "NTLM_WB", CURL_VERSION_NTLM_WB
, CONST_CS
|CONST_PERSISTENT
);
2593 #if PHP_HTTP_CURL_VERSION(7,33,0)
2594 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "HTTP2", CURL_VERSION_HTTP2
, CONST_CS
|CONST_PERSISTENT
);
2596 #if PHP_HTTP_CURL_VERSION(7,40,0)
2597 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "UNIX_SOCKETS", CURL_VERSION_UNIX_SOCKETS
, CONST_CS
|CONST_PERSISTENT
);
2599 #if PHP_HTTP_CURL_VERSION(7,47,0)
2600 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl\\Features", "PSL", CURL_VERSION_PSL
, CONST_CS
|CONST_PERSISTENT
);
2606 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl", "VERSIONS", curl_version(), CONST_CS
|CONST_PERSISTENT
);
2607 #if CURLVERSION_NOW >= 0
2608 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "CURL", (char *) info
->version
, CONST_CS
|CONST_PERSISTENT
);
2609 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "SSL", (char *) info
->ssl_version
, CONST_CS
|CONST_PERSISTENT
);
2610 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "LIBZ", (char *) info
->libz_version
, CONST_CS
|CONST_PERSISTENT
);
2611 # if CURLVERSION_NOW >= 1
2612 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "ARES", (char *) info
->ares
, CONST_CS
|CONST_PERSISTENT
);
2613 # if CURLVERSION_NOW >= 2
2614 REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "IDN", (char *) info
->libidn
, CONST_CS
|CONST_PERSISTENT
);
2621 * HTTP Protocol Version Constants
2623 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_1_0", CURL_HTTP_VERSION_1_0
, CONST_CS
|CONST_PERSISTENT
);
2624 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_1_1", CURL_HTTP_VERSION_1_1
, CONST_CS
|CONST_PERSISTENT
);
2625 #if PHP_HTTP_CURL_VERSION(7,33,0)
2626 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2_0", CURL_HTTP_VERSION_2_0
, CONST_CS
|CONST_PERSISTENT
);
2628 #if PHP_HTTP_CURL_VERSION(7,47,0)
2629 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_2TLS", CURL_HTTP_VERSION_2TLS
, CONST_CS
|CONST_PERSISTENT
);
2631 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "HTTP_VERSION_ANY", CURL_HTTP_VERSION_NONE
, CONST_CS
|CONST_PERSISTENT
);
2634 * SSL Version Constants
2636 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1", CURL_SSLVERSION_TLSv1
, CONST_CS
|CONST_PERSISTENT
);
2637 #if PHP_HTTP_CURL_VERSION(7,34,0)
2638 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_0", CURL_SSLVERSION_TLSv1_0
, CONST_CS
|CONST_PERSISTENT
);
2639 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_1", CURL_SSLVERSION_TLSv1_1
, CONST_CS
|CONST_PERSISTENT
);
2640 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_TLSv1_2", CURL_SSLVERSION_TLSv1_2
, CONST_CS
|CONST_PERSISTENT
);
2642 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv2", CURL_SSLVERSION_SSLv2
, CONST_CS
|CONST_PERSISTENT
);
2643 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv3", CURL_SSLVERSION_SSLv3
, CONST_CS
|CONST_PERSISTENT
);
2644 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_ANY", CURL_SSLVERSION_DEFAULT
, CONST_CS
|CONST_PERSISTENT
);
2645 #if PHP_HTTP_CURL_VERSION(7,21,4) && defined(PHP_HTTP_CURL_TLSAUTH_SRP)
2646 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "TLSAUTH_SRP", CURL_TLSAUTH_SRP
, CONST_CS
|CONST_PERSISTENT
);
2650 * DNS IPvX resolving
2652 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_V4", CURL_IPRESOLVE_V4
, CONST_CS
|CONST_PERSISTENT
);
2653 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_V6", CURL_IPRESOLVE_V6
, CONST_CS
|CONST_PERSISTENT
);
2654 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "IPRESOLVE_ANY", CURL_IPRESOLVE_WHATEVER
, CONST_CS
|CONST_PERSISTENT
);
2659 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_BASIC", CURLAUTH_BASIC
, CONST_CS
|CONST_PERSISTENT
);
2660 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_DIGEST", CURLAUTH_DIGEST
, CONST_CS
|CONST_PERSISTENT
);
2661 #if PHP_HTTP_CURL_VERSION(7,19,3)
2662 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_DIGEST_IE", CURLAUTH_DIGEST_IE
, CONST_CS
|CONST_PERSISTENT
);
2664 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_NTLM", CURLAUTH_NTLM
, CONST_CS
|CONST_PERSISTENT
);
2665 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_GSSNEG", CURLAUTH_GSSNEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2666 #if PHP_HTTP_CURL_VERSION(7,38,0)
2667 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_SPNEGO", CURLAUTH_NEGOTIATE
, CONST_CS
|CONST_PERSISTENT
);
2669 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "AUTH_ANY", CURLAUTH_ANY
, CONST_CS
|CONST_PERSISTENT
);
2672 * Proxy Type Constants
2674 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS4", CURLPROXY_SOCKS4
, CONST_CS
|CONST_PERSISTENT
);
2675 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS4A", CURLPROXY_SOCKS5
, CONST_CS
|CONST_PERSISTENT
);
2676 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS5_HOSTNAME", CURLPROXY_SOCKS5
, CONST_CS
|CONST_PERSISTENT
);
2677 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_SOCKS5", CURLPROXY_SOCKS5
, CONST_CS
|CONST_PERSISTENT
);
2678 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_HTTP", CURLPROXY_HTTP
, CONST_CS
|CONST_PERSISTENT
);
2679 #if PHP_HTTP_CURL_VERSION(7,19,4)
2680 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "PROXY_HTTP_1_0", CURLPROXY_HTTP_1_0
, CONST_CS
|CONST_PERSISTENT
);
2684 * Post Redirection Constants
2686 #if PHP_HTTP_CURL_VERSION(7,19,1)
2687 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_301", CURL_REDIR_POST_301
, CONST_CS
|CONST_PERSISTENT
);
2688 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_302", CURL_REDIR_POST_302
, CONST_CS
|CONST_PERSISTENT
);
2689 #if PHP_HTTP_CURL_VERSION(7,26,0)
2690 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_303", CURL_REDIR_POST_303
, CONST_CS
|CONST_PERSISTENT
);
2692 REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_ALL", CURL_REDIR_POST_ALL
, CONST_CS
|CONST_PERSISTENT
);
2698 PHP_MSHUTDOWN_FUNCTION(http_client_curl
)
2700 php_persistent_handle_cleanup(PHP_HTTP_G
->client
.curl
.driver
.client_name
, NULL
);
2701 php_persistent_handle_cleanup(PHP_HTTP_G
->client
.curl
.driver
.request_name
, NULL
);
2702 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.client_name
);
2703 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.request_name
);
2704 zend_string_release(PHP_HTTP_G
->client
.curl
.driver
.driver_name
);
2706 php_http_options_dtor(&php_http_curle_options
);
2707 php_http_options_dtor(&php_http_curlm_options
);
2712 #endif /* PHP_HTTP_HAVE_CURL */
2719 * vim600: noet sw=4 ts=4 fdm=marker
2720 * vim<600: noet sw=4 ts=4