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("raphf")
48 ZEND_MOD_REQUIRED("propro")
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_JSON
57 ZEND_MOD_REQUIRED("json")
59 #ifdef PHP_HTTP_HAVE_EVENT
60 ZEND_MOD_CONFLICTS("event")
65 zend_module_entry http_module_entry
= {
66 STANDARD_MODULE_HEADER_EX
,
77 STANDARD_MODULE_PROPERTIES
80 int http_module_number
;
82 static HashTable http_module_classes
;
83 void php_http_register_class(zend_class_entry
*(*get_ce
)(void))
85 zend_hash_next_index_insert(&http_module_classes
, &get_ce
, sizeof(get_ce
), NULL
);
87 static void php_http_registered_classes(php_http_buffer_t
*buf
, unsigned flags
)
90 zend_class_entry
*(**get_ce
)(void);
92 FOREACH_HASH_VAL(pos
, &http_module_classes
, get_ce
) {
93 zend_class_entry
*ce
= (*get_ce
)();
94 if ((flags
&& (ce
->ce_flags
& flags
)) || (!flags
&& !(ce
->ce_flags
& 0x0fff))) {
96 php_http_buffer_appends(buf
, ", ");
98 php_http_buffer_append(buf
, ce
->name
, ce
->name_length
);
101 php_http_buffer_fix(buf
);
104 #if PHP_DEBUG && !HAVE_GCOV
105 void _dpf(int type
, const char *data
, size_t length
)
107 static const char _sym
[] = "><><><";
110 for (fprintf(stderr
, "%c ", _sym
[type
-1]); length
--; data
++) {
111 int ip
= PHP_HTTP_IS_CTYPE(print
, *data
);
112 if (!ip
&& *data
!= '\r' && *data
!= '\n') nwp
= 1;
113 fprintf(stderr
, ip
?"%c":"\\x%02x", (int) (*data
& 0xff));
114 if (!nwp
&& *data
== '\n' && length
) {
115 fprintf(stderr
, "\n%c ", _sym
[type
-1]);
118 fprintf(stderr
, "\n");
120 fprintf(stderr
, "# %.*s\n", (int) length
, data
);
125 static void php_http_globals_init_once(zend_php_http_globals
*G
)
127 memset(G
, 0, sizeof(*G
));
131 static inline void php_http_globals_init(zend_php_http_globals
*G TSRMLS_DC
)
135 static inline void php_http_globals_free(zend_php_http_globals
*G TSRMLS_DC
)
140 #if ZTS && PHP_DEBUG && !HAVE_GCOV
141 zend_php_http_globals
*php_http_globals(void)
149 PHP_HTTP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL
, OnUpdateString
, env
.etag_mode
)
152 PHP_MINIT_FUNCTION(http
)
154 http_module_number
= module_number
;
155 ZEND_INIT_MODULE_GLOBALS(php_http
, php_http_globals_init_once
, NULL
);
156 REGISTER_INI_ENTRIES();
158 zend_hash_init(&http_module_classes
, 0, NULL
, NULL
, 1);
161 || SUCCESS
!= PHP_MINIT_CALL(http_object
)
162 || SUCCESS
!= PHP_MINIT_CALL(http_exception
)
163 || SUCCESS
!= PHP_MINIT_CALL(http_cookie
)
164 || SUCCESS
!= PHP_MINIT_CALL(http_encoding
)
165 || SUCCESS
!= PHP_MINIT_CALL(http_filter
)
166 || SUCCESS
!= PHP_MINIT_CALL(http_header
)
167 || SUCCESS
!= PHP_MINIT_CALL(http_message
)
168 || SUCCESS
!= PHP_MINIT_CALL(http_message_body
)
169 || SUCCESS
!= PHP_MINIT_CALL(http_querystring
)
170 || SUCCESS
!= PHP_MINIT_CALL(http_client
)
171 || SUCCESS
!= PHP_MINIT_CALL(http_client_request
)
172 || SUCCESS
!= PHP_MINIT_CALL(http_client_response
)
173 #if PHP_HTTP_HAVE_CURL
174 || SUCCESS
!= PHP_MINIT_CALL(http_curl
)
175 || SUCCESS
!= PHP_MINIT_CALL(http_client_curl
)
177 || SUCCESS
!= PHP_MINIT_CALL(http_url
)
178 || SUCCESS
!= PHP_MINIT_CALL(http_env
)
179 || SUCCESS
!= PHP_MINIT_CALL(http_env_request
)
180 || SUCCESS
!= PHP_MINIT_CALL(http_env_response
)
181 || SUCCESS
!= PHP_MINIT_CALL(http_params
)
191 PHP_MSHUTDOWN_FUNCTION(http
)
193 UNREGISTER_INI_ENTRIES();
196 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_message
)
197 #if PHP_HTTP_HAVE_CURL
198 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_client_curl
)
199 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_curl
)
201 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_client
)
206 zend_hash_destroy(&http_module_classes
);
211 PHP_RINIT_FUNCTION(http
)
214 || SUCCESS
!= PHP_RINIT_CALL(http_env
)
215 #if PHP_HTTP_HAVE_CURL && PHP_HTTP_HAVE_EVENT
216 || SUCCESS
!= PHP_RINIT_CALL(http_client_curl
)
225 PHP_RSHUTDOWN_FUNCTION(http
)
228 #if PHP_HTTP_HAVE_CURL && PHP_HTTP_HAVE_EVENT
229 || SUCCESS
!= PHP_RSHUTDOWN_CALL(http_client_curl
)
231 || SUCCESS
!= PHP_RSHUTDOWN_CALL(http_env
)
239 PHP_MINFO_FUNCTION(http
)
242 php_http_buffer_t buf
;
244 php_http_buffer_init(&buf
);
246 php_info_print_table_start();
247 php_info_print_table_header(2, "HTTP Support", "enabled");
248 php_info_print_table_row(2, "Extension Version", PHP_HTTP_EXT_VERSION
);
249 php_info_print_table_end();
251 php_info_print_table_start();
252 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
253 php_info_print_table_row(3, "libz", ZLIB_VERSION
, zlibVersion());
254 #if PHP_HTTP_HAVE_CURL
256 curl_version_info_data
*cv
= curl_version_info(CURLVERSION_NOW
);
257 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION
, cv
->version
);
260 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
263 #if PHP_HTTP_HAVE_EVENT
264 php_info_print_table_row(3, "libevent",
265 # ifdef LIBEVENT_VERSION
268 PHP_HTTP_EVENT_VERSION
,
270 event_get_version());
272 php_info_print_table_row(3, "libevent", "disabled", "disabled");
275 #if PHP_HTTP_HAVE_SERF
279 serf_lib_version(&v
[0], &v
[1], &v
[2]);
280 php_http_buffer_appendf(&buf
, "%d.%d.%d", v
[0], v
[1], v
[2]);
281 php_http_buffer_fix(&buf
);
282 php_info_print_table_row(3, "libserf", SERF_VERSION_STRING
, buf
.data
);
283 php_http_buffer_reset(&buf
);
286 php_info_print_table_row(3, "libserf", "disabled", "disabled");
288 php_info_print_table_end();
290 php_info_print_table_start();
291 php_info_print_table_colspan_header(2, "Registered API");
292 for (i
= 0; http_functions
[i
].fname
; ++i
) {
294 php_http_buffer_appends(&buf
, ", ");
296 php_http_buffer_appendl(&buf
, http_functions
[i
].fname
);
298 php_http_buffer_fix(&buf
);
299 php_info_print_table_row(2, "Functions", buf
.data
);
300 php_http_buffer_reset(&buf
);
301 php_http_registered_classes(&buf
, ZEND_ACC_INTERFACE
);
302 php_info_print_table_row(2, "Interfaces", buf
.data
);
303 php_http_buffer_reset(&buf
);
304 php_http_registered_classes(&buf
, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS
);
305 php_info_print_table_row(2, "Abstract Classes", buf
.data
);
306 php_http_buffer_reset(&buf
);
307 php_http_registered_classes(&buf
, 0);
308 php_info_print_table_row(2, "Implemented Classes", buf
.data
);
309 php_http_buffer_reset(&buf
);
310 php_http_registered_classes(&buf
, ZEND_ACC_FINAL_CLASS
);
311 php_info_print_table_row(2, "Final Classes", buf
.data
);
312 php_http_buffer_dtor(&buf
);
314 php_info_print_table_row(2, "Stream Filters", "http.chunked_encode, http.chunked_decode, http.inflate, http.deflate");
315 php_info_print_table_end();
318 DISPLAY_INI_ENTRIES();
327 * vim600: noet sw=4 ts=4 fdm=marker
328 * vim<600: noet sw=4 ts=4