- adjust ini entry names to those of the globals struct
authorMichael Wallner <mike@php.net>
Sat, 27 May 2006 11:51:17 +0000 (11:51 +0000)
committerMichael Wallner <mike@php.net>
Sat, 27 May 2006 11:51:17 +0000 (11:51 +0000)
- add http.request.methods.custom ini entry
- fix ini entries with PHP_INI_PERDIR to include PHP_INI_SYSTEM
- add flags argument to http_parse_params()
- add HTTP_PARAMS constants
- fixed http_parse_params("foo,bar") returning "foo" and "ar"
- update changelog

docs/http.ini
http.c
http_api.c
http_cookie_api.c
http_functions.c
http_request_method_api.c
http_util_object.c
package2.xml
php_http.h
php_http_api.h

index 2d96869f03a04f9faf9d97ef995cfa634ad51bca..b3124ff5ee64db91e5ff64a3a1a9735919cf8268 100644 (file)
 ; the hashing algorithm with wich ETags are generated (MD5, SHA1, CRC32B)
 ; if ext/hash is available, this can be set to any hash algorithm ext/hash supports
 ; MD5 is the default and fallback algorithm
-http.etag_mode = "MD5"
+http.etag.mode = "MD5"
 
 ; allowed request methods
 ; by default PHP ignores unkown request methods
 ; PHP will exit with a response status of 405 and an Allow header
 ; if it encounters a request method not contained in the specified list
-;http.allowed_methods = "HEAD, GET, POST"
+;http.request.methods.allowed = "HEAD, GET, POST"
+
+; custom request methods
+;http.request.methods.custom = "KICK, BANN"
 
 ; log file for positive cache hits
-;http.cache_log =
+;http.log.cache =
 
 ; log file for redirects
-;http.redirect_log =
+;http.log.redirect =
 
 ; log file for requests with an unallowed request method
-;http.allowed_methods_log =
+;http.log.allowed_methods =
 
 ; composite log file (i.e. log all messages to this file)
-;http.composite_log =
+;http.log.composite =
 
 ; automatically deflate content if requested/supported by client
-;http.ob_deflate_auto = 1
-;http.ob_deflate_flags = HTTP_DEFLATE_LEVEL_DEF
+;http.send.deflate.start_auto = 1
+;http.send.deflate.start_flags = HTTP_DEFLATE_LEVEL_DEF
 
-; automatically inflate compressed content
-;http.ob_inflate_auto = 0
-;http.ob_inflate_flags =
+; automatically inflate sent content
+;http.send.inflate.start_auto = 0
+;http.send.inflate.start_flags =
diff --git a/http.c b/http.c
index 729d025891237e71dd85c8ae9909a1ef9cfdc165..9eb59b99e600625eb57946d109e65f6d699dd8aa 100644 (file)
--- a/http.c
+++ b/http.c
@@ -224,22 +224,23 @@ PHP_INI_MH(http_update_allowed_methods)
 #endif
 
 PHP_INI_BEGIN()
-       HTTP_PHP_INI_ENTRY("http.allowed_methods", "", PHP_INI_ALL, http_update_allowed_methods, request.methods.allowed)
-       HTTP_PHP_INI_ENTRY("http.cache_log", "", PHP_INI_ALL, OnUpdateString, log.cache)
-       HTTP_PHP_INI_ENTRY("http.redirect_log", "", PHP_INI_ALL, OnUpdateString, log.redirect)
-       HTTP_PHP_INI_ENTRY("http.allowed_methods_log", "", PHP_INI_ALL, OnUpdateString, log.allowed_methods)
-       HTTP_PHP_INI_ENTRY("http.composite_log", "", PHP_INI_ALL, OnUpdateString, log.composite)
-       HTTP_PHP_INI_ENTRY("http.etag_mode", "MD5", PHP_INI_ALL, OnUpdateString, etag.mode)
+       HTTP_PHP_INI_ENTRY("http.etag.mode", "MD5", PHP_INI_ALL, OnUpdateString, etag.mode)
+       HTTP_PHP_INI_ENTRY("http.log.cache", "", PHP_INI_ALL, OnUpdateString, log.cache)
+       HTTP_PHP_INI_ENTRY("http.log.redirect", "", PHP_INI_ALL, OnUpdateString, log.redirect)
+       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)
+#ifdef HTTP_HAVE_ZLIB
+       HTTP_PHP_INI_ENTRY("http.send.inflate.start_auto", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, send.inflate.start_auto)
+       HTTP_PHP_INI_ENTRY("http.send.inflate.start_flags", "0", PHP_INI_ALL, OnUpdateLong, send.inflate.start_flags)
+       HTTP_PHP_INI_ENTRY("http.send.deflate.start_auto", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, send.deflate.start_auto)
+       HTTP_PHP_INI_ENTRY("http.send.deflate.start_flags", "0", PHP_INI_ALL, OnUpdateLong, send.deflate.start_flags)
+#endif
 #ifdef ZEND_ENGINE_2
        HTTP_PHP_INI_ENTRY("http.only_exceptions", "0", PHP_INI_ALL, OnUpdateBool, only_exceptions)
 #endif
        HTTP_PHP_INI_ENTRY("http.force_exit", "1", PHP_INI_ALL, OnUpdateBool, force_exit)
