2 +--------------------------------------------------------------------+
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 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
16 #include <ext/standard/info.h>
20 #if PHP_HTTP_HAVE_CURL
21 # include <curl/curl.h>
22 # if PHP_HTTP_HAVE_EVENT
26 #if PHP_HTTP_HAVE_SERF
30 ZEND_DECLARE_MODULE_GLOBALS(php_http
);
32 #ifdef COMPILE_DL_HTTP
36 zend_function_entry http_functions
[] = {
40 PHP_MINIT_FUNCTION(http
);
41 PHP_MSHUTDOWN_FUNCTION(http
);
42 PHP_RINIT_FUNCTION(http
);
43 PHP_RSHUTDOWN_FUNCTION(http
);
44 PHP_MINFO_FUNCTION(http
);
46 static zend_module_dep http_module_deps
[] = {
47 ZEND_MOD_REQUIRED("spl")
48 #ifdef PHP_HTTP_HAVE_HASH
49 ZEND_MOD_REQUIRED("hash")
51 #ifdef PHP_HTTP_HAVE_ICONV
52 ZEND_MOD_REQUIRED("iconv")
54 #ifdef PHP_HTTP_HAVE_EVENT
55 ZEND_MOD_CONFLICTS("event")
60 zend_module_entry http_module_entry
= {
61 STANDARD_MODULE_HEADER_EX
,
72 STANDARD_MODULE_PROPERTIES
75 int http_module_number
;
78 void _dpf(int type
, const char *data
, size_t length
)
80 static const char _sym
[] = "><><><";
83 for (fprintf(stderr
, "%c ", _sym
[type
-1]); length
--; data
++) {
84 int ip
= PHP_HTTP_IS_CTYPE(print
, *data
);
85 if (!ip
&& *data
!= '\r' && *data
!= '\n') nwp
= 1;
86 fprintf(stderr
, ip
?"%c":"\\x%02x", (int) (*data
& 0xff));
87 if (!nwp
&& *data
== '\n' && length
) {
88 fprintf(stderr
, "\n%c ", _sym
[type
-1]);
91 fprintf(stderr
, "\n");
93 fprintf(stderr
, "# %.*s\n", (int) length
, data
);
98 static void php_http_globals_init_once(zend_php_http_globals
*G
)
100 memset(G
, 0, sizeof(*G
));
103 static inline void php_http_globals_init(zend_php_http_globals
*G TSRMLS_DC
)
107 static inline void php_http_globals_free(zend_php_http_globals
*G TSRMLS_DC
)
111 #if defined(ZTS) && defined(PHP_DEBUG)
113 zend_php_http_globals
*php_http_globals(void)
121 PHP_HTTP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL
, OnUpdateString
, env
.etag_mode
)
122 PHP_HTTP_INI_ENTRY("http.persistent_handle.limit", "-1", PHP_INI_SYSTEM
, OnUpdateLong
, persistent_handle
.limit
)
125 PHP_MINIT_FUNCTION(http
)
127 http_module_number
= module_number
;
128 ZEND_INIT_MODULE_GLOBALS(php_http
, php_http_globals_init_once
, NULL
);
129 REGISTER_INI_ENTRIES();
132 || SUCCESS
!= PHP_MINIT_CALL(http_object
)
133 || SUCCESS
!= PHP_MINIT_CALL(http_exception
)
134 || SUCCESS
!= PHP_MINIT_CALL(http_persistent_handle
)
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_message
)
140 || SUCCESS
!= PHP_MINIT_CALL(http_message_body
)
141 || SUCCESS
!= PHP_MINIT_CALL(http_property_proxy
)
142 || SUCCESS
!= PHP_MINIT_CALL(http_querystring
)
143 || SUCCESS
!= PHP_MINIT_CALL(http_client_interface
)
144 || SUCCESS
!= PHP_MINIT_CALL(http_client
)
145 || SUCCESS
!= PHP_MINIT_CALL(http_client_request
)
146 || SUCCESS
!= PHP_MINIT_CALL(http_client_response
)
147 || SUCCESS
!= PHP_MINIT_CALL(http_client_datashare
)
148 || SUCCESS
!= PHP_MINIT_CALL(http_client_pool
)
149 || SUCCESS
!= PHP_MINIT_CALL(http_client_factory
)
150 #if PHP_HTTP_HAVE_CURL
151 || SUCCESS
!= PHP_MINIT_CALL(http_curl
)
153 || SUCCESS
!= PHP_MINIT_CALL(http_curl_client
)
154 || SUCCESS
!= PHP_MINIT_CALL(http_curl_client_pool
)
155 || SUCCESS
!= PHP_MINIT_CALL(http_curl_client_datashare
)
156 || SUCCESS
!= PHP_MINIT_CALL(http_url
)
157 || SUCCESS
!= PHP_MINIT_CALL(http_env
)
158 || SUCCESS
!= PHP_MINIT_CALL(http_env_request
)
159 || SUCCESS
!= PHP_MINIT_CALL(http_env_response
)
160 || SUCCESS
!= PHP_MINIT_CALL(http_params
)
170 PHP_MSHUTDOWN_FUNCTION(http
)
172 UNREGISTER_INI_ENTRIES();
175 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_message
)
176 #if PHP_HTTP_HAVE_CURL
177 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_curl
)
179 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_persistent_handle
)
180 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_client_factory
)
188 PHP_RINIT_FUNCTION(http
)
191 || SUCCESS
!= PHP_RINIT_CALL(http_env
)
192 #if PHP_HTTP_HAVE_CURL && PHP_HTTP_HAVE_EVENT
193 || SUCCESS
!= PHP_RINIT_CALL(http_curl_client_pool
)
202 PHP_RSHUTDOWN_FUNCTION(http
)
205 || SUCCESS
!= PHP_RSHUTDOWN_CALL(http_env
)
213 PHP_MINFO_FUNCTION(http
)
215 php_info_print_table_start();
216 php_info_print_table_header(2, "HTTP Support", "enabled");
217 php_info_print_table_row(2, "Extension Version", PHP_HTTP_EXT_VERSION
);
218 php_info_print_table_end();
220 php_info_print_table_start();
221 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
222 php_info_print_table_row(3, "libz", ZLIB_VERSION
, zlibVersion());
223 #if PHP_HTTP_HAVE_CURL
225 curl_version_info_data
*cv
= curl_version_info(CURLVERSION_NOW
);
226 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION
, cv
->version
);
229 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
232 #if PHP_HTTP_HAVE_EVENT
233 php_info_print_table_row(3, "libevent", PHP_HTTP_EVENT_VERSION
, event_get_version());
235 php_info_print_table_row(3, "libevent", "disabled", "disabled");
238 #if PHP_HTTP_HAVE_SERF
243 serf_lib_version(&v
[0], &v
[1], &v
[2]);
244 slprintf(sl_v
, lenof(sl_v
), "%d.%d.%d", v
[0], v
[1], v
[2]);
245 php_info_print_table_row(3, "libserf", SERF_VERSION_STRING
, sl_v
);
248 php_info_print_table_row(3, "libserf", "disabled", "disabled");
250 php_info_print_table_end();
252 php_info_print_table_start();
253 php_info_print_table_colspan_header(4, "Persistent Handles");
254 php_info_print_table_header(4, "Provider", "Ident", "Used", "Free");
257 HashPosition pos1
, pos2
;
258 php_http_array_hashkey_t provider
= php_http_array_hashkey_init(0), ident
= php_http_array_hashkey_init(0);
259 zval
**val
, **sub
, **zused
, **zfree
;
261 if ((ht
= php_http_persistent_handle_statall(NULL TSRMLS_CC
)) && zend_hash_num_elements(ht
)) {
262 FOREACH_HASH_KEYVAL(pos1
, ht
, provider
, val
) {
263 if (zend_hash_num_elements(Z_ARRVAL_PP(val
))) {
264 FOREACH_KEYVAL(pos2
, *val
, ident
, sub
) {
265 if ( SUCCESS
== zend_hash_find(Z_ARRVAL_PP(sub
), ZEND_STRS("used"), (void *) &zused
) &&
266 SUCCESS
== zend_hash_find(Z_ARRVAL_PP(sub
), ZEND_STRS("free"), (void *) &zfree
)) {
267 zval
*used
= php_http_ztyp(IS_STRING
, *zused
);
268 zval
*free
= php_http_ztyp(IS_STRING
, *zfree
);
269 php_info_print_table_row(4, provider
.str
, ident
.str
, Z_STRVAL_P(used
), Z_STRVAL_P(free
));
270 zval_ptr_dtor(&used
);
271 zval_ptr_dtor(&free
);
273 php_info_print_table_row(4, provider
.str
, ident
.str
, "0", "0");
277 php_info_print_table_row(4, provider
.str
, "N/A", "0", "0");
281 php_info_print_table_row(4, "N/A", "N/A", "0", "0");
284 zend_hash_destroy(ht
);
288 php_info_print_table_end();
290 DISPLAY_INI_ENTRIES();
299 * vim600: noet sw=4 ts=4 fdm=marker
300 * vim<600: noet sw=4 ts=4