[asterisk-commits] mjordan: branch mjordan/trunk-astdb-cluster r434016 - in /team/mjordan/trunk-...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Apr 5 21:14:33 CDT 2015


Author: mjordan
Date: Sun Apr  5 21:14:30 2015
New Revision: 434016

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=434016
Log:
Fix Mark's findings

Modified:
    team/mjordan/trunk-astdb-cluster/funcs/func_db.c
    team/mjordan/trunk-astdb-cluster/main/db.c
    team/mjordan/trunk-astdb-cluster/tests/test_db.c

Modified: team/mjordan/trunk-astdb-cluster/funcs/func_db.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-astdb-cluster/funcs/func_db.c?view=diff&rev=434016&r1=434015&r2=434016
==============================================================================
--- team/mjordan/trunk-astdb-cluster/funcs/func_db.c (original)
+++ team/mjordan/trunk-astdb-cluster/funcs/func_db.c Sun Apr  5 21:14:30 2015
@@ -450,27 +450,16 @@
 };
 
 static int function_db_shared_exists_read(struct ast_channel *chan,
-	const char *cmd, char *parse, char *buf, size_t len)
-{
-	AST_DECLARE_APP_ARGS(args,
-		AST_APP_ARG(family);
-	);
-
+	const char *cmd, char *args, char *buf, size_t len)
+{
 	buf[0] = '\0';
 
-	if (ast_strlen_zero(parse)) {
+	if (ast_strlen_zero(args)) {
 		ast_log(LOG_WARNING, "DB_SHARED_EXISTS requires an argument, DB_SHARED_EXISTS(<family>)\n");
 		return -1;
 	}
 
-	AST_STANDARD_APP_ARGS(args, parse);
-
-	if (args.argc != 1) {
-		ast_log(LOG_WARNING, "DB_SHARED_EXISTS requires an argument, DB_SHARED_EXISTS(<family>)\n");
-		return -1;
-	}
-
-	if (ast_db_is_shared(args.family)) {
+	if (ast_db_is_shared(args)) {
 		ast_copy_string(buf, "1", len);
 	} else {
 		ast_copy_string(buf, "0", len);
@@ -494,6 +483,11 @@
 		AST_APP_ARG(type);
 	);
 
+	if (ast_strlen_zero(value)) {
+		ast_log(LOG_WARNING, "DB_SHARED requires a value, DB_SHARED(<action>[,<type>])=<family>\n");
+		return -1;
+	}
+
 	if (ast_strlen_zero(parse)) {
 		ast_log(LOG_WARNING, "DB_SHARED requires an argument, DB_SHARED(<action>[,<type>])=<family>\n");
 		return -1;
@@ -501,18 +495,14 @@
 
 	AST_STANDARD_APP_ARGS(args, parse);
 
-	if (args.argc < 1) {
-		ast_log(LOG_WARNING, "DB_SHARED requires an argument, DB_SHARED(<action>[,<type>])=<family>\n");
-		return -1;
-	}
-
-	if (ast_strlen_zero(value)) {
-		ast_log(LOG_WARNING, "DB_SHARED requires a value, DB_SHARED(<action>[,<type>])=<family>\n");
-		return -1;
-	}
-
 	if (!strcasecmp(args.action, "put")) {
-		if (ast_strlen_zero(args.type) || !strcasecmp(args.type, "global")) {
+
+		if (ast_strlen_zero(args.type)) {
+			ast_log(LOG_WARNING, "DB_SHARED: No 'type' provided.\n");
+			return -1;
+		}
+
+		if (!strcasecmp(args.type, "global")) {
 			share_type = DB_SHARE_TYPE_GLOBAL;
 		} else if (!strcasecmp(args.type, "unique")) {
 			share_type = DB_SHARE_TYPE_UNIQUE;

Modified: team/mjordan/trunk-astdb-cluster/main/db.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-astdb-cluster/main/db.c?view=diff&rev=434016&r1=434015&r2=434016
==============================================================================
--- team/mjordan/trunk-astdb-cluster/main/db.c (original)
+++ team/mjordan/trunk-astdb-cluster/main/db.c Sun Apr  5 21:14:30 2015
@@ -258,11 +258,7 @@
  */
 static struct ast_db_shared_family *db_shared_family_clone(const struct ast_db_shared_family *shared_family)
 {
-	struct ast_db_shared_family *clone;
-
-	clone = ast_db_shared_family_alloc(shared_family->name, shared_family->share_type);
-
-	return clone;
+	return ast_db_shared_family_alloc(shared_family->name, shared_family->share_type);
 }
 
 /*! \internal
@@ -427,13 +423,12 @@
 	}
 
 	ao2_link_flags(shared_families, shared_family, OBJ_NOLOCK);
+	ao2_unlock(shared_families);
 
 	db_put_common(SHARED_FAMILY, shared_family->name,
 		share_type == DB_SHARE_TYPE_UNIQUE ? "UNIQUE" : "GLOBAL", 0);
 
 	ao2_ref(shared_family, -1);
-
-	ao2_unlock(shared_families);
 
 	return 0;
 }
@@ -559,13 +554,14 @@
 	shared_family = ao2_find(shared_families, family, OBJ_SEARCH_KEY | OBJ_NOLOCK);
 	if (shared_family) {
 		ao2_unlink_flags(shared_families, shared_family, OBJ_NOLOCK);
+		ao2_unlock(shared_families);
+
 		db_del_common(SHARED_FAMILY, shared_family->name, 0);
 		ao2_ref(shared_family, -1);
 	} else {
+		ao2_unlock(shared_families);
 		res = -1;
 	}
-
-	ao2_unlock(shared_families);
 
 	return res;
 }
@@ -1429,7 +1425,6 @@
 			ao2_ref(shared_family, -1);
 			continue;
 		}
-
 		ast_db_publish_shared_message(ast_db_put_shared_type(), clone, NULL);
 
 		ao2_ref(clone, -1);
@@ -1641,10 +1636,11 @@
 		const char *family;
 
 		/* Find the 'key', which is the name of the shared family */
-		family = strchr(cur->key + 1, '/') + 1;
+		family = strchr(cur->key + 1, '/');
 		if (!family) {
 			continue;
 		}
+		family++;
 
 		if (!strcasecmp(cur->data, "unique")) {
 			share_type = DB_SHARE_TYPE_UNIQUE;

Modified: team/mjordan/trunk-astdb-cluster/tests/test_db.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-astdb-cluster/tests/test_db.c?view=diff&rev=434016&r1=434015&r2=434016
==============================================================================
--- team/mjordan/trunk-astdb-cluster/tests/test_db.c (original)
+++ team/mjordan/trunk-astdb-cluster/tests/test_db.c Sun Apr  5 21:14:30 2015
@@ -137,7 +137,7 @@
 		if (r == ETIMEDOUT) {
 			break;
 		}
-		ast_assert(r == 0); /* Not expecting any othet types of errors */
+		ast_assert(r == 0); /* Not expecting any other types of errors */
 	}
 	return consumer->messages_rxed_len;
 }
@@ -390,7 +390,7 @@
  * As annoying as it is, it's actually really hard to synchronize on when the
  * AstDB updates itself from the received publication of a shared family value.
  * This is because while we can synchronize on the delivery to a topic, we can't
- * synchronize that the AstDB handler's for that topic has written the value out.
+ * synchronize that the AstDB handlers for that topic have written the value out.
  * Hence, we use this loop - if we don't get a value written within 1000 usec,
  * something is definitely wrong and we should just fail the unit test.
  */
@@ -410,6 +410,8 @@
 
 AST_TEST_DEFINE(test_ast_db_put_shared_create)
 {
+	RAII_VAR(const char *, global_family, GLOBAL_SHARED_FAMILY, ast_db_del_shared);
+	RAII_VAR(const char *, unique_family, UNIQUE_SHARED_FAMILY, ast_db_del_shared);
 	int res;
 
 	switch (cmd) {
@@ -442,14 +444,13 @@
 	res = ast_db_put_shared(UNIQUE_SHARED_FAMILY, DB_SHARE_TYPE_GLOBAL);
 	ast_test_validate(test, res != 0, "Creating duplicate global of unique shared area");
 
-	ast_db_del_shared(GLOBAL_SHARED_FAMILY);
-	ast_db_del_shared(UNIQUE_SHARED_FAMILY);
-
 	return AST_TEST_PASS;
 }
 
 AST_TEST_DEFINE(test_ast_db_put_shared_delete)
 {
+	RAII_VAR(const char *, global_family, GLOBAL_SHARED_FAMILY, ast_db_del_shared);
+	RAII_VAR(const char *, unique_family, UNIQUE_SHARED_FAMILY, ast_db_del_shared);
 	int res;
 
 	switch (cmd) {
@@ -485,8 +486,15 @@
 	return AST_TEST_PASS;
 }
 
+static void tree_cleanup(const char *name)
+{
+	ast_db_deltree(name, "");
+}
+
 AST_TEST_DEFINE(test_ast_db_put_shared_unique)
 {
+	RAII_VAR(const char *, unique_family, UNIQUE_SHARED_FAMILY, ast_db_del_shared);
+	RAII_VAR(const char *, tree_family, UNIQUE_SHARED_FAMILY, tree_cleanup);
 	RAII_VAR(struct consumer *, consumer, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_subscription *, uut, NULL, stasis_unsubscribe);
 	int res;
@@ -534,14 +542,13 @@
 	ast_test_validate(test, stasis_message_type(consumer->messages_rxed[0]) == ast_db_put_shared_type());
 	ast_test_validate(test, stasis_message_type(consumer->messages_rxed[1]) == ast_db_put_shared_type());
 
-	ast_db_del_shared(UNIQUE_SHARED_FAMILY);
-	ast_db_deltree(UNIQUE_SHARED_FAMILY, "");
-
 	return AST_TEST_PASS;
 }
 
 AST_TEST_DEFINE(test_ast_db_put_shared_global)
 {
+	RAII_VAR(const char *, global_family, GLOBAL_SHARED_FAMILY, ast_db_del_shared);
+	RAII_VAR(const char *, tree_family, GLOBAL_SHARED_FAMILY, tree_cleanup);
 	RAII_VAR(struct consumer *, consumer, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_subscription *, uut, NULL, stasis_unsubscribe);
 	int res;
@@ -589,17 +596,17 @@
 	ast_test_validate(test, stasis_message_type(consumer->messages_rxed[0]) == ast_db_put_shared_type());
 	ast_test_validate(test, stasis_message_type(consumer->messages_rxed[1]) == ast_db_put_shared_type());
 
-	ast_db_deltree(GLOBAL_SHARED_FAMILY, "");
-	ast_db_del_shared(GLOBAL_SHARED_FAMILY);
-
 	return AST_TEST_PASS;
 }
 
 AST_TEST_DEFINE(test_ast_db_put_shared_unique_update)
 {
+	RAII_VAR(const char *, unique_family, UNIQUE_SHARED_FAMILY, ast_db_del_shared);
+	RAII_VAR(const char *, tree_family, "astdbtest_unique", tree_cleanup);
+	RAII_VAR(const char *, eid_tree_family, TEST_EID, tree_cleanup);
 	RAII_VAR(struct ast_db_shared_family *, shared_family, NULL, ao2_cleanup);
+	RAII_VAR(char *, value, NULL, ast_free);
 	char eid_family[256];
-	char *value = NULL;
 	struct ast_eid eid;
 	int res;
 
@@ -634,6 +641,7 @@
 	TEST_FOR_VALUE(eid_family, "foo", value);
 	ast_test_validate(test, strcmp(value, "bar") == 0);
 	ast_free(value);
+	value = NULL;
 
 	res = ast_db_del_shared(UNIQUE_SHARED_FAMILY);
 	ast_test_validate(test, res == 0, "Removal of unique shared area");
@@ -652,18 +660,17 @@
 	/* Make sure we didn't update the value */
 	TEST_FOR_VALUE(eid_family, "foo", value);
 	ast_test_validate(test, strcmp(value, "bar") == 0);
-	ast_free(value);
-
-	ast_db_deltree("astdbtest_unique", "");
-	ast_db_deltree(TEST_EID, "");
+
 	return AST_TEST_PASS;
 }
 
 AST_TEST_DEFINE(test_ast_db_put_shared_global_update)
 {
+	RAII_VAR(const char *, global_family, GLOBAL_SHARED_FAMILY, ast_db_del_shared);
+	RAII_VAR(const char *, tree_family, GLOBAL_SHARED_FAMILY, tree_cleanup);
 	RAII_VAR(struct ast_db_shared_family *, shared_family, NULL, ao2_cleanup);
+	RAII_VAR(char *, value, NULL, ast_free);
 	struct ast_eid eid;
-	char *value = NULL;
 	int res;
 
 	switch (cmd) {
@@ -696,6 +703,7 @@
 	TEST_FOR_VALUE(GLOBAL_SHARED_FAMILY, "foo", value);
 	ast_test_validate(test, strcmp(value, "bar") == 0);
 	ast_free(value);
+	value = NULL;
 
 	res = ast_db_del_shared(GLOBAL_SHARED_FAMILY);
 	ast_test_validate(test, res == 0, "Removal of global shared area");
@@ -714,9 +722,6 @@
 	/* Make sure we didn't update the value */
 	TEST_FOR_VALUE(GLOBAL_SHARED_FAMILY, "foo", value);
 	ast_test_validate(test, strcmp(value, "bar") == 0);
-	ast_free(value);
-
-	ast_db_deltree(GLOBAL_SHARED_FAMILY, "");
 
 	return AST_TEST_PASS;
 }
@@ -725,6 +730,10 @@
 {
 	RAII_VAR(struct consumer *, consumer, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_subscription *, uut, NULL, stasis_unsubscribe);
+	RAII_VAR(const char *, global_family, GLOBAL_SHARED_FAMILY, ast_db_del_shared);
+	RAII_VAR(const char *, global_tree_family, GLOBAL_SHARED_FAMILY, tree_cleanup);
+	RAII_VAR(const char *, unique_family, UNIQUE_SHARED_FAMILY, ast_db_del_shared);
+	RAII_VAR(const char *, unique_tree_family, UNIQUE_SHARED_FAMILY, tree_cleanup);
 	int res;
 	int actual_len;
 
@@ -767,11 +776,6 @@
 
 	ast_test_validate(test, stasis_message_type(consumer->messages_rxed[0]) == ast_db_put_shared_type());
 	ast_test_validate(test, stasis_message_type(consumer->messages_rxed[1]) == ast_db_put_shared_type());
-
-	ast_db_del_shared(UNIQUE_SHARED_FAMILY);
-	ast_db_del_shared(GLOBAL_SHARED_FAMILY);
-	ast_db_deltree(UNIQUE_SHARED_FAMILY, "");
-	ast_db_deltree(GLOBAL_SHARED_FAMILY, "");
 
 	return AST_TEST_PASS;
 }




More information about the asterisk-commits mailing list