2 * Copyright (C) 2015 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
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>.
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
16 #include "generic_attr_chunk.h"
20 #include <utils/debug.h>
22 typedef struct private_generic_attr_chunk_t private_generic_attr_chunk_t
;
25 * Private data of an generic_attr_chunk_t object.
27 struct private_generic_attr_chunk_t
{
30 * Public members of generic_attr_chunk_t
32 generic_attr_chunk_t
public;
35 * Vendor-specific attribute type
40 * Length of attribute value
45 * Fixed size of attribute value, set to 0 if dynamic
50 * Attribute value or segment
65 METHOD(pa_tnc_attr_t
, get_type
, pen_type_t
,
66 private_generic_attr_chunk_t
*this)
71 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
72 private_generic_attr_chunk_t
*this)
77 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
78 private_generic_attr_chunk_t
*this)
80 return this->noskip_flag
;
83 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
84 private_generic_attr_chunk_t
*this, bool noskip
)
86 this->noskip_flag
= noskip
;
89 METHOD(pa_tnc_attr_t
, build
, void,
90 private_generic_attr_chunk_t
*this)
95 METHOD(pa_tnc_attr_t
, process
, status_t
,
96 private_generic_attr_chunk_t
*this, u_int32_t
*offset
)
98 enum_name_t
*pa_attr_names
;
101 if (this->value
.len
< this->length
)
105 pa_attr_names
= imcv_pa_tnc_attributes
->get_names(imcv_pa_tnc_attributes
,
106 this->type
.vendor_id
);
108 if ((this->size
== 0 && this->value
.len
> this->length
) ||
109 (this->size
!= 0 && this->value
.len
!= this->size
))
111 DBG1(DBG_TNC
, "inconsistent length of %N/%N string attribute",
112 pen_names
, this->type
.vendor_id
, pa_attr_names
, this->type
.type
);
119 METHOD(pa_tnc_attr_t
, add_segment
, void,
120 private_generic_attr_chunk_t
*this, chunk_t segment
)
122 this->value
= chunk_cat("mc", this->value
, segment
);
125 METHOD(pa_tnc_attr_t
, get_ref
, pa_tnc_attr_t
*,
126 private_generic_attr_chunk_t
*this)
129 return &this->public.pa_tnc_attribute
;
132 METHOD(pa_tnc_attr_t
, destroy
, void,
133 private_generic_attr_chunk_t
*this)
135 if (ref_put(&this->ref
))
137 free(this->value
.ptr
);
143 * Described in header.
145 pa_tnc_attr_t
*generic_attr_chunk_create_from_data(size_t length
, chunk_t value
,
146 size_t size
, pen_type_t type
)
148 private_generic_attr_chunk_t
*this;
152 .pa_tnc_attribute
= {
153 .get_type
= _get_type
,
154 .get_value
= _get_value
,
155 .get_noskip_flag
= _get_noskip_flag
,
156 .set_noskip_flag
= _set_noskip_flag
,
159 .add_segment
= _add_segment
,
167 .value
= chunk_clone(value
),
171 return &this->public.pa_tnc_attribute
;
175 * Described in header.
177 pa_tnc_attr_t
*generic_attr_chunk_create(chunk_t value
, pen_type_t type
)
179 return generic_attr_chunk_create_from_data(value
.len
, value
,