[asterisk-commits] file: branch file/ari-spy r402516 - in /team/file/ari-spy: include/asterisk/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 6 09:50:04 CST 2013


Author: file
Date: Wed Nov  6 09:50:01 2013
New Revision: 402516

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=402516
Log:
Allow snooping to occur at any time and fix a bug where hanging up the Snoop channel would block.

Modified:
    team/file/ari-spy/include/asterisk/stasis_app_snoop.h
    team/file/ari-spy/res/ari/resource_channels.c
    team/file/ari-spy/res/res_ari_channels.c
    team/file/ari-spy/res/res_stasis_snoop.c
    team/file/ari-spy/rest-api/api-docs/channels.json

Modified: team/file/ari-spy/include/asterisk/stasis_app_snoop.h
URL: http://svnview.digium.com/svn/asterisk/team/file/ari-spy/include/asterisk/stasis_app_snoop.h?view=diff&rev=402516&r1=402515&r2=402516
==============================================================================
--- team/file/ari-spy/include/asterisk/stasis_app_snoop.h (original)
+++ team/file/ari-spy/include/asterisk/stasis_app_snoop.h Wed Nov  6 09:50:01 2013
@@ -43,9 +43,9 @@
 };
 
 /*!
- * \brief Create a snoop on the channel associated with this control.
+ * \brief Create a snoop on the provided channel.
  *
- * \param control Control for \c res_stasis.
+ * \param chan Channel to snoop on.
  * \param spy Direction of media that should be spied on.
  * \param whisper Direction of media that should be whispered into.
  * \param app Stasis application to execute on the snoop channel.
@@ -53,7 +53,7 @@
  * \return Snoop channel. ast_channel_unref() when done.
  * \return \c NULL if snoop channel couldn't be created.
  */
-struct ast_channel *stasis_app_control_snoop(struct stasis_app_control *control,
+struct ast_channel *stasis_app_control_snoop(struct ast_channel *chan,
 	enum stasis_app_snoop_direction spy, enum stasis_app_snoop_direction whisper,
 	const char *app, const char *app_args);
 

Modified: team/file/ari-spy/res/ari/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/file/ari-spy/res/ari/resource_channels.c?view=diff&rev=402516&r1=402515&r2=402516
==============================================================================
--- team/file/ari-spy/res/ari/resource_channels.c (original)
+++ team/file/ari-spy/res/ari/resource_channels.c Wed Nov  6 09:50:01 2013
@@ -722,7 +722,7 @@
 void ast_ari_snoop_channel(struct ast_variable *headers, struct ast_snoop_channel_args *args, struct ast_ari_response *response)
 {
 	enum stasis_app_snoop_direction spy, whisper;
-	RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_channel *, chan, NULL, ast_channel_cleanup);
 	RAII_VAR(struct ast_channel *, snoop, NULL, ast_channel_cleanup);
 	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
 
@@ -775,13 +775,15 @@
 		return;
 	}
 
