Moved generic RADIUS protocol support to a dedicated libradius
[strongswan.git] / src / pluto / defs.h
1 /* misc. universal things
2 * Copyright (C) 1997 Angelos D. Keromytis.
3 * Copyright (C) 1998-2001 D. Hugh Redelmeier.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #ifndef _DEFS_H
17 #define _DEFS_H
18
19 #include <string.h>
20 #include <sys/types.h>
21
22 #include <chunk.h>
23
24 #ifdef DEBUG
25 # define USED_BY_DEBUG /* ignore */
26 #else
27 # define USED_BY_DEBUG UNUSED
28 #endif
29
30 /* type of serial number of a state object
31 * Needed in connections.h and state.h; here to simplify dependencies.
32 */
33 typedef unsigned long so_serial_t;
34 #define SOS_NOBODY 0 /* null serial number */
35 #define SOS_FIRST 1 /* first normal serial number */
36
37 /* memory allocation */
38
39 #define clone_thing(orig) clalloc((void *)&(orig), sizeof(orig))
40
41 #define clone_str(str) \
42 ((str) == NULL? NULL : strdup(str))
43
44 #define replace(p, q) \
45 { free(p); (p) = (q); }
46
47 #define chunkcpy(dst, chunk) \
48 { memcpy(dst, chunk.ptr, chunk.len); dst += chunk.len;}
49
50 extern char* temporary_cyclic_buffer(void);
51 extern char* concatenate_paths(char *a, char *b);
52
53 /* move a chunk to a memory position and free it after insertion */
54 extern void mv_chunk(u_char **pos, chunk_t content);
55
56 /* warns a predefined interval before expiry */
57 extern const char* check_expiry(time_t expiration_date,
58 int warning_interval, bool strict);
59
60 #define MAX_PROMPT_PASS_TRIALS 5
61 #define PROMPT_PASS_LEN 64
62
63 /* filter eliminating the directory entries '.' and '..' */
64 typedef struct dirent dirent_t;
65 extern int file_select(const dirent_t *entry);
66
67 /* cleanly exit Pluto */
68 extern void exit_pluto(int /*status*/) NEVER_RETURNS;
69
70 /* zero all bytes */
71 #define zero(x) memset((x), '\0', sizeof(*(x)))
72
73 /* are all bytes 0? */
74 extern bool all_zero(const unsigned char *m, size_t len);
75
76 /* pad_up(n, m) is the amount to add to n to make it a multiple of m */
77 #define pad_up(n, m) (((m) - 1) - (((n) + (m) - 1) % (m)))
78
79 #endif /* _DEFS_H */