- revised request_method api
authorMichael Wallner <mike@php.net>
Thu, 29 Dec 2005 14:28:27 +0000 (14:28 +0000)
committerMichael Wallner <mike@php.net>
Thu, 29 Dec 2005 14:28:27 +0000 (14:28 +0000)
12 files changed:
http.c
http_functions.c
http_request_method_api.c
package.xml
php_http.h
php_http_request_method_api.h
tests/HttpRequest_002.phpt
tests/HttpRequest_004.phpt
tests/HttpRequest_006.phpt
tests/HttpRequest_008.phpt [new file with mode: 0644]
tests/request_gzip.phpt
tests/request_methods.phpt

diff --git a/http.c b/http.c
index c9e693126f2c9839a1e627524b9b4751108575bd..d22499c4a8d3dd35d68b00f2c12c53fdcf86e0bb 100644 (file)
--- a/http.c
+++ b/http.c
@@ -167,7 +167,6 @@ static void http_globals_init_once(zend_http_globals *G)
 static inline void _http_globals_init(zend_http_globals *G TSRMLS_DC)
 {
        G->send.buffer_size = HTTP_SENDBUF_SIZE;
 static inline void _http_globals_init(zend_http_globals *G TSRMLS_DC)
 {
        G->send.buffer_size = HTTP_SENDBUF_SIZE;
-       zend_hash_init(&G->request.methods.custom, 0, NULL, ZVAL_PTR_DTOR, 0);
 }
 
 #define http_globals_free(g) _http_globals_free((g) TSRMLS_CC)
 }
 
 #define http_globals_free(g) _http_globals_free((g) TSRMLS_CC)
@@ -175,7 +174,6 @@ static inline void _http_globals_free(zend_http_globals *G TSRMLS_DC)
 {
        STR_SET(G->send.content_type, NULL);
        STR_SET(G->send.unquoted_etag, NULL);
 {
        STR_SET(G->send.content_type, NULL);
        STR_SET(G->send.unquoted_etag, NULL);
-       zend_hash_destroy(&G->request.methods.custom);
 }
 /* }}} */
 
 }
 /* }}} */
 
@@ -290,11 +288,13 @@ PHP_RINIT_FUNCTION(http)
 
        http_globals_init(HTTP_GLOBALS);
 
 
        http_globals_init(HTTP_GLOBALS);
 
+       if (    (SUCCESS != PHP_RINIT_CALL(http_request_method))
 #ifdef HTTP_HAVE_ZLIB  
 #ifdef HTTP_HAVE_ZLIB  
-       if (SUCCESS != PHP_RINIT_CALL(http_encoding)) {
+               ||      (SUCCESS != PHP_RINIT_CALL(http_encoding))
+#endif
+       ) {
                return FAILURE;
        }
                return FAILURE;
        }
-#endif
        
        return SUCCESS;
 }
        
        return SUCCESS;
 }
@@ -305,14 +305,11 @@ PHP_RSHUTDOWN_FUNCTION(http)
 {
        STATUS status = SUCCESS;
        
 {
        STATUS status = SUCCESS;
        
-       if (
+       if (    (SUCCESS != PHP_RSHUTDOWN_CALL(http_request_method))
 #ifdef HTTP_HAVE_ZLIB
 #ifdef HTTP_HAVE_ZLIB
-               (SUCCESS != PHP_RSHUTDOWN_CALL(http_encoding)) ||
-#endif
-#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
-               (SUCCESS != PHP_RSHUTDOWN_CALL(http_request_method)) ||
+               ||      (SUCCESS != PHP_RSHUTDOWN_CALL(http_encoding))
 #endif
 #endif
-       0) {
+       ) {
                status = FAILURE;
        }
        
                status = FAILURE;
        }
        
@@ -375,19 +372,20 @@ PHP_MINFO_FUNCTION(http)
        php_info_print_table_start();
        php_info_print_table_colspan_header(2, "Request Methods");
        {
        php_info_print_table_start();
        php_info_print_table_colspan_header(2, "Request Methods");
        {
-               unsigned i;
-               HashPosition pos;
-               zval **custom_method;
+               int i;
+               getGlobals(G);
+               struct _entry {char *name; char *cnst;} *entry;
                phpstr *known_request_methods = phpstr_new();
                phpstr *custom_request_methods = phpstr_new();
 
                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) {
+               for (i = HTTP_MIN_REQUEST_METHOD; i < HTTP_MAX_REQUEST_METHOD; ++i) {
                        phpstr_appendl(known_request_methods, http_request_method_name(i));
                        phpstr_appends(known_request_methods, ", ");
                }
                        phpstr_appendl(known_request_methods, http_request_method_name(i));
                        phpstr_appends(known_request_methods, ", ");
                }
-               FOREACH_HASH_VAL(pos, &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, ", ");
+               for (i = 0; i < G->request.methods.custom.count; ++i) {
+                       if ((entry = ((struct _entry **) G->request.methods.custom.entries)[i])) {
+                               phpstr_appendf(custom_request_methods, "%s, ", entry->name);
+                       }
                }
 
                phpstr_append(known_request_methods, PHPSTR_VAL(custom_request_methods), PHPSTR_LEN(custom_request_methods));
                }
 
                phpstr_append(known_request_methods, PHPSTR_VAL(custom_request_methods), PHPSTR_LEN(custom_request_methods));
index 7f7c4d68647ed9b37eae9a95612fe4f3c2a5d507..a1620e6b80f2fec52fcd9a9e5fec8fbfaa5436cf 100644 (file)
@@ -1462,7 +1462,7 @@ PHP_FUNCTION(http_request_method_unregister)
                        if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) {
                                convert_to_long(method);
                        } else {
                        if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) {
                                convert_to_long(method);
                        } else {
-                               ulong mn;
+                               int mn;
                                if (!(mn = http_request_method_exists(1, 0, Z_STRVAL_P(method)))) {
                                        RETURN_FALSE;
                                }
                                if (!(mn = http_request_method_exists(1, 0, Z_STRVAL_P(method)))) {
                                        RETURN_FALSE;
                                }
@@ -1505,7 +1505,7 @@ PHP_FUNCTION(http_request_method_exists)
                                        RETURN_LONG((long) http_request_method_exists(1, 0, Z_STRVAL_P(method)));
                                }
                        case IS_LONG:
                                        RETURN_LONG((long) http_request_method_exists(1, 0, Z_STRVAL_P(method)));
                                }
                        case IS_LONG:
