diff options
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 80e7f87fd..88506a4c8 100644 --- a/main/endpoints.c +++ b/main/endpoints.c @@ -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; } |