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