manager/config: Support templates and non-unique category names via AMI

This patch provides the capability to manipulate templates and categories
with non-unique names via AMI.

Summary of changes:

GetConfig and GetConfigJSON: Added "Filter" parameter:  A comma separated list
of name_regex=value_regex expressions which will cause only categories whose
variables match all expressions to be considered.  The special variable name
TEMPLATES can be used to control whether templates are included.  Passing
'include' as the value will include templates along with normal categories.
Passing 'restrict' as the value will restrict the operation to ONLY templates.
Not specifying a TEMPLATES expression results in the current default behavior
which is to not include templates.

UpdateConfig: NewCat now includes options for allowing duplicate category
names, indicating if the category should be created as a template, and
specifying templates the category should inherit from.  The rest of the
actions now accept a filter string as defined above.  If there are non-unique
category names, you can now update specific ones based on variable values.

To facilitate the new capabilities in manager, corresponding changes had to be
made to config, most notably the addition of filter criteria to many of the
APIs.  In some cases it was easy to change the references to use the new
prototype but others would have required touching too many files for this
patch so a wrapper with the original prototype was created.  Macros couldn't
be used in this case because it would break binary compatibility with modules
such as res_digium_phone that are linked to real symbols.

Tested-by: George Joseph

Review: https://reviewboard.asterisk.org/r/4033/
........

Merged revisions 425383 from http://svn.asterisk.org/svn/asterisk/branches/12
........

Merged revisions 425384 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@425385 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
George Joseph
2014-10-13 16:12:17 +00:00
parent 8d6f1d763c
commit c7e6b6ba3d
11 changed files with 1267 additions and 220 deletions

View File

@@ -139,15 +139,15 @@ static struct ast_config *realtime_sorcery_multi(const char *database, const cha
static int realtime_sorcery_update(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields)
{
struct ast_category *object;
struct ast_category *object, *found;
if (!ast_category_exist(realtime_objects, entity)) {
if (!(found = ast_category_get(realtime_objects, entity, NULL))) {
return 0;
} else if (!(object = ast_category_new(entity, "", 0))) {
return -1;
}
ast_category_delete(realtime_objects, entity);
ast_category_delete(realtime_objects, found);
ast_variable_append(object, ast_variables_dup((struct ast_variable*)fields));
ast_variable_append(object, ast_variable_new(keyfield, entity, ""));
ast_category_append(realtime_objects, object);
@@ -161,7 +161,7 @@ static int realtime_sorcery_store(const char *database, const char *table, const
const struct ast_variable *keyfield = realtime_find_variable(fields, "id");
struct ast_category *object;
if (!keyfield || ast_category_exist(realtime_objects, keyfield->value) || !(object = ast_category_new(keyfield->value, "", 0))) {
if (!keyfield || ast_category_exist(realtime_objects, keyfield->value, NULL) || !(object = ast_category_new(keyfield->value, "", 0))) {
return -1;
}
@@ -173,11 +173,12 @@ static int realtime_sorcery_store(const char *database, const char *table, const
static int realtime_sorcery_destroy(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields)
{
if (!ast_category_exist(realtime_objects, entity)) {
struct ast_category *found;
if (!(found = ast_category_get(realtime_objects, entity, NULL))) {
return 0;
}
ast_category_delete(realtime_objects, entity);
ast_category_delete(realtime_objects, found);
return 1;
}
@@ -570,7 +571,7 @@ AST_TEST_DEFINE(object_retrieve_regex)
ast_test_status_update(test, "Failed to retrieve a container of objects\n");
return AST_TEST_FAIL;
} else if (ao2_container_count(objects) != 2) {
ast_test_status_update(test, "Received a container with incorrect number of objects in it\n");
ast_test_status_update(test, "Received a container with incorrect number of objects in it: %d instead of 2\n", ao2_container_count(objects));
return AST_TEST_FAIL;
}