diff options
author | Corey Farrell <git@cfware.com> | 2017-12-29 23:59:00 -0500 |
---|---|---|
committer | Corey Farrell <git@cfware.com> | 2017-12-30 13:20:16 -0500 |
commit | bc73337e0796d7b85b7b4f86d427b4212b895745 (patch) | |
tree | 017a012d065fed8a132c6c747215aa446e5e0d38 /main/endpoints.c | |
parent | 80e6b2eff54a4ff57e2521164224b1b1c878ae94 (diff) |
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)
* ast_bucket_file (media_cache.c)
* named_acl
Change-Id: Ide4c1449a894bce70dea1fef664dade9b57578f1
Diffstat (limited to 'main/endpoints.c')
-rw-r--r-- | main/endpoints.c | 57 |
1 files changed, 6 insertions, 51 deletions
diff --git a/main/endpoints.c b/main/endpoints.c index d31405244..f1608f3a0 100644 --- a/main/endpoints.c +++ b/main/endpoints.c @@ -76,53 +76,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) { @@ -522,14 +477,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; } |