- use exceptions in constructors and HttpRequest::send()
[m6w6/ext-http] / php_http_std_defs.h
index 8854b92fe68a212a7e83a87416ebe6bffd1ff679..49591cd578476612499a4f51e7394147ce0a6e92 100644 (file)
 #ifndef PHP_HTTP_STD_DEFS_H
 #define PHP_HTTP_STD_DEFS_H
 
-#define RETURN_SUCCESS(v)      RETURN_BOOL(SUCCESS == (v))
-#define HASH_ORNULL(z)                 ((z) ? Z_ARRVAL_P(z) : NULL)
-#define NO_ARGS                        if (ZEND_NUM_ARGS()) WRONG_PARAM_COUNT
+#ifdef PHP_WIN32
+#      define PHP_HTTP_API __declspec(dllexport)
+#else
+#      define PHP_HTTP_API
+#endif
+
+/* make functions that return SUCCESS|FAILURE more obvious */
+typedef int STATUS;
+
+/* lenof() */
+#define lenof(S) (sizeof(S) - 1)
+
+/* return bool (v == SUCCESS) */
+#define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
+
+/* function accepts no args */
+#define NO_ARGS if (ZEND_NUM_ARGS()) WRONG_PARAM_COUNT
 
 /* CR LF */
 #define HTTP_CRLF "\r\n"
 /* default cache control */
 #define HTTP_DEFAULT_CACHECONTROL "private, must-revalidate, max-age=0"
 
-/* max URI length */
-#define HTTP_URI_MAXLEN 2048
+/* max URL length */
+#define HTTP_URL_MAXLEN 2048
+#define HTTP_URI_MAXLEN HTTP_URL_MAXLEN
+
+/* def URL arg separator */
+#define HTTP_URL_ARGSEP "&"
+#define HTTP_URI_ARGSEP HTTP_URL_ARGSEP
 
 /* send buffer size */
 #define HTTP_SENDBUF_SIZE 2097152
 /* server vars shorthand */
 #define HTTP_SERVER_VARS Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])
 
-
-/* {{{ HTTP_GSC(var, name, ret) */
-#define HTTP_GSC(var, name, ret)  HTTP_GSP(var, name, return ret)
-/* }}} */
-
-/* {{{ HTTP_GSP(var, name, ret) */
-#define HTTP_GSP(var, name, ret) \
-               if (!(var = _http_get_server_var_ex(name, strlen(name)+1, 1 TSRMLS_CC))) { \
-                       ret; \
-               }
-/* }}} */
-
-/* override arg_separator.output to "&" for data used in outgoing requests */
-#include "zend_ini.h"
-#define HTTP_URL_ARGSEP_DEFAULT "&"
-#define HTTP_URL_ARGSEP_OVERRIDE zend_alter_ini_entry("arg_separator.output", sizeof("arg_separator.output") - 1, HTTP_URL_ARGSEP_DEFAULT, sizeof(HTTP_URL_ARGSEP_DEFAULT) - 1, ZEND_INI_ALL, ZEND_INI_STAGE_RUNTIME)
-#define HTTP_URL_ARGSEP_RESTORE zend_restore_ini_entry("arg_separator.output", sizeof("arg_separator.output") - 1, ZEND_INI_STAGE_RUNTIME)
-
 /* {{{ arrays */
 #define FOREACH_VAL(array, val) FOREACH_HASH_VAL(Z_ARRVAL_P(array), val)
 #define FOREACH_HASH_VAL(hash, val) \
 #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 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)
                } \
        }
 
+#      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 */
 /* }}} */