include headers where they're needed
[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-2010, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id: http.c 300300 2010-06-09 07:29:35Z mike $ */
14
15 #include "php_http.h"
16
17 #include <main/php_ini.h>
18 #include <ext/standard/info.h>
19 #include <Zend/zend_extensions.h>
20
21 ZEND_DECLARE_MODULE_GLOBALS(php_http);
22
23 #ifdef COMPILE_DL_HTTP
24 ZEND_GET_MODULE(http)
25 #endif
26
27 zend_function_entry http_functions[] = {
28 EMPTY_FUNCTION_ENTRY
29 };
30
31 PHP_MINIT_FUNCTION(http);
32 PHP_MSHUTDOWN_FUNCTION(http);
33 PHP_RINIT_FUNCTION(http);
34 PHP_RSHUTDOWN_FUNCTION(http);
35 PHP_MINFO_FUNCTION(http);
36
37 static zend_module_dep http_module_deps[] = {
38 ZEND_MOD_REQUIRED("spl")
39 #ifdef PHP_HTTP_HAVE_HASH
40 ZEND_MOD_REQUIRED("hash")
41 #endif
42 #ifdef PHP_HTTP_HAVE_ICONV
43 ZEND_MOD_REQUIRED("iconv")
44 #endif
45 #ifdef PHP_HTTP_HAVE_EVENT
46 ZEND_MOD_CONFLICTS("event")
47 #endif
48 {NULL, NULL, NULL, 0}
49 };
50
51 zend_module_entry http_module_entry = {
52 STANDARD_MODULE_HEADER_EX,
53 NULL,
54 http_module_deps,
55 "http",
56 http_functions,
57 PHP_MINIT(http),
58 PHP_MSHUTDOWN(http),
59 PHP_RINIT(http),
60 PHP_RSHUTDOWN(http),
61 PHP_MINFO(http),
62 PHP_HTTP_EXT_VERSION,
63 STANDARD_MODULE_PROPERTIES
64 };
65
66 int http_module_number;
67
68 static void php_http_globals_init_once(zend_php_http_globals *G)
69 {
70 memset(G, 0, sizeof(*G));
71 }
72
73 static inline void php_http_globals_init(zend_php_http_globals *G TSRMLS_DC)
74 {
75 }
76
77 static inline void php_http_globals_free(zend_php_http_globals *G TSRMLS_DC)
78 {
79 }
80
81 #if defined(ZTS) && defined(PHP_DEBUG)
82 #if ZTS && PHP_DEBUG
83 zend_http_globals *php_http_globals(void)
84 {
85 TSRMLS_FETCH();
86 return PHP_HTTP_G;
87 }
88 #endif
89 #endif
90 PHP_INI_MH(http_update_persistent_handle_ident)
91 {
92 PHP_HTTP_G->persistent_handle.ident.h = zend_hash_func(new_value, PHP_HTTP_G->persistent_handle.ident.l = new_value_length+1);
93 return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
94 }
95
96 PHP_INI_BEGIN()
97 PHP_HTTP_INI_ENTRY("http.etag.mode", "md5", PHP_INI_ALL, OnUpdateString, env.etag_mode)
98 PHP_HTTP_INI_ENTRY("http.request_datashare.cookie", "0", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.cookie)
99 PHP_HTTP_INI_ENTRY("http.request_datashare.dns", "1", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.dns)
100 PHP_HTTP_INI_ENTRY("http.request_datashare.ssl", "0", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.ssl)
101 PHP_HTTP_INI_ENTRY("http.request_datashare.connect", "0", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.connect)
102 PHP_HTTP_INI_ENTRY("http.persistent_handle.limit", "-1", PHP_INI_SYSTEM, OnUpdateLong, persistent_handle.limit)
103 PHP_HTTP_INI_ENTRY("http.persistent_handle.ident", "GLOBAL", PHP_INI_ALL, http_update_persistent_handle_ident, persistent_handle.ident.s)
104 PHP_INI_END()
105
106 PHP_MINIT_FUNCTION(http)
107 {
108 http_module_number = module_number;
109 ZEND_INIT_MODULE_GLOBALS(php_http, php_http_globals_init_once, NULL);
110 REGISTER_INI_ENTRIES();
111
112 if (0
113 || SUCCESS != PHP_MINIT_CALL(http_object)
114 || SUCCESS != PHP_MINIT_CALL(http_exception)
115 || SUCCESS != PHP_MINIT_CALL(http_cookie)
116 || SUCCESS != PHP_MINIT_CALL(http_encoding)
117 || SUCCESS != PHP_MINIT_CALL(http_filter)
118 || SUCCESS != PHP_MINIT_CALL(http_message)
119 || SUCCESS != PHP_MINIT_CALL(http_message_body)
120 || SUCCESS != PHP_MINIT_CALL(http_persistent_handle)
121 || SUCCESS != PHP_MINIT_CALL(http_property_proxy)
122 || SUCCESS != PHP_MINIT_CALL(http_querystring)
123 || SUCCESS != PHP_MINIT_CALL(http_request)
124 || SUCCESS != PHP_MINIT_CALL(http_request_datashare)
125 || SUCCESS != PHP_MINIT_CALL(http_request_method)
126 || SUCCESS != PHP_MINIT_CALL(http_request_pool)
127 || SUCCESS != PHP_MINIT_CALL(http_url)
128 || SUCCESS != PHP_MINIT_CALL(http_env)
129 ) {
130 return FAILURE;
131 }
132
133 return SUCCESS;
134 }
135
136
137
138 PHP_MSHUTDOWN_FUNCTION(http)
139 {
140 UNREGISTER_INI_ENTRIES();
141
142 if (0
143 || SUCCESS != PHP_MSHUTDOWN_CALL(http_message)
144 || SUCCESS != PHP_MSHUTDOWN_CALL(http_request)
145 || SUCCESS != PHP_MSHUTDOWN_CALL(http_request_datashare)
146 || SUCCESS != PHP_MSHUTDOWN_CALL(http_persistent_handle)
147 ) {
148 return FAILURE;
149 }
150
151 return SUCCESS;
152 }
153
154 PHP_RINIT_FUNCTION(http)
155 {
156 if (0
157 || SUCCESS != PHP_RINIT_CALL(http_env)
158 || SUCCESS != PHP_RINIT_CALL(http_request_datashare)
159 || SUCCESS != PHP_RINIT_CALL(http_request_pool)
160 ) {
161 return FAILURE;
162 }
163
164 return SUCCESS;
165 }
166
167 PHP_RSHUTDOWN_FUNCTION(http)
168 {
169 if (0
170 || SUCCESS != PHP_RSHUTDOWN_CALL(http_env)
171 || SUCCESS != PHP_RSHUTDOWN_CALL(http_request_datashare)
172 ) {
173 return FAILURE;
174 }
175
176 return SUCCESS;
177 }
178
179
180
181 PHP_MINFO_FUNCTION(http)
182 {
183 php_info_print_table_start();
184 {
185 php_info_print_table_header(2, "HTTP Support", "enabled");
186 php_info_print_table_row(2, "Extension Version", PHP_HTTP_EXT_VERSION);
187 }
188 php_info_print_table_end();
189
190 php_info_print_table_start();
191 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
192 {
193 #ifdef PHP_HTTP_HAVE_CURL
194 curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
195 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
196 #else
197 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
198 #endif
199 #ifdef PHP_HTTP_HAVE_EVENT
200 php_info_print_table_row(3, "libevent", PHP_HTTP_EVENT_VERSION, event_get_version());
201 #else
202 php_info_print_table_row(3, "libevent", "disabled", "disabled");
203 #endif
204 #ifdef PHP_HTTP_HAVE_ZLIB
205 php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
206 #else
207 php_info_print_table_row(3, "libz", "disabled", "disabled");
208 #endif
209 }
210 php_info_print_table_end();
211
212 php_info_print_table_start();
213 php_info_print_table_colspan_header(4, "Persistent Handles");
214 php_info_print_table_header(4, "Provider", "Ident", "Used", "Free");
215 {
216 HashTable *ht;
217 HashPosition pos1, pos2;
218 php_http_array_hashkey_t provider = php_http_array_hashkey_init(0), ident = php_http_array_hashkey_init(0);
219 zval **val, **sub, **zused, **zfree;
220
221 if ((ht = php_http_persistent_handle_statall(NULL TSRMLS_CC)) && zend_hash_num_elements(ht)) {
222 FOREACH_HASH_KEYVAL(pos1, ht, provider, val) {
223 if (zend_hash_num_elements(Z_ARRVAL_PP(val))) {
224 FOREACH_KEYVAL(pos2, *val, ident, sub) {
225 if ( SUCCESS == zend_hash_find(Z_ARRVAL_PP(sub), ZEND_STRS("used"), (void *) &zused) &&
226 SUCCESS == zend_hash_find(Z_ARRVAL_PP(sub), ZEND_STRS("free"), (void *) &zfree)) {
227 zval *used = php_http_zsep(IS_STRING, *zused);
228 zval *free = php_http_zsep(IS_STRING, *zfree);
229 php_info_print_table_row(4, provider.str, ident.str, Z_STRVAL_P(used), Z_STRVAL_P(free));
230 zval_ptr_dtor(&used);
231 zval_ptr_dtor(&free);
232 } else {
233 php_info_print_table_row(4, provider.str, ident.str, "0", "0");
234 }
235 }
236 } else {
237 php_info_print_table_row(4, provider.str, "N/A", "0", "0");
238 }
239 }
240 } else {
241 php_info_print_table_row(4, "N/A", "N/A", "0", "0");
242 }
243 if (ht) {
244 zend_hash_destroy(ht);
245 FREE_HASHTABLE(ht);
246 }
247 }
248 php_info_print_table_end();
249
250 DISPLAY_INI_ENTRIES();
251 }
252
253
254 /*
255 * Local variables:
256 * tab-width: 4
257 * c-basic-offset: 4
258 * End:
259 * vim600: noet sw=4 ts=4 fdm=marker
260 * vim<600: noet sw=4 ts=4
261 */
262