[svn-commits] dlee: branch dlee/stasis-cache-split r394204 - in /team/dlee/stasis-cache-spl...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jul 12 13:54:41 CDT 2013


Author: dlee
Date: Fri Jul 12 13:54:39 2013
New Revision: 394204

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394204
Log:
Merged revisions 394189,394203 from http://svn.asterisk.org/svn/asterisk/trunk

Modified:
    team/dlee/stasis-cache-split/   (props changed)
    team/dlee/stasis-cache-split/res/res_stasis_http.c
    team/dlee/stasis-cache-split/res/stasis_http/cli.c
    team/dlee/stasis-cache-split/res/stasis_http/config.c
    team/dlee/stasis-cache-split/res/stasis_http/internal.h
    team/dlee/stasis-cache-split/tests/test_json.c

Propchange: team/dlee/stasis-cache-split/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Jul 12 13:54:39 2013
@@ -1,1 +1,1 @@
-/trunk:1-394158
+/trunk:1-394203

Modified: team/dlee/stasis-cache-split/res/res_stasis_http.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-cache-split/res/res_stasis_http.c?view=diff&rev=394204&r1=394203&r2=394204
==============================================================================
--- team/dlee/stasis-cache-split/res/res_stasis_http.c (original)
+++ team/dlee/stasis-cache-split/res/res_stasis_http.c Fri Jul 12 13:54:39 2013
@@ -293,6 +293,26 @@
 	ast_str_append(&response->headers, 0, "\r\n");
 }
 
