Coverage Report

Created: 2025-07-23 06:33

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