[asterisk-commits] kmoore: branch kmoore/stasis-http_sounds r390390 - in /team/kmoore/stasis-htt...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 3 21:49:27 CDT 2013


Author: kmoore
Date: Mon Jun  3 21:49:24 2013
New Revision: 390390

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390390
Log:
Fix minor problems from dlee's review

Modified:
    team/kmoore/stasis-http_sounds/include/asterisk/file.h
    team/kmoore/stasis-http_sounds/include/asterisk/media_index.h
    team/kmoore/stasis-http_sounds/include/asterisk/sounds_index.h
    team/kmoore/stasis-http_sounds/main/file.c
    team/kmoore/stasis-http_sounds/main/media_index.c
    team/kmoore/stasis-http_sounds/main/sounds_index.c
    team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c

Modified: team/kmoore/stasis-http_sounds/include/asterisk/file.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/include/asterisk/file.h?view=diff&rev=390390&r1=390389&r2=390390
==============================================================================
--- team/kmoore/stasis-http_sounds/include/asterisk/file.h (original)
+++ team/kmoore/stasis-http_sounds/include/asterisk/file.h Mon Jun  3 21:49:24 2013
@@ -378,6 +378,7 @@
 
 /*!
  * \brief Get the ast_format associated with the given file extension
+ * \since 12
  *
  * \param file_ext The file extension for which to find the format
  *

Modified: team/kmoore/stasis-http_sounds/include/asterisk/media_index.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/include/asterisk/media_index.h?view=diff&rev=390390&r1=390389&r2=390390
==============================================================================
--- team/kmoore/stasis-http_sounds/include/asterisk/media_index.h (original)
+++ team/kmoore/stasis-http_sounds/include/asterisk/media_index.h Mon Jun  3 21:49:24 2013
@@ -50,9 +50,9 @@
  * \param variant Media variant for which to get the description
  *
  * \retval NULL if not found
- * \return a copy of the description (must be ast_freed)
+ * \return The description requested (must be copied to be kept)
  */
-char *ast_media_get_description(struct ast_media_index *index, const char *filename, const char *variant);
+const char *ast_media_get_description(struct ast_media_index *index, const char *filename, const char *variant);
 
 /*!
  * \brief Get the ast_format_cap for a media file
@@ -62,7 +62,7 @@
  * \param variant Media variant for which to get the description
  *
  * \retval NULL if not found
- * \return a copy of the format capabilities (must be destroyed)
+ * \return a copy of the format capabilities (must be destroyed with ast_format_cap_destroy)
  */
 struct ast_format_cap *ast_media_get_format_cap(struct ast_media_index *index, const char *filename, const char *variant);
 

Modified: team/kmoore/stasis-http_sounds/include/asterisk/sounds_index.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/include/asterisk/sounds_index.h?view=diff&rev=390390&r1=390389&r2=390390
==============================================================================
--- team/kmoore/stasis-http_sounds/include/asterisk/sounds_index.h (original)
+++ team/kmoore/stasis-http_sounds/include/asterisk/sounds_index.h Mon Jun  3 21:49:24 2013
@@ -43,7 +43,7 @@
 /*!
  * \brief Get the sounds index
  *
- * \retval sounds index
+ * \retval sounds index (must be ao2_cleanup()'ed)
  * \retval NULL on failure
  */
 struct ast_media_index *ast_sounds_get_index(void);

Modified: team/kmoore/stasis-http_sounds/main/file.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/main/file.c?view=diff&rev=390390&r1=390389&r2=390390
==============================================================================
--- team/kmoore/stasis-http_sounds/main/file.c (original)
+++ team/kmoore/stasis-http_sounds/main/file.c Mon Jun  3 21:49:24 2013
@@ -82,17 +82,12 @@
 	}
 
 	while ((ext = strsep(&stringp, sep))) {
-		struct ast_json *ext_str = ast_json_string_create(ext);
-		if (!ext_str) {
+		if (ast_json_array_append(array, ast_json_string_create(ext))) {
 			return NULL;
 		}
-
-		/* append consumes the reference */
-		ast_json_array_append(array, ext_str);
-	}
-
-	ast_json_ref(array);
-	return array;
+	}
+
+	return ast_json_ref(array);
 }
 
 static int publish_format_update(const struct ast_format_def *f, struct stasis_message_type *type)

