Skip to content

Commit 77b3a83

Browse files
committed
Lot of fixes and added support for equalsTo()
1 parent 8e07430 commit 77b3a83

33 files changed

+968
-302
lines changed

ext/dom/lexbor/lexbor/url/url.c

Lines changed: 477 additions & 98 deletions
Large diffs are not rendered by default.

ext/dom/lexbor/lexbor/url/url.h

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
* Copyright (C) 2023 Alexander Borisov
34
*
@@ -295,6 +296,19 @@ lxb_url_parse_basic(lxb_url_parser_t *parser, lxb_url_t *url,
295296
const lxb_char_t *data, size_t length,
296297
lxb_url_state_t override_state, lxb_encoding_t encoding);
297298

299+
/*
300+
* Erase URL.
301+
*
302+
* Frees all internal memory occupied by the URL object, but does not destroy
303+
* the object.
304+
*
305+
* @param[in] lxb_url_t *.
306+
*
307+
* @return NULL.
308+
*/
309+
LXB_API void
310+
lxb_url_erase(lxb_url_t *url);
311+
298312
/*
299313
* Destroys URL.
300314
*
@@ -322,6 +336,70 @@ lxb_url_destroy(lxb_url_t *url);
322336
LXB_API void
323337
lxb_url_memory_destroy(lxb_url_t *url);
324338

339+
340+
/*
341+
* Below is an API for modifying the URL object according to the
342+
* https://url.spec.whatwg.org/#api specification.
343+
*
344+
* It is not necessary to pass the lxb_url_parser_t object to API functions.
345+
* You need to pass the parser if you want to have logs of parsing.
346+
*
347+
* All API functions can be passed NULL as "const lxb_char_t *" data.
348+
*/
349+
350+
LXB_API lxb_status_t
351+
lxb_url_api_href_set(lxb_url_t *url, lxb_url_parser_t *parser,
352+
const lxb_char_t *href, size_t length);
353+
354+
LXB_API lxb_status_t
355+
lxb_url_api_protocol_set(lxb_url_t *url, lxb_url_parser_t *parser,
356+
const lxb_char_t *protocol, size_t length);
357+
358+
LXB_API lxb_status_t
359+
lxb_url_api_username_set(lxb_url_t *url,
360+
const lxb_char_t *username, size_t length);
361+
362+
LXB_API lxb_status_t
363+
lxb_url_api_password_set(lxb_url_t *url,
364+
const lxb_char_t *password, size_t length);
365+
366+
LXB_API lxb_status_t
367+
lxb_url_api_host_set(lxb_url_t *url, lxb_url_parser_t *parser,
368+
const lxb_char_t *host, size_t length);
369+
370+
LXB_API lxb_status_t
371+
lxb_url_api_hostname_set(lxb_url_t *url, lxb_url_parser_t *parser,
372+
const lxb_char_t *hostname, size_t length);
373+
374+
LXB_API lxb_status_t
375+
lxb_url_api_port_set(lxb_url_t *url, lxb_url_parser_t *parser,
376+
const lxb_char_t *port, size_t length);
377+
378+
LXB_API lxb_status_t
379+
lxb_url_api_pathname_set(lxb_url_t *url, lxb_url_parser_t *parser,
380+
const lxb_char_t *pathname, size_t length);
381+
382+
LXB_API lxb_status_t
383+
lxb_url_api_search_set(lxb_url_t *url, lxb_url_parser_t *parser,
384+
const lxb_char_t *search, size_t length);
385+
386+
LXB_API lxb_status_t
387+
lxb_url_api_hash_set(lxb_url_t *url, lxb_url_parser_t *parser,
388+
const lxb_char_t *hash, size_t length);
389+
390+
391+
/*
392+
* Below are functions for serializing a URL object and its individual
393+
* parameters.
394+
*
395+
* Note that the callback may be called more than once.
396+
* For example, the lxb_url_serialize() function will callback multiple times:
397+
* 1. http
398+
* 2. ://
399+
* 3. example.com
400+
* and so on.
401+
*/
402+
325403
LXB_API lxb_status_t
326404
lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
327405
bool exclude_fragment);
@@ -384,7 +462,6 @@ lxb_url_serialize_fragment(const lxb_url_t *url,
384462
LXB_API lxb_url_t *
385463
lxb_url_clone(lexbor_mraw_t *mraw, lxb_url_t *url);
386464

387-
388465
/*
389466
* Inline functions.
390467
*/

ext/soap/php_http.c

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "php_soap.h"
2020
#include "ext/hash/php_hash.h" /* For php_hash_bin2hex() */
21+
#include "ext/uri/php_uri.h"
2122

2223
static char *get_http_header_value_nodup(char *headers, char *type, size_t *len);
2324
static char *get_http_header_value(char *headers, char *type);
@@ -335,18 +336,20 @@ static bool in_domain(const zend_string *host, const zend_string *domain)
335336
}
336337
}
337338

