Merge "res_sorcery_realtime: Remove leading ^ requirement."

This commit is contained in:
Joshua Colp
2016-01-12 13:59:26 -06:00
committed by Gerrit Code Review
2 changed files with 5 additions and 13 deletions

View File

@@ -218,16 +218,12 @@ static void sorcery_realtime_retrieve_multiple(const struct ast_sorcery *sorcery
static void sorcery_realtime_retrieve_regex(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *regex) 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); 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 */ /* 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(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, ""))) { if (!(fields = ast_variable_new(field, value, ""))) {
return; return;

View File

@@ -67,17 +67,13 @@ static int realtime_is_object_matching(const char *object_id, const struct ast_v
/* If we are doing a pattern matching we need to remove the LIKE from the name */ /* If we are doing a pattern matching we need to remove the LIKE from the name */
if ((like = strstr(name, " LIKE"))) { if ((like = strstr(name, " LIKE"))) {
char *pattern, *field_value = ast_strdupa(field->value); char *field_value = ast_strdupa(field->value);
*like = '\0'; *like = '\0';
value = ast_strdupa(ast_variable_retrieve(realtime_objects, object_id, name)); value = ast_strdupa(ast_variable_retrieve(realtime_objects, object_id, name));
if (!(pattern = strchr(field_value, '%'))) { field_value = ast_strip_quoted(field_value, "%", "%");
return 0;
}
*pattern = '\0';
if (strncmp(value, field_value, strlen(field_value))) { if (strncmp(value, field_value, strlen(field_value))) {
return 0; return 0;
@@ -567,7 +563,7 @@ AST_TEST_DEFINE(object_retrieve_regex)
return AST_TEST_FAIL; 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"); ast_test_status_update(test, "Failed to retrieve a container of objects\n");
return AST_TEST_FAIL; return AST_TEST_FAIL;
} else if (ao2_container_count(objects) != 2) { } else if (ao2_container_count(objects) != 2) {