[asterisk-commits] file: branch file/res_sorcery_astdb r383441 - /team/file/res_sorcery_astdb/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 20 13:20:15 CDT 2013


Author: file
Date: Wed Mar 20 13:20:12 2013
New Revision: 383441

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383441
Log:
Implement retrieve_regex.

Modified:
    team/file/res_sorcery_astdb/res/res_sorcery_astdb.c

Modified: team/file/res_sorcery_astdb/res/res_sorcery_astdb.c
URL: http://svnview.digium.com/svn/asterisk/team/file/res_sorcery_astdb/res/res_sorcery_astdb.c?view=diff&rev=383441&r1=383440&r2=383441
==============================================================================
--- team/file/res_sorcery_astdb/res/res_sorcery_astdb.c (original)
+++ team/file/res_sorcery_astdb/res/res_sorcery_astdb.c Wed Mar 20 13:20:12 2013
@@ -159,6 +159,39 @@
 
 static void sorcery_astdb_retrieve_regex(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *regex)
 {
+	const char *prefix = data;
+	char family[strlen(prefix) + strlen(type) + 2];
+	RAII_VAR(struct ast_db_entry *, entries, NULL, ast_db_freetree);
+	regex_t expression;
+	struct ast_db_entry *entry;
+
+	snprintf(family, sizeof(family), "%s/%s", prefix, type);
+
+	if (!(entries = ast_db_gettree(family, NULL)) || regcomp(&expression, regex, REG_EXTENDED | REG_NOSUB)) {
+		return;
+	}
+
+	for (entry = entries; entry; entry = entry->next) {
+		/* The key in the entry includes the family, so we need to strip it out for regex purposes */
+		const char *key = entry->key + strlen(family) + 2;
+		RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+		struct ast_json_error error;
+		RAII_VAR(void *, object, NULL, ao2_cleanup);
+		RAII_VAR(struct ast_variable *, objset, NULL, ast_variables_destroy);
+
+		if (regexec(&expression, key, 0, NULL, 0)) {
+			continue;
+		} else if (!(json = ast_json_load_string(entry->data, &error)) ||
+			!(objset = sorcery_json_to_objectset(json)) ||
+			!(object = ast_sorcery_alloc(sorcery, type, key)) ||
+			ast_sorcery_objectset_apply(sorcery, object, objset)) {
+			return;
+		}
+
+		ao2_link(objects, object);
+	}
+
+	regfree(&expression);
 }
 
 static int sorcery_astdb_update(const struct ast_sorcery *sorcery, void *data, void *object)




More information about the asterisk-commits mailing list