bc9166aa9596f7fbe4176a7bf9af4b520de01692
[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_filter)
141 || SUCCESS != PHP_MINIT_CALL(http_header)
142 || SUCCESS != PHP_MINIT_CALL(http_header_parser)
143 || SUCCESS != PHP_MINIT_CALL(http_message)
144 || SUCCESS != PHP_MINIT_CALL(http_message_parser)
145 || SUCCESS != PHP_MINIT_CALL(http_message_body)
146 || SUCCESS != PHP_MINIT_CALL(http_querystring)
147 || SUCCESS != PHP_MINIT_CALL(http_client)
148 || SUCCESS != PHP_MINIT_CALL(http_client_request)
149 || SUCCESS != PHP_MINIT_CALL(http_client_response)
150 #if PHP_HTTP_HAVE_LIBCURL
151 || SUCCESS != PHP_MINIT_CALL(http_curl)
152 || SUCCESS != PHP_MINIT_CALL(http_client_curl)
153 || SUCCESS != PHP_MINIT_CALL(http_client_curl_user)
154 #endif
155 || SUCCESS != PHP_MINIT_CALL(http_url)
156 || SUCCESS != PHP_MINIT_CALL(http_env)
157 || SUCCESS != PHP_MINIT_CALL(http_env_request)
158 || SUCCESS != PHP_MINIT_CALL(http_env_response)
159 || SUCCESS != PHP_MINIT_CALL(http_params)
160 ) {
161 return FAILURE;
162 }
163
164 return SUCCESS;
165 }
166
167
168
169 PHP_MSHUTDOWN_FUNCTION(http)
170 {
171 UNREGISTER_INI_ENTRIES();
172
173 if (0
174 || SUCCESS != PHP_MSHUTDOWN_CALL(http_message)
175 #if PHP_HTTP_HAVE_LIBCURL
176 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client_curl)
177 || SUCCESS != PHP_MSHUTDOWN_CALL(http_curl)
178 #endif
179 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client)
180 ) {
181 return FAILURE;
182 }
183
184 return SUCCESS;
185 }
186
187 PHP_RSHUTDOWN_FUNCTION(http)
188 {
189 if (0
190 || SUCCESS != PHP_RSHUTDOWN_CALL(http_env)
191 ) {
192 return FAILURE;
193 }
194
195 return SUCCESS;
196 }
197
198 PHP_MINFO_FUNCTION(http)
199 {
200 php_http_buffer_t buf;
201
202 php_http_buffer_init(&buf);
203
204 php_info_print_table_start();
205 php_info_print_table_header(2, "HTTP Support", "enabled");
206 php_info_print_table_row(2, "Extension Version", PHP_PECL_HTTP_VERSION);
207 php_info_print_table_end();
208
209 php_info_print_table_start();
210 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
211 php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
212 #if PHP_HTTP_HAVE_LIBCURL
213 {
214 curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
215 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
216 }
217 #else
218 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
219 #endif
220
221 #if PHP_HTTP_HAVE_LIBEVENT
222 php_info_print_table_row(3, "libevent",
223 # ifdef LIBEVENT_VERSION
224 LIBEVENT_VERSION,
225 # else
226 PHP_HTTP_LIBEVENT_VERSION,
227 # endif
228 event_get_version());
229 #else
230 php_info_print_table_row(3, "libevent", "disabled", "disabled");
231 #endif
232
233 #if PHP_HTTP_HAVE_LIBICU
234 {
235 UVersionInfo uv = {0};
236 char us[U_MAX_VERSION_STRING_LENGTH] = {0};
237
238 u_getVersion(uv);
239 u_versionToString(uv, us);
240 php_info_print_table_row(3, "libicu "
241 #if HAVE_UIDNA_NAMETOASCII_UTF8 && HAVE_UIDNA_IDNTOASCII
242 "(IDNA2008/IDNA2003)"
243 #elif HAVE_UIDNA_NAMETOASCII_UTF8
244 "(IDNA2008)"
245 #elif HAVE_UIDNA_IDNTOASCII
246 "(IDNA2003)"
247 #endif
248 , U_ICU_VERSION, us);
249 }
250 #else
251 php_info_print_table_row(3, "libicu (IDNA2008/IDNA2003)", "disabled", "disabled");
252 #endif
253 #if PHP_HTTP_HAVE_LIBIDN2
254 php_info_print_table_row(3, "libidn2 (IDNA2008)", IDN2_VERSION, idn2_check_version(NULL));
255 #else
256 php_info_print_table_row(3, "libidn2 (IDNA2008)", "disabled", "disabled");
257 #endif
258 #if PHP_HTTP_HAVE_LIBIDN
259 php_info_print_table_row(3, "libidn (IDNA2003)", PHP_HTTP_LIBIDN_VERSION, "unknown");
260 #else
261 php_info_print_table_row(3, "libidn (IDNA2003)", "disabled", "disabled");
262 #endif
263 #if PHP_HTTP_HAVE_LIBIDNKIT2
264 php_info_print_table_row(3, "libidnkit2 (IDNA2008)", IDNKIT_VERSION_LIBIDN, idn_version_libidn());
265 #else
266 php_info_print_table_row(3, "libidnkit2 (IDNA2008)", "disabled", "disabled");
267 #endif
268 #if PHP_HTTP_HAVE_LIBIDNKIT
269 php_info_print_table_row(3, "libidnkit (IDNA2003)", IDNKIT_VERSION, idn_version_getstring());
270 #else
271 php_info_print_table_row(3, "libidnkit (IDNA2003)", "disabled", "disabled");
272 #endif
273 php_info_print_table_end();
274
275 DISPLAY_INI_ENTRIES();
276 }
277
278
279 /*
280 * Local variables:
281 * tab-width: 4
282 * c-basic-offset: 4
283 * End:
284 * vim600: noet sw=4 ts=4 fdm=marker
285 * vim<600: noet sw=4 ts=4
286 */
287