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:
+31
-30
@@ -120,48 +120,49 @@ typedef struct {
|
||||
identification_t *id;
|
||||
} cert_data_t;
|
||||
|
||||
/**
|
||||
* Destroy CA certificate enumerator 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 certificates enumerator
|
||||
*/
|
||||
static bool cert_filter(cert_data_t *data, certificate_t **in,
|
||||
certificate_t **out)
|
||||
CALLBACK(cert_filter, bool,
|
||||
cert_data_t *data, enumerator_t *orig, va_list args)
|
||||
{
|
||||
certificate_t *cert = *in;
|
||||
certificate_t *cert, **out;
|
||||
public_key_t *public;
|
||||
|
||||
public = cert->get_public_key(cert);
|
||||
if (!public)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (data->key != KEY_ANY && public->get_type(public) != data->key)
|
||||
{
|
||||
public->destroy(public);
|
||||
return FALSE;
|
||||
}
|
||||
if (data->id && data->id->get_type(data->id) == ID_KEY_ID &&
|
||||
public->has_fingerprint(public, data->id->get_encoding(data->id)))
|
||||
VA_ARGS_VGET(args, out);
|
||||
|
||||
while (orig->enumerate(orig, &cert))
|
||||
{
|
||||
public = cert->get_public_key(cert);
|
||||
if (!public)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (data->key != KEY_ANY && public->get_type(public) != data->key)
|
||||
{
|
||||
public->destroy(public);
|
||||
continue;
|
||||
}
|
||||
if (data->id && data->id->get_type(data->id) == ID_KEY_ID &&
|
||||
public->has_fingerprint(public, data->id->get_encoding(data->id)))
|
||||
{
|
||||
public->destroy(public);
|
||||
*out = cert;
|
||||
return TRUE;
|
||||
}
|
||||
public->destroy(public);
|
||||
if (data->id && !cert->has_subject(cert, data->id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
*out = cert;
|
||||
return TRUE;
|
||||
}
|
||||
public->destroy(public);
|
||||
if (data->id && !cert->has_subject(cert, data->id))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
*out = cert;
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,7 +182,7 @@ static enumerator_t *create_trusted_cert_enumerator(private_nm_creds_t *this,
|
||||
this->lock->read_lock(this->lock);
|
||||
return enumerator_create_filter(
|
||||
this->certs->create_enumerator(this->certs),
|
||||
(void*)cert_filter, data, (void*)cert_data_destroy);
|
||||
cert_filter, data, cert_data_destroy);
|
||||
}
|
||||
|
||||
METHOD(credential_set_t, create_cert_enumerator, enumerator_t*,
|
||||
|
||||
@@ -113,13 +113,20 @@ METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t*,
|
||||
return enumerator_create_empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* convert plain byte ptrs to handy chunk during enumeration
|
||||
*/
|
||||
static bool filter_chunks(void* null, char **in, chunk_t *out)
|
||||
CALLBACK(filter_chunks, bool,
|
||||
void *null, enumerator_t *orig, va_list args)
|
||||
{
|
||||
*out = chunk_create(*in, 4);
|
||||
return TRUE;
|
||||
chunk_t *out;
|
||||
char *ptr;
|
||||
|
||||
VA_ARGS_VGET(args, out);
|
||||
|
||||
if (orig->enumerate(orig, &ptr))
|
||||
{
|
||||
*out = chunk_create(ptr, 4);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(nm_handler_t, create_enumerator, enumerator_t*,
|
||||
@@ -139,7 +146,7 @@ METHOD(nm_handler_t, create_enumerator, enumerator_t*,
|
||||
return enumerator_create_empty();
|
||||
}
|
||||
return enumerator_create_filter(list->create_enumerator(list),
|
||||
(void*)filter_chunks, NULL, NULL);
|
||||
filter_chunks, NULL, NULL);
|
||||
}
|
||||
|
||||
METHOD(nm_handler_t, reset, void,
|
||||
|
||||
Reference in New Issue
Block a user