[asterisk-commits] kmoore: branch kmoore/stasis-http_sounds r387778 - /team/kmoore/stasis-http_s...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon May 6 14:28:42 CDT 2013
Author: kmoore
Date: Mon May 6 14:28:41 2013
New Revision: 387778
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387778
Log:
Enable filtering sounds response by format
Modified:
team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c
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=387778&r1=387777&r2=387778
==============================================================================
--- team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c (original)
+++ team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c Mon May 6 14:28:41 2013
@@ -33,25 +33,38 @@
#include "asterisk/format_cap.h"
#include "asterisk/json.h"
-static int add_format_information_cb(void *obj, void *arg, void *data, int flags)
+struct lang_format_info {
+ struct ast_json *format_list;
+ const char *filename;
+ const char *format_filter;
+};
+
+static int add_format_information_cb(void *obj, void *arg, int flags)
{
char *language = obj;
- struct ast_json *format_list = arg;
- char *filename = data;
+ struct lang_format_info *args = arg;
struct ast_format format;
- RAII_VAR(struct ast_format_cap *, cap, ast_sounds_get_format_cap(filename, language), ast_format_cap_destroy);
+ RAII_VAR(struct ast_format_cap *, cap, ast_sounds_get_format_cap(args->filename, language), ast_format_cap_destroy);
ast_format_cap_iter_start(cap);
while (!ast_format_cap_iter_next(cap, &format)) {
- struct ast_json *lang_format_pair = ast_json_pack("{s: s, s: s}",
+ struct ast_json *lang_format_pair;
+ const char *format_name = ast_getformatname(&format);
+
+ if (!ast_strlen_zero(args->format_filter)
+ && strcmp(args->format_filter, format_name)) {
+ continue;
+ }
+
+ lang_format_pair = ast_json_pack("{s: s, s: s}",
"language", language,
- "format", ast_getformatname(&format));
+ "format", format_name);
if (!lang_format_pair) {
ast_format_cap_iter_end(cap);
return CMP_STOP;
}
- ast_json_array_append(format_list, lang_format_pair);
+ ast_json_array_append(args->format_list, lang_format_pair);
}
ast_format_cap_iter_end(cap);
return 0;
@@ -73,7 +86,7 @@
RAII_VAR(struct ao2_container *, languages, NULL, ao2_cleanup);
RAII_VAR(char *, description, NULL, ast_free);
struct ast_json *format_lang_list;
- char *filename_dup;
+ struct lang_format_info info;
description = ast_sounds_get_description(filename, "en");
if (ast_strlen_zero(description)) {
@@ -109,8 +122,19 @@
}
}
- filename_dup = ast_strdupa(filename);
- ao2_callback_data(languages, OBJ_NODATA, add_format_information_cb, format_lang_list, filename_dup);
+ info.filename = filename;
+ info.format_list = format_lang_list;
+ info.format_filter = NULL;
+ if (args) {
+ info.format_filter = args->format;
+ }
+ ao2_callback(languages, OBJ_NODATA, add_format_information_cb, &info);
+
+ /* no format/lang pairs for this sound so nothing to return */
+ if (!ast_json_array_size(format_lang_list)) {
+ return NULL;
+ }
+
return ast_json_ref(sound);
}
@@ -138,6 +162,11 @@
ao2_callback_data(sound_files, OBJ_NODATA, append_sound_cb, sounds_blob, args);
+ if (!ast_json_array_size(sounds_blob)) {
+ stasis_http_response_error(response, 404, "Not Found", "No sounds found that matched the query");
+ return;
+ }
+
stasis_http_response_ok(response, sounds_blob);
}
More information about the asterisk-commits
mailing list