-                               RETURN_LONG((long) http_request_method_exists(0, Z_LVAL_P(method), NULL));
+                               RETURN_LONG((long) http_request_method_exists(0, (int) Z_LVAL_P(method), NULL));
                        default:
                                RETURN_FALSE;
                }
                        default:
                                RETURN_FALSE;
                }
@@ -1530,7 +1530,7 @@ PHP_FUNCTION(http_request_method_name)
                        RETURN_FALSE;
                }
 
                        RETURN_FALSE;
                }
 
-               RETURN_STRING(estrdup(http_request_method_name((ulong) method)), 0);
+               RETURN_STRING(estrdup(http_request_method_name((int) method)), 0);
        }
 }
 /* }}} */
        }
 }
 /* }}} */
index ead74ac57a8043e90e3e73a581a42b06a0941c8c..3480c3be0dad4d453b3975b5f64402c9d846e8c3 100644 (file)
@@ -102,13 +102,25 @@ PHP_MINIT_FUNCTION(http_request_method)
        return SUCCESS;
 }
 
        return SUCCESS;
 }
 
+PHP_RINIT_FUNCTION(http_request_method)
+{
+       HTTP_G(request).methods.custom.entries = ecalloc(1, sizeof(http_request_method_entry *));
+       
+       return SUCCESS;
+}
+
 PHP_RSHUTDOWN_FUNCTION(http_request_method)
 {
 PHP_RSHUTDOWN_FUNCTION(http_request_method)
 {
-       int i, c = zend_hash_num_elements(&HTTP_G(request).methods.custom);
+       int i;
+       getGlobals(G);
+       http_request_method_entry **ptr = G->request.methods.custom.entries;
        
        
-       for (i = 0; i < c; ++i) {
-               http_request_method_unregister(HTTP_MAX_REQUEST_METHOD + i);
+       for (i = 0; i < G->request.methods.custom.count; ++i) {
+               if (ptr[i]) {
+                       http_request_method_unregister(HTTP_CUSTOM_REQUEST_METHOD_START + i);
+               }
        }
        }
+       efree(G->request.methods.custom.entries);
        
        return SUCCESS;
 }
        
        return SUCCESS;
 }
@@ -116,95 +128,139 @@ PHP_RSHUTDOWN_FUNCTION(http_request_method)
 /* {{{ char *http_request_method_name(http_request_method) */
 PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC)
 {
 /* {{{ char *http_request_method_name(http_request_method) */
 PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC)
 {
-       zval **meth;
+       getGlobals(G);
+       http_request_method_entry **ptr = G->request.methods.custom.entries;
 
        if (HTTP_STD_REQUEST_METHOD(m)) {
                return http_request_methods[m];
        }
 
 
        if (HTTP_STD_REQUEST_METHOD(m)) {
                return http_request_methods[m];
        }
 
-       if (SUCCESS == zend_hash_index_find(&HTTP_G(request).methods.custom, HTTP_CUSTOM_REQUEST_METHOD(m), (void **) &meth)) {
-               return Z_STRVAL_PP(meth);
+       if (    (HTTP_CUSTOM_REQUEST_METHOD(m) >= 0) && 
+                       (HTTP_CUSTOM_REQUEST_METHOD(m) < G->request.methods.custom.count) &&
+                       (ptr[HTTP_CUSTOM_REQUEST_METHOD(m)])) {
+               return ptr[HTTP_CUSTOM_REQUEST_METHOD(m)]->name;
        }
 
        return http_request_methods[0];
 }
 /* }}} */
 
        }
 
        return http_request_methods[0];
 }
 /* }}} */
 
