Skip to content

Commit

Permalink
Lot of fixes and added support for equalsTo()
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Nov 11, 2024
1 parent 8e07430 commit 77b3a83
Show file tree
Hide file tree
Showing 33 changed files with 968 additions and 302 deletions.
575 changes: 477 additions & 98 deletions ext/dom/lexbor/lexbor/url/url.c

Large diffs are not rendered by default.

79 changes: 78 additions & 1 deletion ext/dom/lexbor/lexbor/url/url.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* Copyright (C) 2023 Alexander Borisov
*
Expand Down Expand Up @@ -295,6 +296,19 @@ lxb_url_parse_basic(lxb_url_parser_t *parser, lxb_url_t *url,
const lxb_char_t *data, size_t length,
lxb_url_state_t override_state, lxb_encoding_t encoding);

/*
* Erase URL.
*
* Frees all internal memory occupied by the URL object, but does not destroy
* the object.
*
* @param[in] lxb_url_t *.
*
* @return NULL.
*/
LXB_API void
lxb_url_erase(lxb_url_t *url);

/*
* Destroys URL.
*
Expand Down Expand Up @@ -322,6 +336,70 @@ lxb_url_destroy(lxb_url_t *url);
LXB_API void
lxb_url_memory_destroy(lxb_url_t *url);


/*
* Below is an API for modifying the URL object according to the
* https://url.spec.whatwg.org/#api specification.
*
* It is not necessary to pass the lxb_url_parser_t object to API functions.
* You need to pass the parser if you want to have logs of parsing.
*
* All API functions can be passed NULL as "const lxb_char_t *" data.
*/

LXB_API lxb_status_t
lxb_url_api_href_set(lxb_url_t *url, lxb_url_parser_t *parser,
const lxb_char_t *href, size_t length);

LXB_API lxb_status_t
lxb_url_api_protocol_set(lxb_url_t *url, lxb_url_parser_t *parser,
const lxb_char_t *protocol, size_t length);

LXB_API lxb_status_t
lxb_url_api_username_set(lxb_url_t *url,
const lxb_char_t *username, size_t length);

LXB_API lxb_status_t
lxb_url_api_password_set(lxb_url_t *url,
const lxb_char_t *password, size_t length);

LXB_API lxb_status_t
lxb_url_api_host_set(lxb_url_t *url, lxb_url_parser_t *parser,
const lxb_char_t *host, size_t length);

LXB_API lxb_status_t
lxb_url_api_hostname_set(lxb_url_t *url, lxb_url_parser_t *parser,
const lxb_char_t *hostname, size_t length);

LXB_API lxb_status_t
lxb_url_api_port_set(lxb_url_t *url, lxb_url_parser_t *parser,
const lxb_char_t *port, size_t length);

LXB_API lxb_status_t
lxb_url_api_pathname_set(lxb_url_t *url, lxb_url_parser_t *parser,
const lxb_char_t *pathname, size_t length);

LXB_API lxb_status_t
lxb_url_api_search_set(lxb_url_t *url, lxb_url_parser_t *parser,
const lxb_char_t *search, size_t length);

LXB_API lxb_status_t
lxb_url_api_hash_set(lxb_url_t *url, lxb_url_parser_t *parser,
const lxb_char_t *hash, size_t length);


/*
* Below are functions for serializing a URL object and its individual
* parameters.
*
* Note that the callback may be called more than once.
* For example, the lxb_url_serialize() function will callback multiple times:
* 1. http
* 2. ://
* 3. example.com
* and so on.
*/

LXB_API lxb_status_t
lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
bool exclude_fragment);
Expand Down Expand Up @@ -384,7 +462,6 @@ lxb_url_serialize_fragment(const lxb_url_t *url,
LXB_API lxb_url_t *
lxb_url_clone(lexbor_mraw_t *mraw, lxb_url_t *url);


/*
* Inline functions.
*/
Expand Down
58 changes: 45 additions & 13 deletions ext/soap/php_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "php_soap.h"
#include "ext/hash/php_hash.h" /* For php_hash_bin2hex() */
#include "ext/uri/php_uri.h"

static char *get_http_header_value_nodup(char *headers, char *type, size_t *len);
static char *get_http_header_value(char *headers, char *type);
Expand Down Expand Up @@ -335,18 +336,20 @@ static bool in_domain(const zend_string *host, const zend_string *domain)
}
}

