1/*	$NetBSD$	*/
2
3/*
4 * Copyright (c) 2010 Kungliga Tekniska H��gskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
6 * All rights reserved.
7 *
8 * Portions Copyright (c) 2010 Apple Inc. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 *
21 * 3. Neither the name of the Institute nor the names of its contributors
22 *    may be used to endorse or promote products derived from this software
23 *    without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38#ifndef HEIM_BASE_H
39#define HEIM_BASE_H 1
40
41#include <sys/types.h>
42#include <krb5/krb5-types.h>
43#include <stdarg.h>
44#include <stdbool.h>
45
46typedef void * heim_object_t;
47typedef unsigned int heim_tid_t;
48typedef heim_object_t heim_bool_t;
49typedef heim_object_t heim_null_t;
50#define HEIM_BASE_ONCE_INIT 0
51typedef long heim_base_once_t; /* XXX arch dependant */
52
53void *	heim_retain(heim_object_t);
54void	heim_release(heim_object_t);
55
56typedef void (*heim_type_dealloc)(void *);
57
58void *
59heim_alloc(size_t size, const char *name, heim_type_dealloc dealloc);
60
61heim_tid_t
62heim_get_tid(heim_object_t object);
63
64int
65heim_cmp(heim_object_t a, heim_object_t b);
66
67unsigned long
68heim_get_hash(heim_object_t ptr);
69
70void
71heim_base_once_f(heim_base_once_t *, void *, void (*)(void *));
72
73void
74heim_abort(const char *fmt, ...)
75    HEIMDAL_NORETURN_ATTRIBUTE
76    HEIMDAL_PRINTF_ATTRIBUTE((printf, 1, 2));
77
78void
79heim_abortv(const char *fmt, va_list ap)
80    HEIMDAL_NORETURN_ATTRIBUTE
81    HEIMDAL_PRINTF_ATTRIBUTE((printf, 1, 0));
82
83#define heim_assert(e,t) \
84    (__builtin_expect(!(e), 0) ? heim_abort(t ":" #e) : (void)0)
85
86/*
87 *
88 */
89
90heim_null_t
91heim_null_create(void);
92
93heim_bool_t
94heim_bool_create(int);
95
96int
97heim_bool_val(heim_bool_t);
98
99/*
100 * Array
101 */
102
103typedef struct heim_array_data *heim_array_t;
104
105heim_array_t heim_array_create(void);
106heim_tid_t heim_array_get_type_id(void);
107
108typedef void (*heim_array_iterator_f_t)(heim_object_t, void *);
109
110int	heim_array_append_value(heim_array_t, heim_object_t);
111void	heim_array_iterate_f(heim_array_t, heim_array_iterator_f_t, void *);
112#ifdef __BLOCKS__
113void	heim_array_iterate(heim_array_t, void (^)(heim_object_t));
114#endif
115size_t	heim_array_get_length(heim_array_t);
116heim_object_t
117	heim_array_copy_value(heim_array_t, size_t);
118void	heim_array_delete_value(heim_array_t, size_t);
119#ifdef __BLOCKS__
120void	heim_array_filter(heim_array_t, bool (^)(heim_object_t));
121#endif
122
123/*
124 * Dict
125 */
126
127typedef struct heim_dict_data *heim_dict_t;
128
129heim_dict_t heim_dict_create(size_t size);
130heim_tid_t heim_dict_get_type_id(void);
131
132typedef void (*heim_dict_iterator_f_t)(heim_object_t, heim_object_t, void *);
133
134int	heim_dict_add_value(heim_dict_t, heim_object_t, heim_object_t);
135void	heim_dict_iterate_f(heim_dict_t, heim_dict_iterator_f_t, void *);
136#ifdef __BLOCKS__
137void	heim_dict_iterate(heim_dict_t, void (^)(heim_object_t, heim_object_t));
138#endif
139
140heim_object_t
141	heim_dict_copy_value(heim_dict_t, heim_object_t);
142void	heim_dict_delete_key(heim_dict_t, heim_object_t);
143
144/*
145 * String
146 */
147
148typedef struct heim_string_data *heim_string_t;
149
150heim_string_t heim_string_create(const char *);
151heim_tid_t heim_string_get_type_id(void);
152const char * heim_string_get_utf8(heim_string_t);
153
154/*
155 * Number
156 */
157
158typedef struct heim_number_data *heim_number_t;
159
160heim_number_t heim_number_create(int);
161heim_tid_t heim_number_get_type_id(void);
162int heim_number_get_int(heim_number_t);
163
164/*
165 *
166 */
167
168typedef struct heim_auto_release * heim_auto_release_t;
169
170heim_auto_release_t heim_auto_release_create(void);
171void heim_auto_release_drain(heim_auto_release_t);
172void heim_auto_release(heim_object_t);
173
174#endif /* HEIM_BASE_H */
175