Modified: team/kmoore/stasis-http_sounds/main/media_index.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/main/media_index.c?view=diff&rev=390390&r1=390389&r2=390390
==============================================================================
--- team/kmoore/stasis-http_sounds/main/media_index.c (original)
+++ team/kmoore/stasis-http_sounds/main/media_index.c Mon Jun  3 21:49:24 2013
@@ -63,7 +63,7 @@
 {
 	RAII_VAR(struct media_variant *, variant, ao2_alloc(sizeof(*variant), media_variant_destroy), ao2_cleanup);
 
-	if (ast_string_field_init(variant, 8)) {
+	if (!variant || ast_string_field_init(variant, 8)) {
 		return NULL;
 	}
 
@@ -112,7 +112,7 @@
 {
 	RAII_VAR(struct media_info *, info, ao2_alloc(sizeof(*info), media_info_destroy), ao2_cleanup);
 
-	if (ast_string_field_init(info, 128)) {
+	if (!info || ast_string_field_init(info, 128)) {
 		return NULL;
 	}
 
@@ -157,6 +157,9 @@
 static struct ast_media_index *media_index_alloc(void)
 {
 	RAII_VAR(struct ast_media_index *, index, ao2_alloc(sizeof(*index), media_index_dtor), ao2_cleanup);
+	if (!index) {
+		return NULL;
+	}
 
 	index->index = ao2_container_alloc(INDEX_BUCKETS, media_info_hash, media_info_cmp);
 	if (!index->index) {
@@ -213,7 +216,7 @@
 	return variant;
 }
 
-char *ast_media_get_description(struct ast_media_index *index, const char *filename, const char *variant_str)
+const char *ast_media_get_description(struct ast_media_index *index, const char *filename, const char *variant_str)
 {
 	RAII_VAR(struct media_variant *, variant, NULL, ao2_cleanup);
 	if (ast_strlen_zero(filename) || ast_strlen_zero(variant_str)) {
@@ -225,7 +228,7 @@
 		return NULL;
 	}
 
-	return ast_strdup(variant->description);
+	return variant->description;
 }
 
 struct ast_format_cap *ast_media_get_format_cap(struct ast_media_index *index, const char *filename, const char *variant_str)
@@ -511,6 +514,7 @@
 	struct dirent* dent;
 	DIR* srcdir;
 	RAII_VAR(struct ast_str *, index_dir, ast_str_create(64), ast_free);
+	RAII_VAR(struct ast_str *, statfile, ast_str_create(64), ast_free);
 	int res = 0;
 
 	if (!index_dir) {
@@ -538,19 +542,26 @@
 			continue;
 		}
 
-		if (fstatat(dirfd(srcdir), dent->d_name, &st, 0) < 0) {
-			ast_log(LOG_ERROR, "Failed to stat %s\n", dent->d_name);
+		ast_str_reset(statfile);
+		ast_str_set(&statfile, 0, "%s/%s", ast_str_buffer(index_dir), dent->d_name);
+
+		if (stat(ast_str_buffer(statfile), &st) < 0) {
+			ast_log(LOG_ERROR, "Failed to stat %s\n", ast_str_buffer(statfile));
 			res = -1;
 			break;
 		}
 
 		if (S_ISDIR(st.st_mode)) {
 			if (ast_strlen_zero(subdir)) {
-				media_index_update(index, base_dir, variant, dent->d_name);
+				res = media_index_update(index, base_dir, variant, dent->d_name);
 			} else {
 				RAII_VAR(struct ast_str *, new_subdir, ast_str_create(64), ast_free);
 				ast_str_set(&new_subdir, 0, "%s/%s", subdir, dent->d_name);
-				media_index_update(index, base_dir, variant, ast_str_buffer(new_subdir));
+				res = media_index_update(index, base_dir, variant, ast_str_buffer(new_subdir));
+			}
+
+			if (res) {
+				break;
 			}
 			continue;
 		}

Modified: team/kmoore/stasis-http_sounds/main/sounds_index.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/main/sounds_index.c?view=diff&rev=390390&r1=390389&r2=390390
==============================================================================
--- team/kmoore/stasis-http_sounds/main/sounds_index.c (original)
+++ team/kmoore/stasis-http_sounds/main/sounds_index.c Mon Jun  3 21:49:24 2013
@@ -55,6 +55,7 @@
 	struct dirent* dent;
 	DIR* srcdir;
 	RAII_VAR(struct ast_str *, media_dir, ast_str_create(64), ast_free);
+	RAII_VAR(struct ast_str *, variant_dir, ast_str_create(64), ast_free);
 
 	lang_dirs = ast_str_container_alloc(LANGUAGE_BUCKETS);
 	if (!media_dir || !lang_dirs) {
@@ -77,8 +78,11 @@
 			continue;
 		}
 
-		if (fstatat(dirfd(srcdir), dent->d_name, &st, 0) < 0) {
-			ast_log(LOG_ERROR, "Failed to stat %s\n", dent->d_name);
+		ast_str_reset(variant_dir);
+		ast_str_set(&variant_dir, 0, "%s/%s", ast_str_buffer(media_dir), dent->d_name);
+
+		if (stat(ast_str_buffer(variant_dir), &st) < 0) {
+			ast_log(LOG_ERROR, "Failed to stat %s\n", ast_str_buffer(variant_dir));
 			continue;
 		}
 
@@ -145,15 +149,16 @@
 	struct ast_cli_args *a = arg;
         struct ast_format format;
 	int formats_shown = 0;
+	RAII_VAR(struct ast_media_index *, local_index, ast_sounds_get_index(), ao2_cleanup);
 	RAII_VAR(struct ast_format_cap *, cap, NULL, ast_format_cap_destroy);
-	RAII_VAR(char *, description, ast_media_get_description(sounds_index, a->argv[2], language), ast_free);
+	const char *description = ast_media_get_description(local_index, a->argv[2], language);
 
 	ast_cli(a->fd, "  Language %s:\n", language);
 	if (!ast_strlen_zero(description)) {
 		ast_cli(a->fd, "    Description: %s\n", description);
 	}
 
-	cap = ast_media_get_format_cap(sounds_index, a->argv[2], language);
+	cap = ast_media_get_format_cap(local_index, a->argv[2], language);
         ast_format_cap_iter_start(cap);
         while (!ast_format_cap_iter_next(cap, &format)) {
 		ast_cli(a->fd, "    Format: %s\n", ast_getformatname(&format));
@@ -202,7 +207,7 @@
 	case CLI_INIT:
 		e->command = "sounds show";
 		e->usage =
-			"Usage: sounds show[ soundid]\n"
+			"Usage: sounds show [soundid]\n"
 			"       Shows a listing of sound files or information about the specified sound.\n";
 		return NULL;
 	case CLI_GENERATE:
@@ -265,7 +270,7 @@
 
 static void sounds_cleanup(void)
 {
-	stasis_message_router_unsubscribe(sounds_system_router);
+	stasis_message_router_unsubscribe_and_join(sounds_system_router);
 	sounds_system_router = NULL;
 	ast_cli_unregister_multiple(cli_sounds, ARRAY_LEN(cli_sounds));
 	ao2_cleanup(sounds_index);

Modified: team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c?view=diff&rev=390390&r1=390389&r2=390390
==============================================================================
--- team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c (original)
+++ team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c Mon Jun  3 21:49:24 2013
@@ -99,7 +99,7 @@
 {
 	RAII_VAR(struct ast_json *, sound, NULL, ast_json_unref);
 	RAII_VAR(struct ao2_container *, languages, NULL, ao2_cleanup);
-	RAII_VAR(char *, description, NULL, ast_free);
+	const char *description;
 	struct ast_json *format_lang_list;
 	struct lang_format_info info;
 	RAII_VAR(struct ast_media_index *, sounds_index, ast_sounds_get_index(), ao2_cleanup);




More information about the asterisk-commits mailing list