header cleanups; fix IDE warnings
[m6w6/ext-http] / 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-2011, 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_CURL
21 # include <curl/curl.h>
22 # if PHP_HTTP_HAVE_EVENT
23 # include <event.h>
24 # endif
25 #endif
26 #if PHP_HTTP_HAVE_NEON
27 # include <neon/ne_utils.h>
28 #endif
29 #if PHP_HTTP_HAVE_SERF
30 # include <serf.h>
31 #endif
32
33 ZEND_DECLARE_MODULE_GLOBALS(php_http);
34
35 #ifdef COMPILE_DL_HTTP
36 ZEND_GET_MODULE(http)
37 #endif
38
39 zend_function_entry http_functions[] = {
40 EMPTY_FUNCTION_ENTRY
41 };
42
43 PHP_MINIT_FUNCTION(http);
44 PHP_MSHUTDOWN_FUNCTION(http);
45 PHP_RINIT_FUNCTION(http);
46 PHP_RSHUTDOWN_FUNCTION(http);
47 PHP_MINFO_FUNCTION(http);
48
49 static zend_module_dep http_module_deps[] = {
50 ZEND_MOD_REQUIRED("spl")
51 #ifdef PHP_HTTP_HAVE_HASH
52 ZEND_MOD_REQUIRED("hash")
53 #endif
54 #ifdef PHP_HTTP_HAVE_ICONV
55 ZEND_MOD_REQUIRED("iconv")
56 #endif
57 #ifdef PHP_HTTP_HAVE_EVENT
58 ZEND_MOD_CONFLICTS("event")
59 #endif
60 {NULL, NULL, NULL, 0}
61 };
62
63 zend_module_entry http_module_entry = {
64 STANDARD_MODULE_HEADER_EX,
65 NULL,
66 http_module_deps,
67 "http",
68 http_functions,
69 PHP_MINIT(http),
70 PHP_MSHUTDOWN(http),
71 PHP_RINIT(http),
72 PHP_RSHUTDOWN(http),
73 PHP_MINFO(http),
74 PHP_HTTP_EXT_VERSION,
75 STANDARD_MODULE_PROPERTIES
76 };
77
78 int http_module_number;
79
80 #if PHP_DEBUG
81 void _dpf(int type, const char *data, size_t length)
82 {
83 static const char _sym[] = "><><><";
84 if (type) {
85 int nwp = 0;
86 for (fprintf(stderr, "%c ", _sym[type-1]); length--; data++) {
87 int ip = PHP_HTTP_IS_CTYPE(print, *data);
88 if (!ip && *data != '\r' && *data != '\n') nwp = 1;
89 fprintf(stderr, ip?"%c":"\\x%02x", (int) (*data & 0xff));
90 if (!nwp && *data == '\n' && length) {
91 fprintf(stderr, "\n%c ", _sym[type-1]);
92 }
93 }
94 fprintf(stderr, "\n");
95 } else {
96 fprintf(stderr, "# %.*s\n", (int) length, data);
97 }
98 }
99 #endif
100
101 static void php_http_globals_init_once(zend_php_http_globals *G)
102 {
103 memset(G, 0, sizeof(*G));
104 }
105
106 static inline void php_http_globals_init(zend_php_http_globals *G TSRMLS_DC)
107 {
108 }
109
110 static inline void php_http_globals_free(zend_php_http_globals *G TSRMLS_DC)
111 {
112 }
113
114 #if defined(ZTS) && defined(PHP_DEBUG)
115 #if ZTS && PHP_DEBUG
116 zend_php_http_globals *php_http_globals(void)
117 {
118 TSRMLS_FETCH();
119 return PHP_HTTP_G;
120 }
121 #endif
122 #endif
123 PHP_INI_BEGIN()
124 PHP_HTTP_INI_ENTRY("http.etag.mode", "md5", PHP_INI_ALL, OnUpdateString, env.etag_mode)
125 PHP_HTTP_INI_ENTRY("http.request_datashare.cookie", "0", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.cookie)
126 PHP_HTTP_INI_ENTRY("http.request_datashare.dns", "1", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.dns)
127 PHP_HTTP_INI_ENTRY("http.request_datashare.ssl", "0", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.ssl)
128 PHP_HTTP_INI_ENTRY("http.request_datashare.connect", "0", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.connect)
129 PHP_HTTP_INI_ENTRY("http.persistent_handle.limit", "-1", PHP_INI_SYSTEM, OnUpdateLong, persistent_handle.limit)
130 PHP_INI_END()
131
132 PHP_MINIT_FUNCTION(http)
133 {
134 http_module_number = module_number;
135 ZEND_INIT_MODULE_GLOBALS(php_http, php_http_globals_init_once, NULL);
136 REGISTER_INI_ENTRIES();
137
138 if (0
139 || SUCCESS != PHP_MINIT_CALL(http_object)
140 || SUCCESS != PHP_MINIT_CALL(http_exception)
141 || SUCCESS != PHP_MINIT_CALL(http_persistent_handle)
142 || SUCCESS != PHP_MINIT_CALL(http_cookie)
143 || SUCCESS != PHP_MINIT_CALL(http_encoding)
144 || SUCCESS != PHP_MINIT_CALL(http_filter)
145 || SUCCESS != PHP_MINIT_CALL(http_header)
146 || SUCCESS != PHP_MINIT_CALL(http_message)
147 || SUCCESS != PHP_MINIT_CALL(http_message_body)
148 || SUCCESS != PHP_MINIT_CALL(http_property_proxy)
149 || SUCCESS != PHP_MINIT_CALL(http_querystring)
150 || SUCCESS != PHP_MINIT_CALL(http_request_factory)
151 || SUCCESS != PHP_MINIT_CALL(http_request)
152 #if PHP_HTTP_HAVE_CURL
153 || SUCCESS != PHP_MINIT_CALL(http_curl)
154 #endif
155 #if PHP_HTTP_HAVE_NEON
156 || SUCCESS != PHP_MINIT_CALL(http_neon)
157 #endif
158 || SUCCESS != PHP_MINIT_CALL(http_request_datashare)
159 || SUCCESS != PHP_MINIT_CALL(http_request_method)
160 || SUCCESS != PHP_MINIT_CALL(http_request_pool)
161 || SUCCESS != PHP_MINIT_CALL(http_url)
162 || SUCCESS != PHP_MINIT_CALL(http_env)
163 || SUCCESS != PHP_MINIT_CALL(http_env_response)
164 || SUCCESS != PHP_MINIT_CALL(http_params)
165 ) {
166 return FAILURE;
167 }
168
169 return SUCCESS;
170 }
171
172
173
174 PHP_MSHUTDOWN_FUNCTION(http)
175 {
176 UNREGISTER_INI_ENTRIES();
177
178 if (0
179 || SUCCESS != PHP_MSHUTDOWN_CALL(http_message)
180 #if PHP_HTTP_HAVE_CURL
181 || SUCCESS != PHP_MSHUTDOWN_CALL(http_curl)
182 #endif
183 #if PHP_HTTP_HAVE_NEON
184 || SUCCESS != PHP_MSHUTDOWN_CALL(http_neon)
185 #endif
186 || SUCCESS != PHP_MSHUTDOWN_CALL(http_request_datashare)
187 || SUCCESS != PHP_MSHUTDOWN_CALL(http_request_factory)
188 || SUCCESS != PHP_MSHUTDOWN_CALL(http_persistent_handle)
189 ) {
190 return FAILURE;
191 }
192
193 return SUCCESS;
194 }
195
196 PHP_RINIT_FUNCTION(http)
197 {
198 if (0
199 || SUCCESS != PHP_RINIT_CALL(http_env)
200 || SUCCESS != PHP_RINIT_CALL(http_request_datashare)
201 #if PHP_HTTP_HAVE_CURL
202 || SUCCESS != PHP_RINIT_CALL(http_curl)
203 #endif
204 ) {
205 return FAILURE;
206 }
207
208 return SUCCESS;
209 }
210
211 PHP_RSHUTDOWN_FUNCTION(http)
212 {
213 if (0
214 || SUCCESS != PHP_RSHUTDOWN_CALL(http_env)
215 || SUCCESS != PHP_RSHUTDOWN_CALL(http_request_datashare)
216 ) {
217 return FAILURE;
218 }
219
220 return SUCCESS;
221 }
222
223 PHP_MINFO_FUNCTION(http)
224 {
225 php_info_print_table_start();
226 php_info_print_table_header(2, "HTTP Support", "enabled");
227 php_info_print_table_row(2, "Extension Version", PHP_HTTP_EXT_VERSION);
228 php_info_print_table_end();
229
230 php_info_print_table_start();
231 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
232 php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
233 #if PHP_HTTP_HAVE_CURL
234 {
235 curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
236 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
237 }
238 #else
239 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
240 #endif
241 #if PHP_HTTP_HAVE_NEON
242 {
243 char ne_v[16] = {0};
244 sscanf(ne_version_string(), "neon %15[^ :]", &ne_v[0]);
245 php_info_print_table_row(3, "libneon", PHP_HTTP_NEON_VERSION, ne_v);
246 }
247 #else
248 php_info_print_table_row(3, "libneon", "disabled", "disabled");
249 #endif
250
251 #if PHP_HTTP_HAVE_EVENT
252 php_info_print_table_row(3, "libevent", PHP_HTTP_EVENT_VERSION, event_get_version());
253 #else
254 php_info_print_table_row(3, "libevent", "disabled", "disabled");
255 #endif
256
257 #if PHP_HTTP_HAVE_SERF
258 {
259 int v[3];
260 char sl_v[16] = {0};
261
262 serf_lib_version(&v[0], &v[1], &v[2]);
263 slprintf(sl_v, lenof(sl_v), "%d.%d.%d", v[0], v[1], v[2]);
264 php_info_print_table_row(3, "libserf", SERF_VERSION_STRING, sl_v);
265 }
266 #else
267 php_info_print_table_row(3, "libserf", "disabled", "disabled");
268 #endif
269 php_info_print_table_end();
270
271 php_info_print_table_start();
272 php_info_print_table_colspan_header(4, "Persistent Handles");
273 php_info_print_table_header(4, "Provider", "Ident", "Used", "Free");
274 {
275 HashTable *ht;
276 HashPosition pos1, pos2;
277 php_http_array_hashkey_t provider = php_http_array_hashkey_init(0), ident = php_http_array_hashkey_init(0);
278 zval **val, **sub, **zused, **zfree;
279
280 if ((ht = php_http_persistent_handle_statall(NULL TSRMLS_CC)) && zend_hash_num_elements(ht)) {
281 FOREACH_HASH_KEYVAL(pos1, ht, provider, val) {
282 if (zend_hash_num_elements(Z_ARRVAL_PP(val))) {
283 FOREACH_KEYVAL(pos2, *val, ident, sub) {
284 if ( SUCCESS == zend_hash_find(Z_ARRVAL_PP(sub), ZEND_STRS("used"), (void *) &zused) &&
285 SUCCESS == zend_hash_find(Z_ARRVAL_PP(sub), ZEND_STRS("free"), (void *) &zfree)) {
286 zval *used = php_http_ztyp(IS_STRING, *zused);
287 zval *free = php_http_ztyp(IS_STRING, *zfree);
288 php_info_print_table_row(4, provider.str, ident.str, Z_STRVAL_P(used), Z_STRVAL_P(free));
289 zval_ptr_dtor(&used);
290 zval_ptr_dtor(&free);
291 } else {
292 php_info_print_table_row(4, provider.str, ident.str, "0", "0");
293 }
294 }
295 } else {
296 php_info_print_table_row(4, provider.str, "N/A", "0", "0");
297 }
298 }
299 } else {
300 php_info_print_table_row(4, "N/A", "N/A", "0", "0");
301 }
302 if (ht) {
303 zend_hash_destroy(ht);
304 FREE_HASHTABLE(ht);
305 }
306 }
307 php_info_print_table_end();
308
309 DISPLAY_INI_ENTRIES();
310 }
311
312
313 /*
314 * Local variables:
315 * tab-width: 4
316 * c-basic-offset: 4
317 * End:
318 * vim600: noet sw=4 ts=4 fdm=marker
319 * vim<600: noet sw=4 ts=4
320 */
321