(no commit message)
[strongswan.git] / src / charon / encoding / payloads / cp_payload.h
1 /**
2 * @file cp_payload.h
3 *
4 * @brief Interface of cp_payload_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
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>.
16 *
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
20 * for more details.
21 */
22
23 #ifndef CP_PAYLOAD_H_
24 #define CP_PAYLOAD_H_
25
26 #include <types.h>
27 #include <encoding/payloads/payload.h>
28 #include <encoding/payloads/configuration_attribute.h>
29 #include <utils/linked_list.h>
30
31 /**
32 * CP_PAYLOAD length in bytes without any proposal substructure.
33 *
34 * @ingroup payloads
35 */
36 #define CP_PAYLOAD_HEADER_LENGTH 8
37
38
39 typedef enum config_type_t config_type_t;
40
41 /**
42 * Config Type of an Configuration Payload.
43 *
44 * @ingroup payloads
45 */
46 enum config_type_t {
47 CFG_REQUEST = 1,
48 CFG_REPLY = 2,
49 CFG_SET = 3,
50 CFG_ACK = 4,
51 };
52
53 /**
54 * string mappings for config_type_t.
55 *
56 * @ingroup payloads
57 */
58 extern mapping_t config_type_m[];
59
60
61 typedef struct cp_payload_t cp_payload_t;
62
63 /**
64 * @brief Class representing an IKEv2-CP Payload.
65 *
66 * The CP Payload format is described in RFC section 3.15.
67 *
68 * @b Constructors:
69 * - cp_payload_create()
70 *
71 * @ingroup payloads
72 */
73 struct cp_payload_t {
74 /**
75 * The payload_t interface.
76 */
77 payload_t payload_interface;
78
79 /**
80 * @brief Creates an iterator of stored configuration_attribute_t objects.
81 *
82 * @warning The created iterator has to get destroyed by the caller!
83 *
84 * @warning When deleting an attribute using this iterator,
85 * the length of this configuration_attribute_t has to be refreshed
86 * by calling get_length()!
87 *
88 * @param this calling cp_payload_t object
89 * @param[in] forward iterator direction (TRUE: front to end)
90 * @return created iterator_t object
91 */
92 iterator_t *(*create_configuration_attribute_iterator) (cp_payload_t *this, bool forward);
93
94 /**
95 * @brief Adds a configuration_attribute_t object to this object.
96 *
97 * @warning The added configuration_attribute_t object is
98 * getting destroyed in destroy function of cp_payload_t.
99 *
100 * @param this calling cp_payload_t object
101 * @param attribute configuration_attribute_t object to add
102 */
103 void (*add_configuration_attribute) (cp_payload_t *this, configuration_attribute_t *attribute);
104
105 /**
106 * @brief Set the config type.
107 *
108 * @param this calling cp_payload_t object
109 * @param config_type config_type_t to set
110 */
111 void (*set_config_type) (cp_payload_t *this,config_type_t config_type);
112
113 /**
114 * @brief Get the config type.
115 *
116 * @param this calling cp_payload_t object
117 * @return config_type_t
118 */
119 config_type_t (*get_config_type) (cp_payload_t *this);
120
121 /**
122 * @brief Destroys an cp_payload_t object.
123 *
124 * @param this cp_payload_t object to destroy
125 */
126 void (*destroy) (cp_payload_t *this);
127 };
128
129 /**
130 * @brief Creates an empty cp_payload_t object
131 *
132 * @return cp_payload_t object
133 *
134 * @ingroup payloads
135 */
136 cp_payload_t *cp_payload_create(void);
137
138 #endif /*CP_PAYLOAD_H_*/