-/* {{{ ulong http_request_method_exists(zend_bool, ulong, char *) */
-PHP_HTTP_API ulong _http_request_method_exists(zend_bool by_name, ulong id, const char *name TSRMLS_DC)
+/* {{{ int http_request_method_exists(zend_bool, ulong, char *) */
+PHP_HTTP_API int _http_request_method_exists(zend_bool by_name, http_request_method id, const char *name TSRMLS_DC)
 {
 {
+       int i;
+       getGlobals(G);
+       http_request_method_entry **ptr = G->request.methods.custom.entries;
+       
        if (by_name) {
        if (by_name) {
-               unsigned i;
-
-               for (i = HTTP_NO_REQUEST_METHOD + 1; i < HTTP_MAX_REQUEST_METHOD; ++i) {
-                       if (!strcmp(name, http_request_methods[i])) {
+               for (i = HTTP_MIN_REQUEST_METHOD; i < HTTP_MAX_REQUEST_METHOD; ++i) {
+                       if (!strcasecmp(name, http_request_methods[i])) {
                                return i;
                        }
                }
                                return i;
                        }
                }
-               {
-                       zval **data;
-                       char *key;
-                       ulong idx;
-                       HashPosition pos;
-
-                       FOREACH_HASH_KEYVAL(pos, &HTTP_G(request).methods.custom, key, idx, data) {
-                               if (!strcmp(name, Z_STRVAL_PP(data))) {
-                                       return idx + HTTP_MAX_REQUEST_METHOD;
-                               }
+               for (i = 0; i < G->request.methods.custom.count; ++i) {
+                       if (ptr[i] && !strcasecmp(name, ptr[i]->name)) {
+                               return HTTP_CUSTOM_REQUEST_METHOD_START + i;
                        }
                }
                        }
                }
-               return 0;
-       } else {
-               return HTTP_STD_REQUEST_METHOD(id) || zend_hash_index_exists(&HTTP_G(request).methods.custom, HTTP_CUSTOM_REQUEST_METHOD(id)) ? id : 0;
+       } else if (HTTP_STD_REQUEST_METHOD(id)) {
+               return id;
+       } else if (     (HTTP_CUSTOM_REQUEST_METHOD(id) >= 0) && 
+                               (HTTP_CUSTOM_REQUEST_METHOD(id) < G->request.methods.custom.count) && 
+                               (ptr[HTTP_CUSTOM_REQUEST_METHOD(id)])) {
+               return id;
        }
        }
+       
+       return 0;
 }
 /* }}} */
 
 }
 /* }}} */
 
-/* {{{ ulong http_request_method_register(char *) */
-PHP_HTTP_API ulong _http_request_method_register(const char *method_name, size_t method_name_len TSRMLS_DC)
+/* {{{ int http_request_method_register(char *) */
+PHP_HTTP_API int _http_request_method_register(const char *method_name, int method_name_len TSRMLS_DC)
 {
 {
-       zval array;
-       char *http_method, *method;
-       ulong i, meth_num = HTTP_G(request).methods.custom.nNextFreeElement + HTTP_MAX_REQUEST_METHOD;
-
+       int i, meth_num;
+       char *http_method, *method, *mconst;
+       getGlobals(G);
+       http_request_method_entry **ptr = G->request.methods.custom.entries;
+       
+       if (!isalpha(*method_name)) {
+               http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Request method does not start with a character (%s)", method_name);
+               return 0;
+       }
+       
+       if (http_request_method_exists(1, 0, method_name)) {
+               http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Request method does already exist (%s)", method_name);
+               return 0;
+       }
+       
        method = emalloc(method_name_len + 1);
        method = emalloc(method_name_len + 1);
+       mconst = emalloc(method_name_len + 1);
        for (i = 0; i < method_name_len; ++i) {
        for (i = 0; i < method_name_len; ++i) {
-               method[i] = toupper(method_name[i]);
+               switch (method_name[i])
+               {
+                       case '-':
+                               method[i] = '-';
+                               mconst[i] = '_';
+                       break;
+                       
+                       default:
+                               if (!isalnum(method_name[i])) {
+                                       efree(method);
+                                       efree(mconst);
+                                       http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Request method contains illegal characters (%s)", method_name);
+                                       return 0;
+                               }
+                               mconst[i] = method[i] = toupper(method_name[i]);
+                       break;
+               }
        }
        method[method_name_len] = '\0';
        }
        method[method_name_len] = '\0';
+       mconst[method_name_len] = '\0';
        
        
-       INIT_ZARR(array, &HTTP_G(request).methods.custom);
-       add_next_index_stringl(&array, method, method_name_len, 0);
+       ptr = erealloc(ptr, sizeof(http_request_method_entry *) * (G->request.methods.custom.count + 1));
+       G->request.methods.custom.entries = ptr;
+       ptr[G->request.methods.custom.count] = emalloc(sizeof(http_request_method_entry));
+       ptr[G->request.methods.custom.count]->name = method;
+       ptr[G->request.methods.custom.count]->cnst = mconst;
+       meth_num = HTTP_CUSTOM_REQUEST_METHOD_START + G->request.methods.custom.count++;
 
 
-       method_name_len = spprintf(&http_method, 0, "HTTP_METH_%s", method);
+       method_name_len = spprintf(&http_method, 0, "HTTP_METH_%s", mconst);
        zend_register_long_constant(http_method, method_name_len + 1, meth_num, CONST_CS, http_module_number TSRMLS_CC);
        efree(http_method);
        
 #if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) && !defined(WONKY)
        zend_register_long_constant(http_method, method_name_len + 1, meth_num, CONST_CS, http_module_number TSRMLS_CC);
        efree(http_method);
        
 #if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) && !defined(WONKY)
-       method_name_len = spprintf(&http_method, 0, "METH_%s", method);
+       method_name_len = spprintf(&http_method, 0, "METH_%s", mconst);
        zend_declare_class_constant_long(http_request_object_ce, http_method, method_name_len, meth_num TSRMLS_CC);
        efree(http_method);
 #endif
        zend_declare_class_constant_long(http_request_object_ce, http_method, method_name_len, meth_num TSRMLS_CC);
        efree(http_method);
 #endif
-
+       
        return meth_num;
 }
 /* }}} */
 
        return meth_num;
 }
 /* }}} */
 
