updated Copyright info
[strongswan.git] / src / libimcv / ita / ita_attr_command.c
1 /*
2 * Copyright (C) 2011-2012 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 #include "ita_attr.h"
17 #include "ita_attr_command.h"
18
19 #include <pen/pen.h>
20
21 #include <debug.h>
22
23 typedef struct private_ita_attr_command_t private_ita_attr_command_t;
24
25 /**
26 * Private data of an ita_attr_command_t object.
27 */
28 struct private_ita_attr_command_t {
29
30 /**
31 * Public members of ita_attr_command_t
32 */
33 ita_attr_command_t public;
34
35 /**
36 * Attribute vendor ID
37 */
38 pen_t vendor_id;
39
40 /**
41 * Attribute type
42 */
43 u_int32_t type;
44
45 /**
46 * Attribute value
47 */
48 chunk_t value;
49
50 /**
51 * Noskip flag
52 */
53 bool noskip_flag;
54
55 /**
56 * Command string
57 */
58 char *command;
59
60 /**
61 * Reference count
62 */
63 refcount_t ref;
64 };
65
66 METHOD(pa_tnc_attr_t, get_vendor_id, pen_t,
67 private_ita_attr_command_t *this)
68 {
69 return this->vendor_id;
70 }
71
72 METHOD(pa_tnc_attr_t, get_type, u_int32_t,
73 private_ita_attr_command_t *this)
74 {
75 return this->type;
76 }
77
78 METHOD(pa_tnc_attr_t, get_value, chunk_t,
79 private_ita_attr_command_t *this)
80 {
81 return this->value;
82 }
83
84 METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
85 private_ita_attr_command_t *this)
86 {
87 return this->noskip_flag;
88 }
89
90 METHOD(pa_tnc_attr_t, set_noskip_flag,void,
91 private_ita_attr_command_t *this, bool noskip)
92 {
93 this->noskip_flag = noskip;
94 }
95
96 METHOD(pa_tnc_attr_t, build, void,
97 private_ita_attr_command_t *this)
98 {
99 if (this->value.ptr)
100 {
101 return;
102 }
103 this->value = chunk_create(this->command, strlen(this->command));
104 this->value = chunk_clone(this->value);
105 }
106
107 METHOD(pa_tnc_attr_t, process, status_t,
108 private_ita_attr_command_t *this, u_int32_t *offset)
109 {
110 this->command = malloc(this->value.len + 1);
111 memcpy(this->command, this->value.ptr, this->value.len);
112 this->command[this->value.len] = '\0';
113
114 return SUCCESS;
115 }
116
117 METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*,
118 private_ita_attr_command_t *this)
119 {
120 ref_get(&this->ref);
121 return &this->public.pa_tnc_attribute;
122 }
123
124 METHOD(pa_tnc_attr_t, destroy, void,
125 private_ita_attr_command_t *this)
126 {
127 if (ref_put(&this->ref))
128 {
129 free(this->value.ptr);
130 free(this->command);
131 free(this);
132 }
133 }
134
135 METHOD(ita_attr_command_t, get_command, char*,
136 private_ita_attr_command_t *this)
137 {
138 return this->command;
139 }
140
141 /**
142 * Described in header.
143 */
144 pa_tnc_attr_t *ita_attr_command_create(char *command)
145 {
146 private_ita_attr_command_t *this;
147
148 INIT(this,
149 .public = {
150 .pa_tnc_attribute = {
151 .get_vendor_id = _get_vendor_id,
152 .get_type = _get_type,
153 .get_value = _get_value,
154 .get_noskip_flag = _get_noskip_flag,
155 .set_noskip_flag = _set_noskip_flag,
156 .build = _build,
157 .process = _process,
158 .get_ref = _get_ref,
159 .destroy = _destroy,
160 },
161 .get_command = _get_command,
162 },
163 .vendor_id = PEN_ITA,
164 .type = ITA_ATTR_COMMAND,
165 .command = strdup(command),
166 .ref = 1,
167 );
168
169 return &this->public.pa_tnc_attribute;
170 }
171
172 /**
173 * Described in header.
174 */
175 pa_tnc_attr_t *ita_attr_command_create_from_data(chunk_t data)
176 {
177 private_ita_attr_command_t *this;
178
179 INIT(this,
180 .public = {
181 .pa_tnc_attribute = {
182 .get_vendor_id = _get_vendor_id,
183 .get_type = _get_type,
184 .get_value = _get_value,
185 .build = _build,
186 .process = _process,
187 .get_ref = _get_ref,
188 .destroy = _destroy,
189 },
190 .get_command = _get_command,
191 },
192 .vendor_id = PEN_ITA,
193 .type = ITA_ATTR_COMMAND,
194 .value = chunk_clone(data),
195 .ref = 1,
196 );
197
198 return &this->public.pa_tnc_attribute;
199 }
200
201