branch off v1 as R_1_7
[m6w6/ext-http] / http.c
diff --git a/http.c b/http.c
index 4f4eca39eaaba652ff9fae064acee37f30d57b51..76629d32265fe5733d33a73037c6d1923d98992a 100644 (file)
--- a/http.c
+++ b/http.c
@@ -6,7 +6,7 @@
     | modification, are permitted provided that the conditions mentioned |
     | in the accompanying LICENSE file are met.                          |
     +--------------------------------------------------------------------+
-    | Copyright (c) 2004-2007, Michael Wallner <mike@php.net>            |
+    | Copyright (c) 2004-2010, Michael Wallner <mike@php.net>            |
     +--------------------------------------------------------------------+
 */
 
@@ -14,6 +14,7 @@
 
 #define HTTP_WANT_SAPI
 #define HTTP_WANT_CURL
+#define HTTP_WANT_EVENT
 #define HTTP_WANT_ZLIB
 #define HTTP_WANT_MAGIC
 #include "php_http.h"
@@ -65,6 +66,7 @@ zend_function_entry http_functions[] = {
        PHP_FE(http_negotiate_language, http_arg_pass_ref_2)
        PHP_FE(http_negotiate_charset, http_arg_pass_ref_2)
        PHP_FE(http_negotiate_content_type, http_arg_pass_ref_2)
+       PHP_FE(http_negotiate, http_arg_pass_ref_3)
        PHP_FE(http_redirect, NULL)
        PHP_FE(http_throttle, NULL)
        PHP_FE(http_send_status, NULL)
@@ -140,6 +142,9 @@ static zend_module_dep http_module_deps[] = {
 #      ifdef HTTP_HAVE_ICONV
        ZEND_MOD_REQUIRED("iconv")
 #      endif
+#      ifdef HTTP_HAVE_EVENT
+       ZEND_MOD_CONFLICTS("event")
+#endif
        {NULL, NULL, NULL, 0}
 };
 #endif
@@ -160,7 +165,7 @@ zend_module_entry http_module_entry = {
        PHP_RINIT(http),
        PHP_RSHUTDOWN(http),
        PHP_MINFO(http),
-       PHP_EXT_HTTP_VERSION,
+       PHP_HTTP_VERSION,
        STANDARD_MODULE_PROPERTIES
 };
 /* }}} */
@@ -200,6 +205,16 @@ static inline void _http_globals_free(zend_http_globals *G TSRMLS_DC)
                G->server_var = NULL;
        }
 }
+
+#if defined(ZTS) && defined(PHP_DEBUG)
+#if ZTS && PHP_DEBUG
+zend_http_globals *http_globals(void)
+{
+       TSRMLS_FETCH();
+       return HTTP_G;
+}
+#endif
+#endif
 /* }}} */
 
 /* {{{ static inline void http_check_allowed_methods(char *) */
@@ -242,7 +257,7 @@ PHP_INI_BEGIN()
        HTTP_PHP_INI_ENTRY("http.log.allowed_methods", "", PHP_INI_ALL, OnUpdateString, log.allowed_methods)
        HTTP_PHP_INI_ENTRY("http.log.composite", "", PHP_INI_ALL, OnUpdateString, log.composite)
        HTTP_PHP_INI_ENTRY("http.request.methods.allowed", "", PHP_INI_ALL, http_update_allowed_methods, request.methods.allowed)
-       HTTP_PHP_INI_ENTRY("http.request.methods.custom", "", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, request.methods.custom.ini)
+       HTTP_PHP_INI_ENTRY("http.request.methods.custom", "", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, request.methods.custom)
 #if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
        HTTP_PHP_INI_ENTRY("http.request.datashare.cookie", "0", PHP_INI_SYSTEM, OnUpdateBool, request.datashare.cookie)
        HTTP_PHP_INI_ENTRY("http.request.datashare.dns", "1", PHP_INI_SYSTEM, OnUpdateBool, request.datashare.dns)
@@ -329,6 +344,7 @@ PHP_MSHUTDOWN_FUNCTION(http)
                || SUCCESS != PHP_MSHUTDOWN_CALL(http_request_datashare)
 #      endif
 #endif