-/* {{{ STATUS http_request_method_unregister(usngigned long) */
-PHP_HTTP_API STATUS _http_request_method_unregister(ulong method TSRMLS_DC)
+/* {{{ STATUS http_request_method_unregister(int) */
+PHP_HTTP_API STATUS _http_request_method_unregister(int method TSRMLS_DC)
 {
 {
-       zval **zmethod;
        char *http_method;
        int method_len;
        char *http_method;
        int method_len;
-
-       if (SUCCESS != zend_hash_index_find(&HTTP_G(request).methods.custom, HTTP_CUSTOM_REQUEST_METHOD(method), (void **) &zmethod)) {
-               http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Request method with id %lu does not exist", method);
+       getGlobals(G);
+       http_request_method_entry **ptr = G->request.methods.custom.entries;
+       
+       if (HTTP_STD_REQUEST_METHOD(method)) {
+               http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Standard request methods cannot be unregistered");
                return FAILURE;
        }
 
                return FAILURE;
        }
 
+       if (    (HTTP_CUSTOM_REQUEST_METHOD(method) < 0) ||
+                       (HTTP_CUSTOM_REQUEST_METHOD(method) > G->request.methods.custom.count) ||
+                       (!ptr[HTTP_CUSTOM_REQUEST_METHOD(method)])) {
+               http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Custom request method with id %lu does not exist", method);
+               return FAILURE;
+       }
+       
 #if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) && !defined(WONKY)
 #if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) && !defined(WONKY)
-       method_len = spprintf(&http_method, 0, "METH_%s", Z_STRVAL_PP(zmethod));
-       if ((SUCCESS != zend_hash_del(&http_request_object_ce->constants_table, http_method, method_len + 1))) {
+       method_len = spprintf(&http_method, 0, "METH_%s", ptr[HTTP_CUSTOM_REQUEST_METHOD(method)]->cnst);
+       if (SUCCESS != zend_hash_del(&http_request_object_ce->constants_table, http_method, method_len + 1)) {
                http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Could not unregister request method: HttpRequest::%s", http_method);
                efree(http_method);
                return FAILURE;
                http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Could not unregister request method: HttpRequest::%s", http_method);
                efree(http_method);
                return FAILURE;
@@ -212,15 +268,18 @@ PHP_HTTP_API STATUS _http_request_method_unregister(ulong method TSRMLS_DC)
        efree(http_method);
 #endif
        
        efree(http_method);
 #endif
        
-       method_len = spprintf(&http_method, 0, "HTTP_METH_%s", Z_STRVAL_PP(zmethod));
-       if (    (SUCCESS != zend_hash_index_del(&HTTP_G(request).methods.custom, HTTP_CUSTOM_REQUEST_METHOD(method)))
-               ||      (SUCCESS != zend_hash_del(EG(zend_constants), http_method, method_len + 1))) {
+       method_len = spprintf(&http_method, 0, "HTTP_METH_%s", ptr[HTTP_CUSTOM_REQUEST_METHOD(method)]->cnst);
+       if (SUCCESS != zend_hash_del(EG(zend_constants), http_method, method_len + 1)) {
                http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Could not unregister request method: %s", http_method);
                efree(http_method);
                return FAILURE;
        }
        efree(http_method);
        
                http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Could not unregister request method: %s", http_method);
                efree(http_method);
                return FAILURE;
        }
        efree(http_method);
        
+       efree(ptr[HTTP_CUSTOM_REQUEST_METHOD(method)]->name);
+       efree(ptr[HTTP_CUSTOM_REQUEST_METHOD(method)]->cnst);
+       STR_SET(ptr[HTTP_CUSTOM_REQUEST_METHOD(method)], NULL);
+       
        return SUCCESS;
 }
 /* }}} */
        return SUCCESS;
 }
 /* }}} */
index cfff0816d894930eeb938ab702d7df9e4a538346..1998bc81c7d8bafdca3dcb911ae28002d066d21f 100644 (file)
@@ -15,7 +15,11 @@ It provides powerful request functionality, if built with CURL
 support. Parallel requests are available for PHP-5 and greater.
 
 PHP-5 classes:
 support. Parallel requests are available for PHP-5 and greater.
 
 PHP-5 classes:
-HttpUtil, HttpMessage, HttpRequest, HttpRequestPool; HttpResponse (PHP-5.1)
+HttpUtil, HttpMessage, HttpRequest, HttpRequestPool, 
+HttpDeflateStream, HttpInflateStream
+
+PHP-5.1 classes:
+HttpResponse
  </description>
  <maintainers>
   <maintainer>
  </description>
  <maintainers>
   <maintainer>
@@ -26,30 +30,18 @@ HttpUtil, HttpMessage, HttpRequest, HttpRequestPool; HttpResponse (PHP-5.1)
   </maintainer>
   </maintainers>
  <release>
   </maintainer>
   </maintainers>
  <release>
-  <version>0.20.0</version>
-  <date>2005-12-15</date>
+  <version>0.21.0</version>
+  <date>2005-12-27</date>
   <license>BSD, revised</license>
   <state>beta</state>
   <license>BSD, revised</license>
   <state>beta</state>
-  <notes>! Request functionality requires libcurl &gt;= 7.12.3 now
+  <notes>! Encodings functionality requires libz version 1.2.0.4 or greater
 
 
-+ Added &apos;bodyonly&apos; request option
-+ Added IOCTL callback for cURL
-+ Added ssl_engines array and cookies array to the request info array
-+ Added http_parse_cookie() to parse Set-Cookie headers
++ Added HttpDeflateStream and HttpInflateStream classes
++ Added ob_deflatehandler and ob_inflatehandler
 
 
-- Renamed http_connectcode to connect_code in the request info array
-- Enable &quot;original headers&quot; previously stripped off by the message parser:
-       o X-Original-Transfer-Encoding (Transfer-Encoding)
-       o X-Original-Content-Encoding (Content-Encoding)
-       o X-Original-Content-Length (Content-Length)
-- RequestExceptions thrown by HttpRequestPool::__construct() and send() are
-  now wrapped into the HttpRequestPoolException object&apos;s $exceptionStack property
-- Removed http_compress() and http_uncompress() (http_deflate/inflate ambiguity)
+- Changed HttpRequest properties to be private
 
 
-* Fixed bug which caused GZIP encoded archives to be decoded
-* Fixed bug with DEFLATE encoded response messages
-* Fixed several memory leaks and inconspicuous access violations
-* Fixed some logical errors in the uri builder
+* Fixed a lot of memory corruptions within HttpRequest
   </notes>
   <deps>
    <dep type="php" rel="ge" version="4.3"/>
   </notes>
   <deps>
    <dep type="php" rel="ge" version="4.3"/>
@@ -73,13 +65,13 @@ HttpUtil, HttpMessage, HttpRequest, HttpRequestPool; HttpResponse (PHP-5.1)
     <file role="src" name="phpstr.h"/>
    </dir> <!-- /phpstr -->
    <dir name="tests">
     <file role="src" name="phpstr.h"/>
    </dir> <!-- /phpstr -->
    <dir name="tests">
-    <file role="test" name="abs_uri_001.phpt"/>
-    <file role="test" name="abs_uri_002.phpt"/>
     <file role="test" name="allowed_methods_001.phpt"/>
     <file role="test" name="allowed_methods_001_logging.phpt"/>
     <file role="test" name="allowed_methods_002.phpt"/>
     <file role="test" name="allowed_methods_002_logging.phpt"/>
     <file role="test" name="allowed_methods_001.phpt"/>
     <file role="test" name="allowed_methods_001_logging.phpt"/>
     <file role="test" name="allowed_methods_002.phpt"/>
     <file role="test" name="allowed_methods_002_logging.phpt"/>
-    <file role="test" name="build_uri_001.phpt"/>
+    <file role="test" name="build_url_001.phpt"/>
+    <file role="test" name="build_url_002.phpt"/>
+    <file role="test" name="build_url_003.phpt"/>
     <file role="test" name="chunked_decode_001.phpt"/>
     <file role="test" name="chunked_decode_002.phpt"/>
     <file role="test" name="chunked_decode_003.phpt"/>
     <file role="test" name="chunked_decode_001.phpt"/>
     <file role="test" name="chunked_decode_002.phpt"/>
     <file role="test" name="chunked_decode_003.phpt"/>
@@ -89,6 +81,7 @@ HttpUtil, HttpMessage, HttpRequest, HttpRequestPool; HttpResponse (PHP-5.1)
     <file role="test" name="date_001.phpt"/>
     <file role="test" name="date_002.phpt"/>
     <file role="test" name="encodings.phpt"/>
     <file role="test" name="date_001.phpt"/>
     <file role="test" name="date_002.phpt"/>
     <file role="test" name="encodings.phpt"/>
+    <file role="test" name="encoding_objects_001.phpt"/>
     <file role="test" name="etag_mode_001.phpt"/>
     <file role="test" name="etag_mode_002.phpt"/>
     <file role="test" name="etag_mode_003.phpt"/>
     <file role="test" name="etag_mode_001.phpt"/>
     <file role="test" name="etag_mode_002.phpt"/>
     <file role="test" name="etag_mode_003.phpt"/>
@@ -114,9 +107,11 @@ HttpUtil, HttpMessage, HttpRequest, HttpRequestPool; HttpResponse (PHP-5.1)
     <file role="test" name="HttpRequestPool_002.phpt"/>
     <file role="test" name="HttpRequestPool_003.phpt"/>
     <file role="test" name="HttpRequestPool_004.phpt"/>
     <file role="test" name="HttpRequestPool_002.phpt"/>
     <file role="test" name="HttpRequestPool_003.phpt"/>
     <file role="test" name="HttpRequestPool_004.phpt"/>
+    <file role="test" name="HttpRequestPool_005.phpt"/>
     <file role="test" name="HttpRequest_001.phpt"/>
     <file role="test" name="HttpRequest_002.phpt"/>
     <file role="test" name="HttpRequest_003.phpt"/>
     <file role="test" name="HttpRequest_001.phpt"/>
     <file role="test" name="HttpRequest_002.phpt"/>
     <file role="test" name="HttpRequest_003.phpt"/>
+    <file role="test" name="HttpRequest_004.phpt"/>
     <file role="test" name="HttpResponse_001.phpt"/>
     <file role="test" name="HttpResponse_002.phpt"/>
     <file role="test" name="HttpResponse_003.phpt"/>
     <file role="test" name="HttpResponse_001.phpt"/>
     <file role="test" name="HttpResponse_002.phpt"/>
     <file role="test" name="HttpResponse_003.phpt"/>
@@ -182,11 +177,13 @@ HttpUtil, HttpMessage, HttpRequest, HttpRequestPool; HttpResponse (PHP-5.1)
    <file role="src" name="http_api.c"/>
    <file role="src" name="http_cache_api.c"/>
    <file role="src" name="http_date_api.c"/>
    <file role="src" name="http_api.c"/>
    <file role="src" name="http_cache_api.c"/>
    <file role="src" name="http_date_api.c"/>
+   <file role="src" name="http_deflatestream_object.c"/>
    <file role="src" name="http_encoding_api.c"/>
    <file role="src" name="http_exception_object.c"/>
    <file role="src" name="http_filter_api.c"/>
    <file role="src" name="http_functions.c"/>
    <file role="src" name="http_headers_api.c"/>
    <file role="src" name="http_encoding_api.c"/>
    <file role="src" name="http_exception_object.c"/>
    <file role="src" name="http_filter_api.c"/>
    <file role="src" name="http_functions.c"/>
    <file role="src" name="http_headers_api.c"/>
+   <file role="src" name="http_inflatestream_object.c"/>
    <file role="src" name="http_info_api.c"/>
    <file role="src" name="http_message_api.c"/>
    <file role="src" name="http_message_object.c"/>
    <file role="src" name="http_info_api.c"/>
    <file role="src" name="http_message_api.c"/>
    <file role="src" name="http_message_object.c"/>
@@ -209,10 +206,12 @@ HttpUtil, HttpMessage, HttpRequest, HttpRequestPool; HttpResponse (PHP-5.1)
    <file role="src" name="php_http_api.h"/>
    <file role="src" name="php_http_cache_api.h"/>
    <file role="src" name="php_http_date_api.h"/>
    <file role="src" name="php_http_api.h"/>
    <file role="src" name="php_http_cache_api.h"/>
    <file role="src" name="php_http_date_api.h"/>
+   <file role="src" name="php_http_deflatestream_object.h"/>
    <file role="src" name="php_http_encoding_api.h"/>
    <file role="src" name="php_http_exception_object.h"/>
    <file role="src" name="php_http_filter_api.h"/>
    <file role="src" name="php_http_headers_api.h"/>
    <file role="src" name="php_http_encoding_api.h"/>
    <file role="src" name="php_http_exception_object.h"/>
    <file role="src" name="php_http_filter_api.h"/>
    <file role="src" name="php_http_headers_api.h"/>
+   <file role="src" name="php_http_inflatestream_object.h"/>
    <file role="src" name="php_http_info_api.h"/>
    <file role="src" name="php_http_message_api.h"/>
    <file role="src" name="php_http_message_object.h"/>
    <file role="src" name="php_http_info_api.h"/>
    <file role="src" name="php_http_message_api.h"/>
    <file role="src" name="php_http_message_object.h"/>
index b0a0a149d5e74798854485fcb7c29d7ba1f82004..58f191e35e88b743254756d5d279557f1d08bf14 100644 (file)
@@ -93,7 +93,10 @@ ZEND_BEGIN_MODULE_GLOBALS(http)
        struct _http_globals_request {
                struct _http_globals_request_methods {
                        char *allowed;
        struct _http_globals_request {
                struct _http_globals_request_methods {
                        char *allowed;
-                       HashTable custom;
+                       struct {
+                               int count;
+                               void *entries;
+                       } custom;
                } methods;
        } request;
 
                } methods;
        } request;
 
@@ -115,7 +118,7 @@ ZEND_EXTERN_MODULE_GLOBALS(http);
 #      define HTTP_G(v) (http_globals.v)
 #      define HTTP_GLOBALS (&http_globals)
 #endif
 #      define HTTP_G(v) (http_globals.v)
 #      define HTTP_GLOBALS (&http_globals)
 #endif
-#define getGlobals(G) zend_http_globals *G = HTTP_GLOBALS;
+#define getGlobals(G) zend_http_globals *G = HTTP_GLOBALS
 
 PHP_FUNCTION(http_test);
 PHP_FUNCTION(http_date);
 
 PHP_FUNCTION(http_test);
 PHP_FUNCTION(http_date);
index 88f79d53423c687c1832a42c35cc86d9e51896a8..179e52e6fcea7c1db05acd49d3d268393e97e156 100644 (file)
@@ -51,23 +51,32 @@ typedef enum {
        HTTP_MAX_REQUEST_METHOD = 28
 } http_request_method;
 
        HTTP_MAX_REQUEST_METHOD = 28
 } http_request_method;
 
+#define HTTP_MIN_REQUEST_METHOD (HTTP_NO_REQUEST_METHOD + 1)
+#define HTTP_CUSTOM_REQUEST_METHOD_START HTTP_MAX_REQUEST_METHOD
+
+typedef struct {
+       char *name;
+       char *cnst;
+} http_request_method_entry;
+
 #define HTTP_STD_REQUEST_METHOD(m) ((m > HTTP_NO_REQUEST_METHOD) && (m < HTTP_MAX_REQUEST_METHOD))
 #define HTTP_CUSTOM_REQUEST_METHOD(m) (m - HTTP_MAX_REQUEST_METHOD)
 
 extern PHP_MINIT_FUNCTION(http_request_method);
 #define HTTP_STD_REQUEST_METHOD(m) ((m > HTTP_NO_REQUEST_METHOD) && (m < HTTP_MAX_REQUEST_METHOD))
 #define HTTP_CUSTOM_REQUEST_METHOD(m) (m - HTTP_MAX_REQUEST_METHOD)
 
 extern PHP_MINIT_FUNCTION(http_request_method);
+extern PHP_RINIT_FUNCTION(http_request_method);
 extern PHP_RSHUTDOWN_FUNCTION(http_request_method);
 
 #define http_request_method_name(m) _http_request_method_name((m) TSRMLS_CC)
 PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC);
 
 #define http_request_method_exists(u, l, c) _http_request_method_exists((u), (l), (c) TSRMLS_CC)
 extern PHP_RSHUTDOWN_FUNCTION(http_request_method);
 
 #define http_request_method_name(m) _http_request_method_name((m) TSRMLS_CC)
 PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC);
 
 #define http_request_method_exists(u, l, c) _http_request_method_exists((u), (l), (c) TSRMLS_CC)
