From: Michael Wallner Date: Fri, 9 Feb 2007 21:35:50 +0000 (+0000) Subject: - include everything in http.c X-Git-Tag: RELEASE_1_5_0_RC2~3 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=521fa338cdcf4121b30d6a55663774561f029e32;p=m6w6%2Fext-http - include everything in http.c - make INIT/SHUTDOWN sequences readable again - improve allowed methods check --- diff --git a/http.c b/http.c index 095cc1e..4f4eca3 100644 --- a/http.c +++ b/http.c @@ -23,43 +23,29 @@ #include "zend_extensions.h" #include "php_http_api.h" -#include "php_http_send_api.h" -#include "php_http_cookie_api.h" #include "php_http_cache_api.h" -#include "php_http_send_api.h" +#include "php_http_cookie_api.h" +#include "php_http_encoding_api.h" +#include "php_http_filter_api.h" #include "php_http_message_api.h" #include "php_http_persistent_handle_api.h" +#include "php_http_request_api.h" +#include "php_http_request_datashare_api.h" #include "php_http_request_method_api.h" -#ifdef HTTP_HAVE_CURL -# include "php_http_request_api.h" -# include "php_http_request_pool_api.h" -# include "php_http_request_datashare_api.h" -#endif -#ifdef HTTP_HAVE_ZLIB -# include "php_http_encoding_api.h" -#endif +#include "php_http_request_pool_api.h" +#include "php_http_send_api.h" #include "php_http_url_api.h" -#ifdef ZEND_ENGINE_2 -# include "php_http_filter_api.h" -# include "php_http_util_object.h" -# include "php_http_message_object.h" -# include "php_http_querystring_object.h" -# ifndef WONKY -# include "php_http_response_object.h" -# endif -# ifdef HTTP_HAVE_CURL -# include "php_http_request_object.h" -# include "php_http_requestpool_object.h" -# include "php_http_requestdatashare_object.h" -# endif -# ifdef HTTP_HAVE_ZLIB -# include "php_http_deflatestream_object.h" -# include "php_http_inflatestream_object.h" -# endif -# include "php_http_exception_object.h" -#endif - +#include "php_http_deflatestream_object.h" +#include "php_http_exception_object.h" +#include "php_http_inflatestream_object.h" +#include "php_http_message_object.h" +#include "php_http_querystring_object.h" +#include "php_http_request_object.h" +#include "php_http_requestdatashare_object.h" +#include "php_http_requestpool_object.h" +#include "php_http_response_object.h" +#include "php_http_util_object.h" ZEND_DECLARE_MODULE_GLOBALS(http); HTTP_DECLARE_ARG_PASS_INFO(); @@ -216,14 +202,14 @@ static inline void _http_globals_free(zend_http_globals *G TSRMLS_DC) } /* }}} */ -/* {{{ static inline void http_check_allowed_methods(char *, int) */ -#define http_check_allowed_methods(m, l) _http_check_allowed_methods((m), (l) TSRMLS_CC) -static inline void _http_check_allowed_methods(char *methods, int length TSRMLS_DC) +/* {{{ static inline void http_check_allowed_methods(char *) */ +#define http_check_allowed_methods(m) _http_check_allowed_methods((m) TSRMLS_CC) +static inline void _http_check_allowed_methods(const char *methods TSRMLS_DC) { - if (length && SG(request_info).request_method) { + if (*methods && SG(request_info).request_method) { if (SUCCESS != http_check_method_ex(SG(request_info).request_method, methods)) { - char *header = emalloc(length + sizeof("Allow: ")); - sprintf(header, "Allow: %s", methods); + char *header; + spprintf(&header, 0, "Allow: %s", methods); http_exit(405, header); } } @@ -233,7 +219,9 @@ static inline void _http_check_allowed_methods(char *methods, int length TSRMLS_ /* {{{ PHP_INI */ PHP_INI_MH(http_update_allowed_methods) { - http_check_allowed_methods(new_value, new_value_length); + if (*new_value) { + http_check_allowed_methods(new_value); + } return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); } PHP_INI_MH(http_update_persistent_handle_ident) @@ -281,53 +269,50 @@ PHP_INI_END() PHP_MINIT_FUNCTION(http) { http_module_number = module_number; - - ZEND_INIT_MODULE_GLOBALS(http, http_globals_init_once, NULL) - + ZEND_INIT_MODULE_GLOBALS(http, http_globals_init_once, NULL); REGISTER_INI_ENTRIES(); - if ( (SUCCESS != PHP_MINIT_CALL(http_persistent_handle)) || /* first */ - (SUCCESS != PHP_MINIT_CALL(http_support)) || - (SUCCESS != PHP_MINIT_CALL(http_cookie)) || - (SUCCESS != PHP_MINIT_CALL(http_send)) || - (SUCCESS != PHP_MINIT_CALL(http_url)) || - + if (0 + || SUCCESS != PHP_MINIT_CALL(http_persistent_handle) /* first */ + || SUCCESS != PHP_MINIT_CALL(http_cookie) +#ifdef HTTP_HAVE_ZLIB + || SUCCESS != PHP_MINIT_CALL(http_encoding) +#endif #ifdef HTTP_HAVE_CURL - (SUCCESS != PHP_MINIT_CALL(http_request)) || + || SUCCESS != PHP_MINIT_CALL(http_request) # ifdef ZEND_ENGINE_2 - (SUCCESS != PHP_MINIT_CALL(http_request_pool)) || - (SUCCESS != PHP_MINIT_CALL(http_request_datashare)) || # endif -#endif /* HTTP_HAVE_CURL */ -#ifdef HTTP_HAVE_ZLIB - (SUCCESS != PHP_MINIT_CALL(http_encoding)) || #endif - (SUCCESS != PHP_MINIT_CALL(http_request_method))) { - return FAILURE; - } - + || SUCCESS != PHP_MINIT_CALL(http_request_method) + || SUCCESS != PHP_MINIT_CALL(http_send) + || SUCCESS != PHP_MINIT_CALL(http_support) + || SUCCESS != PHP_MINIT_CALL(http_url) + #ifdef ZEND_ENGINE_2 - if ( (SUCCESS != PHP_MINIT_CALL(http_filter)) || - (SUCCESS != PHP_MINIT_CALL(http_util_object)) || - (SUCCESS != PHP_MINIT_CALL(http_message_object)) || - (SUCCESS != PHP_MINIT_CALL(http_querystring_object))|| -# ifndef WONKY - (SUCCESS != PHP_MINIT_CALL(http_response_object)) || -# endif /* WONKY */ -# ifdef HTTP_HAVE_CURL - (SUCCESS != PHP_MINIT_CALL(http_request_object)) || - (SUCCESS != PHP_MINIT_CALL(http_requestpool_object))|| - (SUCCESS != PHP_MINIT_CALL(http_requestdatashare_object))|| -# endif /* HTTP_HAVE_CURL */ + || SUCCESS != PHP_MINIT_CALL(http_filter) + || SUCCESS != PHP_MINIT_CALL(http_exception_object) # ifdef HTTP_HAVE_ZLIB - (SUCCESS != PHP_MINIT_CALL(http_deflatestream_object)) || - (SUCCESS != PHP_MINIT_CALL(http_inflatestream_object)) || -# endif /* HTTP_HAVE_ZLIB */ - (SUCCESS != PHP_MINIT_CALL(http_exception_object))) { + || SUCCESS != PHP_MINIT_CALL(http_deflatestream_object) + || SUCCESS != PHP_MINIT_CALL(http_inflatestream_object) +# endif + || SUCCESS != PHP_MINIT_CALL(http_message_object) + || SUCCESS != PHP_MINIT_CALL(http_querystring_object) +# ifdef HTTP_HAVE_CURL + || SUCCESS != PHP_MINIT_CALL(http_request_datashare) + || SUCCESS != PHP_MINIT_CALL(http_request_pool) + || SUCCESS != PHP_MINIT_CALL(http_request_object) + || SUCCESS != PHP_MINIT_CALL(http_requestdatashare_object) + || SUCCESS != PHP_MINIT_CALL(http_requestpool_object) +# endif +# ifndef WONKY + || SUCCESS != PHP_MINIT_CALL(http_response_object) +# endif + || SUCCESS != PHP_MINIT_CALL(http_util_object) +#endif + ) { return FAILURE; } -#endif /* ZEND_ENGINE_2 */ - + return SUCCESS; } /* }}} */ @@ -336,17 +321,19 @@ PHP_MINIT_FUNCTION(http) PHP_MSHUTDOWN_FUNCTION(http) { UNREGISTER_INI_ENTRIES(); - if ( + + if (0 #ifdef HTTP_HAVE_CURL + || SUCCESS != PHP_MSHUTDOWN_CALL(http_request) # ifdef ZEND_ENGINE_2 - (SUCCESS != PHP_MSHUTDOWN_CALL(http_request_datashare)) || + || SUCCESS != PHP_MSHUTDOWN_CALL(http_request_datashare) # endif - (SUCCESS != PHP_MSHUTDOWN_CALL(http_request)) || #endif - (SUCCESS != PHP_MSHUTDOWN_CALL(http_persistent_handle)) /* last */ + || SUCCESS != PHP_MSHUTDOWN_CALL(http_persistent_handle) /* last */ ) { return FAILURE; } + return SUCCESS; } /* }}} */ @@ -355,19 +342,21 @@ PHP_MSHUTDOWN_FUNCTION(http) PHP_RINIT_FUNCTION(http) { http_globals_init(HTTP_G); - - if (HTTP_G->request.methods.allowed) { - http_check_allowed_methods(HTTP_G->request.methods.allowed, - strlen(HTTP_G->request.methods.allowed)); + + if (HTTP_G->request.methods.allowed && *HTTP_G->request.methods.allowed) { + http_check_allowed_methods(HTTP_G->request.methods.allowed); } - - if ( (SUCCESS != PHP_RINIT_CALL(http_request_method)) -#ifdef HTTP_HAVE_ZLIB - || (SUCCESS != PHP_RINIT_CALL(http_encoding)) + + if (0 +#ifdef HTTP_HAVE_ZLIB + || SUCCESS != PHP_RINIT_CALL(http_encoding) #endif -#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) - || (SUCCESS != PHP_RINIT_CALL(http_request_datashare)) +#ifdef HTTP_HAVE_CURL +# ifdef ZEND_ENGINE_2 + || SUCCESS != PHP_RINIT_CALL(http_request_datashare) +# endif #endif + || SUCCESS != PHP_RINIT_CALL(http_request_method) ) { return FAILURE; } @@ -381,14 +370,17 @@ PHP_RSHUTDOWN_FUNCTION(http) { STATUS status = SUCCESS; - if ( (SUCCESS != PHP_RSHUTDOWN_CALL(http_request_method)) + if (0 #ifdef HTTP_HAVE_ZLIB - || (SUCCESS != PHP_RSHUTDOWN_CALL(http_encoding)) + || SUCCESS != PHP_RSHUTDOWN_CALL(http_encoding) #endif -#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) - || (SUCCESS != PHP_RSHUTDOWN_CALL(http_request_datashare)) +#ifdef HTTP_HAVE_CURL +# ifdef ZEND_ENGINE_2 + || SUCCESS != PHP_RSHUTDOWN_CALL(http_request_datashare) +# endif #endif - ) { + || SUCCESS != PHP_RSHUTDOWN_CALL(http_request_method) + ) { status = FAILURE; } diff --git a/package.xml b/package.xml index 0f559aa..48bf39e 100644 --- a/package.xml +++ b/package.xml @@ -23,15 +23,16 @@ support. Parallel requests are available for PHP 5 and greater. - 1.5.0RC1 - 2007-02-08 + 1.5.0RC2 + 2007-02-09 BSD, revised beta - + Added HttpMessage::fromEnv(int type[, string class_name = "HttpMessage"]) (Clay Loveless) -+ Added support for per process persistent cURL handles (requested by Clay Loveless): - o Added --enable-http-persistent-handles configure option - o Added http_persistent_handles_count(), http_persistent_handles_clean([string name]), http_persistent_handles_ident([string ident]) - o Added http.persistent.handles.ident INI setting + o Improved new persistent handles functionality + - Removed --enable-http-persistent-handles + + Added http.persistent.handles.limit system INI option which controls + the maximum amount of idle persistent handles kept around; + 0 means every handle is destroyed after usage (i.e. disabled), + -1 means virtually unlimited maximum amount of idle handles (default) @@ -42,7 +43,6 @@ support. Parallel requests are available for PHP 5 and greater. - diff --git a/php_http_deflatestream_object.h b/php_http_deflatestream_object.h index e3d3924..a49e19e 100644 --- a/php_http_deflatestream_object.h +++ b/php_http_deflatestream_object.h @@ -14,7 +14,8 @@ #ifndef PHP_HTTP_DEFLATESTREAM_OBJECT_H #define PHP_HTTP_DEFLATESTREAM_OBJECT_H -#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_ZLIB) +#ifdef HTTP_HAVE_ZLIB +#ifdef ZEND_ENGINE_2 typedef struct _http_deflatestream_object_t { zend_object zo; @@ -41,6 +42,7 @@ PHP_METHOD(HttpDeflateStream, update); PHP_METHOD(HttpDeflateStream, flush); PHP_METHOD(HttpDeflateStream, finish); +#endif #endif #endif diff --git a/php_http_filter_api.h b/php_http_filter_api.h index e94ba4b..22cda83 100644 --- a/php_http_filter_api.h +++ b/php_http_filter_api.h @@ -14,12 +14,12 @@ #ifndef PHP_HTTP_FILTER_API_H #define PHP_HTTP_FILTER_API_H - #ifdef ZEND_ENGINE_2 + extern php_stream_filter_factory http_filter_factory; PHP_MINIT_FUNCTION(http_filter); -#endif +#endif #endif /* diff --git a/php_http_inflatestream_object.h b/php_http_inflatestream_object.h index ae6a2ae..3a09013 100644 --- a/php_http_inflatestream_object.h +++ b/php_http_inflatestream_object.h @@ -14,7 +14,8 @@ #ifndef PHP_HTTP_INFLATESTREAM_OBJECT_H #define PHP_HTTP_INFLATESTREAM_OBJECT_H -#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_ZLIB) +#ifdef HTTP_HAVE_ZLIB +#ifdef ZEND_ENGINE_2 typedef struct _http_inflatestream_object_t { zend_object zo; @@ -41,6 +42,7 @@ PHP_METHOD(HttpInflateStream, update); PHP_METHOD(HttpInflateStream, flush); PHP_METHOD(HttpInflateStream, finish); +#endif #endif #endif diff --git a/php_http_request_datashare_api.h b/php_http_request_datashare_api.h index 2d38aac..2b50c44 100644 --- a/php_http_request_datashare_api.h +++ b/php_http_request_datashare_api.h @@ -15,6 +15,7 @@ #ifndef PHP_HTTP_REQUEST_DATASHARE_API_H #define PHP_HTTP_REQUEST_DATASHARE_API_H #ifdef HTTP_HAVE_CURL +#ifdef ZEND_ENGINE_2 #ifdef ZTS typedef struct _http_request_datashare_lock_t { @@ -72,6 +73,7 @@ PHP_HTTP_API void _http_request_datashare_free(http_request_datashare **share TS PHP_HTTP_API STATUS _http_request_datashare_set(http_request_datashare *share, const char *option, size_t option_len, zend_bool enable TSRMLS_DC); +#endif #endif #endif diff --git a/php_http_request_object.h b/php_http_request_object.h index d959a47..ad7e9c5 100644 --- a/php_http_request_object.h +++ b/php_http_request_object.h @@ -17,6 +17,7 @@ #ifdef HTTP_HAVE_CURL #ifdef ZEND_ENGINE_2 +#include "php_http_request_api.h" #include "php_http_request_pool_api.h" #include "php_http_request_datashare_api.h" diff --git a/php_http_request_pool_api.h b/php_http_request_pool_api.h index 34294a9..2c066e3 100644 --- a/php_http_request_pool_api.h +++ b/php_http_request_pool_api.h @@ -15,6 +15,7 @@ #ifndef PHP_HTTP_REQUEST_POOL_API_H #define PHP_HTTP_REQUEST_POOL_API_H #ifdef HTTP_HAVE_CURL +#ifdef ZEND_ENGINE_2 typedef struct _http_request_pool_t { CURLM *ch; @@ -61,6 +62,7 @@ PHP_HTTP_API int _http_request_pool_perform(http_request_pool *pool TSRMLS_DC); #define http_request_pool_dtor(p) _http_request_pool_dtor((p) TSRMLS_CC) PHP_HTTP_API void _http_request_pool_dtor(http_request_pool *pool TSRMLS_DC); +#endif #endif #endif diff --git a/php_http_requestdatashare_object.h b/php_http_requestdatashare_object.h index 9c0dd37..e79427c 100644 --- a/php_http_requestdatashare_object.h +++ b/php_http_requestdatashare_object.h @@ -14,6 +14,7 @@ #ifndef PHP_HTTP_REQUEST_DATASHARE_OBJECT_H #define PHP_HTTP_REQUEST_DATASHARE_OBJECT_H +#ifdef HTTP_HAVE_CURL #ifdef ZEND_ENGINE_2 typedef struct _http_requestdatashare_object_t { @@ -43,6 +44,7 @@ PHP_METHOD(HttpRequestDataShare, factory); PHP_METHOD(HttpRequestDataShare, singleton); #endif +#endif #endif #endif diff --git a/tests/persistent_handles_001.phpt b/tests/persistent_handles_001.phpt index 45332d9..a2711a8 100644 --- a/tests/persistent_handles_001.phpt +++ b/tests/persistent_handles_001.phpt @@ -56,7 +56,7 @@ stdClass Object ) - [http_request_pool] => Array + [http_request_datashare] => Array ( [GLOBAL] => Array ( @@ -66,7 +66,7 @@ stdClass Object ) - [http_request_datashare] => Array + [http_request_datashare_lock] => Array ( [GLOBAL] => Array ( @@ -76,7 +76,7 @@ stdClass Object ) - [http_request_datashare_lock] => Array + [http_request_pool] => Array ( [GLOBAL] => Array (