2 * Copyright (C) 2011 Andreas Steffen
4 * HSR Hochschule fuer Technik Rapperswil
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 "pa_tnc_attr_manager.h"
19 #include <collections/linked_list.h>
22 typedef struct private_pa_tnc_attr_manager_t private_pa_tnc_attr_manager_t
;
23 typedef struct entry_t entry_t
;
27 enum_name_t
*attr_names
;
28 pa_tnc_attr_create_t attr_create
;
32 * Private data of a pa_tnc_attr_manager_t object.
35 struct private_pa_tnc_attr_manager_t
{
38 * Public pa_tnc_attr_manager_t interface.
40 pa_tnc_attr_manager_t
public;
43 * List of PA-TNC vendor attributes
48 METHOD(pa_tnc_attr_manager_t
, add_vendor
, void,
49 private_pa_tnc_attr_manager_t
*this, pen_t vendor_id
,
50 pa_tnc_attr_create_t attr_create
, enum_name_t
*attr_names
)
54 entry
= malloc_thing(entry_t
);
55 entry
->vendor_id
= vendor_id
;
56 entry
->attr_create
= attr_create
;
57 entry
->attr_names
= attr_names
;
59 this->list
->insert_last(this->list
, entry
);
60 DBG2(DBG_TNC
, "added %N attributes", pen_names
, vendor_id
);
63 METHOD(pa_tnc_attr_manager_t
, remove_vendor
, void,
64 private_pa_tnc_attr_manager_t
*this, pen_t vendor_id
)
66 enumerator_t
*enumerator
;
69 enumerator
= this->list
->create_enumerator(this->list
);
70 while (enumerator
->enumerate(enumerator
, &entry
))
72 if (entry
->vendor_id
== vendor_id
)
74 this->list
->remove_at(this->list
, enumerator
);
76 DBG2(DBG_TNC
, "removed %N attributes", pen_names
, vendor_id
);
79 enumerator
->destroy(enumerator
);
82 METHOD(pa_tnc_attr_manager_t
, get_names
, enum_name_t
*,
83 private_pa_tnc_attr_manager_t
*this, pen_t vendor_id
)
85 enumerator_t
*enumerator
;
87 enum_name_t
*attr_names
= NULL
;
89 enumerator
= this->list
->create_enumerator(this->list
);
90 while (enumerator
->enumerate(enumerator
, &entry
))
92 if (entry
->vendor_id
== vendor_id
)
94 attr_names
= entry
->attr_names
;
98 enumerator
->destroy(enumerator
);
103 METHOD(pa_tnc_attr_manager_t
, create
, pa_tnc_attr_t
*,
104 private_pa_tnc_attr_manager_t
*this, pen_t vendor_id
, u_int32_t type
,
107 enumerator_t
*enumerator
;
109 pa_tnc_attr_t
*attr
= NULL
;
111 enumerator
= this->list
->create_enumerator(this->list
);
112 while (enumerator
->enumerate(enumerator
, &entry
))
114 if (entry
->vendor_id
== vendor_id
)
116 if (entry
->attr_create
)
118 attr
= entry
->attr_create(type
, value
);
123 enumerator
->destroy(enumerator
);
128 METHOD(pa_tnc_attr_manager_t
, destroy
, void,
129 private_pa_tnc_attr_manager_t
*this)
131 this->list
->destroy_function(this->list
, free
);
138 pa_tnc_attr_manager_t
*pa_tnc_attr_manager_create(void)
140 private_pa_tnc_attr_manager_t
*this;
144 .add_vendor
= _add_vendor
,
145 .remove_vendor
= _remove_vendor
,
146 .get_names
= _get_names
,
150 .list
= linked_list_create(),
153 return &this->public;