moved batch size calculation into pb_tnc_batch_t
[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 typedef enum pb_tnc_batch_type_t pb_tnc_batch_type_t;
25 typedef struct pb_tnc_batch_t pb_tnc_batch_t;
26
27 #include "messages/pb_tnc_msg.h"
28 #include "state_machine/pb_tnc_state_machine.h"
29
30 #include <library.h>
31
32 /**
33 * PB-TNC Batch Types as defined in section 4.1 of RFC 5793
34 */
35 enum pb_tnc_batch_type_t {
36 PB_BATCH_NONE = 0, /* for internal use only */
37 PB_BATCH_CDATA = 1,
38 PB_BATCH_SDATA = 2,
39 PB_BATCH_RESULT = 3,
40 PB_BATCH_CRETRY = 4,
41 PB_BATCH_SRETRY = 5,
42 PB_BATCH_CLOSE = 6,
43 PB_BATCH_ROOF = 6
44 };
45
46 /**
47 * enum name for pb_tnc_batch_type_t.
48 */
49 extern enum_name_t *pb_tnc_batch_type_names;
50
51 /**
52 * Interface for all PB-TNC Batch Types.
53 */
54 struct pb_tnc_batch_t {
55
56 /**
57 * Get the PB-TNC Message Type
58 *
59 * @return PB-TNC batch type
60 */
61 pb_tnc_batch_type_t (*get_type)(pb_tnc_batch_t *this);
62
63 /**
64 * Get the encoding of the PB-TNC Batch
65 *
66 * @return encoded PB-TNC batch
67 */
68 chunk_t (*get_encoding)(pb_tnc_batch_t *this);
69
70 /**
71 * Add a PB-TNC Message
72 *
73 * @param msg PB-TNC message to be addedd
74 * @return TRUE if message fit into batch and was added
75 */
76 bool (*add_msg)(pb_tnc_batch_t *this, pb_tnc_msg_t* msg);
77
78 /**
79 * Build the PB-TNC Batch
80 */
81 void (*build)(pb_tnc_batch_t *this);
82
83 /**
84 * Process the PB-TNC Batch
85 *
86 * @param PB-TNC state machine
87 * @return return processing status
88 */
89 status_t (*process)(pb_tnc_batch_t *this,
90 pb_tnc_state_machine_t *state_machine);
91
92 /**
93 * Enumerates over all PB-TNC Messages
94 *
95 * @return return message enumerator
96 */
97 enumerator_t* (*create_msg_enumerator)(pb_tnc_batch_t *this);
98
99 /**
100 * Enumerates over all parsing errors
101 *
102 * @return return error enumerator
103 */
104 enumerator_t* (*create_error_enumerator)(pb_tnc_batch_t *this);
105
106 /**
107 * Destroys a pb_tnc_batch_t object.
108 */
109 void (*destroy)(pb_tnc_batch_t *this);
110 };
111
112 /**
113 * Create an empty PB-TNC Batch of a given type
114 *
115 * @param is_server TRUE if server, FALSE if client
116 * @param type PB-TNC batch type
117 * @param max_batch_len maximum size the PB-TNC batch
118 */
119 pb_tnc_batch_t* pb_tnc_batch_create(bool is_server, pb_tnc_batch_type_t type,
120 size_t max_batch_len);
121
122 /**
123 * Create an unprocessed PB-TNC Batch from data
124 *
125 * @param is_server TRUE if server, FALSE if client
126 * @param data encoded PB-TNC batch
127 */
128 pb_tnc_batch_t* pb_tnc_batch_create_from_data(bool is_server, chunk_t data);
129
130 #endif /** PB_TNC_BATCH_H_ @}*/