core: Use macros to generate ao2_container callbacks where possible.

This uses AO2_STRING_FIELD_HASH_FN and AO2_STRING_FIELD_CMP_FN where
possible in the Asterisk core.

This removes CMP_STOP from the result of CMP_FN callbacks for the
following structure types:
* ast_bucket_metadata
* ast_bucket_scheme
* generic_monitor_instance_list (ccss.c)
* named_acl

Change-Id: Ide4c1449a894bce70dea1fef664dade9b57578f1
This commit is contained in:
Corey Farrell
2017-12-29 23:59:00 -05:00
parent b47882df72
commit 5b395a7b97
9 changed files with 52 additions and 605 deletions

View File

@@ -78,53 +78,8 @@ struct ast_endpoint {
struct stasis_forward *tech_forward;
};
static int endpoint_hash(const void *obj, int flags)
{
const struct ast_endpoint *endpoint;
const char *key;
switch (flags & OBJ_SEARCH_MASK) {
case OBJ_SEARCH_KEY:
key = obj;
return ast_str_hash(key);
case OBJ_SEARCH_OBJECT:
endpoint = obj;
return ast_str_hash(endpoint->id);
default:
/* Hash can only work on something with a full key. */
ast_assert(0);
return 0;
}
}
static int endpoint_cmp(void *obj, void *arg, int flags)
{
const struct ast_endpoint *left = obj;
const struct ast_endpoint *right = arg;
const char *right_key = arg;
int cmp;
switch (flags & OBJ_SEARCH_MASK) {
case OBJ_SEARCH_OBJECT:
right_key = right->id;
/* Fall through */
case OBJ_SEARCH_KEY:
cmp = strcmp(left->id, right_key);
break;
case OBJ_SEARCH_PARTIAL_KEY:
cmp = strncmp(left->id, right_key, strlen(right_key));
break;
default:
ast_assert(0);
cmp = 0;
break;
}
if (cmp) {
return 0;
}
return CMP_MATCH;
}
AO2_STRING_FIELD_HASH_FN(ast_endpoint, id)
AO2_STRING_FIELD_CMP_FN(ast_endpoint, id)
struct ast_endpoint *ast_endpoint_find_by_id(const char *id)
{
@@ -524,14 +479,14 @@ int ast_endpoint_init(void)
{
ast_register_cleanup(endpoint_cleanup);
endpoints = ao2_container_alloc(ENDPOINT_BUCKETS, endpoint_hash,
endpoint_cmp);
endpoints = ao2_container_alloc(ENDPOINT_BUCKETS, ast_endpoint_hash_fn,
ast_endpoint_cmp_fn);
if (!endpoints) {
return -1;
}
tech_endpoints = ao2_container_alloc(TECH_ENDPOINT_BUCKETS, endpoint_hash,
endpoint_cmp);
tech_endpoints = ao2_container_alloc(TECH_ENDPOINT_BUCKETS, ast_endpoint_hash_fn,
ast_endpoint_cmp_fn);
if (!tech_endpoints) {
return -1;
}