[Asterisk-code-review] res stasis: Allow the user to specify the app of a bridge (asterisk[15])

Pascal Cadotte Michaud asteriskteam at digium.com
Fri Sep 28 07:52:40 CDT 2018


Pascal Cadotte Michaud has uploaded this change for review. ( https://gerrit.asterisk.org/10314


Change subject: res_stasis: Allow the user to specify the app of a bridge
......................................................................

res_stasis: Allow the user to specify the app of a bridge

When creating a bridge using the ARI your application will not subscribe to the
created bridge until a first call enters that bridge.

On the POST to /bridges or /bridges/{bridgeId} the app parameter allow the
user to specify the stasis application name and have the application registered
to that bridge from the moment of its creation.

ASTERISK-28082

Change-Id: Ie3714ef42a4c2e1d95196cecdbc001c0dbff19e3
---
M include/asterisk/stasis_app.h
M res/ari/resource_bridges.c
M res/ari/resource_bridges.h
M res/res_ari_bridges.c
M res/res_stasis.c
M rest-api/api-docs/bridges.json
6 files changed, 82 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/14/10314/1

diff --git a/include/asterisk/stasis_app.h b/include/asterisk/stasis_app.h
index ca5c251..745ac7d 100644
--- a/include/asterisk/stasis_app.h
+++ b/include/asterisk/stasis_app.h
@@ -335,6 +335,21 @@
 enum stasis_app_subscribe_res stasis_app_subscribe_channel(const char *app_name,
 	struct ast_channel *chan);
 
+/*!
+ * \brief Directly subscribe an application to a bridge
+ *
+ * \param app_name Name of the application to subscribe.
+ * \param bridge The bridge to subscribe to
+ *
+ * \return \ref stasis_app_subscribe_res return code.
+ *
+ * \note This method can be used when you already hold a bridge and its
+ *       lock. This bypasses the channel lookup that would normally be
+ *       performed by \ref stasis_app_subscribe.
+ */
+enum stasis_app_subscribe_res stasis_app_subscribe_bridge(const char *app_name,
+	struct ast_bridge *bridge);
+
 /*! @} */
 
 /*! @{ */
diff --git a/res/ari/resource_bridges.c b/res/ari/resource_bridges.c
index 019cdea..0ee379b 100644
--- a/res/ari/resource_bridges.c
+++ b/res/ari/resource_bridges.c
@@ -938,6 +938,10 @@
 		return;
 	}
 
+	if (!ast_strlen_zero(args->app)) {
+		stasis_app_subscribe_bridge(args->app, bridge);
+	}
+
 	ast_bridge_lock(bridge);
 	snapshot = ast_bridge_snapshot_create(bridge);
 	ast_bridge_unlock(bridge);
@@ -988,6 +992,10 @@
 		return;
 	}
 
+	if (!ast_strlen_zero(args->app)) {
+		stasis_app_subscribe_bridge(args->app, bridge);
+	}
+
 	ast_bridge_lock(bridge);
 	snapshot = ast_bridge_snapshot_create(bridge);
 	ast_bridge_unlock(bridge);
diff --git a/res/ari/resource_bridges.h b/res/ari/resource_bridges.h
index a3b6430..3d1deb2 100644
--- a/res/ari/resource_bridges.h
+++ b/res/ari/resource_bridges.h
@@ -58,6 +58,8 @@
 	const char *bridge_id;
 	/*! Name to give to the bridge being created. */
 	const char *name;
+	/*! The application that is subscribed to the bridge. */
+	const char *app;
 };
 /*!
  * \brief Body parsing function for /bridges.
@@ -88,6 +90,8 @@
 	const char *bridge_id;
 	/*! Set the name of the bridge. */
 	const char *name;
