kphp
kphp copied to clipboard
Add missing options for `curl_setopt()` function
Update KPHP curl_setopt()
function
This PR extends the options of the curl_setopt()
function:
- primitive options of the
curl_setopt()
function up to the current version of php - support for non-standard
CURLOPT_*FUNCTION
s options, as well as stream descriptor options
Requirements
libcurl version 8.4.0
Support for callable options
PHP supports wrappers for custom functions for parameters: CURLOPT_WRITEFUNCTION, CURLOPT_HEADERFUNCTION, CURLOPT_READFUNCTION, CURLOPT_PROGRESSFUNCTION, CURLOPT_XFERINFOFUNCTION.
Problem
To be able to pass callable objects to runtime and not override the logic of accepting mixed arguments, the curl_setopt()
function must be overloaded.
However, overloading with a callable argument is not so simple: compiler optimizations prevent lambda expressions from being called from the runtime. The generated lambda expression code contains only the functionality that is explicitly called in the php code. Lambda expressions passed to curl_setopt()
are called inside the runtime, so the compiler simply does not create methods to call the generated lambda objects => it will not be possible to call them in the runtime.
Solution
The key change for the overload operation is the rearrangement of the optimization step EarlyOptimizationF
in compiler.cpp
.
Next, to redirect the function call, use:
- Definition of new functions in
kphp_internal.txt
- Rules for redirecting functions in
early_opt.rules
- The logic of calling functions in
curl.h
andcurl.cpp
.
Logic
The lambda expressions that the user passes to curl_setopt()
are stored in an object of the EasyContext class. Wrapper functions are defined in the runtime for each of the CURLOPT_*FUNCTION
s options:
Support for stream options
Added support for options: CURLOPT_FILE, CURLOPT_INFILE, CURLOPT_WRITEHEADER.
These options redirect the output of information in the CURLOPT_*FUNCTION
s to the installed stream descriptors.
It was necessary to add:
- a field in the structure of each handler of a callable object for storing the stream descriptor and the mode of operation of the curl function;
- a function for setting stream object to the handler.
Support for missing primitive options
- added bitmasks for
CURLOPT_PROTOCOLS
; - added bitmasks for
CURLOPT_SSH_AUTH_TYPES
; - added bitmasks for
CURLAUTH
options; - added bitmasks for SSL options:
unsupported flags are not allowed to be transmitted:
CURLSSLOPT_NO_REVOKE
,CURLSSLOPT_REVOKE_BEST_EFFORT
,CURLSSLOPT_AUTO_CLIENT_CERT
The full list of added options is located in the curl-options.md
Tests
-
Updated tests in 2_curl_setopt.php: removed tests with bad options., the new version of libcurl throws an error instead of a warning.
-
Added simple tests for missing options, which should work on both libcurl version 7.60.0 and the new version: 13_curl_setopt_new.php.
-
Added simple tests for stream options: 14_curl_setopt_streams.php.
-
Added simple tests for options with additional dependencies: 15_curl_setopt_problems.php.
-
Added simple tests that require a new version of libcurl: 16_curl_setopt_only_new_curl.php.
-
Added simple tests for callable options: 17_curl_setopt_callables.php.
-
Added auxiliary tests with raising the local server to check the stream and callable options: the tests are located on an additional branch of the pull request (14_curl_setopt_streams-server.php, 17_curl_setopt_callables-server.php).
Is this pr ready for review?
Is this pr ready for review?
not yet
Is this pr ready for review?
not yet
Convert it to Draft please