[asterisk-commits] file: branch file/sorceryx4 r391898 - in /team/file/sorceryx4: include/asteri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 14 16:29:03 CDT 2013


Author: file
Date: Fri Jun 14 16:29:02 2013
New Revision: 391898

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391898
Log:
Incorporate review feedback.

1. Improve documentation
2. Add tests for setting extended fields
3. Allow overwriting the value of an extended field

Modified:
    team/file/sorceryx4/include/asterisk/sorcery.h
    team/file/sorceryx4/main/sorcery.c
    team/file/sorceryx4/tests/test_sorcery.c

Modified: team/file/sorceryx4/include/asterisk/sorcery.h
URL: http://svnview.digium.com/svn/asterisk/team/file/sorceryx4/include/asterisk/sorcery.h?view=diff&rev=391898&r1=391897&r2=391898
==============================================================================
--- team/file/sorceryx4/include/asterisk/sorcery.h (original)
+++ team/file/sorceryx4/include/asterisk/sorcery.h Fri Jun 14 16:29:02 2013
@@ -728,6 +728,9 @@
  *
  * \retval 0 success
  * \retval -1 failure
+ *
+ * \note The field name MUST begin with '@' to indicate it is an extended field.
+ * \note If the extended field already exists it will be overwritten with the new value.
  */
 int ast_sorcery_object_set_extended(const void *object, const char *name, const char *value);
 

Modified: team/file/sorceryx4/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorceryx4/main/sorcery.c?view=diff&rev=391898&r1=391897&r2=391898
==============================================================================
--- team/file/sorceryx4/main/sorcery.c (original)
+++ team/file/sorceryx4/main/sorcery.c Fri Jun 14 16:29:02 2013
@@ -1458,12 +1458,24 @@
 
 int ast_sorcery_object_set_extended(const void *object, const char *name, const char *value)
 {
-	struct ast_variable *extended;
+	RAII_VAR(struct ast_variable *, field, NULL, ast_variables_destroy);
+	struct ast_variable *extended = ast_variable_new(name, value, ""), *previous = NULL;
 	const struct ast_sorcery_object_details *details = object;
 
-	if (ast_sorcery_object_get_extended(object, name) || 
-		!(extended = ast_variable_new(name, value, ""))) {
-		return -1;
+	if (!extended) {
+		return -1;
+	}
+
+	for (field = details->object->extended; field; previous = field, field = field->next) {
+		if (!strcmp(field->name, name)) {
+			if (previous) {
+				previous->next = field->next;
+			} else {
+				details->object->extended = field->next;
+			}
+			field->next = NULL;
+			break;
+		}
 	}
 
 	extended->next = details->object->extended;

Modified: team/file/sorceryx4/tests/test_sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorceryx4/tests/test_sorcery.c?view=diff&rev=391898&r1=391897&r2=391898
==============================================================================
--- team/file/sorceryx4/tests/test_sorcery.c (original)
+++ team/file/sorceryx4/tests/test_sorcery.c Fri Jun 14 16:29:02 2013
@@ -1340,6 +1340,24 @@
 		ast_test_status_update(test, "Extended field, which was set using object set, could not be found\n");
 		res = AST_TEST_FAIL;
 	} else if (strcmp(value, "toast")) {
+		ast_test_status_update(test, "Extended field does not contain expected value\n");
+		res = AST_TEST_FAIL;
+	} else if (ast_sorcery_object_set_extended(obj, "@tacos", "supreme")) {
+		ast_test_status_update(test, "Extended field could not be set\n");
+		res = AST_TEST_FAIL;
+	} else if (!(value = ast_sorcery_object_get_extended(obj, "tacos"))) {
+		ast_test_status_update(test, "Extended field, which was set using the API, could not be found\n");
+		res = AST_TEST_FAIL;
+	} else if (strcmp(value, "supreme")) {
+		ast_test_status_update(test, "Extended field does not contain expected value\n");
+		res = AST_TEST_FAIL;
+	} else if (ast_sorcery_object_set_extended(obj, "@tacos", "canadian")) {
+		ast_test_status_update(test, "Extended field could not be set a second time\n");
+		res = AST_TEST_FAIL;
+	} else if (!(value = ast_sorcery_object_get_extended(obj, "tacos"))) {
+		ast_test_status_update(test, "Extended field, which was set using the API, could not be found\n");
+		res = AST_TEST_FAIL;
+	} else if (strcmp(value, "canadian")) {
 		ast_test_status_update(test, "Extended field does not contain expected value\n");
 		res = AST_TEST_FAIL;
 	}




More information about the asterisk-commits mailing list