From b5a2055fb1b88ea4abb97334d89e311c9ceaa7d4 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Tue, 17 Nov 2009 14:51:50 +0100 Subject: Give plugins more control of which configuration attributes to request, and pass received attributes back to the requesting handler --- src/charon/plugins/resolve/resolve_handler.c | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/charon/plugins/resolve/resolve_handler.c') diff --git a/src/charon/plugins/resolve/resolve_handler.c b/src/charon/plugins/resolve/resolve_handler.c index 7c7d52a05..ff0e5943e 100644 --- a/src/charon/plugins/resolve/resolve_handler.c +++ b/src/charon/plugins/resolve/resolve_handler.c @@ -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); -- cgit v1.2.3