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