-PHP_HTTP_API ulong _http_request_method_exists(zend_bool by_name, ulong id, const char *name TSRMLS_DC);
+PHP_HTTP_API int _http_request_method_exists(zend_bool by_name, http_request_method id, const char *name TSRMLS_DC);
 
 #define http_request_method_register(m, l) _http_request_method_register((m), (l) TSRMLS_CC)
 
 #define http_request_method_register(m, l) _http_request_method_register((m), (l) TSRMLS_CC)
-PHP_HTTP_API ulong _http_request_method_register(const char *method, size_t method_name_len TSRMLS_DC);
+PHP_HTTP_API int _http_request_method_register(const char *method, int method_name_len TSRMLS_DC);
 
 #define http_request_method_unregister(mn) _http_request_method_unregister((mn) TSRMLS_CC)
 
 #define http_request_method_unregister(mn) _http_request_method_unregister((mn) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_request_method_unregister(ulong method TSRMLS_DC);
+PHP_HTTP_API STATUS _http_request_method_unregister(int method TSRMLS_DC);
 
 #endif
 
 
 #endif
 
index 5913f8c6abc62c80c0cf121eab178b12e3c355c8..eca6d021d49c4506532c4682f098c952fcb2edf9 100644 (file)
@@ -78,6 +78,5 @@ Array
         )
 
 )
         )
 
 )
