[asterisk-commits] rmudgett: branch 12 r403545 - /branches/12/res/res_sorcery_astdb.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 9 12:49:30 CST 2013


Author: rmudgett
Date: Mon Dec  9 12:49:28 2013
New Revision: 403545

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403545
Log:
res_sorcery_astdb.c: Fix get multiple records by regex.

* Fix sorcery_astdb_retrieve_regex() pattern matching.  Let the regexec()
function match the stored key values instead of having astdb prefilter
them.  Previoiusly you could only use a simple regex pattern when the
pattern began with '^'.

* Fix off nominal memory leak in sorcery_astdb_retrieve_regex().

Modified:
    branches/12/res/res_sorcery_astdb.c

Modified: branches/12/res/res_sorcery_astdb.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_sorcery_astdb.c?view=diff&rev=403545&r1=403544&r2=403545
==============================================================================
--- branches/12/res/res_sorcery_astdb.c (original)
+++ branches/12/res/res_sorcery_astdb.c Mon Dec  9 12:49:28 2013
@@ -218,20 +218,14 @@
 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], tree[strlen(regex) + 1];
+	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 (regex[0] == '^') {
-		snprintf(tree, sizeof(tree), "%s%%", regex + 1);
-	} else {
-		tree[0] = '\0';
-	}
-
-	if (!(entries = ast_db_gettree(family, tree)) || regcomp(&expression, regex, REG_EXTENDED | REG_NOSUB)) {
+	if (!(entries = ast_db_gettree(family, NULL)) || regcomp(&expression, regex, REG_EXTENDED | REG_NOSUB)) {
 		return;
 	}
 
@@ -249,6 +243,7 @@
 			!(objset = sorcery_json_to_objectset(json)) ||
 			!(object = ast_sorcery_alloc(sorcery, type, key)) ||
 			ast_sorcery_objectset_apply(sorcery, object, objset)) {
+			regfree(&expression);
 			return;
 		}
 




More information about the asterisk-commits mailing list