int make_http_soap_request(zval *this_ptr,
zend_string *buf,
char *location,
char *soapaction,
int soap_version,
zval *return_value)
int make_http_soap_request(zval *this_ptr,
zend_string *buf,
zend_string *location,
char *soapaction,
int soap_version,
const zend_string *uri_parser_name,
zval *return_value)
{
zend_string *request;
smart_str soap_headers = {0};
smart_str soap_headers_z = {0};
size_t err;
php_url *phpurl = NULL;
uri_internal_t *uri_internal = NULL;
php_stream *stream;
zval *tmp;
int use_proxy = 0;
Expand Down Expand Up @@ -431,8 +434,14 @@ int make_http_soap_request(zval *this_ptr,
stream = NULL;
}

if (location != NULL && location[0] != '\000') {
phpurl = php_url_parse(location);
if (location != NULL && ZSTR_VAL(location)[0] != '\000') {
uri_handler_t *uri_handler = php_uri_get_handler(uri_parser_name);
if (uri_handler == NULL) {
zend_argument_value_error(6, "must be a valid URI parser name");
return FALSE;
}
uri_internal = php_uri_parse(uri_handler, location, NULL);
phpurl = php_url_parse(ZSTR_VAL(location));
}

tmp = Z_CLIENT_STREAM_CONTEXT_P(this_ptr);
Expand All @@ -449,8 +458,11 @@ int make_http_soap_request(zval *this_ptr,
}

try_again:
if (phpurl == NULL || phpurl->host == NULL) {
if (phpurl != NULL) {php_url_free(phpurl);}
if (uri_internal == NULL || phpurl->host == NULL) {
if (phpurl != NULL) {
php_url_free(phpurl);
php_uri_free(uri_internal);
}
if (request != buf) {
zend_string_release_ex(request, 0);
}
Expand Down Expand Up @@ -478,6 +490,7 @@ int make_http_soap_request(zval *this_ptr,
PG(allow_url_fopen) = 1;
if (use_ssl && php_stream_locate_url_wrapper("https://", NULL, STREAM_LOCATE_WRAPPERS_ONLY) == NULL) {
php_url_free(phpurl);
php_uri_free(uri_internal);
if (request != buf) {
zend_string_release_ex(request, 0);
}
Expand Down Expand Up @@ -533,6 +546,7 @@ int make_http_soap_request(zval *this_ptr,
ZVAL_LONG(Z_CLIENT_USE_PROXY_P(this_ptr), use_proxy);
} else {
php_url_free(phpurl);
php_uri_free(uri_internal);
if (request != buf) {
zend_string_release_ex(request, 0);
}
Expand Down Expand Up @@ -1144,13 +1158,31 @@ int make_http_soap_request(zval *this_ptr,
char *loc;

if ((loc = get_http_header_value(ZSTR_VAL(http_headers), "Location:")) != NULL) {
php_url *new_url = php_url_parse(loc);
uri_handler_t *uri_handler = php_uri_get_handler(uri_parser_name);
if (uri_handler == NULL) {
zend_argument_value_error(6, "must be a valid URI parser name");
return FALSE;
}

zend_string *loc_str = zend_string_init(loc, strlen(loc), false);
php_url *new_url = php_url_parse(loc);
uri_internal_t *new_uri_internal = php_uri_parse(uri_handler, loc_str, NULL);
zend_string_release(loc_str);

zval new_uri_scheme, new_uri_host, new_uri_port, new_uri_path;
zend_result new_scheme_result = php_uri_get_scheme(new_uri_internal, &new_uri_scheme);
zend_result new_host_result = php_uri_get_host(new_uri_internal, &new_uri_host);
zend_result new_port_result = php_uri_get_port(new_uri_internal, &new_uri_port);
zend_result new_path_result = php_uri_get_path(new_uri_internal, &new_uri_path);

if (new_url != NULL) {
if (new_uri_internal != NULL && new_scheme_result == SUCCESS && new_host_result == SUCCESS &&
new_port_result == SUCCESS && new_path_result == SUCCESS
) {
zend_string_release_ex(http_headers, 0);
zend_string_release_ex(http_body, 0);
efree(loc);
if (new_url->scheme == NULL && new_url->path != NULL) {

if (Z_TYPE(new_uri_scheme) == IS_NULL && Z_TYPE(new_uri_path) == IS_STRING) {
new_url->scheme = phpurl->scheme ? zend_string_copy(phpurl->scheme) : NULL;
new_url->host = phpurl->host ? zend_string_copy(phpurl->host) : NULL;
new_url->port = phpurl->port;
Expand Down
13 changes: 7 additions & 6 deletions ext/soap/php_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
#ifndef PHP_HTTP_H
#define PHP_HTTP_H

int make_http_soap_request(zval *this_ptr,
zend_string *request,
char *location,
char *soapaction,
int soap_version,
zval *response);
int make_http_soap_request(zval *this_ptr,
zend_string *request,
zend_string *location,
char *soapaction,
int soap_version,
const zend_string *uri_parser_name,
zval *response);

int proxy_authentication(zval* this_ptr, smart_str* soap_headers);
int basic_authentication(zval* this_ptr, smart_str* soap_headers);
Expand Down
16 changes: 8 additions & 8 deletions ext/soap/soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2771,28 +2771,28 @@ PHP_METHOD(SoapClient, __getLastResponseHeaders)
/* {{{ SoapClient::__doRequest() */
PHP_METHOD(SoapClient, __doRequest)
{
zend_string *buf;
char *location, *action;
size_t location_size, action_size;
zend_string *buf, *location, *uri_parser_name = NULL;
char *action;
size_t action_size;
zend_long version;
bool one_way = 0;
zval *this_ptr = ZEND_THIS;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sssl|b",
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSsl|bS!",
&buf,
&location, &location_size,
&location,
&action, &action_size,
&version, &one_way) == FAILURE) {
&version, &one_way, &uri_parser_name) == FAILURE) {
RETURN_THROWS();
}
if (SOAP_GLOBAL(features) & SOAP_WAIT_ONE_WAY_CALLS) {
one_way = 0;
}
if (one_way) {
if (make_http_soap_request(this_ptr, buf, location, action, version, NULL)) {
if (make_http_soap_request(this_ptr, buf, location, action, version, uri_parser_name, NULL)) {
RETURN_EMPTY_STRING();
}
} else if (make_http_soap_request(this_ptr, buf, location, action, version,
} else if (make_http_soap_request(this_ptr, buf, location, action, uri_parser_name, version,
return_value)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/soap/soap.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public function __getLastRequestHeaders(): ?string {}
public function __getLastResponseHeaders(): ?string {}

/** @tentative-return-type */
public function __doRequest(string $request, string $location, string $action, int $version, bool $oneWay = false): ?string {}
public function __doRequest(string $request, string $location, string $action, int $version, bool $oneWay = false, ?string $uriParserName = null): ?string {}

/** @tentative-return-type */
public function __setCookie(string $name, ?string $value = null): void {}
Expand Down
3 changes: 2 additions & 1 deletion ext/soap/soap_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ext/standard/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ static void *parse_url_parse_uri(const zend_string *uri_str, const zend_string *
return php_url_parse_ex2(ZSTR_VAL(uri_str), ZSTR_LEN(uri_str), &has_port);
}

static zend_string *parse_url_uri_to_string(void *uri)
static zend_string *parse_url_uri_to_string(void *uri, bool exclude_fragment)
{
ZEND_UNREACHABLE();
}
Expand Down
Loading

0 comments on commit 77b3a83

Please sign in to comment.