summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2013-02-16 16:24:21 +0000
committerJoshua Colp <jcolp@digium.com>2013-02-16 16:24:21 +0000
commitcce1c9547facb5cf28dc4e74f9d2369e83f3a212 (patch)
treeffb07b4eb1b7d7ec2ce5b294fdca3810c8413436 /main
parentc209e85ad31ac3983a0eb7684055cdd808cbd8fe (diff)
Add support for retrieving multiple objects from sorcery using a regex on their id.
Review: https://reviewboard.asterisk.org/r/2329/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@381614 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r--main/sorcery.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/main/sorcery.c b/main/sorcery.c
index 6a0fb4acc..242d65bdc 100644
--- a/main/sorcery.c
+++ b/main/sorcery.c
@@ -959,6 +959,30 @@ void *ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const ch
return object;
}
+struct ao2_container *ast_sorcery_retrieve_by_regex(const struct ast_sorcery *sorcery, const char *type, const char *regex)
+{
+ RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup);
+ struct ao2_container *objects;
+ struct ao2_iterator i;
+ struct ast_sorcery_object_wizard *wizard;
+
+ if (!object_type || !(objects = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 1, NULL, NULL))) {
+ return NULL;
+ }
+
+ i = ao2_iterator_init(object_type->wizards, 0);
+ for (; (wizard = ao2_iterator_next(&i)); ao2_ref(wizard, -1)) {
+ if (!wizard->wizard->retrieve_regex) {
+ continue;
+ }
+
+ wizard->wizard->retrieve_regex(sorcery, wizard->data, object_type->name, objects, regex);
+ }
+ ao2_iterator_destroy(&i);
+
+ return objects;
+}
+
/*! \brief Internal function which returns if the wizard has created the object */
static int sorcery_wizard_create(void *obj, void *arg, int flags)
{