+#define HTTP_DO_NEGOTIATE(type, supported, as_array) \
+{ \
+ HashTable *result; \
+ if (result = http_negotiate_ ##type(supported)) { \
+ if (as_array) { \
+ Z_TYPE_P(return_value) = IS_ARRAY; \
+ Z_ARRVAL_P(return_value) = result; \
+ } else { \
+ char *key; \
+ uint key_len; \
+ ulong idx; \
+ \
+ if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(result, &key, &key_len, &idx, 1, NULL)) { \
+ RETVAL_STRINGL(key, key_len-1, 0); \
+ } else { \
+ RETVAL_NULL(); \
+ } \
+ zend_hash_destroy(result); \
+ } \
+ } else { \
+ if (as_array) { \
+ zval **value; \
+ \
+ array_init(return_value); \
+ \
+ FOREACH_VAL(supported, value) { \
+ convert_to_string_ex(value); \
+ add_assoc_double(return_value, Z_STRVAL_PP(value), 1.0); \
+ } \
+ } else { \
+ zval **value; \
+ \
+ zend_hash_internal_pointer_reset(Z_ARRVAL_P(supported)); \
+ if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(supported), (void **) &value)) { \
+ RETVAL_ZVAL(*value, 1, 0); \
+ } else { \
+ RETVAL_NULL(); \
+ } \
+ } \
+ } \
+}
+
+
+/* {{{ proto string http_negotiate_language(array supported[, bool return_quality_array = false])