1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/*
* Copyright (C) 2011 Andreas Steffen
*
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "pa_tnc_attr_manager.h"
#include <collections/linked_list.h>
#include <utils/debug.h>
typedef struct private_pa_tnc_attr_manager_t private_pa_tnc_attr_manager_t;
typedef struct entry_t entry_t;
struct entry_t {
pen_t vendor_id;
enum_name_t *attr_names;
pa_tnc_attr_create_t attr_create;
};
/**
* Private data of a pa_tnc_attr_manager_t object.
*
*/
struct private_pa_tnc_attr_manager_t {
/**
* Public pa_tnc_attr_manager_t interface.
*/
pa_tnc_attr_manager_t public;
/**
* List of PA-TNC vendor attributes
*/
linked_list_t *list;
};
METHOD(pa_tnc_attr_manager_t, add_vendor, void,
private_pa_tnc_attr_manager_t *this, pen_t vendor_id,
pa_tnc_attr_create_t attr_create, enum_name_t *attr_names)
{
entry_t *entry;
entry = malloc_thing(entry_t);
entry->vendor_id = vendor_id;
entry->attr_create = attr_create;
entry->attr_names = attr_names;
this->list->insert_last(this->list, entry);
DBG2(DBG_TNC, "added %N attributes", pen_names, vendor_id);
}
METHOD(pa_tnc_attr_manager_t, remove_vendor, void,
private_pa_tnc_attr_manager_t *this, pen_t vendor_id)
{
enumerator_t *enumerator;
entry_t *entry;
enumerator = this->list->create_enumerator(this->list);
while (enumerator->enumerate(enumerator, &entry))
{
if (entry->vendor_id == vendor_id)
{
this->list->remove_at(this->list, enumerator);
free(entry);
DBG2(DBG_TNC, "removed %N attributes", pen_names, vendor_id);
}
}
enumerator->destroy(enumerator);
}
METHOD(pa_tnc_attr_manager_t, get_names, enum_name_t*,
private_pa_tnc_attr_manager_t *this, pen_t vendor_id)
{
enumerator_t *enumerator;
entry_t *entry;
enum_name_t *attr_names = NULL;
enumerator = this->list->create_enumerator(this->list);
while (enumerator->enumerate(enumerator, &entry))
{
if (entry->vendor_id == vendor_id)
{
attr_names = entry->attr_names;
break;
}
}
enumerator->destroy(enumerator);
return attr_names;
}
METHOD(pa_tnc_attr_manager_t, create, pa_tnc_attr_t*,
private_pa_tnc_attr_manager_t *this, pen_t vendor_id, u_int32_t type,
chunk_t value)
{
enumerator_t *enumerator;
entry_t *entry;
pa_tnc_attr_t *attr = NULL;
enumerator = this->list->create_enumerator(this->list);
while (enumerator->enumerate(enumerator, &entry))
{
if (entry->vendor_id == vendor_id)
{
if (entry->attr_create)
{
attr = entry->attr_create(type, value);
}
break;
}
}
enumerator->destroy(enumerator);
return attr;
}
METHOD(pa_tnc_attr_manager_t, destroy, void,
private_pa_tnc_attr_manager_t *this)
{
this->list->destroy_function(this->list, free);
free(this);
}
/**
* See header
*/
pa_tnc_attr_manager_t *pa_tnc_attr_manager_create(void)
{
private_pa_tnc_attr_manager_t *this;
INIT(this,
.public = {
.add_vendor = _add_vendor,
.remove_vendor = _remove_vendor,
.get_names = _get_names,
.create = _create,
.destroy = _destroy,
},
.list = linked_list_create(),
);
return &this->public;
}
|