[asterisk-commits] res sorcery realtime: Remove leading ^ requirement. (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 12 13:59:27 CST 2016


Joshua Colp has submitted this change and it was merged.

Change subject: res_sorcery_realtime: Remove leading ^ requirement.
......................................................................


res_sorcery_realtime: Remove leading ^ requirement.

res_sorcery_realtime's search-by-regex callback performed a check to
ensure that the passed-in regex began with a caret (^). If it did not,
then no results would be returned.

This callback only started to become used when "like" support was added
to PJSIP CLI commands. The CLI command for listing objects would pass an
empty regex ("") to the sorcery backend if no "like" statement was
present. For most sorcery backends, this resulted in returning all
objects. However, for realtime, this resulted in returning no objects.

This commit seeks to fix the regression by removing the requirement from
res_sorcery_realtime for the passed-in-regex to begin with a caret.

ASTERISK-25689 #close
Reported by Marcelo Terres

Change-Id: I22b4dc5d7f3f11bb29ac2e42ef94682e9bab3b20
---
M res/res_sorcery_realtime.c
M tests/test_sorcery_realtime.c
2 files changed, 5 insertions(+), 13 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/res/res_sorcery_realtime.c b/res/res_sorcery_realtime.c
index 8807c01..1a30e0c 100644
--- a/res/res_sorcery_realtime.c
+++ b/res/res_sorcery_realtime.c
@@ -218,16 +218,12 @@
 
 static void sorcery_realtime_retrieve_regex(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *regex)
 {
-	char field[strlen(UUID_FIELD) + 6], value[strlen(regex) + 2];
+	char field[strlen(UUID_FIELD) + 6], value[strlen(regex) + 3];
 	RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
 
 	/* The realtime API provides no direct ability to do regex so for now we support a limited subset using pattern matching */
-	if (regex[0] != '^') {
-		return;
-	}
-
 	snprintf(field, sizeof(field), "%s LIKE", UUID_FIELD);
-	snprintf(value, sizeof(value), "%s%%", regex + 1);
+	snprintf(value, sizeof(value), "%%%s%%", regex);
 
 	if (!(fields = ast_variable_new(field, value, ""))) {
 		return;
diff --git a/tests/test_sorcery_realtime.c b/tests/test_sorcery_realtime.c
index 347280d..76dfb66 100644
--- a/tests/test_sorcery_realtime.c
+++ b/tests/test_sorcery_realtime.c
@@ -67,17 +67,13 @@
 
 		/* If we are doing a pattern matching we need to remove the LIKE from the name */
 		if ((like = strstr(name, " LIKE"))) {
-			char *pattern, *field_value = ast_strdupa(field->value);
+			char *field_value = ast_strdupa(field->value);
 
 			*like = '\0';
 
 			value = ast_strdupa(ast_variable_retrieve(realtime_objects, object_id, name));
 
-			if (!(pattern = strchr(field_value, '%'))) {
-				return 0;
-			}
-
-			*pattern = '\0';
+			field_value = ast_strip_quoted(field_value, "%", "%");
 
 			if (strncmp(value, field_value, strlen(field_value))) {
 				return 0;
@@ -567,7 +563,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (!(objects = ast_sorcery_retrieve_by_regex(sorcery, "test", "^blah-"))) {
+	if (!(objects = ast_sorcery_retrieve_by_regex(sorcery, "test", "blah-"))) {
 		ast_test_status_update(test, "Failed to retrieve a container of objects\n");
 		return AST_TEST_FAIL;
 	} else if (ao2_container_count(objects) != 2) {

-- 
To view, visit https://gerrit.asterisk.org/1992
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I22b4dc5d7f3f11bb29ac2e42ef94682e9bab3b20
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <george.joseph at fairview5.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>



More information about the asterisk-commits mailing list