[Asterisk-code-review] res stasis: Auto-create context and extens on Stasis app lau... (asterisk[13])
George Joseph
asteriskteam at digium.com
Tue Feb 5 08:26:56 CST 2019
George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/10938 )
Change subject: res_stasis: Auto-create context and extens on Stasis app launch.
......................................................................
res_stasis: Auto-create context and extens on Stasis app launch.
At AstriCon, there was a strong desire for the ability to completely
bypass dialplan when using ARI. This is possible through the automatic
creation of a context and a couple of extensions whenever an application
is started.
For example, if you have an application named 'ari-example', a context
named 'stasis-ari-example' will be automatically created whenever this
application is started as long as one does not already exist. Two
extensions (a match-all extension for Stasis and a 'h' extension) are
created within this context. Any endpoint that registers to Asterisk
within this context will send all calls to the corresponding Stasis
application. When the application is destroyed, the context is removed.
ASTERISK-28104 #close
Change-Id: Ie35bd93075e05b05e3ae129a83c9426931b7ebac
---
M CHANGES
M res/stasis/app.c
2 files changed, 33 insertions(+), 0 deletions(-)
Approvals:
Joshua C. Colp: Looks good to me, but someone else must approve
Corey Farrell: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
diff --git a/CHANGES b/CHANGES
index da58f29..1c79b81 100644
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,14 @@
--- Functionality changes from Asterisk 13.24.0 to Asterisk 13.25.0 ----------
------------------------------------------------------------------------------
+ARI
+------------------
+ * Whenever an ARI application is started, a context will be created for it
+ automatically as long as one does not already exist, following the format
+ 'stasis-<app_name>'. Two extensions are also added to this context: a match-all
+ extension, and the 'h' extension. Any phone that registers under this context
+ will place all calls to the corresponding Stasis application.
+
res_pjsip
------------------
* Added "send_contact_status_on_update_registration" global configuration option
diff --git a/res/stasis/app.c b/res/stasis/app.c
index ccb93bc..887e8f1 100644
--- a/res/stasis/app.c
+++ b/res/stasis/app.c
@@ -299,6 +299,8 @@
static void app_dtor(void *obj)
{
struct stasis_app *app = obj;
+ size_t size = strlen("stasis-") + strlen(app->name) + 1;
+ char context_name[size];
ast_verb(1, "Destroying Stasis app %s\n", app->name);
@@ -306,6 +308,11 @@
ast_assert(app->bridge_router == NULL);
ast_assert(app->endpoint_router == NULL);
+ /* If we created a context for this application, remove it */
+ strcpy(context_name, "stasis-");
+ strcat(context_name, app->name);
+ ast_context_destroy_by_name(context_name, "res_stasis");
+
ao2_cleanup(app->topic);
app->topic = NULL;
ao2_cleanup(app->forwards);
@@ -934,6 +941,8 @@
RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
size_t size;
int res = 0;
+ size_t context_size = strlen("stasis-") + strlen(name) + 1;
+ char context_name[context_size];
ast_assert(name != NULL);
ast_assert(handler != NULL);
@@ -1009,6 +1018,22 @@
app->handler = handler;
app->data = ao2_bump(data);
+ /* Create a context, a match-all extension, and a 'h' extension for this application. Note that
+ * this should only be done if a context does not already exist. */
+ strcpy(context_name, "stasis-");
+ strcat(context_name, name);
+ if (!ast_context_find(context_name)) {
+ if (!ast_context_find_or_create(NULL, NULL, context_name, "res_stasis")) {
+ ast_log(LOG_WARNING, "Could not create context '%s' for Stasis application '%s'\n", context_name, name);
+ } else {
+ ast_add_extension(context_name, 0, "_.", 1, NULL, NULL, "Stasis", ast_strdup(name), ast_free_ptr, "res_stasis");
+ ast_add_extension(context_name, 0, "h", 1, NULL, NULL, "NoOp", NULL, NULL, "res_stasis");
+ }
+ } else {
+ ast_log(LOG_WARNING, "Not creating context '%s' for Stasis application '%s' because it already exists\n",
+ context_name, name);
+ }
+
ao2_ref(app, +1);
return app;
}
--
To view, visit https://gerrit.asterisk.org/10938
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie35bd93075e05b05e3ae129a83c9426931b7ebac
Gerrit-Change-Number: 10938
Gerrit-PatchSet: 2
Gerrit-Owner: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Friendly Automation (1000185)
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua C. Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190205/2041d693/attachment-0001.html>
More information about the asterisk-code-review
mailing list