build: fix master
[m6w6/ext-http] / src / php_http.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #include "php_http_api.h"
14
15 #include "php_ini.h"
16 #include "ext/standard/info.h"
17
18 #include <zlib.h>
19
20 #if PHP_HTTP_HAVE_LIBCURL
21 # include <curl/curl.h>
22 # if PHP_HTTP_HAVE_LIBEVENT
23 # if PHP_HTTP_HAVE_LIBEVENT2
24 # include <event2/event.h>
25 # include <event2/event_struct.h>
26 # else
27 # include <event.h>
28 # endif
29 # endif
30 #endif
31 #if PHP_HTTP_HAVE_LIBICU
32 # include <unicode/uversion.h>
33 #endif
34 #if PHP_HTTP_HAVE_LIBIDN
35 # include <idna.h>
36 #endif
37 #if PHP_HTTP_HAVE_LIBIDN2
38 # include <idn2.h>
39 #endif
40 #if PHP_HTTP_HAVE_LIBIDNKIT2 || PHP_HTTP_HAVE_LIBIDNKIT
41 #include "idn/version.h"
42 #endif
43
44 ZEND_DECLARE_MODULE_GLOBALS(php_http);
45
46 #if COMPILE_DL_HTTP
47 ZEND_GET_MODULE(http)
48 #endif
49
50 zend_function_entry http_functions[] = {
51 EMPTY_FUNCTION_ENTRY
52 };
53
54 PHP_MINIT_FUNCTION(http);
55 PHP_MSHUTDOWN_FUNCTION(http);
56 PHP_RSHUTDOWN_FUNCTION(http);
57 PHP_MINFO_FUNCTION(http);
58
59 static zend_module_dep http_module_deps[] = {
60 ZEND_MOD_REQUIRED("raphf")
61 ZEND_MOD_REQUIRED("propro")
62 ZEND_MOD_REQUIRED("spl")
63 #if PHP_HTTP_HAVE_HASH
64 ZEND_MOD_REQUIRED("hash")
65 #endif
66 #if PHP_HTTP_HAVE_ICONV
67 ZEND_MOD_REQUIRED("iconv")
68 #endif
69 {NULL, NULL, NULL, 0}
70 };
71
72 zend_module_entry http_module_entry = {
73 STANDARD_MODULE_HEADER_EX,
74 NULL,
75 http_module_deps,
76 "http",
77 http_functions,
78 PHP_MINIT(http),
79 PHP_MSHUTDOWN(http),
80 NULL,
81 PHP_RSHUTDOWN(http),
82 PHP_MINFO(http),
83 PHP_PECL_HTTP_VERSION,
84 STANDARD_MODULE_PROPERTIES
85 };
86
87 int http_module_number;
88
89 #if PHP_DEBUG && !HAVE_GCOV
90 void _dpf(int type, const char *data, size_t length)
91 {
92 static const char _sym[] = "><><><";
93 if (type) {
94 int nwp = 0;
95 for (fprintf(stderr, "%c ", _sym[type-1]); length--; data++) {
96 int ip = PHP_HTTP_IS_CTYPE(print, *data);
97 if (!ip && *data != '\r' && *data != '\n') nwp = 1;
98 fprintf(stderr, ip?"%c":"\\x%02x", (int) (*data & 0xff));
99 if (!nwp && *data == '\n' && length) {
100 fprintf(stderr, "\n%c ", _sym[type-1]);
101 }
102 }
103 fprintf(stderr, "\n");
104 } else {
105 fprintf(stderr, "# %.*s\n", (int) length, data);
106 }
107 }
108 #endif
109
110 static void php_http_globals_init_once(zend_php_http_globals *G)
111 {
112 memset(G, 0, sizeof(*G));
113 }
114
115 #if 0
116 static inline void php_http_globals_init(zend_php_http_globals *G)
117 {
118 }
119
120 static inline void php_http_globals_free(zend_php_http_globals *G)
121 {
122 }
123 #endif
124
125 PHP_INI_BEGIN()
126 STD_PHP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL, OnUpdateString, env.etag_mode, zend_php_http_globals, php_http_globals)
127 PHP_INI_END()
128
129 PHP_MINIT_FUNCTION(http)
130 {
131 http_module_number = module_number;
132 ZEND_INIT_MODULE_GLOBALS(php_http, php_http_globals_init_once, NULL);
133 REGISTER_INI_ENTRIES();
134
135 if (0
136 || SUCCESS != PHP_MINIT_CALL(http_object)
137 || SUCCESS != PHP_MINIT_CALL(http_exception)
138 || SUCCESS != PHP_MINIT_CALL(http_cookie)
139 || SUCCESS != PHP_MINIT_CALL(http_encoding)
140 || SUCCESS != PHP_MINIT_CALL(http_encoding_zlib)
141 #if PHP_HTTP_HAVE_LIBBROTLI
142 || SUCCESS != PHP_MINIT_CALL(http_encoding_brotli)
143 #endif
144 || SUCCESS != PHP_MINIT_CALL(http_filter)
145 || SUCCESS != PHP_MINIT_CALL(http_header)
146 || SUCCESS != PHP_MINIT_CALL(http_header_parser)
147 || SUCCESS != PHP_MINIT_CALL(http_message)
148 || SUCCESS != PHP_MINIT_CALL(http_message_parser)
149 || SUCCESS != PHP_MINIT_CALL(http_message_body)
150 || SUCCESS != PHP_MINIT_CALL(http_querystring)
151 || SUCCESS != PHP_MINIT_CALL(http_client)
152 || SUCCESS != PHP_MINIT_CALL(http_client_request)
153 || SUCCESS != PHP_MINIT_CALL(http_client_response)
154 #if PHP_HTTP_HAVE_LIBCURL
155 || SUCCESS != PHP_MINIT_CALL(http_curl)
156 || SUCCESS != PHP_MINIT_CALL(http_client_curl)
157 || SUCCESS != PHP_MINIT_CALL(http_client_curl_user)
158 #endif
159 || SUCCESS != PHP_MINIT_CALL(http_url)
160 || SUCCESS != PHP_MINIT_CALL(http_env)
161 || SUCCESS != PHP_MINIT_CALL(http_env_request)
162 || SUCCESS != PHP_MINIT_CALL(http_env_response)
163 || SUCCESS != PHP_MINIT_CALL(http_params)
164 ) {
165 return FAILURE;
166 }
167
168 return SUCCESS;
169 }
170
171
172
173 PHP_MSHUTDOWN_FUNCTION(http)
174 {
175 UNREGISTER_INI_ENTRIES();
176
177 if (0
178 || SUCCESS != PHP_MSHUTDOWN_CALL(http_message)
179 #if PHP_HTTP_HAVE_LIBCURL
180 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client_curl)
181 || SUCCESS != PHP_MSHUTDOWN_CALL(http_curl)
182 #endif
183 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client)
184 ) {
185 return FAILURE;
186 }
187
188 return SUCCESS;
189 }
190
191 PHP_RSHUTDOWN_FUNCTION(http)
192 {
193 if (0
194 || SUCCESS != PHP_RSHUTDOWN_CALL(http_env)
195 ) {
196 return FAILURE;
197 }
198
199 return SUCCESS;
200 }
201
202 PHP_MINFO_FUNCTION(http)
203 {
204 php_http_buffer_t buf;
205
206 php_http_buffer_init(&buf);
207
208 php_info_print_table_start();
209 php_info_print_table_header(2, "HTTP Support", "enabled");
210 php_info_print_table_row(2, "Extension Version", PHP_PECL_HTTP_VERSION);
211 php_info_print_table_end();
212
213 php_info_print_table_start();
214 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
215 php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
216 #if PHP_HTTP_HAVE_LIBCURL
217 {
218 curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
219 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
220 }
221 #else
222 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
223 #endif
224
225 #if PHP_HTTP_HAVE_LIBEVENT
226 php_info_print_table_row(3, "libevent",
227 # ifdef LIBEVENT_VERSION
228 LIBEVENT_VERSION,
229 # else
230 PHP_HTTP_LIBEVENT_VERSION,
231 # endif
232 event_get_version());
233 #else
234 php_info_print_table_row(3, "libevent", "disabled", "disabled");
235 #endif
236
237 #if PHP_HTTP_HAVE_LIBICU
238 {
239 UVersionInfo uv = {0};
240 char us[U_MAX_VERSION_STRING_LENGTH] = {0};
241
242 u_getVersion(uv);
243 u_versionToString(uv, us);
244 php_info_print_table_row(3, "libicu "
245 #if HAVE_UIDNA_NAMETOASCII_UTF8 && HAVE_UIDNA_IDNTOASCII
246 "(IDNA2008/IDNA2003)"
247 #elif HAVE_UIDNA_NAMETOASCII_UTF8
248 "(IDNA2008)"
249 #elif HAVE_UIDNA_IDNTOASCII
250 "(IDNA2003)"
251 #endif
252 , U_ICU_VERSION, us);
253 }
254 #else
255 php_info_print_table_row(3, "libicu (IDNA2008/IDNA2003)", "disabled", "disabled");
256 #endif
257 #if PHP_HTTP_HAVE_LIBIDN2
258 php_info_print_table_row(3, "libidn2 (IDNA2008)", IDN2_VERSION, idn2_check_version(NULL));
259 #else
260 php_info_print_table_row(3, "libidn2 (IDNA2008)", "disabled", "disabled");
261 #endif
262 #if PHP_HTTP_HAVE_LIBIDN
263 php_info_print_table_row(3, "libidn (IDNA2003)", PHP_HTTP_LIBIDN_VERSION, "unknown");
264 #else
265 php_info_print_table_row(3, "libidn (IDNA2003)", "disabled", "disabled");
266 #endif
267 #if PHP_HTTP_HAVE_LIBIDNKIT2
268 php_info_print_table_row(3, "libidnkit2 (IDNA2008)", IDNKIT_VERSION_LIBIDN, idn_version_libidn());
269 #else
270 php_info_print_table_row(3, "libidnkit2 (IDNA2008)", "disabled", "disabled");
271 #endif
272 #if PHP_HTTP_HAVE_LIBIDNKIT
273 php_info_print_table_row(3, "libidnkit (IDNA2003)", IDNKIT_VERSION, idn_version_getstring());
274 #else
275 php_info_print_table_row(3, "libidnkit (IDNA2003)", "disabled", "disabled");
276 #endif
277 php_info_print_table_end();
278
279 DISPLAY_INI_ENTRIES();
280 }
281
282
283 /*
284 * Local variables:
285 * tab-width: 4
286 * c-basic-offset: 4
287 * End:
288 * vim600: noet sw=4 ts=4 fdm=marker
289 * vim<600: noet sw=4 ts=4
290 */
291