2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2011, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
15 PHP_HTTP_API STATUS
php_http_new(zend_object_value
*ov
, zend_class_entry
*ce
, php_http_new_t create
, zend_class_entry
*parent_ce
, void *intern_ptr
, void **obj_ptr TSRMLS_DC
)
19 } else if (parent_ce
&& !instanceof_function(ce
, parent_ce TSRMLS_CC
)) {
20 php_http_error(HE_WARNING
, PHP_HTTP_E_RUNTIME
, "Class %s does not extend %s", ce
->name
, parent_ce
->name
);
24 *ov
= create(ce
, intern_ptr
, obj_ptr TSRMLS_CC
);
28 PHP_HTTP_API zend_error_handling_t
php_http_object_get_error_handling(zval
*object TSRMLS_DC
)
33 zeh
= zend_read_property(Z_OBJCE_P(object
), object
, ZEND_STRL("errorHandling"), 0 TSRMLS_CC
);
34 if (Z_TYPE_P(zeh
) != IS_NULL
) {
35 lzeh
= php_http_ztyp(IS_LONG
, zeh
);
40 zeh
= zend_read_static_property(php_http_object_get_class_entry(), ZEND_STRL("defaultErrorHandling"), 0 TSRMLS_CC
);
41 if (Z_TYPE_P(zeh
) != IS_NULL
) {
42 lzeh
= php_http_ztyp(IS_LONG
, zeh
);
50 #define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpObject, method, 0, req_args)
51 #define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpObject, method, 0)
52 #define PHP_HTTP_OBJECT_ME(method, visibility) PHP_ME(HttpObject, method, PHP_HTTP_ARGS(HttpObject, method), visibility)
54 PHP_HTTP_BEGIN_ARGS(setErrorHandling
, 1)
55 PHP_HTTP_ARG_VAL(eh
, 0)
58 PHP_HTTP_EMPTY_ARGS(getErrorHandling
);
60 PHP_HTTP_BEGIN_ARGS(setDefaultErrorHandling
, 1)
61 PHP_HTTP_ARG_VAL(eh
, 0)
64 PHP_HTTP_EMPTY_ARGS(getDefaultErrorHandling
);
66 PHP_HTTP_BEGIN_ARGS(triggerError
, 3)
67 PHP_HTTP_ARG_VAL(error_type
, 0)
68 PHP_HTTP_ARG_VAL(error_code
, 0)
69 PHP_HTTP_ARG_VAL(error_message
, 0)
72 static zend_class_entry
*php_http_object_class_entry
;
74 zend_class_entry
*php_http_object_get_class_entry(void)
76 return php_http_object_class_entry
;
79 static zend_function_entry php_http_object_method_entry
[] = {
80 PHP_HTTP_OBJECT_ME(setErrorHandling
, ZEND_ACC_PUBLIC
)
81 PHP_HTTP_OBJECT_ME(getErrorHandling
, ZEND_ACC_PUBLIC
)
82 PHP_HTTP_OBJECT_ME(setDefaultErrorHandling
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
83 PHP_HTTP_OBJECT_ME(getDefaultErrorHandling
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
84 PHP_HTTP_OBJECT_ME(triggerError
, ZEND_ACC_PUBLIC
)
89 zend_object_value
php_http_object_new(zend_class_entry
*ce TSRMLS_DC
)
91 return php_http_object_new_ex(ce
, NULL
, NULL TSRMLS_CC
);
94 zend_object_value
php_http_object_new_ex(zend_class_entry
*ce
, void *nothing
, php_http_object_t
**ptr TSRMLS_DC
)
99 o
= ecalloc(1, sizeof(php_http_object_t
));
100 zend_object_std_init((zend_object
*) o
, ce TSRMLS_CC
);
101 object_properties_init((zend_object
*) o
, ce
);
107 ov
.handle
= zend_objects_store_put(o
, NULL
, (zend_objects_free_object_storage_t
) zend_objects_free_object_storage
, NULL TSRMLS_CC
);
108 ov
.handlers
= zend_get_std_object_handlers();
113 PHP_METHOD(HttpObject
, getErrorHandling
)
115 RETURN_PROP(php_http_object_get_class_entry(), "errorHandling");
118 PHP_METHOD(HttpObject
, setErrorHandling
)
122 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &eh
)) {
127 zend_update_property_long(php_http_object_get_class_entry(), getThis(), ZEND_STRL("errorHandling"), eh TSRMLS_CC
);
131 php_http_error(HE_WARNING
, PHP_HTTP_E_RUNTIME
, "unknown error handling code (%ld)", eh
);
136 RETURN_ZVAL(getThis(), 1, 0);
139 PHP_METHOD(HttpObject
, getDefaultErrorHandling
)
141 RETURN_SPROP(php_http_object_get_class_entry(), "defaultErrorHandling");
144 PHP_METHOD(HttpObject
, setDefaultErrorHandling
)
148 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &eh
)) {
153 zend_update_static_property_long(php_http_object_get_class_entry(), ZEND_STRL("defaultErrorHandling"), eh TSRMLS_CC
);
157 php_http_error(HE_WARNING
, PHP_HTTP_E_RUNTIME
, "unknown error handling code (%ld)", eh
);
163 PHP_METHOD(HttpObject
, triggerError
)
169 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "lls", &eh
, &code
, &msg_str
, &msg_len
)) {
170 php_http_error(eh TSRMLS_CC
, code
, "%.*s", msg_len
, msg_str
);
174 PHP_MINIT_FUNCTION(http_object
)
176 PHP_HTTP_REGISTER_CLASS(http
, Object
, http_object
, NULL
, ZEND_ACC_ABSTRACT
);
177 php_http_object_get_class_entry()->create_object
= php_http_object_new
;
179 zend_declare_property_null(php_http_object_get_class_entry(), ZEND_STRL("defaultErrorHandling"), (ZEND_ACC_STATIC
|ZEND_ACC_PROTECTED
) TSRMLS_CC
);
180 zend_declare_property_null(php_http_object_get_class_entry(), ZEND_STRL("errorHandling"), ZEND_ACC_PROTECTED TSRMLS_CC
);
182 zend_declare_class_constant_long(php_http_object_get_class_entry(), ZEND_STRL("EH_NORMAL"), EH_NORMAL TSRMLS_CC
);
183 zend_declare_class_constant_long(php_http_object_get_class_entry(), ZEND_STRL("EH_SUPPRESS"), EH_SUPPRESS TSRMLS_CC
);
184 zend_declare_class_constant_long(php_http_object_get_class_entry(), ZEND_STRL("EH_THROW"), EH_THROW TSRMLS_CC
);
195 * vim600: noet sw=4 ts=4 fdm=marker
196 * vim<600: noet sw=4 ts=4