338-
int make_http_soap_request(zval *this_ptr,
339-
zend_string *buf,
340-
char *location,
341-
char *soapaction,
342-
int soap_version,
343-
zval *return_value)
339+
int make_http_soap_request(zval *this_ptr,
340+
zend_string *buf,
341+
zend_string *location,
342+
char *soapaction,
343+
int soap_version,
344+
const zend_string *uri_parser_name,
345+
zval *return_value)
344346
{
345347
zend_string *request;
346348
smart_str soap_headers = {0};
347349
smart_str soap_headers_z = {0};
348350
size_t err;
349351
php_url *phpurl = NULL;
352+
uri_internal_t *uri_internal = NULL;
350353
php_stream *stream;
351354
zval *tmp;
352355
int use_proxy = 0;
@@ -431,8 +434,14 @@ int make_http_soap_request(zval *this_ptr,
431434
stream = NULL;
432435
}
433436

434-
if (location != NULL && location[0] != '\000') {
435-
phpurl = php_url_parse(location);
437+
if (location != NULL && ZSTR_VAL(location)[0] != '\000') {
438+
uri_handler_t *uri_handler = php_uri_get_handler(uri_parser_name);
439+
if (uri_handler == NULL) {
440+
zend_argument_value_error(6, "must be a valid URI parser name");
441+
return FALSE;
442+
}
443+
uri_internal = php_uri_parse(uri_handler, location, NULL);
444+
phpurl = php_url_parse(ZSTR_VAL(location));
436445
}
437446

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

451460
try_again:
452-
if (phpurl == NULL || phpurl->host == NULL) {
453-
if (phpurl != NULL) {php_url_free(phpurl);}
461+
if (uri_internal == NULL || phpurl->host == NULL) {
462+
if (phpurl != NULL) {
463+
php_url_free(phpurl);
464+
php_uri_free(uri_internal);
465+
}
454466
if (request != buf) {
455467
zend_string_release_ex(request, 0);
456468
}
@@ -478,6 +490,7 @@ int make_http_soap_request(zval *this_ptr,
478490
PG(allow_url_fopen) = 1;
479491
if (use_ssl && php_stream_locate_url_wrapper("https://", NULL, STREAM_LOCATE_WRAPPERS_ONLY) == NULL) {
480492
php_url_free(phpurl);
493+
php_uri_free(uri_internal);
481494
if (request != buf) {
482495
zend_string_release_ex(request, 0);
483496
}
@@ -533,6 +546,7 @@ int make_http_soap_request(zval *this_ptr,
533546
ZVAL_LONG(Z_CLIENT_USE_PROXY_P(this_ptr), use_proxy);
534547
} else {
535548
php_url_free(phpurl);
549+
php_uri_free(uri_internal);
536550
if (request != buf) {
537551
zend_string_release_ex(request, 0);
538552
}
@@ -1144,13 +1158,31 @@ int make_http_soap_request(zval *this_ptr,
11441158
char *loc;
11451159

11461160
if ((loc = get_http_header_value(ZSTR_VAL(http_headers), "Location:")) != NULL) {
1147-
php_url *new_url = php_url_parse(loc);
1161+
uri_handler_t *uri_handler = php_uri_get_handler(uri_parser_name);
1162+
if (uri_handler == NULL) {
1163+
zend_argument_value_error(6, "must be a valid URI parser name");
1164+
return FALSE;
1165+
}
1166+
1167+
zend_string *loc_str = zend_string_init(loc, strlen(loc), false);
1168+
php_url *new_url = php_url_parse(loc);
1169+
uri_internal_t *new_uri_internal = php_uri_parse(uri_handler, loc_str, NULL);
1170+
zend_string_release(loc_str);
1171+
1172+
zval new_uri_scheme, new_uri_host, new_uri_port, new_uri_path;
1173+
zend_result new_scheme_result = php_uri_get_scheme(new_uri_internal, &new_uri_scheme);
1174+
zend_result new_host_result = php_uri_get_host(new_uri_internal, &new_uri_host);
1175+
zend_result new_port_result = php_uri_get_port(new_uri_internal, &new_uri_port);
1176+
zend_result new_path_result = php_uri_get_path(new_uri_internal, &new_uri_path);
11481177

1149-
if (new_url != NULL) {
1178+
if (new_uri_internal != NULL && new_scheme_result == SUCCESS && new_host_result == SUCCESS &&
1179+
new_port_result == SUCCESS && new_path_result == SUCCESS
1180+
) {
11501181
zend_string_release_ex(http_headers, 0);
11511182
zend_string_release_ex(http_body, 0);
11521183
efree(loc);
1153-
if (new_url->scheme == NULL && new_url->path != NULL) {
1184+
1185+
if (Z_TYPE(new_uri_scheme) == IS_NULL && Z_TYPE(new_uri_path) == IS_STRING) {
11541186
new_url->scheme = phpurl->scheme ? zend_string_copy(phpurl->scheme) : NULL;
11551187
new_url->host = phpurl->host ? zend_string_copy(phpurl->host) : NULL;
11561188
new_url->port = phpurl->port;

ext/soap/php_http.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
#ifndef PHP_HTTP_H
2020
#define PHP_HTTP_H
2121

22-
int make_http_soap_request(zval *this_ptr,
23-
zend_string *request,
24-
char *location,
25-
char *soapaction,
26-
int soap_version,
27-
zval *response);
22+
int make_http_soap_request(zval *this_ptr,
23+
zend_string *request,
24+
zend_string *location,
25+
char *soapaction,
26+
int soap_version,
27+
const zend_string *uri_parser_name,
28+
zval *response);
2829

2930
int proxy_authentication(zval* this_ptr, smart_str* soap_headers);
3031
int basic_authentication(zval* this_ptr, smart_str* soap_headers);

ext/soap/soap.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,28 +2771,28 @@ PHP_METHOD(SoapClient, __getLastResponseHeaders)
27712771
/* {{{ SoapClient::__doRequest() */
27722772
PHP_METHOD(SoapClient, __doRequest)
27732773
{
2774-
zend_string *buf;
2775-
char *location, *action;
2776-
size_t location_size, action_size;
2774+
zend_string *buf, *location, *uri_parser_name = NULL;
2775+
char *action;
2776+
size_t action_size;
27772777
zend_long version;
27782778
bool one_way = 0;
27792779
zval *this_ptr = ZEND_THIS;
27802780

2781-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sssl|b",
2781+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSsl|bS!",
27822782
&buf,
2783-
&location, &location_size,
2783+
&location,
27842784
&action, &action_size,
2785-
&version, &one_way) == FAILURE) {
2785+
&version, &one_way, &uri_parser_name) == FAILURE) {
27862786
RETURN_THROWS();
27872787
}
27882788
if (SOAP_GLOBAL(features) & SOAP_WAIT_ONE_WAY_CALLS) {
27892789
one_way = 0;
27902790
}
27912791
if (one_way) {
2792-
if (make_http_soap_request(this_ptr, buf, location, action, version, NULL)) {
2792+
if (make_http_soap_request(this_ptr, buf, location, action, version, uri_parser_name, NULL)) {
27932793
RETURN_EMPTY_STRING();
27942794
}
2795-
} else if (make_http_soap_request(this_ptr, buf, location, action, version,
2795+
} else if (make_http_soap_request(this_ptr, buf, location, action, uri_parser_name, version,
27962796
return_value)) {
27972797
return;
27982798
}

ext/soap/soap.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ public function __getLastRequestHeaders(): ?string {}
604604
public function __getLastResponseHeaders(): ?string {}
605605

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

609609
/** @tentative-return-type */
610610
public function __setCookie(string $name, ?string $value = null): void {}

ext/soap/soap_arginfo.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/url.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ static void *parse_url_parse_uri(const zend_string *uri_str, const zend_string *
465465
return php_url_parse_ex2(ZSTR_VAL(uri_str), ZSTR_LEN(uri_str), &has_port);
466466
}
467467

468-
static zend_string *parse_url_uri_to_string(void *uri)
468+
static zend_string *parse_url_uri_to_string(void *uri, bool exclude_fragment)
469469
{
470470
ZEND_UNREACHABLE();
471471
}

0 commit comments

Comments
 (0)