-#ifdef HTTP_HAVE_ZLIB
-       HTTP_PHP_INI_ENTRY("http.ob_inflate_auto", "0", PHP_INI_PERDIR, OnUpdateBool, send.inflate.start_auto)
-       HTTP_PHP_INI_ENTRY("http.ob_inflate_flags", "0", PHP_INI_ALL, OnUpdateLong, send.inflate.start_flags)
-       HTTP_PHP_INI_ENTRY("http.ob_deflate_auto", "0", PHP_INI_PERDIR, OnUpdateBool, send.deflate.start_auto)
-       HTTP_PHP_INI_ENTRY("http.ob_deflate_flags", "0", PHP_INI_ALL, OnUpdateLong, send.deflate.start_flags)
-#endif
 PHP_INI_END()
 /* }}} */
 
index 4744a827f32fffd80e88d3824bfada3f081621f4..22542083ee1e88b3a01bbbe46909ae644f1dc281 100644 (file)
@@ -33,6 +33,11 @@ PHP_MINIT_FUNCTION(http_support)
        HTTP_LONG_CONSTANT("HTTP_SUPPORT_ENCODINGS", HTTP_SUPPORT_ENCODINGS);
        HTTP_LONG_CONSTANT("HTTP_SUPPORT_SSLREQUESTS", HTTP_SUPPORT_SSLREQUESTS);
        
+       HTTP_LONG_CONSTANT("HTTP_PARAMS_ALLOW_COMMA", HTTP_PARAMS_ALLOW_COMMA);
+       HTTP_LONG_CONSTANT("HTTP_PARAMS_ALLOW_FAILURE", HTTP_PARAMS_ALLOW_FAILURE);
+       HTTP_LONG_CONSTANT("HTTP_PARAMS_RAISE_ERROR", HTTP_PARAMS_RAISE_ERROR);
+       HTTP_LONG_CONSTANT("HTTP_PARAMS_DEFAULT", HTTP_PARAMS_DEFAULT);
+       
        return SUCCESS;
 }
 
@@ -316,7 +321,7 @@ PHP_HTTP_API void _http_parse_params_default_callback(void *arg, const char *key
 /* }}} */
 
 /* {{{ STATUS http_parse_params(const char *, HashTable *) */
-PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int allow_comma_sep, http_parse_params_callback cb, void *cb_arg TSRMLS_DC)
+PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int flags, http_parse_params_callback cb, void *cb_arg TSRMLS_DC)
 {
 #define ST_QUOTE       1
 #define ST_VALUE       2
@@ -357,10 +362,11 @@ PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int allow_comma_sep
                                                st == ST_ASSIGN ? "ASSIGN" :
                                                st == ST_ADD ? "ADD":
                                                "HUH?"
-                               ), *c, tk, tv
+                               ), *c?*c:'0', tk, tv
                );
                STR_FREE(tk); STR_FREE(tv);
 #endif
