{
char *key = NULL;
ulong idx = 0;
+ uint keylen = 0;
zval array, **hsv;
HashPosition pos;
Z_ARRVAL(array) = headers;
if (SUCCESS == zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &hsv)) {
- FOREACH_KEY(pos, *hsv, key, idx) {
- if (key && !strncmp(key, "HTTP_", 5)) {
- zval **header;
+ FOREACH_KEYLEN(pos, *hsv, key, keylen, idx) {
+ if (key && keylen > 6 && !strncmp(key, "HTTP_", 5)) {
+ zval **header, *orig;
key += 5;
+ keylen -= 6;
if (prettify) {
- key = pretty_key(key, strlen(key), 1, 1);
+ key = pretty_key(estrndup(key, keylen), keylen, 1, 1);
}
zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv), (void **) &header, &pos);
+
+ orig = *header;
+ convert_to_string_ex(header);
add_assoc_stringl(&array, key, Z_STRVAL_PP(header), Z_STRLEN_PP(header), 1);
+ if (orig != *header) {
+ zval_ptr_dtor(header);
+ }
+
+ if (prettify) {
+ efree(key);
+ }
+
key = NULL;
+ keylen = 0;
}
}
}
zend_hash_get_current_key_ex(hash, &strkey, NULL, &numkey, 0, &pos) != HASH_KEY_NON_EXISTANT; \
zend_hash_move_forward_ex(hash, &pos)) \
+#define FOREACH_KEYLEN(pos, array, strkey, keylen, numkey) FOREACH_HASH_KEYLEN(pos, Z_ARRVAL_P(array), strkey, keylen, numkey)
+#define FOREACH_HASH_KEYLEN(pos, hash, strkey, keylen, numkey) \
+ for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
+ zend_hash_get_current_key_ex(hash, &strkey, &keylen, &numkey, 0, &pos) != HASH_KEY_NON_EXISTANT; \
+ zend_hash_move_forward_ex(hash, &pos)) \
+
#define FOREACH_KEYVAL(pos, array, strkey, numkey, val) FOREACH_HASH_KEYVAL(pos, Z_ARRVAL_P(array), strkey, numkey, val)
#define FOREACH_HASH_KEYVAL(pos, hash, strkey, numkey, val) \
for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \