summaryrefslogtreecommitdiff
path: root/res/res_sorcery_config.c
diff options
context:
space:
mode:
authorSean Bright <sean.bright@gmail.com>2017-11-09 09:21:38 -0500
committerSean Bright <sean.bright@gmail.com>2017-11-13 16:52:22 -0500
commit2e01b779cc18c1f0f66c28db775e1e6b1d5065e4 (patch)
treea95ad356e5f4f1efdae07f65225ae5ca47857c4c /res/res_sorcery_config.c
parentbcd3782051fa069252ba8a9cd9c6cc13d827e0bf (diff)
sorcery: Add ast_sorcery_retrieve_by_prefix()
Some consumers of the sorcery API use ast_sorcery_retrieve_by_regex only so that they can anchor the potential match as a prefix and not because they truly need regular expressions. Rather than using regular expressions for simple prefix lookups, add a new operation - ast_sorcery_retrieve_by_prefix - that does them. Patches against 13 and 15 have a compatibility layer needed to maintain ABI that is not needed in master. Change-Id: I56f4e20ba1154bd52281f995c27a429a854f6a79
Diffstat (limited to 'res/res_sorcery_config.c')
-rw-r--r--res/res_sorcery_config.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/res/res_sorcery_config.c b/res/res_sorcery_config.c
index 0de34c640..20178883b 100644
--- a/res/res_sorcery_config.c
+++ b/res/res_sorcery_config.c
@@ -71,6 +71,12 @@ struct sorcery_config_fields_cmp_params {
/*! \brief Regular expression for checking object id */
regex_t *regex;
+ /*! \brief Prefix for matching object id */
+ const char *prefix;
+
+ /*! \brief Prefix length in bytes for matching object id */
+ const size_t prefix_len;
+
/*! \brief Optional container to put object into */
struct ao2_container *container;
};
@@ -83,6 +89,7 @@ static void *sorcery_config_retrieve_fields(const struct ast_sorcery *sorcery, v
static void sorcery_config_retrieve_multiple(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects,
const struct ast_variable *fields);
static void sorcery_config_retrieve_regex(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *regex);
+static void sorcery_config_retrieve_prefix(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *prefix, const size_t prefix_len);
static void sorcery_config_close(void *data);
static struct ast_sorcery_wizard config_object_wizard = {
@@ -94,6 +101,7 @@ static struct ast_sorcery_wizard config_object_wizard = {
.retrieve_fields = sorcery_config_retrieve_fields,
.retrieve_multiple = sorcery_config_retrieve_multiple,
.retrieve_regex = sorcery_config_retrieve_regex,
+ .retrieve_prefix = sorcery_config_retrieve_prefix,
.close = sorcery_config_close,
};
@@ -118,6 +126,11 @@ static int sorcery_config_fields_cmp(void *obj, void *arg, int flags)
ao2_link(params->container, obj);
}
return 0;
+ } else if (params->prefix) {
+ if (!strncmp(params->prefix, ast_sorcery_object_get_id(obj), params->prefix_len)) {
+ ao2_link(params->container, obj);
+ }
+ return 0;
} else if (params->fields &&
(!(objset = ast_sorcery_objectset_create(params->sorcery, obj)) ||
(!ast_variable_lists_match(objset, params->fields, 0)))) {
@@ -206,6 +219,24 @@ static void sorcery_config_retrieve_regex(const struct ast_sorcery *sorcery, voi
regfree(&expression);
}
+static void sorcery_config_retrieve_prefix(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *prefix, const size_t prefix_len)
+{
+ struct sorcery_config *config = data;
+ RAII_VAR(struct ao2_container *, config_objects, ao2_global_obj_ref(config->objects), ao2_cleanup);
+ struct sorcery_config_fields_cmp_params params = {
+ .sorcery = sorcery,
+ .container = objects,
+ .prefix = prefix,
+ .prefix_len = prefix_len,
+ };
+
+ if (!config_objects) {
+ return;
+ }
+
+ ao2_callback(config_objects, OBJ_NODATA | OBJ_MULTIPLE, sorcery_config_fields_cmp, &params);
+}
+
/*! \brief Internal function which determines if criteria has been met for considering an object set applicable */
static int sorcery_is_criteria_met(struct ast_variable *objset, struct ast_variable *criteria)
{