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:
@@ -153,30 +153,32 @@ static bool load_certificates(private_pkcs11_creds_t *this)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* filter function for certs enumerator
|
||||
*/
|
||||
static bool certs_filter(identification_t *id,
|
||||
certificate_t **in, certificate_t **out)
|
||||
CALLBACK(certs_filter, bool,
|
||||
identification_t *id, enumerator_t *orig, va_list args)
|
||||
{
|
||||
public_key_t *public;
|
||||
certificate_t *cert = *in;
|
||||
certificate_t *cert, **out;
|
||||
|
||||
if (id == NULL || cert->has_subject(cert, id))
|
||||
VA_ARGS_VGET(args, out);
|
||||
|
||||
while (orig->enumerate(orig, &cert))
|
||||
{
|
||||
*out = *in;
|
||||
return TRUE;
|
||||
}
|
||||
public = cert->get_public_key(cert);
|
||||
if (public)
|
||||
{
|
||||
if (public->has_fingerprint(public, id->get_encoding(id)))
|
||||
if (id == NULL || cert->has_subject(cert, id))
|
||||
{
|
||||
public->destroy(public);
|
||||
*out = *in;
|
||||
*out = cert;
|
||||
return TRUE;
|
||||
}
|
||||
public->destroy(public);
|
||||
public = cert->get_public_key(cert);
|
||||
if (public)
|
||||
{
|
||||
if (public->has_fingerprint(public, id->get_encoding(id)))
|
||||
{
|
||||
public->destroy(public);
|
||||
*out = cert;
|
||||
return TRUE;
|
||||
}
|
||||
public->destroy(public);
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
@@ -199,7 +201,7 @@ METHOD(credential_set_t, create_cert_enumerator, enumerator_t*,
|
||||
{
|
||||
inner = this->untrusted->create_enumerator(this->untrusted);
|
||||
}
|
||||
return enumerator_create_filter(inner, (void*)certs_filter, id, NULL);
|
||||
return enumerator_create_filter(inner, certs_filter, id, NULL);
|
||||
}
|
||||
|
||||
METHOD(pkcs11_creds_t, get_library, pkcs11_library_t*,
|
||||
|
||||
@@ -465,34 +465,48 @@ static plugin_entry_t *load_plugin(private_plugin_loader_t *this, char *name,
|
||||
return entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert enumerated provided_feature_t to plugin_feature_t
|
||||
*/
|
||||
static bool feature_filter(void *null, provided_feature_t **provided,
|
||||
plugin_feature_t **feature)
|
||||
CALLBACK(feature_filter, bool,
|
||||
void *null, enumerator_t *orig, va_list args)
|
||||
{
|
||||
*feature = (*provided)->feature;
|
||||
return (*provided)->loaded;
|
||||
provided_feature_t *provided;
|
||||
plugin_feature_t **feature;
|
||||
|
||||
VA_ARGS_VGET(args, feature);
|
||||
|
||||
while (orig->enumerate(orig, &provided))
|
||||
{
|
||||
if (provided->loaded)
|
||||
{
|
||||
*feature = provided->feature;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert enumerated entries to plugin_t
|
||||
*/
|
||||
static bool plugin_filter(void *null, plugin_entry_t **entry, plugin_t **plugin,
|
||||
void *in, linked_list_t **list)
|
||||
CALLBACK(plugin_filter, bool,
|
||||
void *null, enumerator_t *orig, va_list args)
|
||||
{
|
||||
plugin_entry_t *this = *entry;
|
||||
plugin_entry_t *entry;
|
||||
linked_list_t **list;
|
||||
plugin_t **plugin;
|
||||
|
||||
*plugin = this->plugin;
|
||||
if (list)
|
||||
VA_ARGS_VGET(args, plugin, list);
|
||||
|
||||
if (orig->enumerate(orig, &entry))
|
||||
{
|
||||
enumerator_t *features;
|
||||
features = enumerator_create_filter(
|
||||
this->features->create_enumerator(this->features),
|
||||
(void*)feature_filter, NULL, NULL);
|
||||
*list = linked_list_create_from_enumerator(features);
|
||||
*plugin = entry->plugin;
|
||||
if (list)
|
||||
{
|
||||
enumerator_t *features;
|
||||
features = enumerator_create_filter(
|
||||
entry->features->create_enumerator(entry->features),
|
||||
feature_filter, NULL, NULL);
|
||||
*list = linked_list_create_from_enumerator(features);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(plugin_loader_t, create_plugin_enumerator, enumerator_t*,
|
||||
@@ -500,7 +514,7 @@ METHOD(plugin_loader_t, create_plugin_enumerator, enumerator_t*,
|
||||
{
|
||||
return enumerator_create_filter(
|
||||
this->plugins->create_enumerator(this->plugins),
|
||||
(void*)plugin_filter, NULL, NULL);
|
||||
plugin_filter, NULL, NULL);
|
||||
}
|
||||
|
||||
METHOD(plugin_loader_t, has_feature, bool,
|
||||
@@ -1095,14 +1109,20 @@ static int plugin_priority_cmp(const plugin_priority_t *a,
|
||||
return diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert enumerated plugin_priority_t to a plugin name
|
||||
*/
|
||||
static bool plugin_priority_filter(void *null, plugin_priority_t **prio,
|
||||
char **name)
|
||||
CALLBACK(plugin_priority_filter, bool,
|
||||
void *null, enumerator_t *orig, va_list args)
|
||||
{
|
||||
*name = (*prio)->name;
|
||||
return TRUE;
|
||||
plugin_priority_t *prio;
|
||||
char **name;
|
||||
|
||||
VA_ARGS_VGET(args, name);
|
||||
|
||||
if (orig->enumerate(orig, &prio))
|
||||
{
|
||||
*name = prio->name;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1142,7 +1162,7 @@ static char *modular_pluginlist(char *list)
|
||||
else
|
||||
{
|
||||
enumerator = enumerator_create_filter(array_create_enumerator(given),
|
||||
(void*)plugin_priority_filter, NULL, NULL);
|
||||
plugin_priority_filter, NULL, NULL);
|
||||
load_def = TRUE;
|
||||
}
|
||||
while (enumerator->enumerate(enumerator, &plugin))
|
||||
|
||||
@@ -804,20 +804,27 @@ METHOD(ac_t, get_authKeyIdentifier, chunk_t,
|
||||
return this->authKeyIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function for attribute enumeration
|
||||
*/
|
||||
static bool attr_filter(void *null, group_t **in, ac_group_type_t *type,
|
||||
void *in2, chunk_t *out)
|
||||
CALLBACK(attr_filter, bool,
|
||||
void *null, enumerator_t *orig, va_list args)
|
||||
{
|
||||
if ((*in)->type == AC_GROUP_TYPE_STRING &&
|
||||
!chunk_printable((*in)->value, NULL, 0))
|
||||
{ /* skip non-printable strings */
|
||||
return FALSE;
|
||||
group_t *group;
|
||||
ac_group_type_t *type;
|
||||
chunk_t *out;
|
||||
|
||||
VA_ARGS_VGET(args, type, out);
|
||||
|
||||
while (orig->enumerate(orig, &group))
|
||||
{
|
||||
if (group->type == AC_GROUP_TYPE_STRING &&
|
||||
!chunk_printable(group->value, NULL, 0))
|
||||
{ /* skip non-printable strings */
|
||||
continue;
|
||||
}
|
||||
*type = group->type;
|
||||
*out = group->value;
|
||||
return TRUE;
|
||||
}
|
||||
*type = (*in)->type;
|
||||
*out = (*in)->value;
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(ac_t, create_group_enumerator, enumerator_t*,
|
||||
@@ -825,7 +832,7 @@ METHOD(ac_t, create_group_enumerator, enumerator_t*,
|
||||
{
|
||||
return enumerator_create_filter(
|
||||
this->groups->create_enumerator(this->groups),
|
||||
(void*)attr_filter, NULL, NULL);
|
||||
attr_filter, NULL, NULL);
|
||||
}
|
||||
|
||||
METHOD(certificate_t, get_type, certificate_type_t,
|
||||
|
||||
@@ -364,25 +364,33 @@ end:
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* enumerator filter callback for create_enumerator
|
||||
*/
|
||||
static bool filter(void *data, revoked_t **revoked, chunk_t *serial, void *p2,
|
||||
time_t *date, void *p3, crl_reason_t *reason)
|
||||
CALLBACK(filter, bool,
|
||||
void *data, enumerator_t *orig, va_list args)
|
||||
{
|
||||
if (serial)
|
||||
revoked_t *revoked;
|
||||
crl_reason_t *reason;
|
||||
chunk_t *serial;
|
||||
time_t *date;
|
||||
|
||||
VA_ARGS_VGET(args, serial, date, reason);
|
||||
|
||||
if (orig->enumerate(orig, &revoked))
|
||||
{
|
||||
*serial = (*revoked)->serial;
|
||||
if (serial)
|
||||
{
|
||||
*serial = revoked->serial;
|
||||
}
|
||||
if (date)
|
||||
{
|
||||
*date = revoked->date;
|
||||
}
|
||||
if (reason)
|
||||
{
|
||||
*reason = revoked->reason;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
if (date)
|
||||
{
|
||||
*date = (*revoked)->date;
|
||||
}
|
||||
if (reason)
|
||||
{
|
||||
*reason = (*revoked)->reason;
|
||||
}
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(crl_t, get_serial, chunk_t,
|
||||
@@ -422,7 +430,7 @@ METHOD(crl_t, create_enumerator, enumerator_t*,
|
||||
{
|
||||
return enumerator_create_filter(
|
||||
this->revoked->create_enumerator(this->revoked),
|
||||
(void*)filter, NULL, NULL);
|
||||
filter, NULL, NULL);
|
||||
}
|
||||
|
||||
METHOD(certificate_t, get_type, certificate_type_t,
|
||||
|
||||
@@ -228,32 +228,38 @@ METHOD(ocsp_response_t, create_cert_enumerator, enumerator_t*,
|
||||
return this->certs->create_enumerator(this->certs);
|
||||
}
|
||||
|
||||
/**
|
||||
* enumerator filter callback for create_response_enumerator
|
||||
*/
|
||||
static bool filter(void *data, single_response_t **response,
|
||||
chunk_t *serialNumber,
|
||||
void *p2, cert_validation_t *status,
|
||||
void *p3, time_t *revocationTime,
|
||||
void *p4, crl_reason_t *revocationReason)
|
||||
CALLBACK(filter, bool,
|
||||
void *data, enumerator_t *orig, va_list args)
|
||||
{
|
||||
if (serialNumber)
|
||||
single_response_t *response;
|
||||
cert_validation_t *status;
|
||||
crl_reason_t *revocationReason;
|
||||
chunk_t *serialNumber;
|
||||
time_t *revocationTime;
|
||||
|
||||
VA_ARGS_VGET(args, serialNumber, status, revocationTime, revocationReason);
|
||||
|
||||
if (orig->enumerate(orig, &response))
|
||||
{
|
||||
*serialNumber = (*response)->serialNumber;
|
||||
if (serialNumber)
|
||||
{
|
||||
*serialNumber = response->serialNumber;
|
||||
}
|
||||
if (status)
|
||||
{
|
||||
*status = response->status;
|
||||
}
|
||||
if (revocationTime)
|
||||
{
|
||||
*revocationTime = response->revocationTime;
|
||||
}
|
||||
if (revocationReason)
|
||||
{
|
||||
*revocationReason = response->revocationReason;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
if (status)
|
||||
{
|
||||
*status = (*response)->status;
|
||||
}
|
||||
if (revocationTime)
|
||||
{
|
||||
*revocationTime = (*response)->revocationTime;
|
||||
}
|
||||
if (revocationReason)
|
||||
{
|
||||
*revocationReason = (*response)->revocationReason;
|
||||
}
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(ocsp_response_t, create_response_enumerator, enumerator_t*,
|
||||
@@ -261,7 +267,7 @@ METHOD(ocsp_response_t, create_response_enumerator, enumerator_t*,
|
||||
{
|
||||
return enumerator_create_filter(
|
||||
this->responses->create_enumerator(this->responses),
|
||||
(void*)filter, NULL, NULL);
|
||||
filter, NULL, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user