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