Change interface for enumerator_create_filter() callback
This avoids the unportable 5 pointer hack, but requires enumerating in the callback.
This commit is contained in:
@@ -178,28 +178,32 @@ METHOD(attribute_provider_t, release_address, bool,
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to convert host to DNS configuration attributes
|
||||
*/
|
||||
static bool attr_filter(void *lock, host_t **in,
|
||||
configuration_attribute_type_t *type,
|
||||
void *dummy, chunk_t *data)
|
||||
CALLBACK(attr_filter, bool,
|
||||
void *lock, enumerator_t *orig, va_list args)
|
||||
{
|
||||
host_t *host = *in;
|
||||
configuration_attribute_type_t *type;
|
||||
chunk_t *data;
|
||||
host_t *host;
|
||||
|
||||
switch (host->get_family(host))
|
||||
VA_ARGS_VGET(args, type, data);
|
||||
|
||||
while (orig->enumerate(orig, &host))
|
||||
{
|
||||
case AF_INET:
|
||||
*type = INTERNAL_IP4_DNS;
|
||||
break;
|
||||
case AF_INET6:
|
||||
*type = INTERNAL_IP6_DNS;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
switch (host->get_family(host))
|
||||
{
|
||||
case AF_INET:
|
||||
*type = INTERNAL_IP4_DNS;
|
||||
break;
|
||||
case AF_INET6:
|
||||
*type = INTERNAL_IP6_DNS;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
*data = host->get_address(host);
|
||||
return TRUE;
|
||||
}
|
||||
*data = host->get_address(host);
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
|
||||
@@ -223,7 +227,7 @@ METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
|
||||
enumerator->destroy(enumerator);
|
||||
return enumerator_create_filter(
|
||||
attr->dns->create_enumerator(attr->dns),
|
||||
(void*)attr_filter, this->lock,
|
||||
attr_filter, this->lock,
|
||||
(void*)this->lock->unlock);
|
||||
}
|
||||
}
|
||||
@@ -338,24 +342,28 @@ METHOD(stroke_attribute_t, del_dns, void,
|
||||
this->lock->unlock(this->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pool enumerator filter function, converts pool_t to name, size, ...
|
||||
*/
|
||||
static bool pool_filter(void *lock, mem_pool_t **poolp, const char **name,
|
||||
void *d1, u_int *size, void *d2, u_int *online,
|
||||
void *d3, u_int *offline)
|
||||
CALLBACK(pool_filter, bool,
|
||||
void *lock, enumerator_t *orig, va_list args)
|
||||
{
|
||||
mem_pool_t *pool = *poolp;
|
||||
mem_pool_t *pool;
|
||||
const char **name;
|
||||
u_int *size, *online, *offline;
|
||||
|
||||
if (pool->get_size(pool) == 0)
|
||||
VA_ARGS_VGET(args, name, size, online, offline);
|
||||
|
||||
while (orig->enumerate(orig, &pool))
|
||||
{
|
||||
return FALSE;
|
||||
if (pool->get_size(pool) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
*name = pool->get_name(pool);
|
||||
*size = pool->get_size(pool);
|
||||
*online = pool->get_online(pool);
|
||||
*offline = pool->get_offline(pool);
|
||||
return TRUE;
|
||||
}
|
||||
*name = pool->get_name(pool);
|
||||
*size = pool->get_size(pool);
|
||||
*online = pool->get_online(pool);
|
||||
*offline = pool->get_offline(pool);
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(stroke_attribute_t, create_pool_enumerator, enumerator_t*,
|
||||
@@ -363,7 +371,7 @@ METHOD(stroke_attribute_t, create_pool_enumerator, enumerator_t*,
|
||||
{
|
||||
this->lock->read_lock(this->lock);
|
||||
return enumerator_create_filter(this->pools->create_enumerator(this->pools),
|
||||
(void*)pool_filter,
|
||||
pool_filter,
|
||||
this->lock, (void*)this->lock->unlock);
|
||||
}
|
||||
|
||||
|
||||
@@ -171,26 +171,30 @@ typedef struct {
|
||||
identification_t *id;
|
||||
} cert_data_t;
|
||||
|
||||
/**
|
||||
* destroy cert_data
|
||||
*/
|
||||
static void cert_data_destroy(cert_data_t *data)
|
||||
CALLBACK(cert_data_destroy, void,
|
||||
cert_data_t *data)
|
||||
{
|
||||
data->this->lock->unlock(data->this->lock);
|
||||
free(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* filter function for certs enumerator
|
||||
*/
|
||||
static bool certs_filter(cert_data_t *data, ca_cert_t **in,
|
||||
certificate_t **out)
|
||||
CALLBACK(certs_filter, bool,
|
||||
cert_data_t *data, enumerator_t *orig, va_list args)
|
||||
{
|
||||
ca_cert_t *cacert;
|
||||
public_key_t *public;
|
||||
certificate_t *cert = (*in)->cert;
|
||||
certificate_t **out;
|
||||
|
||||
if (data->cert == CERT_ANY || data->cert == cert->get_type(cert))
|
||||
VA_ARGS_VGET(args, out);
|
||||
|
||||
while (orig->enumerate(orig, &cacert))
|
||||
{
|
||||
certificate_t *cert = cacert->cert;
|
||||
|
||||
if (data->cert != CERT_ANY && data->cert != cert->get_type(cert))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
public = cert->get_public_key(cert);
|
||||
if (public)
|
||||
{
|
||||
@@ -208,9 +212,9 @@ static bool certs_filter(cert_data_t *data, ca_cert_t **in,
|
||||
}
|
||||
else if (data->key != KEY_ANY)
|
||||
{
|
||||
return FALSE;
|
||||
continue;
|
||||
}
|
||||
if (data->id == NULL || cert->has_subject(cert, data->id))
|
||||
if (!data->id || cert->has_subject(cert, data->id))
|
||||
{
|
||||
*out = cert;
|
||||
return TRUE;
|
||||
@@ -235,8 +239,8 @@ METHOD(credential_set_t, create_cert_enumerator, enumerator_t*,
|
||||
|
||||
this->lock->read_lock(this->lock);
|
||||
enumerator = this->certs->create_enumerator(this->certs);
|
||||
return enumerator_create_filter(enumerator, (void*)certs_filter, data,
|
||||
(void*)cert_data_destroy);
|
||||
return enumerator_create_filter(enumerator, certs_filter, data,
|
||||
cert_data_destroy);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -68,13 +68,20 @@ METHOD(backend_t, create_peer_cfg_enumerator, enumerator_t*,
|
||||
(void*)this->mutex->unlock, this->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* filter function for ike configs
|
||||
*/
|
||||
static bool ike_filter(void *data, peer_cfg_t **in, ike_cfg_t **out)
|
||||
CALLBACK(ike_filter, bool,
|
||||
void *data, enumerator_t *orig, va_list args)
|
||||
{
|
||||
*out = (*in)->get_ike_cfg(*in);
|
||||
return TRUE;
|
||||
peer_cfg_t *cfg;
|
||||
ike_cfg_t **out;
|
||||
|
||||
VA_ARGS_VGET(args, out);
|
||||
|
||||
if (orig->enumerate(orig, &cfg))
|
||||
{
|
||||
*out = cfg->get_ike_cfg(cfg);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(backend_t, create_ike_cfg_enumerator, enumerator_t*,
|
||||
@@ -82,7 +89,7 @@ METHOD(backend_t, create_ike_cfg_enumerator, enumerator_t*,
|
||||
{
|
||||
this->mutex->lock(this->mutex);
|
||||
return enumerator_create_filter(this->list->create_enumerator(this->list),
|
||||
(void*)ike_filter, this->mutex,
|
||||
ike_filter, this->mutex,
|
||||
(void*)this->mutex->unlock);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,35 +62,39 @@ static void attributes_destroy(attributes_t *this)
|
||||
free(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to convert host to DNS configuration attributes
|
||||
*/
|
||||
static bool attr_filter(void *lock, host_t **in,
|
||||
configuration_attribute_type_t *type,
|
||||
void *dummy, chunk_t *data)
|
||||
CALLBACK(attr_filter, bool,
|
||||
void *lock, enumerator_t *orig, va_list args)
|
||||
{
|
||||
host_t *host = *in;
|
||||
configuration_attribute_type_t *type;
|
||||
chunk_t *data;
|
||||
host_t *host;
|
||||
|
||||
switch (host->get_family(host))
|
||||
VA_ARGS_VGET(args, type, data);
|
||||
|
||||
while (orig->enumerate(orig, &host))
|
||||
{
|
||||
case AF_INET:
|
||||
*type = INTERNAL_IP4_DNS;
|
||||
break;
|
||||
case AF_INET6:
|
||||
*type = INTERNAL_IP6_DNS;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
switch (host->get_family(host))
|
||||
{
|
||||
case AF_INET:
|
||||
*type = INTERNAL_IP4_DNS;
|
||||
break;
|
||||
case AF_INET6:
|
||||
*type = INTERNAL_IP6_DNS;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
if (host->is_anyaddr(host))
|
||||
{
|
||||
*data = chunk_empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
*data = host->get_address(host);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
if (host->is_anyaddr(host))
|
||||
{
|
||||
*data = chunk_empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
*data = host->get_address(host);
|
||||
}
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t*,
|
||||
@@ -114,7 +118,7 @@ METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t*,
|
||||
enumerator->destroy(enumerator);
|
||||
return enumerator_create_filter(
|
||||
attr->dns->create_enumerator(attr->dns),
|
||||
(void*)attr_filter, this->lock,
|
||||
attr_filter, this->lock,
|
||||
(void*)this->lock->unlock);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user