readded local_credential_store
[strongswan.git] / src / libstrongswan / types.h
1 /**
2 * @file types.h
3 *
4 * @brief Generic types.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23
24 #ifndef TYPES_H_
25 #define TYPES_H_
26
27 #include <gmp.h>
28 #include <sys/types.h>
29 #include <stdlib.h>
30
31 #include <definitions.h>
32
33 /**
34 * General purpose boolean type.
35 */
36 typedef int bool;
37 #define FALSE 0
38 #define TRUE 1
39
40 /**
41 * error message, or NULL for success
42 */
43 typedef const char *err_t;
44
45 typedef enum status_t status_t;
46
47 /**
48 * Return values of function calls.
49 */
50 enum status_t {
51 /**
52 * Call succeeded.
53 */
54 SUCCESS,
55
56 /**
57 * Call failed.
58 */
59 FAILED,
60
61 /**
62 * Out of resources.
63 */
64 OUT_OF_RES,
65
66 /**
67 * The suggested operation is already done
68 */
69 ALREADY_DONE,
70
71 /**
72 * Not supported.
73 */
74 NOT_SUPPORTED,
75
76 /**
77 * One of the arguments is invalid.
78 */
79 INVALID_ARG,
80
81 /**
82 * Something could not be found.
83 */
84 NOT_FOUND,
85
86 /**
87 * Error while parsing.
88 */
89 PARSE_ERROR,
90
91 /**
92 * Error while verifying.
93 */
94 VERIFY_ERROR,
95
96 /**
97 * Object in invalid state.
98 */
99 INVALID_STATE,
100
101 /**
102 * Destroy object which called method belongs to.
103 */
104 DESTROY_ME,
105
106 /**
107 * An object got created.
108 */
109 CREATED,
110 };
111
112 /**
113 * RFC 2459 CRL reason codes
114 */
115
116 /* TODO extern enum_names crl_reason_names; */
117
118 typedef enum {
119 REASON_UNSPECIFIED = 0,
120 REASON_KEY_COMPROMISE = 1,
121 REASON_CA_COMPROMISE = 2,
122 REASON_AFFILIATION_CHANGED = 3,
123 REASON_SUPERSEDED = 4,
124 REASON_CESSATION_OF_OPERATON = 5,
125 REASON_CERTIFICATE_HOLD = 6,
126 REASON_REMOVE_FROM_CRL = 8
127 } crl_reason_t;
128
129 /**
130 * String mappings for type status_t.
131 */
132 extern mapping_t status_m[];
133
134 /**
135 * Handle struct timeval like an own type.
136 */
137 typedef struct timeval timeval_t;
138
139 /**
140 * Handle struct timespec like an own type.
141 */
142 typedef struct timespec timespec_t;
143
144 /**
145 * Handle struct chunk_t like an own type.
146 */
147 typedef struct sockaddr sockaddr_t;
148
149 /**
150 * Use struct chunk_t as chunk_t.
151 */
152 typedef struct chunk_t chunk_t;
153
154 /**
155 * General purpose pointer/length abstraction.
156 */
157 struct chunk_t {
158 /**
159 * Pointer to start of data
160 */
161 u_char *ptr;
162
163 /**
164 * Length of data in bytes
165 */
166 size_t len;
167 };
168
169 /**
170 * used to initialize a chunk to { NULL, 0 }.
171 */
172 extern chunk_t CHUNK_INITIALIZER;
173
174 /**
175 * Initialize a chunk to a static buffer
176 */
177 #define chunk_from_buf(str) { str, sizeof(str) }
178
179 /**
180 * Clone chunk contents in a newly allocated chunk
181 */
182 chunk_t chunk_clone(chunk_t chunk);
183
184 /**
185 * Free contents of a chunk
186 */
187 void chunk_free(chunk_t *chunk);
188
189 /**
190 * Allocate a chunk
191 */
192 chunk_t chunk_alloc(size_t bytes);
193
194 /**
195 * Compare two chunks for equality,
196 * NULL chunks are never equal.
197 */
198 bool chunk_equals(chunk_t a, chunk_t b);
199
200 /**
201 * Compare two chunks for equality,
202 * NULL chunks are always equal.
203 */
204 bool chunk_equals_or_null(chunk_t a, chunk_t b);
205
206 /**
207 * Print a chunk in hexadecimal form
208 * with each byte separated by a colon
209 */
210 void chunk_to_hex(char *buf, size_t buflen, chunk_t chunk);
211
212 /**
213 * Clone a data to a newly allocated buffer
214 */
215 void *clalloc(void *pointer, size_t size);
216
217 #define UNDEFINED_TIME 0
218 #define TIMETOA_BUF 30
219
220 /**
221 * @brief Display a date either in local or UTC time
222 *
223 * @param buf buffer where displayed time will be written to
224 * @param buflen buffer length
225 * @param time time to be displayed
226 * @param utc UTC (TRUE) or local time (FALSE)
227 *
228 */
229 void timetoa(char *buf, size_t buflen, const time_t *time, bool utc);
230
231 #endif /*TYPES_H_*/