+static int origin_allowed(const char *origin)
+{
+	RAII_VAR(struct ari_conf *, cfg, ari_config_get(), ao2_cleanup);
+
+	char *allowed = ast_strdupa(cfg->general->allowed_origins);
+	char *current;
+
+	while ((current = strsep(&allowed, ","))) {
+		if (!strcmp(current, "*")) {
+			return 1;
+		}
+
+		if (!strcmp(current, origin)) {
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
 #define ACR_METHOD "Access-Control-Request-Method"
 #define ACR_HEADERS "Access-Control-Request-Headers"
 #define ACA_METHODS "Access-Control-Allow-Methods"
@@ -333,7 +353,7 @@
 	}
 
 	/* CORS 6.2, #1 - "If the Origin header is not present terminate this
-	 * set of steps.
+	 * set of steps."
 	 */
 	if (origin == NULL) {
 		return;
@@ -343,14 +363,16 @@
 	 * case-sensitive match for any of the values in list of origins do not
 	 * set any additional headers and terminate this set of steps.
 	 *
-	 * "Always matching is acceptable since the list of origins can be
+	 * Always matching is acceptable since the list of origins can be
 	 * unbounded.
 	 *
-	 * "The Origin header can only contain a single origin as the user agent
-	 * will not follow redirects.
-	 *
-	 * TODO - pull list of allowed origins from config
-	 */
+	 * The Origin header can only contain a single origin as the user agent
+	 * will not follow redirects."
+	 */
+	if (!origin_allowed(origin)) {
+		ast_log(LOG_NOTICE, "Origin header '%s' does not match an allowed origin.\n", origin);
+		return;
+	}
 
 	/* CORS 6.2, #3 - "If there is no Access-Control-Request-Method header
 	 * or if parsing failed, do not set any additional headers and terminate
@@ -397,7 +419,7 @@
 	 * case-insensitive match for any of the values in list of headers do
 	 * not set any additional headers and terminate this set of steps.
 	 *
-	 * "Note: Always matching is acceptable since the list of headers can be
+	 * Note: Always matching is acceptable since the list of headers can be
 	 * unbounded."
 	 */
 
@@ -423,7 +445,7 @@
 	/* CORS 6.2, #10 - "Add one or more Access-Control-Allow-Headers headers
 	 * consisting of (a subset of) the list of headers.
 	 *
-	 * "Since the list of headers can be unbounded simply returning headers
+	 * Since the list of headers can be unbounded simply returning headers
 	 * can be enough."
 	 */
 	if (!ast_strlen_zero(acr_headers)) {
@@ -700,25 +722,26 @@
 	 * case-sensitive match for any of the values in list of origins, do not
 	 * set any additional headers and terminate this set of steps.
 	 *
-	 * "Note: Always matching is acceptable since the list of origins can be
+	 * Note: Always matching is acceptable since the list of origins can be
 	 * unbounded."
-	 *
-	 * TODO - pull list of allowed origins from config
-	 */
+	 */
+	if (!origin_allowed(origin)) {
+		ast_log(LOG_NOTICE, "Origin header '%s' does not match an allowed origin.\n", origin);
+		return;
+	}
 
 	/* CORS 6.1, #3 - "If the resource supports credentials add a single
 	 * Access-Control-Allow-Origin header, with the value of the Origin
 	 * header as value, and add a single Access-Control-Allow-Credentials
 	 * header with the case-sensitive string "true" as value.
 	 *
-	 * "Otherwise, add a single Access-Control-Allow-Origin header, with
+	 * Otherwise, add a single Access-Control-Allow-Origin header, with
 	 * either the value of the Origin header or the string "*" as value."
-	 *
-	 * TODO - when we add authentication, this will change to
-	 * Access-Control-Allow-Credentials.
 	 */
 	ast_str_append(&response->headers, 0,
 		       "Access-Control-Allow-Origin: %s\r\n", origin);
+	ast_str_append(&response->headers, 0,
+		       "Access-Control-Allow-Credentials: true\r\n");
 
 	/* CORS 6.1, #4 - "If the list of exposed headers is not empty add one
 	 * or more Access-Control-Expose-Headers headers, with as values the

Modified: team/dlee/stasis-cache-split/res/stasis_http/cli.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-cache-split/res/stasis_http/cli.c?view=diff&rev=394204&r1=394203&r2=394204
==============================================================================
--- team/dlee/stasis-cache-split/res/stasis_http/cli.c (original)
+++ team/dlee/stasis-cache-split/res/stasis_http/cli.c Fri Jul 12 13:54:39 2013
@@ -71,6 +71,7 @@
 	}
 	ast_cli(a->fd, "\n");
 	ast_cli(a->fd, "Auth realm: %s\n", conf->general->auth_realm);
+	ast_cli(a->fd, "Allowed Origins: %s\n", conf->general->allowed_origins);
 	ast_cli(a->fd, "User count: %d\n", ao2_container_count(conf->users));
 	return CLI_SUCCESS;
 }

Modified: team/dlee/stasis-cache-split/res/stasis_http/config.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-cache-split/res/stasis_http/config.c?view=diff&rev=394204&r1=394203&r2=394204
==============================================================================
--- team/dlee/stasis-cache-split/res/stasis_http/config.c (original)
+++ team/dlee/stasis-cache-split/res/stasis_http/config.c Fri Jul 12 13:54:39 2013
@@ -158,6 +158,9 @@
 static void conf_destructor(void *obj)
 {
 	struct ari_conf *cfg = obj;
+
+	ast_string_field_free_memory(cfg->general);
+
 	ao2_cleanup(cfg->general);
 	ao2_cleanup(cfg->users);
 }
@@ -179,6 +182,10 @@
 		return NULL;
 	}
 	aco_set_defaults(&general_option, "general", cfg->general);
+
+	if (ast_string_field_init(cfg->general, 64)) {
+		return NULL;
+	}
 
 	cfg->users = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_NOLOCK,
 		AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE, user_sort_cmp, NULL);
@@ -308,6 +315,9 @@
 		"Asterisk REST Interface", OPT_CHAR_ARRAY_T, 0,
 		FLDSET(struct ari_conf_general, auth_realm),
 		ARI_AUTH_REALM_LEN);
+	aco_option_register(&cfg_info, "allowed_origins", ACO_EXACT, general_options,
+		"", OPT_STRINGFIELD_T, 0,
+		STRFLDSET(struct ari_conf_general, allowed_origins));
 
 	aco_option_register(&cfg_info, "type", ACO_EXACT, user, NULL,
 		OPT_NOOP_T, 0, 0);

Modified: team/dlee/stasis-cache-split/res/stasis_http/internal.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-cache-split/res/stasis_http/internal.h?view=diff&rev=394204&r1=394203&r2=394204
==============================================================================
--- team/dlee/stasis-cache-split/res/stasis_http/internal.h (original)
+++ team/dlee/stasis-cache-split/res/stasis_http/internal.h Fri Jul 12 13:54:39 2013
@@ -67,6 +67,10 @@
 	enum ast_json_encoding_format format;
 	/*! Authentication realm */
 	char auth_realm[ARI_AUTH_REALM_LEN];
+
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(allowed_origins);
+	);
 };
 
 /*! \brief Password format */

Modified: team/dlee/stasis-cache-split/tests/test_json.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-cache-split/tests/test_json.c?view=diff&rev=394204&r1=394203&r2=394204
==============================================================================
--- team/dlee/stasis-cache-split/tests/test_json.c (original)
+++ team/dlee/stasis-cache-split/tests/test_json.c Fri Jul 12 13:54:39 2013
@@ -41,6 +41,8 @@
 #include "asterisk/module.h"
 #include "asterisk/test.h"
 
+#define CATEGORY "/main/json/"
+
 /*!
  * Number of allocations from JSON library that have not yet been freed.
  */
@@ -68,33 +70,34 @@
 	ast_free(p);
 }
 
-static void *json_test_init(struct ast_test *test)
+static int json_test_init(struct ast_test_info *info, struct ast_test *test)
 {
 	ast_json_set_alloc_funcs(json_debug_malloc, json_debug_free);
 	alloc_count = 0;
-	return test;
-}
-
-static void json_test_finish(void *test)
-{
-	struct ast_test *t = test;
+	return 0;
+}
+
+static int json_test_cleanup(struct ast_test_info *info, struct ast_test *test)
+{
 	ast_json_reset_alloc_funcs();
 	if (0 != alloc_count) {
-		ast_test_status_update(t, "JSON test leaked %zd allocations!", alloc_count);
-	}
+		ast_test_status_update(test,
+			"JSON test leaked %zd allocations!\n", alloc_count);
+		return -1;
+	}
+	return 0;
 }
 
 /*!@}*/
 
 AST_TEST_DEFINE(json_test_false)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "false";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing fundamental JSON false value.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -114,13 +117,12 @@
 
 AST_TEST_DEFINE(json_test_true)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "true";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing JSON true value.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -140,13 +142,12 @@
 
 AST_TEST_DEFINE(json_test_bool0)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "bool0";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing JSON boolean function (false).";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -168,13 +169,12 @@
 
 AST_TEST_DEFINE(json_test_bool1)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "bool1";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing JSON boolean function (true).";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -196,13 +196,12 @@
 
 AST_TEST_DEFINE(json_test_null)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "null";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing JSON null value.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -222,11 +221,10 @@
 
 AST_TEST_DEFINE(json_test_null_val)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "null_val";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing JSON handling of NULL.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -249,14 +247,13 @@
 
 AST_TEST_DEFINE(json_test_string)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	int uut_res;
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "string";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Basic string tests.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -290,13 +287,12 @@
 
 AST_TEST_DEFINE(json_test_string_null)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "string_null";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "JSON string NULL tests.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -323,14 +319,13 @@
 
 AST_TEST_DEFINE(json_test_stringf)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "stringf";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Basic string formatting tests.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -357,14 +352,13 @@
 
 AST_TEST_DEFINE(json_test_int)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	int uut_res;
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "int";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Basic JSON integer tests.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -399,13 +393,12 @@
 
 AST_TEST_DEFINE(json_test_non_int)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "non_int";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing integer functions with non-integer types.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -438,13 +431,12 @@
 
 AST_TEST_DEFINE(json_test_array_create)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "array_create";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing creating JSON arrays.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -463,14 +455,13 @@
 
 AST_TEST_DEFINE(json_test_array_append)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	int uut_res;
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "array_append";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing appending to JSON arrays.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -493,14 +484,13 @@
 
 AST_TEST_DEFINE(json_test_array_inset)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	int uut_res;
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "array_insert";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing inserting into JSON arrays.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -521,14 +511,13 @@
 
 AST_TEST_DEFINE(json_test_array_set)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	int uut_res;
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "array_set";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing setting a value in JSON arrays.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -549,7 +538,6 @@
 
 AST_TEST_DEFINE(json_test_array_remove)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 	int uut_res;
