flush WIP
[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 zend_object *php_http_object_new(zend_class_entry *ce)
16 {
17 return &php_http_object_new_ex(ce, NULL)->zo;
18 }
19
20 php_http_object_t *php_http_object_new_ex(zend_class_entry *ce, void *intern)
21 {
22 php_http_object_t *o;
23
24 o = ecalloc(1, sizeof(php_http_object_t) + (ce->default_properties_count - 1) * sizeof(zval));
25 zend_object_std_init(&o->zo, ce);
26 object_properties_init(&o->zo, ce);
27
28 o->intern = intern;
29 o->zo.handlers = zend_get_std_object_handlers();
30
31 return o;
32 }
33
34 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)
35 {
36 void *obj;
37
38 if (!ce) {
39 ce = parent_ce;
40 } else if (parent_ce && !instanceof_function(ce, parent_ce)) {
41 php_http_throw(unexpected_val, "Class %s does not extend %s", ce->name->val, parent_ce->name->val);
42 return FAILURE;
43 }
44
45 obj = create(ce, intern_ptr);
46 if (obj_ptr) {
47 *obj_ptr = obj;
48 }
49 return SUCCESS;
50 }
51
52 ZEND_RESULT_CODE php_http_method_call(zval *object, const char *method_str, size_t method_len, int argc, zval argv[], zval *retval_ptr)
53 {
54 zend_fcall_info fci;
55 zval *retval;
56 ZEND_RESULT_CODE rv;
57
58 fci.size = sizeof(fci);
59 fci.object = Z_OBJ_P(object);
60 fci.retval = retval_ptr ? retval_ptr : &retval;
61 fci.param_count = argc;
62 fci.params = argv;
63 fci.no_separation = 1;
64 fci.symbol_table = NULL;
65 fci.function_table = NULL;
66
67 ZVAL_STRINGL(&fci.function_name, method_str, method_len);
68 rv = zend_call_function(&fci, NULL TSRMLS_CC);
69 zval_ptr_dtor(&fci.function_name);
70
71 if (!retval_ptr && retval) {
72 zval_ptr_dtor(&retval);
73 }
74 return rv;
75 }
76
77 /*
78 * Local variables:
79 * tab-width: 4
80 * c-basic-offset: 4
81 * End:
82 * vim600: noet sw=4 ts=4 fdm=marker
83 * vim<600: noet sw=4 ts=4
84 */
85