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-2013, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
15 php_http_options_t
*php_http_options_init(php_http_options_t
*registry
, zend_bool persistent
)
18 registry
= pecalloc(1, sizeof(*registry
), persistent
);
20 memset(registry
, 0, sizeof(*registry
));
23 registry
->persistent
= persistent
;
24 zend_hash_init(®istry
->options
, 0, NULL
, (dtor_func_t
) zend_hash_destroy
, persistent
);
29 STATUS
php_http_options_apply(php_http_options_t
*registry
, HashTable
*options
, void *userdata
)
33 php_http_option_t
*opt
;
35 FOREACH_HASH_VAL(pos
, ®istry
->options
, opt
) {
36 if (!(val
= registry
->getter(opt
, options
, userdata
))) {
39 if (registry
->setter
) {
40 if (SUCCESS
!= registry
->setter(opt
, val
, userdata
)) {
43 } else if (!opt
->setter
|| SUCCESS
!= opt
->setter(opt
, val
, userdata
)) {
50 void php_http_options_dtor(php_http_options_t
*registry
)
52 zend_hash_destroy(®istry
->options
);
55 void php_http_options_free(php_http_options_t
**registry
)
58 php_http_options_dtor(*registry
);
59 pefree(*registry
, (*registry
)->persistent
);
64 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
)
66 php_http_option_t opt
, *dst
= NULL
;
68 memset(&opt
, 0, sizeof(opt
));
70 php_http_options_init(&opt
.suboptions
, registry
->persistent
);
71 opt
.suboptions
.getter
= registry
->getter
;
72 opt
.suboptions
.setter
= registry
->setter
;
74 opt
.name
.h
= zend_hash_func(opt
.name
.s
= name_str
, opt
.name
.l
= name_len
+ 1);
78 INIT_ZVAL(opt
.defval
);
79 switch ((opt
.type
= type
)) {
81 ZVAL_BOOL(&opt
.defval
, 0);
85 ZVAL_LONG(&opt
.defval
, 0);
89 ZVAL_STRINGL(&opt
.defval
, NULL
, 0, 0);
93 ZVAL_DOUBLE(&opt
.defval
, 0);
97 ZVAL_NULL(&opt
.defval
);
101 zend_hash_quick_update(®istry
->options
, opt
.name
.s
, opt
.name
.l
, opt
.name
.h
, (void *) &opt
, sizeof(opt
), (void *) &dst
);
105 zval
*php_http_option_get(php_http_option_t
*opt
, HashTable
*options
, void *userdata
)
110 if (SUCCESS
== zend_hash_quick_find(options
, opt
->name
.s
, opt
->name
.l
, opt
->name
.h
, (void *) &zoption
)) {
124 * vim600: noet sw=4 ts=4 fdm=marker
125 * vim<600: noet sw=4 ts=4