2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
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 "dhcp_transaction.h"
18 #include <collections/linked_list.h>
20 typedef struct private_dhcp_transaction_t private_dhcp_transaction_t
;
23 * Private data of an dhcp_transaction_t object.
25 struct private_dhcp_transaction_t
{
28 * Public dhcp_transaction_t interface.
30 dhcp_transaction_t
public;
40 identification_t
*identity
;
43 * received DHCP address
48 * discovered DHCP server address
53 * List of added attributes, as attribute_entry_t
55 linked_list_t
*attributes
;
59 * Entry for an added attribute
62 configuration_attribute_type_t type
;
66 METHOD(dhcp_transaction_t
, get_id
, uint32_t,
67 private_dhcp_transaction_t
*this)
72 METHOD(dhcp_transaction_t
, get_identity
, identification_t
*,
73 private_dhcp_transaction_t
*this)
75 return this->identity
;
78 METHOD(dhcp_transaction_t
, set_address
, void,
79 private_dhcp_transaction_t
*this, host_t
*address
)
81 DESTROY_IF(this->address
);
82 this->address
= address
;
85 METHOD(dhcp_transaction_t
, get_address
, host_t
*,
86 private_dhcp_transaction_t
*this)
91 METHOD(dhcp_transaction_t
, set_server
, void,
92 private_dhcp_transaction_t
*this, host_t
*server
)
94 DESTROY_IF(this->server
);
95 this->server
= server
;
98 METHOD(dhcp_transaction_t
, get_server
, host_t
*,
99 private_dhcp_transaction_t
*this)
104 METHOD(dhcp_transaction_t
, add_attribute
, void,
105 private_dhcp_transaction_t
*this, configuration_attribute_type_t type
,
108 attribute_entry_t
*entry
;
112 .data
= chunk_clone(data
),
114 this->attributes
->insert_last(this->attributes
, entry
);
117 CALLBACK(attribute_filter
, bool,
118 void *null
, enumerator_t
*orig
, va_list args
)
120 configuration_attribute_type_t
*type
;
121 attribute_entry_t
*entry
;
124 VA_ARGS_VGET(args
, type
, data
);
126 if (orig
->enumerate(orig
, &entry
))
135 METHOD(dhcp_transaction_t
, create_attribute_enumerator
, enumerator_t
*,
136 private_dhcp_transaction_t
*this)
138 return enumerator_create_filter(
139 this->attributes
->create_enumerator(this->attributes
),
140 attribute_filter
, NULL
, NULL
);
144 * Clean up an attribute entry
146 static void attribute_entry_destroy(attribute_entry_t
*entry
)
148 free(entry
->data
.ptr
);
152 METHOD(dhcp_transaction_t
, destroy
, void,
153 private_dhcp_transaction_t
*this)
155 this->identity
->destroy(this->identity
);
156 DESTROY_IF(this->address
);
157 DESTROY_IF(this->server
);
158 this->attributes
->destroy_function(this->attributes
,
159 (void*)attribute_entry_destroy
);
166 dhcp_transaction_t
*dhcp_transaction_create(uint32_t id
,
167 identification_t
*identity
)
169 private_dhcp_transaction_t
*this;
174 .get_identity
= _get_identity
,
175 .set_address
= _set_address
,
176 .get_address
= _get_address
,
177 .set_server
= _set_server
,
178 .get_server
= _get_server
,
179 .add_attribute
= _add_attribute
,
180 .create_attribute_enumerator
= _create_attribute_enumerator
,
184 .identity
= identity
->clone(identity
),
185 .attributes
= linked_list_create(),
188 return &this->public;