]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libimcv/ita/ita_attr_dummy.c
Moved debug.[ch] to utils folder
[thirdparty/strongswan.git] / src / libimcv / ita / ita_attr_dummy.c
1 /*
2 * Copyright (C) 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_dummy.h"
18
19 #include <pen/pen.h>
20
21 #include <utils/debug.h>
22
23 typedef struct private_ita_attr_dummy_t private_ita_attr_dummy_t;
24
25 /**
26 * Private data of an ita_attr_dummy_t object.
27 */
28 struct private_ita_attr_dummy_t {
29
30 /**
31 * Public members of ita_attr_dummy_t
32 */
33 ita_attr_dummy_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 * Size of the attribute value
52 */
53 int size;
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_dummy_t *this)
63 {
64 return this->type;
65 }
66
67 METHOD(pa_tnc_attr_t, get_value, chunk_t,
68 private_ita_attr_dummy_t *this)
69 {
70 return this->value;
71 }
72
73 METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
74 private_ita_attr_dummy_t *this)
75 {
76 return this->noskip_flag;
77 }
78
79 METHOD(pa_tnc_attr_t, set_noskip_flag,void,
80 private_ita_attr_dummy_t *this, bool noskip)
81 {
82 this->noskip_flag = noskip;
83 }
84
85 METHOD(pa_tnc_attr_t, build, void,
86 private_ita_attr_dummy_t *this)
87 {
88 if (this->value.ptr)
89 {
90 return;
91 }
92 this->value = chunk_alloc(this->size);
93 memset(this->value.ptr, 0xdd, this->value.len);
94 }
95
96 METHOD(pa_tnc_attr_t, process, status_t,
97 private_ita_attr_dummy_t *this, u_int32_t *offset)
98 {
99 this->size = this->value.len;
100
101 return SUCCESS;
102 }
103
104 METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*,
105 private_ita_attr_dummy_t *this)
106 {
107 ref_get(&this->ref);
108 return &this->public.pa_tnc_attribute;
109 }
110
111 METHOD(pa_tnc_attr_t, destroy, void,
112 private_ita_attr_dummy_t *this)
113 {
114 if (ref_put(&this->ref))
115 {
116 free(this->value.ptr);
117 free(this);
118 }
119 }
120
121 METHOD(ita_attr_dummy_t, get_size, int,
122 private_ita_attr_dummy_t *this)
123 {
124 return this->size;
125 }
126
127 /**
128 * Described in header.
129 */
130 pa_tnc_attr_t *ita_attr_dummy_create(int size)
131 {
132 private_ita_attr_dummy_t *this;
133
134 INIT(this,
135 .public = {
136 .pa_tnc_attribute = {
137 .get_type = _get_type,
138 .get_value = _get_value,
139 .get_noskip_flag = _get_noskip_flag,
140 .set_noskip_flag = _set_noskip_flag,
141 .build = _build,
142 .process = _process,
143 .get_ref = _get_ref,
144 .destroy = _destroy,
145 },
146 .get_size = _get_size,
147 },
148 .type = { PEN_ITA, ITA_ATTR_DUMMY },
149 .size = size,
150 .ref = 1,
151 );
152
153 return &this->public.pa_tnc_attribute;
154 }
155
156 /**
157 * Described in header.
158 */
159 pa_tnc_attr_t *ita_attr_dummy_create_from_data(chunk_t data)
160 {
161 private_ita_attr_dummy_t *this;
162
163 INIT(this,
164 .public = {
165 .pa_tnc_attribute = {
166 .get_type = _get_type,
167 .get_value = _get_value,
168 .build = _build,
169 .process = _process,
170 .get_ref = _get_ref,
171 .destroy = _destroy,
172 },
173 .get_size = _get_size,
174 },
175 .type = { PEN_ITA, ITA_ATTR_DUMMY },
176 .value = chunk_clone(data),
177 .ref = 1,
178 );
179
180 return &this->public.pa_tnc_attribute;
181 }
182
183