2 * Copyright (C) 2013-2015 Andreas Steffen
4 * Copyright (C) secunet Security Networks AG
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 #include "generic_attr_string.h"
21 #include <utils/debug.h>
23 typedef struct private_generic_attr_string_t private_generic_attr_string_t
;
26 * Private data of an generic_attr_string_t object.
28 struct private_generic_attr_string_t
{
31 * Public members of generic_attr_string_t
33 generic_attr_string_t
public;
36 * Vendor-specific attribute type
41 * Length of attribute value
46 * Attribute value or segment
61 METHOD(pa_tnc_attr_t
, get_type
, pen_type_t
,
62 private_generic_attr_string_t
*this)
67 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
68 private_generic_attr_string_t
*this)
73 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
74 private_generic_attr_string_t
*this)
76 return this->noskip_flag
;
79 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
80 private_generic_attr_string_t
*this, bool noskip
)
82 this->noskip_flag
= noskip
;
85 METHOD(pa_tnc_attr_t
, build
, void,
86 private_generic_attr_string_t
*this)
91 METHOD(pa_tnc_attr_t
, process
, status_t
,
92 private_generic_attr_string_t
*this, uint32_t *offset
)
94 enum_name_t
*pa_attr_names
;
98 if (this->value
.len
< this->length
)
102 pa_attr_names
= imcv_pa_tnc_attributes
->get_names(imcv_pa_tnc_attributes
,
103 this->type
.vendor_id
);
104 if (this->value
.len
> this->length
)
106 DBG1(DBG_TNC
, "inconsistent length of %N/%N string attribute",
107 pen_names
, this->type
.vendor_id
, pa_attr_names
, this->type
.type
);
111 pos
= memchr(this->value
.ptr
, '\0', this->value
.len
);
114 DBG1(DBG_TNC
, "nul termination in %N/%N string attribute",
115 pen_names
, this->type
.vendor_id
, pa_attr_names
, this->type
.type
);
116 *offset
= pos
- this->value
.ptr
;
123 METHOD(pa_tnc_attr_t
, add_segment
, void,
124 private_generic_attr_string_t
*this, chunk_t segment
)
126 this->value
= chunk_cat("mc", this->value
, segment
);
129 METHOD(pa_tnc_attr_t
, get_ref
, pa_tnc_attr_t
*,
130 private_generic_attr_string_t
*this)
133 return &this->public.pa_tnc_attribute
;
136 METHOD(pa_tnc_attr_t
, destroy
, void,
137 private_generic_attr_string_t
*this)
139 if (ref_put(&this->ref
))
141 free(this->value
.ptr
);
147 * Described in header.
149 pa_tnc_attr_t
*generic_attr_string_create_from_data(size_t length
,
150 chunk_t value
, pen_type_t type
)
152 private_generic_attr_string_t
*this;
156 .pa_tnc_attribute
= {
157 .get_type
= _get_type
,
158 .get_value
= _get_value
,
159 .get_noskip_flag
= _get_noskip_flag
,
160 .set_noskip_flag
= _set_noskip_flag
,
163 .add_segment
= _add_segment
,
170 .value
= chunk_clone(value
),
174 return &this->public.pa_tnc_attribute
;
178 * Described in header.
180 pa_tnc_attr_t
*generic_attr_string_create(chunk_t value
, pen_type_t type
)
182 return generic_attr_string_create_from_data(value
.len
, value
, type
);