-
 int(200)
 Done
 int(200)
 Done
index f6094bb03580879b78e58890c5541795606c2547..a9ade65320c51f4c359188bbe0349666cb384c15 100644 (file)
@@ -42,7 +42,7 @@ echo "Done\n";
 %sTEST
 
 First Request
 %sTEST
 
 First Request
-string(150) "Array
+string(149) "Array
 (
     [int] => 1
     [dbl] => 3.1415926535898
 (
     [int] => 1
     [dbl] => 3.1415926535898
@@ -50,7 +50,6 @@ string(150) "Array
     [nil] => 
 )
 string(44) "int=1&dbl=3.1415926535898&str=something&nil="
     [nil] => 
 )
 string(44) "int=1&dbl=3.1415926535898&str=something&nil="
-
 "
 array(2) {
   [0]=>
 "
 array(2) {
   [0]=>
@@ -70,7 +69,7 @@ array(2) {
 }
 
 Second Request
 }
 
 Second Request
-string(270) "Array
+string(269) "Array
 (
     [0] => Array
         (
 (
     [0] => Array
         (
@@ -86,7 +85,6 @@ string(270) "Array
 
 )
 string(56) "0[int]=1&0[dbl]=3.1415926535898&1[str]=something&1[nil]="
 
 )
 string(56) "0[int]=1&0[dbl]=3.1415926535898&1[str]=something&1[nil]="
-
 "
 array(2) {
   [0]=>
 "
 array(2) {
   [0]=>
@@ -106,7 +104,7 @@ array(2) {
 }
 
 Third Request
 }
 
 Third Request
-string(287) "Array
+string(286) "Array
 (
     [0] => Array
         (
 (
     [0] => Array
         (
@@ -123,7 +121,6 @@ string(287) "Array
     [x] => X
 )
 string(60) "0[int]=1&0[dbl]=3.1415926535898&1[str]=something&1[nil]=&x=X"
     [x] => X
 )
 string(60) "0[int]=1&0[dbl]=3.1415926535898&1[str]=something&1[nil]=&x=X"
-
 "
 array(2) {
   [0]=>
 "
 array(2) {
   [0]=>
@@ -143,8 +140,7 @@ array(2) {
 }
 
 Fourth Request
 }
 
 Fourth Request
-string(14) "string(0) ""
-
+string(13) "string(0) ""
 "
 array(2) {
   [0]=>
 "
 array(2) {
   [0]=>
index 57eda667f72b906f436a7a0316d49a5f859ad619..5f933b7248a14e5c5fd89eed9d1219586cf5175f 100644 (file)
@@ -39,7 +39,7 @@ object(HttpMessage)#%d (%d) {
     %s
   }
   ["body:protected"]=>
     %s
   }
   ["body:protected"]=>
-  string(310) "string(294) "<?xml version="1.0" encoding="iso-8859-1"?>
+  string(309) "string(294) "<?xml version="1.0" encoding="iso-8859-1"?>
 <methodCall>
 <methodName>testMethod</methodName>
 <params>
 <methodCall>
 <methodName>testMethod</methodName>
 <params>
@@ -58,7 +58,6 @@ object(HttpMessage)#%d (%d) {
 </params>
 </methodCall>
 "
 </params>
 </methodCall>
 "
-
 "
 }
 object(HttpMessage)#%d (%d) {
 "
 }
 object(HttpMessage)#%d (%d) {
@@ -79,7 +78,7 @@ object(HttpMessage)#%d (%d) {
     %s
   }
   ["body:protected"]=>
     %s
   }
   ["body:protected"]=>
-  string(310) "string(294) "<?xml version="1.0" encoding="iso-8859-1"?>
+  string(309) "string(294) "<?xml version="1.0" encoding="iso-8859-1"?>
 <methodCall>
 <methodName>testMethod</methodName>
 <params>
 <methodCall>
 <methodName>testMethod</methodName>
 <params>
@@ -98,7 +97,6 @@ object(HttpMessage)#%d (%d) {
 </params>
 </methodCall>
 "
 </params>
 </methodCall>
 "
-
 "
 }
 object(HttpMessage)#%d (%d) {
 "
 }
 object(HttpMessage)#%d (%d) {
@@ -119,7 +117,7 @@ object(HttpMessage)#%d (%d) {
     %s
   }
   ["body:protected"]=>
     %s
   }
   ["body:protected"]=>
