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-2010, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 /* $Id: http.c 300300 2010-06-09 07:29:35Z mike $ */
18 #ifdef PHP_HTTP_HAVE_CURL
19 # include <curl/curl.h>
20 # ifdef PHP_HTTP_HAVE_EVENT
24 #ifdef PHP_HTTP_HAVE_NEON
25 # include "neon/ne_utils.h"
28 #include <main/php_ini.h>
29 #include <ext/standard/info.h>
30 #include <Zend/zend_extensions.h>
32 ZEND_DECLARE_MODULE_GLOBALS(php_http
);
34 #ifdef COMPILE_DL_HTTP
38 zend_function_entry http_functions
[] = {
42 PHP_MINIT_FUNCTION(http
);
43 PHP_MSHUTDOWN_FUNCTION(http
);
44 PHP_RINIT_FUNCTION(http
);
45 PHP_RSHUTDOWN_FUNCTION(http
);
46 PHP_MINFO_FUNCTION(http
);
48 static zend_module_dep http_module_deps
[] = {
49 ZEND_MOD_REQUIRED("spl")
50 #ifdef PHP_HTTP_HAVE_HASH
51 ZEND_MOD_REQUIRED("hash")
53 #ifdef PHP_HTTP_HAVE_ICONV
54 ZEND_MOD_REQUIRED("iconv")
56 #ifdef PHP_HTTP_HAVE_EVENT
57 ZEND_MOD_CONFLICTS("event")
62 zend_module_entry http_module_entry
= {
63 STANDARD_MODULE_HEADER_EX
,
74 STANDARD_MODULE_PROPERTIES
77 int http_module_number
;
80 void _dpf(int type
, const char *data
, size_t length
)
82 static const char _sym
[] = "><><><";
85 for (fprintf(stderr
, "%c ", _sym
[type
-1]); length
--; data
++) {
86 int ip
= PHP_HTTP_IS_CTYPE(print
, *data
);
87 if (!ip
&& *data
!= '\r' && *data
!= '\n') nwp
= 1;
88 fprintf(stderr
, ip
?"%c":"\\x%02x", (int) (*data
& 0xff));
89 if (!nwp
&& *data
== '\n' && length
) {
90 fprintf(stderr
, "\n%c ", _sym
[type
-1]);
93 fprintf(stderr
, "\n");
95 fprintf(stderr
, "# %.*s\n", (int) length
, data
);
100 static void php_http_globals_init_once(zend_php_http_globals
*G
)
102 memset(G
, 0, sizeof(*G
));
105 static inline void php_http_globals_init(zend_php_http_globals
*G TSRMLS_DC
)
109 static inline void php_http_globals_free(zend_php_http_globals
*G TSRMLS_DC
)
113 #if defined(ZTS) && defined(PHP_DEBUG)
115 zend_php_http_globals
*php_http_globals(void)
123 PHP_HTTP_INI_ENTRY("http.etag.mode", "md5", PHP_INI_ALL
, OnUpdateString
, env
.etag_mode
)
124 PHP_HTTP_INI_ENTRY("http.request_datashare.cookie", "0", PHP_INI_SYSTEM
, OnUpdateBool
, request_datashare
.cookie
)
125 PHP_HTTP_INI_ENTRY("http.request_datashare.dns", "1", PHP_INI_SYSTEM
, OnUpdateBool
, request_datashare
.dns
)
126 PHP_HTTP_INI_ENTRY("http.request_datashare.ssl", "0", PHP_INI_SYSTEM
, OnUpdateBool
, request_datashare
.ssl
)
127 PHP_HTTP_INI_ENTRY("http.request_datashare.connect", "0", PHP_INI_SYSTEM
, OnUpdateBool
, request_datashare
.connect
)
128 PHP_HTTP_INI_ENTRY("http.persistent_handle.limit", "-1", PHP_INI_SYSTEM
, OnUpdateLong
, persistent_handle
.limit
)
131 PHP_MINIT_FUNCTION(http
)
133 http_module_number
= module_number
;
134 ZEND_INIT_MODULE_GLOBALS(php_http
, php_http_globals_init_once
, NULL
);
135 REGISTER_INI_ENTRIES();
138 || SUCCESS
!= PHP_MINIT_CALL(http_object
)
139 || SUCCESS
!= PHP_MINIT_CALL(http_exception
)
140 || SUCCESS
!= PHP_MINIT_CALL(http_persistent_handle
)
141 || SUCCESS
!= PHP_MINIT_CALL(http_cookie
)
142 || SUCCESS
!= PHP_MINIT_CALL(http_encoding
)
143 || SUCCESS
!= PHP_MINIT_CALL(http_filter
)
144 || SUCCESS
!= PHP_MINIT_CALL(http_message
)
145 || SUCCESS
!= PHP_MINIT_CALL(http_message_body
)
146 || SUCCESS
!= PHP_MINIT_CALL(http_property_proxy
)
147 || SUCCESS
!= PHP_MINIT_CALL(http_querystring
)
148 || SUCCESS
!= PHP_MINIT_CALL(http_request_factory
)
149 || SUCCESS
!= PHP_MINIT_CALL(http_request
)
150 || SUCCESS
!= PHP_MINIT_CALL(http_curl
)
151 || SUCCESS
!= PHP_MINIT_CALL(http_neon
)
152 || SUCCESS
!= PHP_MINIT_CALL(http_request_datashare
)
153 || SUCCESS
!= PHP_MINIT_CALL(http_request_method
)
154 || SUCCESS
!= PHP_MINIT_CALL(http_request_pool
)
155 || SUCCESS
!= PHP_MINIT_CALL(http_url
)
156 || SUCCESS
!= PHP_MINIT_CALL(http_env
)
157 || SUCCESS
!= PHP_MINIT_CALL(http_env_response
)
167 PHP_MSHUTDOWN_FUNCTION(http
)
169 UNREGISTER_INI_ENTRIES();
172 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_message
)
173 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_curl
)
174 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_neon
)
175 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_request_datashare
)
176 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_request_factory
)
177 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_persistent_handle
)
185 PHP_RINIT_FUNCTION(http
)
188 || SUCCESS
!= PHP_RINIT_CALL(http_env
)
189 || SUCCESS
!= PHP_RINIT_CALL(http_request_datashare
)
190 || SUCCESS
!= PHP_RINIT_CALL(http_curl
)
198 PHP_RSHUTDOWN_FUNCTION(http
)
201 || SUCCESS
!= PHP_RSHUTDOWN_CALL(http_env
)
202 || SUCCESS
!= PHP_RSHUTDOWN_CALL(http_request_datashare
)
210 PHP_MINFO_FUNCTION(http
)
212 php_info_print_table_start();
213 php_info_print_table_header(2, "HTTP Support", "enabled");
214 php_info_print_table_row(2, "Extension Version", PHP_HTTP_EXT_VERSION
);
215 php_info_print_table_end();
217 php_info_print_table_start();
218 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
219 php_info_print_table_row(3, "libz", ZLIB_VERSION
, zlibVersion());
220 #ifdef PHP_HTTP_HAVE_CURL
222 curl_version_info_data
*cv
= curl_version_info(CURLVERSION_NOW
);
223 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION
, cv
->version
);
226 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
228 #ifdef PHP_HTTP_HAVE_NEON
231 sscanf(ne_version_string(), "neon %15[^ :]", &ne_v
[0]);
232 php_info_print_table_row(3, "libneon", PHP_HTTP_NEON_VERSION
, ne_v
);
235 php_info_print_table_row(3, "libneon", "disabled", "disabled");
238 #ifdef PHP_HTTP_HAVE_EVENT
239 php_info_print_table_row(3, "libevent", PHP_HTTP_EVENT_VERSION
, event_get_version());
241 php_info_print_table_row(3, "libevent", "disabled", "disabled");
243 php_info_print_table_end();
245 php_info_print_table_start();
246 php_info_print_table_colspan_header(4, "Persistent Handles");
247 php_info_print_table_header(4, "Provider", "Ident", "Used", "Free");
250 HashPosition pos1
, pos2
;
251 php_http_array_hashkey_t provider
= php_http_array_hashkey_init(0), ident
= php_http_array_hashkey_init(0);
252 zval
**val
, **sub
, **zused
, **zfree
;
254 if ((ht
= php_http_persistent_handle_statall(NULL TSRMLS_CC
)) && zend_hash_num_elements(ht
)) {
255 FOREACH_HASH_KEYVAL(pos1
, ht
, provider
, val
) {
256 if (zend_hash_num_elements(Z_ARRVAL_PP(val
))) {
257 FOREACH_KEYVAL(pos2
, *val
, ident
, sub
) {
258 if ( SUCCESS
== zend_hash_find(Z_ARRVAL_PP(sub
), ZEND_STRS("used"), (void *) &zused
) &&
259 SUCCESS
== zend_hash_find(Z_ARRVAL_PP(sub
), ZEND_STRS("free"), (void *) &zfree
)) {
260 zval
*used
= php_http_ztyp(IS_STRING
, *zused
);
261 zval
*free
= php_http_ztyp(IS_STRING
, *zfree
);
262 php_info_print_table_row(4, provider
.str
, ident
.str
, Z_STRVAL_P(used
), Z_STRVAL_P(free
));
263 zval_ptr_dtor(&used
);
264 zval_ptr_dtor(&free
);
266 php_info_print_table_row(4, provider
.str
, ident
.str
, "0", "0");
270 php_info_print_table_row(4, provider
.str
, "N/A", "0", "0");
274 php_info_print_table_row(4, "N/A", "N/A", "0", "0");
277 zend_hash_destroy(ht
);
281 php_info_print_table_end();
283 DISPLAY_INI_ENTRIES();
292 * vim600: noet sw=4 ts=4 fdm=marker
293 * vim<600: noet sw=4 ts=4