- x509 certificate loading with pluto asn1 code
[strongswan.git] / Source / lib / 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 /**
35 * General purpose boolean type.
36 */
37 typedef int bool;
38 #define FALSE 0
39 #define TRUE 1
40
41 typedef enum status_t status_t;
42
43 /**
44 * Return values of function calls.
45 */
46 enum status_t {
47 /**
48 * Call succeeded.
49 */
50 SUCCESS,
51
52 /**
53 * Call failed.
54 */
55 FAILED,
56
57 /**
58 * Out of ressources.
59 */
60
61 OUT_OF_RES,
62 /**
63 * Already done.
64 */
65 ALREADY_DONE,
66
67 /**
68 * Not supported.
69 */
70 NOT_SUPPORTED,
71
72 /**
73 * One of the arguments is invalid.
74 */
75 INVALID_ARG,
76
77 /**
78 * Something could not be found.
79 */
80 NOT_FOUND,
81
82 /**
83 * Error while parsing.
84 */
85 PARSE_ERROR,
86
87 /**
88 * Error while verifying.
89 */
90 VERIFY_ERROR,
91
92 /**
93 * Object in invalid state.
94 */
95 INVALID_STATE,
96
97 /**
98 * Delete object which function belongs to.
99 */
100 DELETE_ME,
101
102 /**
103 * An object got created.
104 */
105 CREATED,
106 };
107
108
109 /**
110 * String mappings for type status_t.
111 */
112 extern mapping_t status_m[];
113
114 /**
115 * Handle struct timeval like an own type.
116 */
117 typedef struct timeval timeval_t;
118
119 /**
120 * Handle struct timespec like an own type.
121 */
122 typedef struct timespec timespec_t;
123
124 /**
125 * Handle struct chunk_t like an own type.
126 */
127 typedef struct sockaddr sockaddr_t;
128
129 /**
130 * Use struct chunk_t as chunk_t.
131 */
132 typedef struct chunk_t chunk_t;
133
134 /**
135 * General purpose pointer/length abstraction.
136 */
137 struct chunk_t {
138 /**
139 * Pointer to start of data
140 */
141 u_char *ptr;
142
143 /**
144 * Length of data in bytes
145 */
146 size_t len;
147 };
148
149 /**
150 * {NULL, 0}-chunk, handy for initialization
151 * of chunks.
152 */
153 extern chunk_t CHUNK_INITIALIZER;
154
155 /**
156 * Initialize a chunk to a static buffer
157 */
158 #define chunk_from_buf(str) { str, sizeof(str) }
159
160 /**
161 * Clone chunk contents in a newly allocated chunk
162 */
163 chunk_t chunk_clone(chunk_t chunk);
164
165 /**
166 * Free contents of a chunk
167 */
168 void chunk_free(chunk_t *chunk);
169
170 /**
171 * Allocate a chunk
172 */
173 chunk_t chunk_alloc(size_t bytes);
174
175 /**
176 * Compare two chunks for equality,
177 * NULL chunks are never equal.
178 */
179 bool chunk_equals(chunk_t a, chunk_t b);
180
181 /**
182 * Clone a data to a newly allocated buffer
183 */
184 void *clalloc(void *pointer, size_t size);
185
186
187 #endif /*TYPES_H_*/