2 * Copyright (C) 2009 Martin Willi
3 * 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 "nm_handler.h"
20 typedef struct private_nm_handler_t private_nm_handler_t
;
23 * Private data of an nm_handler_t object.
25 struct private_nm_handler_t
{
28 * Public nm_handler_t interface.
33 * list of received DNS server attributes, pointer to 4 byte data
38 * list of received NBNS server attributes, pointer to 4 byte data
43 METHOD(attribute_handler_t
, handle
, bool,
44 private_nm_handler_t
*this, identification_t
*server
,
45 configuration_attribute_type_t type
, chunk_t data
)
51 case INTERNAL_IP4_DNS
:
54 case INTERNAL_IP4_NBNS
:
64 list
->insert_last(list
, chunk_clone(data
).ptr
);
69 * Implementation of create_attribute_enumerator().enumerate() for WINS
71 static bool enumerate_nbns(enumerator_t
*this,
72 configuration_attribute_type_t
*type
, chunk_t
*data
)
74 *type
= INTERNAL_IP4_NBNS
;
77 this->enumerate
= (void*)return_false
;
82 * Implementation of create_attribute_enumerator().enumerate() for DNS
84 static bool enumerate_dns(enumerator_t
*this,
85 configuration_attribute_type_t
*type
, chunk_t
*data
)
87 *type
= INTERNAL_IP4_DNS
;
89 /* enumerate WINS server as next attribute ... */
90 this->enumerate
= (void*)enumerate_nbns
;
94 METHOD(attribute_handler_t
, create_attribute_enumerator
, enumerator_t
*,
95 private_nm_handler_t
*this, identification_t
*server
, host_t
*vip
)
97 if (vip
&& vip
->get_family(vip
) == AF_INET
)
98 { /* no IPv6 attributes yet */
99 enumerator_t
*enumerator
= malloc_thing(enumerator_t
);
100 /* enumerate DNS attribute first ... */
101 enumerator
->enumerate
= (void*)enumerate_dns
;
102 enumerator
->destroy
= (void*)free
;
106 return enumerator_create_empty();
110 * convert plain byte ptrs to handy chunk during enumeration
112 static bool filter_chunks(void* null
, char **in
, chunk_t
*out
)
114 *out
= chunk_create(*in
, 4);
118 METHOD(nm_handler_t
, create_enumerator
, enumerator_t
*,
119 private_nm_handler_t
*this, configuration_attribute_type_t type
)
125 case INTERNAL_IP4_DNS
:
128 case INTERNAL_IP4_NBNS
:
132 return enumerator_create_empty();
134 return enumerator_create_filter(list
->create_enumerator(list
),
135 (void*)filter_chunks
, NULL
, NULL
);
138 METHOD(nm_handler_t
, reset
, void,
139 private_nm_handler_t
*this)
143 while (this->dns
->remove_last(this->dns
, (void**)&data
) == SUCCESS
)
147 while (this->nbns
->remove_last(this->nbns
, (void**)&data
) == SUCCESS
)
153 METHOD(nm_handler_t
, destroy
, void,
154 private_nm_handler_t
*this)
157 this->dns
->destroy(this->dns
);
158 this->nbns
->destroy(this->nbns
);
165 nm_handler_t
*nm_handler_create()
167 private_nm_handler_t
*this;
174 .create_attribute_enumerator
= _create_attribute_enumerator
,
176 .create_enumerator
= _create_enumerator
,
180 .dns
= linked_list_create(),
181 .nbns
= linked_list_create(),
184 return &this->public;