4 * @brief Generic types.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
28 #include <sys/types.h>
31 #include <definitions.h>
34 * General purpose boolean type.
41 * error message, or NULL for success
43 typedef const char *err_t
;
45 typedef enum status_t status_t
;
48 * Return values of function calls.
67 * The suggested operation is already done
77 * One of the arguments is invalid.
82 * Something could not be found.
87 * Error while parsing.
92 * Error while verifying.
97 * Object in invalid state.
102 * Destroy object which called method belongs to.
107 * An object got created.
114 * Certificate sending policy
116 typedef enum certpolicy
{
117 CERT_ALWAYS_SEND
= 0,
118 CERT_SEND_IF_ASKED
= 1,
121 CERT_YES_SEND
= 3, /* synonym for CERT_ALWAYS_SEND */
122 CERT_NO_SEND
= 4 /* synonym for CERT_NEVER_SEND */
126 * String mappings for type status_t.
128 extern mapping_t status_m
[];
131 * Handle struct timeval like an own type.
133 typedef struct timeval timeval_t
;
136 * Handle struct timespec like an own type.
138 typedef struct timespec timespec_t
;
141 * Handle struct chunk_t like an own type.
143 typedef struct sockaddr sockaddr_t
;
146 * Use struct chunk_t as chunk_t.
148 typedef struct chunk_t chunk_t
;
151 * General purpose pointer/length abstraction.
155 * Pointer to start of data
160 * Length of data in bytes
166 * {NULL, 0}-chunk, handy for initialization
169 extern chunk_t CHUNK_INITIALIZER
;
172 * Initialize a chunk to a static buffer
174 #define chunk_from_buf(str) { str, sizeof(str) }
177 * Clone chunk contents in a newly allocated chunk
179 chunk_t
chunk_clone(chunk_t chunk
);
182 * Free contents of a chunk
184 void chunk_free(chunk_t
*chunk
);
189 chunk_t
chunk_alloc(size_t bytes
);
192 * Compare two chunks for equality,
193 * NULL chunks are never equal.
195 bool chunk_equals(chunk_t a
, chunk_t b
);
198 * Print a chunk in hexadecimal form
199 * with each byte separated by a colon
201 void chunk_to_hex(char *buf
, size_t buflen
, chunk_t chunk
);
204 * Clone a data to a newly allocated buffer
206 void *clalloc(void *pointer
, size_t size
);
208 #define UNDEFINED_TIME 0
209 #define TIMETOA_BUF 30
212 * @brief Display a date either in local or UTC time
214 * @param buf buffer where displayed time will be written to
215 * @param buflen buffer length
216 * @param time time to be displayed
217 * @param utc UTC (TRUE) or local time (FALSE)
220 void timetoa(char *buf
, size_t buflen
, const time_t *time
, bool utc
);