Give plugins more control of which configuration attributes to request, and pass received attributes back to the requesting handler
This commit is contained in:
@@ -61,12 +61,16 @@ static bool attr_enum_filter(void *null, attribute_entry_t **in,
|
||||
/**
|
||||
* Implementation of attribute_provider_t.create_attribute_enumerator
|
||||
*/
|
||||
static enumerator_t* create_attribute_enumerator(
|
||||
private_attr_provider_t *this, identification_t *id)
|
||||
static enumerator_t* create_attribute_enumerator(private_attr_provider_t *this,
|
||||
identification_t *id, host_t *vip)
|
||||
{
|
||||
return enumerator_create_filter(
|
||||
if (vip)
|
||||
{
|
||||
return enumerator_create_filter(
|
||||
this->attributes->create_enumerator(this->attributes),
|
||||
(void*)attr_enum_filter, NULL, NULL);
|
||||
}
|
||||
return enumerator_create_empty();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,7 +142,7 @@ attr_provider_t *attr_provider_create(database_t *db)
|
||||
|
||||
this->public.provider.acquire_address = (host_t*(*)(attribute_provider_t *this, char*, identification_t *, host_t *))return_null;
|
||||
this->public.provider.release_address = (bool(*)(attribute_provider_t *this, char*,host_t *, identification_t*))return_false;
|
||||
this->public.provider.create_attribute_enumerator = (enumerator_t*(*)(attribute_provider_t*, identification_t *id))create_attribute_enumerator;
|
||||
this->public.provider.create_attribute_enumerator = (enumerator_t*(*)(attribute_provider_t*, identification_t *id, host_t *vip))create_attribute_enumerator;
|
||||
this->public.destroy = (void(*)(attr_provider_t*))destroy;
|
||||
|
||||
this->attributes = linked_list_create();
|
||||
|
||||
@@ -67,6 +67,50 @@ static bool handle(private_nm_handler_t *this, identification_t *server,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of create_attribute_enumerator().enumerate() for WINS
|
||||
*/
|
||||
static bool enumerate_nbns(enumerator_t *this,
|
||||
configuration_attribute_type_t *type, chunk_t *data)
|
||||
{
|
||||
*type = INTERNAL_IP4_NBNS;
|
||||
*data = chunk_empty;
|
||||
/* done */
|
||||
this->enumerate = (void*)return_false;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of create_attribute_enumerator().enumerate() for DNS
|
||||
*/
|
||||
static bool enumerate_dns(enumerator_t *this,
|
||||
configuration_attribute_type_t *type, chunk_t *data)
|
||||
{
|
||||
*type = INTERNAL_IP4_DNS;
|
||||
*data = chunk_empty;
|
||||
/* enumerate WINS server as next attribute ... */
|
||||
this->enumerate = (void*)enumerate_nbns;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of attribute_handler_t.create_attribute_enumerator
|
||||
*/
|
||||
static enumerator_t* create_attribute_enumerator(private_nm_handler_t *this,
|
||||
identification_t *server, host_t *vip)
|
||||
{
|
||||
if (vip && vip->get_family(vip) == AF_INET)
|
||||
{ /* no IPv6 attributes yet */
|
||||
enumerator_t *enumerator = malloc_thing(enumerator_t);
|
||||
/* enumerate DNS attribute first ... */
|
||||
enumerator->enumerate = (void*)enumerate_dns;
|
||||
enumerator->destroy = (void*)free;
|
||||
|
||||
return enumerator;
|
||||
}
|
||||
return enumerator_create_empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* convert plain byte ptrs to handy chunk during enumeration
|
||||
*/
|
||||
@@ -136,6 +180,7 @@ nm_handler_t *nm_handler_create()
|
||||
|
||||
this->public.handler.handle = (bool(*)(attribute_handler_t*, identification_t*, configuration_attribute_type_t, chunk_t))handle;
|
||||
this->public.handler.release = (void(*)(attribute_handler_t*, identification_t*, configuration_attribute_type_t, chunk_t))nop;
|
||||
this->public.handler.create_attribute_enumerator = (enumerator_t*(*)(attribute_handler_t*, identification_t *server, host_t *vip))create_attribute_enumerator;
|
||||
this->public.create_enumerator = (enumerator_t*(*)(nm_handler_t*, configuration_attribute_type_t type))create_enumerator;
|
||||
this->public.reset = (void(*)(nm_handler_t*))reset;
|
||||
this->public.destroy = (void(*)(nm_handler_t*))destroy;
|
||||
|
||||
@@ -163,6 +163,59 @@ static void release(private_resolve_handler_t *this, identification_t *server,
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute enumerator implementation
|
||||
*/
|
||||
typedef struct {
|
||||
/** implements enumerator_t interface */
|
||||
enumerator_t public;
|
||||
/** virtual IP we are requesting */
|
||||
host_t *vip;
|
||||
} attribute_enumerator_t;
|
||||
|
||||
/**
|
||||
* Implementation of create_attribute_enumerator().enumerate()
|
||||
*/
|
||||
static bool attribute_enumerate(attribute_enumerator_t *this,
|
||||
configuration_attribute_type_t *type, chunk_t *data)
|
||||
{
|
||||
switch (this->vip->get_family(this->vip))
|
||||
{
|
||||
case AF_INET:
|
||||
*type = INTERNAL_IP4_DNS;
|
||||
break;
|
||||
case AF_INET6:
|
||||
*type = INTERNAL_IP6_DNS;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
*data = chunk_empty;
|
||||
/* enumerate only once */
|
||||
this->public.enumerate = (void*)return_false;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of attribute_handler_t.create_attribute_enumerator
|
||||
*/
|
||||
static enumerator_t* create_attribute_enumerator(private_resolve_handler_t *this,
|
||||
identification_t *server, host_t *vip)
|
||||
{
|
||||
if (vip)
|
||||
{
|
||||
attribute_enumerator_t *enumerator;
|
||||
|
||||
enumerator = malloc_thing(attribute_enumerator_t);
|
||||
enumerator->public.enumerate = (void*)attribute_enumerate;
|
||||
enumerator->public.destroy = (void*)free;
|
||||
enumerator->vip = vip;
|
||||
|
||||
return &enumerator->public;
|
||||
}
|
||||
return enumerator_create_empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of resolve_handler_t.destroy.
|
||||
*/
|
||||
@@ -181,6 +234,7 @@ resolve_handler_t *resolve_handler_create()
|
||||
|
||||
this->public.handler.handle = (bool(*)(attribute_handler_t*, identification_t*, configuration_attribute_type_t, chunk_t))handle;
|
||||
this->public.handler.release = (void(*)(attribute_handler_t*, identification_t*, configuration_attribute_type_t, chunk_t))release;
|
||||
this->public.handler.create_attribute_enumerator = (enumerator_t*(*)(attribute_handler_t*, identification_t *server, host_t *vip))create_attribute_enumerator;
|
||||
this->public.destroy = (void(*)(resolve_handler_t*))destroy;
|
||||
|
||||
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
|
||||
|
||||
@@ -531,7 +531,7 @@ stroke_attribute_t *stroke_attribute_create()
|
||||
|
||||
this->public.provider.acquire_address = (host_t*(*)(attribute_provider_t *this, char*, identification_t *,host_t *))acquire_address;
|
||||
this->public.provider.release_address = (bool(*)(attribute_provider_t *this, char*,host_t *, identification_t*))release_address;
|
||||
this->public.provider.create_attribute_enumerator = (enumerator_t*(*)(attribute_provider_t*, identification_t *id))enumerator_create_empty;
|
||||
this->public.provider.create_attribute_enumerator = (enumerator_t*(*)(attribute_provider_t*, identification_t *id, host_t *vip))enumerator_create_empty;
|
||||
this->public.add_pool = (void(*)(stroke_attribute_t*, stroke_msg_t *msg))add_pool;
|
||||
this->public.del_pool = (void(*)(stroke_attribute_t*, stroke_msg_t *msg))del_pool;
|
||||
this->public.create_pool_enumerator = (enumerator_t*(*)(stroke_attribute_t*))create_pool_enumerator;
|
||||
|
||||
Reference in New Issue
Block a user