Skip to content
Merged
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/openssl/xp_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2640,7 +2640,7 @@ static char *php_openssl_get_url_name(const char *resourcename,
return NULL;
}

uri_internal_t *internal_uri = php_uri_parse(uri_parser, resourcename, resourcenamelen, true);
php_uri_internal *internal_uri = php_uri_parse(uri_parser, resourcename, resourcenamelen, true);
if (internal_uri == NULL) {
return NULL;
}
Expand Down
239 changes: 120 additions & 119 deletions ext/uri/php_uri.c

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions ext/uri/php_uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ PHPAPI zend_result php_uri_parser_register(const php_uri_parser *uri_parser);
*/
PHPAPI const php_uri_parser *php_uri_get_parser(zend_string *uri_parser_name);

ZEND_ATTRIBUTE_NONNULL PHPAPI uri_internal_t *php_uri_parse(const php_uri_parser *uri_parser, const char *uri_str, size_t uri_str_len, bool silent);
ZEND_ATTRIBUTE_NONNULL PHPAPI php_uri_internal *php_uri_parse(const php_uri_parser *uri_parser, const char *uri_str, size_t uri_str_len, bool silent);

/**
* Retrieves the scheme component based on the read_mode and passes it to the zv ZVAL in case of success.
Expand All @@ -66,7 +66,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI uri_internal_t *php_uri_parse(const php_uri_parser
* @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL).
* @return SUCCESS in case of success, FAILURE otherwise.
*/
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_scheme(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv);
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_scheme(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv);

/**
* Retrieves the username component based on the read_mode and passes it to the zv ZVAL in case of success.
Expand All @@ -81,7 +81,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_scheme(const uri_internal_
* @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL).
* @return SUCCESS in case of success, FAILURE otherwise.
*/
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_username(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv);
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_username(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv);

/**
* Retrieves the password component based on the read_mode and passes it to the zv ZVAL in case of success.
Expand All @@ -96,7 +96,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_username(const uri_interna
* @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL).
* @return SUCCESS in case of success, FAILURE otherwise.
*/
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_password(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv);
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_password(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv);

/**
* Retrieves the host component based on the read_mode and passes it to the zv ZVAL in case of success.
Expand All @@ -111,7 +111,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_password(const uri_interna
* @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL).
* @return SUCCESS in case of success, FAILURE otherwise.
*/
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_host(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv);
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_host(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv);

/**
* Retrieves the port component based on the read_mode and passes it to the zv ZVAL in case of success.
Expand All @@ -126,7 +126,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_host(const uri_internal_t
* @param zv The output parameter containing the retrieved component as a ZVAL (either IS_LONG or IS_NULL).
* @return SUCCESS in case of success, FAILURE otherwise.
*/
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_port(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv);
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_port(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv);

/**
* Retrieves the path component based on the read_mode and passes it to the zv ZVAL in case of success.
Expand All @@ -141,7 +141,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_port(const uri_internal_t
* @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL).
* @return SUCCESS in case of success, FAILURE otherwise.
*/
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_path(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv);
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_path(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv);

/**
* Retrieves the query component based on the read_mode and passes it to the zv ZVAL in case of success.
Expand All @@ -156,7 +156,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_path(const uri_internal_t
* @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL).
* @return SUCCESS in case of success, FAILURE otherwise.
*/
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_query(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv);
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_query(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv);

/**
* Retrieves the fragment component based on the read_mode and passes it to the zv ZVAL in case of success.
Expand All @@ -171,14 +171,14 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_query(const uri_internal_t
* @param zv The output parameter containing the retrieved component as a ZVAL (either IS_STRING or IS_NULL).
* @return SUCCESS in case of success, FAILURE otherwise.
*/
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_fragment(const uri_internal_t *internal_uri, php_uri_component_read_mode read_mode, zval *zv);
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_uri_get_fragment(const php_uri_internal *internal_uri, php_uri_component_read_mode read_mode, zval *zv);

/**
* Frees the uri member within the provided internal URI.
*
* @param internal_uri The internal URI
*/
ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_free(uri_internal_t *internal_uri);
ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_free(php_uri_internal *internal_uri);

