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-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
15 static void php_http_options_hash_dtor(zval
*pData
)
17 php_http_option_t
*opt
= Z_PTR_P(pData
);
19 zval_ptr_dtor(&opt
->defval
);
20 zend_hash_destroy(&opt
->suboptions
.options
);
21 zend_string_release(opt
->name
);
22 pefree(opt
, opt
->persistent
);
25 php_http_options_t
*php_http_options_init(php_http_options_t
*registry
, zend_bool persistent
)
28 registry
= pecalloc(1, sizeof(*registry
), persistent
);
30 memset(registry
, 0, sizeof(*registry
));
33 registry
->persistent
= persistent
;
34 zend_hash_init(®istry
->options
, 0, NULL
, php_http_options_hash_dtor
, persistent
);
39 ZEND_RESULT_CODE
php_http_options_apply(php_http_options_t
*registry
, HashTable
*options
, void *userdata
)
42 php_http_option_t
*opt
;
44 ZEND_HASH_FOREACH_VAL(®istry
->options
, entry
)
47 if (!(val
= registry
->getter(opt
, options
, userdata
))) {
50 if (registry
->setter
) {
51 if (SUCCESS
!= registry
->setter(opt
, val
, userdata
)) {
54 } else if (!opt
->setter
|| SUCCESS
!= opt
->setter(opt
, val
, userdata
)) {
58 ZEND_HASH_FOREACH_END();
63 void php_http_options_dtor(php_http_options_t
*registry
)
65 zend_hash_destroy(®istry
->options
);
68 void php_http_options_free(php_http_options_t
**registry
)
71 php_http_options_dtor(*registry
);
72 pefree(*registry
, (*registry
)->persistent
);
77 php_http_option_t
*php_http_option_register(php_http_options_t
*registry
, const char *name_str
, size_t name_len
, ulong option
, zend_uchar type
)
79 php_http_option_t opt
;
81 memset(&opt
, 0, sizeof(opt
));
83 php_http_options_init(&opt
.suboptions
, registry
->persistent
);
84 opt
.suboptions
.getter
= registry
->getter
;
85 opt
.suboptions
.setter
= registry
->setter
;
87 opt
.persistent
= registry
->persistent
;
88 opt
.name
= zend_string_init(name_str
, name_len
, registry
->persistent
);
92 switch ((opt
.type
= type
)) {
94 ZVAL_TRUE(&opt
.defval
);
98 ZVAL_FALSE(&opt
.defval
);
102 ZVAL_LONG(&opt
.defval
, 0);
106 ZVAL_DOUBLE(&opt
.defval
, 0);
110 ZVAL_NULL(&opt
.defval
);
114 return zend_hash_update_mem(®istry
->options
, opt
.name
, &opt
, sizeof(opt
));
117 zval
*php_http_option_get(php_http_option_t
*opt
, HashTable
*options
, void *userdata
)
120 return zend_hash_find(options
, opt
->name
);
132 * vim600: noet sw=4 ts=4 fdm=marker
133 * vim<600: noet sw=4 ts=4