[asterisk-commits] kmoore: branch kmoore/stasis-http_sounds r387773 - /team/kmoore/stasis-http_s...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon May 6 13:55:39 CDT 2013
Author: kmoore
Date: Mon May 6 13:55:36 2013
New Revision: 387773
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387773
Log:
Enable language filtering for stasis/sounds
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=387773&r1=387772&r2=387773
==============================================================================
--- 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 13:55:36 2013
@@ -57,7 +57,17 @@
return 0;
}
-static struct ast_json *create_sound_blob(const char *filename)
+static int filter_langs_cb(void *obj, void *arg, int flags)
+{
+ char *lang_filter = arg;
+ char *lang = obj;
+ if (strcmp(lang, lang_filter)) {
+ return CMP_MATCH;
+ }
+ return 0;
+}
+
+static struct ast_json *create_sound_blob(const char *filename, struct ast_get_sounds_args *args)
{
RAII_VAR(struct ast_json *, sound, NULL, ast_json_unref);
RAII_VAR(struct ao2_container *, languages, NULL, ao2_cleanup);
@@ -90,18 +100,28 @@
return NULL;
}
+ /* filter requested languages */
+ if (args && !ast_strlen_zero(args->lang)) {
+ char *lang_filter = ast_strdupa(args->lang);
+ ao2_callback(languages, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, filter_langs_cb, lang_filter);
+ if (!languages || !ao2_container_count(languages)) {
+ return NULL;
+ }
+ }
+
filename_dup = ast_strdupa(filename);
ao2_callback_data(languages, OBJ_NODATA, add_format_information_cb, format_lang_list, filename_dup);
return ast_json_ref(sound);
}
-static int append_sound_cb(void *obj, void *arg, int flags)
+static int append_sound_cb(void *obj, void *arg, void *data, int flags)
{
struct ast_json *sounds_array = arg;
char *filename = obj;
- struct ast_json *sound_blob = create_sound_blob(filename);
+ struct ast_get_sounds_args *args = data;
+ struct ast_json *sound_blob = create_sound_blob(filename, args);
if (!sound_blob) {
- return CMP_STOP;
+ return 0;
}
ast_json_array_append(sounds_array, sound_blob);
@@ -116,14 +136,14 @@
stasis_http_response_error(response, 500, "Internal Error", "Allocation Error");
}
- ao2_callback(sound_files, OBJ_NODATA, append_sound_cb, sounds_blob);
+ ao2_callback_data(sound_files, OBJ_NODATA, append_sound_cb, sounds_blob, args);
stasis_http_response_ok(response, sounds_blob);
}
void stasis_http_get_stored_sound(struct ast_variable *headers, struct ast_get_stored_sound_args *args, struct stasis_http_response *response)
{
- struct ast_json *sound_blob = create_sound_blob(args->sound_id);
+ struct ast_json *sound_blob = create_sound_blob(args->sound_id, NULL);
if (sound_blob) {
stasis_http_response_ok(response, sound_blob);
return;
More information about the asterisk-commits
mailing list