/**
* Creates a new php_uri struct containing all the URI components. The components are retrieved based on the read_mode parameter.
Expand Down Expand Up @@ -207,7 +207,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI php_uri *php_uri_parse_to_struct(
ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_struct_free(php_uri *uri);

ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri(
INTERNAL_FUNCTION_PARAMETERS, const zend_string *uri_str, const uri_object_t *base_url_object,
INTERNAL_FUNCTION_PARAMETERS, const zend_string *uri_str, const php_uri_object *base_url_object,
bool should_throw, bool should_update_this_object, zval *errors_zv
);

Expand Down
24 changes: 12 additions & 12 deletions ext/uri/php_uri_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ static zend_string *get_known_string_by_property_name(php_uri_property_name prop
}
}

void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, php_uri_component_read_mode component_read_mode)
void php_uri_property_read_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, php_uri_component_read_mode component_read_mode)
{
ZEND_PARSE_PARAMETERS_NONE();

uri_object_t *uri_object = Z_URI_OBJECT_P(ZEND_THIS);
php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS);
ZEND_ASSERT(uri_object->uri != NULL);

const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(uri_object->parser, property_name);

if (UNEXPECTED(property_handler->read(uri_object->uri, component_read_mode, return_value) == FAILURE)) {
zend_throw_exception_ex(uri_error_ce, 0, "The %s component cannot be retrieved", ZSTR_VAL(get_known_string_by_property_name(property_name)));
zend_throw_exception_ex(php_uri_ce_error, 0, "The %s component cannot be retrieved", ZSTR_VAL(get_known_string_by_property_name(property_name)));
RETURN_THROWS();
}
}

static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, zval *property_zv)
static void php_uri_property_write_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, zval *property_zv)
{
uri_object_t *old_uri_object = Z_URI_OBJECT_P(ZEND_THIS);
php_uri_object *old_uri_object = Z_URI_OBJECT_P(ZEND_THIS);
ZEND_ASSERT(old_uri_object->uri != NULL);

zend_object *new_object = old_uri_object->std.handlers->clone_obj(&old_uri_object->std);
Expand All @@ -73,7 +73,7 @@ static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, php_uri_propert

const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(old_uri_object->parser, property_name);

uri_object_t *new_uri_object = uri_object_from_obj(new_object);
php_uri_object *new_uri_object = php_uri_object_from_obj(new_object);
ZEND_ASSERT(new_uri_object->uri != NULL);
if (UNEXPECTED(property_handler->write == NULL)) {
zend_readonly_property_modification_error_ex(ZSTR_VAL(old_uri_object->std.ce->name),
Expand All @@ -91,7 +91,7 @@ static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, php_uri_propert
ZEND_ASSERT(Z_ISUNDEF(errors));
}

void uri_write_component_str(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name)
void php_uri_property_write_str_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name)
{
zend_string *value;

Expand All @@ -102,10 +102,10 @@ void uri_write_component_str(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name
zval zv;
ZVAL_STR(&zv, value);

uri_write_component_ex(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_name, &zv);
php_uri_property_write_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_name, &zv);
}

void uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name)
void php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name)
{
zend_string *value;

Expand All @@ -120,10 +120,10 @@ void uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAMETERS, php_uri_prope
ZVAL_STR(&zv, value);
}

uri_write_component_ex(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_name, &zv);
php_uri_property_write_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_name, &zv);
}

void uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name)
void php_uri_property_write_long_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name)
{
zend_long value;
bool value_is_null;
Expand All @@ -139,5 +139,5 @@ void uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAMETERS, php_uri_prop
ZVAL_LONG(&zv, value);
}

uri_write_component_ex(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_name, &zv);
php_uri_property_write_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_name, &zv);
}
46 changes: 22 additions & 24 deletions ext/uri/php_uri_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
#ifndef PHP_URI_COMMON_H
#define PHP_URI_COMMON_H

extern zend_class_entry *uri_rfc3986_uri_ce;
extern zend_object_handlers uri_rfc3986_uri_object_handlers;
extern zend_class_entry *uri_whatwg_url_ce;
extern zend_object_handlers uri_whatwg_uri_object_handlers;
extern zend_class_entry *uri_comparison_mode_ce;
extern zend_class_entry *uri_exception_ce;
extern zend_class_entry *uri_error_ce;
extern zend_class_entry *uri_invalid_uri_exception_ce;
extern zend_class_entry *uri_whatwg_invalid_url_exception_ce;
extern zend_class_entry *uri_whatwg_url_validation_error_type_ce;
extern zend_class_entry *uri_whatwg_url_validation_error_ce;
extern zend_class_entry *php_uri_ce_rfc3986_uri;
extern zend_class_entry *php_uri_ce_whatwg_url;
extern zend_class_entry *php_uri_ce_comparison_mode;
extern zend_class_entry *php_uri_ce_exception;
extern zend_class_entry *php_uri_ce_error;
extern zend_class_entry *php_uri_ce_invalid_uri_exception;
extern zend_class_entry *php_uri_ce_whatwg_invalid_url_exception;
extern zend_class_entry *php_uri_ce_whatwg_url_validation_error_type;
extern zend_class_entry *php_uri_ce_whatwg_url_validation_error;

typedef enum php_uri_recomposition_mode {
PHP_URI_RECOMPOSITION_MODE_RAW_ASCII,
Expand Down Expand Up @@ -137,31 +135,31 @@ typedef struct php_uri_parser {
} property_handler;
} php_uri_parser;

typedef struct uri_internal_t {
typedef struct php_uri_internal {
const php_uri_parser *parser;
void *uri;
} uri_internal_t;
} php_uri_internal;

typedef struct uri_object_t {
typedef struct php_uri_object {
const php_uri_parser *parser;
void *uri;
zend_object std;
} uri_object_t;
} php_uri_object;

static inline uri_object_t *uri_object_from_obj(zend_object *object) {
return (uri_object_t*)((char*)(object) - XtOffsetOf(uri_object_t, std));
static inline php_uri_object *php_uri_object_from_obj(zend_object *object) {
return (php_uri_object*)((char*)(object) - XtOffsetOf(php_uri_object, std));
}

#define Z_URI_OBJECT_P(zv) uri_object_from_obj(Z_OBJ_P((zv)))
#define Z_URI_OBJECT_P(zv) php_uri_object_from_obj(Z_OBJ_P((zv)))

PHPAPI uri_object_t *php_uri_object_create(zend_class_entry *class_type, const php_uri_parser *parser);
PHPAPI php_uri_object *php_uri_object_create(zend_class_entry *class_type, const php_uri_parser *parser);
PHPAPI void php_uri_object_handler_free(zend_object *object);
PHPAPI zend_object *php_uri_object_handler_clone(zend_object *object);

#define PHP_URI_PARSER_RFC3986 "Uri\\Rfc3986\\Uri"
#define PHP_URI_PARSER_WHATWG "Uri\\WhatWg\\Url"
#define PHP_URI_PARSER_PHP_PARSE_URL "parse_url"
#define URI_SERIALIZED_PROPERTY_NAME "uri"
#define PHP_URI_SERIALIZE_URI_FIELD_NAME "uri"

static inline const php_uri_property_handler *php_uri_parser_property_handler_by_name(const php_uri_parser *parser, php_uri_property_name property_name)
{
Expand All @@ -186,9 +184,9 @@ static inline const php_uri_property_handler *php_uri_parser_property_handler_by
}
}

void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, php_uri_component_read_mode component_read_mode);
void uri_write_component_str(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name);
void uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name);
void uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name);
void php_uri_property_read_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, php_uri_component_read_mode component_read_mode);
void php_uri_property_write_str_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name);
void php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name);
void php_uri_property_write_long_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name);

#endif
2 changes: 1 addition & 1 deletion ext/uri/uri_parser_php_parse_url.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static void *uri_parser_php_parse_url_parse(const char *uri_str, size_t uri_str_

php_url *url = php_url_parse_ex2(uri_str, uri_str_len, &has_port);
if (url == NULL && !silent) {
zend_throw_exception(uri_invalid_uri_exception_ce, "The specified URI is malformed", 0);
zend_throw_exception(php_uri_ce_invalid_uri_exception, "The specified URI is malformed", 0);
}

return url;
Expand Down
Loading