zend_string updates
[m6w6/ext-http] / php_http_object.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
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-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #include "php_http_api.h"
14
15 static zend_object_handlers php_http_object_handlers;
16
17 zend_object *php_http_object_new(zend_class_entry *ce)
18 {
19 return &php_http_object_new_ex(ce, NULL)->zo;
20 }
21
22 php_http_object_t *php_http_object_new_ex(zend_class_entry *ce, void *intern)
23 {
24 php_http_object_t *o;
25
26 o = ecalloc(1, sizeof(php_http_object_t) + (ce->default_properties_count - 1) * sizeof(zval));
27 zend_object_std_init(&o->zo, ce);
28 object_properties_init(&o->zo, ce);
29
30 o->intern = intern;
31 o->zo.handlers = &php_http_object_handlers;
32
33 return o;
34 }
35
36 void php_http_object_free(zend_object *object)
37 {
38 php_http_object_t *obj = PHP_HTTP_OBJ(object, NULL);
39 zend_object_std_dtor(object);
40 }
41
42 ZEND_RESULT_CODE php_http_new(void **obj_ptr, zend_class_entry *ce, php_http_new_t create, zend_class_entry *parent_ce, void *intern_ptr)
43 {
44 void *obj;
45
46 if (!ce) {
47 ce = parent_ce;
48 } else if (parent_ce && !instanceof_function(ce, parent_ce)) {
49 php_http_throw(unexpected_val, "Class %s does not extend %s", ce->name->val, parent_ce->name->val);
50 return FAILURE;
51 }
52
53 obj = create(ce, intern_ptr);
54 if (obj_ptr) {
55 *obj_ptr = obj;
56 }
57 return SUCCESS;
58 }
59
60 ZEND_RESULT_CODE php_http_method_call(zval *object, const char *method_str, size_t method_len, int argc, zval argv[], zval *retval_ptr)
61 {
62 zend_fcall_info fci;
63 zval retval;
64 ZEND_RESULT_CODE rv;
65
66 ZVAL_UNDEF(&retval);
67 fci.size = sizeof(fci);
68 fci.object = Z_OBJ_P(object);
69 fci.retval = retval_ptr ? retval_ptr : &retval;
70 fci.param_count = argc;
71 fci.params = argv;
72 fci.no_separation = 1;
73 fci.symbol_table = NULL;
74 fci.function_table = NULL;
75
76 ZVAL_STRINGL(&fci.function_name, method_str, method_len);
77 rv = zend_call_function(&fci, NULL TSRMLS_CC);
78 zval_ptr_dtor(&fci.function_name);
79
80 if (!retval_ptr) {
81 zval_ptr_dtor(&retval);
82 }
83 return rv;
84 }
85
86 PHP_MINIT_FUNCTION(http_object)
87 {
88 memcpy(&php_http_object_handlers, zend_get_std_object_handlers(), sizeof(php_http_object_handlers));
89 php_http_object_handlers.offset = XtOffsetOf(php_http_object_t, zo);
90
91 return SUCCESS;
92 }
93
94 /*
95 * Local variables:
96 * tab-width: 4
97 * c-basic-offset: 4
98 * End:
99 * vim600: noet sw=4 ts=4 fdm=marker
100 * vim<600: noet sw=4 ts=4
101 */
102