]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libstrongswan/metadata/metadata.h
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / libstrongswan / metadata / metadata.h
1 /*
2 * Copyright (C) 2021 Tobias Brunner
3 * Copyright (C) 2021 Thomas Egerer
4 *
5 * Copyright (C) secunet Security Networks AG
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup metadata metadata
20 * @ingroup libstrongswan
21 *
22 * @defgroup metadata_t metadata
23 * @{ @ingroup metadata
24 */
25
26 #ifndef METADATA_H_
27 #define METADATA_H_
28
29 #include <utils/utils.h>
30
31 typedef struct metadata_t metadata_t;
32
33 /**
34 * Pre-defined metadata type for int values. Note that while the constructor and
35 * equals() work with integer values/types smaller than int (such values get
36 * promoted to int when passed via ...), get() does not and expects a pointer to
37 * an int variable.
38 */
39 #define METADATA_TYPE_INT "int"
40
41 /**
42 * Pre-defined metadata type for uint64_t values. Make sure to pass only
43 * uint64_t values/variables also to the constructor and equals() (or cast them
44 * appropriately there).
45 */
46 #define METADATA_TYPE_UINT64 "uint64"
47
48 /**
49 * Metadata object to allow storing arbitrary values in an encapsulated
50 * object.
51 */
52 struct metadata_t {
53
54 /**
55 * Return the type of the metadata object.
56 *
57 * @return string type of the metadata object
58 */
59 const char *(*get_type)(metadata_t *this);
60
61 /**
62 * Clone this metadata object.
63 *
64 * @return a cloned instance
65 */
66 metadata_t *(*clone)(metadata_t *this);
67
68 /**
69 * Compare this to another value (or values, depending on the type).
70 *
71 * @param ... value(s) (raw, not metadata_t) to compare this to
72 * @return TRUE if value is equal to metadata value
73 */
74 bool (*equals)(metadata_t *this, ...);
75
76 /**
77 * Retrieve the values via variadic argument(s).
78 *
79 * @param ... pointer(s) to obtain metadata value(s)
80 */
81 void (*get)(metadata_t *this, ...);
82
83 /**
84 * Destroy this metadata object.
85 */
86 void (*destroy)(metadata_t *this);
87 };
88
89 /**
90 * Constructor type for metadata objects.
91 *
92 * @param type type of the metadata object, allows using the same
93 * constructor for different types
94 * @param args type-specific arguments
95 * @return metadata object, NULL on failure
96 */
97 typedef metadata_t *(*metadata_create_t)(const char *type, va_list args);
98
99 #endif /** METADATA_H_ @}*/