From: Michael Wallner Date: Mon, 23 Jan 2012 15:18:28 +0000 (+0000) Subject: negotiation test & fixes X-Git-Tag: DEV_2-before-client~54 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=a5e1d0cdf87105d3577ca2db9cb2c5c380062c10;p=m6w6%2Fext-http negotiation test & fixes --- diff --git a/php_http_env.c b/php_http_env.c index f7df9d0..a0232d2 100644 --- a/php_http_env.c +++ b/php_http_env.c @@ -575,6 +575,11 @@ PHP_HTTP_BEGIN_ARGS(negotiateCharset, 1) PHP_HTTP_ARG_VAL(result_array, 1) PHP_HTTP_END_ARGS; +PHP_HTTP_BEGIN_ARGS(negotiateEncoding, 1) + PHP_HTTP_ARG_VAL(supported, 0) + PHP_HTTP_ARG_VAL(result_array, 1) +PHP_HTTP_END_ARGS; + PHP_HTTP_BEGIN_ARGS(negotiate, 2) PHP_HTTP_ARG_VAL(value, 0) PHP_HTTP_ARG_VAL(supported, 0) @@ -602,6 +607,7 @@ zend_function_entry php_http_env_method_entry[] = { PHP_HTTP_ENV_ME(negotiateLanguage) PHP_HTTP_ENV_ME(negotiateContentType) + PHP_HTTP_ENV_ME(negotiateEncoding) PHP_HTTP_ENV_ME(negotiateCharset) PHP_HTTP_ENV_ME(negotiate) @@ -747,6 +753,22 @@ PHP_METHOD(HttpEnv, negotiateCharset) } } +PHP_METHOD(HttpEnv, negotiateEncoding) +{ + HashTable *supported; + zval *rs_array = NULL; + + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) { + if (rs_array) { + zval_dtor(rs_array); + array_init(rs_array); + } + PHP_HTTP_DO_NEGOTIATE(encoding, supported, rs_array); + } else { + RETURN_FALSE; + } +} + PHP_METHOD(HttpEnv, negotiateContentType) { HashTable *supported; diff --git a/php_http_env.h b/php_http_env.h index 62e22cd..64cc702 100644 --- a/php_http_env.h +++ b/php_http_env.h @@ -81,6 +81,7 @@ PHP_METHOD(HttpEnv, setResponseHeader); PHP_METHOD(HttpEnv, setResponseCode); PHP_METHOD(HttpEnv, negotiateLanguage); PHP_METHOD(HttpEnv, negotiateCharset); +PHP_METHOD(HttpEnv, negotiateEncoding); PHP_METHOD(HttpEnv, negotiateContentType); PHP_METHOD(HttpEnv, negotiate); PHP_METHOD(HttpEnv, persistentHandlesStat); diff --git a/php_http_negotiate.c b/php_http_negotiate.c index aeb9521..69c7393 100644 --- a/php_http_negotiate.c +++ b/php_http_negotiate.c @@ -74,6 +74,11 @@ PHP_HTTP_API HashTable *php_http_negotiate(const char *value_str, size_t value_l q = Z_DVAL_P(tmp); zval_ptr_dtor(&tmp); + + if (!q) { + STR_FREE(key.str); + continue; + } } else { q = 1.0 - ++i / 100.0; } diff --git a/tests/negotiate001.phpt b/tests/negotiate001.phpt new file mode 100644 index 0000000..b71efe0 --- /dev/null +++ b/tests/negotiate001.phpt @@ -0,0 +1,111 @@ +--TEST-- +negotiate +--SKIPIF-- + +--ENV-- +HTTP_ACCEPT=text/html,text/plain,text/xml;q=0.1,*/*;q=0 +HTTP_ACCEPT_CHARSET=utf-8,iso-8859-1;q=0.8,iso-8859-15;q=0 +HTTP_ACCEPT_ENCODING=gzip,deflate;q=0 +HTTP_ACCEPT_LANGUAGE=de-DE,de-AT;q=0.9,en;q=0.8,fr;q=0 +--FILE-- +CONTENT TYPE + + + +CHARSET + + + +ENCODING + + + +LANGUAGE + + +DONE +--EXPECT-- +CONTENT TYPE + +text/html: Array +( + [text/html] => 0.99 + [text/xml] => 0.1 +) +text/xml: Array +( + [text/xml] => 0.1 +) +text/json: Array +( +) + +CHARSET + +utf-8: Array +( + [utf-8] => 0.99 + [iso-8859-1] => 0.8 +) +iso-8859-1: Array +( + [iso-8859-1] => 0.8 +) +utf-16: Array +( +) + +ENCODING + +gzip: Array +( + [gzip] => 0.99 +) +: Array +( +) + +LANGUAGE + +de: Array +( + [de] => 0.899 + [en] => 0.8 +) +de-DE: Array +( + [de-DE] => 0.99 + [de-AT] => 0.9 + [en] => 0.8 +) +en: Array +( + [en] => 0.8 +) +DONE