diff options
Diffstat (limited to 'main/cel.c')
-rw-r--r-- | main/cel.c | 213 |
1 files changed, 28 insertions, 185 deletions
diff --git a/main/cel.c b/main/cel.c index 0cdf1be00..31cd04542 100644 --- a/main/cel.c +++ b/main/cel.c @@ -244,15 +244,28 @@ static struct aco_type general_option = { .type = ACO_GLOBAL, .name = "general", .item_offset = offsetof(struct cel_config, general), - .category_match = ACO_WHITELIST, - .category = "^general$", + .category_match = ACO_WHITELIST_EXACT, + .category = "general", +}; + +/*! Config sections used by existing modules. Do not add to this list. */ +static const char *ignore_categories[] = { + "manager", + "radius", + NULL, +}; + +static struct aco_type ignore_option = { + .type = ACO_IGNORE, + .name = "modules", + .category = (const char*)ignore_categories, + .category_match = ACO_WHITELIST_ARRAY, }; /*! \brief The config file to be processed for the module. */ static struct aco_file cel_conf = { .filename = "cel.conf", /*!< The name of the config file */ - .types = ACO_TYPES(&general_option), /*!< The mapping object types to be processed */ - .skip_category = "(^manager$|^radius$)", /*!< Config sections used by existing modules. Do not add to this list. */ + .types = ACO_TYPES(&general_option, &ignore_option), /*!< The mapping object types to be processed */ }; static int cel_pre_apply_config(void); @@ -318,129 +331,16 @@ struct cel_backend { }; /*! \brief Hashing function for cel_backend */ -static int cel_backend_hash(const void *obj, int flags) -{ - const struct cel_backend *backend; - const char *name; - - switch (flags & OBJ_SEARCH_MASK) { - case OBJ_SEARCH_OBJECT: - backend = obj; - name = backend->name; - break; - case OBJ_SEARCH_KEY: - name = obj; - break; - default: - /* Hash can only work on something with a full key. */ - ast_assert(0); - return 0; - } - - return ast_str_hash(name); -} +AO2_STRING_FIELD_HASH_FN(cel_backend, name) /*! \brief Comparator function for cel_backend */ -static int cel_backend_cmp(void *obj, void *arg, int flags) -{ - const struct cel_backend *object_left = obj; - const struct cel_backend *object_right = arg; - const char *right_key = arg; - int cmp; - - switch (flags & OBJ_SEARCH_MASK) { - case OBJ_SEARCH_OBJECT: - right_key = object_right->name; - /* Fall through */ - case OBJ_SEARCH_KEY: - cmp = strcmp(object_left->name, right_key); - break; - case OBJ_SEARCH_PARTIAL_KEY: - /* - * We could also use a partial key struct containing a length - * so strlen() does not get called for every comparison instead. - */ - cmp = strncmp(object_left->name, right_key, strlen(right_key)); - break; - default: - /* - * What arg points to is specific to this traversal callback - * and has no special meaning to astobj2. - */ - cmp = 0; - break; - } - if (cmp) { - return 0; - } - /* - * At this point the traversal callback is identical to a sorted - * container. - */ - return CMP_MATCH; -} +AO2_STRING_FIELD_CMP_FN(cel_backend, name) /*! \brief Hashing function for dialstatus container */ -static int dialstatus_hash(const void *obj, int flags) -{ - const struct cel_dialstatus *dialstatus; - const char *key; - - switch (flags & OBJ_SEARCH_MASK) { - case OBJ_SEARCH_KEY: - key = obj; - break; - case OBJ_SEARCH_OBJECT: - dialstatus = obj; - key = dialstatus->uniqueid; - break; - default: - /* Hash can only work on something with a full key. */ - ast_assert(0); - return 0; - } - return ast_str_hash(key); -} +AO2_STRING_FIELD_HASH_FN(cel_dialstatus, uniqueid) /*! \brief Comparator function for dialstatus container */ -static int dialstatus_cmp(void *obj, void *arg, int flags) -{ - struct cel_dialstatus *object_left = obj; - struct cel_dialstatus *object_right = arg; - const char *right_key = arg; - int cmp; - - switch (flags & OBJ_SEARCH_MASK) { - case OBJ_SEARCH_OBJECT: - right_key = object_right->uniqueid; - /* Fall through */ - case OBJ_SEARCH_KEY: - cmp = strcmp(object_left->uniqueid, right_key); - break; - case OBJ_SEARCH_PARTIAL_KEY: - /* - * We could also use a partial key struct containing a length - * so strlen() does not get called for every comparison instead. - */ - cmp = strncmp(object_left->uniqueid, right_key, strlen(right_key)); - break; - default: - /* - * What arg points to is specific to this traversal callback - * and has no special meaning to astobj2. - */ - cmp = 0; - break; - } - if (cmp) { - return 0; - } - /* - * At this point the traversal callback is identical to a sorted - * container. - */ - return CMP_MATCH; -} +AO2_STRING_FIELD_CMP_FN(cel_dialstatus, uniqueid) unsigned int ast_cel_check_enabled(void) { @@ -1654,71 +1554,14 @@ static int create_routes(void) return ret; } -static int lid_hash(const void *obj, const int flags) -{ - const struct cel_linkedid *lid; - const char *key; - - switch (flags & OBJ_SEARCH_MASK) { - case OBJ_SEARCH_KEY: - key = obj; - break; - case OBJ_SEARCH_OBJECT: - lid = obj; - key = lid->id; - break; - default: - /* Hash can only work on something with a full key. */ - ast_assert(0); - return 0; - } - return ast_str_hash(key); -} - -static int lid_cmp(void *obj, void *arg, int flags) -{ - const struct cel_linkedid *object_left = obj; - const struct cel_linkedid *object_right = arg; - const char *right_key = arg; - int cmp; - - switch (flags & OBJ_SEARCH_MASK) { - case OBJ_SEARCH_OBJECT: - right_key = object_right->id; - /* Fall through */ - case OBJ_SEARCH_KEY: - cmp = strcmp(object_left->id, right_key); - break; - case OBJ_SEARCH_PARTIAL_KEY: - /* - * We could also use a partial key struct containing a length - * so strlen() does not get called for every comparison instead. - */ - cmp = strncmp(object_left->id, right_key, strlen(right_key)); - break; - default: - /* - * What arg points to is specific to this traversal callback - * and has no special meaning to astobj2. - */ - cmp = 0; - break; - } - if (cmp) { - return 0; - } - /* - * At this point the traversal callback is identical to a sorted - * container. - */ - return CMP_MATCH; -} +AO2_STRING_FIELD_HASH_FN(cel_linkedid, id) +AO2_STRING_FIELD_CMP_FN(cel_linkedid, id) int ast_cel_engine_init(void) { struct ao2_container *container; - container = ao2_container_alloc(NUM_APP_BUCKETS, lid_hash, lid_cmp); + container = ao2_container_alloc(NUM_APP_BUCKETS, cel_linkedid_hash_fn, cel_linkedid_cmp_fn); ao2_global_obj_replace_unref(cel_linkedids, container); ao2_cleanup(container); if (!container) { @@ -1727,7 +1570,7 @@ int ast_cel_engine_init(void) } container = ao2_container_alloc(NUM_DIALSTATUS_BUCKETS, - dialstatus_hash, dialstatus_cmp); + cel_dialstatus_hash_fn, cel_dialstatus_cmp_fn); ao2_global_obj_replace_unref(cel_dialstatus_store, container); ao2_cleanup(container); if (!container) { @@ -1745,7 +1588,7 @@ int ast_cel_engine_init(void) return -1; } - container = ao2_container_alloc(BACKEND_BUCKETS, cel_backend_hash, cel_backend_cmp); + container = ao2_container_alloc(BACKEND_BUCKETS, cel_backend_hash_fn, cel_backend_cmp_fn); ao2_global_obj_replace_unref(cel_backends, container); ao2_cleanup(container); if (!container) { @@ -1824,9 +1667,9 @@ void ast_cel_publish_event(struct ast_channel *chan, struct ast_json *cel_blob; struct stasis_message *message; - cel_blob = ast_json_pack("{s: i, s: O}", + cel_blob = ast_json_pack("{s: i, s: o}", "event_type", event_type, - "event_details", blob); + "event_details", ast_json_ref(blob)); message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan), cel_generic_type(), cel_blob); if (message) { |