-  string(310) "string(294) "<?xml version="1.0" encoding="iso-8859-1"?>
+  string(309) "string(294) "<?xml version="1.0" encoding="iso-8859-1"?>
 <methodCall>
 <methodName>testMethod</methodName>
 <params>
 <methodCall>
 <methodName>testMethod</methodName>
 <params>
@@ -138,7 +136,6 @@ object(HttpMessage)#%d (%d) {
 </params>
 </methodCall>
 "
 </params>
 </methodCall>
 "
-
 "
 }
 Done
 "
 }
 Done
diff --git a/tests/HttpRequest_008.phpt b/tests/HttpRequest_008.phpt
new file mode 100644 (file)
index 0000000..bcb16ec
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--
+HttpRequest custom request method
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkcls('HttpRequest');
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+HttpRequest::methodRegister('foobar');
+$r = new HttpRequest('http://dev.iworks.at/.print_request.php', HttpRequest::METH_FOOBAR);
+$r->setContentType('text/plain');
+$r->setRawPostData('Yep, this is FOOBAR!');
+var_dump($r->send()->getResponseCode());
+var_dump($r->getRawRequestMessage());
+
+echo "Done\n";
+?>
+--EXPECTF--
+%sTEST
+int(200)
+string(189) "FOOBAR /.print_request.php HTTP/1.1
+User-Agent: %s
+Host: dev.iworks.at
+Accept: */*
+Content-Type: text/plain
+Content-Length: 20
+
+Yep, this is FOOBAR!"
+Done
index c947f62d7cf97b86482cad1efb7ae5fb20449559..6f78eda51a9f228da32ae27ef3ee047ea7627ab5 100644 (file)
@@ -30,20 +30,19 @@ object(stdClass)#%d (%d) {
     ["Vary"]=>
     string(15) "Accept-Encoding"
     ["Content-Length"]=>
     ["Vary"]=>
     string(15) "Accept-Encoding"
     ["Content-Length"]=>
-    string(2) "27"
+    string(2) "26"
     ["Content-Type"]=>
     string(9) "text/html"
     ["X-Original-Content-Encoding"]=>
     string(4) "gzip"
     ["X-Original-Content-Length"]=>
     ["Content-Type"]=>
     string(9) "text/html"
     ["X-Original-Content-Encoding"]=>
     string(4) "gzip"
     ["X-Original-Content-Length"]=>
-    string(2) "52"
+    string(2) "51"
   }
   ["body"]=>
   }
   ["body"]=>
-  string(27) "Array
+  string(26) "Array
 (
     [gzip] => 1
 )
 (
     [gzip] => 1
 )
-
 "
   ["parentMessage"]=>
   NULL
 "
   ["parentMessage"]=>
   NULL
index 6efb865211bb04ccfff766d130b162268873097d..2832c80a0ac5d957df51b72ecbb17aff004ce3ae 100644 (file)
@@ -26,6 +26,7 @@ for ($i = 0; $i < 5; ++$i) {
 }
 
 echo "Done\n";
 }
 
 echo "Done\n";
+?>
 --EXPECTF--
 %sTEST
 int(0)
 --EXPECTF--
 %sTEST
 int(0)