[asterisk-commits] kmoore: branch kmoore/stasis-http_sounds r390391 - in /team/kmoore/stasis-htt...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 4 08:37:22 CDT 2013
Author: kmoore
Date: Tue Jun 4 08:37:19 2013
New Revision: 390391
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390391
Log:
Pull base_dir into the media index constructor
Modified:
team/kmoore/stasis-http_sounds/include/asterisk/media_index.h
team/kmoore/stasis-http_sounds/main/media_index.c
team/kmoore/stasis-http_sounds/main/sounds_index.c
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=390391&r1=390390&r2=390391
==============================================================================
--- team/kmoore/stasis-http_sounds/include/asterisk/media_index.h (original)
+++ team/kmoore/stasis-http_sounds/include/asterisk/media_index.h Tue Jun 4 08:37:19 2013
@@ -37,10 +37,13 @@
/*!
* \brief Creates a new media index
*
+ * \param base_dir Base directory for indexing
+ *
* \retval NULL on error
* \retval A new AO2 refcounted media index
*/
-struct ast_media_index *ast_media_index_create(void);
+struct ast_media_index *ast_media_index_create(
+ const char *base_dir);
/*!
* \brief Get the description for a media file
@@ -91,14 +94,12 @@
* \brief Update a media index
*
* \param index Media index in which to query information
- * \param base_dir Base directory in which to start the indexing
* \param variant Media variant for which to get the description
*
* \retval non-zero on error
* \return zero on success
*/
int ast_media_index_update(struct ast_media_index *index,
- const char *base_dir,
const char *variant);
#if defined(__cplusplus) || defined(c_plusplus)
}
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=390391&r1=390390&r2=390391
==============================================================================
--- team/kmoore/stasis-http_sounds/main/media_index.c (original)
+++ team/kmoore/stasis-http_sounds/main/media_index.c Tue Jun 4 08:37:19 2013
@@ -141,6 +141,9 @@
}
struct ast_media_index {
+ AST_DECLARE_STRING_FIELDS(
+ AST_STRING_FIELD(base_dir); /*!< Base directory for indexing */
+ );
struct ao2_container *index; /*!< The index of media that has requested */
struct ao2_container *media_list_cache; /*!< Cache of filenames to prevent them from being regenerated so often */
};
@@ -152,14 +155,17 @@
index->index = NULL;
ao2_cleanup(index->media_list_cache);
index->media_list_cache = NULL;
-}
-
-static struct ast_media_index *media_index_alloc(void)
+ ast_string_field_free_memory(index);
+}
+
+struct ast_media_index *ast_media_index_create(const char *base_dir)
{
RAII_VAR(struct ast_media_index *, index, ao2_alloc(sizeof(*index), media_index_dtor), ao2_cleanup);
- if (!index) {
- return NULL;
- }
+ if (!index || ast_string_field_init(index, 64)) {
+ return NULL;
+ }
+
+ ast_string_field_set(index, base_dir, base_dir);
index->index = ao2_container_alloc(INDEX_BUCKETS, media_info_hash, media_info_cmp);
if (!index->index) {
@@ -362,7 +368,6 @@
* process others if present.
*/
static int process_description_file(struct ast_media_index *index,
- const char *base_dir,
const char *subdir,
const char *variant_str,
const char *filename)
@@ -383,9 +388,9 @@
}
if (ast_strlen_zero(subdir)) {
- ast_str_set(&description_file_path, 0, "%s/%s/%s", base_dir, variant_str, filename);
+ ast_str_set(&description_file_path, 0, "%s/%s/%s", index->base_dir, variant_str, filename);
} else {
- ast_str_set(&description_file_path, 0, "%s/%s/%s/%s", base_dir, variant_str, subdir, filename);
+ ast_str_set(&description_file_path, 0, "%s/%s/%s/%s", index->base_dir, variant_str, subdir, filename);
}
f = fopen(ast_str_buffer(description_file_path), "r");
if (!f) {
@@ -477,7 +482,7 @@
}
/*! \brief process an individual file listing */
-static int process_file(struct ast_media_index *index, const char *base_dir, const char *variant_str, const char *subdir, const char *filename)
+static int process_file(struct ast_media_index *index, const char *variant_str, const char *subdir, const char *filename)
{
RAII_VAR(char *, filename_stripped, ast_strdup(filename), ast_free);
char *ext;
@@ -494,7 +499,7 @@
*ext++ = '\0';
if (!strcmp(ext, "txt")) {
- if (process_description_file(index, base_dir, subdir, variant_str, filename)) {
+ if (process_description_file(index, subdir, variant_str, filename)) {
return -1;
}
} else {
@@ -507,7 +512,6 @@
/*! \brief internal function for updating the index, recursive */
static int media_index_update(struct ast_media_index *index,
- const char *base_dir,
const char *variant,
const char *subdir)
{
@@ -521,7 +525,7 @@
return 0;
}
- ast_str_set(&index_dir, 0, "%s", base_dir);
+ ast_str_set(&index_dir, 0, "%s", index->base_dir);
if (!ast_strlen_zero(variant)) {
ast_str_append(&index_dir, 0, "/%s", variant);
}
@@ -553,11 +557,11 @@
if (S_ISDIR(st.st_mode)) {
if (ast_strlen_zero(subdir)) {
- res = media_index_update(index, base_dir, variant, dent->d_name);
+ res = media_index_update(index, 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);
- res = media_index_update(index, base_dir, variant, ast_str_buffer(new_subdir));
+ res = media_index_update(index, variant, ast_str_buffer(new_subdir));
}
if (res) {
@@ -570,7 +574,7 @@
continue;
}
- if (process_file(index, base_dir, variant, subdir, dent->d_name)) {
+ if (process_file(index, variant, subdir, dent->d_name)) {
res = -1;
break;
}
@@ -581,13 +585,8 @@
}
int ast_media_index_update(struct ast_media_index *index,
- const char *base_dir,
const char *variant)
{
- return media_index_update(index, base_dir, variant, NULL);
-}
-
-struct ast_media_index *ast_media_index_create(void)
-{
- return media_index_alloc();
-}
+ return media_index_update(index, variant, NULL);
+}
+
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=390391&r1=390390&r2=390391
==============================================================================
--- team/kmoore/stasis-http_sounds/main/sounds_index.c (original)
+++ team/kmoore/stasis-http_sounds/main/sounds_index.c Tue Jun 4 08:37:19 2013
@@ -101,15 +101,8 @@
{
char *lang = obj;
struct ast_media_index *index = arg;
- RAII_VAR(struct ast_str *, sounds_lang_dir, ast_str_create(64), ast_free);
-
- if (!sounds_lang_dir) {
- return CMP_STOP;
- }
-
- ast_str_set(&sounds_lang_dir, 0, "%s/sounds", ast_config_AST_DATA_DIR);
-
- if (ast_media_index_update(index, ast_str_buffer(sounds_lang_dir), lang)) {
+
+ if (ast_media_index_update(index, lang)) {
return CMP_STOP;
}
return 0;
@@ -119,12 +112,14 @@
{
RAII_VAR(struct ao2_container *, languages, get_languages(), ao2_cleanup);
struct ast_media_index *new_index, *old_index = sounds_index;
-
- if (!languages) {
- return -1;
- }
-
- new_index = ast_media_index_create();
+ RAII_VAR(struct ast_str *, sounds_dir, ast_str_create(64), ast_free);
+
+ if (!languages || !sounds_dir) {
+ return -1;
+ }
+
+ ast_str_set(&sounds_dir, 0, "%s/sounds", ast_config_AST_DATA_DIR);
+ new_index = ast_media_index_create(ast_str_buffer(sounds_dir));
if (!new_index) {
return -1;
}
More information about the asterisk-commits
mailing list