kphp icon indicating copy to clipboard operation
kphp copied to clipboard

Add missing options for `curl_setopt()` function

Open mt-omarov opened this issue 1 year ago • 3 comments

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_*FUNCTIONs 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:

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_*FUNCTIONs 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_*FUNCTIONs to the installed stream descriptors. It was necessary to add:

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

mt-omarov avatar Oct 14 '23 22:10 mt-omarov

Is this pr ready for review?

astrophysik avatar Oct 17 '23 13:10 astrophysik

Is this pr ready for review?

not yet

mt-omarov avatar Oct 20 '23 16:10 mt-omarov

Is this pr ready for review?

not yet

Convert it to Draft please

Danil42Russia avatar Oct 23 '23 11:10 Danil42Russia