gp: Test with binary content for certificate data
[Samba.git] / third_party / heimdal / lib / base / heimbase.h
blob4546df94699ca909063f3421ac4401b7b5d75618
1 /*
2 * Copyright (c) 2010 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Portions Copyright (c) 2010 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
36 #ifndef HEIM_BASE_H
37 #define HEIM_BASE_H 1
39 #include <sys/types.h>
40 #ifndef _WIN32
41 #include <sys/socket.h>
42 #endif
43 #if !defined(WIN32) && !defined(HAVE_DISPATCH_DISPATCH_H) && defined(ENABLE_PTHREAD_SUPPORT)
44 #include <pthread.h>
45 #endif
46 #include <krb5-types.h>
47 #include <stdarg.h>
48 #ifdef _WIN32
49 #include <winsock2.h>
50 #endif
51 #ifdef HAVE_STDBOOL_H
52 #include <stdbool.h>
53 #else
54 #ifndef false
55 #define false 0
56 #endif
57 #ifndef true
58 #define true 1
59 #endif
60 #endif
62 #include <stdint.h>
64 #include <heim_err.h>
66 #ifdef _WIN32
67 #define HEIM_CALLCONV __stdcall
68 #define HEIM_LIB_CALL __stdcall
69 #else
70 #define HEIM_CALLCONV
71 #define HEIM_LIB_CALL
72 #endif
74 #if !defined(__GNUC__) && !defined(__attribute__)
75 #define __attribute__(x)
76 #endif
78 #define HEIM_BASE_API_VERSION 20130210
81 * Generic facilities (moved from lib/krb5/.
84 typedef int32_t heim_error_code;
85 typedef struct heim_context_s *heim_context;
86 typedef struct heim_pcontext_s *heim_pcontext;
88 typedef void (HEIM_CALLCONV *heim_log_log_func_t)(heim_context,
89 const char *,
90 const char *,
91 void *);
92 typedef void (HEIM_CALLCONV *heim_log_close_func_t)(void *);
94 typedef struct heim_log_facility_s heim_log_facility;
96 typedef uintptr_t
97 (HEIM_LIB_CALL *heim_get_instance_func_t)(const char *);
99 #define HEIM_PLUGIN_INVOKE_ALL 1
101 struct heim_plugin_data {
102 const char *module;
103 const char *name;
104 int min_version;
105 const char *const *deps;
106 heim_get_instance_func_t get_instance;
110 * heim_config_binding is identical to struct krb5_config_binding
111 * within krb5.h. Its format is public and used by callers of
112 * krb5_config_get_list() and krb5_config_vget_list().
114 enum heim_config_type {
115 heim_config_string,
116 heim_config_list,
118 struct heim_config_binding {
119 enum heim_config_type type;
120 char *name;
121 struct heim_config_binding *next;
122 union {
123 char *string;
124 struct heim_config_binding *list;
125 void *generic;
126 } u;
128 typedef struct heim_config_binding heim_config_binding;
129 typedef struct heim_config_binding heim_config_section;
132 * CF-like, JSON APIs
135 typedef enum heim_tid_enum {
136 HEIM_TID_NUMBER = 0,
137 HEIM_TID_NULL = 1,
138 HEIM_TID_BOOL = 2,
139 HEIM_TID_TAGGED_UNUSED2 = 3, /* reserved for tagged object types */
140 HEIM_TID_TAGGED_UNUSED3 = 4, /* reserved for tagged object types */
141 HEIM_TID_TAGGED_UNUSED4 = 5, /* reserved for tagged object types */
142 HEIM_TID_TAGGED_UNUSED5 = 6, /* reserved for tagged object types */
143 HEIM_TID_TAGGED_UNUSED6 = 7, /* reserved for tagged object types */
144 HEIM_TID_MEMORY = 128,
145 HEIM_TID_ARRAY = 129,
146 HEIM_TID_DICT = 130,
147 HEIM_TID_STRING = 131,
148 HEIM_TID_AUTORELEASE = 132,
149 HEIM_TID_ERROR = 133,
150 HEIM_TID_DATA = 134,
151 HEIM_TID_DB = 135,
152 HEIM_TID_PA_AUTH_MECH = 136,
153 HEIM_TID_PAC = 137,
154 HEIM_TID_USER = 255
155 } heim_tid;
157 typedef void * heim_object_t;
158 typedef unsigned int heim_tid_t;
159 typedef heim_object_t heim_bool_t;
160 typedef heim_object_t heim_null_t;
161 #ifdef WIN32
162 typedef LONG heim_base_once_t;
163 #define HEIM_BASE_ONCE_INIT 0
164 #elif defined(HAVE_DISPATCH_DISPATCH_H)
165 typedef long heim_base_once_t; /* XXX arch dependant */
166 #define HEIM_BASE_ONCE_INIT 0
167 #elif defined(ENABLE_PTHREAD_SUPPORT)
168 typedef pthread_once_t heim_base_once_t;
169 #define HEIM_BASE_ONCE_INIT PTHREAD_ONCE_INIT
170 #else
171 typedef long heim_base_once_t; /* XXX arch dependant */
172 #define HEIM_BASE_ONCE_INIT 0
173 #endif
175 #if !defined(__has_extension)
176 #define __has_extension(x) 0
177 #endif
179 #define HEIM_REQUIRE_GNUC(m,n,p) \
180 (((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + __GNUC_PATCHLEVEL__) >= \
181 (((m) * 10000) + ((n) * 100) + (p)))
184 #if __has_extension(__builtin_expect) || HEIM_REQUIRE_GNUC(3,0,0)
185 #define heim_builtin_expect(_op,_res) __builtin_expect(_op,_res)
186 #else
187 #define heim_builtin_expect(_op,_res) (_op)
188 #endif
191 typedef void (HEIM_CALLCONV *heim_type_dealloc)(void *);
193 #define heim_assert(e,t) \
194 (heim_builtin_expect(!(e), 0) ? heim_abort(t ":" #e) : (void)0)
201 * Array
204 typedef struct heim_array_data *heim_array_t;
206 typedef void (*heim_array_iterator_f_t)(heim_object_t, void *, int *);
207 typedef int (*heim_array_filter_f_t)(heim_object_t, void *);
210 * Dict
213 typedef struct heim_dict_data *heim_dict_t;
215 typedef void (*heim_dict_iterator_f_t)(heim_object_t, heim_object_t, void *);
218 * String
221 typedef struct heim_string_data *heim_string_t;
222 typedef void (*heim_string_free_f_t)(void *);
224 #define HSTR(_str) (__heim_string_constant("" _str ""))
225 heim_string_t __heim_string_constant(const char *);
228 * Errors
231 typedef struct heim_error * heim_error_t;
234 * Path
238 * Data (octet strings)
241 #ifndef __HEIM_BASE_DATA__
242 #define __HEIM_BASE_DATA__
243 struct heim_base_data {
244 size_t length;
245 void *data;
247 typedef struct heim_base_data heim_octet_string;
248 #endif
250 typedef struct heim_base_data * heim_data_t;
251 typedef void (*heim_data_free_f_t)(void *);
254 * DB
257 typedef struct heim_db_data *heim_db_t;
259 typedef void (*heim_db_iterator_f_t)(heim_data_t, heim_data_t, void *);
261 typedef int (*heim_db_plug_open_f_t)(void *, const char *, const char *,
262 heim_dict_t, void **, heim_error_t *);
263 typedef int (*heim_db_plug_clone_f_t)(void *, void **, heim_error_t *);
264 typedef int (*heim_db_plug_close_f_t)(void *, heim_error_t *);
265 typedef int (*heim_db_plug_lock_f_t)(void *, int, heim_error_t *);
266 typedef int (*heim_db_plug_unlock_f_t)(void *, heim_error_t *);
267 typedef int (*heim_db_plug_sync_f_t)(void *, heim_error_t *);
268 typedef int (*heim_db_plug_begin_f_t)(void *, int, heim_error_t *);
269 typedef int (*heim_db_plug_commit_f_t)(void *, heim_error_t *);
270 typedef int (*heim_db_plug_rollback_f_t)(void *, heim_error_t *);
271 typedef heim_data_t (*heim_db_plug_copy_value_f_t)(void *, heim_string_t,
272 heim_data_t,
273 heim_error_t *);
274 typedef int (*heim_db_plug_set_value_f_t)(void *, heim_string_t, heim_data_t,
275 heim_data_t, heim_error_t *);
276 typedef int (*heim_db_plug_del_key_f_t)(void *, heim_string_t, heim_data_t,
277 heim_error_t *);
278 typedef void (*heim_db_plug_iter_f_t)(void *, heim_string_t, void *,
279 heim_db_iterator_f_t, heim_error_t *);
281 struct heim_db_type {
282 int version;
283 heim_db_plug_open_f_t openf;
284 heim_db_plug_clone_f_t clonef;
285 heim_db_plug_close_f_t closef;
286 heim_db_plug_lock_f_t lockf;
287 heim_db_plug_unlock_f_t unlockf;
288 heim_db_plug_sync_f_t syncf;
289 heim_db_plug_begin_f_t beginf;
290 heim_db_plug_commit_f_t commitf;
291 heim_db_plug_rollback_f_t rollbackf;
292 heim_db_plug_copy_value_f_t copyf;
293 heim_db_plug_set_value_f_t setf;
294 heim_db_plug_del_key_f_t delf;
295 heim_db_plug_iter_f_t iterf;
298 extern struct heim_db_type heim_sorted_text_file_dbtype;
300 #define HEIM_DB_TYPE_VERSION_01 1
303 * Number
306 typedef struct heim_number_data *heim_number_t;
309 * Autorelease
312 typedef struct heim_auto_release * heim_auto_release_t;
315 * JSON
317 typedef enum heim_json_flags {
318 HEIM_JSON_F_NO_C_NULL = 1,
319 HEIM_JSON_F_STRICT_STRINGS = 2,
320 HEIM_JSON_F_NO_DATA = 4,
321 HEIM_JSON_F_NO_DATA_DICT = 8,
322 HEIM_JSON_F_STRICT_DICT = 16,
323 HEIM_JSON_F_STRICT = 31,
324 HEIM_JSON_F_CNULL2JSNULL = 32,
325 HEIM_JSON_F_TRY_DECODE_DATA = 64,
326 HEIM_JSON_F_ONE_LINE = 128,
327 HEIM_JSON_F_ESCAPE_NON_ASCII = 256,
328 HEIM_JSON_F_NO_ESCAPE_NON_ASCII = 512,
329 /* The default is to indent with one tab */
330 HEIM_JSON_F_INDENT2 = 1024,
331 HEIM_JSON_F_INDENT4 = 2048,
332 HEIM_JSON_F_INDENT8 = 4096,
333 } heim_json_flags_t;
336 * Debug
340 * Binary search.
342 * Note: these are private until integrated into the heimbase object system.
344 typedef struct bsearch_file_handle *bsearch_file_handle;
345 int _bsearch_text(const char *buf, size_t buf_sz, const char *key,
346 char **value, size_t *location, size_t *loops);
347 int _bsearch_file_open(const char *fname, size_t max_sz, size_t page_sz,
348 bsearch_file_handle *bfh, size_t *reads);
349 int _bsearch_file(bsearch_file_handle bfh, const char *key, char **value,
350 size_t *location, size_t *loops, size_t *reads);
351 void _bsearch_file_info(bsearch_file_handle bfh, size_t *page_sz,
352 size_t *max_sz, int *blockwise);
353 void _bsearch_file_close(bsearch_file_handle *bfh);
356 * Thread-specific keys
359 #include <heim_threads.h>
360 #include <com_err.h>
363 * Service logging facility (moved from kdc/).
366 #define HEIM_SVC_AUDIT_EATWHITE 0x1
367 #define HEIM_SVC_AUDIT_VIS 0x2
368 #define HEIM_SVC_AUDIT_VISLAST 0x4
370 typedef struct heim_svc_req_desc_common_s *heim_svc_req_desc;
372 #include <heimbase-protos.h>
374 #endif /* HEIM_BASE_H */