+       continued:
                switch (st) {
                        case ST_QUOTE:
                        quote:
@@ -397,7 +403,10 @@ PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int allow_comma_sep
                                        case '\0':
                                                goto add;
                                                break;
-                                       
+                                       case ',':
+                                               if (flags & HTTP_PARAMS_ALLOW_COMMA) {
+                                                       goto add;
+                                               }
                                        default:
                                                if (!val) {
                                                        val = c;
@@ -409,7 +418,7 @@ PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int allow_comma_sep
                        case ST_KEY:
                                switch (*c) {
                                        case ',':
-                                               if (allow_comma_sep) {
+                                               if (flags & HTTP_PARAMS_ALLOW_COMMA) {
                                                        goto allow_comma;
                                                }
                                        case '\r':
@@ -440,7 +449,7 @@ PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int allow_comma_sep
                                        case '\0':
                                        allow_comma:
                                                if (key) {
-                                                       keylen = c - key;
+                                                       keylen = c-- - key;
                                                        st = ST_ADD;
                                                }
                                                break;
@@ -456,7 +465,7 @@ PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int allow_comma_sep
                        case ST_ASSIGN:
                                if (*c == '=') {
                                        st = ST_VALUE;
-                               } else if (!*c || *c == ';') {
+                               } else if (!*c || *c == ';' || ((flags & HTTP_PARAMS_ALLOW_COMMA) && *c == ',')) {
                                        st = ST_ADD;
                                } else if (*c != ' ') {
                                        goto failure;
@@ -482,7 +491,6 @@ PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int allow_comma_sep
                                keylen = vallen = 0;
                                break;
                }
-               
                if (*c) {
                        ++c;
                } else if (st == ST_ADD) {
@@ -496,7 +504,14 @@ PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int allow_comma_sep
        return SUCCESS;
        
 failure:
-       http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Unexpected character (%c) at pos %tu of %zu", *c, c-s, strlen(s));
+       if (flags & HTTP_PARAMS_RAISE_ERROR) {
+               http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Unexpected character (%c) at pos %tu of %zu", *c, c-s, strlen(s));
+       }
+       if (flags & HTTP_PARAMS_ALLOW_FAILURE) {
+               --c;
+               st = ST_ADD;
+               goto continued;
+       }
        efree(s);
        return FAILURE;
 }
index 7d10ba5c524f05835d06d8824e329a68645d50b3..1ad997a63f377718f6108acdeb21760c166c9b87 100644 (file)
@@ -153,7 +153,7 @@ PHP_HTTP_API http_cookie_list *_http_parse_cookie_ex(http_cookie_list *list, con
        arg.flags = flags;
        arg.allowed_extras = allowed_extras;
        
-       if (SUCCESS != http_parse_params_ex(string, 0, http_parse_cookie_callback, &arg)) {
+       if (SUCCESS != http_parse_params_ex(string, HTTP_PARAMS_RAISE_ERROR, http_parse_cookie_callback, &arg)) {
                if (free_list) {
                        http_cookie_list_free(&list);
                } else {
index 807b0a527cb94ae2f3bfeff483bf066b6eb08d7c..e894b19ebe4ec892a94e3fb7fab5f0c1533c5b5b 100644 (file)
@@ -1089,7 +1089,7 @@ PHP_FUNCTION(http_parse_cookie)
        }
 }
 
-/* {{{ proto object http_parse_params(string param)
+/* {{{ proto object http_parse_params(string param[, int flags = HTTP_PARAMS_DEFAULT])
  *
  * Parse parameter list.
  */
@@ -1098,14 +1098,15 @@ PHP_FUNCTION(http_parse_params)
        char *param;
        int param_len;
        zval *params;
+       long flags = HTTP_PARAMS_DEFAULT;
        
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &param, &param_len)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &param, &param_len, &flags)) {
                RETURN_FALSE;
        }
        
        params = ecalloc(1, sizeof(zval));
        array_init(params);
-       if (SUCCESS != http_parse_params(param, Z_ARRVAL_P(params))) {
+       if (SUCCESS != http_parse_params(param, flags, Z_ARRVAL_P(params))) {
                zval_dtor(params);
                FREE_ZVAL(params);
                RETURN_FALSE;
index 1d73ddda5b4a447acea1b2f7ea54ebdfe4d9485a..9e428d15ce9ff37960e69f786daad2cca2416a4e 100644 (file)
@@ -103,6 +103,20 @@ PHP_RINIT_FUNCTION(http_request_method)
 {
        HTTP_G->request.methods.custom.entries = ecalloc(1, sizeof(http_request_method_entry *));
        
+       if (HTTP_G->request.methods.custom.ini && *HTTP_G->request.methods.custom.ini) {
+               HashPosition pos;
+               HashTable methods;
+               zval **data;
+       
+               zend_hash_init(&methods, 0, NULL, ZVAL_PTR_DTOR, 0);
+               http_parse_params(HTTP_G->request.methods.custom.ini, &methods);
+               FOREACH_HASH_VAL(pos, &methods, data) {
+                       if (Z_TYPE_PP(data) == IS_STRING) {
+                               http_request_method_register(Z_STRVAL_PP(data), Z_STRLEN_PP(data));
+                       }
+               }
+               zend_hash_destroy(&methods);
+       }
        return SUCCESS;
 }
 
index d5c503b094e95a330ad8f1f94331ede5360f871f..2d46aa8c84ec81a427d3df1f45878f1b996762ac 100644 (file)
@@ -87,6 +87,7 @@ HTTP_END_ARGS;
 
 HTTP_BEGIN_ARGS(parseParams, 1)
        HTTP_ARG_VAL(param_string, 0)
+       HTTP_ARG_VAL(flags, 0)
 HTTP_END_ARGS;
 
 HTTP_BEGIN_ARGS(chunkedDecode, 1)
index 0eaebcdba10bfac444f6f1aa500c8bf45548697f..8c8e030f6dff7adc787ff4db807b69d50bafc0ce 100644 (file)
@@ -21,13 +21,6 @@ arbitrary data with caching and resuming capabilities.
 
 It provides powerful request functionality, if built with CURL 
 support. Parallel requests are available for PHP-5 and greater.
-
-PHP-5 classes:
-HttpUtil, HttpMessage, HttpRequest, HttpRequestPool, 
-HttpDeflateStream, HttpInflateStream, HttpQueryString
-
-PHP-5.1 classes:
-HttpResponse
 ]]></description>
  <lead>
   <name>Michael Wallner</name>
@@ -46,7 +39,13 @@ HttpResponse
  </stability>
  <license>BSD, revised</license>
  <notes><![CDATA[
++ Added HttpRequest::enableCookies() and HttpRequest::resetCookies([bool session_only=FALSE])
++ Added optional flags argument to http_parse_params()
++ Added HTTP_PARAMS_ALLOW_COMMA, HTTP_PARAMS_ALLOW_FAILURE, HTTP_PARAMS_RAISE_ERROR constants
 * Fixed http_build_url("./path") if REQUEST_URI is empty
+* Fixed http_parse_params("foo;bar") returning "foo" and "ar"
+* Fixed return value of http_parse_params() Object{"params"=>Array("value", Array("name"=>"value"), ...)}
+* Fixed HttpMessage::setRequestMethod() errenously issuing a warning about an unknown request method
 ]]></notes>
  <contents>
   <dir name="/">
@@ -194,6 +193,7 @@ HttpResponse
     <file role="test" name="HttpRequest_007.phpt"/>
     <file role="test" name="HttpRequest_008.phpt"/>
     <file role="test" name="HttpRequest_009.phpt"/>
+    <file role="test" name="HttpRequest_010.phpt"/>
     <file role="test" name="HttpRequestPool_001.phpt"/>
     <file role="test" name="HttpRequestPool_002.phpt"/>
     <file role="test" name="HttpRequestPool_003.phpt"/>
@@ -216,6 +216,7 @@ HttpResponse
     <file role="test" name="parse_message_003.phpt"/>
     <file role="test" name="parse_message_004.phpt"/>
     <file role="test" name="parse_message_005.phpt"/>
+    <file role="test" name="parse_params_001.phpt"/>
     <file role="test" name="redirect_001.phpt"/>
     <file role="test" name="redirect_001_logging.phpt"/>
     <file role="test" name="redirect_002.phpt"/>
index 9e6083cce5b40006c0686f848aea144d8d0311a8..4e2a7c67bc5e0c2b49f418b354c39224af60e1b8 100644 (file)
@@ -118,6 +118,7 @@ ZEND_BEGIN_MODULE_GLOBALS(http)
                struct _http_globals_request_methods {
                        char *allowed;
                        struct _http_globals_request_methods_custom {
+                               char *ini;
                                int count;
                                void *entries;
                        } custom;
index 05b9a107ef79e7a80104faca9c988d7b947f88fd..a7349b21d8bde8853f09bce4d354404de201b803 100644 (file)
 #define HTTP_SUPPORT_ENCODINGS         0x08L
 #define HTTP_SUPPORT_SSLREQUESTS       0x20L
 
+#define HTTP_PARAMS_ALLOW_COMMA                0x01
+#define HTTP_PARAMS_ALLOW_FAILURE      0x02
+#define HTTP_PARAMS_RAISE_ERROR                0x04
+#define HTTP_PARAMS_DEFAULT    (HTTP_PARAMS_ALLOW_COMMA|HTTP_PARAMS_ALLOW_FAILURE|HTTP_PARAMS_RAISE_ERROR)
+
 extern PHP_MINIT_FUNCTION(http_support);
 
 #define http_support(f) _http_support(f)
@@ -125,9 +130,9 @@ typedef void (*http_parse_params_callback)(void *cb_arg, const char *key, int ke
 #define http_parse_params_default_callback _http_parse_params_default_callback
 PHP_HTTP_API void _http_parse_params_default_callback(void *ht, const char *key, int keylen, const char *val, int vallen TSRMLS_DC);
 
-#define http_parse_params(s, ht) _http_parse_params_ex((s), 1, _http_parse_params_default_callback, (ht) TSRMLS_CC)
-#define http_parse_params_ex(s, comma, cb, a) _http_parse_params_ex((s), (comma), (cb), (a) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_parse_params_ex(const char *params, int alloc_comma_sep, http_parse_params_callback cb, void *cb_arg TSRMLS_DC);
+#define http_parse_params(s, f, ht) _http_parse_params_ex((s), (f), _http_parse_params_default_callback, (ht) TSRMLS_CC)
+#define http_parse_params_ex(s, f, cb, a) _http_parse_params_ex((s), (f), (cb), (a) TSRMLS_CC)
+PHP_HTTP_API STATUS _http_parse_params_ex(const char *params, int flags, http_parse_params_callback cb, void *cb_arg TSRMLS_DC);
 
 
 #define http_locate_body _http_locate_body