+               || SUCCESS != PHP_MSHUTDOWN_CALL(http_message_object)
                || SUCCESS != PHP_MSHUTDOWN_CALL(http_persistent_handle) /* last */
        ) {
                return FAILURE;
@@ -353,6 +369,9 @@ PHP_RINIT_FUNCTION(http)
 #endif
 #ifdef HTTP_HAVE_CURL
 #      ifdef ZEND_ENGINE_2
+#              ifdef HTTP_HAVE_EVENT
+               || SUCCESS != PHP_RINIT_CALL(http_request_pool)
+#              endif
                || SUCCESS != PHP_RINIT_CALL(http_request_datashare)
 #      endif
 #endif
@@ -394,8 +413,8 @@ PHP_MINFO_FUNCTION(http)
 {
        php_info_print_table_start();
        {
-               php_info_print_table_row(2, "HTTP Support", "enabled");
-               php_info_print_table_row(2, "Extension Version", PHP_EXT_HTTP_VERSION);
+               php_info_print_table_header(2, "HTTP Support", "enabled");
+               php_info_print_table_row(2, "Extension Version", PHP_HTTP_VERSION);
                php_info_print_table_row(2, "Registered Classes",
 #ifndef ZEND_ENGINE_2
                        "none"
@@ -437,6 +456,11 @@ PHP_MINFO_FUNCTION(http)
 #else
                php_info_print_table_row(2, "libcurl", "disabled", "disabled");
 #endif
+#ifdef HTTP_HAVE_EVENT
+               php_info_print_table_row(3, "libevent", HTTP_EVENT_VERSION, event_get_version());
+#else
+               php_info_print_table_row(3, "libevent", "disabled", "disabled");
+#endif
 #ifdef HTTP_HAVE_ZLIB
                php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
 #else
@@ -465,9 +489,11 @@ PHP_MINFO_FUNCTION(http)
                                        FOREACH_KEYVAL(pos2, *val, ident, sub) {
                                                if (    SUCCESS == zend_hash_find(Z_ARRVAL_PP(sub), ZEND_STRS("used"), (void *) &zused) &&
                                                                SUCCESS == zend_hash_find(Z_ARRVAL_PP(sub), ZEND_STRS("free"), (void *) &zfree)) {
-                                                       convert_to_string(*zused);
-                                                       convert_to_string(*zfree);
-                                                       php_info_print_table_row(4, provider.str, ident.str, Z_STRVAL_PP(zused), Z_STRVAL_PP(zfree));
+                                                       zval *used = http_zsep(IS_STRING, *zused);
+                                                       zval *free = http_zsep(IS_STRING, *zfree);
+                                                       php_info_print_table_row(4, provider.str, ident.str, Z_STRVAL_P(used), Z_STRVAL_P(free));
+                                                       zval_ptr_dtor(&used);
+                                                       zval_ptr_dtor(&free);
                                                } else {
                                                        php_info_print_table_row(4, provider.str, ident.str, "0", "0");
                                                }
@@ -489,31 +515,22 @@ PHP_MINFO_FUNCTION(http)
        php_info_print_table_start();
        php_info_print_table_colspan_header(2, "Request Methods");
        {
-               int i;
-               phpstr *custom_request_methods = phpstr_new();
-               phpstr *known_request_methods = phpstr_from_string(HTTP_KNOWN_METHODS, lenof(HTTP_KNOWN_METHODS));
-               http_request_method_entry **ptr = HTTP_G->request.methods.custom.entries;
-
-               for (i = 0; i < HTTP_G->request.methods.custom.count; ++i) {
-                       if (ptr[i]) {
-                               phpstr_appendf(custom_request_methods, "%s, ", ptr[i]->name);
+               HashPosition pos;
+               phpstr *methods = phpstr_new();
+               char **name;
+               
+               FOREACH_HASH_VAL(pos, &HTTP_G->request.methods.registered, name) {
+                       if (pos->h) {
+                               phpstr_appendf(methods, "%s, ", *name);
                        }
                }
-
-               phpstr_append(known_request_methods, PHPSTR_VAL(custom_request_methods), PHPSTR_LEN(custom_request_methods));
-               phpstr_fix(known_request_methods);
-               phpstr_fix(custom_request_methods);
-
-               php_info_print_table_row(2, "Known", PHPSTR_VAL(known_request_methods));
-               php_info_print_table_row(2, "Custom",
-                       PHPSTR_LEN(custom_request_methods) ? PHPSTR_VAL(custom_request_methods) : "none registered");
-               php_info_print_table_row(2, "Allowed", strlen(HTTP_G->request.methods.allowed) ? HTTP_G->request.methods.allowed : "(ANY)");
-               
-               phpstr_free(&known_request_methods);
-               phpstr_free(&custom_request_methods);
+               phpstr_fix(methods);
+               php_info_print_table_row(2, "Registered", PHPSTR_VAL(methods));
+               php_info_print_table_row(2, "Allowed", *HTTP_G->request.methods.allowed ? HTTP_G->request.methods.allowed : "(ANY)");
+               phpstr_free(&methods);
        }
        php_info_print_table_end();
-
+       
        DISPLAY_INI_ENTRIES();
 }
 /* }}} */