@@ -557,7 +545,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "array_remove";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing removing a value from JSON arrays.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -577,14 +565,13 @@
 
 AST_TEST_DEFINE(json_test_array_clear)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	int uut_res;
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "array_clear";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing clearing JSON arrays.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -603,7 +590,6 @@
 
 AST_TEST_DEFINE(json_test_array_extend)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, tail, NULL, ast_json_unref);
@@ -612,7 +598,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "array_extend";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing extending JSON arrays.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -650,13 +636,12 @@
 
 AST_TEST_DEFINE(json_test_array_null)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "array_null";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing NULL conditions for JSON arrays.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -682,13 +667,12 @@
 
 AST_TEST_DEFINE(json_test_object_alloc)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_alloc";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing creating JSON objects.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -707,7 +691,6 @@
 
 AST_TEST_DEFINE(json_test_object_set)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 	int uut_res;
@@ -715,7 +698,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_set";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing setting values in JSON objects.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -740,14 +723,13 @@
 
 AST_TEST_DEFINE(json_test_object_set_overwrite)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	int uut_res;
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_set_overwriting";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing changing values in JSON objects.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -766,13 +748,12 @@
 
 AST_TEST_DEFINE(json_test_object_get)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_get";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing getting values from JSON objects.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -791,7 +772,6 @@
 
 AST_TEST_DEFINE(json_test_object_del)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 	int uut_res;
