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