-	control = find_control(response, args->channel_id);
-	if (control == NULL) {
-		/* response filled in by find_control */
-		return;
-	}
-
-	snoop = stasis_app_control_snoop(control, spy, whisper, args->app, args->app_args);
+	chan = ast_channel_get_by_name(args->channel_id);
+	if (chan == NULL) {
+		ast_ari_response_error(
+			response, 404, "Channel Not Found",
+			"Provided channel was not found");
+		return;
+	}
+
+	snoop = stasis_app_control_snoop(chan, spy, whisper, args->app, args->app_args);
 	if (snoop == NULL) {
 		ast_ari_response_error(
 			response, 500, "Internal error",

Modified: team/file/ari-spy/res/res_ari_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/file/ari-spy/res/res_ari_channels.c?view=diff&rev=402516&r1=402515&r2=402516
==============================================================================
--- team/file/ari-spy/res/res_ari_channels.c (original)
+++ team/file/ari-spy/res/res_ari_channels.c Wed Nov  6 09:50:01 2013
@@ -1127,7 +1127,6 @@
 	case 501: /* Not Implemented */
 	case 400: /* Invalid parameters */
 	case 404: /* Channel not found */
-	case 409: /* Channel is not in a Stasis application */
 		is_valid = 1;
 		break;
 	default:

Modified: team/file/ari-spy/res/res_stasis_snoop.c
URL: http://svnview.digium.com/svn/asterisk/team/file/ari-spy/res/res_stasis_snoop.c?view=diff&rev=402516&r1=402515&r2=402516
==============================================================================
--- team/file/ari-spy/res/res_stasis_snoop.c (original)
+++ team/file/ari-spy/res/res_stasis_snoop.c Wed Nov  6 09:50:01 2013
@@ -143,11 +143,15 @@
 	struct stasis_app_snoop *snoop = ast_channel_tech_pvt(chan);
 
 	if (snoop->spy_active) {
+		ast_audiohook_lock(&snoop->spy);
 		ast_audiohook_detach(&snoop->spy);
+		ast_audiohook_unlock(&snoop->spy);
 	}
 
 	if (snoop->whisper_active) {
+		ast_audiohook_lock(&snoop->whisper);
 		ast_audiohook_detach(&snoop->whisper);
+		ast_audiohook_unlock(&snoop->whisper);
 	}
 
 	ao2_cleanup(snoop);
@@ -220,21 +224,21 @@
 	return ast_audiohook_attach(chan, audiohook);
 }
 
-struct stasis_app_control_snoop_data {
-	enum stasis_app_snoop_direction spy;
-	enum stasis_app_snoop_direction whisper;
-	const char *app;
-	const char *app_args;
-};
-
-static void *app_control_snoop(struct stasis_app_control *control,
-	struct ast_channel *chan, void *data)
-{
-	struct stasis_app_control_snoop_data *snoop_data = data;
-	RAII_VAR(struct stasis_app_snoop *, snoop, ao2_alloc_options(sizeof(*snoop), snoop_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK), ao2_cleanup);
+struct ast_channel *stasis_app_control_snoop(struct ast_channel *chan,
+	enum stasis_app_snoop_direction spy, enum stasis_app_snoop_direction whisper,
+	const char *app, const char *app_args)
+{
+	RAII_VAR(struct stasis_app_snoop *, snoop, NULL, ao2_cleanup);
 	unsigned int rate;
 	pthread_t thread;
-
+	SCOPED_CHANNELLOCK(lock, chan);
+
+	if (spy == STASIS_SNOOP_DIRECTION_NONE &&
+		whisper == STASIS_SNOOP_DIRECTION_NONE) {
+		return NULL;
+	}
+
+	snoop = ao2_alloc_options(sizeof(*snoop), snoop_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
 	if (!snoop) {
 		return NULL;
 	}
@@ -245,9 +249,9 @@
 		return NULL;
 	}
 
-	ast_str_set(&snoop->app, 0, "%s", snoop_data->app);
-	if (!ast_strlen_zero(snoop_data->app_args)) {
-		ast_str_append(&snoop->app, 0, ",%s", snoop_data->app_args);
+	ast_str_set(&snoop->app, 0, "%s", app);
+	if (!ast_strlen_zero(app_args)) {
+		ast_str_append(&snoop->app, 0, ",%s", app_args);
 	}
 
 	/* Set up a timer for the Snoop channel so it wakes up at a specific interval */
@@ -283,8 +287,8 @@
 	ast_format_copy(ast_channel_readformat(snoop->chan), &snoop->spy_format);
 	ast_format_copy(ast_channel_rawreadformat(snoop->chan), &snoop->spy_format);
 
-	if (snoop_data->spy != STASIS_SNOOP_DIRECTION_NONE) {
-		if (snoop_setup_audiohook(chan, AST_AUDIOHOOK_TYPE_SPY, snoop_data->spy, &snoop->spy_direction, &snoop->spy)) {
+	if (spy != STASIS_SNOOP_DIRECTION_NONE) {
+		if (snoop_setup_audiohook(chan, AST_AUDIOHOOK_TYPE_SPY, spy, &snoop->spy_direction, &snoop->spy)) {
 			ast_hangup(snoop->chan);
 			return NULL;
 		}
@@ -294,8 +298,8 @@
 	}
 
 	/* If whispering is enabled set up the audiohook */
-	if (snoop_data->whisper != STASIS_SNOOP_DIRECTION_NONE) {
-		if (snoop_setup_audiohook(chan, AST_AUDIOHOOK_TYPE_WHISPER, snoop_data->whisper, &snoop->whisper_direction, &snoop->whisper)) {
+	if (whisper != STASIS_SNOOP_DIRECTION_NONE) {
+		if (snoop_setup_audiohook(chan, AST_AUDIOHOOK_TYPE_WHISPER, whisper, &snoop->whisper_direction, &snoop->whisper)) {
 			ast_hangup(snoop->chan);
 			return NULL;
 		}
@@ -317,25 +321,6 @@
 	return ast_channel_ref(snoop->chan);
 }
 
-struct ast_channel *stasis_app_control_snoop(struct stasis_app_control *control,
-	enum stasis_app_snoop_direction spy, enum stasis_app_snoop_direction whisper,
-	const char *app, const char *app_args)
-{
-	struct stasis_app_control_snoop_data snoop_data = {
-		.spy = spy,
-		.whisper = whisper,
-		.app = app,
-		.app_args = app_args,
-	};
-
-	if (spy == STASIS_SNOOP_DIRECTION_NONE &&
-		whisper == STASIS_SNOOP_DIRECTION_NONE) {
-		return NULL;
-	}
-
-	return stasis_app_send_command(control, app_control_snoop, &snoop_data);
-}
-
 static int load_module(void)
 {
 	return AST_MODULE_LOAD_SUCCESS;

Modified: team/file/ari-spy/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/team/file/ari-spy/rest-api/api-docs/channels.json?view=diff&rev=402516&r1=402515&r2=402516
==============================================================================
--- team/file/ari-spy/rest-api/api-docs/channels.json (original)
+++ team/file/ari-spy/rest-api/api-docs/channels.json Wed Nov  6 09:50:01 2013
@@ -835,10 +835,6 @@
 						{
 							"code": 404,
 							"reason": "Channel not found"
-						},
-						{
-							"code": 409,
-							"reason": "Channel is not in a Stasis application"
 						}
 					]
 				}




More information about the asterisk-commits mailing list