@@ -799,7 +779,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_del";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing deleting values from JSON objects.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -821,14 +801,13 @@
 
 AST_TEST_DEFINE(json_test_object_clear)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	int uut_res;
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_clear";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing clearing values from JSON objects.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -850,7 +829,6 @@
 
 AST_TEST_DEFINE(json_test_object_merge_all)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, merge, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
@@ -859,7 +837,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_alloc";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing merging JSON objects.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -896,7 +874,6 @@
 
 AST_TEST_DEFINE(json_test_object_merge_existing)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, merge, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
@@ -905,7 +882,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_alloc";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing merging JSON objects, updating only existing fields.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -940,7 +917,6 @@
 
 AST_TEST_DEFINE(json_test_object_merge_missing)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, merge, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
@@ -949,7 +925,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_merge_missing";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing merging JSON objects, adding only missing fields.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -986,13 +962,12 @@
 
 AST_TEST_DEFINE(json_test_object_null)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_null";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing JSON object NULL behavior.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1022,7 +997,6 @@
 
 AST_TEST_DEFINE(json_test_object_iter)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	struct ast_json_iter *iter;
 	int count;
 	int uut_res;
@@ -1031,7 +1005,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_iter";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing iterating through JSON objects.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1086,13 +1060,12 @@
 
 AST_TEST_DEFINE(json_test_object_iter_null)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_iter_null";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing JSON object iterator NULL testings.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1116,7 +1089,6 @@
 
 AST_TEST_DEFINE(json_test_dump_load_string)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 	RAII_VAR(char *, str, NULL, json_debug_free);
@@ -1124,7 +1096,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "dump_load_string";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing dumping strings from JSON.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1146,7 +1118,6 @@
 
 AST_TEST_DEFINE(json_test_dump_load_str)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 	RAII_VAR(struct ast_str *, astr, NULL, ast_free);
@@ -1155,7 +1126,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "dump_load_str";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing dumping ast_str from JSON.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1177,7 +1148,6 @@
 
 AST_TEST_DEFINE(json_test_dump_str_fail)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 	struct ast_str *astr;
