From: Michael Wallner Date: Sat, 27 May 2006 11:51:17 +0000 (+0000) Subject: - adjust ini entry names to those of the globals struct X-Git-Tag: RELEASE_1_0_0~16 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=dbc4ec02cd319000b5c8589910047cfe6d5738be - adjust ini entry names to those of the globals struct - 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 --- diff --git a/docs/http.ini b/docs/http.ini index 2d96869..b3124ff 100644 --- a/docs/http.ini +++ b/docs/http.ini @@ -11,30 +11,33 @@ ; 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 729d025..9eb59b9 100644 --- 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() /* }}} */ diff --git a/http_api.c b/http_api.c index 4744a82..2254208 100644 --- a/http_api.c +++ b/http_api.c @@ -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; } diff --git a/http_cookie_api.c b/http_cookie_api.c index 7d10ba5..1ad997a 100644 --- a/http_cookie_api.c +++ b/http_cookie_api.c @@ -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 { diff --git a/http_functions.c b/http_functions.c index 807b0a5..e894b19 100644 --- a/http_functions.c +++ b/http_functions.c @@ -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", ¶m, ¶m_len)) { + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", ¶m, ¶m_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; diff --git a/http_request_method_api.c b/http_request_method_api.c index 1d73ddd..9e428d1 100644 --- a/http_request_method_api.c +++ b/http_request_method_api.c @@ -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; } diff --git a/http_util_object.c b/http_util_object.c index d5c503b..2d46aa8 100644 --- a/http_util_object.c +++ b/http_util_object.c @@ -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) diff --git a/package2.xml b/package2.xml index 0eaebcd..8c8e030 100644 --- a/package2.xml +++ b/package2.xml @@ -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 ]]> Michael Wallner @@ -46,7 +39,13 @@ HttpResponse BSD, revised Array("value", Array("name"=>"value"), ...)} +* Fixed HttpMessage::setRequestMethod() errenously issuing a warning about an unknown request method ]]> @@ -194,6 +193,7 @@ HttpResponse + @@ -216,6 +216,7 @@ HttpResponse + diff --git a/php_http.h b/php_http.h index 9e6083c..4e2a7c6 100644 --- a/php_http.h +++ b/php_http.h @@ -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; diff --git a/php_http_api.h b/php_http_api.h index 05b9a10..a7349b2 100644 --- a/php_http_api.h +++ b/php_http_api.h @@ -21,6 +21,11 @@ #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