7bc4639d42368b284700daa9be5773531a0b6683
[strongswan.git] / src / libcharon / plugins / tnccs_20 / batch / pb_tnc_batch.h
1 /*
2 * Copyright (C) 2010 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
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 /**
17 * @defgroup pb_tnc_batch pb_tnc_batch
18 * @{ @ingroup tnccs_20
19 */
20
21 #ifndef PB_TNC_BATCH_H_
22 #define PB_TNC_BATCH_H_
23
24 #include "messages/pb_tnc_message.h"
25
26 #include <library.h>
27
28 typedef enum pb_tnc_state_t pb_tnc_state_t;
29
30 /**
31 * PB-TNC States (State machine) as defined in section 3.2 of RFC 5793
32 */
33 enum pb_tnc_state_t {
34 PB_STATE_INIT,
35 PB_STATE_SERVER_WORKING,
36 PB_STATE_CLIENT_WORKING,
37 PB_STATE_DECIDED,
38 PB_STATE_END,
39 };
40
41 /**
42 * enum name for pb_tnc_state_t.
43 */
44 extern enum_name_t *pb_tnc_state_names;
45
46 typedef enum pb_tnc_batch_type_t pb_tnc_batch_type_t;
47
48 /**
49 * PB-TNC Batch Types as defined in section 4.1 of RFC 5793
50 */
51 enum pb_tnc_batch_type_t {
52 PB_BATCH_CDATA = 1,
53 PB_BATCH_SDATA = 2,
54 PB_BATCH_RESULT = 3,
55 PB_BATCH_CRETRY = 4,
56 PB_BATCH_SRETRY = 5,
57 PB_BATCH_CLOSE = 6,
58 PB_BATCH_ROOF = 6
59 };
60
61 typedef struct pb_tnc_batch_t pb_tnc_batch_t;
62
63 /**
64 * enum name for pb_tnc_batch_type_t.
65 */
66 extern enum_name_t *pb_tnc_batch_type_names;
67
68 /**
69 * Interface for all PB-TNC Batch Types.
70 */
71 struct pb_tnc_batch_t {
72
73 /**
74 * Get the PB-TNC Message Type
75 *
76 * @return PB-TNC batch type
77 */
78 pb_tnc_batch_type_t (*get_type)(pb_tnc_batch_t *this);
79
80 /**
81 * Get the encoding of the PB-TNC Batch
82 *
83 * @return encoded PB-TNC batch
84 */
85 chunk_t (*get_encoding)(pb_tnc_batch_t *this);
86
87 /**
88 * Add a PB-TNC Message
89 *
90 * @param msg PB-TNC message to be addedd
91 */
92 void (*add_message)(pb_tnc_batch_t *this, pb_tnc_message_t* msg);
93
94 /**
95 * Build the PB-TNC Batch
96 */
97 void (*build)(pb_tnc_batch_t *this);
98
99 /**
100 * Process the PB-TNC Batch
101 *
102 * @param in: current state, out: new state
103 * @return return processing status
104 */
105 status_t (*process)(pb_tnc_batch_t *this, pb_tnc_state_t *state);
106
107 /**
108 * Enumerates over all PB-TNC Messages
109 *
110 * @return return message enumerator
111 */
112 enumerator_t* (*create_msg_enumerator)(pb_tnc_batch_t *this);
113
114 /**
115 * Enumerates over all parsing errors
116 *
117 * @return return error enumerator
118 */
119 enumerator_t* (*create_error_enumerator)(pb_tnc_batch_t *this);
120
121 /**
122 * Destroys a pb_tnc_batch_t object.
123 */
124 void (*destroy)(pb_tnc_batch_t *this);
125 };
126
127 /**
128 * Create an empty PB-TNC Batch of a given type
129 *
130 * @parame is_server TRUE if server, FALSE if client
131 * @param type PB-TNC batch type
132 */
133 pb_tnc_batch_t* pb_tnc_batch_create(bool is_server, pb_tnc_batch_type_t type);
134
135 /**
136 * Create an unprocessed PB-TNC Batch from data
137 *
138 * @parame is_server TRUE if server, FALSE if client
139 * @param data encoded PB-TNC batch
140 */
141 pb_tnc_batch_t* pb_tnc_batch_create_from_data(bool is_server, chunk_t data);
142
143 #endif /** PB_TNC_BATCH_H_ @}*/