Coverage Report

Created: 2025-09-27 06:26

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