Coverage Report

Created: 2025-06-13 06:43

/src/php-src/ext/uri/php_uri_common.h
Line
Count
Source (jump to first uncovered line)
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
extern zend_class_entry *uri_whatwg_url_ce;
21
extern zend_object_handlers uri_whatwg_uri_object_handlers;
22
extern zend_class_entry *uri_comparison_mode_ce;
23
extern zend_class_entry *uri_exception_ce;
24
extern zend_class_entry *uri_invalid_uri_exception_ce;
25
extern zend_class_entry *uri_whatwg_invalid_url_exception_ce;
26
extern zend_class_entry *uri_whatwg_url_validation_error_type_ce;
27
extern zend_class_entry *uri_whatwg_url_validation_error_ce;
28
extern zend_object *uri_clone_obj_handler(zend_object *object);
29
30
typedef enum {
31
  URI_RECOMPOSITION_RAW_ASCII,
32
  URI_RECOMPOSITION_RAW_UNICODE,
33
  URI_RECOMPOSITION_NORMALIZED_ASCII,
34
  URI_RECOMPOSITION_NORMALIZED_UNICODE,
35
} uri_recomposition_mode_t;
36
37
typedef enum {
38
  URI_COMPONENT_READ_RAW,
39
  URI_COMPONENT_READ_NORMALIZED_ASCII,
40
  URI_COMPONENT_READ_NORMALIZED_UNICODE,
41
} uri_component_read_mode_t;
42
43
struct uri_internal_t;
44
45
typedef zend_result (*uri_read_t)(const struct uri_internal_t *internal_uri, uri_component_read_mode_t read_mode, zval *retval);
46
47
typedef zend_result (*uri_write_t)(struct uri_internal_t *internal_uri, zval *value, zval *errors);
48
49
typedef enum {
50
  URI_PROPERTY_NAME_SCHEME,
51
  URI_PROPERTY_NAME_USERNAME,
52
  URI_PROPERTY_NAME_PASSWORD,
53
  URI_PROPERTY_NAME_HOST,
54
  URI_PROPERTY_NAME_PORT,
55
  URI_PROPERTY_NAME_PATH,
56
  URI_PROPERTY_NAME_QUERY,
57
  URI_PROPERTY_NAME_FRAGMENT,
58
} uri_property_name_t;
59
60
typedef struct uri_property_handler_t {
61
  uri_read_t read_func;
62
  uri_write_t write_func;
63
} uri_property_handler_t;
64
65
typedef struct uri_property_handlers_t {
66
  uri_property_handler_t scheme;
67
  uri_property_handler_t username;
68
  uri_property_handler_t password;
69
  uri_property_handler_t host;
70
  uri_property_handler_t port;
71
  uri_property_handler_t path;
72
  uri_property_handler_t query;
73
  uri_property_handler_t fragment;
74
} uri_property_handlers_t;
75
76
typedef struct uri_handler_t {
77
  const char *name;
78
79
  /**
80
   * Parse a URI string into a URI.
81
   *
82
   * If the URI string is valid, a URI is returned. In case of failure, NULL is
83
   * returned.
84
   *
85
   * The errors by-ref parameter can contain errors that occurred during parsing.
86
   * If the input value is NULL, or there were no errors, the errors parameter should
87
   * not be modified.
88
   *
89
   * If the URI string is valid and the base_url URI is not NULL, the URI object
90
   * is resolved against the base_url.
91
   *
92
   * If the silent parameter is true, a Uri\InvalidUriException instance must be thrown.
93
   * If the parameter is false, the possible errors should be handled by the caller.
94
   */
95
  void *(*parse_uri)(const zend_string *uri_str, const void *base_url, zval *errors, bool silent);
96
  void *(*clone_uri)(void *uri);
97
  zend_string *(*uri_to_string)(void *uri, uri_recomposition_mode_t recomposition_mode, bool exclude_fragment);
98
  void (*free_uri)(void *uri);
99
100
  const uri_property_handlers_t property_handlers;
101
} uri_handler_t;
102
103
typedef struct uri_internal_t {
104
  const uri_handler_t *handler;
105
  void *uri;
106
} uri_internal_t;
107
108
typedef struct uri_object_t {
109
  uri_internal_t internal;
110
  zend_object std;
111
} uri_object_t;
112
113
5
static inline uri_object_t *uri_object_from_obj(const zend_object *object) {
114
5
  return (uri_object_t*)((char*)(object) - XtOffsetOf(uri_object_t, std));
115
5
}
Unexecuted instantiation: php_lexbor.c:uri_object_from_obj
php_uri.c:uri_object_from_obj
Line
Count
Source
113
5
static inline uri_object_t *uri_object_from_obj(const zend_object *object) {
114
5
  return (uri_object_t*)((char*)(object) - XtOffsetOf(uri_object_t, std));
115
5
}
Unexecuted instantiation: php_uri_common.c:uri_object_from_obj
Unexecuted instantiation: internal_functions_cli.c:uri_object_from_obj
116
117
0
static inline uri_internal_t *uri_internal_from_obj(const zend_object *object) {
118
0
  return &(uri_object_from_obj(object)->internal);
119
0
}
Unexecuted instantiation: php_lexbor.c:uri_internal_from_obj
Unexecuted instantiation: php_uri.c:uri_internal_from_obj
Unexecuted instantiation: php_uri_common.c:uri_internal_from_obj
Unexecuted instantiation: internal_functions_cli.c:uri_internal_from_obj
120
121
0
#define Z_URI_OBJECT_P(zv) uri_object_from_obj(Z_OBJ_P((zv)))
122
0
#define Z_URI_INTERNAL_P(zv) uri_internal_from_obj(Z_OBJ_P((zv)))
123
124
0
#define URI_PARSER_WHATWG "Uri\\WhatWg\\Url"
125
#define URI_SERIALIZED_PROPERTY_NAME "uri"
126
127
zend_result uri_handler_register(const uri_handler_t *uri_handler);
128
const uri_property_handler_t *uri_property_handler_from_internal_uri(const uri_internal_t *internal_uri, uri_property_name_t property_name);
129
void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, uri_property_name_t property_name, uri_component_read_mode_t component_read_mode);
130
void uri_write_component_str(INTERNAL_FUNCTION_PARAMETERS, uri_property_name_t property_name);
131
void uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAMETERS, uri_property_name_t property_name);
132
void uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAMETERS, uri_property_name_t property_name);
133
134
0
#define URI_ASSERT_INITIALIZATION(internal_uri) do { \
135
0
  ZEND_ASSERT(internal_uri != NULL && internal_uri->uri != NULL); \
136
0
} while (0)
137
138
#endif