* flush *
[m6w6/ext-http] / http.c
diff --git a/http.c b/http.c
index b214c4c7f9cd856d3e684372f5312eb984cf7b90..7b90bd01d98dc5d6e93f7de1cbdd4bb092d1f6fa 100644 (file)
--- a/http.c
+++ b/http.c
@@ -98,6 +98,7 @@ function_entry http_functions[] = {
        PHP_FE(http_negotiate_language, NULL)
        PHP_FE(http_negotiate_charset, NULL)
        PHP_FE(http_redirect, NULL)
+       PHP_FE(http_throttle, NULL)
        PHP_FE(http_send_status, NULL)
        PHP_FE(http_send_last_modified, NULL)
        PHP_FE(http_send_content_type, NULL)
@@ -120,6 +121,10 @@ function_entry http_functions[] = {
        PHP_FE(http_post_fields, http_request_info_ref_5)
        PHP_FE(http_put_file, http_request_info_ref_4)
        PHP_FE(http_put_stream, http_request_info_ref_4)
+       PHP_FE(http_request_method_register, NULL)
+       PHP_FE(http_request_method_unregister, NULL)
+       PHP_FE(http_request_method_exists, NULL)
+       PHP_FE(http_request_method_name, NULL)
 #endif
        PHP_FE(http_auth_basic, NULL)
        PHP_FE(http_auth_basic_cb, NULL)
@@ -150,54 +155,32 @@ zend_module_entry http_module_entry = {
 };
 /* }}} */
 
+#ifdef HTTP_HAVE_CURL
+#      ifdef HTTP_CURL_USE_ZEND_MM
+static void http_curl_free(void *p)                                    { efree(p); }
+static char *http_curl_strdup(const char *p)           { return estrdup(p); }
+static void *http_curl_malloc(size_t s)                                { return emalloc(s); }
+static void *http_curl_realloc(void *p, size_t s)      { return erealloc(p, s); }
+static void *http_curl_calloc(size_t n, size_t s)      { return ecalloc(n, s); }
+#      endif /* HTTP_CURL_USE_ZEND_MM */
+static void http_curl_freestr(void *s)                         { efree(*(char **)s); }
+#endif /* HTTP_HAVE_CURL */
 
-static void free_to_free(void *s)
-{
-       efree(*(char **)s);
-}
-
-/* {{{ void http_globals_ctor(zend_http_globals *) */
-#define http_globals_ctor _http_globals_ctor
-static inline void _http_globals_ctor(zend_http_globals *http_globals)
+/* {{{ http_globals */
+static inline void http_globals_init(zend_http_globals *G)
 {
-       http_globals->etag_started = 0;
-       http_globals->ctype = NULL;
-       http_globals->etag  = NULL;
-       http_globals->lmod  = 0;
+       memset(G, 0, sizeof(zend_http_globals));
+       G->send.buffer_size = HTTP_SENDBUF_SIZE;
+       zend_hash_init(&G->request.methods.custom, 0, NULL, ZVAL_PTR_DTOR, 0);
 #ifdef HTTP_HAVE_CURL
-#      if LIBCURL_VERSION_NUM < 0x070c00
-       memset(&http_globals->curlerr, 0, sizeof(http_globals->curlerr));
-#      endif
-       zend_llist_init(&http_globals->to_free, sizeof(char *), free_to_free, 0);
+       zend_llist_init(&G->request.curl.copies, sizeof(char *), http_curl_freestr, 0);
 #endif
-       http_globals->allowed_methods = NULL;
-       http_globals->cache_log = NULL;
 }
-/* }}} */
-
-/* {{{ void http_globals_dtor() */
-#define http_globals_dtor() _http_globals_dtor(TSRMLS_C)
-static inline void _http_globals_dtor(TSRMLS_D)
+static inline void http_globals_free(zend_http_globals *G)
 {
-       HTTP_G(etag_started) = 0;
-       HTTP_G(lmod) = 0;
-
-       if (HTTP_G(etag)) {
-               efree(HTTP_G(etag));
-               HTTP_G(etag) = NULL;
-       }
-
-       if (HTTP_G(ctype)) {
-               efree(HTTP_G(ctype));
-               HTTP_G(ctype) = NULL;
-       }
-
-#ifdef HTTP_HAVE_CURL
-#      if LIBCURL_VERSION_NUM < 0x070c00
-       memset(&HTTP_G(curlerr), 0, sizeof(HTTP_G(curlerr)));
-#      endif
-#endif
-
+       STR_FREE(G->send.content_type);
+       STR_FREE(G->send.unquoted_etag);
+       zend_hash_destroy(&G->request.methods.custom);
 }
 /* }}} */
 
@@ -222,28 +205,17 @@ PHP_INI_MH(http_update_allowed_methods)
        return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
 }
 
-#define http_update_cache_log OnUpdateString
-
 PHP_INI_BEGIN()
-       HTTP_INI_ENTRY("http.allowed_methods", HTTP_KNOWN_METHODS, PHP_INI_ALL, allowed_methods)
-       HTTP_INI_ENTRY("http.cache_log", NULL, PHP_INI_ALL, cache_log)
+       HTTP_PHP_INI_ENTRY("http.allowed_methods", NULL, PHP_INI_ALL, http_update_allowed_methods, request.methods.allowed)
+       HTTP_PHP_INI_ENTRY("http.cache_log", NULL, PHP_INI_ALL, OnUpdateString, log.cache)
 PHP_INI_END()
 /* }}} */
 
-/* {{{ HTTP_CURL_USE_ZEND_MM */
-#if defined(HTTP_HAVE_CURL) && defined(HTTP_CURL_USE_ZEND_MM)
-static void http_curl_free(void *p)                                    { efree(p); }
-static char *http_curl_strdup(const char *p)           { return estrdup(p); }
-static void *http_curl_malloc(size_t s)                                { return emalloc(s); }
-static void *http_curl_realloc(void *p, size_t s)      { return erealloc(p, s); }
-static void *http_curl_calloc(size_t n, size_t s)      { return ecalloc(n, s); }
-#endif /* HTTP_HAVE_CURL && HTTP_CURL_USE_ZEND_MM */
-/* }}} */
 
 /* {{{ PHP_MINIT_FUNCTION */
 PHP_MINIT_FUNCTION(http)
 {
-       ZEND_INIT_MODULE_GLOBALS(http, http_globals_ctor, NULL);
+       ZEND_INIT_MODULE_GLOBALS(http, NULL, NULL);
        REGISTER_INI_ENTRIES();
 
 #ifdef HTTP_HAVE_CURL
@@ -260,13 +232,13 @@ PHP_MINIT_FUNCTION(http)
 #endif /* HTTP_HAVE_CURL */
 
 #ifdef ZEND_ENGINE_2
-       http_util_object_init(INIT_FUNC_ARGS_PASSTHRU);
-       http_message_object_init(INIT_FUNC_ARGS_PASSTHRU);
-       http_response_object_init(INIT_FUNC_ARGS_PASSTHRU);
+       http_util_object_init();
+       http_message_object_init();
+       http_response_object_init();
 #      ifdef HTTP_HAVE_CURL
-       http_request_object_init(INIT_FUNC_ARGS_PASSTHRU);
+       http_request_object_init();
 #      endif /* HTTP_HAVE_CURL */
-       http_exception_object_init(INIT_FUNC_ARGS_PASSTHRU);
+       http_exception_object_init();
 #endif /* ZEND_ENGINE_2 */
 
        return SUCCESS;
@@ -287,8 +259,13 @@ PHP_MSHUTDOWN_FUNCTION(http)
 /* {{{ PHP_RINIT_FUNCTION */
 PHP_RINIT_FUNCTION(http)
 {
-       char *allowed_methods = INI_STR("http.allowed_methods");
-       http_check_allowed_methods(allowed_methods, strlen(allowed_methods));
+       char *m;
+
+       if (m = INI_STR("http.allowed_methods")) {
+               http_check_allowed_methods(m, strlen(m));
+       }
+
+       http_globals_init(HTTP_GLOBALS);
        return SUCCESS;
 }
 /* }}} */
@@ -296,7 +273,7 @@ PHP_RINIT_FUNCTION(http)
 /* {{{ PHP_RSHUTDOWN_FUNCTION */
 PHP_RSHUTDOWN_FUNCTION(http)
 {
-       http_globals_dtor();
+       http_globals_free(HTTP_GLOBALS);
        return SUCCESS;
 }
 /* }}} */
@@ -322,19 +299,54 @@ PHP_MINFO_FUNCTION(http)
 #      define HTTP_CURL_AVAIL(CLASS) "libcurl not available"
 #endif
 
-       char full_version_string[1024] = {0};
-       snprintf(full_version_string, 1023, "%s (%s)", HTTP_PEXT_VERSION, HTTP_CURL_VERSION);
+#include "php_http_request_api.h"
 
        php_info_print_table_start();
-       php_info_print_table_row(2, "Extended HTTP support", "enabled");
-       php_info_print_table_row(2, "Extension Version:", full_version_string);
+       {
+               char full_version_string[1024] = {0};
+               snprintf(full_version_string, 1023, "%s (%s)", HTTP_PEXT_VERSION, HTTP_CURL_VERSION);
+
+               php_info_print_table_row(2, "Extended HTTP support:", "enabled");
+               php_info_print_table_row(2, "Extension Version:", full_version_string);
+       }
        php_info_print_table_end();
 
        php_info_print_table_start();
-       php_info_print_table_header(2, "Functionality",            "Availability");
-       php_info_print_table_row(2,    "Miscellaneous Utilities:", HTTP_FUNC_AVAIL("HttpUtil, HttpMessage"));
-       php_info_print_table_row(2,    "Extended HTTP Responses:", HTTP_FUNC_AVAIL("HttpResponse"));
-       php_info_print_table_row(2,    "Extended HTTP Requests:",  HTTP_CURL_AVAIL("HttpRequest"));
+       {
+               unsigned i;
+               zval **custom_method;
+               phpstr *known_request_methods = phpstr_new();
+               phpstr *custom_request_methods = phpstr_new();
+
+               for (i = HTTP_NO_REQUEST_METHOD+1; i < HTTP_MAX_REQUEST_METHOD; ++i) {
+                       phpstr_appendl(known_request_methods, http_request_method_name(i));
+                       phpstr_appends(known_request_methods, ", ");
+               }
+               FOREACH_HASH_VAL(&HTTP_G(request).methods.custom, custom_method) {
+                       phpstr_append(custom_request_methods, Z_STRVAL_PP(custom_method), Z_STRLEN_PP(custom_method));
+                       phpstr_appends(custom_request_methods, ", ");
+               }
+
+               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 Request Methods:", PHPSTR_VAL(known_request_methods));
+               php_info_print_table_row(2, "Custom Request Methods:",
+                       PHPSTR_LEN(custom_request_methods) ? PHPSTR_VAL(custom_request_methods) : "none registered");
+
+               phpstr_free(known_request_methods);
+               phpstr_free(custom_request_methods);
+       }
+       php_info_print_table_end();
+
+       php_info_print_table_start();
+       {
+               php_info_print_table_header(2, "Functionality",            "Availability");
+               php_info_print_table_row(2,    "Miscellaneous Utilities:", HTTP_FUNC_AVAIL("HttpUtil, HttpMessage"));
+               php_info_print_table_row(2,    "Extended HTTP Responses:", HTTP_FUNC_AVAIL("HttpResponse"));
+               php_info_print_table_row(2,    "Extended HTTP Requests:",  HTTP_CURL_AVAIL("HttpRequest"));
+       }
        php_info_print_table_end();
 
        DISPLAY_INI_ENTRIES();