<p>Pascal Cadotte Michaud has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10314">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_stasis: Allow the user to specify the app of a bridge<br><br>When creating a bridge using the ARI your application will not subscribe to the<br>created bridge until a first call enters that bridge.<br><br>On the POST to /bridges or /bridges/{bridgeId} the app parameter allow the<br>user to specify the stasis application name and have the application registered<br>to that bridge from the moment of its creation.<br><br>ASTERISK-28082<br><br>Change-Id: Ie3714ef42a4c2e1d95196cecdbc001c0dbff19e3<br>---<br>M include/asterisk/stasis_app.h<br>M res/ari/resource_bridges.c<br>M res/ari/resource_bridges.h<br>M res/res_ari_bridges.c<br>M res/res_stasis.c<br>M rest-api/api-docs/bridges.json<br>6 files changed, 82 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/14/10314/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/stasis_app.h b/include/asterisk/stasis_app.h</span><br><span>index ca5c251..745ac7d 100644</span><br><span>--- a/include/asterisk/stasis_app.h</span><br><span>+++ b/include/asterisk/stasis_app.h</span><br><span>@@ -335,6 +335,21 @@</span><br><span> enum stasis_app_subscribe_res stasis_app_subscribe_channel(const char *app_name,</span><br><span> struct ast_channel *chan);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Directly subscribe an application to a bridge</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param app_name Name of the application to subscribe.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param bridge The bridge to subscribe to</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return \ref stasis_app_subscribe_res return code.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note This method can be used when you already hold a bridge and its</span><br><span style="color: hsl(120, 100%, 40%);">+ * lock. This bypasses the channel lookup that would normally be</span><br><span style="color: hsl(120, 100%, 40%);">+ * performed by \ref stasis_app_subscribe.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+enum stasis_app_subscribe_res stasis_app_subscribe_bridge(const char *app_name,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_bridge *bridge);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! @} */</span><br><span> </span><br><span> /*! @{ */</span><br><span>diff --git a/res/ari/resource_bridges.c b/res/ari/resource_bridges.c</span><br><span>index 019cdea..0ee379b 100644</span><br><span>--- a/res/ari/resource_bridges.c</span><br><span>+++ b/res/ari/resource_bridges.c</span><br><span>@@ -938,6 +938,10 @@</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(args->app)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ stasis_app_subscribe_bridge(args->app, bridge);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ast_bridge_lock(bridge);</span><br><span> snapshot = ast_bridge_snapshot_create(bridge);</span><br><span> ast_bridge_unlock(bridge);</span><br><span>@@ -988,6 +992,10 @@</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(args->app)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ stasis_app_subscribe_bridge(args->app, bridge);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ast_bridge_lock(bridge);</span><br><span> snapshot = ast_bridge_snapshot_create(bridge);</span><br><span> ast_bridge_unlock(bridge);</span><br><span>diff --git a/res/ari/resource_bridges.h b/res/ari/resource_bridges.h</span><br><span>index a3b6430..3d1deb2 100644</span><br><span>--- a/res/ari/resource_bridges.h</span><br><span>+++ b/res/ari/resource_bridges.h</span><br><span>@@ -58,6 +58,8 @@</span><br><span> const char *bridge_id;</span><br><span> /*! Name to give to the bridge being created. */</span><br><span> const char *name;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! The application that is subscribed to the bridge. */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *app;</span><br><span> };</span><br><span> /*!</span><br><span> * \brief Body parsing function for /bridges.</span><br><span>@@ -88,6 +90,8 @@</span><br><span> const char *bridge_id;</span><br><span> /*! Set the name of the bridge. */</span><br><span> const char *name;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! The application that is subscribed to the bridge. */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *app;</span><br><span> };</span><br><span> /*!</span><br><span> * \brief Body parsing function for /bridges/{bridgeId}.</span><br><span>diff --git a/res/res_ari_bridges.c b/res/res_ari_bridges.c</span><br><span>index b761bed..5036505 100644</span><br><span>--- a/res/res_ari_bridges.c</span><br><span>+++ b/res/res_ari_bridges.c</span><br><span>@@ -118,6 +118,10 @@</span><br><span> if (field) {</span><br><span> args->name = ast_json_string_get(field);</span><br><span> }</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> return 0;</span><br><span> }</span><br><span> </span><br><span>@@ -150,6 +154,9 @@</span><br><span> if (strcmp(i->name, "name") == 0) {</span><br><span> args.name = (i->value);</span><br><span> } 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> {}</span><br><span> }</span><br><span> if (ast_ari_bridges_create_parse_body(body, &args)) {</span><br><span>@@ -202,6 +209,10 @@</span><br><span> if (field) {</span><br><span> args->name = ast_json_string_get(field);</span><br><span> }</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> return 0;</span><br><span> }</span><br><span> </span><br><span>@@ -231,6 +242,9 @@</span><br><span> if (strcmp(i->name, "name") == 0) {</span><br><span> args.name = (i->value);</span><br><span> } 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> {}</span><br><span> }</span><br><span> for (i = path_vars; i; i = i->next) {</span><br><span>diff --git a/res/res_stasis.c b/res/res_stasis.c</span><br><span>index a60ec5f..7573f2c 100644</span><br><span>--- a/res/res_stasis.c</span><br><span>+++ b/res/res_stasis.c</span><br><span>@@ -1850,6 +1850,31 @@</span><br><span> }</span><br><span> </span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+enum stasis_app_subscribe_res stasis_app_subscribe_bridge(const char *app_name,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_bridge *bridge)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct stasis_app *app = find_app_by_name(app_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ int res;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!app) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return STASIS_ASR_APP_NOT_FOUND;</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%);">+ ast_debug(3, "%s: Subscribing to %s\n", app_name, bridge->uniqueid);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ res = app_subscribe_bridge(app, bridge);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(app, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (res != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Error subscribing app '%s' to bridge '%s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ app_name, bridge->uniqueid);</span><br><span style="color: hsl(120, 100%, 40%);">+ return STASIS_ASR_INTERNAL_ERROR;</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%);">+ return STASIS_ASR_OK;</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> * \internal</span><br><span> * \brief Subscribe an app to an event source.</span><br><span>diff --git a/rest-api/api-docs/bridges.json b/rest-api/api-docs/bridges.json</span><br><span>index 877fdf8..1a7e6d6 100644</span><br><span>--- a/rest-api/api-docs/bridges.json</span><br><span>+++ b/rest-api/api-docs/bridges.json</span><br><span>@@ -47,6 +47,14 @@</span><br><span> "required": false,</span><br><span> "allowMultiple": false,</span><br><span> "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": "The application that is subscribed to the bridge.",</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> }</span><br><span> ]</span><br><span> }</span><br><span>@@ -86,6 +94,14 @@</span><br><span> "required": false,</span><br><span> "allowMultiple": false,</span><br><span> "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": "The application that is subscribed to the bridge.",</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> }</span><br><span> ]</span><br><span> },</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10314">change 10314</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/10314"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ie3714ef42a4c2e1d95196cecdbc001c0dbff19e3 </div>
<div style="display:none"> Gerrit-Change-Number: 10314 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Pascal Cadotte Michaud <pcm@wazo.io> </div>