+/* {{{ char *http_negotiate_language_func */
+char *_http_negotiate_language_func(const char *test, double *quality, HashTable *supported TSRMLS_DC)
+{
+ zval **value;
+ HashPosition pos;
+ const char *dash_test;
+
+ FOREACH_HASH_VAL(pos, supported, value) {
+#if HTTP_DBG_NEG
+ fprintf(stderr, "strcasecmp('%s', '%s')\n", Z_STRVAL_PP(value), test);
+#endif
+ if (!strcasecmp(Z_STRVAL_PP(value), test)) {
+ return Z_STRVAL_PP(value);
+ }
+ }
+
+ /* no distinct match found, so try primaries */
+ if ((dash_test = strchr(test, '-'))) {
+ FOREACH_HASH_VAL(pos, supported, value) {
+ int len = dash_test - test;
+#if HTTP_DBG_NEG
+ fprintf(stderr, "strncasecmp('%s', '%s', %d)\n", Z_STRVAL_PP(value), test, len);
+#endif
+ if ( (!strncasecmp(Z_STRVAL_PP(value), test, len)) &&
+ ( (Z_STRVAL_PP(value)[len] == '\0') ||
+ (Z_STRVAL_PP(value)[len] == '-'))) {
+ *quality *= .9;
+ return Z_STRVAL_PP(value);
+ }
+ }
+ }
+
+ return NULL;
+}
+/* }}} */
+
+/* {{{ char *http_negotiate_default_func */
+char *_http_negotiate_default_func(const char *test, double *quality, HashTable *supported TSRMLS_DC)
+{
+ zval **value;
+ HashPosition pos;
+
+ FOREACH_HASH_VAL(pos, supported, value) {
+#if HTTP_DBG_NEG
+ fprintf(stderr, "strcasecmp('%s', '%s')\n", Z_STRVAL_PP(value), test);
+#endif
+ if (!strcasecmp(Z_STRVAL_PP(value), test)) {
+ return Z_STRVAL_PP(value);
+ }
+ }
+
+ return NULL;
+}
+/* }}} */
+
+/* {{{ HashTable *http_negotiate_z(zval *, HashTable *, negotiate_func_t) */
+PHP_HTTP_API HashTable *_http_negotiate_z(zval *value, HashTable *supported, negotiate_func_t neg TSRMLS_DC)