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 zend_hash_destroy(&opt
->suboptions
.options
);
20 zend_string_release(opt
->name
);
23 php_http_options_t
*php_http_options_init(php_http_options_t
*registry
, zend_bool persistent
)
26 registry
= pecalloc(1, sizeof(*registry
), persistent
);
28 memset(registry
, 0, sizeof(*registry
));
31 registry
->persistent
= persistent
;
32 zend_hash_init(®istry
->options
, 0, NULL
, php_http_options_hash_dtor
, persistent
);
37 ZEND_RESULT_CODE
php_http_options_apply(php_http_options_t
*registry
, HashTable
*options
, void *userdata
)
40 php_http_option_t
*opt
;
42 ZEND_HASH_FOREACH_VAL(®istry
->options
, entry
)
45 if (!(val
= registry
->getter(opt
, options
, userdata
))) {
48 if (registry
->setter
) {
49 if (SUCCESS
!= registry
->setter(opt
, val
, userdata
)) {
52 } else if (!opt
->setter
|| SUCCESS
!= opt
->setter(opt
, val
, userdata
)) {
56 ZEND_HASH_FOREACH_END();
61 void php_http_options_dtor(php_http_options_t
*registry
)
63 zend_hash_destroy(®istry
->options
);
66 void php_http_options_free(php_http_options_t
**registry
)
69 php_http_options_dtor(*registry
);
70 pefree(*registry
, (*registry
)->persistent
);
75 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
)
77 php_http_option_t opt
;
79 memset(&opt
, 0, sizeof(opt
));
81 php_http_options_init(&opt
.suboptions
, registry
->persistent
);
82 opt
.suboptions
.getter
= registry
->getter
;
83 opt
.suboptions
.setter
= registry
->setter
;
85 opt
.name
= zend_string_init(name_str
, name_len
, registry
->persistent
);
89 switch ((opt
.type
= type
)) {
91 ZVAL_TRUE(&opt
.defval
);
95 ZVAL_FALSE(&opt
.defval
);
99 ZVAL_LONG(&opt
.defval
, 0);
103 ZVAL_EMPTY_STRING(&opt
.defval
);
107 ZVAL_DOUBLE(&opt
.defval
, 0);
111 ZVAL_NULL(&opt
.defval
);
115 return zend_hash_update_mem(®istry
->options
, opt
.name
, &opt
, sizeof(opt
));
118 zval
*php_http_option_get(php_http_option_t
*opt
, HashTable
*options
, void *userdata
)
121 return zend_hash_find(options
, opt
->name
);
133 * vim600: noet sw=4 ts=4 fdm=marker
134 * vim<600: noet sw=4 ts=4