prepare v4.2.5
[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("spl")
62 #if PHP_HTTP_HAVE_HASH
63 ZEND_MOD_REQUIRED("hash")
64 #endif
65 #if PHP_HTTP_HAVE_ICONV
66 ZEND_MOD_REQUIRED("iconv")
67 #endif
68 {NULL, NULL, NULL, 0}
69 };
70
71 zend_module_entry http_module_entry = {
72 STANDARD_MODULE_HEADER_EX,
73 NULL,
74 http_module_deps,
75 "http",
76 http_functions,
77 PHP_MINIT(http),
78 PHP_MSHUTDOWN(http),
79 NULL,
80 PHP_RSHUTDOWN(http),
81 PHP_MINFO(http),
82 PHP_PECL_HTTP_VERSION,
83 STANDARD_MODULE_PROPERTIES
84 };
85
86 int http_module_number;
87
88 #if PHP_DEBUG && !HAVE_GCOV
89 void _dpf(int type, const char *data, size_t length)
90 {
91 static const char _sym[] = "><><><";
92 if (type) {
93 int nwp = 0;
94 for (fprintf(stderr, "%c ", _sym[type-1]); length--; data++) {
95 int ip = PHP_HTTP_IS_CTYPE(print, *data);
96 if (!ip && *data != '\r' && *data != '\n') nwp = 1;
97 fprintf(stderr, ip?"%c":"\\x%02x", (int) (*data & 0xff));
98 if (!nwp && *data == '\n' && length) {
99 fprintf(stderr, "\n%c ", _sym[type-1]);
100 }
101 }
102 fprintf(stderr, "\n");
103 } else {
104 fprintf(stderr, "# %.*s\n", (int) length, data);
105 }
106 }
107 #endif
108
109 static void php_http_globals_init_once(zend_php_http_globals *G)
110 {
111 memset(G, 0, sizeof(*G));
112 }
113
114 #if 0
115 static inline void php_http_globals_init(zend_php_http_globals *G)
116 {
117 }
118
119 static inline void php_http_globals_free(zend_php_http_globals *G)
120 {
121 }
122 #endif
123
124 PHP_INI_BEGIN()
125 STD_PHP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL, OnUpdateString, env.etag_mode, zend_php_http_globals, php_http_globals)
126 PHP_INI_END()
127
128 PHP_MINIT_FUNCTION(http)
129 {
130 http_module_number = module_number;
131 ZEND_INIT_MODULE_GLOBALS(php_http, php_http_globals_init_once, NULL);
132 REGISTER_INI_ENTRIES();
133
134 if (0
135 || SUCCESS != PHP_MINIT_CALL(http_object)
136 || SUCCESS != PHP_MINIT_CALL(http_exception)
137 || SUCCESS != PHP_MINIT_CALL(http_cookie)
138 || SUCCESS != PHP_MINIT_CALL(http_encoding)
139 || SUCCESS != PHP_MINIT_CALL(http_encoding_zlib)
140 #if PHP_HTTP_HAVE_LIBBROTLI
141 || SUCCESS != PHP_MINIT_CALL(http_encoding_brotli)
142 #endif
143 || SUCCESS != PHP_MINIT_CALL(http_filter)
144 || SUCCESS != PHP_MINIT_CALL(http_header)
145 || SUCCESS != PHP_MINIT_CALL(http_header_parser)
146 || SUCCESS != PHP_MINIT_CALL(http_message)
147 || SUCCESS != PHP_MINIT_CALL(http_message_parser)
148 || SUCCESS != PHP_MINIT_CALL(http_message_body)
149 || SUCCESS != PHP_MINIT_CALL(http_querystring)
150 || SUCCESS != PHP_MINIT_CALL(http_client)
151 || SUCCESS != PHP_MINIT_CALL(http_client_request)
152 || SUCCESS != PHP_MINIT_CALL(http_client_response)
153 #if PHP_HTTP_HAVE_LIBCURL
154 || SUCCESS != PHP_MINIT_CALL(http_curl)
155 || SUCCESS != PHP_MINIT_CALL(http_client_curl)
156 || SUCCESS != PHP_MINIT_CALL(http_client_curl_user)
157 #endif
158 || SUCCESS != PHP_MINIT_CALL(http_url)
159 || SUCCESS != PHP_MINIT_CALL(http_env)
160 || SUCCESS != PHP_MINIT_CALL(http_env_request)
161 || SUCCESS != PHP_MINIT_CALL(http_env_response)
162 || SUCCESS != PHP_MINIT_CALL(http_params)
163 ) {
164 return FAILURE;
165 }
166
167 return SUCCESS;
168 }
169
170
171
172 PHP_MSHUTDOWN_FUNCTION(http)
173 {
174 UNREGISTER_INI_ENTRIES();
175
176 if (0
177 || SUCCESS != PHP_MSHUTDOWN_CALL(http_message)
178 #if PHP_HTTP_HAVE_LIBCURL
179 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client_curl)
180 || SUCCESS != PHP_MSHUTDOWN_CALL(http_curl)
181 #endif
182 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client)
183 ) {
184 return FAILURE;
185 }
186
187 return SUCCESS;
188 }
189
190 PHP_RSHUTDOWN_FUNCTION(http)
191 {
192 if (0
193 || SUCCESS != PHP_RSHUTDOWN_CALL(http_env)
194 ) {
195 return FAILURE;
196 }
197
198 return SUCCESS;
199 }
200
201 PHP_MINFO_FUNCTION(http)
202 {
203 php_http_buffer_t buf;
204
205 php_http_buffer_init(&buf);
206
207 php_info_print_table_start();
208 php_info_print_table_header(2, "HTTP Support", "enabled");
209 php_info_print_table_row(2, "Extension Version", PHP_PECL_HTTP_VERSION);
210 php_info_print_table_end();
211
212 php_info_print_table_start();
213 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
214 php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
215 #if PHP_HTTP_HAVE_LIBCURL
216 {
217 curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
218 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
219 }
220 #else
221 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
222 #endif
223
224 #if PHP_HTTP_HAVE_LIBEVENT
225 php_info_print_table_row(3, "libevent",
226 # ifdef LIBEVENT_VERSION
227 LIBEVENT_VERSION,
228 # else
229 PHP_HTTP_LIBEVENT_VERSION,
230 # endif
231 event_get_version());
232 #else
233 php_info_print_table_row(3, "libevent", "disabled", "disabled");
234 #endif
235
236 #if PHP_HTTP_HAVE_LIBICU
237 {
238 UVersionInfo uv = {0};
239 char us[U_MAX_VERSION_STRING_LENGTH] = {0};
240
241 u_getVersion(uv);
242 u_versionToString(uv, us);
243 php_info_print_table_row(3, "libicu "
244 #if HAVE_UIDNA_NAMETOASCII_UTF8 && HAVE_UIDNA_IDNTOASCII
245 "(IDNA2008/IDNA2003)"
246 #elif HAVE_UIDNA_NAMETOASCII_UTF8
247 "(IDNA2008)"
248 #elif HAVE_UIDNA_IDNTOASCII
249 "(IDNA2003)"
250 #endif
251 , U_ICU_VERSION, us);
252 }
253 #else
254 php_info_print_table_row(3, "libicu (IDNA2008/IDNA2003)", "disabled", "disabled");
255 #endif
256 #if PHP_HTTP_HAVE_LIBIDN2
257 php_info_print_table_row(3, "libidn2 (IDNA2008)", IDN2_VERSION, idn2_check_version(NULL));
258 #else
259 php_info_print_table_row(3, "libidn2 (IDNA2008)", "disabled", "disabled");
260 #endif
261 #if PHP_HTTP_HAVE_LIBIDN
262 php_info_print_table_row(3, "libidn (IDNA2003)", PHP_HTTP_LIBIDN_VERSION, "unknown");
263 #else
264 php_info_print_table_row(3, "libidn (IDNA2003)", "disabled", "disabled");
265 #endif
266 #if PHP_HTTP_HAVE_LIBIDNKIT2
267 php_info_print_table_row(3, "libidnkit2 (IDNA2008)", IDNKIT_VERSION_LIBIDN, idn_version_libidn());
268 #else
269 php_info_print_table_row(3, "libidnkit2 (IDNA2008)", "disabled", "disabled");
270 #endif
271 #if PHP_HTTP_HAVE_LIBIDNKIT
272 php_info_print_table_row(3, "libidnkit (IDNA2003)", IDNKIT_VERSION, idn_version_getstring());
273 #else
274 php_info_print_table_row(3, "libidnkit (IDNA2003)", "disabled", "disabled");
275 #endif
276 php_info_print_table_end();
277
278 DISPLAY_INI_ENTRIES();
279 }
280
281
282 /*
283 * Local variables:
284 * tab-width: 4
285 * c-basic-offset: 4
286 * End:
287 * vim600: noet sw=4 ts=4 fdm=marker
288 * vim<600: noet sw=4 ts=4
289 */
290