int php_http_match(const char *haystack, const char *needle, int flags);
char *php_http_pretty_key(register char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen);
-size_t php_http_boundary(char *buf, size_t len TSRMLS_DC);
+size_t php_http_boundary(char *buf, size_t len);
int php_http_select_str(const char *cmp, int argc, ...);
-/* See "A Reusable Duff Device" By Ralf Holly, August 01, 2005 */
-#define PHP_HTTP_DUFF_BREAK() times_=1
-#define PHP_HTTP_DUFF(c, a) do { \
- size_t count_ = (c); \
- size_t times_ = (count_ + 7) >> 3; \
- switch (count_ & 7){ \
- case 0: do { \
- a; \
- case 7: \
- a; \
- case 6: \
- a; \
- case 5: \
- a; \
- case 4: \
- a; \
- case 3: \
- a; \
- case 2: \
- a; \
- case 1: \
- a; \
- } while (--times_ > 0); \
- } \
-} while (0)
-
-static inline const char *php_http_locate_str(register const char *h, size_t h_len, const char *n, size_t n_len)
-{
- if (!n_len || !h_len || h_len < n_len) {
- return NULL;
- }
-
- PHP_HTTP_DUFF(h_len - n_len + 1,
- if (*h == *n && !strncmp(h + 1, n + 1, n_len - 1)) {
- return h;
- }
- ++h;
- );
-
- return NULL;
-}
+#define php_http_locate_str(h, h_len, n, n_len) zend_memnstr((h), (n), (n_len), (h)+(h_len))
static inline const char *php_http_locate_eol(const char *line, int *eol_len)
{
{
register const char *eol = bin;
- if (len > 0) {
- PHP_HTTP_DUFF(len,
- if (*eol == '\r' || *eol == '\n') {
- if (eol_len) {
- *eol_len = ((eol[0] == '\r' && eol[1] == '\n') ? 2 : 1);
- }
- return eol;
+ while (len--) {
+ if (UNEXPECTED(*eol == '\r' || *eol == '\n')) {
+ if (EXPECTED(eol_len)) {
+ *eol_len = (EXPECTED(eol[0] == '\r' && eol[1] == '\n') ? 2 : 1);
}
- ++eol;
- );
+ return eol;
+ }
+ ++eol;
}
return NULL;
}
/* ZEND */
-#if PHP_VERSION_ID < 50400
-# define object_properties_init(o, ce) zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*))
-# define PHP_HTTP_ZEND_LITERAL_DC
-# define PHP_HTTP_ZEND_LITERAL_CC
-# define PHP_HTTP_ZEND_LITERAL_CCN
-# define ZVAL_COPY_VALUE(zv, arr) do { \
- (zv)->value = (arr)->value; \
- Z_TYPE_P(zv) = Z_TYPE_P(arr); \
- } while (0)
-#else
-# define PHP_HTTP_ZEND_LITERAL_DC , const zend_literal *literal_key
-# define PHP_HTTP_ZEND_LITERAL_CC , (literal_key)
-# define PHP_HTTP_ZEND_LITERAL_CCN , NULL
+#if PHP_DEBUG
+# undef HASH_OF
+# if PHP_VERSION_ID >= 70500
+# define HASH_OF(p) ((HashTable*)(Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties(Z_OBJ_P(p)) : NULL))))
+# else
+# define HASH_OF(p) ((HashTable*)(Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p)) : NULL))))
+# endif
#endif
-#if PHP_VERSION_ID < 50500
-#undef SUCCESS
-#undef FAILURE
-typedef enum {
- SUCCESS = 0,
- FAILURE = -1
-} ZEND_RESULT_CODE;
+#ifndef GC_SET_REFCOUNT
+# define GC_SET_REFCOUNT(gc, rc) GC_REFCOUNT(gc) = rc
+#endif
+#ifndef GC_ADDREF
+# define GC_ADDREF(gc) ++GC_REFCOUNT(gc)
+#endif
+#ifndef GC_DELREF
+# define GC_DELREF(gc) --GC_REFCOUNT(gc)
#endif
-#if PHP_VERSION_ID < 50700
-# define z_is_true zend_is_true
+#ifdef ZEND_HASH_GET_APPLY_COUNT
+# define HT_IS_RECURSIVE(ht) (ZEND_HASH_GET_APPLY_COUNT(ht) > 0)
#else
-# define z_is_true(z) zend_is_true(z TSRMLS_CC)
+# define HT_IS_RECURSIVE(ht) GC_IS_RECURSIVE(ht)
+#endif
+#ifdef ZEND_HASH_INC_APPLY_COUNT
+# define HT_PROTECT_RECURSION(ht) ZEND_HASH_INC_APPLY_COUNT(ht)
+#else
+# define HT_PROTECT_RECURSION(ht) GC_PROTECT_RECURSION(ht)
+#endif
+#ifdef ZEND_HASH_DEC_APPLY_COUNT
+# define HT_UNPROTECT_RECURSION(ht) ZEND_HASH_DEC_APPLY_COUNT(ht)
+#else
+# define HT_UNPROTECT_RECURSION(ht) GC_UNPROTECT_RECURSION(ht)
#endif
-#define INIT_PZVAL_ARRAY(zv, ht) \
- { \
- INIT_PZVAL((zv)); \
- Z_TYPE_P(zv) = IS_ARRAY; \
- Z_ARRVAL_P(zv) = (ht); \
- }
+#if PHP_VERSION_ID >= 70400
+# define PHP_WRITE_PROP_HANDLER_TYPE zval *
+# define PHP_WRITE_PROP_HANDLER_RETURN(v) return v
+#else
+# define PHP_WRITE_PROP_HANDLER_TYPE void
+# define PHP_WRITE_PROP_HANDLER_RETURN(v)
+#endif
-static inline zval *php_http_zconv(int type, zval *z)
+static inline void *PHP_HTTP_OBJ(zend_object *zo, zval *zv)
{
- switch (type) {
- case IS_NULL: convert_to_null_ex(&z); break;
- case IS_BOOL: convert_to_boolean_ex(&z); break;
- case IS_LONG: convert_to_long_ex(&z); break;
- case IS_DOUBLE: convert_to_double_ex(&z); break;
- case IS_STRING: convert_to_string_ex(&z); break;
- case IS_ARRAY: convert_to_array_ex(&z); break;
- case IS_OBJECT: convert_to_object_ex(&z); break;
+ if (!zo) {
+ zo = Z_OBJ_P(zv);
}
- return z;
+ return (char *) zo - zo->handlers->offset;
}
-static inline zval *php_http_ztyp(int type, zval *z)
+static inline zend_string *php_http_cs2zs(char *s, size_t l)
{
- SEPARATE_ARG_IF_REF(z);
- return (Z_TYPE_P(z) == type) ? z : php_http_zconv(type, z);
-}
+ zend_string *str = erealloc(s, sizeof(*str) + l);
-static inline zval *php_http_zsep(zend_bool add_ref, int type, zval *z)
-{
- if (add_ref) {
- Z_ADDREF_P(z);
- }
- if (Z_TYPE_P(z) != type) {
- return php_http_zconv(type, z);
- } else {
- SEPARATE_ZVAL_IF_NOT_REF(&z);
- return z;
- }
+ memmove(str->val, str, l);
+ str->val[l] = 0;
+ str->len = l;
+ str->h = 0;
+
+ GC_SET_REFCOUNT(str, 1);
+ GC_TYPE_INFO(str) = IS_STRING;
+
+ return str;
}
-static inline ZEND_RESULT_CODE php_http_ini_entry(const char *name_str, size_t name_len, const char **value_str, size_t *value_len, zend_bool orig TSRMLS_DC)
+static inline ZEND_RESULT_CODE php_http_ini_entry(const char *name_str, size_t name_len, const char **val_str, size_t *val_len, zend_bool orig)
{
zend_ini_entry *ini_entry;
- if (SUCCESS == zend_hash_find(EG(ini_directives), name_str, name_len + 1, (void *) &ini_entry)) {
+ if ((ini_entry = zend_hash_str_find_ptr(EG(ini_directives), name_str, name_len))) {
if (orig && ini_entry->modified) {
- *value_str = ini_entry->orig_value;
- *value_len = (size_t) ini_entry->orig_value_length;
+ *val_str = ini_entry->orig_value->val;
+ *val_len = ini_entry->orig_value->len;
} else {
- *value_str = ini_entry->value;
- *value_len = (size_t) ini_entry->value_length;
+ *val_str = ini_entry->value->val;
+ *val_len = ini_entry->value->len;
}
return SUCCESS;
}
return FAILURE;
}
+#define Z_ISUSER(zv) (Z_TYPE(zv) <= 10)
+#define Z_ISUSER_P(zvp) Z_ISUSER(*(zvp))
+
/* return object(values) */
+#define ZVAL_OBJECT(z, o, addref) \
+ ZVAL_OBJ(z, o); \
+ if (addref) { \
+ Z_ADDREF_P(z); \
+ }
#define RETVAL_OBJECT(o, addref) \
- RETVAL_OBJVAL((o)->value.obj, addref)
+ ZVAL_OBJECT(return_value, o, addref)
#define RETURN_OBJECT(o, addref) \
RETVAL_OBJECT(o, addref); \
return
-#define RETVAL_OBJVAL(ov, addref) \
- ZVAL_OBJVAL(return_value, ov, addref)
-#define RETURN_OBJVAL(ov, addref) \
- RETVAL_OBJVAL(ov, addref); \
- return
-#define ZVAL_OBJVAL(zv, ov, addref) \
- (zv)->type = IS_OBJECT; \
- (zv)->value.obj = (ov);\
- if (addref && Z_OBJ_HT_P(zv)->add_ref) { \
- Z_OBJ_HT_P(zv)->add_ref((zv) TSRMLS_CC); \
- }
-
-#define Z_OBJ_DELREF(z) \
- if (Z_OBJ_HT(z)->del_ref) { \
- Z_OBJ_HT(z)->del_ref(&(z) TSRMLS_CC); \
- }
-#define Z_OBJ_ADDREF(z) \
- if (Z_OBJ_HT(z)->add_ref) { \
- Z_OBJ_HT(z)->add_ref(&(z) TSRMLS_CC); \
- }
-#define Z_OBJ_DELREF_P(z) \
- if (Z_OBJ_HT_P(z)->del_ref) { \
- Z_OBJ_HT_P(z)->del_ref((z) TSRMLS_CC); \
- }
-#define Z_OBJ_ADDREF_P(z) \
- if (Z_OBJ_HT_P(z)->add_ref) { \
- Z_OBJ_HT_P(z)->add_ref((z) TSRMLS_CC); \
- }
-#define Z_OBJ_DELREF_PP(z) \
- if (Z_OBJ_HT_PP(z)->del_ref) { \
- Z_OBJ_HT_PP(z)->del_ref(*(z) TSRMLS_CC); \
- }
-#define Z_OBJ_ADDREF_PP(z) \
- if (Z_OBJ_HT_PP(z)->add_ref) { \
- Z_OBJ_HT_PP(z)->add_ref(*(z) TSRMLS_CC); \
- }
#define EMPTY_FUNCTION_ENTRY {NULL, NULL, NULL, 0, 0}
/* ARRAYS */
-#ifndef HASH_KEY_NON_EXISTENT
-# define HASH_KEY_NON_EXISTENT HASH_KEY_NON_EXISTANT
-#endif
-
-PHP_HTTP_API unsigned php_http_array_list(HashTable *ht TSRMLS_DC, unsigned argc, ...);
+PHP_HTTP_API unsigned php_http_array_list(HashTable *ht, unsigned argc, ...);
-typedef struct php_http_array_hashkey {
- char *str;
- uint len;
- ulong num;
- uint dup:1;
- uint type:31;
-} php_http_array_hashkey_t;
-#define php_http_array_hashkey_init(dup) {NULL, 0, 0, (dup), 0}
+typedef struct php_http_arrkey {
+ zend_ulong h;
+ zend_string *key;
+ unsigned allocated:1;
+ unsigned stringified:1;
+} php_http_arrkey_t;
-static inline void php_http_array_hashkey_stringify(php_http_array_hashkey_t *key)
+static inline void *php_http_arrkey_stringify(php_http_arrkey_t *arrkey, zend_hash_key *key)
{
- if (key->type != HASH_KEY_IS_STRING) {
- key->len = spprintf(&key->str, 0, "%lu", key->num) + 1;
+ if (arrkey) {
+ arrkey->allocated = 0;
+ } else {
+ arrkey = emalloc(sizeof(*arrkey));
+ arrkey->allocated = 1;
}
+
+ if (key) {
+ memcpy(arrkey, key, sizeof(*key));
+ }
+ if ((arrkey->stringified = !arrkey->key)) {
+ arrkey->key = zend_long_to_str(arrkey->h);
+ }
+ return arrkey;
}
-static inline void php_http_array_hashkey_stringfree(php_http_array_hashkey_t *key)
+static inline void php_http_arrkey_dtor(php_http_arrkey_t *arrkey)
{
- if (key->type != HASH_KEY_IS_STRING || key->dup) {
- PTR_FREE(key->str);
+ if (arrkey->stringified) {
+ zend_string_release(arrkey->key);
+ }
+ if (arrkey->allocated) {
+ efree(arrkey);
}
}
-#define FOREACH_VAL(pos, array, val) FOREACH_HASH_VAL(pos, HASH_OF(array), val)
-#define FOREACH_HASH_VAL(pos, hash, val) \
- for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
- zend_hash_get_current_data_ex(hash, (void *) &val, &pos) == SUCCESS; \
- zend_hash_move_forward_ex(hash, &pos))
-
-#define FOREACH_KEY(pos, array, key) FOREACH_HASH_KEY(pos, HASH_OF(array), key)
-#define FOREACH_HASH_KEY(pos, hash, _key) \
- for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
- ((_key).type = zend_hash_get_current_key_ex(hash, &(_key).str, &(_key).len, &(_key).num, (zend_bool) (_key).dup, &pos)) != HASH_KEY_NON_EXISTANT; \
- zend_hash_move_forward_ex(hash, &pos)) \
-
-#define FOREACH_KEYVAL(pos, array, key, val) FOREACH_HASH_KEYVAL(pos, HASH_OF(array), key, val)
-#define FOREACH_HASH_KEYVAL(pos, hash, _key, val) \
- for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
- ((_key).type = zend_hash_get_current_key_ex(hash, &(_key).str, &(_key).len, &(_key).num, (zend_bool) (_key).dup, &pos)) != HASH_KEY_NON_EXISTANT && \
- zend_hash_get_current_data_ex(hash, (void *) &val, &pos) == SUCCESS; \
- zend_hash_move_forward_ex(hash, &pos))
-
-#define array_copy(src, dst) zend_hash_copy(dst, src, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *))
-#define array_copy_strings(src, dst) zend_hash_copy(dst, src, php_http_array_copy_strings, NULL, sizeof(zval *))
+#define array_copy(src, dst) zend_hash_copy(dst, src, (copy_ctor_func_t) zval_add_ref)
+#define array_copy_strings(src, dst) zend_hash_copy(dst, src, php_http_array_copy_strings)
#define ARRAY_JOIN_STRONLY 0x01
#define ARRAY_JOIN_PRETTIFY 0x02
#define ARRAY_JOIN_STRINGIFY 0x04
-#define array_join(src, dst, append, flags) zend_hash_apply_with_arguments(src TSRMLS_CC, (append)?php_http_array_apply_append_func:php_http_array_apply_merge_func, 2, dst, (int)flags)
+#define array_join(src, dst, append, flags) zend_hash_apply_with_arguments(src, (append)?php_http_array_apply_append_func:php_http_array_apply_merge_func, 2, dst, (int)flags)
-void php_http_array_copy_strings(void *zpp);
-int php_http_array_apply_append_func(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key);
-int php_http_array_apply_merge_func(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key);
+void php_http_array_copy_strings(zval *zp);
+int php_http_array_apply_append_func(zval *pDest, int num_args, va_list args, zend_hash_key *hash_key);
+int php_http_array_apply_merge_func(zval *pDest, int num_args, va_list args, zend_hash_key *hash_key);
/* PASS CALLBACK */
typedef size_t (*php_http_pass_format_callback_t)(void *cb_arg, const char *fmt, ...);
typedef struct php_http_pass_fcall_arg {
- zval *fcz;
+ zval fcz;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
-#ifdef ZTS
- void ***ts;
-#endif
} php_http_pass_fcall_arg_t;
PHP_HTTP_API size_t php_http_pass_fcall_callback(void *cb_arg, const char *str, size_t len);