[asterisk-commits] kmoore: branch kmoore/stasis-http_sounds r389248 - /team/kmoore/stasis-http_s...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 20 12:55:32 CDT 2013


Author: kmoore
Date: Mon May 20 12:55:28 2013
New Revision: 389248

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389248
Log:
Break up allocation and search

Modified:
    team/kmoore/stasis-http_sounds/res/res_sounds.c

Modified: team/kmoore/stasis-http_sounds/res/res_sounds.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/res/res_sounds.c?view=diff&rev=389248&r1=389247&r2=389248
==============================================================================
--- team/kmoore/stasis-http_sounds/res/res_sounds.c (original)
+++ team/kmoore/stasis-http_sounds/res/res_sounds.c Mon May 20 12:55:28 2013
@@ -185,17 +185,26 @@
 	return lang_dirs;
 }
 
-/*! \brief Find or optionally create the appropriate sound_variant and any necessary structures */
-static struct sound_variant *get_variant(const char *filename, const char *lang, int no_alloc)
+static struct sound_variant *find_variant(const char *filename, const char *lang)
+{
+	RAII_VAR(struct sound_info *, info, NULL, ao2_cleanup);
+
+	info = ao2_find(sounds_index, filename, OBJ_KEY);
+	if (!info) {
+		return NULL;
+	}
+
+	return ao2_find(info->variant_list, lang, OBJ_KEY);
+}
+
+/*! \brief create the appropriate sound_variant and any necessary structures */
+static struct sound_variant *alloc_variant(const char *filename, const char *lang)
 {
 	RAII_VAR(struct sound_info *, info, NULL, ao2_cleanup);
 	RAII_VAR(struct sound_variant *, variant, NULL, ao2_cleanup);
 
 	info = ao2_find(sounds_index, filename, OBJ_KEY);
 	if (!info) {
-		if (no_alloc) {
-			return NULL;
-		}
 		/* This is the first time the index has seen this filename,
 		 * allocate and link */
 		info = sound_info_alloc(filename);
@@ -208,9 +217,6 @@
 
 	variant = ao2_find(info->variant_list, lang, OBJ_KEY);
 	if (!variant) {
-		if (no_alloc) {
-			return NULL;
-		}
 		/* This is the first time the index has seen this language for
 		 * this filename, allocate and link */
 		variant = sound_variant_alloc(lang);
@@ -233,7 +239,7 @@
 		return NULL;
 	}
 
-	variant = get_variant(filename, lang, 1);
+	variant = find_variant(filename, lang);
 	if (!variant) {
 		return NULL;
 	}
@@ -249,7 +255,7 @@
 		return NULL;
 	}
 
-	variant = get_variant(filename, lang, 1);
+	variant = find_variant(filename, lang);
 	if (!variant) {
 		return NULL;
 	}
@@ -319,9 +325,12 @@
 /*! \brief Update an index with new format/language information */
 static int update_file_format_info(const char *filename, const char *lang, const struct ast_format *file_format)
 {
-	RAII_VAR(struct sound_variant *, variant, get_variant(filename, lang, 0), ao2_cleanup);
+	RAII_VAR(struct sound_variant *, variant, find_variant(filename, lang), ao2_cleanup);
 	if (!variant) {
-		return -1;
+		variant = alloc_variant(filename, lang);
+		if (!variant) {
+			return -1;
+		}
 	}
 
 	ast_format_cap_add(variant->formats, file_format);
@@ -429,10 +438,13 @@
 			/* if there's text in cumulative_description, archive it and start anew */
 			if (file_id_persist && !ast_strlen_zero(ast_str_buffer(cumulative_description))) {
 				RAII_VAR(struct sound_variant *, variant, NULL, ao2_cleanup);
-				variant = get_variant(file_id_persist, lang, 0);
+				variant = find_variant(file_id_persist, lang);
 				if (!variant) {
-					res = -1;
-					break;
+					variant = alloc_variant(filename, lang);
+					if (!variant) {
+						res = -1;
+						break;
+					}
 				}
 
 				ast_string_field_set(variant, description, ast_str_buffer(cumulative_description));
@@ -451,7 +463,11 @@
 	/* handle the last one */
 	if (file_id_persist && !ast_strlen_zero(ast_str_buffer(cumulative_description))) {
 		RAII_VAR(struct sound_variant *, variant, NULL, ao2_cleanup);
-		variant = get_variant(file_id_persist, lang, 0);
+		variant = find_variant(file_id_persist, lang);
+		if (!variant) {
+			variant = alloc_variant(filename, lang);
+		}
+
 		if (variant) {
 			ast_string_field_set(variant, description, ast_str_buffer(cumulative_description));
 			ast_free(file_id_persist);




More information about the asterisk-commits mailing list