[asterisk-commits] twilson: branch group/srtp r167934 - /team/group/srtp/apps/app_dial.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 8 18:09:47 CST 2009


Author: twilson
Date: Thu Jan  8 18:09:47 2009
New Revision: 167934

URL: http://svn.digium.com/view/asterisk?view=rev&rev=167934
Log:
Add PLAY_CALLER: and PLAY_BOTH: to MACRO_RESULT responses

To allow playing notification messages for checking whether or not both sides
of a call are secure (as defined by the user in the dialplan), you can play
a message by setting MACRO_RESULT to either PLAY_CALLER:prompt or
PLAY_BOTH:prompt_caller^prompt_callee with the prompt options being the name
(without extension) of a prompt.  PLAY_BOTH: will play to both sides of the
call simultaneously just before bridging the call.

Modified:
    team/group/srtp/apps/app_dial.c

Modified: team/group/srtp/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/group/srtp/apps/app_dial.c?view=diff&rev=167934&r1=167933&r2=167934
==============================================================================
--- team/group/srtp/apps/app_dial.c (original)
+++ team/group/srtp/apps/app_dial.c Thu Jan  8 18:09:47 2009
@@ -1502,19 +1502,39 @@
 struct prompt_data {
 	struct ast_channel *chan;
 	const char *prompt;
+	int res;
 };
 
-static void *play_prompt(void *data)
+static void *play_prompts_cb(void *data)
 {
 	struct prompt_data *pd = data;
 
-	int res;
-
-	if (!ast_strlen_zero(pd->prompt) && !(res = ast_streamfile(pd->chan, pd->prompt, pd->chan->language))) {
-		res = ast_waitstream(pd->chan, "");
-	}
-
-	return NULL;
+	if (!ast_strlen_zero(pd->prompt) && !(pd->res = ast_streamfile(pd->chan, pd->prompt, pd->chan->language))) {
+		pd->res = ast_waitstream(pd->chan, "");
+	}
+
+	return &pd->res;
+}
+
+static int play_prompts(struct ast_channel *chan, struct ast_channel *peer, const char *chan_prompt, const char *peer_prompt)
+{
+	struct prompt_data one, two;
+	pthread_t thread1 = AST_PTHREADT_NULL, thread2 = AST_PTHREADT_NULL;
+	int *ret, res;
+
+	one.chan = chan;
+	two.chan = peer;
+	one.prompt = chan_prompt;
+	two.prompt = peer_prompt;
+
+	ast_pthread_create(&thread1, NULL, play_prompts_cb, &one);
+	ast_pthread_create(&thread2, NULL, play_prompts_cb, &two);
+	pthread_join(thread1, (void **)&ret);
+	res = *ret;
+	pthread_join(thread2, (void **)&ret);
+	res |= *ret;
+
+	return res;
 }
 
 static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags64 *peerflags, int *continue_exec)
@@ -2010,8 +2030,11 @@
 			}
 
 			theapp = pbx_findapp("Macro");
-
 			if (theapp && !res) { /* XXX why check res here ? */
+				/* Set peer->exten and peer->context so that MACRO_EXTEN and MACRO_CONTEXT get set */
+				ast_copy_string(peer->context, chan->context, sizeof(peer->context));
+				ast_copy_string(peer->exten, chan->exten, sizeof(peer->exten));
+
 				replace_macro_delimiter(opt_args[OPT_ARG_CALLEE_MACRO]);
 				res = pbx_exec(peer, theapp, opt_args[OPT_ARG_CALLEE_MACRO]);
 				ast_debug(1, "Macro exited with status %d\n", res);
@@ -2030,6 +2053,7 @@
 
 			if (!res && (macro_result = pbx_builtin_getvar_helper(peer, "MACRO_RESULT"))) {
 				char *macro_transfer_dest;
+				char *prompt1;
 
 				if (!strcasecmp(macro_result, "BUSY")) {
 					ast_copy_string(pa.status, macro_result, sizeof(pa.status));
@@ -2057,6 +2081,24 @@
 						if (!ast_parseable_goto(chan, macro_transfer_dest))
 							ast_set_flag64(peerflags, OPT_GO_ON);
 					}
+				} else if (!strncasecmp(macro_result, "PLAY_CALLER:", 12) && (prompt1 = ast_strdupa(macro_result + 12))) {
+					ast_answer(chan); /* Macro has completed, so peer has answered */
+					ast_stream_and_wait(chan, prompt1, "");
+				} else if (!strncasecmp(macro_result, "PLAY_BOTH:", 10) && (prompt1 = ast_strdupa(macro_result + 10))) {
+					char *prompt2 = prompt1;
+
+					prompt1 = strsep(&prompt2, "^");
+					if (ast_strlen_zero(prompt2)) {
+						prompt2 = prompt1;
+					}
+
+					ast_answer(chan);
+
+					ast_channel_unlock(peer);
+					if (play_prompts(chan, peer, prompt1, prompt2)) {
+						ast_log(LOG_WARNING, "An error occured playing prompts!\n");
+					}
+					ast_channel_lock(peer);
 				}
 			}
 
@@ -2234,16 +2276,7 @@
 			}
 
 			if (ast_test_flag64(&opts, OPT_ANNOUNCE_BOTH) && !ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE_BOTH])) {
-			   struct prompt_data one, two;
-				pthread_t thread1 = AST_PTHREADT_NULL, thread2 = AST_PTHREADT_NULL;
-
-				one.chan = chan;
-				two.chan = peer;
-				one.prompt = two.prompt = opt_args[OPT_ARG_ANNOUNCE_BOTH];
-				ast_pthread_create(&thread1, NULL, play_prompt, &one);
-				ast_pthread_create(&thread2, NULL, play_prompt, &two);
-				pthread_join(thread1, NULL);
-				pthread_join(thread2, NULL);
+				play_prompts(chan, peer, opt_args[OPT_ARG_ANNOUNCE_BOTH], opt_args[OPT_ARG_ANNOUNCE_BOTH]);
 			}
 
 			res = ast_bridge_call(chan, peer, &config);




More information about the asterisk-commits mailing list