From e773e3a9bbaf378d53647e4bac3ffcd61afb4ae6 Mon Sep 17 00:00:00 2001 From: Matt Jordan Date: Wed, 18 May 2016 06:19:58 -0500 Subject: ARI: Add the ability to download the media associated with a stored recording This patch adds a new feature to ARI that allows a client to download the media associated with a stored recording. The new route is /recordings/stored/{name}/file, and transmits the underlying binary file using Asterisk's HTTP server's underlying file transfer facilities. Because this REST route returns non-JSON, a few small enhancements had to be made to the Python Swagger generation code, as well as the mustache templates that generate the ARI bindings. ASTERISK-26042 #close Change-Id: I49ec5c4afdec30bb665d9c977ab423b5387e0181 --- rest-api-templates/ari_resource.h.mustache | 8 ++++++++ rest-api-templates/res_ari_resource.c.mustache | 11 +++++++++++ rest-api-templates/swagger_model.py | 3 +++ 3 files changed, 22 insertions(+) (limited to 'rest-api-templates') diff --git a/rest-api-templates/ari_resource.h.mustache b/rest-api-templates/ari_resource.h.mustache index 5e06af734..df075af35 100644 --- a/rest-api-templates/ari_resource.h.mustache +++ b/rest-api-templates/ari_resource.h.mustache @@ -82,11 +82,19 @@ int ast_ari_{{c_name}}_{{c_nickname}}_parse_body( * {{{notes}}} {{/notes}} * +{{#is_binary_response}} + * \param ser TCP/TLS session instance +{{/is_binary_response}} * \param headers HTTP headers * \param args Swagger parameters * \param[out] response HTTP response */ +{{^is_binary_response}} void ast_ari_{{c_name}}_{{c_nickname}}(struct ast_variable *headers, struct ast_ari_{{c_name}}_{{c_nickname}}_args *args, struct ast_ari_response *response); +{{/is_binary_response}} +{{#is_binary_response}} +void ast_ari_{{c_name}}_{{c_nickname}}(struct ast_tcptls_session_instance *ser, struct ast_variable *headers, struct ast_ari_{{c_name}}_{{c_nickname}}_args *args, struct ast_ari_response *response); +{{/is_binary_response}} {{/is_req}} {{#is_websocket}} diff --git a/rest-api-templates/res_ari_resource.c.mustache b/rest-api-templates/res_ari_resource.c.mustache index 23f2a52ac..c4e6f3d54 100644 --- a/rest-api-templates/res_ari_resource.c.mustache +++ b/rest-api-templates/res_ari_resource.c.mustache @@ -91,7 +91,12 @@ static void ast_ari_{{c_name}}_{{c_nickname}}_cb( #endif /* AST_DEVMODE */ {{> param_parsing}} +{{^is_binary_response}} ast_ari_{{c_name}}_{{c_nickname}}(headers, &args, response); +{{/is_binary_response}} +{{#is_binary_response}} + ast_ari_{{c_name}}_{{c_nickname}}(ser, headers, &args, response); +{{/is_binary_response}} #if defined(AST_DEVMODE) code = response->response_code; @@ -114,8 +119,14 @@ static void ast_ari_{{c_name}}_{{c_nickname}}_cb( ast_ari_validate_{{c_singular_name}}_fn()); {{/is_list}} {{^is_list}} +{{^is_binary_response}} is_valid = ast_ari_validate_{{c_name}}( response->message); +{{/is_binary_response}} +{{#is_binary_response}} + /* No validation on a raw binary response */ + is_valid = 1; +{{/is_binary_response}} {{/is_list}} {{/response_class}} } else { diff --git a/rest-api-templates/swagger_model.py b/rest-api-templates/swagger_model.py index f3b49e12e..c76cb7f28 100644 --- a/rest-api-templates/swagger_model.py +++ b/rest-api-templates/swagger_model.py @@ -332,6 +332,7 @@ class SwaggerType(Stringify): self.is_list = None self.singular_name = None self.is_primitive = None + self.is_binary = None def load(self, type_name, processor, context): # Some common errors @@ -346,6 +347,7 @@ class SwaggerType(Stringify): else: self.singular_name = self.name self.is_primitive = self.singular_name in SWAGGER_PRIMITIVES + self.is_binary = (self.singular_name == 'binary') processor.process_type(self, context) return self @@ -401,6 +403,7 @@ class Operation(Stringify): self.has_header_parameters = self.header_parameters and True self.has_parameters = self.has_query_parameters or \ self.has_path_parameters or self.has_header_parameters + self.is_binary_response = self.response_class.is_binary # Body param is different, since there's at most one self.body_parameter = [ -- cgit v1.2.3