- separated http_check_method() from http_check_allowed_methods()
[m6w6/ext-http] / php_http_std_defs.h
index a0f7ddf7b4d40104e1135436e6c02d0bb1961d43..953d4ac22e6db6a7d04ed65eb9bf47176b6d2975 100644 (file)
@@ -34,7 +34,10 @@ typedef int STATUS;
 #define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
 
 /* function accepts no args */
-#define NO_ARGS if (ZEND_NUM_ARGS()) WRONG_PARAM_COUNT
+#define NO_ARGS \
+       if (ZEND_NUM_ARGS()) { \
+               zend_error(E_NOTICE, "Wrong parameter count for %s()", get_active_function_name(TSRMLS_C)); \
+       }
 
 /* CR LF */
 #define HTTP_CRLF "\r\n"
@@ -56,9 +59,26 @@ typedef int STATUS;
 /* CURL buffer size */
 #define HTTP_CURLBUF_SIZE 16384
 
+/* known methods */
+#define HTTP_KNOWN_METHODS \
+               /* HTTP 1.1 */ \
+               "GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT, " \
+               /* WebDAV - RFC 2518 */ \
+               "PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, " \
+               /* WebDAV Versioning - RFC 3253 */ \
+               "VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, " \
+               "MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, " \
+               /* WebDAV Access Control - RFC 3744 */ \
+               "ACL, " \
+               /* END */
+
+
 /* server vars shorthand */
 #define HTTP_SERVER_VARS Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])
 
+#define HTTP_INI_ENTRY(entry, default, scope, global) \
+       STD_PHP_INI_ENTRY(entry, default, scope, http_update_##global, global, zend_http_globals, http_globals)
+
 /* {{{ arrays */
 #define FOREACH_VAL(array, val) FOREACH_HASH_VAL(Z_ARRVAL_P(array), val)
 #define FOREACH_HASH_VAL(hash, val) \
@@ -81,33 +101,64 @@ typedef int STATUS;
 
 #define array_copy(src, dst)   zend_hash_copy(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *))
 #define array_merge(src, dst)  zend_hash_merge(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 1)
+#define array_append(src, dst) \
+       { \
+               ulong idx; \
+               uint klen; \
+               char *key = NULL; \
+               zval **data; \
+                \
+               for (   zend_hash_internal_pointer_reset(Z_ARRVAL_P(src)); \
+                               zend_hash_get_current_key_ex(Z_ARRVAL_P(src), &key, &klen, &idx, 0, NULL) != HASH_KEY_NON_EXISTANT && \
+                               zend_hash_get_current_data(Z_ARRVAL_P(src), (void **) &data) == SUCCESS; \
+                               zend_hash_move_forward(Z_ARRVAL_P(src))) \
+               { \
+                       if (key) { \
+                               zval **tmp; \
+                                \
+                               if (SUCCESS == zend_hash_find(Z_ARRVAL_P(dst), key, klen, (void **) &tmp)) { \
+                                       if (Z_TYPE_PP(tmp) != IS_ARRAY) { \
+                                               convert_to_array_ex(tmp); \
+                                       } \
+                                       add_next_index_zval(*tmp, *data); \
+                               } else { \
+                                       add_assoc_zval(dst, key, *data); \
+                               } \
+                               zval_add_ref(data); \
+                               key = NULL; \
+                       } \
+               } \
+       }
 /* }}} */
 
+#define HTTP_LONG_CONSTANT(name, const) REGISTER_LONG_CONSTANT(name, const, CONST_CS | CONST_PERSISTENT);
+
 /* {{{ objects & properties */
 #ifdef ZEND_ENGINE_2
 
+
 #      define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \
        { \
                zend_class_entry ce; \
-               INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \
-               ce.create_object = name## _new_object; \
+               INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
+               ce.create_object = name## _new; \
                name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
                name## _ce->ce_flags |= flags;  \
-               memcpy(& name## _object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
-               name## _object_handlers.clone_obj = NULL; \
-               name## _declare_default_properties(name## _ce); \
+               memcpy(& name## _handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
+               name## _declare_default_properties(); \
        }
 
 #      define HTTP_REGISTER_CLASS(classname, name, parent, flags) \
        { \
                zend_class_entry ce; \
-               INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \
+               INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
                ce.create_object = NULL; \
                name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
                name## _ce->ce_flags |= flags;  \
        }
 
-#      define getObject(t, o) t * o = ((t *) zend_object_store_get_object(getThis() TSRMLS_CC))
+#      define getObject(t, o) getObjectEx(t, o, getThis())
+#      define getObjectEx(t, o, v) t * o = ((t *) zend_object_store_get_object(v TSRMLS_CC))
 #      define OBJ_PROP(o) o->zo.properties
 #      define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
 #      define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
@@ -134,9 +185,27 @@ typedef int STATUS;
                } \
        }
 
+#      define SET_EH_THROW() SET_EH_THROW_EX(zend_exception_get_default())
+#      define SET_EH_THROW_HTTP() SET_EH_THROW_EX(http_exception_get_default())
+#      define SET_EH_THROW_EX(ex) php_set_error_handling(EH_THROW, ex TSRMLS_CC)
+#      define SET_EH_NORMAL() php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC)
+
 #endif /* ZEND_ENGINE_2 */
 /* }}} */
 
+#ifndef E_THROW
+#      define E_THROW 0
+#endif
+
+#define HTTP_E_UNKOWN          0L
+#define HTTP_E_PARSE           1L
+#define HTTP_E_HEADER          2L
+#define HTTP_E_OBUFFER         3L
+#define HTTP_E_CURL                    4L
+#define HTTP_E_ENCODE          5L
+#define HTTP_E_PARAM           6L
+#define HTTP_E_URL                     7L
+#define HTTP_E_MSG                     8L
 
 #endif /* PHP_HTTP_STD_DEFS_H */