change array_list API
[m6w6/ext-http] / php_http_misc.h
index a07f32fc83b835ccd6971088cc3837a9a8329a57..67fc711e2c96113bf72ed87a9e03dc10f5e62c1c 100644 (file)
@@ -6,12 +6,10 @@
     | modification, are permitted provided that the conditions mentioned |
     | in the accompanying LICENSE file are met.                          |
     +--------------------------------------------------------------------+
-    | Copyright (c) 2004-2010, Michael Wallner <mike@php.net>            |
+    | Copyright (c) 2004-2011, Michael Wallner <mike@php.net>            |
     +--------------------------------------------------------------------+
 */
 
-/* $Id: php_http_api.h 298891 2010-05-03 08:26:38Z mike $ */
-
 #ifndef PHP_HTTP_MISC_H
 #define PHP_HTTP_MISC_H
 
@@ -79,12 +77,12 @@ PHP_HTTP_API void php_http_sleep(double s);
 #define PHP_HTTP_MATCH_CASE            0x01
 #define PHP_HTTP_MATCH_WORD            0x10
 #define PHP_HTTP_MATCH_FULL            0x20
-#define PHP_HTTP_MATCH_STRICT  (PHP_HTTP_ENV_MATCH_CASE|PHP_HTTP_ENV_MATCH_FULL)
-
-extern int php_http_match(const char *haystack, const char *needle, int flags);
+#define PHP_HTTP_MATCH_STRICT  (PHP_HTTP_MATCH_CASE|PHP_HTTP_MATCH_FULL)
 
