This avoids the unportable five pointer hack.
}
}
-/**
- * Find a list entry with given src, dst, (remote) spi and proto values.
- */
-static bool sad_entry_match(sad_entry_t * const entry, const host_t * const src,
- const host_t * const dst, const uint32_t * const spi,
- const uint8_t * const proto)
+CALLBACK(sad_entry_match, bool,
+ sad_entry_t * const entry, va_list args)
{
+ const host_t *src, *dst;
+ const uint32_t *spi;
+ const uint8_t *proto;
+
+ VA_ARGS_VGET(args, src, dst, spi, proto);
+
if (entry->src == NULL || entry->dst == NULL)
{
return FALSE;
}
-
return src->ip_equals(entry->src, (host_t *)src) &&
dst->ip_equals(entry->dst, (host_t *)dst) &&
entry->spi_rem == *spi && entry->proto == *proto;
}
-/**
- * Find a list entry with given reqid, spi and proto values.
- */
-static bool sad_entry_match_dst(sad_entry_t * const entry,
- const uint32_t * const reqid,
- const uint32_t * const spi,
- const uint8_t * const proto)
+CALLBACK(sad_entry_match_dst, bool,
+ sad_entry_t * const entry, va_list args)
{
+ const uint32_t *reqid, *spi;
+ const uint8_t *proto;
+
+ VA_ARGS_VGET(args, reqid, spi, proto);
return entry->reqid == *reqid &&
entry->spi_rem == *spi &&
entry->proto == *proto;
}
-/**
- * Find a list entry with given esa id.
- */
-static bool sad_entry_match_esa_id(sad_entry_t * const entry,
- const esa_id_type * const esa_id)
+CALLBACK(sad_entry_match_esa_id, bool,
+ sad_entry_t * const entry, va_list args)
{
+ const esa_id_type *esa_id;
+
+ VA_ARGS_VGET(args, esa_id);
return entry->esa_id == *esa_id;
}
-/**
- * Find a list entry with given reqid and different esa id.
- */
-static bool sad_entry_match_other_esa(sad_entry_t * const entry,
- const esa_id_type * const esa_id,
- const uint32_t * const reqid)
+CALLBACK(sad_entry_match_other_esa, bool,
+ sad_entry_t * const entry, va_list args)
{
+ const esa_id_type *esa_id;
+ const uint32_t *reqid;
+
+ VA_ARGS_VGET(args, esa_id, reqid);
return entry->reqid == *reqid &&
entry->esa_id != *esa_id;
}
-/**
- * Compare two SAD entries for equality.
- */
-static bool sad_entry_equal(sad_entry_t * const left, sad_entry_t * const right)
+CALLBACK(sad_entry_equal, bool,
+ sad_entry_t * const left, va_list args)
{
+ sad_entry_t *right;
+
+ VA_ARGS_VGET(args, right);
+
if (left->src == NULL || left->dst == NULL || right->src == NULL ||
right->dst == NULL)
{
const uint32_t reqid, const host_t * const src, const host_t * const dst,
const uint32_t spi_loc, const uint32_t spi_rem, const uint8_t proto)
{
- status_t result;
sad_entry_t *new_entry;
+ bool found;
INIT(new_entry,
.esa_id = esa_id,
);
this->mutex->lock(this->mutex);
- result = this->data->find_first(this->data,
- (linked_list_match_t)sad_entry_equal, NULL,
+ found = this->data->find_first(this->data, sad_entry_equal, NULL,
new_entry);
- if (result == NOT_FOUND)
+ if (!found)
{
DBG3(DBG_KNL, "inserting SAD entry (esa: %llu, reqid: %u, src: %H, "
"dst: %H, spi_loc: %x, spi_rem: %x,proto: %u)", esa_id, reqid, src,
free(new_entry);
}
this->mutex->unlock(this->mutex);
- return result == NOT_FOUND;
+ return !found;
}
METHOD(tkm_kernel_sad_t, get_esa_id, esa_id_type,
sad_entry_t *entry = NULL;
this->mutex->lock(this->mutex);
- const status_t res = this->data->find_first(this->data,
- (linked_list_match_t)sad_entry_match,
- (void**)&entry, src, dst, &spi,
- &proto);
- if (res == SUCCESS && entry)
+ const bool res = this->data->find_first(this->data, sad_entry_match,
+ (void**)&entry, src, dst, &spi,
+ &proto);
+ if (res && entry)
{
id = entry->esa_id;
DBG3(DBG_KNL, "returning ESA id %llu of SAD entry (src: %H, dst: %H, "
esa_id_type id = 0;
sad_entry_t *entry = NULL;
uint32_t reqid;
- status_t res;
+ bool res;
this->mutex->lock(this->mutex);
- res = this->data->find_first(this->data,
- (linked_list_match_t)sad_entry_match_esa_id,
+ res = this->data->find_first(this->data, sad_entry_match_esa_id,
(void**)&entry, &esa_id);
- if (res == SUCCESS && entry)
+ if (res && entry)
{
reqid = entry->reqid;
}
return id;
}
- res = this->data->find_first(this->data,
- (linked_list_match_t)sad_entry_match_other_esa,
+ res = this->data->find_first(this->data, sad_entry_match_other_esa,
(void**)&entry, &esa_id, &reqid);
- if (res == SUCCESS && entry)
+ if (res && entry)
{
id = entry->esa_id;
DBG3(DBG_KNL, "returning ESA id %llu of other SAD entry with reqid %u",
sad_entry_t *entry = NULL;
this->mutex->lock(this->mutex);
- const status_t res = this->data->find_first(this->data,
- (linked_list_match_t)sad_entry_match_dst,
- (void**)&entry, &reqid, &spi, &proto);
- if (res == SUCCESS && entry)
+ const bool res = this->data->find_first(this->data, sad_entry_match_dst,
+ (void**)&entry, &reqid, &spi, &proto);
+ if (res && entry)
{
dst = entry->dst;
DBG3(DBG_KNL, "returning destination host %H of SAD entry (reqid: %u,"
free(this);
}
-/**
- * compare two overlays by path
- */
-static bool overlay_equals(overlay_t *this, overlay_t *other)
+CALLBACK(overlay_equals, bool,
+ overlay_t *this, va_list args)
{
+ overlay_t *other;
+
+ VA_ARGS_VGET(args, other);
return streq(this->path, other->path);
}
{
overlay_t over, *current;
over.path = path;
- if (this->overlays->find_first(this->overlays,
- (linked_list_match_t)overlay_equals, (void**)¤t, &over) != SUCCESS)
+ if (!this->overlays->find_first(this->overlays, overlay_equals,
+ (void**)¤t, &over))
{
return FALSE;
}
return host_create_from_sockaddr((sockaddr_t*)&addr);
}
+CALLBACK(vip_equals, bool,
+ host_t *vip, va_list args)
+{
+ host_t *host;
+
+ VA_ARGS_VGET(args, host);
+ return host->ip_equals(host, vip);
+}
+
METHOD(kernel_net_t, get_source_addr_old, host_t*,
private_android_net_t *this, host_t *dest, host_t *src)
{
if (host)
{
this->mutex->lock(this->mutex);
- if (this->vips->find_first(this->vips, (void*)host->ip_equals,
- NULL, host) == SUCCESS)
+ if (this->vips->find_first(this->vips, vip_equals, NULL, host))
{
host->destroy(host);
host = NULL;
host_t *vip;
this->mutex->lock(this->mutex);
- if (this->vips->find_first(this->vips, (void*)virtual_ip->ip_equals,
- (void**)&vip, virtual_ip) == SUCCESS)
+ if (this->vips->find_first(this->vips, vip_equals, (void**)&vip,
+ virtual_ip))
{
this->vips->remove(this->vips, vip, NULL);
vip->destroy(vip);
}
}
-/**
- * Find the log level of the first registered logger that implements log or
- * vlog (or both).
- */
-static bool find_max_levels(log_entry_t *entry, debug_t *group, level_t *level,
- level_t *vlevel)
+CALLBACK(find_max_levels, bool,
+ log_entry_t *entry, va_list args)
{
+ level_t *level, *vlevel;
+ debug_t group;
+
+ VA_ARGS_VGET(args, group, level, vlevel);
if (entry->logger->log && *level == LEVEL_SILENT)
{
- *level = entry->levels[*group];
+ *level = entry->levels[group];
}
if (entry->logger->vlog && *vlevel == LEVEL_SILENT)
{
- *vlevel = entry->levels[*group];
+ *vlevel = entry->levels[group];
}
return *level > LEVEL_SILENT && *vlevel > LEVEL_SILENT;
}
loggers = this->loggers[group];
loggers->remove(loggers, found, NULL);
- loggers->find_first(loggers, (linked_list_match_t)find_max_levels,
- NULL, &group, &level, &vlevel);
+ loggers->find_first(loggers, find_max_levels, NULL, group,
+ &level, &vlevel);
set_level(&this->max_level[group], level);
set_level(&this->max_vlevel[group], vlevel);
}
}
}
-static bool match_proposal(proposal_t *item, proposal_t *proposal)
+CALLBACK(match_proposal, bool,
+ proposal_t *item, va_list args)
{
+ proposal_t *proposal;
+
+ VA_ARGS_VGET(args, proposal);
return item->equals(item, proposal);
}
{
current->strip_dh(current, MODP_NONE);
}
- if (proposals->find_first(proposals, (linked_list_match_t)match_proposal,
- NULL, current) == SUCCESS)
+ if (proposals->find_first(proposals, match_proposal, NULL, current))
{
current->destroy(current);
continue;
logger_entry_destroy(this);
}
-/**
- * Match a logger entry by target and whether it is a file or syslog logger
- */
-static bool logger_entry_match(logger_entry_t *this, char *target,
- logger_type_t *type)
+CALLBACK(logger_entry_match, bool,
+ logger_entry_t *this, va_list args)
{
- return this->type == *type && streq(this->target, target);
+ logger_type_t type;
+ char *target;
+
+ VA_ARGS_VGET(args, target, type);
+ return this->type == type && streq(this->target, target);
}
/**
{
logger_entry_t *entry;
- if (existing->find_first(existing, (void*)logger_entry_match,
- (void**)&entry, target, &type) != SUCCESS)
+ if (!existing->find_first(existing, logger_entry_match, (void**)&entry,
+ target, type))
{
INIT(entry,
.target = strdup(target),
METHOD(kernel_interface_t, is_interface_usable, bool,
private_kernel_interface_t *this, const char *iface)
{
- status_t expected;
-
if (!this->ifaces_filter)
{
return TRUE;
}
- expected = this->ifaces_exclude ? NOT_FOUND : SUCCESS;
- return this->ifaces_filter->find_first(this->ifaces_filter, (void*)streq,
- NULL, iface) == expected;
+ return this->ifaces_filter->find_first(this->ifaces_filter,
+ linked_list_match_str, NULL, iface) != this->ifaces_exclude;
}
METHOD(kernel_interface_t, all_interfaces_usable, bool,
private_kernel_interface_t *this)
{
- return this->ifaces_filter == NULL;
+ return !this->ifaces_filter;
}
METHOD(kernel_interface_t, get_address_by_ts, status_t,
*/
static bool consider_interface(private_bypass_lan_listener_t *this, char *iface)
{
- status_t expected;
-
if (!iface || !this->ifaces_filter)
{
return TRUE;
}
- expected = this->ifaces_exclude ? NOT_FOUND : SUCCESS;
- return this->ifaces_filter->find_first(this->ifaces_filter, (void*)streq,
- NULL, iface) == expected;
+ return this->ifaces_filter->find_first(this->ifaces_filter,
+ linked_list_match_str, NULL, iface) != this->ifaces_exclude;
}
/**
identification_t *id;
host_t *vip;
- if (pools->find_first(pools, (linked_list_match_t)streq,
- NULL, "dhcp") != SUCCESS)
+ if (!pools->find_first(pools, linked_list_match_str, NULL, "dhcp"))
{
return NULL;
}
while (try <= DHCP_TRIES && discover(this, transaction))
{
if (!this->condvar->timed_wait(this->condvar, this->mutex, 1000 * try) &&
- this->request->find_first(this->request, NULL,
- (void**)&transaction) == SUCCESS)
+ this->request->find_first(this->request, NULL, (void**)&transaction))
{
break;
}
return item->type == other->type && item->vendor == other->vendor;
}
+CALLBACK(entry_matches_cb, bool,
+ eap_vendor_type_t *item, va_list args)
+{
+ eap_vendor_type_t *other;
+
+ VA_ARGS_VGET(args, other);
+ return entry_matches(item, other);
+}
+
/**
* Load the given EAP method
*/
{
if (inner)
{
- if (inner->find_first(inner, (void*)entry_matches,
- NULL, entry) != SUCCESS)
+ if (!inner->find_first(inner, entry_matches_cb, NULL, entry))
{
if (entry->vendor)
{
free(this);
}
-/**
- * Find an exclude route entry by destination address
- */
-static bool exclude_route_match(exclude_route_t *current,
- host_t *dst)
+CALLBACK(exclude_route_match, bool,
+ exclude_route_t *current, va_list args)
{
+ host_t *dst;
+
+ VA_ARGS_VGET(args, dst);
return dst->ip_equals(dst, current->dst);
}
free(this);
}
-/**
- * Compare two policy_entry_t objects
- */
-static inline bool policy_entry_equals(policy_entry_t *a,
- policy_entry_t *b)
+CALLBACK(policy_entry_equals, bool,
+ policy_entry_t *a, va_list args)
{
+ policy_entry_t *b;
+
+ VA_ARGS_VGET(args, b);
return a->direction == b->direction &&
a->src.proto == b->src.proto &&
a->dst.proto == b->dst.proto &&
exclude_route_t *exclude;
host_t *gtw;
- if (this->excludes->find_first(this->excludes,
- (linked_list_match_t)exclude_route_match,
- (void**)&exclude, dst) == SUCCESS)
+ if (this->excludes->find_first(this->excludes, exclude_route_match,
+ (void**)&exclude, dst))
{
route->exclude = exclude;
exclude->refs++;
policy = create_policy_entry(id->src_ts, id->dst_ts, id->dir);
this->mutex->lock(this->mutex);
- if (this->policies->find_first(this->policies,
- (linked_list_match_t)policy_entry_equals,
- (void**)&found, policy) == SUCCESS)
+ if (this->policies->find_first(this->policies, policy_entry_equals,
+ (void**)&found, policy))
{
policy_entry_destroy(policy);
policy = found;
policy = create_policy_entry(id->src_ts, id->dst_ts, id->dir);
this->mutex->lock(this->mutex);
- if (this->policies->find_first(this->policies,
- (linked_list_match_t)policy_entry_equals,
- (void**)&found, policy) != SUCCESS)
+ if (!this->policies->find_first(this->policies, policy_entry_equals,
+ (void**)&found, policy))
{
policy_entry_destroy(policy);
this->mutex->unlock(this->mutex);
free(this);
}
-/**
- * find an interface entry by index
- */
-static bool iface_entry_by_index(iface_entry_t *this, int *ifindex)
+CALLBACK(iface_entry_by_index, bool,
+ iface_entry_t *this, va_list args)
{
- return this->ifindex == *ifindex;
+ int ifindex;
+
+ VA_ARGS_VGET(args, ifindex);
+ return this->ifindex == ifindex;
}
-/**
- * find an interface entry by name
- */
-static bool iface_entry_by_name(iface_entry_t *this, char *ifname)
+CALLBACK(iface_entry_by_name, bool,
+ iface_entry_t *this, va_list args)
{
+ char *ifname;
+
+ VA_ARGS_VGET(args, ifname);
return streq(this->ifname, ifname);
}
{
iface_entry_t *iface;
- if (this->ifaces->find_first(this->ifaces, (void*)iface_entry_by_index,
- (void**)&iface, &index) == SUCCESS)
+ if (this->ifaces->find_first(this->ifaces, iface_entry_by_index,
+ (void**)&iface, index))
{
return iface_entry_up_and_usable(iface);
}
{
case RTM_NEWLINK:
{
- if (this->ifaces->find_first(this->ifaces,
- (void*)iface_entry_by_index, (void**)&entry,
- &msg->ifi_index) != SUCCESS)
+ if (!this->ifaces->find_first(this->ifaces, iface_entry_by_index,
+ (void**)&entry, msg->ifi_index))
{
INIT(entry,
.ifindex = msg->ifi_index,
}
this->lock->write_lock(this->lock);
- if (this->ifaces->find_first(this->ifaces, (void*)iface_entry_by_index,
- (void**)&iface, &msg->ifa_index) == SUCCESS)
+ if (this->ifaces->find_first(this->ifaces, iface_entry_by_index,
+ (void**)&iface, msg->ifa_index))
{
addr_map_entry_t *entry, lookup = {
.ip = host,
DBG2(DBG_KNL, "getting iface index for %s", name);
this->lock->read_lock(this->lock);
- if (this->ifaces->find_first(this->ifaces, (void*)iface_entry_by_name,
- (void**)&iface, name) == SUCCESS)
+ if (this->ifaces->find_first(this->ifaces, iface_entry_by_name,
+ (void**)&iface, name))
{
ifindex = iface->ifindex;
}
DBG2(DBG_KNL, "getting iface name for index %d", index);
this->lock->read_lock(this->lock);
- if (this->ifaces->find_first(this->ifaces, (void*)iface_entry_by_index,
- (void**)&iface, &index) == SUCCESS)
+ if (this->ifaces->find_first(this->ifaces, iface_entry_by_index,
+ (void**)&iface, index))
{
name = strdup(iface->ifname);
}
table = (uintptr_t)route->table;
if (this->rt_exclude->find_first(this->rt_exclude, NULL,
- (void**)&table) == SUCCESS)
+ (void**)&table))
{ /* route is from an excluded routing table */
continue;
}
}
/* try to find the target interface, either by config or via src ip */
if (!this->install_virtual_ip_on ||
- this->ifaces->find_first(this->ifaces, (void*)iface_entry_by_name,
- (void**)&iface, this->install_virtual_ip_on) != SUCCESS)
+ !this->ifaces->find_first(this->ifaces, iface_entry_by_name,
+ (void**)&iface, this->install_virtual_ip_on))
{
- if (this->ifaces->find_first(this->ifaces, (void*)iface_entry_by_name,
- (void**)&iface, iface_name) != SUCCESS)
+ if (!this->ifaces->find_first(this->ifaces, iface_entry_by_name,
+ (void**)&iface, iface_name))
{ /* if we don't find the requested interface we just use the first */
this->ifaces->get_first(this->ifaces, (void**)&iface);
}
policy_entry_destroy(policy, this);
}
-/**
- * compares two policy_entry_t
- */
-static inline bool policy_entry_equals(policy_entry_t *current,
- policy_entry_t *policy)
+CALLBACK(policy_entry_equals, bool,
+ policy_entry_t *current, va_list args)
{
+ policy_entry_t *policy;
+
+ VA_ARGS_VGET(args, policy);
return current->direction == policy->direction &&
current->src.proto == policy->src.proto &&
current->dst.proto == policy->dst.proto &&
current->dst.net->equals(current->dst.net, policy->dst.net);
}
-/**
- * compare the given kernel index with that of a policy
- */
-static inline bool policy_entry_match_byindex(policy_entry_t *current,
- uint32_t *index)
+CALLBACK(policy_entry_match_byindex, bool,
+ policy_entry_t *current, va_list args)
{
- return current->index == *index;
+ uint32_t index;
+
+ VA_ARGS_VGET(args, index);
+ return current->index == index;
}
/**
index = response.x_policy->sadb_x_policy_id;
this->mutex->lock(this->mutex);
- if (this->policies->find_first(this->policies,
- (linked_list_match_t)policy_entry_match_byindex,
- (void**)&policy, &index) == SUCCESS &&
+ if (this->policies->find_first(this->policies, policy_entry_match_byindex,
+ (void**)&policy, index) &&
policy->used_by->get_first(policy->used_by, (void**)&sa) == SUCCESS)
{
reqid = sa->sa->cfg.reqid;
/* we try to find the policy again and update the kernel index */
this->mutex->lock(this->mutex);
- if (this->policies->find_first(this->policies, NULL,
- (void**)&policy) != SUCCESS)
+ if (!this->policies->find_first(this->policies, NULL, (void**)&policy))
{
DBG2(DBG_KNL, "unable to update index, the policy is already gone, "
"ignoring");
/* find a matching policy */
this->mutex->lock(this->mutex);
- if (this->policies->find_first(this->policies,
- (linked_list_match_t)policy_entry_equals,
- (void**)&found, policy) == SUCCESS)
+ if (this->policies->find_first(this->policies, policy_entry_equals,
+ (void**)&found, policy))
{ /* use existing policy */
DBG2(DBG_KNL, "policy %R === %R %N already exists, increasing "
"refcount", id->src_ts, id->dst_ts, policy_dir_names, id->dir);
/* find a matching policy */
this->mutex->lock(this->mutex);
- if (this->policies->find_first(this->policies,
- (linked_list_match_t)policy_entry_equals,
- (void**)&found, policy) != SUCCESS)
+ if (!this->policies->find_first(this->policies, policy_entry_equals,
+ (void**)&found, policy))
{
DBG1(DBG_KNL, "querying policy %R === %R %N failed, not found",
id->src_ts, id->dst_ts, policy_dir_names, id->dir);
/* find a matching policy */
this->mutex->lock(this->mutex);
- if (this->policies->find_first(this->policies,
- (linked_list_match_t)policy_entry_equals,
- (void**)&found, policy) != SUCCESS)
+ if (!this->policies->find_first(this->policies, policy_entry_equals,
+ (void**)&found, policy))
{
DBG1(DBG_KNL, "deleting policy %R === %R %N failed, not found",
id->src_ts, id->dst_ts, policy_dir_names, id->dir);
return FALSE;
}
-/**
- * Check if the given host has a matching address family
- */
-static bool is_family(host_t *host, int *family)
+CALLBACK(is_family, bool,
+ host_t *host, va_list args)
{
- return host->get_family(host) == *family;
+ int family;
+
+ VA_ARGS_VGET(args, family);
+ return host->get_family(host) == family;
}
/**
*/
static bool has_host_family(linked_list_t *list, int family)
{
- return list->find_first(list, (void*)is_family, NULL, &family) == SUCCESS;
+ return list->find_first(list, is_family, NULL, family);
}
METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t *,
data, (void*)cdp_data_destroy);
}
-/**
- * Compare the given certificate to the ca_cert_t items in the list
- */
-static bool match_cert(ca_cert_t *item, certificate_t *cert)
+CALLBACK(match_cert, bool,
+ ca_cert_t *item, va_list args)
{
+ certificate_t *cert;
+
+ VA_ARGS_VGET(args, cert);
return cert->equals(cert, item->cert);
}
{
ca_cert_t *found;
- if (this->certs->find_first(this->certs, (linked_list_match_t)match_cert,
- (void**)&found, cert) == SUCCESS)
+ if (this->certs->find_first(this->certs, match_cert, (void**)&found, cert))
{
cert->destroy(cert);
cert = found->cert->get_ref(found->cert);
ca_cert_t *found;
this->lock->read_lock(this->lock);
- if (this->certs->find_first(this->certs, (linked_list_match_t)match_cert,
- (void**)&found, cert) == SUCCESS)
+ if (this->certs->find_first(this->certs, match_cert, (void**)&found, cert))
{
cert->destroy(cert);
cert = found->cert->get_ref(found->cert);
{
case FEATURE_PROVIDE:
fp = &features[i];
- loaded = list->find_first(list, NULL,
- (void**)&fp) == SUCCESS;
+ loaded = list->find_first(list, NULL, (void**)&fp);
fprintf(out, " %s%s\n",
str, loaded ? "" : " (not loaded)");
break;
/**
* Function that matches entry_t objects by ike_sa_id_t.
*/
-static bool entry_match_by_id(entry_t *entry, ike_sa_id_t *id)
+static bool entry_match_by_id(entry_t *entry, void *arg)
{
+ ike_sa_id_t *id = arg;
+
if (id->equals(id, entry->ike_sa_id))
{
return TRUE;
/**
* Function that matches entry_t objects by ike_sa_t pointers.
*/
-static bool entry_match_by_sa(entry_t *entry, ike_sa_t *ike_sa)
+static bool entry_match_by_sa(entry_t *entry, void *ike_sa)
{
return entry->ike_sa == ike_sa;
}
*/
static status_t get_entry_by_match_function(private_ike_sa_manager_t *this,
ike_sa_id_t *ike_sa_id, entry_t **entry, u_int *segment,
- linked_list_match_t match, void *param)
+ bool (*match)(entry_t*,void*), void *param)
{
table_item_t *item;
u_int row, seg;
ike_sa_id_t *ike_sa_id, entry_t **entry, u_int *segment)
{
return get_entry_by_match_function(this, ike_sa_id, entry, segment,
- (linked_list_match_t)entry_match_by_id, ike_sa_id);
+ entry_match_by_id, ike_sa_id);
}
/**
ike_sa_id_t *ike_sa_id, ike_sa_t *ike_sa, entry_t **entry, u_int *segment)
{
return get_entry_by_match_function(this, ike_sa_id, entry, segment,
- (linked_list_match_t)entry_match_by_sa, ike_sa);
+ entry_match_by_sa, ike_sa);
}
/**
lock->unlock(lock);
}
+CALLBACK(id_matches, bool,
+ ike_sa_id_t *a, va_list args)
+{
+ ike_sa_id_t *b;
+
+ VA_ARGS_VGET(args, b);
+ return a->equals(a, b);
+}
+
/**
* Put an SA between two peers into the hash table.
*/
entry->other_id, family))
{
if (connected_peers->sas->find_first(connected_peers->sas,
- (linked_list_match_t)entry->ike_sa_id->equals,
- NULL, entry->ike_sa_id) == SUCCESS)
+ id_matches, NULL, entry->ike_sa_id))
{
lock->unlock(lock);
return;
return this;
}
-/**
- * Find an initiated connection by the peers' ids
- */
-static bool match_initiated_by_ids(initiated_t *current, identification_t *id,
- identification_t *peer_id)
+CALLBACK(match_initiated_by_ids, bool,
+ initiated_t *current, va_list args)
{
+ identification_t *id, *peer_id;
+
+ VA_ARGS_VGET(args, id, peer_id);
return id->equals(id, current->id) && peer_id->equals(peer_id, current->peer_id);
}
-static status_t get_initiated_by_ids(private_connect_manager_t *this,
- identification_t *id,
- identification_t *peer_id,
- initiated_t **initiated)
+static bool get_initiated_by_ids(private_connect_manager_t *this,
+ identification_t *id,
+ identification_t *peer_id,
+ initiated_t **initiated)
{
- return this->initiated->find_first(this->initiated,
- (linked_list_match_t)match_initiated_by_ids,
+ return this->initiated->find_first(this->initiated, match_initiated_by_ids,
(void**)initiated, id, peer_id);
}
enumerator->destroy(enumerator);
}
-/**
- * Find the checklist with a specific connect ID
- */
-static bool match_checklist_by_id(check_list_t *current, chunk_t *connect_id)
+CALLBACK(match_checklist_by_id, bool,
+ check_list_t *current, va_list args)
{
- return chunk_equals(*connect_id, current->connect_id);
+ chunk_t connect_id;
+
+ VA_ARGS_VGET(args, connect_id);
+ return chunk_equals(connect_id, current->connect_id);
}
-static status_t get_checklist_by_id(private_connect_manager_t *this,
- chunk_t connect_id,
- check_list_t **check_list)
+static bool get_checklist_by_id(private_connect_manager_t *this,
+ chunk_t connect_id, check_list_t **check_list)
{
- return this->checklists->find_first(this->checklists,
- (linked_list_match_t)match_checklist_by_id,
- (void**)check_list, &connect_id);
+ return this->checklists->find_first(this->checklists, match_checklist_by_id,
+ (void**)check_list, connect_id);
}
/**
enumerator->destroy(enumerator);
}
-/**
- * Checks if a list of endpoint_notify_t contains a certain host_t
- */
-static bool match_endpoint_by_host(endpoint_notify_t *current, host_t *host)
+CALLBACK(match_endpoint_by_host, bool,
+ endpoint_notify_t *current, va_list args)
{
+ host_t *host;
+
+ VA_ARGS_VGET(args, host);
return host->equals(host, current->get_host(current));
}
-static status_t endpoints_contain(linked_list_t *endpoints, host_t *host,
+static bool endpoints_contain(linked_list_t *endpoints, host_t *host,
endpoint_notify_t **endpoint)
{
- return endpoints->find_first(endpoints,
- (linked_list_match_t)match_endpoint_by_host,
+ return endpoints->find_first(endpoints, match_endpoint_by_host,
(void**)endpoint, host);
}
enumerator->destroy(enumerator);
}
-/**
- * Searches a list of endpoint_pair_t for a pair with specific host_ts
- */
-static bool match_pair_by_hosts(endpoint_pair_t *current, host_t *local,
- host_t *remote)
+CALLBACK(match_pair_by_hosts, bool,
+ endpoint_pair_t *current, va_list args)
{
- return local->equals(local, current->local) && remote->equals(remote, current->remote);
+ host_t *local, *remote;
+
+ VA_ARGS_VGET(args, local, remote);
+ return local->equals(local, current->local) &&
+ remote->equals(remote, current->remote);
}
-static status_t get_pair_by_hosts(linked_list_t *pairs, host_t *local,
- host_t *remote, endpoint_pair_t **pair)
+static bool get_pair_by_hosts(linked_list_t *pairs, host_t *local,
+ host_t *remote, endpoint_pair_t **pair)
{
- return pairs->find_first(pairs, (linked_list_match_t)match_pair_by_hosts,
- (void**)pair, local, remote);
+ return pairs->find_first(pairs, match_pair_by_hosts, (void**)pair, local,
+ remote);
}
-static bool match_pair_by_id(endpoint_pair_t *current, uint32_t *id)
+CALLBACK(match_pair_by_id, bool,
+ endpoint_pair_t *current, va_list args)
{
- return current->id == *id;
+ uint32_t id;
+
+ VA_ARGS_VGET(args, id);
+ return current->id == id;
}
/**
* Searches for a pair with a specific id
*/
-static status_t get_pair_by_id(check_list_t *checklist, uint32_t id,
- endpoint_pair_t **pair)
+static bool get_pair_by_id(check_list_t *checklist, uint32_t id,
+ endpoint_pair_t **pair)
{
- return checklist->pairs->find_first(checklist->pairs,
- (linked_list_match_t)match_pair_by_id,
- (void**)pair, &id);
+ return checklist->pairs->find_first(checklist->pairs, match_pair_by_id,
+ (void**)pair, id);
}
-static bool match_succeeded_pair(endpoint_pair_t *current)
+CALLBACK(match_succeeded_pair, bool,
+ endpoint_pair_t *current, va_list args)
{
return current->state == CHECK_SUCCEEDED;
}
/**
* Returns the best pair of state CHECK_SUCCEEDED from a checklist.
*/
-static status_t get_best_valid_pair(check_list_t *checklist,
- endpoint_pair_t **pair)
+static bool get_best_valid_pair(check_list_t *checklist, endpoint_pair_t **pair)
{
- return checklist->pairs->find_first(checklist->pairs,
- (linked_list_match_t)match_succeeded_pair,
- (void**)pair);
+ return checklist->pairs->find_first(checklist->pairs, match_succeeded_pair,
+ (void**)pair);
}
-static bool match_waiting_pair(endpoint_pair_t *current)
+CALLBACK(match_waiting_pair, bool,
+ endpoint_pair_t *current, va_list args)
{
return current->state == CHECK_WAITING;
}
this->mutex->lock(this->mutex);
check_list_t *checklist;
- if (get_checklist_by_id(this, data->connect_id, &checklist) != SUCCESS)
+ if (!get_checklist_by_id(this, data->connect_id, &checklist))
{
DBG1(DBG_IKE, "checklist with id '%#B' not found, can't finish "
"connectivity checks", &data->connect_id);
this->mutex->lock(this->mutex);
check_list_t *checklist;
- if (get_checklist_by_id(this, data->connect_id, &checklist) != SUCCESS)
+ if (!get_checklist_by_id(this, data->connect_id, &checklist))
{
DBG1(DBG_IKE, "checklist with id '%#B' not found, can't retransmit "
"connectivity check", &data->connect_id);
}
endpoint_pair_t *pair;
- if (get_pair_by_id(checklist, data->mid, &pair) != SUCCESS)
+ if (!get_pair_by_id(checklist, data->mid, &pair))
{
DBG1(DBG_IKE, "pair with id '%d' not found, can't retransmit "
"connectivity check", data->mid);
this->mutex->lock(this->mutex);
check_list_t *checklist;
- if (get_checklist_by_id(this, data->connect_id, &checklist) != SUCCESS)
+ if (!get_checklist_by_id(this, data->connect_id, &checklist))
{
DBG1(DBG_IKE, "checklist with id '%#B' not found, can't send "
"connectivity check", &data->connect_id);
{
DBG1(DBG_IKE, "no triggered check queued, sending an ordinary check");
- if (checklist->pairs->find_first(checklist->pairs,
- (linked_list_match_t)match_waiting_pair,
- (void**)&pair) != SUCCESS)
+ if (!checklist->pairs->find_first(checklist->pairs, match_waiting_pair,
+ (void**)&pair))
{
this->mutex->unlock(this->mutex);
DBG1(DBG_IKE, "no pairs in waiting state, aborting");
initiated_t *initiated = data->initiated;
endpoint_pair_t *pair;
- if (get_best_valid_pair(checklist, &pair) == SUCCESS)
+ if (get_best_valid_pair(checklist, &pair))
{
ike_sa_id_t *waiting_sa;
enumerator_t *enumerator = initiated->mediated->create_enumerator(
{
initiated_t *initiated;
if (get_initiated_by_ids(this, checklist->initiator.id,
- checklist->responder.id, &initiated) == SUCCESS)
+ checklist->responder.id, &initiated))
{
callback_job_t *job;
check_list_t *checklist)
{
endpoint_pair_t *pair;
- if (get_pair_by_id(checklist, check->mid, &pair) == SUCCESS)
+ if (get_pair_by_id(checklist, check->mid, &pair))
{
if (pair->local->equals(pair->local, check->dst) &&
pair->remote->equals(pair->remote, check->src))
checklist->initiator.endpoints : checklist->responder.endpoints;
endpoint_notify_t *local_endpoint;
- if (endpoints_contain(local_endpoints,
- check->endpoint->get_host(check->endpoint),
- &local_endpoint) != SUCCESS)
+ if (!endpoints_contain(local_endpoints,
+ check->endpoint->get_host(check->endpoint),
+ &local_endpoint))
{
local_endpoint = endpoint_notify_create_from_host(PEER_REFLEXIVE,
check->endpoint->get_host(check->endpoint), pair->local);
peer_reflexive->set_priority(peer_reflexive,
check->endpoint->get_priority(check->endpoint));
- if (endpoints_contain(remote_endpoints, check->src, &remote_endpoint) != SUCCESS)
+ if (!endpoints_contain(remote_endpoints, check->src, &remote_endpoint))
{
remote_endpoint = peer_reflexive->clone(peer_reflexive);
remote_endpoints->insert_last(remote_endpoints, remote_endpoint);
}
endpoint_pair_t *pair;
- if (get_pair_by_hosts(checklist->pairs, check->dst, check->src,
- &pair) == SUCCESS)
+ if (get_pair_by_hosts(checklist->pairs, check->dst, check->src, &pair))
{
switch(pair->state)
{
this->mutex->lock(this->mutex);
check_list_t *checklist;
- if (get_checklist_by_id(this, check->connect_id, &checklist) != SUCCESS)
+ if (!get_checklist_by_id(this, check->connect_id, &checklist))
{
DBG1(DBG_IKE, "checklist with id '%#B' not found",
&check->connect_id);
check_destroy(check);
}
+CALLBACK(id_matches, bool,
+ ike_sa_id_t *a, va_list args)
+{
+ ike_sa_id_t *b;
+
+ VA_ARGS_VGET(args, b);
+ return a->equals(a, b);
+}
+
METHOD(connect_manager_t, check_and_register, bool,
private_connect_manager_t *this, identification_t *id,
identification_t *peer_id, ike_sa_id_t *mediated_sa)
this->mutex->lock(this->mutex);
- if (get_initiated_by_ids(this, id, peer_id, &initiated) != SUCCESS)
+ if (!get_initiated_by_ids(this, id, peer_id, &initiated))
{
DBG2(DBG_IKE, "registered waiting mediated connection with '%Y'",
peer_id);
already_there = FALSE;
}
- if (initiated->mediated->find_first(initiated->mediated,
- (linked_list_match_t)mediated_sa->equals,
- NULL, mediated_sa) != SUCCESS)
+ if (!initiated->mediated->find_first(initiated->mediated, id_matches,
+ NULL, mediated_sa))
{
initiated->mediated->insert_last(initiated->mediated,
mediated_sa->clone(mediated_sa));
this->mutex->lock(this->mutex);
- if (get_initiated_by_ids(this, id, peer_id, &initiated) != SUCCESS)
+ if (!get_initiated_by_ids(this, id, peer_id, &initiated))
{
DBG2(DBG_IKE, "no waiting mediated connections with '%Y'", peer_id);
this->mutex->unlock(this->mutex);
this->mutex->lock(this->mutex);
- if (get_checklist_by_id(this, connect_id, NULL) == SUCCESS)
+ if (get_checklist_by_id(this, connect_id, NULL))
{
DBG1(DBG_IKE, "checklist with id '%#B' already exists, aborting",
&connect_id);
this->mutex->lock(this->mutex);
- if (get_checklist_by_id(this, connect_id, &checklist) != SUCCESS)
+ if (!get_checklist_by_id(this, connect_id, &checklist))
{
DBG1(DBG_IKE, "checklist with id '%#B' not found",
&connect_id);
this->mutex->lock(this->mutex);
- if (get_checklist_by_id(this, connect_id, &checklist) != SUCCESS)
+ if (!get_checklist_by_id(this, connect_id, &checklist))
{
DBG1(DBG_IKE, "checklist with id '%#B' not found",
&connect_id);
bool check_delete_action;
} entry_t;
-/**
- * Check if the given entry is for the same CHILD_SA
- */
-static bool match_child(entry_t *entry, child_sa_t *child_sa)
+CALLBACK(match_child, bool,
+ entry_t *entry, va_list args)
{
+ child_sa_t *child_sa;
+
+ VA_ARGS_VGET(args, child_sa);
return entry->child_sa == child_sa;
}
DBG1(DBG_IKE, "received DELETE for %N CHILD_SA with SPI %.8x",
protocol_id_names, protocol, ntohl(spi));
- if (this->child_sas->find_first(this->child_sas,
- (void*)match_child, NULL, child_sa) == SUCCESS)
+ if (this->child_sas->find_first(this->child_sas, match_child,
+ NULL, child_sa))
{
continue;
}
free(this);
}
-/**
- * match an acquire entry by reqid
- */
-static bool acquire_by_reqid(acquire_t *this, uint32_t *reqid)
+CALLBACK(acquire_by_reqid, bool,
+ acquire_t *this, va_list args)
{
- return this->reqid == *reqid;
+ uint32_t reqid;
+
+ VA_ARGS_VGET(args, reqid);
+ return this->reqid == reqid;
}
-/**
- * match an acquire entry by destination address
- */
-static bool acquire_by_dst(acquire_t *this, host_t *dst)
+CALLBACK(acquire_by_dst, bool,
+ acquire_t *this, va_list args)
{
+ host_t *dst;
+
+ VA_ARGS_VGET(args, dst);
return this->dst && this->dst->ip_equals(this->dst, dst);
}
uint8_t mask;
dst->to_subnet(dst, &host, &mask);
- if (this->acquires->find_first(this->acquires, (void*)acquire_by_dst,
- (void**)&acquire, host) == SUCCESS)
+ if (this->acquires->find_first(this->acquires, acquire_by_dst,
+ (void**)&acquire, host))
{
host->destroy(host);
ignore = TRUE;
}
else
{
- if (this->acquires->find_first(this->acquires, (void*)acquire_by_reqid,
- (void**)&acquire, &reqid) == SUCCESS)
+ if (this->acquires->find_first(this->acquires, acquire_by_reqid,
+ (void**)&acquire, reqid))
{
ignore = TRUE;
}
enumerator->destroy(enumerator);
}
-/*
- * Different match functions to find SAs in the linked list
- */
-static bool match_entry_by_ptr(ipsec_sa_entry_t *item, ipsec_sa_entry_t *entry)
+CALLBACK(match_entry_by_sa_ptr, bool,
+ ipsec_sa_entry_t *item, va_list args)
{
- return item == entry;
-}
+ ipsec_sa_t *sa;
-static bool match_entry_by_sa_ptr(ipsec_sa_entry_t *item, ipsec_sa_t *sa)
-{
+ VA_ARGS_VGET(args, sa);
return item->sa == sa;
}
-static bool match_entry_by_spi_inbound(ipsec_sa_entry_t *item, uint32_t *spi,
- bool *inbound)
+CALLBACK(match_entry_by_spi_inbound, bool,
+ ipsec_sa_entry_t *item, va_list args)
{
- return item->sa->get_spi(item->sa) == *spi &&
- item->sa->is_inbound(item->sa) == *inbound;
+ uint32_t spi;
+ int inbound;
+
+ VA_ARGS_VGET(args, spi, inbound);
+ return item->sa->get_spi(item->sa) == spi &&
+ item->sa->is_inbound(item->sa) == inbound;
}
-static bool match_entry_by_spi_src_dst(ipsec_sa_entry_t *item, uint32_t *spi,
+static bool match_entry_by_spi_src_dst(ipsec_sa_entry_t *item, uint32_t spi,
host_t *src, host_t *dst)
{
- return item->sa->match_by_spi_src_dst(item->sa, *spi, src, dst);
+ return item->sa->match_by_spi_src_dst(item->sa, spi, src, dst);
}
-static bool match_entry_by_reqid_inbound(ipsec_sa_entry_t *item,
- uint32_t *reqid, bool *inbound)
+CALLBACK(match_entry_by_spi_src_dst_cb, bool,
+ ipsec_sa_entry_t *item, va_list args)
{
- return item->sa->match_by_reqid(item->sa, *reqid, *inbound);
+ host_t *src, *dst;
+ uint32_t spi;
+
+ VA_ARGS_VGET(args, spi, src, dst);
+ return match_entry_by_spi_src_dst(item, spi, src, dst);
+}
+
+CALLBACK(match_entry_by_reqid_inbound, bool,
+ ipsec_sa_entry_t *item, va_list args)
+{
+ uint32_t reqid;
+ int inbound;
+
+ VA_ARGS_VGET(args, reqid, inbound);
+ return item->sa->match_by_reqid(item->sa, reqid, inbound);
}
-static bool match_entry_by_spi_dst(ipsec_sa_entry_t *item, uint32_t *spi,
- host_t *dst)
+CALLBACK(match_entry_by_spi_dst, bool,
+ ipsec_sa_entry_t *item, va_list args)
{
- return item->sa->match_by_spi_dst(item->sa, *spi, dst);
+ host_t *dst;
+ uint32_t spi;
+
+ VA_ARGS_VGET(args, spi, dst);
+ return item->sa->match_by_spi_dst(item->sa, spi, dst);
}
/**
private_ipsec_sa_mgr_t *this = expired->manager;
this->mutex->lock(this->mutex);
- if (this->sas->find_first(this->sas, (void*)match_entry_by_ptr,
- NULL, expired->entry) == SUCCESS)
+ if (this->sas->find_first(this->sas, NULL, (void**)&expired->entry))
{
uint32_t hard_offset;
uint32_t *spi_alloc;
if (this->allocated_spis->get(this->allocated_spis, &spi) ||
- this->sas->find_first(this->sas, (void*)match_entry_by_spi_inbound,
- NULL, &spi, TRUE) == SUCCESS)
+ this->sas->find_first(this->sas, match_entry_by_spi_inbound,
+ NULL, spi, TRUE))
{
return FALSE;
}
free(spi_alloc);
}
- if (this->sas->find_first(this->sas, (void*)match_entry_by_spi_src_dst,
- NULL, &spi, src, dst) == SUCCESS)
+ if (this->sas->find_first(this->sas, match_entry_by_spi_src_dst_cb, NULL,
+ spi, src, dst))
{
this->mutex->unlock(this->mutex);
DBG1(DBG_ESP, "failed to install SAD entry: already installed");
}
this->mutex->lock(this->mutex);
- if (this->sas->find_first(this->sas, (void*)match_entry_by_spi_src_dst,
- (void**)&entry, &spi, src, dst) == SUCCESS &&
+ if (this->sas->find_first(this->sas, match_entry_by_spi_src_dst_cb,
+ (void**)&entry, spi, src, dst) &&
wait_for_entry(this, entry))
{
entry->sa->set_source(entry->sa, new_src);
ipsec_sa_entry_t *entry = NULL;
this->mutex->lock(this->mutex);
- if (this->sas->find_first(this->sas, (void*)match_entry_by_spi_src_dst,
- (void**)&entry, &spi, src, dst) == SUCCESS &&
+ if (this->sas->find_first(this->sas, match_entry_by_spi_src_dst_cb,
+ (void**)&entry, spi, src, dst) &&
wait_for_entry(this, entry))
{
entry->sa->get_usestats(entry->sa, bytes, packets, time);
enumerator = this->sas->create_enumerator(this->sas);
while (enumerator->enumerate(enumerator, (void**)¤t))
{
- if (match_entry_by_spi_src_dst(current, &spi, src, dst))
+ if (match_entry_by_spi_src_dst(current, spi, src, dst))
{
if (wait_remove_entry(this, current))
{
ipsec_sa_t *sa = NULL;
this->mutex->lock(this->mutex);
- if (this->sas->find_first(this->sas, (void*)match_entry_by_reqid_inbound,
- (void**)&entry, &reqid, &inbound) == SUCCESS &&
+ if (this->sas->find_first(this->sas, match_entry_by_reqid_inbound,
+ (void**)&entry, reqid, inbound) &&
wait_for_entry(this, entry))
{
sa = entry->sa;
ipsec_sa_t *sa = NULL;
this->mutex->lock(this->mutex);
- if (this->sas->find_first(this->sas, (void*)match_entry_by_spi_dst,
- (void**)&entry, &spi, dst) == SUCCESS &&
+ if (this->sas->find_first(this->sas, match_entry_by_spi_dst,
+ (void**)&entry, spi, dst) &&
wait_for_entry(this, entry))
{
sa = entry->sa;
ipsec_sa_entry_t *entry;
this->mutex->lock(this->mutex);
- if (this->sas->find_first(this->sas, (void*)match_entry_by_sa_ptr,
- (void**)&entry, sa) == SUCCESS)
+ if (this->sas->find_first(this->sas, match_entry_by_sa_ptr,
+ (void**)&entry, sa))
{
if (entry->locked)
{
element_t *next;
};
+/*
+ * Described in header
+ */
+bool linked_list_match_str(void *item, va_list args)
+{
+ char *a = item, *b;
+
+ VA_ARGS_VGET(args, b);
+ return streq(a, b);
+}
+
/**
* Creates an empty linked list object.
*/
}
}
-METHOD(linked_list_t, find_first, status_t,
- private_linked_list_t *this, linked_list_match_t match,
- void **item, void *d1, void *d2, void *d3, void *d4, void *d5)
+METHOD(linked_list_t, find_first, bool,
+ private_linked_list_t *this, linked_list_match_t match, void **item, ...)
{
element_t *current = this->first;
+ va_list args;
+ bool matched = FALSE;
+
+ if (!match && !item)
+ {
+ return FALSE;
+ }
while (current)
{
- if ((match && match(current->value, d1, d2, d3, d4, d5)) ||
- (!match && item && current->value == *item))
+ if (match)
+ {
+ va_start(args, item);
+ matched = match(current->value, args);
+ va_end(args);
+ }
+ else
+ {
+ matched = current->value == *item;
+ }
+ if (matched)
{
if (item != NULL)
{
*item = current->value;
}
- return SUCCESS;
+ return TRUE;
}
current = current->next;
}
- return NOT_FOUND;
+ return FALSE;
}
METHOD(linked_list_t, invoke_offset, void,
.reset_enumerator = (void*)_reset_enumerator,
.get_first = _get_first,
.get_last = _get_last,
- .find_first = (void*)_find_first,
+ .find_first = _find_first,
.insert_first = _insert_first,
.insert_last = _insert_last,
.insert_before = (void*)_insert_before,
#include <collections/enumerator.h>
/**
- * Method to match elements in a linked list (used in find_* functions)
+ * Function to match elements in a linked list
*
* @param item current list item
- * @param ... user supplied data (only pointers, at most 5)
+ * @param args user supplied data
+ * @return TRUE, if the item matched, FALSE otherwise
+ */
+typedef bool (*linked_list_match_t)(void *item, va_list args);
+
+/**
+ * Helper function to match a string in a linked list of strings
+ *
+ * @param item list item (char*)
+ * @param args user supplied data (char*)
* @return
- * - TRUE, if the item matched
- * - FALSE, otherwise
*/
-typedef bool (*linked_list_match_t)(void *item, ...);
+bool linked_list_match_str(void *item, va_list args);
/**
* Function to be invoked on elements in a linked list
*
* The first object passed to the match function is the current list item,
* followed by the user supplied data.
- * If the supplied function returns TRUE this function returns SUCCESS, and
- * the current object is returned in the third parameter, otherwise,
+ * If the supplied function returns TRUE so does this function, and the
+ * current object is returned in the third parameter (if given), otherwise,
* the next item is checked.
*
* If match is NULL, *item and the current object are compared.
*
- * @warning Only use pointers as user supplied data.
- *
* @param match comparison function to call on each object, or NULL
- * @param item the list item, if found
- * @param ... user data to supply to match function (limited to 5 arguments)
- * @return SUCCESS if found, NOT_FOUND otherwise
+ * @param item the list item, if found, or NULL
+ * @param ... user data to supply to match function
+ * @return TRUE if found, FALSE otherwise (or if neither match,
+ * nor item is supplied)
*/
- status_t (*find_first) (linked_list_t *this, linked_list_match_t match,
- void **item, ...);
+ bool (*find_first)(linked_list_t *this, linked_list_match_t match,
+ void **item, ...);
/**
* Invoke a method on all of the contained objects.
return trusted;
}
-/**
- * List find match function for certificates
- */
-static bool cert_equals(certificate_t *a, certificate_t *b)
+CALLBACK(cert_equals, bool,
+ certificate_t *a, va_list args)
{
+ certificate_t *b;
+
+ VA_ARGS_VGET(args, b);
return a->equals(a, b);
}
continue;
}
- if (this->failed->find_first(this->failed, (void*)cert_equals,
- NULL, current) == SUCCESS)
+ if (this->failed->find_first(this->failed, cert_equals, NULL, current))
{ /* check each candidate only once */
continue;
}
cert_data_destroy);
}
-static bool certificate_equals(certificate_t *item, certificate_t *cert)
+CALLBACK(certificate_equals, bool,
+ certificate_t *item, va_list args)
{
+ certificate_t *cert;
+
+ VA_ARGS_VGET(args, cert);
return item->equals(item, cert);
}
{
certificate_t *cached;
this->lock->write_lock(this->lock);
- if (this->untrusted->find_first(this->untrusted,
- (linked_list_match_t)certificate_equals,
- (void**)&cached, cert) == SUCCESS)
+ if (this->untrusted->find_first(this->untrusted, certificate_equals,
+ (void**)&cached, cert))
{
cert->destroy(cert);
cert = cached->get_ref(cached);
certificate_t *cached;
this->lock->read_lock(this->lock);
- if (this->untrusted->find_first(this->untrusted,
- (linked_list_match_t)certificate_equals,
- (void**)&cached, cert) == SUCCESS)
+ if (this->untrusted->find_first(this->untrusted, certificate_equals,
+ (void**)&cached, cert))
{
cert->destroy(cert);
cert = cached->get_ref(cached);
this->lock->unlock(this->lock);
}
-/**
- * match algorithms of an entry?
- */
-static bool entry_match(entry_t *a, entry_t *b)
+CALLBACK(entry_match, bool,
+ entry_t *a, va_list args)
{
+ entry_t *b;
+
+ VA_ARGS_VGET(args, b);
return a->algo == b->algo;
}
while (orig->enumerate(orig, &entry))
{
- if (list->find_first(list, (void*)entry_match, NULL, entry) == SUCCESS)
+ if (list->find_first(list, entry_match, NULL, entry))
{
continue;
}
provided_feature_t *provided,
int level);
-/**
- * Used to find a loaded feature
- */
-static bool is_feature_loaded(provided_feature_t *item)
+CALLBACK(is_feature_loaded, bool,
+ provided_feature_t *item, va_list args)
{
return item->loaded;
}
-/**
- * Used to find a loadable feature
- */
-static bool is_feature_loadable(provided_feature_t *item)
+CALLBACK(is_feature_loadable, bool,
+ provided_feature_t *item, va_list args)
{
return !item->loading && !item->loaded && !item->failed;
}
{
if (plugin_feature_matches(a->feature, b->feature))
{
- return b->plugins->find_first(b->plugins, (void*)is_feature_loaded,
- NULL) == SUCCESS;
+ return b->plugins->find_first(b->plugins, is_feature_loaded, NULL);
}
return FALSE;
}
{
if (plugin_feature_equals(a->feature, b->feature))
{
- return b->plugins->find_first(b->plugins, (void*)is_feature_loadable,
- NULL) == SUCCESS;
+ return b->plugins->find_first(b->plugins, is_feature_loadable, NULL);
}
return FALSE;
}
{
if (plugin_feature_matches(a->feature, b->feature))
{
- return b->plugins->find_first(b->plugins, (void*)is_feature_loadable,
- NULL) == SUCCESS;
+ return b->plugins->find_first(b->plugins, is_feature_loadable, NULL);
}
return FALSE;
}
{ /* feature interface not supported */
continue;
}
- if (entry->features->find_first(entry->features,
- (void*)is_feature_loaded, NULL) != SUCCESS)
+ if (!entry->features->find_first(entry->features, is_feature_loaded,
+ NULL))
{
DBG2(DBG_LIB, "unloading plugin '%s' without loaded features",
entry->plugin->get_name(entry->plugin));
return FALSE;
}
+CALLBACK(find_plugin_cb, bool,
+ char *path, va_list args)
+{
+ char *name, *buf, **file;
+
+ VA_ARGS_VGET(args, name, buf, file);
+ return find_plugin(path, name, buf, file);
+}
+
/**
* Used to sort plugins by priority
*/
}
if (this->paths)
{
- this->paths->find_first(this->paths, (void*)find_plugin, NULL,
- token, buf, &file);
+ this->paths->find_first(this->paths, find_plugin_cb, NULL, token,
+ buf, &file);
}
if (!file)
{
* find
*/
-static bool match_a_b(void *item, void *a, void *b)
+CALLBACK(find_a_b, bool,
+ void *item, va_list args)
{
+ void *a, *b;
+
+ VA_ARGS_VGET(args, a, b);
ck_assert(a == (void*)1);
ck_assert(b == (void*)2);
return item == a || item == b;
}
+CALLBACK(find_a, bool,
+ void *item, va_list args)
+{
+ void *a;
+
+ VA_ARGS_VGET(args, a);
+ return match_a(item, a);
+}
+
+CALLBACK(find_b, bool,
+ void *item, va_list args)
+{
+ void *b;
+
+ VA_ARGS_VGET(args, b);
+ return match_b(item, b);
+}
+
START_TEST(test_find)
{
void *a = (void*)1, *b = (void*)2;
- ck_assert(list->find_first(list, NULL, &a) == NOT_FOUND);
+ ck_assert(!list->find_first(list, NULL, &a));
list->insert_last(list, a);
- ck_assert(list->find_first(list, NULL, &a) == SUCCESS);
- ck_assert(list->find_first(list, NULL, &b) == NOT_FOUND);
+ ck_assert(list->find_first(list, NULL, &a));
+ ck_assert(!list->find_first(list, NULL, &b));
list->insert_last(list, b);
- ck_assert(list->find_first(list, NULL, &a) == SUCCESS);
- ck_assert(list->find_first(list, NULL, &b) == SUCCESS);
+ ck_assert(list->find_first(list, NULL, &a));
+ ck_assert(list->find_first(list, NULL, &b));
- ck_assert(list->find_first(list, NULL, NULL) == NOT_FOUND);
+ ck_assert(!list->find_first(list, NULL, NULL));
}
END_TEST
{
void *a = (void*)1, *b = (void*)2, *x = NULL;
- ck_assert(list->find_first(list, (linked_list_match_t)match_a_b, &x, a, b) == NOT_FOUND);
+ ck_assert(!list->find_first(list, find_a_b, &x, a, b));
list->insert_last(list, a);
- ck_assert(list->find_first(list, (linked_list_match_t)match_a, NULL, a) == SUCCESS);
+ ck_assert(list->find_first(list, find_a, NULL, a));
x = NULL;
- ck_assert(list->find_first(list, (linked_list_match_t)match_a, &x, a) == SUCCESS);
+ ck_assert(list->find_first(list, find_a, &x, a));
ck_assert(a == x);
- ck_assert(list->find_first(list, (linked_list_match_t)match_b, &x, b) == NOT_FOUND);
+ ck_assert(!list->find_first(list, find_b, &x, b));
ck_assert(a == x);
x = NULL;
- ck_assert(list->find_first(list, (linked_list_match_t)match_a_b, &x, a, b) == SUCCESS);
+ ck_assert(list->find_first(list, find_a_b, &x, a, b));
ck_assert(a == x);
list->insert_last(list, b);
- ck_assert(list->find_first(list, (linked_list_match_t)match_a, &x, a) == SUCCESS);
+ ck_assert(list->find_first(list, find_a, &x, a));
ck_assert(a == x);
- ck_assert(list->find_first(list, (linked_list_match_t)match_b, &x, b) == SUCCESS);
+ ck_assert(list->find_first(list, find_b, &x, b));
ck_assert(b == x);
x = NULL;
- ck_assert(list->find_first(list, (linked_list_match_t)match_a_b, &x, a, b) == SUCCESS);
+ ck_assert(list->find_first(list, find_a_b, &x, a, b));
ck_assert(a == x);
}
END_TEST
+CALLBACK(find_args, bool,
+ void *item, va_list args)
+{
+ uint64_t d, e;
+ level_t c;
+ int *a, b;
+
+ VA_ARGS_VGET(args, a, b, c, d, e);
+ ck_assert_int_eq(*a, 1);
+ ck_assert_int_eq(b, 2);
+ ck_assert_int_eq(c, LEVEL_PRIVATE);
+ ck_assert_int_eq(d, UINT64_MAX);
+ ck_assert_int_eq(e, UINT64_MAX-1);
+ return item == a;
+}
+
+START_TEST(test_find_callback_args)
+{
+ int a = 1, b = 2, *x;
+ uint64_t d = UINT64_MAX;
+
+ list->insert_last(list, &a);
+ ck_assert(list->find_first(list, find_args, (void**)&x, &a, b,
+ LEVEL_PRIVATE, d, UINT64_MAX-1));
+ ck_assert_int_eq(a, *x);
+}
+END_TEST
+
/*******************************************************************************
* invoke
*/
tcase_add_checked_fixture(tc, setup_list, teardown_list);
tcase_add_test(tc, test_find);
tcase_add_test(tc, test_find_callback);
+ tcase_add_test(tc, test_find_callback_args);
suite_add_tcase(s, tc);
tc = tcase_create("invoke");