- FOREACH_HASH_VAL(Z_ARRVAL(zarray), zentry) {
- if (q_ptr = strrchr(Z_STRVAL_PP(zentry), ';')) {
- qual = strtod(q_ptr + 3, NULL);
- *q_ptr = 0;
- q_ptr = NULL;
- } else {
- qual = 1000.0 - i++;
- }
- /* TODO: support primaries only, too */
- FOREACH_HASH_VAL((HashTable *)supported, zsupp) {
- if (!strcasecmp(Z_STRVAL_PP(zsupp), Z_STRVAL_PP(zentry))) {
- add_assoc_double(&zentries, Z_STRVAL_PP(zsupp), qual);
- break;
+ php_explode(&ex_del, accept, &ex_arr, INT_MAX);
+
+ if (zend_hash_num_elements(Z_ARRVAL(ex_arr)) > 0) {
+ int i = 0;
+ HashPosition pos;
+ zval **entry, array;
+
+ INIT_PZVAL(&array);
+ array_init(&array);
+
+ FOREACH_HASH_VAL(pos, Z_ARRVAL(ex_arr), entry) {
+ int ident_len;
+ double quality;
+ char *selected, *identifier, *freeme;
+ const char *separator;
+
+#if HTTP_DBG_NEG
+ fprintf(stderr, "Checking %s\n", Z_STRVAL_PP(entry));
+#endif
+
+ if ((separator = strchr(Z_STRVAL_PP(entry), ';'))) {
+ const char *ptr = separator;
+
+ while (*++ptr && !HTTP_IS_CTYPE(digit, *ptr) && '.' != *ptr);
+
+ quality = zend_strtod(ptr, NULL);
+ identifier = estrndup(Z_STRVAL_PP(entry), ident_len = separator - Z_STRVAL_PP(entry));
+ } else {
+ quality = 1000.0 - i++;
+ identifier = estrndup(Z_STRVAL_PP(entry), ident_len = Z_STRLEN_PP(entry));
+ }
+ freeme = identifier;
+
+ while (HTTP_IS_CTYPE(space, *identifier)) {
+ ++identifier;
+ --ident_len;
+ }
+ while (ident_len && HTTP_IS_CTYPE(space, identifier[ident_len - 1])) {
+ identifier[--ident_len] = '\0';
+ }
+
+ if ((selected = neg(identifier, &quality, supported TSRMLS_CC))) {
+ /* don't overwrite previously set with higher quality */
+ if (!zend_hash_exists(Z_ARRVAL(array), selected, strlen(selected) + 1)) {
+ add_assoc_double(&array, selected, quality);
+ }
+ }
+
+ efree(freeme);