+#define HTTP_DO_NEGOTIATE(type, supported, rs_array) \
+{ \
+ HashTable *result; \
+ if (result = http_negotiate_ ##type(supported)) { \
+ 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(); \
+ } \
+ \
+ if (rs_array) { \
+ zend_hash_copy(Z_ARRVAL_P(rs_array), result, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); \
+ } \
+ \
+ zend_hash_destroy(result); \
+ FREE_HASHTABLE(result); \
+ \
+ } 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(); \
+ } \
+ \
+ if (rs_array) { \
+ zval **value; \
+ \
+ FOREACH_VAL(supported, value) { \
+ convert_to_string_ex(value); \
+ add_assoc_double(rs_array, Z_STRVAL_PP(value), 1.0); \
+ } \
+ } \
+ } \
+}
+
+
+/* {{{ proto string http_negotiate_language(array supported[, array &result])