Added missing noskip_flag setter/getter to some pa_tnc_attr_t constructors
[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 <utils/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 * Vendor-specific attribute type
37 */
38 pen_type_t type;
39
40 /**
41 * Attribute value
42 */
43 chunk_t value;
44
45 /**
46 * Noskip flag
47 */
48 bool noskip_flag;
49
50 /**
51 * Command string
52 */
53 char *command;
54
55 /**
56 * Reference count
57 */
58 refcount_t ref;
59 };
60
61 METHOD(pa_tnc_attr_t, get_type, pen_type_t,
62 private_ita_attr_command_t *this)
63 {
64 return this->type;
65 }
66
67 METHOD(pa_tnc_attr_t, get_value, chunk_t,
68 private_ita_attr_command_t *this)
69 {
70 return this->value;
71 }
72
73 METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
74 private_ita_attr_command_t *this)
75 {
76 return this->noskip_flag;
77 }
78
79 METHOD(pa_tnc_attr_t, set_noskip_flag,void,
80 private_ita_attr_command_t *this, bool noskip)
81 {
82 this->noskip_flag = noskip;
83 }
84
85 METHOD(pa_tnc_attr_t, build, void,
86 private_ita_attr_command_t *this)
87 {
88 if (this->value.ptr)
89 {
90 return;
91 }
92 this->value = chunk_create(this->command, strlen(this->command));
93 this->value = chunk_clone(this->value);
94 }
95
96 METHOD(pa_tnc_attr_t, process, status_t,
97 private_ita_attr_command_t *this, u_int32_t *offset)
98 {
99 this->command = malloc(this->value.len + 1);
100 memcpy(this->command, this->value.ptr, this->value.len);
101 this->command[this->value.len] = '\0';
102
103 return SUCCESS;
104 }
105
106 METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*,
107 private_ita_attr_command_t *this)
108 {
109 ref_get(&this->ref);
110 return &this->public.pa_tnc_attribute;
111 }
112
113 METHOD(pa_tnc_attr_t, destroy, void,
114 private_ita_attr_command_t *this)
115 {
116 if (ref_put(&this->ref))
117 {
118 free(this->value.ptr);
119 free(this->command);
120 free(this);
121 }
122 }
123
124 METHOD(ita_attr_command_t, get_command, char*,
125 private_ita_attr_command_t *this)
126 {
127 return this->command;
128 }
129
130 /**
131 * Described in header.
132 */
133 pa_tnc_attr_t *ita_attr_command_create(char *command)
134 {
135 private_ita_attr_command_t *this;
136
137 INIT(this,
138 .public = {
139 .pa_tnc_attribute = {
140 .get_type = _get_type,
141 .get_value = _get_value,
142 .get_noskip_flag = _get_noskip_flag,
143 .set_noskip_flag = _set_noskip_flag,
144 .build = _build,
145 .process = _process,
146 .get_ref = _get_ref,
147 .destroy = _destroy,
148 },
149 .get_command = _get_command,
150 },
151 .type = { PEN_ITA, ITA_ATTR_COMMAND },
152 .command = strdup(command),
153 .ref = 1,
154 );
155
156 return &this->public.pa_tnc_attribute;
157 }
158
159 /**
160 * Described in header.
161 */
162 pa_tnc_attr_t *ita_attr_command_create_from_data(chunk_t data)
163 {
164 private_ita_attr_command_t *this;
165
166 INIT(this,
167 .public = {
168 .pa_tnc_attribute = {
169 .get_type = _get_type,
170 .get_value = _get_value,
171 .get_noskip_flag = _get_noskip_flag,
172 .set_noskip_flag = _set_noskip_flag,
173 .build = _build,
174 .process = _process,
175 .get_ref = _get_ref,
176 .destroy = _destroy,
177 },
178 .get_command = _get_command,
179 },
180 .type = {PEN_ITA, ITA_ATTR_COMMAND },
181 .value = chunk_clone(data),
182 .ref = 1,
183 );
184
185 return &this->public.pa_tnc_attribute;
186 }
187
188