[asterisk-commits] kmoore: branch kmoore/stasis-http_sounds r387415 - in /team/kmoore/stasis-htt...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu May 2 09:33:53 CDT 2013
Author: kmoore
Date: Thu May 2 09:33:51 2013
New Revision: 387415
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387415
Log:
Fix bugs to get things working
Properly handle the last entry in a sound description file
Strip leading whitespace from descriptions
Add the ability to defer URI decode in Asterisk's HTTP server to prevent premature decoding when necessary
A lack of a description for a sound is fine, but don't try to encode NULL as a string into a JSON blob
Remove an unnecessary ast_json_unref
Modified:
team/kmoore/stasis-http_sounds/include/asterisk/http.h
team/kmoore/stasis-http_sounds/main/file.c
team/kmoore/stasis-http_sounds/main/http.c
team/kmoore/stasis-http_sounds/res/res_stasis_http.c
team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c
Modified: team/kmoore/stasis-http_sounds/include/asterisk/http.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/include/asterisk/http.h?view=diff&rev=387415&r1=387414&r2=387415
==============================================================================
--- team/kmoore/stasis-http_sounds/include/asterisk/http.h (original)
+++ team/kmoore/stasis-http_sounds/include/asterisk/http.h Thu May 2 09:33:51 2013
@@ -101,6 +101,8 @@
unsigned int mallocd:1;
/*! Data structure is malloc'd */
unsigned int dmallocd:1;
+ /*! Don't automatically decode URI before passing it to the callback */
+ unsigned int no_decode_uri:1;
/*! Data to bind to the uri if needed */
void *data;
/*! Key to be used for unlinking if multiple URIs registered */
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=387415&r1=387414&r2=387415
==============================================================================
--- team/kmoore/stasis-http_sounds/main/file.c (original)
+++ team/kmoore/stasis-http_sounds/main/file.c Thu May 2 09:33:51 2013
@@ -2008,8 +2008,21 @@
}
file_id_persist = strdup(file_identifier);
+ description = ast_skip_blanks(description);
ast_str_set(&cumulative_description, 0, "%s", description);
}
+ }
+
+ /* handle the last one */
+ if (file_id_persist && !ast_strlen_zero(ast_str_buffer(cumulative_description))) {
+ variant = get_variant(file_id_persist, lang);
+ if (!variant) {
+ res = -1;
+ break;
+ }
+
+ ast_string_field_set(variant, description, ast_str_buffer(cumulative_description));
+ ast_free(file_id_persist);
}
fclose(f);
Modified: team/kmoore/stasis-http_sounds/main/http.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/main/http.c?view=diff&rev=387415&r1=387414&r2=387415
==============================================================================
--- team/kmoore/stasis-http_sounds/main/http.c (original)
+++ team/kmoore/stasis-http_sounds/main/http.c Thu May 2 09:33:51 2013
@@ -718,7 +718,6 @@
}
}
}
- ast_uri_decode(uri, ast_uri_http_legacy);
AST_RWLIST_RDLOCK(&uri_redirects);
AST_RWLIST_TRAVERSE(&uri_redirects, redirect, entry) {
@@ -760,6 +759,9 @@
AST_RWLIST_UNLOCK(&uris);
}
if (urih) {
+ if (!urih->no_decode_uri) {
+ ast_uri_decode(uri, ast_uri_http_legacy);
+ }
res = urih->callback(ser, urih, uri, method, get_vars, headers);
} else {
ast_http_error(ser, 404, "Not Found", "The requested URL was not found on this server.");
Modified: team/kmoore/stasis-http_sounds/res/res_stasis_http.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/res/res_stasis_http.c?view=diff&rev=387415&r1=387414&r2=387415
==============================================================================
--- team/kmoore/stasis-http_sounds/res/res_stasis_http.c (original)
+++ team/kmoore/stasis-http_sounds/res/res_stasis_http.c Thu May 2 09:33:51 2013
@@ -498,7 +498,7 @@
struct stasis_rest_handlers *handler;
struct ast_variable *path_vars = NULL;
char *path = ast_strdupa(uri);
- const char *path_segment;
+ char *path_segment;
stasis_rest_callback callback;
root = handler = get_root_handler();
@@ -507,6 +507,7 @@
while ((path_segment = strsep(&path, "/")) && (strlen(path_segment) > 0)) {
struct stasis_rest_handlers *found_handler = NULL;
int i;
+ ast_uri_decode(path_segment, ast_uri_http_legacy);
ast_debug(3, "Finding handler for %s\n", path_segment);
for (i = 0; found_handler == NULL && i < handler->num_children; ++i) {
struct stasis_rest_handlers *child = handler->children[i];
@@ -855,6 +856,7 @@
.has_subtree = 1,
.data = NULL,
.key = __FILE__,
+ .no_decode_uri = 1,
};
static int load_module(void)
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=387415&r1=387414&r2=387415
==============================================================================
--- team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c (original)
+++ team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c Thu May 2 09:33:51 2013
@@ -38,13 +38,15 @@
description = ast_sounds_get_description(filename, "en");
if (!description) {
- return NULL;
+ sound = ast_json_pack("{s: s, s: []}",
+ "id", filename,
+ "formats");
+ } else {
+ sound = ast_json_pack("{s: s, s: s, s: []}",
+ "id", filename,
+ "text", description,
+ "formats");
}
-
- sound = ast_json_pack("{s: s, s: s, s: []}",
- "id", filename,
- "text", description,
- "formats");
if (!sound) {
return NULL;
}
@@ -64,7 +66,7 @@
void stasis_http_get_stored_sound(struct ast_variable *headers, struct ast_get_stored_sound_args *args, struct stasis_http_response *response)
{
- RAII_VAR(struct ast_json *, sound_blob, create_sound_blob(args->sound_id), ast_json_unref);
+ struct ast_json *sound_blob = create_sound_blob(args->sound_id);
if (sound_blob) {
stasis_http_response_ok(response, sound_blob);
return;
More information about the asterisk-commits
mailing list