2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
26 #include "ext/standard/info.h"
29 #include "php_http_std_defs.h"
30 #include "php_http_api.h"
31 #include "php_http_send_api.h"
32 #include "php_http_cache_api.h"
33 #include "php_http_request_method_api.h"
35 # include "php_http_request_api.h"
39 # include "php_http_util_object.h"
40 # include "php_http_message_object.h"
42 # include "php_http_response_object.h"
44 # ifdef HTTP_HAVE_CURL
45 # include "php_http_request_object.h"
46 # include "php_http_requestpool_object.h"
48 # include "php_http_exception_object.h"
52 #include "phpstr/phpstr.h"
56 # include <winsock2.h>
58 # include <curl/curl.h>
60 #ifdef HTTP_HAVE_MHASH
66 ZEND_DECLARE_MODULE_GLOBALS(http
);
67 HTTP_DECLARE_ARG_PASS_INFO();
69 #ifdef COMPILE_DL_HTTP
73 /* {{{ http_functions[] */
74 zend_function_entry http_functions
[] = {
75 PHP_FE(http_test
, NULL
)
76 PHP_FE(http_date
, NULL
)
77 PHP_FE(http_absolute_uri
, NULL
)
78 PHP_FE(http_negotiate_language
, NULL
)
79 PHP_FE(http_negotiate_charset
, NULL
)
80 PHP_FE(http_redirect
, NULL
)
81 PHP_FE(http_throttle
, NULL
)
82 PHP_FE(http_send_status
, NULL
)
83 PHP_FE(http_send_last_modified
, NULL
)
84 PHP_FE(http_send_content_type
, NULL
)
85 PHP_FE(http_send_content_disposition
, NULL
)
86 PHP_FE(http_match_modified
, NULL
)
87 PHP_FE(http_match_etag
, NULL
)
88 PHP_FE(http_cache_last_modified
, NULL
)
89 PHP_FE(http_cache_etag
, NULL
)
90 PHP_FE(http_send_data
, NULL
)
91 PHP_FE(http_send_file
, NULL
)
92 PHP_FE(http_send_stream
, NULL
)
93 PHP_FE(http_chunked_decode
, NULL
)
94 PHP_FE(http_parse_message
, NULL
)
95 PHP_FE(http_parse_headers
, NULL
)
96 PHP_FE(http_get_request_headers
, NULL
)
97 PHP_FE(http_get_request_body
, NULL
)
98 PHP_FE(http_match_request_header
, NULL
)
100 PHP_FE(http_get
, http_arg_pass_ref_3
)
101 PHP_FE(http_head
, http_arg_pass_ref_3
)
102 PHP_FE(http_post_data
, http_arg_pass_ref_4
)
103 PHP_FE(http_post_fields
, http_arg_pass_ref_5
)
104 PHP_FE(http_put_file
, http_arg_pass_ref_4
)
105 PHP_FE(http_put_stream
, http_arg_pass_ref_4
)
107 PHP_FE(http_request_method_register
, NULL
)
108 PHP_FE(http_request_method_unregister
, NULL
)
109 PHP_FE(http_request_method_exists
, NULL
)
110 PHP_FE(http_request_method_name
, NULL
)
111 #ifndef ZEND_ENGINE_2
112 PHP_FE(http_build_query
, NULL
)
114 PHP_FE(ob_etaghandler
, NULL
)
120 /* {{{ http_module_entry */
121 zend_module_entry http_module_entry
= {
122 #if ZEND_MODULE_API_NO >= 20010901
123 STANDARD_MODULE_HEADER
,
132 #if ZEND_MODULE_API_NO >= 20010901
135 STANDARD_MODULE_PROPERTIES
139 int http_module_number
;
141 /* {{{ http_globals */
142 static void http_globals_init_once(zend_http_globals
*G
)
144 memset(G
, 0, sizeof(zend_http_globals
));
147 static inline void http_globals_init(zend_http_globals
*G
)
149 G
->send
.buffer_size
= HTTP_SENDBUF_SIZE
;
150 zend_hash_init(&G
->request
.methods
.custom
, 0, NULL
, ZVAL_PTR_DTOR
, 0);
151 #ifdef HTTP_HAVE_CURL
152 zend_llist_init(&G
->request
.copies
.strings
, sizeof(char *), http_request_data_free_string
, 0);
153 zend_llist_init(&G
->request
.copies
.slists
, sizeof(struct curl_slist
*), http_request_data_free_slist
, 0);
154 zend_llist_init(&G
->request
.copies
.contexts
, sizeof(http_request_callback_ctx
*), http_request_data_free_context
, 0);
155 zend_llist_init(&G
->request
.copies
.convs
, sizeof(http_request_conv
*), http_request_data_free_conv
, 0);
159 static inline void http_globals_free(zend_http_globals
*G
)
161 STR_SET(G
->send
.content_type
, NULL
);
162 STR_SET(G
->send
.unquoted_etag
, NULL
);
163 zend_hash_destroy(&G
->request
.methods
.custom
);
164 #ifdef HTTP_HAVE_CURL
165 zend_llist_clean(&G
->request
.copies
.strings
);
166 zend_llist_clean(&G
->request
.copies
.slists
);
167 zend_llist_clean(&G
->request
.copies
.contexts
);
168 zend_llist_clean(&G
->request
.copies
.convs
);
173 /* {{{ static inline void http_check_allowed_methods(char *, int) */
174 #define http_check_allowed_methods(m, l) _http_check_allowed_methods((m), (l) TSRMLS_CC)
175 static inline void _http_check_allowed_methods(char *methods
, int length TSRMLS_DC
)
177 if (length
&& SG(request_info
).request_method
) {
178 if (SUCCESS
!= http_check_method_ex(SG(request_info
).request_method
, methods
)) {
179 char *header
= emalloc(length
+ sizeof("Allow: "));
180 sprintf(header
, "Allow: %s", methods
);
181 http_exit(405, header
);
188 PHP_INI_MH(http_update_allowed_methods
)
190 http_check_allowed_methods(new_value
, new_value_length
);
191 return OnUpdateString(entry
, new_value
, new_value_length
, mh_arg1
, mh_arg2
, mh_arg3
, stage TSRMLS_CC
);
194 PHP_INI_DISP(http_etag_mode_displayer
)
198 if (type
== ZEND_INI_DISPLAY_ORIG
&& ini_entry
->modified
) {
199 value
= (ini_entry
->orig_value
) ? atoi(ini_entry
->orig_value
) : HTTP_ETAG_MD5
;
200 } else if (ini_entry
->value
) {
201 value
= (ini_entry
->value
[0]) ? atoi(ini_entry
->value
) : HTTP_ETAG_MD5
;
203 value
= HTTP_ETAG_MD5
;
208 case HTTP_ETAG_CRC32
:
209 ZEND_WRITE("HTTP_ETAG_CRC32", lenof("HTTP_ETAG_CRC32"));
213 ZEND_WRITE("HTTP_ETAG_SHA1", lenof("HTTP_ETAG_SHA1"));
217 #ifndef HTTP_HAVE_MHASH
220 ZEND_WRITE("HTTP_ETAG_MD5", lenof("HTTP_ETAG_MD5"));
223 #ifdef HTTP_HAVE_MHASH
226 const char *hash_name
= mhash_get_hash_name_static(value
);
229 ZEND_WRITE("HTTP_ETAG_MD5", lenof("HTTP_ETAG_MD5"));
231 ZEND_WRITE("HTTP_ETAG_MHASH_", lenof("HTTP_ETAG_MHASH_"));
232 ZEND_WRITE(hash_name
, strlen(hash_name
));
240 #ifndef ZEND_ENGINE_2
241 # define OnUpdateLong OnUpdateInt
245 HTTP_PHP_INI_ENTRY("http.allowed_methods", "", PHP_INI_ALL
, http_update_allowed_methods
, request
.methods
.allowed
)
246 HTTP_PHP_INI_ENTRY("http.cache_log", "", PHP_INI_ALL
, OnUpdateString
, log
.cache
)
247 HTTP_PHP_INI_ENTRY("http.redirect_log", "", PHP_INI_ALL
, OnUpdateString
, log
.redirect
)
248 HTTP_PHP_INI_ENTRY("http.allowed_methods_log", "", PHP_INI_ALL
, OnUpdateString
, log
.allowed_methods
)
249 HTTP_PHP_INI_ENTRY("http.composite_log", "", PHP_INI_ALL
, OnUpdateString
, log
.composite
)
251 HTTP_PHP_INI_ENTRY("http.only_exceptions", "0", PHP_INI_ALL
, OnUpdateBool
, only_exceptions
)
253 HTTP_PHP_INI_ENTRY_EX("http.etag_mode", "-2", PHP_INI_ALL
, OnUpdateLong
, http_etag_mode_displayer
, etag
.mode
)
257 /* {{{ PHP_MINIT_FUNCTION */
258 PHP_MINIT_FUNCTION(http
)
260 http_module_number
= module_number
;
262 ZEND_INIT_MODULE_GLOBALS(http
, http_globals_init_once
, NULL
)
264 REGISTER_INI_ENTRIES();
266 if (SUCCESS
!= http_cache_global_init()) {
269 if (SUCCESS
!= http_request_method_global_init()) {
272 #ifdef HTTP_HAVE_CURL
273 if (SUCCESS
!= http_request_global_init()) {
276 #endif /* HTTP_HAVE_CURL */
279 http_util_object_init();
280 http_message_object_init();
282 http_response_object_init();
284 # ifdef HTTP_HAVE_CURL
285 http_request_object_init();
286 http_requestpool_object_init();
287 # endif /* HTTP_HAVE_CURL */
288 http_exception_object_init();
289 #endif /* ZEND_ENGINE_2 */
295 /* {{{ PHP_MSHUTDOWN_FUNCTION */
296 PHP_MSHUTDOWN_FUNCTION(http
)
298 UNREGISTER_INI_ENTRIES();
299 #ifdef HTTP_HAVE_CURL
300 http_request_global_cleanup();
306 /* {{{ PHP_RINIT_FUNCTION */
307 PHP_RINIT_FUNCTION(http
)
311 if (m
= INI_STR("http.allowed_methods")) {
312 http_check_allowed_methods(m
, strlen(m
));
315 http_globals_init(HTTP_GLOBALS
);
320 /* {{{ PHP_RSHUTDOWN_FUNCTION */
321 PHP_RSHUTDOWN_FUNCTION(http
)
323 #if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
324 int i
, c
= zend_hash_num_elements(&HTTP_G(request
).methods
.custom
);
326 for (i
= 0; i
< c
; ++i
) {
327 http_request_method_unregister(HTTP_MAX_REQUEST_METHOD
+ i
);
330 http_globals_free(HTTP_GLOBALS
);
335 /* {{{ PHP_MINFO_FUNCTION */
336 PHP_MINFO_FUNCTION(http
)
338 php_info_print_table_start();
340 php_info_print_table_row(2, "Extended HTTP support", "enabled");
341 php_info_print_table_row(2, "Extension Version", HTTP_PEXT_VERSION
);
342 #ifdef HTTP_HAVE_CURL
343 php_info_print_table_row(2, "cURL HTTP Requests", curl_version());
345 php_info_print_table_row(2, "cURL HTTP Requests", "disabled");
347 #ifdef HTTP_HAVE_MHASH
351 snprintf(mhash_info
, 32, "libmhash/%d", MHASH_API_VERSION
);
352 php_info_print_table_row(2, "mhash ETag Generator", mhash_info
);
355 php_info_print_table_row(2, "mhash ETag Generator", "disabled");
357 #if defined(HTTP_HAVE_MAGIC) && !defined(WONKY)
358 php_info_print_table_row(2, "magic MIME Guessing", "libmagic/unknown");
360 php_info_print_table_row(2, "magic MIME Guessing", "disabled");
362 php_info_print_table_row(2, "Registered Classes",
363 #ifndef ZEND_ENGINE_2
368 # ifdef HTTP_HAVE_CURL
378 php_info_print_table_end();
380 php_info_print_table_start();
381 php_info_print_table_colspan_header(2, "Supported ETag Hash Algorithms");
384 php_info_print_table_row(2, "PHP", "CRC32, MD5, SHA1");
385 #ifdef HTTP_HAVE_MHASH
387 phpstr
*algos
= phpstr_new();
388 int i
, c
= mhash_count();
390 for (i
= 0; i
<= c
; ++i
) {
391 const char *hash
= mhash_get_hash_name_static(i
);
394 phpstr_appendf(algos
, "%s, ", hash
);
398 php_info_print_table_row(2, "MHASH", PHPSTR_VAL(algos
));
402 php_info_print_table_row(2, "MHASH", "not available");
405 php_info_print_table_end();
407 php_info_print_table_start();
408 php_info_print_table_colspan_header(2, "Request Methods");
411 zval
**custom_method
;
412 phpstr
*known_request_methods
= phpstr_new();
413 phpstr
*custom_request_methods
= phpstr_new();
415 for (i
= HTTP_NO_REQUEST_METHOD
+1; i
< HTTP_MAX_REQUEST_METHOD
; ++i
) {
416 phpstr_appendl(known_request_methods
, http_request_method_name(i
));
417 phpstr_appends(known_request_methods
, ", ");
419 FOREACH_HASH_VAL(&HTTP_G(request
).methods
.custom
, custom_method
) {
420 phpstr_append(custom_request_methods
, Z_STRVAL_PP(custom_method
), Z_STRLEN_PP(custom_method
));
421 phpstr_appends(custom_request_methods
, ", ");
424 phpstr_append(known_request_methods
, PHPSTR_VAL(custom_request_methods
), PHPSTR_LEN(custom_request_methods
));
425 phpstr_fix(known_request_methods
);
426 phpstr_fix(custom_request_methods
);
428 php_info_print_table_row(2, "Known", PHPSTR_VAL(known_request_methods
));
429 php_info_print_table_row(2, "Custom",
430 PHPSTR_LEN(custom_request_methods
) ? PHPSTR_VAL(custom_request_methods
) : "none registered");
431 php_info_print_table_row(2, "Allowed", strlen(HTTP_G(request
).methods
.allowed
) ? HTTP_G(request
).methods
.allowed
: "(ANY)");
433 phpstr_free(&known_request_methods
);
434 phpstr_free(&custom_request_methods
);
436 php_info_print_table_end();
438 DISPLAY_INI_ENTRIES();
447 * vim600: noet sw=4 ts=4 fdm=marker
448 * vim<600: noet sw=4 ts=4