@@ -1186,7 +1156,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "dump_str_fail";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing dumping to ast_str when it can't grow.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1205,14 +1175,13 @@
 
 AST_TEST_DEFINE(json_test_load_buffer)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	const char *str;
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "load_buffer";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing loading JSON from buffer.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1241,7 +1210,6 @@
 
 AST_TEST_DEFINE(json_test_dump_load_file)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 	RAII_VAR(char *, filename, NULL, free);
@@ -1251,7 +1219,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "dump_load_file";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing dumping/loading JSON to/from file by FILE *.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1275,7 +1243,6 @@
 
 AST_TEST_DEFINE(json_test_dump_load_new_file)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 	RAII_VAR(char *, filename, NULL, free);
@@ -1284,7 +1251,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "dump_load_new_file";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing dumping/load JSON to/from file by filename.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1305,7 +1272,6 @@
 
 AST_TEST_DEFINE(json_test_dump_load_null)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(char *, filename, NULL, free);
 	RAII_VAR(FILE *, file, NULL, safe_fclose);
@@ -1313,7 +1279,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "dump_load_null";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing NULL handling of dump/load functions.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1343,13 +1309,12 @@
 
 AST_TEST_DEFINE(json_test_parse_errors)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "parse_errors";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing various parse errors.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1372,14 +1337,13 @@
 
 AST_TEST_DEFINE(json_test_pack)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "pack";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing json_pack function.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1403,13 +1367,12 @@
 
 AST_TEST_DEFINE(json_test_pack_ownership)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "pack_ownership";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing json_pack failure conditions.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1424,13 +1387,12 @@
 
 AST_TEST_DEFINE(json_test_pack_errors)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_alloc";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing json_pack failure conditions.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1448,14 +1410,13 @@
 
 AST_TEST_DEFINE(json_test_copy)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "copy";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing copying JSON.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1475,14 +1436,13 @@
 
 AST_TEST_DEFINE(json_test_deep_copy)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "deep_copy";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing deep copying of JSON.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1505,11 +1465,10 @@
 
 AST_TEST_DEFINE(json_test_copy_null)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "copy_null";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Testing NULL handling of copy functions.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1526,14 +1485,13 @@
 
 AST_TEST_DEFINE(json_test_circular_object)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	int uut_res;
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "circular_object";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Object cannot be added to itself.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1553,14 +1511,13 @@
 
 AST_TEST_DEFINE(json_test_circular_array)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	int uut_res;
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "circular_array";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "Array cannot be added to itself.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1579,7 +1536,6 @@
 
 AST_TEST_DEFINE(json_test_clever_circle)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, inner_child, NULL, ast_json_unref);
 	RAII_VAR(char *, str, NULL, json_debug_free);
@@ -1588,7 +1544,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "clever_circle";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "JSON with circular references cannot be encoded.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1613,14 +1569,13 @@
 
 AST_TEST_DEFINE(json_test_name_number)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "name_number";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "JSON encoding of name/number pair.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1643,7 +1598,6 @@
 
 AST_TEST_DEFINE(json_test_timeval)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 	struct timeval tv = {};
@@ -1651,7 +1605,7 @@
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "timeval";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "JSON encoding of timevals.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1672,14 +1626,13 @@
 
 AST_TEST_DEFINE(json_test_cep)
 {
-	RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
 	RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
 
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "cep";
-		info->category = "/main/json/";
+		info->category = CATEGORY;
 		info->summary = "JSON with circular references cannot be encoded.";
 		info->description = "Test JSON abstraction library.";
 		return AST_TEST_NOT_RUN;
@@ -1815,6 +1768,10 @@
 	AST_TEST_REGISTER(json_test_name_number);
 	AST_TEST_REGISTER(json_test_timeval);
 	AST_TEST_REGISTER(json_test_cep);
+
+	ast_test_register_init(CATEGORY, json_test_init);
+	ast_test_register_cleanup(CATEGORY, json_test_cleanup);
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 




More information about the svn-commits mailing list