- include everything in http.c
authorMichael Wallner <mike@php.net>
Fri, 9 Feb 2007 21:35:50 +0000 (21:35 +0000)
committerMichael Wallner <mike@php.net>
Fri, 9 Feb 2007 21:35:50 +0000 (21:35 +0000)
- make INIT/SHUTDOWN sequences readable again
- improve allowed methods check

http.c
package.xml
php_http_deflatestream_object.h
php_http_filter_api.h
php_http_inflatestream_object.h
php_http_request_datashare_api.h
php_http_request_object.h
php_http_request_pool_api.h
php_http_requestdatashare_object.h
tests/persistent_handles_001.phpt

diff --git a/http.c b/http.c
index 095cc1ebdc04cb6bcdbf532d561f1fc8ea9efa8c..4f4eca39eaaba652ff9fae064acee37f30d57b51 100644 (file)
--- a/http.c
+++ b/http.c
 #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;
        }
        
index 0f559aa28dd39a94c4df8e7b75e1d75cabb8615d..48bf39ee01c7246f4c5a3aa34b101ab67bcb8a14 100644 (file)
@@ -23,15 +23,16 @@ support. Parallel requests are available for PHP 5 and greater.
   </maintainer>
   </maintainers>
  <release>
-  <version>1.5.0RC1</version>
-  <date>2007-02-08</date>
+  <version>1.5.0RC2</version>
+  <date>2007-02-09</date>
   <license>BSD, revised</license>
   <state>beta</state>
-  <notes>+ Added HttpMessage::fromEnv(int type[, string class_name = &quot;HttpMessage&quot;]) (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
+  <notes>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)
   </notes>
   <deps>
    <dep type="php" rel="ge" version="4.3"/>
@@ -42,7 +43,6 @@ support. Parallel requests are available for PHP 5 and greater.
    <configureoption name="with-http-zlib-compression" default="yes" prompt="whether to enable support for gzencoded/deflated message bodies; specify zlib directory"/>
    <configureoption name="with-http-magic-mime" default="no" prompt="whether to enable response content type guessing; specify libmagic directory"/>
    <configureoption name="with-http-shared-deps" default="yes" prompt="whether to depend on extensions which have been built shared"/>
-   <configureoption name="enable-http-persistent-handles" default="no" prompt="whether to enable per-process persistent cURL handles"/>
   </configureoptions>
   <filelist>
    <dir name="docs">
index e3d39248fafb13b8fd5933ed614b90b6f268e283..a49e19ebde63cfd245fb82316aba9c8f20388819 100644 (file)
@@ -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
 
index e94ba4b9b0303f757a72cfddd55f639449fce493..22cda837ed00642869d6d191e230b66048c47d72 100644 (file)
 
 #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
 
 /*
index ae6a2ae83aa13d313372aaeb122a4c17ba6a3b6d..3a090139219e9a09bb9b07afb4eaaba06ca19d8d 100644 (file)
@@ -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
 
index 2d38aaca1343979c8841e7be929131ad351aea64..2b50c443dbc86385c69215dd10ac0ae580c04a9f 100644 (file)
@@ -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
 
index d959a47269c4dc82eeaf70745b5050a70b68c16e..ad7e9c52dc45a29939356f0f20d012f00b384975 100644 (file)
@@ -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"
 
index 34294a97859c46fae5d3af3e2091bc15430ce102..2c066e312fb79b78d17808bd92c4160e7ee4fd33 100644 (file)
@@ -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
 
index 9c0dd370e2ccc1de8505a0f66b43a8911a9a970c..e79427cb9688cbdf3ca948fc9de156e7145dca79 100644 (file)
@@ -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
 
index 45332d97cbe1db07a0f4713032b7caf1e8f1bbb3..a2711a890f5d388d959c5984cf650abae4f160f5 100644 (file)
@@ -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
                 (