/src/php-src/ext/uri/php_uri.c
Line | Count | Source |
1 | | /* |
2 | | +----------------------------------------------------------------------+ |
3 | | | Copyright © The PHP Group and Contributors. | |
4 | | +----------------------------------------------------------------------+ |
5 | | | This source file is subject to the Modified BSD License that is | |
6 | | | bundled with this package in the file LICENSE, and is available | |
7 | | | through the World Wide Web at <https://www.php.net/license/>. | |
8 | | | | |
9 | | | SPDX-License-Identifier: BSD-3-Clause | |
10 | | +----------------------------------------------------------------------+ |
11 | | | Authors: Máté Kocsis <kocsismate@php.net> | |
12 | | +----------------------------------------------------------------------+ |
13 | | */ |
14 | | |
15 | | #ifdef HAVE_CONFIG_H |
16 | | # include <config.h> |
17 | | #endif |
18 | | |
19 | | #include "php.h" |
20 | | #include "Zend/zend_interfaces.h" |
21 | | #include "Zend/zend_exceptions.h" |
22 | | #include "ext/standard/info.h" |
23 | | |
24 | | #include "php_uri.h" |
25 | | #include "uri_parser_whatwg.h" |
26 | | #include "uri_parser_rfc3986.h" |
27 | | #include "uri_parser_php_parse_url.h" |
28 | | #include "php_uri_arginfo.h" |
29 | | #include "uriparser/Uri.h" |
30 | | |
31 | | zend_class_entry *php_uri_ce_rfc3986_uri_builder; |
32 | | zend_class_entry *php_uri_ce_rfc3986_uri; |
33 | | zend_class_entry *php_uri_ce_rfc3986_uri_type; |
34 | | zend_class_entry *php_uri_ce_rfc3986_uri_host_type; |
35 | | zend_class_entry *php_uri_ce_whatwg_url_builder; |
36 | | zend_class_entry *php_uri_ce_whatwg_url; |
37 | | zend_class_entry *php_uri_ce_whatwg_url_percent_encoding_mode; |
38 | | zend_class_entry *php_uri_ce_comparison_mode; |
39 | | zend_class_entry *php_uri_ce_exception; |
40 | | zend_class_entry *php_uri_ce_error; |
41 | | zend_class_entry *php_uri_ce_invalid_uri_exception; |
42 | | zend_class_entry *php_uri_ce_whatwg_url_host_type; |
43 | | zend_class_entry *php_uri_ce_whatwg_invalid_url_exception; |
44 | | zend_class_entry *php_uri_ce_whatwg_url_validation_error_type; |
45 | | zend_class_entry *php_uri_ce_whatwg_url_validation_error; |
46 | | |
47 | | static zend_object_handlers object_handlers_rfc3986_uri; |
48 | | static zend_object_handlers object_handlers_whatwg_uri; |
49 | | |
50 | | typedef zend_result (*php_uri_component_validator_string)(const zend_string *component); |
51 | | typedef zend_result (*php_uri_component_validator_long)(zend_long component); |
52 | | |
53 | | static const zend_module_dep uri_deps[] = { |
54 | | ZEND_MOD_REQUIRED("lexbor") |
55 | | ZEND_MOD_END |
56 | | }; |
57 | | |
58 | | static zend_array uri_parsers; |
59 | | |
60 | | static zend_always_inline zval *php_uri_deref(zval *zv) |
61 | 0 | { |
62 | 0 | if (UNEXPECTED(Z_TYPE_P(zv) == IS_REFERENCE)) { |
63 | 0 | return Z_REFVAL_P(zv); |
64 | 0 | } |
65 | | |
66 | 0 | return zv; |
67 | 0 | } |
68 | | |
69 | 0 | #define Z_RFC3986_URI_PROP_SCHEME_DEREF_P(zv) php_uri_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 0)) |
70 | 0 | #define Z_RFC3986_URI_PROP_USERINFO_DEREF_P(zv) php_uri_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 1)) |
71 | 0 | #define Z_RFC3986_URI_PROP_HOST_DEREF_P(zv) php_uri_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 2)) |
72 | 0 | #define Z_RFC3986_URI_PROP_PORT_DEREF_P(zv) php_uri_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 3)) |
73 | 0 | #define Z_RFC3986_URI_PROP_PATH_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 4) |
74 | 0 | #define Z_RFC3986_URI_PROP_PATH_DEREF_P(zv) php_uri_deref(Z_RFC3986_URI_PROP_PATH_P(zv)) |
75 | 0 | #define Z_RFC3986_URI_PROP_QUERY_DEREF_P(zv) php_uri_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 5)) |
76 | 0 | #define Z_RFC3986_URI_PROP_FRAGMENT_DEREF_P(zv) php_uri_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 6)) |
77 | | |
78 | 0 | #define Z_WHATWG_URL_PROP_SCHEME_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 0) |
79 | 0 | #define Z_WHATWG_URL_PROP_SCHEME_DEREF_P(zv) php_uri_deref(Z_WHATWG_URL_PROP_SCHEME_P(zv)) |
80 | 0 | #define Z_WHATWG_URL_PROP_USERNAME_DEREF_P(zv) php_uri_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 1)) |
81 | 0 | #define Z_WHATWG_URL_PROP_PASSWORD_DEREF_P(zv) php_uri_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 2)) |
82 | 0 | #define Z_WHATWG_URL_PROP_HOST_DEREF_P(zv) php_uri_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 3)) |
83 | 0 | #define Z_WHATWG_URL_PROP_PORT_DEREF_P(zv) php_uri_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 4)) |
84 | 0 | #define Z_WHATWG_URL_PROP_PATH_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 5) |
85 | 0 | #define Z_WHATWG_URL_PROP_PATH_DEREF_P(zv) php_uri_deref(Z_WHATWG_URL_PROP_PATH_P(zv)) |
86 | 0 | #define Z_WHATWG_URL_PROP_QUERY_DEREF_P(zv) php_uri_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 6)) |
87 | 0 | #define Z_WHATWG_URL_PROP_FRAGMENT_DEREF_P(zv) php_uri_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 7)) |
88 | | |
89 | | static HashTable *uri_get_debug_properties(php_uri_object *object) |
90 | 0 | { |
91 | 0 | const HashTable *std_properties = zend_std_get_properties(&object->std); |
92 | 0 | HashTable *result = zend_array_dup(std_properties); |
93 | |
|
94 | 0 | const php_uri_parser * const parser = object->parser; |
95 | 0 | void * const uri = object->uri; |
96 | |
|
97 | 0 | if (UNEXPECTED(uri == NULL)) { |
98 | 0 | return result; |
99 | 0 | } |
100 | | |
101 | 0 | zval tmp; |
102 | 0 | if (parser->property_handler.scheme.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) { |
103 | 0 | zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_SCHEME), &tmp); |
104 | 0 | } |
105 | |
|
106 | 0 | if (parser->property_handler.username.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) { |
107 | 0 | zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_USERNAME), &tmp); |
108 | 0 | } |
109 | |
|
110 | 0 | if (parser->property_handler.password.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) { |
111 | 0 | zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_PASSWORD), &tmp); |
112 | 0 | } |
113 | |
|
114 | 0 | if (parser->property_handler.host.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) { |
115 | 0 | zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_HOST), &tmp); |
116 | 0 | } |
117 | |
|
118 | 0 | if (parser->property_handler.port.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) { |
119 | 0 | zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_PORT), &tmp); |
120 | 0 | } |
121 | |
|
122 | 0 | if (parser->property_handler.path.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) { |
123 | 0 | zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_PATH), &tmp); |
124 | 0 | } |
125 | |
|
126 | 0 | if (parser->property_handler.query.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) { |
127 | 0 | zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_QUERY), &tmp); |
128 | 0 | } |
129 | |
|
130 | 0 | if (parser->property_handler.fragment.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) { |
131 | 0 | zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_FRAGMENT), &tmp); |
132 | 0 | } |
133 | |
|
134 | 0 | return result; |
135 | 0 | } |
136 | | |
137 | | PHPAPI const php_uri_parser *php_uri_get_parser(zend_string *uri_parser_name) |
138 | 0 | { |
139 | 0 | if (uri_parser_name == NULL) { |
140 | 0 | return zend_hash_str_find_ptr(&uri_parsers, PHP_URI_PARSER_PHP_PARSE_URL, sizeof(PHP_URI_PARSER_PHP_PARSE_URL) - 1); |
141 | 0 | } |
142 | | |
143 | 0 | return zend_hash_find_ptr(&uri_parsers, uri_parser_name); |
144 | 0 | } |
145 | | |
146 | | 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) |
147 | 0 | { |
148 | 0 | void *uri = uri_parser->parse(uri_str, uri_str_len, NULL, NULL, silent); |
149 | |
|
150 | 0 | if (uri == NULL) { |
151 | 0 | return NULL; |
152 | 0 | } |
153 | | |
154 | 0 | php_uri_internal *internal_uri = emalloc(sizeof(*internal_uri)); |
155 | 0 | internal_uri->parser = uri_parser; |
156 | 0 | internal_uri->uri = uri; |
157 | |
|
158 | 0 | return internal_uri; |
159 | 0 | } |
160 | | |
161 | | 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) |
162 | 0 | { |
163 | 0 | return internal_uri->parser->property_handler.scheme.read(internal_uri->uri, read_mode, zv); |
164 | 0 | } |
165 | | |
166 | | 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) |
167 | 0 | { |
168 | 0 | return internal_uri->parser->property_handler.username.read(internal_uri->uri, read_mode, zv); |
169 | 0 | } |
170 | | |
171 | | 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) |
172 | 0 | { |
173 | 0 | return internal_uri->parser->property_handler.password.read(internal_uri->uri, read_mode, zv); |
174 | 0 | } |
175 | | |
176 | | 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) |
177 | 0 | { |
178 | 0 | return internal_uri->parser->property_handler.host.read(internal_uri->uri, read_mode, zv); |
179 | 0 | } |
180 | | |
181 | | 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) |
182 | 0 | { |
183 | 0 | return internal_uri->parser->property_handler.port.read(internal_uri->uri, read_mode, zv); |
184 | 0 | } |
185 | | |
186 | | 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) |
187 | 0 | { |
188 | 0 | return internal_uri->parser->property_handler.path.read(internal_uri->uri, read_mode, zv); |
189 | 0 | } |
190 | | |
191 | | 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) |
192 | 0 | { |
193 | 0 | return internal_uri->parser->property_handler.query.read(internal_uri->uri, read_mode, zv); |
194 | 0 | } |
195 | | |
196 | | 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) |
197 | 0 | { |
198 | 0 | return internal_uri->parser->property_handler.fragment.read(internal_uri->uri, read_mode, zv); |
199 | 0 | } |
200 | | |
201 | | ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_free(php_uri_internal *internal_uri) |
202 | 0 | { |
203 | 0 | internal_uri->parser->destroy(internal_uri->uri); |
204 | 0 | internal_uri->uri = NULL; |
205 | 0 | internal_uri->parser = NULL; |
206 | 0 | efree(internal_uri); |
207 | 0 | } |
208 | | |
209 | | ZEND_ATTRIBUTE_NONNULL PHPAPI php_uri *php_uri_parse_to_struct( |
210 | | const php_uri_parser *uri_parser, const char *uri_str, size_t uri_str_len, php_uri_component_read_mode read_mode, bool silent |
211 | 0 | ) { |
212 | 0 | php_uri_internal *uri_internal = php_uri_parse(uri_parser, uri_str, uri_str_len, silent); |
213 | 0 | if (uri_internal == NULL) { |
214 | 0 | return NULL; |
215 | 0 | } |
216 | | |
217 | 0 | php_uri *uri = ecalloc(1, sizeof(*uri)); |
218 | 0 | zval tmp; |
219 | 0 | zend_result result; |
220 | |
|
221 | 0 | result = php_uri_get_scheme(uri_internal, read_mode, &tmp); |
222 | 0 | if (result == FAILURE) { |
223 | 0 | goto error; |
224 | 0 | } |
225 | 0 | if (Z_TYPE(tmp) == IS_STRING) { |
226 | 0 | uri->scheme = Z_STR(tmp); |
227 | 0 | } |
228 | |
|
229 | 0 | result = php_uri_get_username(uri_internal, read_mode, &tmp); |
230 | 0 | if (result == FAILURE) { |
231 | 0 | goto error; |
232 | 0 | } |
233 | 0 | if (Z_TYPE(tmp) == IS_STRING) { |
234 | 0 | uri->user = Z_STR(tmp); |
235 | 0 | } |
236 | |
|
237 | 0 | result = php_uri_get_password(uri_internal, read_mode, &tmp); |
238 | 0 | if (result == FAILURE) { |
239 | 0 | goto error; |
240 | 0 | } |
241 | 0 | if (Z_TYPE(tmp) == IS_STRING) { |
242 | 0 | uri->password = Z_STR(tmp); |
243 | 0 | } |
244 | |
|
245 | 0 | result = php_uri_get_host(uri_internal, read_mode, &tmp); |
246 | 0 | if (result == FAILURE) { |
247 | 0 | goto error; |
248 | 0 | } |
249 | 0 | if (Z_TYPE(tmp) == IS_STRING) { |
250 | 0 | uri->host = Z_STR(tmp); |
251 | 0 | } |
252 | |
|
253 | 0 | result = php_uri_get_port(uri_internal, read_mode, &tmp); |
254 | 0 | if (result == FAILURE) { |
255 | 0 | goto error; |
256 | 0 | } |
257 | 0 | if (Z_TYPE(tmp) == IS_LONG) { |
258 | 0 | uri->port = Z_LVAL(tmp); |
259 | 0 | } |
260 | |
|
261 | 0 | result = php_uri_get_path(uri_internal, read_mode, &tmp); |
262 | 0 | if (result == FAILURE) { |
263 | 0 | goto error; |
264 | 0 | } |
265 | 0 | if (Z_TYPE(tmp) == IS_STRING) { |
266 | 0 | uri->path = Z_STR(tmp); |
267 | 0 | } |
268 | |
|
269 | 0 | result = php_uri_get_query(uri_internal, read_mode, &tmp); |
270 | 0 | if (result == FAILURE) { |
271 | 0 | goto error; |
272 | 0 | } |
273 | 0 | if (Z_TYPE(tmp) == IS_STRING) { |
274 | 0 | uri->query = Z_STR(tmp); |
275 | 0 | } |
276 | |
|
277 | 0 | result = php_uri_get_fragment(uri_internal, read_mode, &tmp); |
278 | 0 | if (result == FAILURE) { |
279 | 0 | goto error; |
280 | 0 | } |
281 | 0 | if (Z_TYPE(tmp) == IS_STRING) { |
282 | 0 | uri->fragment = Z_STR(tmp); |
283 | 0 | } |
284 | |
|
285 | 0 | php_uri_free(uri_internal); |
286 | |
|
287 | 0 | return uri; |
288 | | |
289 | 0 | error: |
290 | 0 | php_uri_free(uri_internal); |
291 | 0 | php_uri_struct_free(uri); |
292 | |
|
293 | 0 | return NULL; |
294 | 0 | } |
295 | | |
296 | | ZEND_ATTRIBUTE_NONNULL PHPAPI void php_uri_struct_free(php_uri *uri) |
297 | 0 | { |
298 | 0 | if (uri->scheme) { |
299 | 0 | zend_string_release(uri->scheme); |
300 | 0 | } |
301 | 0 | if (uri->user) { |
302 | 0 | zend_string_release(uri->user); |
303 | 0 | } |
304 | 0 | if (uri->password) { |
305 | 0 | zend_string_release(uri->password); |
306 | 0 | } |
307 | 0 | if (uri->host) { |
308 | 0 | zend_string_release(uri->host); |
309 | 0 | } |
310 | 0 | if (uri->path) { |
311 | 0 | zend_string_release(uri->path); |
312 | 0 | } |
313 | 0 | if (uri->query) { |
314 | 0 | zend_string_release(uri->query); |
315 | 0 | } |
316 | 0 | if (uri->fragment) { |
317 | 0 | zend_string_release(uri->fragment); |
318 | 0 | } |
319 | |
|
320 | 0 | efree(uri); |
321 | 0 | } |
322 | | |
323 | | /** |
324 | | * Pass the errors parameter by ref to errors_zv for userland, and frees it if |
325 | | * it is not not needed anymore. |
326 | | */ |
327 | | static zend_result pass_errors_by_ref_and_free(zval *errors_zv, zval *errors) |
328 | 0 | { |
329 | 0 | ZEND_ASSERT(Z_TYPE_P(errors) == IS_UNDEF || Z_TYPE_P(errors) == IS_ARRAY); |
330 | | |
331 | | /* There was no error during parsing */ |
332 | 0 | if (Z_ISUNDEF_P(errors)) { |
333 | 0 | return SUCCESS; |
334 | 0 | } |
335 | | |
336 | | /* The errors parameter is an array, but the pass-by ref argument stored by |
337 | | * errors_zv was not passed - the URI implementation either doesn't support |
338 | | * returning additional error information, or the caller is not interested in it */ |
339 | 0 | if (errors_zv == NULL) { |
340 | 0 | zval_ptr_dtor(errors); |
341 | 0 | return SUCCESS; |
342 | 0 | } |
343 | | |
344 | 0 | ZEND_TRY_ASSIGN_REF_TMP(errors_zv, errors); |
345 | 0 | if (EG(exception)) { |
346 | 0 | return FAILURE; |
347 | 0 | } |
348 | | |
349 | 0 | return SUCCESS; |
350 | 0 | } |
351 | | |
352 | | ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) PHPAPI void php_uri_instantiate_uri( |
353 | | INTERNAL_FUNCTION_PARAMETERS, const zend_string *uri_str, const php_uri_object *base_url_object, |
354 | | bool should_throw, bool should_update_this_object, zval *errors_zv |
355 | 0 | ) { |
356 | |
|
357 | 0 | php_uri_object *uri_object; |
358 | 0 | if (should_update_this_object) { |
359 | 0 | uri_object = Z_URI_OBJECT_P(ZEND_THIS); |
360 | 0 | if (uri_object->uri != NULL) { |
361 | 0 | zend_throw_error(NULL, "Cannot modify readonly object of class %pS", Z_OBJCE_P(ZEND_THIS)->name); |
362 | 0 | RETURN_THROWS(); |
363 | 0 | } |
364 | 0 | } else { |
365 | 0 | if (EX(func)->common.fn_flags & ZEND_ACC_STATIC) { |
366 | 0 | object_init_ex(return_value, Z_CE_P(ZEND_THIS)); |
367 | 0 | } else { |
368 | 0 | object_init_ex(return_value, Z_OBJCE_P(ZEND_THIS)); |
369 | 0 | } |
370 | 0 | uri_object = Z_URI_OBJECT_P(return_value); |
371 | 0 | } |
372 | | |
373 | 0 | const php_uri_parser *uri_parser = uri_object->parser; |
374 | |
|
375 | 0 | zval errors; |
376 | 0 | ZVAL_UNDEF(&errors); |
377 | |
|
378 | 0 | void *base_url = NULL; |
379 | 0 | if (base_url_object != NULL) { |
380 | 0 | ZEND_ASSERT(base_url_object->std.ce == uri_object->std.ce); |
381 | 0 | ZEND_ASSERT(base_url_object->uri != NULL); |
382 | 0 | ZEND_ASSERT(base_url_object->parser == uri_parser); |
383 | 0 | base_url = base_url_object->uri; |
384 | 0 | } |
385 | |
|
386 | 0 | void *uri = uri_parser->parse(ZSTR_VAL(uri_str), ZSTR_LEN(uri_str), base_url, errors_zv != NULL ? &errors : NULL, !should_throw); |
387 | 0 | if (UNEXPECTED(uri == NULL)) { |
388 | 0 | if (should_throw) { |
389 | 0 | zval_ptr_dtor(&errors); |
390 | 0 | ZVAL_EMPTY_ARRAY(&errors); |
391 | 0 | pass_errors_by_ref_and_free(errors_zv, &errors); |
392 | 0 | RETURN_THROWS(); |
393 | 0 | } else { |
394 | 0 | if (pass_errors_by_ref_and_free(errors_zv, &errors) == FAILURE) { |
395 | 0 | RETURN_THROWS(); |
396 | 0 | } |
397 | 0 | zval_ptr_dtor(return_value); |
398 | 0 | RETURN_NULL(); |
399 | 0 | } |
400 | 0 | } |
401 | | |
402 | 0 | if (pass_errors_by_ref_and_free(errors_zv, &errors) == FAILURE) { |
403 | 0 | uri_parser->destroy(uri); |
404 | 0 | RETURN_THROWS(); |
405 | 0 | } |
406 | | |
407 | 0 | uri_object->uri = uri; |
408 | 0 | } |
409 | | |
410 | | static void create_rfc3986_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor) |
411 | 0 | { |
412 | 0 | zend_string *uri_str; |
413 | 0 | zend_object *base_url_object = NULL; |
414 | |
|
415 | 0 | ZEND_PARSE_PARAMETERS_START(1, 2) |
416 | 0 | Z_PARAM_STR(uri_str) |
417 | 0 | Z_PARAM_OPTIONAL |
418 | 0 | Z_PARAM_OBJ_OF_CLASS_OR_NULL(base_url_object, php_uri_ce_rfc3986_uri) |
419 | 0 | ZEND_PARSE_PARAMETERS_END(); |
420 | | |
421 | 0 | php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, |
422 | 0 | uri_str, base_url_object ? php_uri_object_from_obj(base_url_object) : NULL, is_constructor, is_constructor, NULL); |
423 | 0 | } |
424 | | |
425 | | static bool is_list_of_whatwg_validation_errors(const HashTable *array) |
426 | 0 | { |
427 | 0 | if (!zend_array_is_list(array)) { |
428 | 0 | return false; |
429 | 0 | } |
430 | | |
431 | 0 | ZEND_HASH_FOREACH_VAL(array, zval *val) { |
432 | | /* Do not allow references as they may change types after checking. */ |
433 | |
|
434 | 0 | if (Z_TYPE_P(val) != IS_OBJECT) { |
435 | 0 | return false; |
436 | 0 | } |
437 | | |
438 | 0 | if (!instanceof_function(Z_OBJCE_P(val), php_uri_ce_whatwg_url_validation_error)) { |
439 | 0 | return false; |
440 | 0 | } |
441 | 0 | } ZEND_HASH_FOREACH_END(); |
442 | | |
443 | 0 | return true; |
444 | 0 | } |
445 | | |
446 | | PHP_METHOD(Uri_Rfc3986_Uri, parse) |
447 | 0 | { |
448 | 0 | create_rfc3986_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, false); |
449 | 0 | } |
450 | | |
451 | | PHP_METHOD(Uri_Rfc3986_Uri, __construct) |
452 | 0 | { |
453 | 0 | create_rfc3986_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, true); |
454 | 0 | } |
455 | | |
456 | | PHP_METHOD(Uri_WhatWg_InvalidUrlException, __construct) |
457 | 0 | { |
458 | 0 | zend_string *message = NULL; |
459 | 0 | zval *errors = NULL; |
460 | 0 | zend_long code = 0; |
461 | 0 | zval *previous = NULL; |
462 | |
|
463 | 0 | ZEND_PARSE_PARAMETERS_START(0, 4) |
464 | 0 | Z_PARAM_OPTIONAL |
465 | 0 | Z_PARAM_STR(message) |
466 | 0 | Z_PARAM_ARRAY(errors) |
467 | 0 | Z_PARAM_LONG(code) |
468 | 0 | Z_PARAM_OBJECT_OF_CLASS_OR_NULL(previous, zend_ce_throwable) |
469 | 0 | ZEND_PARSE_PARAMETERS_END(); |
470 | | |
471 | 0 | if (zend_update_exception_properties(INTERNAL_FUNCTION_PARAM_PASSTHRU, message, code, previous) == FAILURE) { |
472 | 0 | RETURN_THROWS(); |
473 | 0 | } |
474 | | |
475 | 0 | if (errors == NULL) { |
476 | 0 | zval tmp; |
477 | 0 | ZVAL_EMPTY_ARRAY(&tmp); |
478 | 0 | zend_update_property(php_uri_ce_whatwg_invalid_url_exception, Z_OBJ_P(ZEND_THIS), ZEND_STRL("errors"), &tmp); |
479 | 0 | } else { |
480 | 0 | if (!is_list_of_whatwg_validation_errors(Z_ARR_P(errors))) { |
481 | 0 | zend_argument_value_error(2, "must be a list of %pS", php_uri_ce_whatwg_url_validation_error->name); |
482 | 0 | RETURN_THROWS(); |
483 | 0 | } |
484 | | |
485 | 0 | zend_update_property(php_uri_ce_whatwg_invalid_url_exception, Z_OBJ_P(ZEND_THIS), ZEND_STRL("errors"), errors); |
486 | 0 | } |
487 | 0 | if (EG(exception)) { |
488 | 0 | RETURN_THROWS(); |
489 | 0 | } |
490 | 0 | } |
491 | | |
492 | | PHP_METHOD(Uri_WhatWg_UrlValidationError, __construct) |
493 | 0 | { |
494 | 0 | zend_string *context; |
495 | 0 | zval *type; |
496 | 0 | bool failure; |
497 | |
|
498 | 0 | ZEND_PARSE_PARAMETERS_START(3, 3) |
499 | 0 | Z_PARAM_STR(context) |
500 | 0 | Z_PARAM_OBJECT_OF_CLASS(type, php_uri_ce_whatwg_url_validation_error_type) |
501 | 0 | Z_PARAM_BOOL(failure) |
502 | 0 | ZEND_PARSE_PARAMETERS_END(); |
503 | | |
504 | 0 | zend_update_property_str(php_uri_ce_whatwg_url_validation_error, Z_OBJ_P(ZEND_THIS), ZEND_STRL("context"), context); |
505 | 0 | if (EG(exception)) { |
506 | 0 | RETURN_THROWS(); |
507 | 0 | } |
508 | | |
509 | 0 | zend_update_property_ex(php_uri_ce_whatwg_url_validation_error, Z_OBJ_P(ZEND_THIS), ZSTR_KNOWN(ZEND_STR_TYPE), type); |
510 | 0 | if (EG(exception)) { |
511 | 0 | RETURN_THROWS(); |
512 | 0 | } |
513 | | |
514 | 0 | zval failure_zv; |
515 | 0 | ZVAL_BOOL(&failure_zv, failure); |
516 | 0 | zend_update_property(php_uri_ce_whatwg_url_validation_error, Z_OBJ_P(ZEND_THIS), ZEND_STRL("failure"), &failure_zv); |
517 | 0 | if (EG(exception)) { |
518 | 0 | RETURN_THROWS(); |
519 | 0 | } |
520 | 0 | } |
521 | | |
522 | | static void create_whatwg_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor) |
523 | 0 | { |
524 | 0 | zend_string *uri_str; |
525 | 0 | zend_object *base_url_object = NULL; |
526 | 0 | zval *errors = NULL; |
527 | |
|
528 | 0 | ZEND_PARSE_PARAMETERS_START(1, 3) |
529 | 0 | Z_PARAM_STR(uri_str) |
530 | 0 | Z_PARAM_OPTIONAL |
531 | 0 | Z_PARAM_OBJ_OF_CLASS_OR_NULL(base_url_object, php_uri_ce_whatwg_url) |
532 | 0 | Z_PARAM_ZVAL(errors) |
533 | 0 | ZEND_PARSE_PARAMETERS_END(); |
534 | | |
535 | 0 | php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, |
536 | 0 | uri_str, base_url_object ? php_uri_object_from_obj(base_url_object) : NULL, is_constructor, is_constructor, errors); |
537 | 0 | } |
538 | | |
539 | | PHP_METHOD(Uri_WhatWg_Url, parse) |
540 | 0 | { |
541 | 0 | create_whatwg_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, false); |
542 | 0 | } |
543 | | |
544 | | PHP_METHOD(Uri_WhatWg_Url, __construct) |
545 | 0 | { |
546 | 0 | create_whatwg_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, true); |
547 | 0 | } |
548 | | |
549 | | PHP_METHOD(Uri_Rfc3986_Uri, getUriType) |
550 | 0 | { |
551 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
552 | | |
553 | 0 | php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); |
554 | 0 | ZEND_ASSERT(uri_object->uri != NULL); |
555 | |
|
556 | 0 | php_uri_parser_rfc3986_uri_type_read(uri_object->uri, return_value); |
557 | 0 | } |
558 | | |
559 | | PHP_METHOD(Uri_Rfc3986_Uri, getScheme) |
560 | 0 | { |
561 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); |
562 | 0 | } |
563 | | |
564 | | PHP_METHOD(Uri_Rfc3986_Uri, getRawScheme) |
565 | 0 | { |
566 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME, PHP_URI_COMPONENT_READ_MODE_RAW); |
567 | 0 | } |
568 | | |
569 | | PHP_METHOD(Uri_Rfc3986_Uri, withScheme) |
570 | 0 | { |
571 | 0 | php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME); |
572 | 0 | } |
573 | | |
574 | | static void rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAMETERS, php_uri_component_read_mode read_mode) |
575 | 0 | { |
576 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
577 | | |
578 | 0 | php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); |
579 | 0 | ZEND_ASSERT(uri_object->uri != NULL); |
580 | |
|
581 | 0 | if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_read(uri_object->uri, read_mode, return_value) == FAILURE)) { |
582 | 0 | zend_throw_error(NULL, "The userinfo component cannot be retrieved"); |
583 | 0 | RETURN_THROWS(); |
584 | 0 | } |
585 | 0 | } |
586 | | |
587 | | PHP_METHOD(Uri_Rfc3986_Uri, getUserInfo) |
588 | 0 | { |
589 | 0 | rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); |
590 | 0 | } |
591 | | |
592 | | PHP_METHOD(Uri_Rfc3986_Uri, getRawUserInfo) |
593 | 0 | { |
594 | 0 | rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_COMPONENT_READ_MODE_RAW); |
595 | 0 | } |
596 | | |
597 | | PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo) |
598 | 0 | { |
599 | 0 | zend_string *value; |
600 | |
|
601 | 0 | ZEND_PARSE_PARAMETERS_START(1, 1) |
602 | 0 | Z_PARAM_STR_OR_NULL(value) |
603 | 0 | ZEND_PARSE_PARAMETERS_END(); |
604 | | |
605 | 0 | zval zv; |
606 | 0 | if (value == NULL) { |
607 | 0 | ZVAL_NULL(&zv); |
608 | 0 | } else { |
609 | 0 | ZVAL_STR(&zv, value); |
610 | 0 | } |
611 | |
|
612 | 0 | php_uri_object *old_uri_object = php_uri_object_from_obj(Z_OBJ_P(ZEND_THIS)); |
613 | 0 | ZEND_ASSERT(old_uri_object->uri != NULL); |
614 | |
|
615 | 0 | zend_object *new_object = old_uri_object->std.handlers->clone_obj(&old_uri_object->std); |
616 | 0 | if (new_object == NULL) { |
617 | 0 | RETURN_THROWS(); |
618 | 0 | } |
619 | | |
620 | | /* Assign the object early. The engine will take care of destruction in |
621 | | * case of an exception being thrown. */ |
622 | 0 | RETVAL_OBJ(new_object); |
623 | |
|
624 | 0 | php_uri_object *new_uri_object = php_uri_object_from_obj(new_object); |
625 | 0 | ZEND_ASSERT(new_uri_object->uri != NULL); |
626 | |
|
627 | 0 | if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_write(new_uri_object->uri, &zv, NULL) == FAILURE)) { |
628 | 0 | RETURN_THROWS(); |
629 | 0 | } |
630 | 0 | } |
631 | | |
632 | | PHP_METHOD(Uri_Rfc3986_Uri, getUsername) |
633 | 0 | { |
634 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_USERNAME, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); |
635 | 0 | } |
636 | | |
637 | | PHP_METHOD(Uri_Rfc3986_Uri, getRawUsername) |
638 | 0 | { |
639 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_USERNAME, PHP_URI_COMPONENT_READ_MODE_RAW); |
640 | 0 | } |
641 | | |
642 | | PHP_METHOD(Uri_Rfc3986_Uri, getPassword) |
643 | 0 | { |
644 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PASSWORD, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); |
645 | 0 | } |
646 | | |
647 | | PHP_METHOD(Uri_Rfc3986_Uri, getRawPassword) |
648 | 0 | { |
649 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PASSWORD, PHP_URI_COMPONENT_READ_MODE_RAW); |
650 | 0 | } |
651 | | |
652 | | PHP_METHOD(Uri_Rfc3986_Uri, getHost) |
653 | 0 | { |
654 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); |
655 | 0 | } |
656 | | |
657 | | PHP_METHOD(Uri_Rfc3986_Uri, getRawHost) |
658 | 0 | { |
659 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST, PHP_URI_COMPONENT_READ_MODE_RAW); |
660 | 0 | } |
661 | | |
662 | | PHP_METHOD(Uri_Rfc3986_Uri, getHostType) |
663 | 0 | { |
664 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
665 | | |
666 | 0 | php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); |
667 | 0 | ZEND_ASSERT(uri_object->uri != NULL); |
668 | |
|
669 | 0 | php_uri_parser_rfc3986_host_type_read(uri_object->uri, return_value); |
670 | 0 | } |
671 | | |
672 | | PHP_METHOD(Uri_Rfc3986_Uri, withHost) |
673 | 0 | { |
674 | 0 | php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST); |
675 | 0 | } |
676 | | |
677 | | PHP_METHOD(Uri_Rfc3986_Uri, getPort) |
678 | 0 | { |
679 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PORT, PHP_URI_COMPONENT_READ_MODE_RAW); |
680 | 0 | } |
681 | | |
682 | | PHP_METHOD(Uri_Rfc3986_Uri, withPort) |
683 | 0 | { |
684 | 0 | php_uri_property_write_long_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PORT); |
685 | 0 | } |
686 | | |
687 | | PHP_METHOD(Uri_Rfc3986_Uri, getPath) |
688 | 0 | { |
689 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PATH, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); |
690 | 0 | } |
691 | | |
692 | | PHP_METHOD(Uri_Rfc3986_Uri, getRawPath) |
693 | 0 | { |
694 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PATH, PHP_URI_COMPONENT_READ_MODE_RAW); |
695 | 0 | } |
696 | | |
697 | | PHP_METHOD(Uri_Rfc3986_Uri, withPath) |
698 | 0 | { |
699 | 0 | php_uri_property_write_str_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PATH); |
700 | 0 | } |
701 | | |
702 | | PHP_METHOD(Uri_Rfc3986_Uri, getQuery) |
703 | 0 | { |
704 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); |
705 | 0 | } |
706 | | |
707 | | PHP_METHOD(Uri_Rfc3986_Uri, getRawQuery) |
708 | 0 | { |
709 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY, PHP_URI_COMPONENT_READ_MODE_RAW); |
710 | 0 | } |
711 | | |
712 | | PHP_METHOD(Uri_Rfc3986_Uri, withQuery) |
713 | 0 | { |
714 | 0 | php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY); |
715 | 0 | } |
716 | | |
717 | | PHP_METHOD(Uri_Rfc3986_Uri, getFragment) |
718 | 0 | { |
719 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); |
720 | 0 | } |
721 | | |
722 | | PHP_METHOD(Uri_Rfc3986_Uri, getRawFragment) |
723 | 0 | { |
724 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT, PHP_URI_COMPONENT_READ_MODE_RAW); |
725 | 0 | } |
726 | | |
727 | | PHP_METHOD(Uri_Rfc3986_Uri, withFragment) |
728 | 0 | { |
729 | 0 | php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT); |
730 | 0 | } |
731 | | |
732 | | static void throw_cannot_recompose_uri_to_string(php_uri_object *object) |
733 | 0 | { |
734 | 0 | if (ZEND_HAS_OOM()) { |
735 | 0 | zend_handle_delayed_oom(); |
736 | 0 | return; |
737 | 0 | } |
738 | | |
739 | 0 | zend_throw_exception_ex(php_uri_ce_error, 0, "Cannot recompose %pS to a string", object->std.ce->name); |
740 | 0 | } |
741 | | |
742 | | static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, php_uri_object *that_object, zend_enum_Uri_UriComparisonMode comparison_mode) |
743 | 0 | { |
744 | 0 | php_uri_object *this_object = Z_URI_OBJECT_P(ZEND_THIS); |
745 | 0 | ZEND_ASSERT(this_object->uri != NULL); |
746 | 0 | ZEND_ASSERT(that_object->uri != NULL); |
747 | |
|
748 | 0 | if (this_object->std.ce != that_object->std.ce && |
749 | 0 | !instanceof_function(this_object->std.ce, that_object->std.ce) && |
750 | 0 | !instanceof_function(that_object->std.ce, this_object->std.ce) |
751 | 0 | ) { |
752 | 0 | RETURN_FALSE; |
753 | 0 | } |
754 | | |
755 | 0 | bool exclude_fragment = comparison_mode == ZEND_ENUM_Uri_UriComparisonMode_ExcludeFragment; |
756 | |
|
757 | 0 | zend_string *this_str = this_object->parser->to_string( |
758 | 0 | this_object->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, exclude_fragment); |
759 | 0 | if (this_str == NULL) { |
760 | 0 | throw_cannot_recompose_uri_to_string(this_object); |
761 | 0 | RETURN_THROWS(); |
762 | 0 | } |
763 | | |
764 | 0 | zend_string *that_str = that_object->parser->to_string( |
765 | 0 | that_object->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, exclude_fragment); |
766 | 0 | if (that_str == NULL) { |
767 | 0 | zend_string_release(this_str); |
768 | 0 | throw_cannot_recompose_uri_to_string(that_object); |
769 | 0 | RETURN_THROWS(); |
770 | 0 | } |
771 | | |
772 | 0 | RETVAL_BOOL(zend_string_equals(this_str, that_str)); |
773 | |
|
774 | 0 | zend_string_release(this_str); |
775 | 0 | zend_string_release(that_str); |
776 | 0 | } |
777 | | |
778 | | PHP_METHOD(Uri_Rfc3986_Uri, equals) |
779 | 0 | { |
780 | 0 | zend_object *that_object; |
781 | 0 | zend_enum_Uri_UriComparisonMode comparison_mode = ZEND_ENUM_Uri_UriComparisonMode_ExcludeFragment; |
782 | |
|
783 | 0 | ZEND_PARSE_PARAMETERS_START(1, 2) |
784 | 0 | Z_PARAM_OBJ_OF_CLASS(that_object, php_uri_ce_rfc3986_uri) |
785 | 0 | Z_PARAM_OPTIONAL |
786 | 0 | Z_PARAM_ENUM(comparison_mode, php_uri_ce_comparison_mode) |
787 | 0 | ZEND_PARSE_PARAMETERS_END(); |
788 | | |
789 | 0 | uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, php_uri_object_from_obj(that_object), comparison_mode); |
790 | 0 | } |
791 | | |
792 | | PHP_METHOD(Uri_Rfc3986_Uri, toRawString) |
793 | 0 | { |
794 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
795 | | |
796 | 0 | php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); |
797 | 0 | ZEND_ASSERT(uri_object->uri != NULL); |
798 | |
|
799 | 0 | zend_string *uri_str = uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); |
800 | 0 | if (uri_str == NULL) { |
801 | 0 | throw_cannot_recompose_uri_to_string(uri_object); |
802 | 0 | RETURN_THROWS(); |
803 | 0 | } |
804 | | |
805 | 0 | RETURN_STR(uri_str); |
806 | 0 | } |
807 | | |
808 | | PHP_METHOD(Uri_Rfc3986_Uri, toString) |
809 | 0 | { |
810 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
811 | | |
812 | 0 | php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); |
813 | 0 | ZEND_ASSERT(uri_object->uri != NULL); |
814 | |
|
815 | 0 | zend_string *uri_str = uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_NORMALIZED_ASCII, false); |
816 | 0 | if (uri_str == NULL) { |
817 | 0 | throw_cannot_recompose_uri_to_string(uri_object); |
818 | 0 | RETURN_THROWS(); |
819 | 0 | } |
820 | | |
821 | 0 | RETURN_STR(uri_str); |
822 | 0 | } |
823 | | |
824 | | PHP_METHOD(Uri_Rfc3986_Uri, resolve) |
825 | 0 | { |
826 | 0 | zend_string *uri_str; |
827 | |
|
828 | 0 | ZEND_PARSE_PARAMETERS_START(1, 1) |
829 | 0 | Z_PARAM_STR(uri_str) |
830 | 0 | ZEND_PARSE_PARAMETERS_END(); |
831 | | |
832 | 0 | php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, |
833 | 0 | uri_str, Z_URI_OBJECT_P(ZEND_THIS), true, false, NULL); |
834 | 0 | } |
835 | | |
836 | | PHP_METHOD(Uri_Rfc3986_Uri, __serialize) |
837 | 0 | { |
838 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
839 | | |
840 | 0 | php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); |
841 | 0 | ZEND_ASSERT(uri_object->uri != NULL); |
842 | | |
843 | | /* Serialize state: "uri" key in the first array */ |
844 | 0 | zend_string *uri_str = uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); |
845 | 0 | if (uri_str == NULL) { |
846 | 0 | throw_cannot_recompose_uri_to_string(uri_object); |
847 | 0 | RETURN_THROWS(); |
848 | 0 | } |
849 | 0 | zval tmp; |
850 | 0 | ZVAL_STR(&tmp, uri_str); |
851 | |
|
852 | 0 | array_init(return_value); |
853 | |
|
854 | 0 | zval arr; |
855 | 0 | array_init(&arr); |
856 | 0 | zend_hash_str_add_new(Z_ARRVAL(arr), PHP_URI_SERIALIZE_URI_FIELD_NAME, sizeof(PHP_URI_SERIALIZE_URI_FIELD_NAME) - 1, &tmp); |
857 | 0 | zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr); |
858 | | |
859 | | /* Serialize regular properties: second array */ |
860 | 0 | ZVAL_EMPTY_ARRAY(&arr); |
861 | 0 | zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr); |
862 | 0 | } |
863 | | |
864 | | static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS) |
865 | 11 | { |
866 | 11 | HashTable *data; |
867 | | |
868 | 33 | ZEND_PARSE_PARAMETERS_START(1, 1) |
869 | 44 | Z_PARAM_ARRAY_HT(data) |
870 | 11 | ZEND_PARSE_PARAMETERS_END(); |
871 | | |
872 | 11 | php_uri_object *uri_object = php_uri_object_from_obj(Z_OBJ_P(ZEND_THIS)); |
873 | 11 | if (uri_object->uri != NULL) { |
874 | | /* Intentionally throw two exceptions for proper chaining. */ |
875 | 0 | zend_throw_error(NULL, "Cannot modify readonly object of class %pS", uri_object->std.ce->name); |
876 | 0 | zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %pS object", uri_object->std.ce->name); |
877 | 0 | RETURN_THROWS(); |
878 | 0 | } |
879 | | |
880 | | /* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */ |
881 | 11 | if (zend_hash_num_elements(data) != 2) { |
882 | 9 | zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %pS object", uri_object->std.ce->name); |
883 | 9 | RETURN_THROWS(); |
884 | 9 | } |
885 | | |
886 | | /* Unserialize state: "uri" key in the first array */ |
887 | 2 | zval *arr = zend_hash_index_find(data, 0); |
888 | 2 | if (arr == NULL || Z_TYPE_P(arr) != IS_ARRAY) { |
889 | 2 | zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %pS object", uri_object->std.ce->name); |
890 | 2 | RETURN_THROWS(); |
891 | 2 | } |
892 | | |
893 | | /* Verify the expected number of elements inside the first array, this implicitly ensures that no additional elements are present. */ |
894 | 0 | if (zend_hash_num_elements(Z_ARRVAL_P(arr)) != 1) { |
895 | 0 | zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %pS object", uri_object->std.ce->name); |
896 | 0 | RETURN_THROWS(); |
897 | 0 | } |
898 | | |
899 | 0 | zval *uri_zv = zend_hash_str_find(Z_ARRVAL_P(arr), ZEND_STRL(PHP_URI_SERIALIZE_URI_FIELD_NAME)); |
900 | 0 | if (uri_zv == NULL || Z_TYPE_P(uri_zv) != IS_STRING) { |
901 | 0 | zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %pS object", uri_object->std.ce->name); |
902 | 0 | RETURN_THROWS(); |
903 | 0 | } |
904 | | |
905 | 0 | uri_object->uri = uri_object->parser->parse(Z_STRVAL_P(uri_zv), Z_STRLEN_P(uri_zv), NULL, NULL, true); |
906 | 0 | if (uri_object->uri == NULL) { |
907 | 0 | if (ZEND_HAS_OOM()) { |
908 | 0 | RETURN_THROWS(); |
909 | 0 | } |
910 | 0 | zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %pS object", uri_object->std.ce->name); |
911 | 0 | RETURN_THROWS(); |
912 | 0 | } |
913 | | |
914 | | /* Unserialize regular properties: second array */ |
915 | 0 | arr = zend_hash_index_find(data, 1); |
916 | 0 | if (arr == NULL || Z_TYPE_P(arr) != IS_ARRAY) { |
917 | 0 | zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %pS object", uri_object->std.ce->name); |
918 | 0 | RETURN_THROWS(); |
919 | 0 | } |
920 | | |
921 | | /* Verify that there is no regular property in the second array, because the URI classes have no properties and they are final. */ |
922 | 0 | if (zend_hash_num_elements(Z_ARRVAL_P(arr)) > 0) { |
923 | 0 | zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %pS object", uri_object->std.ce->name); |
924 | 0 | RETURN_THROWS(); |
925 | 0 | } |
926 | 0 | } |
927 | | |
928 | | PHP_METHOD(Uri_Rfc3986_Uri, __unserialize) |
929 | 4 | { |
930 | 4 | uri_unserialize(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
931 | 4 | } |
932 | | |
933 | | PHP_METHOD(Uri_Rfc3986_Uri, __debugInfo) |
934 | 0 | { |
935 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
936 | | |
937 | 0 | php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); |
938 | |
|
939 | 0 | RETURN_ARR(uri_get_debug_properties(uri_object)); |
940 | 0 | } |
941 | | |
942 | | PHP_METHOD(Uri_WhatWg_Url, getScheme) |
943 | 0 | { |
944 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); |
945 | 0 | } |
946 | | |
947 | | PHP_METHOD(Uri_WhatWg_Url, withScheme) |
948 | 0 | { |
949 | 0 | php_uri_property_write_str_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME); |
950 | 0 | } |
951 | | |
952 | | PHP_METHOD(Uri_WhatWg_Url, isSpecialScheme) |
953 | 0 | { |
954 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
955 | | |
956 | 0 | php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); |
957 | 0 | ZEND_ASSERT(uri_object->uri != NULL); |
958 | |
|
959 | 0 | RETVAL_BOOL(php_uri_parser_whatwg_is_special(uri_object->uri)); |
960 | 0 | } |
961 | | |
962 | | PHP_METHOD(Uri_WhatWg_Url, withUsername) |
963 | 0 | { |
964 | 0 | php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_USERNAME); |
965 | 0 | } |
966 | | |
967 | | PHP_METHOD(Uri_WhatWg_Url, withPassword) |
968 | 0 | { |
969 | 0 | php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_PASSWORD); |
970 | 0 | } |
971 | | |
972 | | PHP_METHOD(Uri_WhatWg_Url, getAsciiHost) |
973 | 0 | { |
974 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII); |
975 | 0 | } |
976 | | |
977 | | PHP_METHOD(Uri_WhatWg_Url, getUnicodeHost) |
978 | 0 | { |
979 | 0 | php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_HOST, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_UNICODE); |
980 | 0 | } |
981 | | |
982 | | PHP_METHOD(Uri_WhatWg_Url, getHostType) |
983 | 0 | { |
984 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
985 | | |
986 | 0 | php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); |
987 | 0 | ZEND_ASSERT(uri_object->uri != NULL); |
988 | |
|
989 | 0 | php_uri_parser_whatwg_host_type_read(uri_object->uri, return_value); |
990 | 0 | } |
991 | | |
992 | | PHP_METHOD(Uri_WhatWg_Url, equals) |
993 | 0 | { |
994 | 0 | zend_object *that_object; |
995 | 0 | zend_enum_Uri_UriComparisonMode comparison_mode = ZEND_ENUM_Uri_UriComparisonMode_ExcludeFragment; |
996 | |
|
997 | 0 | ZEND_PARSE_PARAMETERS_START(1, 2) |
998 | 0 | Z_PARAM_OBJ_OF_CLASS(that_object, php_uri_ce_whatwg_url) |
999 | 0 | Z_PARAM_OPTIONAL |
1000 | 0 | Z_PARAM_ENUM(comparison_mode, php_uri_ce_comparison_mode) |
1001 | 0 | ZEND_PARSE_PARAMETERS_END(); |
1002 | | |
1003 | 0 | uri_equals(INTERNAL_FUNCTION_PARAM_PASSTHRU, php_uri_object_from_obj(that_object), comparison_mode); |
1004 | 0 | } |
1005 | | |
1006 | | PHP_METHOD(Uri_WhatWg_Url, toUnicodeString) |
1007 | 0 | { |
1008 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
1009 | | |
1010 | 0 | zend_object *this_object = Z_OBJ_P(ZEND_THIS); |
1011 | 0 | php_uri_object *uri_object = php_uri_object_from_obj(this_object); |
1012 | 0 | ZEND_ASSERT(uri_object->uri != NULL); |
1013 | |
|
1014 | 0 | zend_string *uri_str = uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_UNICODE, false); |
1015 | 0 | if (uri_str == NULL) { |
1016 | 0 | throw_cannot_recompose_uri_to_string(uri_object); |
1017 | 0 | RETURN_THROWS(); |
1018 | 0 | } |
1019 | | |
1020 | 0 | RETURN_STR(uri_str); |
1021 | 0 | } |
1022 | | |
1023 | | PHP_METHOD(Uri_WhatWg_Url, toAsciiString) |
1024 | 0 | { |
1025 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
1026 | | |
1027 | 0 | zend_object *this_object = Z_OBJ_P(ZEND_THIS); |
1028 | 0 | php_uri_object *uri_object = php_uri_object_from_obj(this_object); |
1029 | 0 | ZEND_ASSERT(uri_object->uri != NULL); |
1030 | |
|
1031 | 0 | zend_string *uri_str = uri_object->parser->to_string(uri_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); |
1032 | 0 | if (uri_str == NULL) { |
1033 | 0 | throw_cannot_recompose_uri_to_string(uri_object); |
1034 | 0 | RETURN_THROWS(); |
1035 | 0 | } |
1036 | | |
1037 | 0 | RETURN_STR(uri_str); |
1038 | 0 | } |
1039 | | |
1040 | | PHP_METHOD(Uri_WhatWg_Url, resolve) |
1041 | 0 | { |
1042 | 0 | zend_string *uri_str; |
1043 | 0 | zval *errors = NULL; |
1044 | |
|
1045 | 0 | ZEND_PARSE_PARAMETERS_START(1, 2) |
1046 | 0 | Z_PARAM_STR(uri_str) |
1047 | 0 | Z_PARAM_OPTIONAL |
1048 | 0 | Z_PARAM_ZVAL(errors) |
1049 | 0 | ZEND_PARSE_PARAMETERS_END(); |
1050 | | |
1051 | 0 | php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1052 | 0 | uri_str, Z_URI_OBJECT_P(ZEND_THIS), true, false, errors); |
1053 | 0 | } |
1054 | | |
1055 | | PHP_METHOD(Uri_WhatWg_Url, __serialize) |
1056 | 0 | { |
1057 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
1058 | | |
1059 | 0 | php_uri_object *this_object = Z_URI_OBJECT_P(ZEND_THIS); |
1060 | 0 | ZEND_ASSERT(this_object->uri != NULL); |
1061 | | |
1062 | | /* Serialize state: "uri" key in the first array */ |
1063 | 0 | zend_string *uri_str = this_object->parser->to_string(this_object->uri, PHP_URI_RECOMPOSITION_MODE_RAW_ASCII, false); |
1064 | 0 | if (uri_str == NULL) { |
1065 | 0 | throw_cannot_recompose_uri_to_string(this_object); |
1066 | 0 | RETURN_THROWS(); |
1067 | 0 | } |
1068 | 0 | zval tmp; |
1069 | 0 | ZVAL_STR(&tmp, uri_str); |
1070 | |
|
1071 | 0 | array_init(return_value); |
1072 | |
|
1073 | 0 | zval arr; |
1074 | 0 | array_init(&arr); |
1075 | 0 | zend_hash_str_add_new(Z_ARRVAL(arr), ZEND_STRL(PHP_URI_SERIALIZE_URI_FIELD_NAME), &tmp); |
1076 | 0 | zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr); |
1077 | | |
1078 | | /* Serialize regular properties: second array */ |
1079 | 0 | ZVAL_EMPTY_ARRAY(&arr); |
1080 | 0 | zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr); |
1081 | 0 | } |
1082 | | |
1083 | | PHP_METHOD(Uri_WhatWg_Url, __unserialize) |
1084 | 7 | { |
1085 | 7 | uri_unserialize(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
1086 | 7 | } |
1087 | | |
1088 | | PHP_METHOD(Uri_WhatWg_Url, __debugInfo) |
1089 | 0 | { |
1090 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
1091 | | |
1092 | 0 | php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS); |
1093 | |
|
1094 | 0 | RETURN_ARR(uri_get_debug_properties(uri_object)); |
1095 | 0 | } |
1096 | | |
1097 | | PHP_FUNCTION(Uri_WhatWg_url_percent_encode) |
1098 | 0 | { |
1099 | 0 | zend_string *input; |
1100 | 0 | zend_enum_Uri_WhatWg_UrlPercentEncodingMode mode; |
1101 | |
|
1102 | 0 | ZEND_PARSE_PARAMETERS_START(2, 2) |
1103 | 0 | Z_PARAM_STR(input) |
1104 | 0 | Z_PARAM_ENUM(mode, php_uri_ce_whatwg_url_percent_encoding_mode) |
1105 | 0 | ZEND_PARSE_PARAMETERS_END(); |
1106 | | |
1107 | 0 | zend_string *str; |
1108 | |
|
1109 | 0 | switch (mode) { |
1110 | 0 | case ZEND_ENUM_Uri_WhatWg_UrlPercentEncodingMode_Username: |
1111 | 0 | ZEND_FALLTHROUGH; |
1112 | 0 | case ZEND_ENUM_Uri_WhatWg_UrlPercentEncodingMode_Password: |
1113 | 0 | str = php_uri_parser_whatwg_userinfo_percent_encode(ZSTR_VAL(input), ZSTR_LEN(input)); |
1114 | 0 | break; |
1115 | 0 | case ZEND_ENUM_Uri_WhatWg_UrlPercentEncodingMode_OpaqueHost: |
1116 | 0 | str = php_uri_parser_whatwg_opaque_host_percent_encode(ZSTR_VAL(input), ZSTR_LEN(input)); |
1117 | 0 | break; |
1118 | 0 | case ZEND_ENUM_Uri_WhatWg_UrlPercentEncodingMode_Path: |
1119 | 0 | str = php_uri_parser_whatwg_path_percent_encode(ZSTR_VAL(input), ZSTR_LEN(input)); |
1120 | 0 | break; |
1121 | 0 | case ZEND_ENUM_Uri_WhatWg_UrlPercentEncodingMode_OpaquePath: |
1122 | 0 | str = php_uri_parser_whatwg_opaque_path_percent_encode(ZSTR_VAL(input), ZSTR_LEN(input)); |
1123 | 0 | break; |
1124 | 0 | case ZEND_ENUM_Uri_WhatWg_UrlPercentEncodingMode_PathSegment: |
1125 | 0 | str = php_uri_parser_whatwg_path_segment_percent_encode(ZSTR_VAL(input), ZSTR_LEN(input)); |
1126 | 0 | break; |
1127 | 0 | case ZEND_ENUM_Uri_WhatWg_UrlPercentEncodingMode_Query: |
1128 | 0 | str = php_uri_parser_whatwg_query_percent_encode(ZSTR_VAL(input), ZSTR_LEN(input)); |
1129 | 0 | break; |
1130 | 0 | case ZEND_ENUM_Uri_WhatWg_UrlPercentEncodingMode_SpecialQuery: |
1131 | 0 | str = php_uri_parser_whatwg_special_query_percent_encode(ZSTR_VAL(input), ZSTR_LEN(input)); |
1132 | 0 | break; |
1133 | 0 | case ZEND_ENUM_Uri_WhatWg_UrlPercentEncodingMode_FormQuery: |
1134 | 0 | str = php_uri_parser_whatwg_form_query_percent_encode(ZSTR_VAL(input), ZSTR_LEN(input)); |
1135 | 0 | break; |
1136 | 0 | case ZEND_ENUM_Uri_WhatWg_UrlPercentEncodingMode_Fragment: |
1137 | 0 | str = php_uri_parser_whatwg_fragment_percent_encode(ZSTR_VAL(input), ZSTR_LEN(input)); |
1138 | 0 | break; |
1139 | 0 | default: ZEND_UNREACHABLE(); |
1140 | 0 | } |
1141 | | |
1142 | | /* This should be unreachable in practice, as str is null only due to memory errors. */ |
1143 | 0 | if (str == NULL) { |
1144 | 0 | zend_throw_exception(php_uri_ce_error, "Cannot percent-encode input", 0); |
1145 | 0 | RETURN_THROWS(); |
1146 | 0 | } |
1147 | | |
1148 | 0 | RETURN_NEW_STR(str); |
1149 | 0 | } |
1150 | | |
1151 | | PHP_METHOD(Uri_Rfc3986_UriBuilder, reset) |
1152 | 0 | { |
1153 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
1154 | | |
1155 | 0 | zend_object *object = Z_OBJ_P(ZEND_THIS); |
1156 | 0 | zval *property = object->properties_table; |
1157 | 0 | const zval *end = property + object->ce->default_properties_count; |
1158 | |
|
1159 | 0 | while (property != end) { |
1160 | 0 | zend_object_dtor_property(object, property); |
1161 | 0 | ZVAL_NULL(property); |
1162 | 0 | property++; |
1163 | 0 | } |
1164 | |
|
1165 | 0 | ZVAL_EMPTY_STRING(Z_RFC3986_URI_PROP_PATH_P(ZEND_THIS)); |
1166 | |
|
1167 | 0 | RETVAL_COPY(ZEND_THIS); |
1168 | 0 | } |
1169 | | |
1170 | | ZEND_ATTRIBUTE_NONNULL static void php_uri_builder_set_component_string( |
1171 | | INTERNAL_FUNCTION_PARAMETERS, const char *name, const size_t name_length, |
1172 | | const php_uri_component_validator_string validator |
1173 | 0 | ) { |
1174 | 0 | zend_string *component; |
1175 | |
|
1176 | 0 | ZEND_PARSE_PARAMETERS_START(1, 1) |
1177 | 0 | Z_PARAM_STR(component) |
1178 | 0 | ZEND_PARSE_PARAMETERS_END(); |
1179 | | |
1180 | 0 | if (validator(component) == FAILURE) { |
1181 | 0 | RETURN_THROWS(); |
1182 | 0 | } |
1183 | | |
1184 | 0 | zend_update_property_str(Z_OBJCE_P(ZEND_THIS), Z_OBJ_P(ZEND_THIS), name, name_length, component); |
1185 | |
|
1186 | 0 | RETVAL_COPY(ZEND_THIS); |
1187 | 0 | } |
1188 | | |
1189 | | ZEND_ATTRIBUTE_NONNULL static void php_uri_builder_set_component_string_or_null( |
1190 | | INTERNAL_FUNCTION_PARAMETERS, const char *name, const size_t name_length, |
1191 | | const php_uri_component_validator_string validator |
1192 | 0 | ) { |
1193 | 0 | zend_string *component; |
1194 | |
|
1195 | 0 | ZEND_PARSE_PARAMETERS_START(1, 1) |
1196 | 0 | Z_PARAM_STR_OR_NULL(component) |
1197 | 0 | ZEND_PARSE_PARAMETERS_END(); |
1198 | | |
1199 | 0 | if (component == NULL) { |
1200 | 0 | zend_update_property_null(Z_OBJCE_P(ZEND_THIS), Z_OBJ_P(ZEND_THIS), name, name_length); |
1201 | 0 | } else { |
1202 | 0 | if (validator(component) == FAILURE) { |
1203 | 0 | RETURN_THROWS(); |
1204 | 0 | } |
1205 | | |
1206 | 0 | zend_update_property_str(Z_OBJCE_P(ZEND_THIS), Z_OBJ_P(ZEND_THIS), name, name_length, component); |
1207 | 0 | } |
1208 | | |
1209 | 0 | RETVAL_COPY(ZEND_THIS); |
1210 | 0 | } |
1211 | | |
1212 | | ZEND_ATTRIBUTE_NONNULL_ARGS(1) static void php_uri_builder_set_component_long_or_null( |
1213 | | INTERNAL_FUNCTION_PARAMETERS, const char *name, const size_t name_length, |
1214 | | const php_uri_component_validator_long validator |
1215 | 0 | ) { |
1216 | 0 | zend_long component; |
1217 | 0 | bool component_is_null; |
1218 | |
|
1219 | 0 | ZEND_PARSE_PARAMETERS_START(1, 1) |
1220 | 0 | Z_PARAM_LONG_OR_NULL(component, component_is_null) |
1221 | 0 | ZEND_PARSE_PARAMETERS_END(); |
1222 | | |
1223 | 0 | if (component_is_null) { |
1224 | 0 | zend_update_property_null(Z_OBJCE_P(ZEND_THIS), Z_OBJ_P(ZEND_THIS), name, name_length); |
1225 | 0 | } else { |
1226 | 0 | if (validator(component) == FAILURE) { |
1227 | 0 | RETURN_THROWS(); |
1228 | 0 | } |
1229 | | |
1230 | 0 | zend_update_property_long(Z_OBJCE_P(ZEND_THIS), Z_OBJ_P(ZEND_THIS), name, name_length, component); |
1231 | 0 | } |
1232 | | |
1233 | 0 | RETVAL_COPY(ZEND_THIS); |
1234 | 0 | } |
1235 | | |
1236 | | PHP_METHOD(Uri_Rfc3986_UriBuilder, setScheme) |
1237 | 0 | { |
1238 | 0 | php_uri_builder_set_component_string_or_null( |
1239 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1240 | 0 | ZEND_STRL("scheme"), |
1241 | 0 | php_uri_parser_rfc3986_scheme_validate |
1242 | 0 | ); |
1243 | 0 | } |
1244 | | |
1245 | | PHP_METHOD(Uri_Rfc3986_UriBuilder, setUserInfo) |
1246 | 0 | { |
1247 | 0 | php_uri_builder_set_component_string_or_null( |
1248 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1249 | 0 | ZEND_STRL("userinfo"), |
1250 | 0 | php_uri_parser_rfc3986_userinfo_validate |
1251 | 0 | ); |
1252 | 0 | } |
1253 | | |
1254 | | PHP_METHOD(Uri_Rfc3986_UriBuilder, setHost) |
1255 | 0 | { |
1256 | 0 | php_uri_builder_set_component_string_or_null( |
1257 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1258 | 0 | ZEND_STRL("host"), |
1259 | 0 | php_uri_parser_rfc3986_host_validate |
1260 | 0 | ); |
1261 | 0 | } |
1262 | | |
1263 | | PHP_METHOD(Uri_Rfc3986_UriBuilder, setPort) |
1264 | 0 | { |
1265 | 0 | php_uri_builder_set_component_long_or_null( |
1266 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1267 | 0 | ZEND_STRL("port"), |
1268 | 0 | php_uri_parser_rfc3986_port_validate |
1269 | 0 | ); |
1270 | 0 | } |
1271 | | |
1272 | | PHP_METHOD(Uri_Rfc3986_UriBuilder, setPath) |
1273 | 0 | { |
1274 | 0 | php_uri_builder_set_component_string( |
1275 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1276 | 0 | ZEND_STRL("path"), |
1277 | 0 | php_uri_parser_rfc3986_path_validate |
1278 | 0 | ); |
1279 | 0 | } |
1280 | | |
1281 | | PHP_METHOD(Uri_Rfc3986_UriBuilder, setQuery) |
1282 | 0 | { |
1283 | 0 | php_uri_builder_set_component_string_or_null( |
1284 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1285 | 0 | ZEND_STRL("query"), |
1286 | 0 | php_uri_parser_rfc3986_query_validate |
1287 | 0 | ); |
1288 | 0 | } |
1289 | | |
1290 | | PHP_METHOD(Uri_Rfc3986_UriBuilder, setFragment) |
1291 | 0 | { |
1292 | 0 | php_uri_builder_set_component_string_or_null( |
1293 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1294 | 0 | ZEND_STRL("fragment"), |
1295 | 0 | php_uri_parser_rfc3986_fragment_validate |
1296 | 0 | ); |
1297 | 0 | } |
1298 | | |
1299 | | PHP_METHOD(Uri_Rfc3986_UriBuilder, build) |
1300 | 0 | { |
1301 | 0 | zval *base_url = NULL; |
1302 | |
|
1303 | 0 | ZEND_PARSE_PARAMETERS_START(0, 1) |
1304 | 0 | Z_PARAM_OPTIONAL |
1305 | 0 | Z_PARAM_OBJECT_OF_CLASS_OR_NULL(base_url, php_uri_ce_rfc3986_uri) |
1306 | 0 | ZEND_PARSE_PARAMETERS_END(); |
1307 | | |
1308 | 0 | const zval *scheme = Z_RFC3986_URI_PROP_SCHEME_DEREF_P(ZEND_THIS); |
1309 | 0 | const zval *userinfo = Z_RFC3986_URI_PROP_USERINFO_DEREF_P(ZEND_THIS); |
1310 | 0 | const zval *host = Z_RFC3986_URI_PROP_HOST_DEREF_P(ZEND_THIS); |
1311 | 0 | const zval *port = Z_RFC3986_URI_PROP_PORT_DEREF_P(ZEND_THIS); |
1312 | 0 | const zval *path = Z_RFC3986_URI_PROP_PATH_DEREF_P(ZEND_THIS); |
1313 | 0 | const zval *query = Z_RFC3986_URI_PROP_QUERY_DEREF_P(ZEND_THIS); |
1314 | 0 | const zval *fragment = Z_RFC3986_URI_PROP_FRAGMENT_DEREF_P(ZEND_THIS); |
1315 | |
|
1316 | 0 | php_uri_parser_rfc3986_uris *base_uris = NULL; |
1317 | 0 | if (base_url != NULL) { |
1318 | 0 | base_uris = Z_URI_OBJECT_P(base_url)->uri; |
1319 | 0 | } |
1320 | |
|
1321 | 0 | php_uri_parser_rfc3986_uris *uriparser_uris = php_uri_parser_rfc3986_build_from_zval( |
1322 | 0 | base_uris, scheme, userinfo, host, port, path, query, fragment |
1323 | 0 | ); |
1324 | 0 | if (uriparser_uris == NULL) { |
1325 | 0 | RETURN_THROWS(); |
1326 | 0 | } |
1327 | | |
1328 | 0 | object_init_ex(return_value, php_uri_ce_rfc3986_uri); |
1329 | 0 | php_uri_object *uri_object = Z_URI_OBJECT_P(return_value); |
1330 | 0 | uri_object->parser = &php_uri_parser_rfc3986; |
1331 | 0 | uri_object->uri = uriparser_uris; |
1332 | 0 | } |
1333 | | |
1334 | | PHP_METHOD(Uri_WhatWg_UrlBuilder, reset) |
1335 | 0 | { |
1336 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
1337 | | |
1338 | 0 | zend_object *object = Z_OBJ_P(ZEND_THIS); |
1339 | 0 | zval *property = object->properties_table; |
1340 | 0 | const zval *end = property + object->ce->default_properties_count; |
1341 | |
|
1342 | 0 | while (property != end) { |
1343 | 0 | zend_object_dtor_property(object, property); |
1344 | 0 | ZVAL_NULL(property); |
1345 | 0 | property++; |
1346 | 0 | } |
1347 | |
|
1348 | 0 | ZVAL_EMPTY_STRING(Z_WHATWG_URL_PROP_SCHEME_P(ZEND_THIS)); |
1349 | 0 | ZVAL_EMPTY_STRING(Z_WHATWG_URL_PROP_PATH_P(ZEND_THIS)); |
1350 | |
|
1351 | 0 | RETVAL_COPY(ZEND_THIS); |
1352 | 0 | } |
1353 | | |
1354 | | PHP_METHOD(Uri_WhatWg_UrlBuilder, setScheme) |
1355 | 0 | { |
1356 | 0 | php_uri_builder_set_component_string( |
1357 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1358 | 0 | ZEND_STRL("scheme"), |
1359 | 0 | php_uri_parser_whatwg_scheme_validate |
1360 | 0 | ); |
1361 | 0 | } |
1362 | | |
1363 | | PHP_METHOD(Uri_WhatWg_UrlBuilder, setUsername) |
1364 | 0 | { |
1365 | 0 | php_uri_builder_set_component_string_or_null( |
1366 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1367 | 0 | ZEND_STRL("username"), |
1368 | 0 | php_uri_parser_whatwg_none_validate |
1369 | 0 | ); |
1370 | 0 | } |
1371 | | |
1372 | | PHP_METHOD(Uri_WhatWg_UrlBuilder, setPassword) |
1373 | 0 | { |
1374 | 0 | php_uri_builder_set_component_string_or_null( |
1375 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1376 | 0 | ZEND_STRL("password"), |
1377 | 0 | php_uri_parser_whatwg_none_validate |
1378 | 0 | ); |
1379 | 0 | } |
1380 | | |
1381 | | PHP_METHOD(Uri_WhatWg_UrlBuilder, setHost) |
1382 | 0 | { |
1383 | 0 | php_uri_builder_set_component_string_or_null( |
1384 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1385 | 0 | ZEND_STRL("host"), |
1386 | 0 | php_uri_parser_whatwg_host_validate |
1387 | 0 | ); |
1388 | 0 | } |
1389 | | |
1390 | | PHP_METHOD(Uri_WhatWg_UrlBuilder, setPort) |
1391 | 0 | { |
1392 | 0 | php_uri_builder_set_component_long_or_null( |
1393 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1394 | 0 | ZEND_STRL("port"), |
1395 | 0 | php_uri_parser_whatwg_port_validate |
1396 | 0 | ); |
1397 | 0 | } |
1398 | | |
1399 | | PHP_METHOD(Uri_WhatWg_UrlBuilder, setPath) |
1400 | 0 | { |
1401 | 0 | php_uri_builder_set_component_string( |
1402 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1403 | 0 | ZEND_STRL("path"), |
1404 | 0 | php_uri_parser_whatwg_none_validate |
1405 | 0 | ); |
1406 | 0 | } |
1407 | | |
1408 | | PHP_METHOD(Uri_WhatWg_UrlBuilder, setQuery) |
1409 | 0 | { |
1410 | 0 | php_uri_builder_set_component_string_or_null( |
1411 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1412 | 0 | ZEND_STRL("query"), |
1413 | 0 | php_uri_parser_whatwg_none_validate |
1414 | 0 | ); |
1415 | 0 | } |
1416 | | |
1417 | | PHP_METHOD(Uri_WhatWg_UrlBuilder, setFragment) |
1418 | 0 | { |
1419 | 0 | php_uri_builder_set_component_string_or_null( |
1420 | 0 | INTERNAL_FUNCTION_PARAM_PASSTHRU, |
1421 | 0 | ZEND_STRL("fragment"), |
1422 | 0 | php_uri_parser_whatwg_none_validate |
1423 | 0 | ); |
1424 | 0 | } |
1425 | | |
1426 | | PHP_METHOD(Uri_WhatWg_UrlBuilder, build) |
1427 | 0 | { |
1428 | 0 | zval *base_url_zv = NULL; |
1429 | 0 | zval *soft_errors = NULL; |
1430 | |
|
1431 | 0 | ZEND_PARSE_PARAMETERS_START(0, 2) |
1432 | 0 | Z_PARAM_OPTIONAL |
1433 | 0 | Z_PARAM_OBJECT_OF_CLASS_OR_NULL(base_url_zv, php_uri_ce_whatwg_url) |
1434 | 0 | Z_PARAM_ZVAL(soft_errors) |
1435 | 0 | ZEND_PARSE_PARAMETERS_END(); |
1436 | | |
1437 | 0 | const zval *scheme = Z_WHATWG_URL_PROP_SCHEME_DEREF_P(ZEND_THIS); |
1438 | 0 | const zval *username = Z_WHATWG_URL_PROP_USERNAME_DEREF_P(ZEND_THIS); |
1439 | 0 | const zval *password = Z_WHATWG_URL_PROP_PASSWORD_DEREF_P(ZEND_THIS); |
1440 | 0 | const zval *host = Z_WHATWG_URL_PROP_HOST_DEREF_P(ZEND_THIS); |
1441 | 0 | const zval *port = Z_WHATWG_URL_PROP_PORT_DEREF_P(ZEND_THIS); |
1442 | 0 | const zval *path = Z_WHATWG_URL_PROP_PATH_DEREF_P(ZEND_THIS); |
1443 | 0 | const zval *query = Z_WHATWG_URL_PROP_QUERY_DEREF_P(ZEND_THIS); |
1444 | 0 | const zval *fragment = Z_WHATWG_URL_PROP_FRAGMENT_DEREF_P(ZEND_THIS); |
1445 | |
|
1446 | 0 | lxb_url_t *base_url = NULL; |
1447 | 0 | if (base_url_zv != NULL) { |
1448 | 0 | base_url = Z_URI_OBJECT_P(base_url_zv)->uri; |
1449 | 0 | } |
1450 | |
|
1451 | 0 | lxb_url_t *lexbor_url = php_uri_parser_whatwg_build_from_zval( |
1452 | 0 | base_url, scheme, username, password, host, port, path, query, fragment, |
1453 | 0 | soft_errors |
1454 | 0 | ); |
1455 | 0 | if (lexbor_url == NULL) { |
1456 | 0 | zval errors; |
1457 | 0 | ZVAL_EMPTY_ARRAY(&errors); |
1458 | 0 | pass_errors_by_ref_and_free(soft_errors, &errors); |
1459 | 0 | RETURN_THROWS(); |
1460 | 0 | } |
1461 | | |
1462 | 0 | object_init_ex(return_value, php_uri_ce_whatwg_url); |
1463 | 0 | php_uri_object *uri_object = Z_URI_OBJECT_P(return_value); |
1464 | 0 | uri_object->parser = &php_uri_parser_whatwg; |
1465 | 0 | uri_object->uri = lexbor_url; |
1466 | 0 | } |
1467 | | |
1468 | | PHPAPI php_uri_object *php_uri_object_create(zend_class_entry *class_type, const php_uri_parser *parser) |
1469 | 212 | { |
1470 | 212 | php_uri_object *uri_object = zend_object_alloc(sizeof(*uri_object), class_type); |
1471 | | |
1472 | 212 | zend_object_std_init(&uri_object->std, class_type); |
1473 | 212 | object_properties_init(&uri_object->std, class_type); |
1474 | | |
1475 | 212 | uri_object->parser = parser; |
1476 | 212 | uri_object->uri = NULL; |
1477 | | |
1478 | 212 | return uri_object; |
1479 | 212 | } |
1480 | | |
1481 | | static zend_object *php_uri_object_create_rfc3986(zend_class_entry *ce) |
1482 | 11 | { |
1483 | 11 | return &php_uri_object_create(ce, &php_uri_parser_rfc3986)->std; |
1484 | 11 | } |
1485 | | |
1486 | | static zend_object *php_uri_object_create_whatwg(zend_class_entry *ce) |
1487 | 201 | { |
1488 | 201 | return &php_uri_object_create(ce, &php_uri_parser_whatwg)->std; |
1489 | 201 | } |
1490 | | |
1491 | | PHPAPI void php_uri_object_handler_free(zend_object *object) |
1492 | 212 | { |
1493 | 212 | php_uri_object *uri_object = php_uri_object_from_obj(object); |
1494 | | |
1495 | 212 | uri_object->parser->destroy(uri_object->uri); |
1496 | 212 | zend_object_std_dtor(&uri_object->std); |
1497 | 212 | } |
1498 | | |
1499 | | PHPAPI zend_object *php_uri_object_handler_clone(zend_object *object) |
1500 | 0 | { |
1501 | 0 | const php_uri_object *uri_object = php_uri_object_from_obj(object); |
1502 | |
|
1503 | 0 | ZEND_ASSERT(uri_object->uri != NULL); |
1504 | |
|
1505 | 0 | php_uri_object *new_uri_object = php_uri_object_from_obj(object->ce->create_object(object->ce)); |
1506 | 0 | ZEND_ASSERT(new_uri_object->parser == uri_object->parser); |
1507 | |
|
1508 | 0 | void *uri = uri_object->parser->clone(uri_object->uri); |
1509 | 0 | if (UNEXPECTED(uri == NULL)) { |
1510 | 0 | ZEND_ASSERT(ZEND_HAS_OOM()); |
1511 | 0 | zend_object_release(&new_uri_object->std); |
1512 | 0 | zend_handle_delayed_oom(); |
1513 | 0 | return NULL; |
1514 | 0 | } |
1515 | | |
1516 | 0 | new_uri_object->uri = uri; |
1517 | |
|
1518 | 0 | zend_objects_clone_members(&new_uri_object->std, &uri_object->std); |
1519 | |
|
1520 | 0 | return &new_uri_object->std; |
1521 | 0 | } |
1522 | | |
1523 | | PHPAPI zend_result php_uri_parser_register(const php_uri_parser *uri_parser) |
1524 | 48 | { |
1525 | 48 | zend_string *key = zend_string_init_interned(uri_parser->name, strlen(uri_parser->name), true); |
1526 | | |
1527 | 48 | ZEND_ASSERT(uri_parser->name != NULL); |
1528 | 48 | ZEND_ASSERT(uri_parser->parse != NULL); |
1529 | 48 | ZEND_ASSERT(uri_parser->clone != NULL || strcmp(uri_parser->name, PHP_URI_PARSER_PHP_PARSE_URL) == 0); |
1530 | 48 | ZEND_ASSERT(uri_parser->to_string != NULL || strcmp(uri_parser->name, PHP_URI_PARSER_PHP_PARSE_URL) == 0); |
1531 | 48 | ZEND_ASSERT(uri_parser->destroy != NULL); |
1532 | | |
1533 | 48 | zend_result result = zend_hash_add_ptr(&uri_parsers, key, (void *) uri_parser) != NULL ? SUCCESS : FAILURE; |
1534 | | |
1535 | 48 | zend_string_release_ex(key, true); |
1536 | | |
1537 | 48 | return result; |
1538 | 48 | } |
1539 | | |
1540 | | static PHP_MINIT_FUNCTION(uri) |
1541 | 16 | { |
1542 | 16 | php_uri_ce_rfc3986_uri_builder = register_class_Uri_Rfc3986_UriBuilder(); |
1543 | | |
1544 | 16 | php_uri_ce_rfc3986_uri = register_class_Uri_Rfc3986_Uri(); |
1545 | 16 | php_uri_ce_rfc3986_uri->create_object = php_uri_object_create_rfc3986; |
1546 | 16 | php_uri_ce_rfc3986_uri->default_object_handlers = &object_handlers_rfc3986_uri; |
1547 | 16 | memcpy(&object_handlers_rfc3986_uri, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); |
1548 | 16 | object_handlers_rfc3986_uri.offset = offsetof(php_uri_object, std); |
1549 | 16 | object_handlers_rfc3986_uri.free_obj = php_uri_object_handler_free; |
1550 | 16 | object_handlers_rfc3986_uri.clone_obj = php_uri_object_handler_clone; |
1551 | | |
1552 | 16 | php_uri_ce_rfc3986_uri_type = register_class_Uri_Rfc3986_UriType(); |
1553 | 16 | php_uri_ce_rfc3986_uri_host_type = register_class_Uri_Rfc3986_UriHostType(); |
1554 | | |
1555 | 16 | php_uri_ce_whatwg_url_builder = register_class_Uri_WhatWg_UrlBuilder(); |
1556 | | |
1557 | 16 | php_uri_ce_whatwg_url = register_class_Uri_WhatWg_Url(); |
1558 | 16 | php_uri_ce_whatwg_url->create_object = php_uri_object_create_whatwg; |
1559 | 16 | php_uri_ce_whatwg_url->default_object_handlers = &object_handlers_whatwg_uri; |
1560 | 16 | memcpy(&object_handlers_whatwg_uri, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); |
1561 | 16 | object_handlers_whatwg_uri.offset = offsetof(php_uri_object, std); |
1562 | 16 | object_handlers_whatwg_uri.free_obj = php_uri_object_handler_free; |
1563 | 16 | object_handlers_whatwg_uri.clone_obj = php_uri_object_handler_clone; |
1564 | | |
1565 | 16 | php_uri_ce_whatwg_url_percent_encoding_mode = register_class_Uri_WhatWg_UrlPercentEncodingMode(); |
1566 | | |
1567 | 16 | php_uri_ce_comparison_mode = register_class_Uri_UriComparisonMode(); |
1568 | 16 | php_uri_ce_exception = register_class_Uri_UriException(zend_ce_exception); |
1569 | 16 | php_uri_ce_error = register_class_Uri_UriError(zend_ce_error); |
1570 | 16 | php_uri_ce_invalid_uri_exception = register_class_Uri_InvalidUriException(php_uri_ce_exception); |
1571 | 16 | php_uri_ce_whatwg_invalid_url_exception = register_class_Uri_WhatWg_InvalidUrlException(php_uri_ce_invalid_uri_exception); |
1572 | 16 | php_uri_ce_whatwg_url_host_type = register_class_Uri_WhatWg_UrlHostType(); |
1573 | 16 | php_uri_ce_whatwg_url_validation_error = register_class_Uri_WhatWg_UrlValidationError(); |
1574 | 16 | php_uri_ce_whatwg_url_validation_error_type = register_class_Uri_WhatWg_UrlValidationErrorType(); |
1575 | | |
1576 | 16 | zend_hash_init(&uri_parsers, 4, NULL, NULL, true); |
1577 | | |
1578 | 16 | if (php_uri_parser_register(&php_uri_parser_rfc3986) == FAILURE) { |
1579 | 0 | return FAILURE; |
1580 | 0 | } |
1581 | | |
1582 | 16 | if (php_uri_parser_register(&php_uri_parser_whatwg) == FAILURE) { |
1583 | 0 | return FAILURE; |
1584 | 0 | } |
1585 | | |
1586 | 16 | if (php_uri_parser_register(&php_uri_parser_php_parse_url) == FAILURE) { |
1587 | 0 | return FAILURE; |
1588 | 0 | } |
1589 | | |
1590 | 16 | return SUCCESS; |
1591 | 16 | } |
1592 | | |
1593 | | static PHP_MINFO_FUNCTION(uri) |
1594 | 0 | { |
1595 | 0 | php_info_print_table_start(); |
1596 | 0 | php_info_print_table_row(2, "URI support", "active"); |
1597 | 0 | #ifdef URI_STATIC_BUILD |
1598 | 0 | php_info_print_table_row(2, "uriparser bundled version", URI_VER_ANSI); |
1599 | | #else |
1600 | | php_info_print_table_row(2, "uriparser compiled version", URI_VER_ANSI); |
1601 | | php_info_print_table_row(2, "uriparser loaded version", uriBaseRuntimeVersionA()); |
1602 | | #endif |
1603 | 0 | php_info_print_table_end(); |
1604 | 0 | } |
1605 | | |
1606 | | static PHP_MSHUTDOWN_FUNCTION(uri) |
1607 | 0 | { |
1608 | 0 | zend_hash_destroy(&uri_parsers); |
1609 | |
|
1610 | 0 | return SUCCESS; |
1611 | 0 | } |
1612 | | |
1613 | | PHP_RINIT_FUNCTION(uri) |
1614 | 306k | { |
1615 | 306k | if (PHP_RINIT(uri_parser_whatwg)(INIT_FUNC_ARGS_PASSTHRU) == FAILURE) { |
1616 | 0 | return FAILURE; |
1617 | 0 | } |
1618 | | |
1619 | 306k | return SUCCESS; |
1620 | 306k | } |
1621 | | |
1622 | | ZEND_MODULE_POST_ZEND_DEACTIVATE_D(uri) |
1623 | 306k | { |
1624 | 306k | if (ZEND_MODULE_POST_ZEND_DEACTIVATE_N(uri_parser_whatwg)() == FAILURE) { |
1625 | 0 | return FAILURE; |
1626 | 0 | } |
1627 | | |
1628 | 306k | return SUCCESS; |
1629 | 306k | } |
1630 | | |
1631 | | zend_module_entry uri_module_entry = { |
1632 | | STANDARD_MODULE_HEADER_EX, NULL, |
1633 | | uri_deps, |
1634 | | "uri", /* Extension name */ |
1635 | | ext_functions, /* zend_function_entry */ |
1636 | | PHP_MINIT(uri), /* PHP_MINIT - Module initialization */ |
1637 | | PHP_MSHUTDOWN(uri), /* PHP_MSHUTDOWN - Module shutdown */ |
1638 | | PHP_RINIT(uri), /* PHP_RINIT - Request initialization */ |
1639 | | NULL, /* PHP_RSHUTDOWN - Request shutdown */ |
1640 | | PHP_MINFO(uri), /* PHP_MINFO - Module info */ |
1641 | | PHP_VERSION, /* Version */ |
1642 | | NO_MODULE_GLOBALS, |
1643 | | ZEND_MODULE_POST_ZEND_DEACTIVATE_N(uri), |
1644 | | STANDARD_MODULE_PROPERTIES_EX |
1645 | | }; |