<p>Benjamin Keith Ford has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10938">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_stasis: Auto-create context and extens on Stasis app launch.<br><br>At AstriCon, there was a strong desire for the ability to completely<br>bypass dialplan when using ARI. This is possible through the automatic<br>creation of a context and a couple of extensions whenever an application<br>is started.<br><br>For example, if you have an application named 'ari-example', a context<br>named 'stasis-ari-example' will be automatically created whenever this<br>application is started. Two extensions (a match-all extension for Stasis<br>and a 'h' extension) are created within this context. Any endpoint that<br>registers to Asterisk within this context will send all calls to the<br>corresponding Stasis application. When the application is destroyed, the<br>context is removed.<br><br>ASTERISK-28104 #close<br><br>Change-Id: Ie35bd93075e05b05e3ae129a83c9426931b7ebac<br>---<br>M CHANGES<br>M res/stasis/app.c<br>2 files changed, 33 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/38/10938/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/CHANGES b/CHANGES</span><br><span>index da58f29..f405e61 100644</span><br><span>--- a/CHANGES</span><br><span>+++ b/CHANGES</span><br><span>@@ -12,6 +12,14 @@</span><br><span> --- Functionality changes from Asterisk 13.24.0 to Asterisk 13.25.0 ----------</span><br><span> ------------------------------------------------------------------------------</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ARI</span><br><span style="color: hsl(120, 100%, 40%);">+------------------</span><br><span style="color: hsl(120, 100%, 40%);">+ * Whenever an ARI application is started, a context will be created for it</span><br><span style="color: hsl(120, 100%, 40%);">+ automatically, following the format 'stasis-<app_name>'. Two extensions</span><br><span style="color: hsl(120, 100%, 40%);">+ are also added to this context: a match-all extension, and the 'h'</span><br><span style="color: hsl(120, 100%, 40%);">+ extension. Any phone that registers under this context will place all calls</span><br><span style="color: hsl(120, 100%, 40%);">+ to the corresponding Stasis application.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> res_pjsip</span><br><span> ------------------</span><br><span> * Added "send_contact_status_on_update_registration" global configuration option</span><br><span>diff --git a/res/stasis/app.c b/res/stasis/app.c</span><br><span>index ccb93bc..887e8f1 100644</span><br><span>--- a/res/stasis/app.c</span><br><span>+++ b/res/stasis/app.c</span><br><span>@@ -299,6 +299,8 @@</span><br><span> static void app_dtor(void *obj)</span><br><span> {</span><br><span> struct stasis_app *app = obj;</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t size = strlen("stasis-") + strlen(app->name) + 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ char context_name[size];</span><br><span> </span><br><span> ast_verb(1, "Destroying Stasis app %s\n", app->name);</span><br><span> </span><br><span>@@ -306,6 +308,11 @@</span><br><span> ast_assert(app->bridge_router == NULL);</span><br><span> ast_assert(app->endpoint_router == NULL);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* If we created a context for this application, remove it */</span><br><span style="color: hsl(120, 100%, 40%);">+ strcpy(context_name, "stasis-");</span><br><span style="color: hsl(120, 100%, 40%);">+ strcat(context_name, app->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_context_destroy_by_name(context_name, "res_stasis");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ao2_cleanup(app->topic);</span><br><span> app->topic = NULL;</span><br><span> ao2_cleanup(app->forwards);</span><br><span>@@ -934,6 +941,8 @@</span><br><span> RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);</span><br><span> size_t size;</span><br><span> int res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t context_size = strlen("stasis-") + strlen(name) + 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ char context_name[context_size];</span><br><span> </span><br><span> ast_assert(name != NULL);</span><br><span> ast_assert(handler != NULL);</span><br><span>@@ -1009,6 +1018,22 @@</span><br><span> app->handler = handler;</span><br><span> app->data = ao2_bump(data);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Create a context, a match-all extension, and a 'h' extension for this application. Note that</span><br><span style="color: hsl(120, 100%, 40%);">+ * this should only be done if a context does not already exist. */</span><br><span style="color: hsl(120, 100%, 40%);">+ strcpy(context_name, "stasis-");</span><br><span style="color: hsl(120, 100%, 40%);">+ strcat(context_name, name);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_context_find(context_name)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_context_find_or_create(NULL, NULL, context_name, "res_stasis")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Could not create context '%s' for Stasis application '%s'\n", context_name, name);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_add_extension(context_name, 0, "_.", 1, NULL, NULL, "Stasis", ast_strdup(name), ast_free_ptr, "res_stasis");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_add_extension(context_name, 0, "h", 1, NULL, NULL, "NoOp", NULL, NULL, "res_stasis");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Not creating context '%s' for Stasis application '%s' because it already exists\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ context_name, name);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ao2_ref(app, +1);</span><br><span> return app;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10938">change 10938</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/10938"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ie35bd93075e05b05e3ae129a83c9426931b7ebac </div>
<div style="display:none"> Gerrit-Change-Number: 10938 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.com> </div>