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("spl")
49 #ifdef PHP_HTTP_HAVE_HASH
50 ZEND_MOD_REQUIRED("hash")
52 #ifdef PHP_HTTP_HAVE_ICONV
53 ZEND_MOD_REQUIRED("iconv")
55 #ifdef PHP_HTTP_HAVE_JSON
56 ZEND_MOD_REQUIRED("json")
58 #ifdef PHP_HTTP_HAVE_EVENT
59 ZEND_MOD_CONFLICTS("event")
64 zend_module_entry http_module_entry
= {
65 STANDARD_MODULE_HEADER_EX
,
76 STANDARD_MODULE_PROPERTIES
79 int http_module_number
;
81 static HashTable http_module_classes
;
82 void php_http_register_class(zend_class_entry
*(*get_ce
)(void))
84 zend_hash_next_index_insert(&http_module_classes
, &get_ce
, sizeof(get_ce
), NULL
);
86 static void php_http_registered_classes(php_http_buffer_t
*buf
, unsigned flags
)
89 zend_class_entry
*(**get_ce
)(void);
91 FOREACH_HASH_VAL(pos
, &http_module_classes
, get_ce
) {
92 zend_class_entry
*ce
= (*get_ce
)();
93 if ((flags
&& (ce
->ce_flags
& flags
)) || (!flags
&& !(ce
->ce_flags
& 0x0fff))) {
95 php_http_buffer_appends(buf
, ", ");
97 php_http_buffer_append(buf
, ce
->name
, ce
->name_length
);
100 php_http_buffer_fix(buf
);
103 #if PHP_DEBUG && !HAVE_GCOV
104 void _dpf(int type
, const char *data
, size_t length
)
106 static const char _sym
[] = "><><><";
109 for (fprintf(stderr
, "%c ", _sym
[type
-1]); length
--; data
++) {
110 int ip
= PHP_HTTP_IS_CTYPE(print
, *data
);
111 if (!ip
&& *data
!= '\r' && *data
!= '\n') nwp
= 1;
112 fprintf(stderr
, ip
?"%c":"\\x%02x", (int) (*data
& 0xff));
113 if (!nwp
&& *data
== '\n' && length
) {
114 fprintf(stderr
, "\n%c ", _sym
[type
-1]);
117 fprintf(stderr
, "\n");
119 fprintf(stderr
, "# %.*s\n", (int) length
, data
);
124 static void php_http_globals_init_once(zend_php_http_globals
*G
)
126 memset(G
, 0, sizeof(*G
));
130 static inline void php_http_globals_init(zend_php_http_globals
*G TSRMLS_DC
)
134 static inline void php_http_globals_free(zend_php_http_globals
*G TSRMLS_DC
)
139 #if ZTS && PHP_DEBUG && !HAVE_GCOV
140 zend_php_http_globals
*php_http_globals(void)
148 PHP_HTTP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL
, OnUpdateString
, env
.etag_mode
)
151 PHP_MINIT_FUNCTION(http
)
153 http_module_number
= module_number
;
154 ZEND_INIT_MODULE_GLOBALS(php_http
, php_http_globals_init_once
, NULL
);
155 REGISTER_INI_ENTRIES();
157 zend_hash_init(&http_module_classes
, 0, NULL
, NULL
, 1);
160 || SUCCESS
!= PHP_MINIT_CALL(http_object
)
161 || SUCCESS
!= PHP_MINIT_CALL(http_exception
)
162 || SUCCESS
!= PHP_MINIT_CALL(http_cookie
)
163 || SUCCESS
!= PHP_MINIT_CALL(http_encoding
)
164 || SUCCESS
!= PHP_MINIT_CALL(http_filter
)
165 || SUCCESS
!= PHP_MINIT_CALL(http_header
)
166 || SUCCESS
!= PHP_MINIT_CALL(http_message
)
167 || SUCCESS
!= PHP_MINIT_CALL(http_message_body
)
168 || SUCCESS
!= PHP_MINIT_CALL(http_querystring
)
169 || SUCCESS
!= PHP_MINIT_CALL(http_client_interface
)
170 || SUCCESS
!= PHP_MINIT_CALL(http_client
)
171 || SUCCESS
!= PHP_MINIT_CALL(http_client_request
)
172 || SUCCESS
!= PHP_MINIT_CALL(http_client_response
)
173 || SUCCESS
!= PHP_MINIT_CALL(http_client_datashare
)
174 || SUCCESS
!= PHP_MINIT_CALL(http_client_pool
)
175 || SUCCESS
!= PHP_MINIT_CALL(http_client_factory
)
176 #if PHP_HTTP_HAVE_CURL
177 || SUCCESS
!= PHP_MINIT_CALL(http_curl
)
178 || SUCCESS
!= PHP_MINIT_CALL(http_curl_client
)
179 || SUCCESS
!= PHP_MINIT_CALL(http_curl_client_pool
)
180 || SUCCESS
!= PHP_MINIT_CALL(http_curl_client_datashare
)
182 || SUCCESS
!= PHP_MINIT_CALL(http_url
)
183 || SUCCESS
!= PHP_MINIT_CALL(http_env
)
184 || SUCCESS
!= PHP_MINIT_CALL(http_env_request
)
185 || SUCCESS
!= PHP_MINIT_CALL(http_env_response
)
186 || SUCCESS
!= PHP_MINIT_CALL(http_params
)
196 PHP_MSHUTDOWN_FUNCTION(http
)
198 UNREGISTER_INI_ENTRIES();
201 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_message
)
202 #if PHP_HTTP_HAVE_CURL
203 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_curl_client
)
204 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_curl
)
206 || SUCCESS
!= PHP_MSHUTDOWN_CALL(http_client_factory
)
211 zend_hash_destroy(&http_module_classes
);
216 PHP_RINIT_FUNCTION(http
)
219 || SUCCESS
!= PHP_RINIT_CALL(http_env
)
220 #if PHP_HTTP_HAVE_CURL && PHP_HTTP_HAVE_EVENT
221 || SUCCESS
!= PHP_RINIT_CALL(http_curl_client_pool
)
230 PHP_RSHUTDOWN_FUNCTION(http
)
233 #if PHP_HTTP_HAVE_CURL && PHP_HTTP_HAVE_EVENT
234 || SUCCESS
!= PHP_RSHUTDOWN_CALL(http_curl_client_pool
)
236 || SUCCESS
!= PHP_RSHUTDOWN_CALL(http_env
)
244 PHP_MINFO_FUNCTION(http
)
247 php_http_buffer_t buf
;
249 php_http_buffer_init(&buf
);
251 php_info_print_table_start();
252 php_info_print_table_header(2, "HTTP Support", "enabled");
253 php_info_print_table_row(2, "Extension Version", PHP_HTTP_EXT_VERSION
);
254 php_info_print_table_end();
256 php_info_print_table_start();
257 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
258 php_info_print_table_row(3, "libz", ZLIB_VERSION
, zlibVersion());
259 #if PHP_HTTP_HAVE_CURL
261 curl_version_info_data
*cv
= curl_version_info(CURLVERSION_NOW
);
262 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION
, cv
->version
);
265 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
268 #if PHP_HTTP_HAVE_EVENT
269 php_info_print_table_row(3, "libevent",
270 # ifdef LIBEVENT_VERSION
273 PHP_HTTP_EVENT_VERSION
,
275 event_get_version());
277 php_info_print_table_row(3, "libevent", "disabled", "disabled");
280 #if PHP_HTTP_HAVE_SERF
284 serf_lib_version(&v
[0], &v
[1], &v
[2]);
285 php_http_buffer_appendf(&buf
, "%d.%d.%d", v
[0], v
[1], v
[2]);
286 php_http_buffer_fix(&buf
);
287 php_info_print_table_row(3, "libserf", SERF_VERSION_STRING
, buf
.data
);
288 php_http_buffer_reset(&buf
);
291 php_info_print_table_row(3, "libserf", "disabled", "disabled");
293 php_info_print_table_end();
295 php_info_print_table_start();
296 php_info_print_table_colspan_header(2, "Registered API");
297 for (i
= 0; http_functions
[i
].fname
; ++i
) {
299 php_http_buffer_appends(&buf
, ", ");
301 php_http_buffer_appendl(&buf
, http_functions
[i
].fname
);
303 php_http_buffer_fix(&buf
);
304 php_info_print_table_row(2, "Functions", buf
.data
);
305 php_http_buffer_reset(&buf
);
306 php_http_registered_classes(&buf
, ZEND_ACC_INTERFACE
);
307 php_info_print_table_row(2, "Interfaces", buf
.data
);
308 php_http_buffer_reset(&buf
);
309 php_http_registered_classes(&buf
, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS
);
310 php_info_print_table_row(2, "Abstract Classes", buf
.data
);
311 php_http_buffer_reset(&buf
);
312 php_http_registered_classes(&buf
, 0);
313 php_info_print_table_row(2, "Implemented Classes", buf
.data
);
314 php_http_buffer_reset(&buf
);
315 php_http_registered_classes(&buf
, ZEND_ACC_FINAL_CLASS
);
316 php_info_print_table_row(2, "Final Classes", buf
.data
);
317 php_http_buffer_dtor(&buf
);
319 php_info_print_table_row(2, "Stream Filters", "http.chunked_encode, http.chunked_decode, http.inflate, http.deflate");
320 php_info_print_table_end();
323 DISPLAY_INI_ENTRIES();
332 * vim600: noet sw=4 ts=4 fdm=marker
333 * vim<600: noet sw=4 ts=4