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 #include <curl/curl.h>
19 #ifdef PHP_HTTP_HAVE_EVENT
23 #include <main/php_ini.h>
24 #include <ext/standard/info.h>
25 #include <Zend/zend_extensions.h>
27 ZEND_DECLARE_MODULE_GLOBALS(php_http
);
29 #ifdef COMPILE_DL_HTTP
33 zend_function_entry http_functions
[] = {
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
);
43 static zend_module_dep http_module_deps
[] = {
44 ZEND_MOD_REQUIRED("spl")
45 #ifdef PHP_HTTP_HAVE_HASH
46 ZEND_MOD_REQUIRED("hash")
48 #ifdef PHP_HTTP_HAVE_ICONV
49 ZEND_MOD_REQUIRED("iconv")
51 #ifdef PHP_HTTP_HAVE_EVENT
52 ZEND_MOD_CONFLICTS("event")
57 zend_module_entry http_module_entry
= {
58 STANDARD_MODULE_HEADER_EX
,
69 STANDARD_MODULE_PROPERTIES
72 int http_module_number
;
74 static void php_http_globals_init_once(zend_php_http_globals
*G
)
76 memset(G
, 0, sizeof(*G
));
79 static inline void php_http_globals_init(zend_php_http_globals
*G TSRMLS_DC
)
83 static inline void php_http_globals_free(zend_php_http_globals
*G TSRMLS_DC
)
87 #if defined(ZTS) && defined(PHP_DEBUG)
89 zend_http_globals
*php_http_globals(void)
96 PHP_INI_MH(http_update_persistent_handle_ident
)
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
);
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
)
112 PHP_MINIT_FUNCTION(http
)
114 http_module_number
= module_number
;
115 ZEND_INIT_MODULE_GLOBALS(php_http
, php_http_globals_init_once
, NULL
);
116 REGISTER_INI_ENTRIES();
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
)
144 PHP_MSHUTDOWN_FUNCTION(http
)
146 UNREGISTER_INI_ENTRIES();
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
)
160 PHP_RINIT_FUNCTION(http
)
163 || SUCCESS
!= PHP_RINIT_CALL(http_env
)
164 || SUCCESS
!= PHP_RINIT_CALL(http_request_datashare
)
165 || SUCCESS
!= PHP_RINIT_CALL(http_request_pool
)
173 PHP_RSHUTDOWN_FUNCTION(http
)
176 || SUCCESS
!= PHP_RSHUTDOWN_CALL(http_env
)
177 || SUCCESS
!= PHP_RSHUTDOWN_CALL(http_request_datashare
)
185 PHP_MINFO_FUNCTION(http
)
187 php_info_print_table_start();
189 php_info_print_table_header(2, "HTTP Support", "enabled");
190 php_info_print_table_row(2, "Extension Version", PHP_HTTP_EXT_VERSION
);
192 php_info_print_table_end();
194 php_info_print_table_start();
195 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
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());
203 php_info_print_table_row(3, "libevent", "disabled", "disabled");
205 php_info_print_table_row(3, "libz", "disabled", "disabled");
207 php_info_print_table_end();
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");
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
;
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
);
230 php_info_print_table_row(4, provider
.str
, ident
.str
, "0", "0");
234 php_info_print_table_row(4, provider
.str
, "N/A", "0", "0");
238 php_info_print_table_row(4, "N/A", "N/A", "0", "0");
241 zend_hash_destroy(ht
);
245 php_info_print_table_end();
247 DISPLAY_INI_ENTRIES();
256 * vim600: noet sw=4 ts=4 fdm=marker
257 * vim<600: noet sw=4 ts=4