/src/php-src/ext/uri/php_uri_common.h
Line | Count | Source |
1 | | /* |
2 | | +----------------------------------------------------------------------+ |
3 | | | Copyright (c) The PHP Group | |
4 | | +----------------------------------------------------------------------+ |
5 | | | This source file is subject to version 3.01 of the PHP license, | |
6 | | | that is bundled with this package in the file LICENSE, and is | |
7 | | | available through the world-wide-web at the following url: | |
8 | | | https://www.php.net/license/3_01.txt | |
9 | | | If you did not receive a copy of the PHP license and are unable to | |
10 | | | obtain it through the world-wide-web, please send a note to | |
11 | | | license@php.net so we can mail you a copy immediately. | |
12 | | +----------------------------------------------------------------------+ |
13 | | | Authors: Máté Kocsis <kocsismate@php.net> | |
14 | | +----------------------------------------------------------------------+ |
15 | | */ |
16 | | |
17 | | #ifndef PHP_URI_COMMON_H |
18 | | #define PHP_URI_COMMON_H |
19 | | |
20 | | #include "php_uri_decl.h" |
21 | | |
22 | | extern zend_class_entry *php_uri_ce_rfc3986_uri; |
23 | | extern zend_class_entry *php_uri_ce_whatwg_url; |
24 | | extern zend_class_entry *php_uri_ce_comparison_mode; |
25 | | extern zend_class_entry *php_uri_ce_exception; |
26 | | extern zend_class_entry *php_uri_ce_error; |
27 | | extern zend_class_entry *php_uri_ce_invalid_uri_exception; |
28 | | extern zend_class_entry *php_uri_ce_whatwg_invalid_url_exception; |
29 | | extern zend_class_entry *php_uri_ce_whatwg_url_validation_error_type; |
30 | | extern zend_class_entry *php_uri_ce_whatwg_url_validation_error; |
31 | | |
32 | | typedef enum php_uri_recomposition_mode { |
33 | | PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, |
34 | | PHP_URI_RECOMPOSITION_MODE_RAW_UNICODE, |
35 | | PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, |
36 | | PHP_URI_RECOMPOSITION_MODE_NORMALIZED_UNICODE, |
37 | | } php_uri_recomposition_mode; |
38 | | |
39 | | typedef enum php_uri_component_read_mode { |
40 | | PHP_URI_COMPONENT_READ_MODE_RAW, |
41 | | PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII, |
42 | | PHP_URI_COMPONENT_READ_MODE_NORMALIZED_UNICODE, |
43 | | } php_uri_component_read_mode; |
44 | | |
45 | | typedef zend_result (*php_uri_property_handler_read)(void *uri, php_uri_component_read_mode read_mode, zval *retval); |
46 | | |
47 | | typedef zend_result (*php_uri_property_handler_write)(void *uri, zval *value, zval *errors); |
48 | | |
49 | | typedef enum php_uri_property_name { |
50 | | PHP_URI_PROPERTY_NAME_SCHEME, |
51 | | PHP_URI_PROPERTY_NAME_USERNAME, |
52 | | PHP_URI_PROPERTY_NAME_PASSWORD, |
53 | | PHP_URI_PROPERTY_NAME_HOST, |
54 | | PHP_URI_PROPERTY_NAME_PORT, |
55 | | PHP_URI_PROPERTY_NAME_PATH, |
56 | | PHP_URI_PROPERTY_NAME_QUERY, |
57 | | PHP_URI_PROPERTY_NAME_FRAGMENT, |
58 | | } php_uri_property_name; |
59 | | |
60 | | typedef struct php_uri_property_handler { |
61 | | php_uri_property_handler_read read; |
62 | | php_uri_property_handler_write write; |
63 | | } php_uri_property_handler; |
64 | | |
65 | | typedef struct php_uri_parser { |
66 | | /** |
67 | | * Name (the FQCN) of the URI parser. The "" name is reserved for the handler of the legacy parse_url(). |
68 | | */ |
69 | | const char *name; |
70 | | |
71 | | /** |
72 | | * Parses a URI string into a URI. |
73 | | * |
74 | | * If the URI string is valid, a URI is returned. In case of failure, NULL is |
75 | | * returned. |
76 | | * |
77 | | * The errors by-ref parameter can contain errors that occurred during parsing. |
78 | | * If the input value is NULL, or there were no errors, the errors parameter should |
79 | | * not be modified. |
80 | | * |
81 | | * If the URI string is valid and the base_url URI is not NULL, the URI object |
82 | | * is resolved against the base_url. |
83 | | * |
84 | | * If the silent parameter is true, a Uri\InvalidUriException instance must be thrown. |
85 | | * If the parameter is false, the possible errors should be handled by the caller. |
86 | | * |
87 | | * @param uri_str The input string that is going to be parsed |
88 | | * @param uri_str_len Length of the input string |
89 | | * @param base_url The base URI if reference resolution should be performed, otherwise NULL |
90 | | * @param errors An out parameter that stores additional error information |
91 | | * @param silent Whether to throw a Uri\InvalidUriException in case of failure |
92 | | */ |
93 | | void *(*parse)(const char *uri_str, size_t uri_str_len, const void *base_url, zval *errors, bool silent); |
94 | | |
95 | | /** |
96 | | * Clones a URI to a new URI. |
97 | | * |
98 | | * A deep-clone must be performed that copies all pointer members to a new memory address. |
99 | | * @param uri The input URI |
100 | | * @return The cloned URI |
101 | | */ |
102 | | void *(*clone)(void *uri); |
103 | | |
104 | | /** |
105 | | * Recomposes a URI as a string according to the recomposition_mode and exclude_fragment parameters. |
106 | | * The returned zend_string must not be persistent. |
107 | | * |
108 | | * Recomposition_mode can be one of the following: |
109 | | * - PHP_URI_RECOMPOSITION_MODE_RAW_ASCII: Recomposes the raw, non-normalized variant of the URI as a string that must only contain ASCII characters |
110 | | * - PHP_URI_RECOMPOSITION_MODE_RAW_UNICODE: Recomposes the raw, non-normalized variant of the URI as a string that may contain Unicode codepoints |
111 | | * - PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII: Recomposes the normalized variant of the URI as a string that must only contain ASCII characters |
112 | | * - PHP_URI_RECOMPOSITION_MODE_NORMALIZED_UNICODE: Recomposes the normalized variant of the URI as a string that may contain Unicode codepoints |
113 | | * |
114 | | * @param uri The input URI |
115 | | * @param recomposition_mode The type of recomposition |
116 | | * @param exclude_fragment Whether the fragment component should be part of the recomposed URI |
117 | | * @return The recomposed URI as a non-persistent zend_string |
118 | | */ |
119 | | zend_string *(*to_string)(void *uri, php_uri_recomposition_mode recomposition_mode, bool exclude_fragment); |
120 | | |
121 | | /** |
122 | | * Destroy (free) the provided URI. |
123 | | * |
124 | | * @param uri The URI to free. Must do nothing if NULL. |
125 | | */ |
126 | | void (*destroy)(void *uri); |
127 | | |
128 | | struct { |
129 | | php_uri_property_handler scheme; |
130 | | php_uri_property_handler username; |
131 | | php_uri_property_handler password; |
132 | | php_uri_property_handler host; |
133 | | php_uri_property_handler port; |
134 | | php_uri_property_handler path; |
135 | | php_uri_property_handler query; |
136 | | php_uri_property_handler fragment; |
137 | | } property_handler; |
138 | | } php_uri_parser; |
139 | | |
140 | | typedef struct php_uri_internal { |
141 | | const php_uri_parser *parser; |
142 | | void *uri; |
143 | | } php_uri_internal; |
144 | | |
145 | | typedef struct php_uri_object { |
146 | | const php_uri_parser *parser; |
147 | | void *uri; |
148 | | zend_object std; |
149 | | } php_uri_object; |
150 | | |
151 | 26 | static inline php_uri_object *php_uri_object_from_obj(zend_object *object) { |
152 | 26 | return (php_uri_object*)((char*)(object) - XtOffsetOf(php_uri_object, std)); |
153 | 26 | } Unexecuted instantiation: ftp_fopen_wrapper.c:php_uri_object_from_obj Unexecuted instantiation: http_fopen_wrapper.c:php_uri_object_from_obj php_uri.c:php_uri_object_from_obj Line | Count | Source | 151 | 26 | static inline php_uri_object *php_uri_object_from_obj(zend_object *object) { | 152 | | return (php_uri_object*)((char*)(object) - XtOffsetOf(php_uri_object, std)); | 153 | 26 | } |
Unexecuted instantiation: php_uri_common.c:php_uri_object_from_obj Unexecuted instantiation: uri_parser_rfc3986.c:php_uri_object_from_obj Unexecuted instantiation: uri_parser_whatwg.c:php_uri_object_from_obj Unexecuted instantiation: uri_parser_php_parse_url.c:php_uri_object_from_obj Unexecuted instantiation: streams.c:php_uri_object_from_obj Unexecuted instantiation: internal_functions_cli.c:php_uri_object_from_obj |
154 | | |
155 | 0 | #define Z_URI_OBJECT_P(zv) php_uri_object_from_obj(Z_OBJ_P((zv))) |
156 | | |
157 | | PHPAPI php_uri_object *php_uri_object_create(zend_class_entry *class_type, const php_uri_parser *parser); |
158 | | PHPAPI void php_uri_object_handler_free(zend_object *object); |
159 | | PHPAPI zend_object *php_uri_object_handler_clone(zend_object *object); |
160 | | |
161 | | #define PHP_URI_PARSER_RFC3986 "Uri\\Rfc3986\\Uri" |
162 | | #define PHP_URI_PARSER_WHATWG "Uri\\WhatWg\\Url" |
163 | 0 | #define PHP_URI_PARSER_PHP_PARSE_URL "parse_url" |
164 | 0 | #define PHP_URI_SERIALIZE_URI_FIELD_NAME "uri" |
165 | | |
166 | | 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) |
167 | 0 | { |
168 | 0 | switch (property_name) { |
169 | 0 | case PHP_URI_PROPERTY_NAME_SCHEME: |
170 | 0 | return &parser->property_handler.scheme; |
171 | 0 | case PHP_URI_PROPERTY_NAME_USERNAME: |
172 | 0 | return &parser->property_handler.username; |
173 | 0 | case PHP_URI_PROPERTY_NAME_PASSWORD: |
174 | 0 | return &parser->property_handler.password; |
175 | 0 | case PHP_URI_PROPERTY_NAME_HOST: |
176 | 0 | return &parser->property_handler.host; |
177 | 0 | case PHP_URI_PROPERTY_NAME_PORT: |
178 | 0 | return &parser->property_handler.port; |
179 | 0 | case PHP_URI_PROPERTY_NAME_PATH: |
180 | 0 | return &parser->property_handler.path; |
181 | 0 | case PHP_URI_PROPERTY_NAME_QUERY: |
182 | 0 | return &parser->property_handler.query; |
183 | 0 | case PHP_URI_PROPERTY_NAME_FRAGMENT: |
184 | 0 | return &parser->property_handler.fragment; |
185 | 0 | EMPTY_SWITCH_DEFAULT_CASE() |
186 | 0 | } |
187 | 0 | } Unexecuted instantiation: ftp_fopen_wrapper.c:php_uri_parser_property_handler_by_name Unexecuted instantiation: http_fopen_wrapper.c:php_uri_parser_property_handler_by_name Unexecuted instantiation: php_uri.c:php_uri_parser_property_handler_by_name Unexecuted instantiation: php_uri_common.c:php_uri_parser_property_handler_by_name Unexecuted instantiation: uri_parser_rfc3986.c:php_uri_parser_property_handler_by_name Unexecuted instantiation: uri_parser_whatwg.c:php_uri_parser_property_handler_by_name Unexecuted instantiation: uri_parser_php_parse_url.c:php_uri_parser_property_handler_by_name Unexecuted instantiation: streams.c:php_uri_parser_property_handler_by_name Unexecuted instantiation: internal_functions_cli.c:php_uri_parser_property_handler_by_name |
188 | | |
189 | | void php_uri_property_read_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, php_uri_component_read_mode component_read_mode); |
190 | | void php_uri_property_write_str_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name); |
191 | | void php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name); |
192 | | void php_uri_property_write_long_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name); |
193 | | |
194 | | #endif |