<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12775">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">ARI: External Media<br><br>The Channel resource has a new sub-resource "externalMedia".<br>This allows an application to create a channel for the sole purpose<br>of exchanging media with an external server. Once created, this<br>channel could be placed into a bridge with existing channels to<br>allow the external server to inject audio into the bridge or<br>receive audio from the bridge.<br>See https://wiki.asterisk.org/wiki/display/AST/External+Media+and+ARI<br>for more information.<br><br>Change-Id: I9618899198880b4c650354581b50c0401b58bc46<br>---<br>A doc/CHANGES-staging/ARI.txt<br>M res/ari/resource_channels.c<br>M res/ari/resource_channels.h<br>M res/res_ari_channels.c<br>M rest-api/api-docs/channels.json<br>5 files changed, 407 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/75/12775/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/ARI.txt b/doc/CHANGES-staging/ARI.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..06ac4ab</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/ARI.txt</span><br><span>@@ -0,0 +1,10 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: ARI Channels</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The Channel resource has a new sub-resource "externalMedia".</span><br><span style="color: hsl(120, 100%, 40%);">+This allows an application to create a channel for the sole purpose</span><br><span style="color: hsl(120, 100%, 40%);">+of exchanging media with an external server. Once created, this</span><br><span style="color: hsl(120, 100%, 40%);">+channel could be placed into a bridge with existing channels to</span><br><span style="color: hsl(120, 100%, 40%);">+allow the external server to inject audio into the bridge or</span><br><span style="color: hsl(120, 100%, 40%);">+receive audio from the bridge.</span><br><span style="color: hsl(120, 100%, 40%);">+See https://wiki.asterisk.org/wiki/display/AST/External+Media+and+ARI</span><br><span style="color: hsl(120, 100%, 40%);">+for more information.</span><br><span>\ No newline at end of file</span><br><span>diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c</span><br><span>index d415224..3aea5dd 100644</span><br><span>--- a/res/ari/resource_channels.c</span><br><span>+++ b/res/ari/resource_channels.c</span><br><span>@@ -2049,3 +2049,100 @@</span><br><span> </span><br><span> return;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void external_media_rtp_udp(struct ast_ari_channels_external_media_args *args,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *variables,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_ari_response *response)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t endpoint_len;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *endpoint;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ endpoint_len = strlen("UnicastRTP/") + strlen(args->external_host) + 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ endpoint = ast_alloca(endpoint_len);</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(endpoint, endpoint_len, "UnicastRTP/%s", args->external_host);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ari_channels_handle_originate_with_id(</span><br><span style="color: hsl(120, 100%, 40%);">+ endpoint,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+ 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+ args->app,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+ 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ variables,</span><br><span style="color: hsl(120, 100%, 40%);">+ args->channel_id,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+ args->format,</span><br><span style="color: hsl(120, 100%, 40%);">+ response);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_variables_destroy(variables);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/config.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/netsock2.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void ast_ari_channels_external_media(struct ast_variable *headers,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_ari_channels_external_media_args *args, struct ast_ari_response *response)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *variables = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *external_host;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *host = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *port = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert(response != NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args->app)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_ari_response_error(response, 400, "Bad Request", "app cannot be empty");</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args->external_host)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_ari_response_error(response, 400, "Bad Request", "external_host cannot be empty");</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ external_host = ast_strdupa(args->external_host);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_sockaddr_split_hostport(external_host, &host, &port, PARSE_PORT_REQUIRE)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_ari_response_error(response, 400, "Bad Request", "external_host must be <host>:<port>");</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args->format)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_ari_response_error(response, 400, "Bad Request", "format cannot be empty");</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args->encapsulation)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->encapsulation = "rtp";</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args->transport)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->transport = "udp";</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args->connection_type)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->connection_type = "client";</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args->direction)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->direction = "both";</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (args->variables) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_json *json_variables;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_ari_channels_external_media_parse_body(args->variables, args);</span><br><span style="color: hsl(120, 100%, 40%);">+ json_variables = ast_json_object_get(args->variables, "variables");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (json_variables</span><br><span style="color: hsl(120, 100%, 40%);">+ && json_to_ast_variables(response, json_variables, &variables)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcasecmp(args->encapsulation, "rtp") == 0 && strcasecmp(args->transport, "udp") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ external_media_rtp_udp(args, variables, response);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_ari_response_error(</span><br><span style="color: hsl(120, 100%, 40%);">+ response, 501, "Not Implemented",</span><br><span style="color: hsl(120, 100%, 40%);">+ "The encapsulation and/or transport is not supported");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/res/ari/resource_channels.h b/res/ari/resource_channels.h</span><br><span>index 401c8a5..7c70cec 100644</span><br><span>--- a/res/ari/resource_channels.h</span><br><span>+++ b/res/ari/resource_channels.h</span><br><span>@@ -822,5 +822,47 @@</span><br><span> * \param[out] response HTTP response</span><br><span> */</span><br><span> void ast_ari_channels_rtpstatistics(struct ast_variable *headers, struct ast_ari_channels_rtpstatistics_args *args, struct ast_ari_response *response);</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Argument struct for ast_ari_channels_external_media() */</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_ari_channels_external_media_args {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! The unique id to assign the channel on creation. */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *channel_id;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Stasis Application to place channel into */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *app;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! The "variables" key in the body object holds variable key/value pairs to set on the channel on creation. Other keys in the body object are interpreted as query parameters. Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } } */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_json *variables;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Hostname/ip:port of external host */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *external_host;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Payload encapsulation protocol */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *encapsulation;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Transport protocol */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *transport;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Connection type (client/server) */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *connection_type;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Format to encode audio in */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *format;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! External media direction */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *direction;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Body parsing function for /channels/externalMedia.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param body The JSON body from which to parse parameters.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] args The args structure to parse into.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval zero on success</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval non-zero on failure</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_ari_channels_external_media_parse_body(</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_json *body,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_ari_channels_external_media_args *args);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Start an External Media session.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Create a channel to an External Media source/sink.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param headers HTTP headers</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param args Swagger parameters</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] response HTTP response</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void ast_ari_channels_external_media(struct ast_variable *headers, struct ast_ari_channels_external_media_args *args, struct ast_ari_response *response);</span><br><span> </span><br><span> #endif /* _ASTERISK_RESOURCE_CHANNELS_H */</span><br><span>diff --git a/res/res_ari_channels.c b/res/res_ari_channels.c</span><br><span>index 73d1e4b..bb153c9 100644</span><br><span>--- a/res/res_ari_channels.c</span><br><span>+++ b/res/res_ari_channels.c</span><br><span>@@ -2807,6 +2807,128 @@</span><br><span> fin: __attribute__((unused))</span><br><span> return;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_ari_channels_external_media_parse_body(</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_json *body,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_ari_channels_external_media_args *args)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_json *field;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Parse query parameters out of it */</span><br><span style="color: hsl(120, 100%, 40%);">+ field = ast_json_object_get(body, "channelId");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (field) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->channel_id = ast_json_string_get(field);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ field = ast_json_object_get(body, "app");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (field) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->app = ast_json_string_get(field);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ field = ast_json_object_get(body, "external_host");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (field) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->external_host = ast_json_string_get(field);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ field = ast_json_object_get(body, "encapsulation");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (field) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->encapsulation = ast_json_string_get(field);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ field = ast_json_object_get(body, "transport");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (field) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->transport = ast_json_string_get(field);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ field = ast_json_object_get(body, "connection_type");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (field) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->connection_type = ast_json_string_get(field);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ field = ast_json_object_get(body, "format");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (field) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->format = ast_json_string_get(field);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ field = ast_json_object_get(body, "direction");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (field) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->direction = ast_json_string_get(field);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Parameter parsing callback for /channels/externalMedia.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param get_params GET parameters in the HTTP request.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param path_vars Path variables extracted from the request.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param headers HTTP headers.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] response Response to the HTTP request.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static void ast_ari_channels_external_media_cb(</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_tcptls_session_instance *ser,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *get_params, struct ast_variable *path_vars,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_ari_channels_external_media_args args = {};</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *i;</span><br><span style="color: hsl(120, 100%, 40%);">+#if defined(AST_DEVMODE)</span><br><span style="color: hsl(120, 100%, 40%);">+ int is_valid;</span><br><span style="color: hsl(120, 100%, 40%);">+ int code;</span><br><span style="color: hsl(120, 100%, 40%);">+#endif /* AST_DEVMODE */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = get_params; i; i = i->next) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(i->name, "channelId") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args.channel_id = (i->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(i->name, "app") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args.app = (i->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(i->name, "external_host") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args.external_host = (i->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(i->name, "encapsulation") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args.encapsulation = (i->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(i->name, "transport") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args.transport = (i->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(i->name, "connection_type") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args.connection_type = (i->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(i->name, "format") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args.format = (i->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(i->name, "direction") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args.direction = (i->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else</span><br><span style="color: hsl(120, 100%, 40%);">+ {}</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ args.variables = body;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_ari_channels_external_media(headers, &args, response);</span><br><span style="color: hsl(120, 100%, 40%);">+#if defined(AST_DEVMODE)</span><br><span style="color: hsl(120, 100%, 40%);">+ code = response->response_code;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (code) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case 0: /* Implementation is still a stub, or the code wasn't set */</span><br><span style="color: hsl(120, 100%, 40%);">+ is_valid = response->message == NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case 500: /* Internal Server Error */</span><br><span style="color: hsl(120, 100%, 40%);">+ case 501: /* Not Implemented */</span><br><span style="color: hsl(120, 100%, 40%);">+ case 400: /* Invalid parameters */</span><br><span style="color: hsl(120, 100%, 40%);">+ case 409: /* Channel is not in a Stasis application; Channel is already bridged */</span><br><span style="color: hsl(120, 100%, 40%);">+ is_valid = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ default:</span><br><span style="color: hsl(120, 100%, 40%);">+ if (200 <= code && code <= 299) {</span><br><span style="color: hsl(120, 100%, 40%);">+ is_valid = ast_ari_validate_channel(</span><br><span style="color: hsl(120, 100%, 40%);">+ response->message);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Invalid error response %d for /channels/externalMedia\n", code);</span><br><span style="color: hsl(120, 100%, 40%);">+ is_valid = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!is_valid) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Response validation failed for /channels/externalMedia\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_ari_response_error(response, 500,</span><br><span style="color: hsl(120, 100%, 40%);">+ "Internal Server Error", "Response validation failed");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+#endif /* AST_DEVMODE */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+fin: __attribute__((unused))</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span> </span><br><span> /*! \brief REST handler for /api-docs/channels.json */</span><br><span> static struct stasis_rest_handlers channels_create = {</span><br><span>@@ -3000,14 +3122,23 @@</span><br><span> .children = { &channels_channelId_continue,&channels_channelId_move,&channels_channelId_redirect,&channels_channelId_answer,&channels_channelId_ring,&channels_channelId_dtmf,&channels_channelId_mute,&channels_channelId_hold,&channels_channelId_moh,&channels_channelId_silence,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable,&channels_channelId_snoop,&channels_channelId_dial,&channels_channelId_rtp_statistics, }</span><br><span> };</span><br><span> /*! \brief REST handler for /api-docs/channels.json */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct stasis_rest_handlers channels_externalMedia = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .path_segment = "externalMedia",</span><br><span style="color: hsl(120, 100%, 40%);">+ .callbacks = {</span><br><span style="color: hsl(120, 100%, 40%);">+ [AST_HTTP_POST] = ast_ari_channels_external_media_cb,</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ .num_children = 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ .children = { }</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief REST handler for /api-docs/channels.json */</span><br><span> static struct stasis_rest_handlers channels = {</span><br><span> .path_segment = "channels",</span><br><span> .callbacks = {</span><br><span> [AST_HTTP_GET] = ast_ari_channels_list_cb,</span><br><span> [AST_HTTP_POST] = ast_ari_channels_originate_cb,</span><br><span> },</span><br><span style="color: hsl(0, 100%, 40%);">- .num_children = 2,</span><br><span style="color: hsl(0, 100%, 40%);">- .children = { &channels_create,&channels_channelId, }</span><br><span style="color: hsl(120, 100%, 40%);">+ .num_children = 3,</span><br><span style="color: hsl(120, 100%, 40%);">+ .children = { &channels_create,&channels_channelId,&channels_externalMedia, }</span><br><span> };</span><br><span> </span><br><span> static int unload_module(void)</span><br><span>diff --git a/rest-api/api-docs/channels.json b/rest-api/api-docs/channels.json</span><br><span>index 4ea5f56..366fec8 100644</span><br><span>--- a/rest-api/api-docs/channels.json</span><br><span>+++ b/rest-api/api-docs/channels.json</span><br><span>@@ -1748,6 +1748,131 @@</span><br><span> ]</span><br><span> }</span><br><span> ]</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "path": "/channels/externalMedia",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "Create a channel to an External Media source/sink.",</span><br><span style="color: hsl(120, 100%, 40%);">+ "operations": [</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "httpMethod": "POST",</span><br><span style="color: hsl(120, 100%, 40%);">+ "summary": "Start an External Media session.",</span><br><span style="color: hsl(120, 100%, 40%);">+ "notes": "Create a channel to an External Media source/sink.",</span><br><span style="color: hsl(120, 100%, 40%);">+ "nickname": "externalMedia",</span><br><span style="color: hsl(120, 100%, 40%);">+ "responseClass": "Channel",</span><br><span style="color: hsl(120, 100%, 40%);">+ "parameters": [</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "name": "channelId",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "The unique id to assign the channel on creation.",</span><br><span style="color: hsl(120, 100%, 40%);">+ "paramType": "query",</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowMultiple": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "dataType": "string"</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "name": "app",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "Stasis Application to place channel into",</span><br><span style="color: hsl(120, 100%, 40%);">+ "paramType": "query",</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": true,</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowMultiple": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "dataType": "string"</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "name": "variables",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "The \"variables\" key in the body object holds variable key/value pairs to set on the channel on creation. Other keys in the body object are interpreted as query parameters. Ex. { \"endpoint\": \"SIP/Alice\", \"variables\": { \"CALLERID(name)\": \"Alice\" } }",</span><br><span style="color: hsl(120, 100%, 40%);">+ "paramType": "body",</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "dataType": "containers",</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowMultiple": false</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "name": "external_host",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "Hostname/ip:port of external host",</span><br><span style="color: hsl(120, 100%, 40%);">+ "paramType": "query",</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": true,</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowMultiple": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "dataType": "string"</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "name": "encapsulation",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "Payload encapsulation protocol",</span><br><span style="color: hsl(120, 100%, 40%);">+ "paramType": "query",</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowMultiple": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "dataType": "string",</span><br><span style="color: hsl(120, 100%, 40%);">+ "defaultValue": "rtp",</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowableValues": {</span><br><span style="color: hsl(120, 100%, 40%);">+ "valueType": "LIST",</span><br><span style="color: hsl(120, 100%, 40%);">+ "values": [</span><br><span style="color: hsl(120, 100%, 40%);">+ "rtp"</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "name": "transport",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "Transport protocol",</span><br><span style="color: hsl(120, 100%, 40%);">+ "paramType": "query",</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowMultiple": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "dataType": "string",</span><br><span style="color: hsl(120, 100%, 40%);">+ "defaultValue": "udp",</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowableValues": {</span><br><span style="color: hsl(120, 100%, 40%);">+ "valueType": "LIST",</span><br><span style="color: hsl(120, 100%, 40%);">+ "values": [</span><br><span style="color: hsl(120, 100%, 40%);">+ "udp"</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "name": "connection_type",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "Connection type (client/server)",</span><br><span style="color: hsl(120, 100%, 40%);">+ "paramType": "query",</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowMultiple": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "dataType": "string",</span><br><span style="color: hsl(120, 100%, 40%);">+ "defaultValue": "client",</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowableValues": {</span><br><span style="color: hsl(120, 100%, 40%);">+ "valueType": "LIST",</span><br><span style="color: hsl(120, 100%, 40%);">+ "values": [</span><br><span style="color: hsl(120, 100%, 40%);">+ "client"</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "name": "format",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "Format to encode audio in",</span><br><span style="color: hsl(120, 100%, 40%);">+ "paramType": "query",</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": true,</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowMultiple": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "dataType": "string"</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "name": "direction",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "External media direction",</span><br><span style="color: hsl(120, 100%, 40%);">+ "paramType": "query",</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowMultiple": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "dataType": "string",</span><br><span style="color: hsl(120, 100%, 40%);">+ "defaultValue": "both",</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowableValues": {</span><br><span style="color: hsl(120, 100%, 40%);">+ "valueType": "LIST",</span><br><span style="color: hsl(120, 100%, 40%);">+ "values": [</span><br><span style="color: hsl(120, 100%, 40%);">+ "both"</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ "errorResponses": [</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "code": 400,</span><br><span style="color: hsl(120, 100%, 40%);">+ "reason": "Invalid parameters"</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "code": 409,</span><br><span style="color: hsl(120, 100%, 40%);">+ "reason": "Channel is not in a Stasis application; Channel is already bridged"</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span> }</span><br><span> ],</span><br><span> "models": {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/12775">change 12775</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/12775"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I9618899198880b4c650354581b50c0401b58bc46 </div>
<div style="display:none"> Gerrit-Change-Number: 12775 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>