eliminated TIMETOA_BUF definition
[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 * RCSID $Id$
16 */
17
18 #ifndef _DEFS_H
19 #define _DEFS_H
20
21 #include <string.h>
22 #include <sys/types.h>
23
24 #include <chunk.h>
25
26 #ifdef KLIPS
27 # define USED_BY_KLIPS /* ignore */
28 #else
29 # define USED_BY_KLIPS UNUSED
30 #endif
31
32 #ifdef DEBUG
33 # define USED_BY_DEBUG /* ignore */
34 #else
35 # define USED_BY_DEBUG UNUSED
36 #endif
37
38 /* type of serial number of a state object
39 * Needed in connections.h and state.h; here to simplify dependencies.
40 */
41 typedef unsigned long so_serial_t;
42 #define SOS_NOBODY 0 /* null serial number */
43 #define SOS_FIRST 1 /* first normal serial number */
44
45 /* memory allocation */
46
47 extern void *clone_bytes(const void *orig, size_t size);
48
49 #define clone_thing(orig) clone_bytes((const void *)&(orig), sizeof(orig))
50
51 #define clone_str(str) \
52 ((str) == NULL? NULL : strdup(str))
53
54 #define replace(p, q) \
55 { free(p); (p) = (q); }
56
57 #define chunkcpy(dst, chunk) \
58 { memcpy(dst, chunk.ptr, chunk.len); dst += chunk.len;}
59
60 extern char* temporary_cyclic_buffer(void);
61 extern const char* concatenate_paths(const char *a, const char *b);
62
63 /* move a chunk to a memory position and free it after insertion */
64 extern void mv_chunk(u_char **pos, chunk_t content);
65
66 /* write the binary contents of a chunk_t to a file */
67 extern bool write_chunk(const char *filename, const char *label, chunk_t ch
68 ,mode_t mask, bool force);
69
70 /* warns a predefined interval before expiry */
71 extern const char* check_expiry(time_t expiration_date,
72 int warning_interval, bool strict);
73
74 #define MAX_PROMPT_PASS_TRIALS 5
75 #define PROMPT_PASS_LEN 64
76
77 /* struct used to prompt for a secret passphrase
78 * from a console with file descriptor fd
79 */
80 typedef struct {
81 char secret[PROMPT_PASS_LEN+1];
82 bool prompt;
83 int fd;
84 } prompt_pass_t;
85
86 /* filter eliminating the directory entries '.' and '..' */
87 typedef struct dirent dirent_t;
88 extern int file_select(const dirent_t *entry);
89
90 /* cleanly exit Pluto */
91
92 extern void exit_pluto(int /*status*/) NEVER_RETURNS;
93
94
95 /* zero all bytes */
96 #define zero(x) memset((x), '\0', sizeof(*(x)))
97
98 /* are all bytes 0? */
99 extern bool all_zero(const unsigned char *m, size_t len);
100
101 /* pad_up(n, m) is the amount to add to n to make it a multiple of m */
102 #define pad_up(n, m) (((m) - 1) - (((n) + (m) - 1) % (m)))
103
104 #endif /* _DEFS_H */