Skip to content

[RFC] Implement new Curl URL Api #8770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/curl/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int main(int argc, char *argv[])
$CURL_LIBS
])

PHP_NEW_EXTENSION(curl, interface.c multi.c share.c curl_file.c, $ext_shared)
PHP_NEW_EXTENSION(curl, interface.c multi.c share.c curl_file.c url.c, $ext_shared)
PHP_INSTALL_HEADERS([ext/curl], [php_curl.h])
PHP_SUBST(CURL_SHARED_LIBADD)
fi
2 changes: 1 addition & 1 deletion ext/curl/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if (PHP_CURL != "no") {
CHECK_LIB("libssh2.lib", "curl", PHP_CURL) &&
CHECK_LIB("nghttp2.lib", "curl", PHP_CURL))
) {
EXTENSION("curl", "interface.c multi.c share.c curl_file.c");
EXTENSION("curl", "interface.c multi.c share.c curl_file.c url.c");
AC_DEFINE('HAVE_CURL', 1, 'Have cURL library');
ADD_FLAG("CFLAGS_CURL", "/D CURL_STATICLIB /D PHP_CURL_EXPORTS=1");
PHP_INSTALL_HEADERS("ext/curl", "php_curl.h");
Expand Down
24 changes: 24 additions & 0 deletions ext/curl/curl_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ typedef struct {
zval private_data;
/* CurlShareHandle object set using CURLOPT_SHARE. */
struct _php_curlsh *share;
#if LIBCURL_VERSION_NUM >= 0x073f00 /* 7.63.0 */
struct _php_curlurl *url;
#endif
zend_object std;
} php_curl;

Expand Down Expand Up @@ -137,6 +140,16 @@ typedef struct _php_curlsh {
zend_object std;
} php_curlsh;

#if LIBCURL_VERSION_NUM >= 0x073e00 /* 7.62.0 */
typedef struct _php_curlurl {
CURLU *url;
struct {
int no;
} err;
zend_object std;
} php_curlurl;
#endif

php_curl *init_curl_handle_into_zval(zval *curl);
void init_curl_handle(php_curl *ch);
void _php_curl_cleanup_handle(php_curl *);
Expand All @@ -156,8 +169,19 @@ static inline php_curlsh *curl_share_from_obj(zend_object *obj) {

#define Z_CURL_SHARE_P(zv) curl_share_from_obj(Z_OBJ_P(zv))

#if LIBCURL_VERSION_NUM >= 0x073e00 /* 7.62.0 */
static inline php_curlurl *curl_url_from_obj(zend_object *obj) {
return (php_curlurl *)((char *)(obj) - XtOffsetOf(php_curlurl, std));
}

#define Z_CURL_URL_P(zv) curl_url_from_obj(Z_OBJ_P(zv))
#endif

void curl_multi_register_handlers(void);
void curl_share_register_handlers(void);
#if LIBCURL_VERSION_NUM >= 0x073e00 /* 7.62.0 */
void curl_url_register_handlers(void);
#endif
void curlfile_register_class(void);
int curl_cast_object(zend_object *obj, zval *result, int type);

Expand Down
234 changes: 234 additions & 0 deletions ext/curl/curl_url.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
<?php

/** @generate-class-entries */

#if LIBCURL_VERSION_NUM >= 0x073E00 /* Available since 7.62.0 */
/**
* @strict-properties
* @not-serializable
*/
final class CurlUrl implements Stringable
{
/**
* @var int
* @cname CURLU_APPENDQUERY
*/
public const APPEND_QUERY = UNKNOWN;

/**
* @var int
* @cname CURLU_DEFAULT_PORT
*/
public const DEFAULT_PORT = UNKNOWN;

/**
* @var int
* @cname CURLU_DEFAULT_SCHEME
*/
public const DEFAULT_SCHEME = UNKNOWN;

/**
* @var int
* @cname CURLU_DISALLOW_USER
*/
public const DISALLOW_USER = UNKNOWN;

/**
* @var int
* @cname CURLU_GUESS_SCHEME
*/
public const GUESS_SCHEME = UNKNOWN;

/**
* @var int
* @cname CURLU_NO_DEFAULT_PORT
*/
public const NO_DEFAULT_PORT = UNKNOWN;

/**
* @var int
* @cname CURLU_NON_SUPPORT_SCHEME
*/
public const ALLOW_UNSUPPORTED_SCHEME = UNKNOWN;

/**
* @var int
* @cname CURLU_PATH_AS_IS
*/
public const PATH_AS_IS = UNKNOWN;

/**
* @var int
* @cname CURLU_URLDECODE
*/
public const URL_DECODE = UNKNOWN;

/**
* @var int
* @cname CURLU_URLENCODE
*/
public const URL_ENCODE = UNKNOWN;

#if LIBCURL_VERSION_NUM >= 0x074300 /* Available since 7.67.0 */
/**
* @var int
* @cname CURLU_NO_AUTHORITY
*/
public const NO_AUTHORITY = UNKNOWN;
#endif

#if LIBCURL_VERSION_NUM >= 0x074e00 /* Available since 7.78.0 */
/**
* @var int
* @cname CURLU_ALLOW_SPACE
*/
public const ALLOW_SPACE = UNKNOWN;
#endif

public function __construct(?string $url = null, int $flags = 0) {}

public function get(int $flags = 0): string {}
public function set(?string $url, int $flags = 0): CurlUrl {}

public function getHost(): ?string {}
public function setHost(?string $host): CurlUrl {}

public function getScheme(): ?string {}
public function setScheme(?string $scheme, int $flags = 0): CurlUrl {}

public function getPort(int $flags = 0): ?int {}
public function setPort(?int $port): CurlUrl {}

public function getPath(int $flags = 0): string {}
public function setPath(?string $scheme, int $flags = 0): CurlUrl {}

public function getQuery(int $flags = 0): ?string {}
public function setQuery(?string $query, int $flags = 0): CurlUrl {}

public function getFragment(int $flags = 0): ?string {}
public function setFragment(?string $fragment, int $flags = 0): CurlUrl {}

public function getUser(int $flags = 0): ?string {}
public function setUser(?string $user, int $flags = 0): CurlUrl {}

public function getPassword(int $flags = 0): ?string {}
public function setPassword(?string $password, int $flags = 0): CurlUrl {}

public function getOptions(int $flags = 0): ?string {}
public function setOptions(?string $options, int $flags = 0): CurlUrl {}

#if LIBCURL_VERSION_NUM >= 0x074100 /* Available since 7.65.0 */
public function getZoneId(int $flags = 0): ?string {}
public function setZoneId(?string $zoneid, int $flags = 0): CurlUrl {}
#endif

public function __toString(): string {}
}

final class CurlUrlException extends Exception
{
/**
* @var int
* @cname CURLUE_BAD_PORT_NUMBER
*/
public const BAD_PORT_NUMBER = UNKNOWN;

/**
* @var int
* @cname CURLUE_MALFORMED_INPUT
*/
public const MALFORMED_INPUT = UNKNOWN;

/**
* @var int
* @cname CURLUE_OUT_OF_MEMORY
*/
public const OUT_OF_MEMORY = UNKNOWN;

/**
* @var int
* @cname CURLUE_UNSUPPORTED_SCHEME
*/
public const UNSUPPORTED_SCHEME = UNKNOWN;

/**
* @var int
* @cname CURLUE_URLDECODE
*/
public const URL_DECODING_FAILED = UNKNOWN;

/**
* @var int
* @cname CURLUE_USER_NOT_ALLOWED
*/
public const USER_NOT_ALLOWED = UNKNOWN;

#if LIBCURL_VERSION_NUM >= 0x075100 /* Available since 7.81.0 */
/**
* @var int
* @cname CURLUE_BAD_FILE_URL
*/
public const BAD_FILE_URL = UNKNOWN;

/**
* @var int
* @cname CURLUE_BAD_FRAGMENT
*/
public const BAD_FRAGMENT = UNKNOWN;

/**
* @var int
* @cname CURLUE_BAD_HOSTNAME
*/
public const BAD_HOSTNAME = UNKNOWN;

/**
* @var int
* @cname CURLUE_BAD_IPV6
*/
public const BAD_IPV6 = UNKNOWN;

/**
* @var int
* @cname CURLUE_BAD_LOGIN
*/
public const BAD_LOGIN = UNKNOWN;

/**
* @var int
* @cname CURLUE_BAD_PASSWORD
*/
public const BAD_PASSWORD = UNKNOWN;

/**
* @var int
* @cname CURLUE_BAD_PATH
*/
public const BAD_PATH = UNKNOWN;

/**
* @var int
* @cname CURLUE_BAD_QUERY
*/
public const BAD_QUERY = UNKNOWN;

/**
* @var int
* @cname CURLUE_BAD_SCHEME
*/
public const BAD_SCHEME = UNKNOWN;

/**
* @var int
* @cname CURLUE_BAD_SLASHES
*/
public const BAD_SLASHES = UNKNOWN;

/**
* @var int
* @cname CURLUE_BAD_USER
*/
public const BAD_USER = UNKNOWN;
#endif
}
#endif
Loading