-extern char *php_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen);
-extern size_t php_http_boundary(char *buf, size_t len TSRMLS_DC);
+int php_http_match(const char *haystack, const char *needle, int flags);
+char *php_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen);
+size_t php_http_boundary(char *buf, size_t len TSRMLS_DC);
+int php_http_select_str(const char *cmp, int argc, ...);
 
 static inline const char *php_http_locate_str(const char *h, size_t h_len, const char *n, size_t n_len)
 {
@@ -139,9 +137,11 @@ static inline const char *php_http_locate_bin_eol(const char *bin, size_t len, i
 {
        const char *eol;
 
-       for (eol = bin; eol - bin < len; ++eol) {
+       for (eol = bin; eol - bin <= len; ++eol) {
                if (*eol == '\r' || *eol == '\n') {
-                       *eol_len = eol ? ((eol[0] == '\r' && eol[1] == '\n') ? 2 : 1) : 0;
+                       if (eol_len) {
+                               *eol_len = ((eol[0] == '\r' && eol[1] == '\n') ? 2 : 1);
+                       }
                        return eol;
                }
        }
@@ -151,6 +151,21 @@ static inline const char *php_http_locate_bin_eol(const char *bin, size_t len, i
 
 /* 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
+#endif
+
 #define INIT_PZVAL_ARRAY(zv, ht) \
        { \
                INIT_PZVAL((zv)); \
@@ -175,7 +190,8 @@ static inline zval *php_http_ztyp(int type, zval *z)
        return z;
 }
 
-static inline zval *php_http_zsep(zend_bool add_ref, int type, zval *z) {
+static inline zval *php_http_zsep(zend_bool add_ref, int type, zval *z)
+{
        if (add_ref) {
                Z_ADDREF_P(z);
        }
@@ -195,6 +211,22 @@ static inline zval *php_http_zsep(zend_bool add_ref, int type, zval *z) {
        return z;
 }
 
+static inline STATUS 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)
+{
+       zend_ini_entry *ini_entry;
+
+       if (SUCCESS == zend_hash_find(EG(ini_directives), name_str, name_len + 1, (void *) &ini_entry)) {
+               if (orig && ini_entry->modified) {
+                       *value_str = ini_entry->orig_value;
+                       *value_len = (size_t) ini_entry->orig_value_length;
+               } else {
+                       *value_str = ini_entry->value;
+                       *value_len = (size_t) ini_entry->value_length;
+               }
+               return SUCCESS;
+       }
+       return FAILURE;
+}
 
 /* return bool (v == SUCCESS) */
 #define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v))
@@ -272,6 +304,7 @@ static inline zval *php_http_zsep(zend_bool add_ref, int type, zval *z) {
 #define PHP_HTTP_ARGS(class, method)                                                           args_for_ ##class## _ ##method
 #define PHP_HTTP_ARG_VAL(name, pass_ref)                                                       ZEND_ARG_INFO(pass_ref, name)
 #define PHP_HTTP_ARG_OBJ(class, name, allow_null)                                      ZEND_ARG_OBJ_INFO(0, name, class, allow_null)
+#define PHP_HTTP_ARG_ARR(name, allow_null, pass_ref)                           ZEND_ARG_ARRAY_INFO(pass_ref, name, allow_null)
 
 #define EMPTY_FUNCTION_ENTRY {NULL, NULL, NULL, 0, 0}
 
@@ -293,6 +326,7 @@ static inline zval *php_http_zsep(zend_bool add_ref, int type, zval *z) {
                INIT_NS_CLASS_ENTRY(ce, #ns, #classname, php_ ##name## _method_entry); \
                php_ ##name## _class_entry = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
                php_ ##name## _class_entry->ce_flags |= flags;  \
+               php_http_register_class(php_ ##name## _get_class_entry); \
        }
 
 #define PHP_HTTP_REGISTER_INTERFACE(ns, ifacename, name, flags) \
@@ -302,6 +336,7 @@ static inline zval *php_http_zsep(zend_bool add_ref, int type, zval *z) {
                INIT_NS_CLASS_ENTRY(ce, #ns, #ifacename, php_ ##name## _method_entry); \
                php_ ##name## _class_entry = zend_register_internal_interface(&ce TSRMLS_CC); \
                php_ ##name## _class_entry->ce_flags |= flags; \
+               php_http_register_class(php_ ##name## _get_class_entry); \
        }
 
 #define PHP_HTTP_REGISTER_EXCEPTION(classname, cename, parent) \
@@ -368,6 +403,7 @@ static inline zval *php_http_zsep(zend_bool add_ref, int type, zval *z) {
 #endif /* PHP_HTTP_HAVE_CURL */
 
 /* ARRAYS */
+PHP_HTTP_API unsigned php_http_array_list(HashTable *ht TSRMLS_DC, unsigned argc, ...);
 
 typedef struct php_http_array_hashkey {
        char *str;
@@ -378,6 +414,23 @@ typedef struct php_http_array_hashkey {
 } php_http_array_hashkey_t;
 #define php_http_array_hashkey_init(dup) {NULL, 0, 0, (dup), 0}
 
+static inline void php_http_array_hashkey_stringify(php_http_array_hashkey_t *key)
+{
+       if (key->type != HASH_KEY_IS_STRING) {
+               key->len = spprintf(&key->str, 0, "%lu", key->num) + 1;
+       }
+}
+
+static inline void php_http_array_hashkey_stringfree(php_http_array_hashkey_t *key)
+{
+       if (key->type != HASH_KEY_IS_STRING || key->dup) {
+               STR_FREE(key->str);
+       }
+}
+
+typedef void (*php_http_array_visitor_t)(void *visitor_arg, php_http_array_hashkey_t *key, zval **val TSRMLS_DC);
+PHP_HTTP_API void php_http_array_visit(HashTable *ht, php_http_array_visitor_t visitor_func, void *visitor_arg TSRMLS_DC);
+
 #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); \
@@ -402,8 +455,8 @@ typedef struct php_http_array_hashkey {
 #define ARRAY_JOIN_PRETTIFY 2
 #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)
 
-extern int php_http_array_apply_append_func(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key);
-extern int php_http_array_apply_merge_func(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key);
+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);
 
 /* PASS CALLBACK */
 
@@ -417,6 +470,17 @@ typedef struct php_http_pass_callback_arg {
 
 PHP_HTTP_API size_t php_http_pass_wrapper(php_http_pass_callback_arg_t *cb_arg, const char *str, size_t len);
 
+typedef struct php_http_pass_fcall_arg {
+       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);
+
 /* ERROR */
 
 extern void php_http_error(long type TSRMLS_DC, long code, const char *format, ...);
@@ -449,9 +513,9 @@ typedef enum php_http_error {
        PHP_HTTP_E_MESSAGE_TYPE,
        PHP_HTTP_E_MESSAGE_BODY,
        PHP_HTTP_E_ENCODING,
-       PHP_HTTP_E_REQUEST,
-       PHP_HTTP_E_REQUEST_POOL,
-       PHP_HTTP_E_REQUEST_DATASHARE,
+       PHP_HTTP_E_CLIENT,
+       PHP_HTTP_E_CLIENT_POOL,
+       PHP_HTTP_E_CLIENT_DATASHARE,
        PHP_HTTP_E_REQUEST_FACTORY,
        PHP_HTTP_E_SOCKET,
        PHP_HTTP_E_RESPONSE,