+	/*! The application that is subscribed to the bridge. */
+	const char *app;
 };
 /*!
  * \brief Body parsing function for /bridges/{bridgeId}.
diff --git a/res/res_ari_bridges.c b/res/res_ari_bridges.c
index b761bed..5036505 100644
--- a/res/res_ari_bridges.c
+++ b/res/res_ari_bridges.c
@@ -118,6 +118,10 @@
 	if (field) {
 		args->name = ast_json_string_get(field);
 	}
+	field = ast_json_object_get(body, "app");
+	if (field) {
+		args->app = ast_json_string_get(field);
+	}
 	return 0;
 }
 
@@ -150,6 +154,9 @@
 		if (strcmp(i->name, "name") == 0) {
 			args.name = (i->value);
 		} else
+		if (strcmp(i->name, "app") == 0) {
+			args.app = (i->value);
+		} else
 		{}
 	}
 	if (ast_ari_bridges_create_parse_body(body, &args)) {
@@ -202,6 +209,10 @@
 	if (field) {
 		args->name = ast_json_string_get(field);
 	}
+	field = ast_json_object_get(body, "app");
+	if (field) {
+		args->app = ast_json_string_get(field);
+	}
 	return 0;
 }
 
@@ -231,6 +242,9 @@
 		if (strcmp(i->name, "name") == 0) {
 			args.name = (i->value);
 		} else
+		if (strcmp(i->name, "app") == 0) {
+			args.app = (i->value);
+		} else
 		{}
 	}
 	for (i = path_vars; i; i = i->next) {
diff --git a/res/res_stasis.c b/res/res_stasis.c
index a60ec5f..7573f2c 100644
--- a/res/res_stasis.c
+++ b/res/res_stasis.c
@@ -1850,6 +1850,31 @@
 }
 
 
+enum stasis_app_subscribe_res stasis_app_subscribe_bridge(const char *app_name,
+	struct ast_bridge *bridge)
+{
+	struct stasis_app *app = find_app_by_name(app_name);
+	int res;
+
+	if (!app) {
+		return STASIS_ASR_APP_NOT_FOUND;
+	}
+
+	ast_debug(3, "%s: Subscribing to %s\n", app_name, bridge->uniqueid);
+
+	res = app_subscribe_bridge(app, bridge);
+	ao2_ref(app, -1);
+
+	if (res != 0) {
+		ast_log(LOG_ERROR, "Error subscribing app '%s' to bridge '%s'\n",
+			app_name, bridge->uniqueid);
+		return STASIS_ASR_INTERNAL_ERROR;
+	}
+
+	return STASIS_ASR_OK;
+}
+
+
 /*!
  * \internal
  * \brief Subscribe an app to an event source.
diff --git a/rest-api/api-docs/bridges.json b/rest-api/api-docs/bridges.json
index 877fdf8..1a7e6d6 100644
--- a/rest-api/api-docs/bridges.json
+++ b/rest-api/api-docs/bridges.json
@@ -47,6 +47,14 @@
 							"required": false,
 							"allowMultiple": false,
 							"dataType": "string"
+						},
+						{
+							"name": "app",
+							"description": "The application that is subscribed to the bridge.",
+							"paramType": "query",
+							"required": false,
+							"allowMultiple": false,
+							"dataType": "string"
 						}
 					]
 				}
@@ -86,6 +94,14 @@
 							"required": false,
 							"allowMultiple": false,
 							"dataType": "string"
+						},
+						{
+							"name": "app",
+							"description": "The application that is subscribed to the bridge.",
+							"paramType": "query",
+							"required": false,
+							"allowMultiple": false,
+							"dataType": "string"
 						}
 					]
 				},

-- 
To view, visit https://gerrit.asterisk.org/10314
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie3714ef42a4c2e1d95196cecdbc001c0dbff19e3
Gerrit-Change-Number: 10314
Gerrit-PatchSet: 1
Gerrit-Owner: Pascal Cadotte Michaud <pcm at wazo.io>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180928/1e671a4e/attachment-0001.html>


More information about the asterisk-code-review mailing list