4 * @brief General purpose definitions and macros.
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
12 * Copyright (C) 1998, 1999 D. Hugh Redelmeier. (Endian stuff)
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 #ifndef DEFINITIONS_H_
26 #define DEFINITIONS_H_
30 /* stolen from FreeS/WAN */
32 # if defined(i386) && !defined(__i386__)
34 # define MYHACKFORTHIS 1
41 #elif !(defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN) && defined(BYTE_ORDER))
42 /* we don't know how to do this, so we require the macros to be defined
43 * with compiler flags:
44 * -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=BIG_ENDIAN
45 * or -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=LITTLE_ENDIAN
46 * Thse match the GNU definitions
48 # include <sys/endian.h>
52 #error "BIG_ENDIAN must be defined"
56 #error "LITTLE_ENDIAN must be defined"
60 #error "BYTE_ORDER must be defined"
63 #define BITS_PER_BYTE 8
64 #define RSA_MIN_OCTETS (1024 / BITS_PER_BYTE)
65 #define RSA_MIN_OCTETS_UGH "RSA modulus too small for security: less than 1024 bits"
66 #define RSA_MAX_OCTETS (8192 / BITS_PER_BYTE)
67 #define RSA_MAX_OCTETS_UGH "RSA modulus too large: more than 8192 bits"
70 * Default length for various auxiliary text buffers
75 * Macro compares two strings for equality
77 #define streq(x,y) (strcmp(x, y) == 0)
80 * Macro compares two binary blobs for equality
82 #define memeq(x,y,len) (memcmp(x, y, len) == 0)
85 * Macro gives back larger of two values.
87 #define max(x,y) ((x) > (y) ? (x):(y))
90 * Macro gives back smaller of two values.
92 #define min(x,y) ((x) < (y) ? (x):(y))
95 * Call destructor of a object if object != NULL
97 #define DESTROY_IF(obj) if (obj) obj->destroy(obj)
100 * Debug macro to follow control flow
102 #define POS printf("%s, line %d\n", __FILE__, __LINE__)
105 * Macro to allocate a sized type.
107 * @param thing object on which a sizeof is performed
108 * @return poiner to allocated memory
110 #define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
114 * Mapping entry which defines the end of a mapping_t array.
116 #define MAPPING_END (-1)
118 typedef struct mapping_t mapping_t
;
121 * @brief Mapping entry, where enum-to-string mappings are stored.
138 * @brief Find a mapping_string in the mapping[].
140 * @param mappings mappings array
141 * @param value enum-value to get the string from
144 char *mapping_find(mapping_t
*mappings
, int value
);
147 * @brief Describes an enumeration
148 * enum_name() returns the name of an enum value, or NULL if invalid.
150 typedef const struct enum_names enum_names
;
153 unsigned long en_first
; /* first value in range */
154 unsigned long en_last
; /* last value in range (inclusive) */
155 const char *const *en_names
;
156 enum_names
*en_next_range
; /* descriptor of next range */
160 * @brief Returns the name of an enum value, or NULL if invalid
162 const char *enum_name(enum_names
*ed
, unsigned long val
);
164 #endif /*DEFINITIONS_H_*/