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:
@@ -163,17 +163,23 @@ METHOD(credential_factory_t, create, void*,
|
||||
return construct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function for builder enumerator
|
||||
*/
|
||||
static bool builder_filter(void *null, entry_t **entry, credential_type_t *type,
|
||||
void *dummy1, int *subtype)
|
||||
CALLBACK(builder_filter, bool,
|
||||
void *null, enumerator_t *orig, va_list args)
|
||||
{
|
||||
if ((*entry)->final)
|
||||
entry_t *entry;
|
||||
credential_type_t *type;
|
||||
int *subtype;
|
||||
|
||||
VA_ARGS_VGET(args, type, subtype);
|
||||
|
||||
while (orig->enumerate(orig, &entry))
|
||||
{
|
||||
*type = (*entry)->type;
|
||||
*subtype = (*entry)->subtype;
|
||||
return TRUE;
|
||||
if (entry->final)
|
||||
{
|
||||
*type = entry->type;
|
||||
*subtype = entry->subtype;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
@@ -184,7 +190,7 @@ METHOD(credential_factory_t, create_builder_enumerator, enumerator_t*,
|
||||
this->lock->read_lock(this->lock);
|
||||
return enumerator_create_filter(
|
||||
this->constructors->create_enumerator(this->constructors),
|
||||
(void*)builder_filter, this->lock, (void*)this->lock->unlock);
|
||||
builder_filter, this->lock, (void*)this->lock->unlock);
|
||||
}
|
||||
|
||||
METHOD(credential_factory_t, destroy, void,
|
||||
|
||||
@@ -74,25 +74,27 @@ 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->lock->unlock(data->lock);
|
||||
free(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* filter function for certs enumerator
|
||||
*/
|
||||
static bool certs_filter(cert_data_t *data, certificate_t **in, certificate_t **out)
|
||||
CALLBACK(certs_filter, bool,
|
||||
cert_data_t *data, enumerator_t *orig, va_list args)
|
||||
{
|
||||
public_key_t *public;
|
||||
certificate_t *cert = *in;
|
||||
certificate_t *cert, **out;
|
||||
|
||||
if (data->cert == CERT_ANY || data->cert == cert->get_type(cert))
|
||||
VA_ARGS_VGET(args, out);
|
||||
|
||||
while (orig->enumerate(orig, &cert))
|
||||
{
|
||||
if (data->cert != CERT_ANY && data->cert != cert->get_type(cert))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
public = cert->get_public_key(cert);
|
||||
if (public)
|
||||
{
|
||||
@@ -102,7 +104,7 @@ static bool certs_filter(cert_data_t *data, certificate_t **in, certificate_t **
|
||||
data->id->get_encoding(data->id)))
|
||||
{
|
||||
public->destroy(public);
|
||||
*out = *in;
|
||||
*out = cert;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@@ -110,11 +112,11 @@ static bool certs_filter(cert_data_t *data, certificate_t **in, certificate_t **
|
||||
}
|
||||
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 = *in;
|
||||
*out = cert;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@@ -143,8 +145,8 @@ METHOD(credential_set_t, create_cert_enumerator, enumerator_t*,
|
||||
{
|
||||
enumerator = this->untrusted->create_enumerator(this->untrusted);
|
||||
}
|
||||
return enumerator_create_filter(enumerator, (void*)certs_filter, data,
|
||||
(void*)cert_data_destroy);
|
||||
return enumerator_create_filter(enumerator, certs_filter, data,
|
||||
cert_data_destroy);
|
||||
}
|
||||
|
||||
static bool certificate_equals(certificate_t *item, certificate_t *cert)
|
||||
@@ -301,30 +303,30 @@ typedef struct {
|
||||
identification_t *id;
|
||||
} key_data_t;
|
||||
|
||||
/**
|
||||
* Destroy key enumerator data
|
||||
*/
|
||||
static void key_data_destroy(key_data_t *data)
|
||||
CALLBACK(key_data_destroy, void,
|
||||
key_data_t *data)
|
||||
{
|
||||
data->lock->unlock(data->lock);
|
||||
free(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* filter function for private key enumerator
|
||||
*/
|
||||
static bool key_filter(key_data_t *data, private_key_t **in, private_key_t **out)
|
||||
CALLBACK(key_filter, bool,
|
||||
key_data_t *data, enumerator_t *orig, va_list args)
|
||||
{
|
||||
private_key_t *key;
|
||||
private_key_t *key, **out;
|
||||
|
||||
key = *in;
|
||||
if (data->type == KEY_ANY || data->type == key->get_type(key))
|
||||
VA_ARGS_VGET(args, out);
|
||||
|
||||
while (orig->enumerate(orig, &key))
|
||||
{
|
||||
if (data->id == NULL ||
|
||||
key->has_fingerprint(key, data->id->get_encoding(data->id)))
|
||||
if (data->type == KEY_ANY || data->type == key->get_type(key))
|
||||
{
|
||||
*out = key;
|
||||
return TRUE;
|
||||
if (data->id == NULL ||
|
||||
key->has_fingerprint(key, data->id->get_encoding(data->id)))
|
||||
{
|
||||
*out = key;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
@@ -342,7 +344,7 @@ METHOD(credential_set_t, create_private_enumerator, enumerator_t*,
|
||||
);
|
||||
this->lock->read_lock(this->lock);
|
||||
return enumerator_create_filter(this->keys->create_enumerator(this->keys),
|
||||
(void*)key_filter, data, (void*)key_data_destroy);
|
||||
key_filter, data, key_data_destroy);
|
||||
}
|
||||
|
||||
METHOD(mem_cred_t, add_key, void,
|
||||
@@ -468,10 +470,8 @@ typedef struct {
|
||||
shared_key_type_t type;
|
||||
} shared_data_t;
|
||||
|
||||
/**
|
||||
* free shared key enumerator data and unlock list
|
||||
*/
|
||||
static void shared_data_destroy(shared_data_t *data)
|
||||
CALLBACK(shared_data_destroy, void,
|
||||
shared_data_t *data)
|
||||
{
|
||||
data->lock->unlock(data->lock);
|
||||
free(data);
|
||||
@@ -499,44 +499,47 @@ static id_match_t has_owner(shared_entry_t *entry, identification_t *owner)
|
||||
return best;
|
||||
}
|
||||
|
||||
/**
|
||||
* enumerator filter function for shared entries
|
||||
*/
|
||||
static bool shared_filter(shared_data_t *data,
|
||||
shared_entry_t **in, shared_key_t **out,
|
||||
void **unused1, id_match_t *me,
|
||||
void **unused2, id_match_t *other)
|
||||
CALLBACK(shared_filter, bool,
|
||||
shared_data_t *data, enumerator_t *orig, va_list args)
|
||||
{
|
||||
id_match_t my_match = ID_MATCH_NONE, other_match = ID_MATCH_NONE;
|
||||
shared_entry_t *entry = *in;
|
||||
shared_entry_t *entry;
|
||||
shared_key_t **out;
|
||||
id_match_t *me, *other;
|
||||
|
||||
if (data->type != SHARED_ANY &&
|
||||
entry->shared->get_type(entry->shared) != data->type)
|
||||
VA_ARGS_VGET(args, out, me, other);
|
||||
|
||||
while (orig->enumerate(orig, &entry))
|
||||
{
|
||||
return FALSE;
|
||||
if (data->type != SHARED_ANY &&
|
||||
entry->shared->get_type(entry->shared) != data->type)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (data->me)
|
||||
{
|
||||
my_match = has_owner(entry, data->me);
|
||||
}
|
||||
if (data->other)
|
||||
{
|
||||
other_match = has_owner(entry, data->other);
|
||||
}
|
||||
if ((data->me || data->other) && (!my_match && !other_match))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
*out = entry->shared;
|
||||
if (me)
|
||||
{
|
||||
*me = my_match;
|
||||
}
|
||||
if (other)
|
||||
{
|
||||
*other = other_match;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
if (data->me)
|
||||
{
|
||||
my_match = has_owner(entry, data->me);
|
||||
}
|
||||
if (data->other)
|
||||
{
|
||||
other_match = has_owner(entry, data->other);
|
||||
}
|
||||
if ((data->me || data->other) && (!my_match && !other_match))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
*out = entry->shared;
|
||||
if (me)
|
||||
{
|
||||
*me = my_match;
|
||||
}
|
||||
if (other)
|
||||
{
|
||||
*other = other_match;
|
||||
}
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(credential_set_t, create_shared_enumerator, enumerator_t*,
|
||||
@@ -554,7 +557,7 @@ METHOD(credential_set_t, create_shared_enumerator, enumerator_t*,
|
||||
data->lock->read_lock(data->lock);
|
||||
return enumerator_create_filter(
|
||||
this->shared->create_enumerator(this->shared),
|
||||
(void*)shared_filter, data, (void*)shared_data_destroy);
|
||||
shared_filter, data, shared_data_destroy);
|
||||
}
|
||||
|
||||
METHOD(mem_cred_t, add_shared_unique, void,
|
||||
@@ -648,23 +651,27 @@ METHOD(mem_cred_t, remove_shared_unique, void,
|
||||
this->lock->unlock(this->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter unique ids of shared keys (ingore secrets without unique id)
|
||||
*/
|
||||
static bool unique_filter(void *unused,
|
||||
shared_entry_t **in, char **id)
|
||||
CALLBACK(unique_filter, bool,
|
||||
void *unused, enumerator_t *orig, va_list args)
|
||||
{
|
||||
shared_entry_t *entry = *in;
|
||||
shared_entry_t *entry;
|
||||
char **id;
|
||||
|
||||
if (!entry->id)
|
||||
VA_ARGS_VGET(args, id);
|
||||
|
||||
while (orig->enumerate(orig, &entry))
|
||||
{
|
||||
return FALSE;
|
||||
if (!entry->id)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (id)
|
||||
{
|
||||
*id = entry->id;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
if (id)
|
||||
{
|
||||
*id = entry->id;
|
||||
}
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(mem_cred_t, create_unique_shared_enumerator, enumerator_t*,
|
||||
@@ -673,7 +680,7 @@ METHOD(mem_cred_t, create_unique_shared_enumerator, enumerator_t*,
|
||||
this->lock->read_lock(this->lock);
|
||||
return enumerator_create_filter(
|
||||
this->shared->create_enumerator(this->shared),
|
||||
(void*)unique_filter, this->lock,
|
||||
unique_filter, this->lock,
|
||||
(void*)this->lock->unlock);
|
||||
}
|
||||
|
||||
@@ -721,30 +728,35 @@ typedef struct {
|
||||
rwlock_t *lock;
|
||||
} cdp_data_t;
|
||||
|
||||
/**
|
||||
* Clean up CDP enumerator data
|
||||
*/
|
||||
static void cdp_data_destroy(cdp_data_t *data)
|
||||
CALLBACK(cdp_data_destroy, void,
|
||||
cdp_data_t *data)
|
||||
{
|
||||
data->lock->unlock(data->lock);
|
||||
free(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* CDP enumerator filter
|
||||
*/
|
||||
static bool cdp_filter(cdp_data_t *data, cdp_t **cdp, char **uri)
|
||||
CALLBACK(cdp_filter, bool,
|
||||
cdp_data_t *data, enumerator_t *orig, va_list args)
|
||||
{
|
||||
if (data->type != CERT_ANY && data->type != (*cdp)->type)
|
||||
cdp_t *cdp;
|
||||
char **uri;
|
||||
|
||||
VA_ARGS_VGET(args, uri);
|
||||
|
||||
while (orig->enumerate(orig, &cdp))
|
||||
{
|
||||
return FALSE;
|
||||
if (data->type != CERT_ANY && data->type != cdp->type)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (data->id && !cdp->id->matches(cdp->id, data->id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
*uri = cdp->uri;
|
||||
return TRUE;
|
||||
}
|
||||
if (data->id && !(*cdp)->id->matches((*cdp)->id, data->id))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
*uri = (*cdp)->uri;
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(credential_set_t, create_cdp_enumerator, enumerator_t*,
|
||||
@@ -759,7 +771,7 @@ METHOD(credential_set_t, create_cdp_enumerator, enumerator_t*,
|
||||
);
|
||||
this->lock->read_lock(this->lock);
|
||||
return enumerator_create_filter(this->cdps->create_enumerator(this->cdps),
|
||||
(void*)cdp_filter, data, (void*)cdp_data_destroy);
|
||||
cdp_filter, data, cdp_data_destroy);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user