[Asterisk-code-review] app queue: Add option for predial handlers on caller and cal... (asterisk[master])

Kristian Høgh asteriskteam at digium.com
Wed Jun 13 02:39:10 CDT 2018


Kristian Høgh has uploaded this change for review. ( https://gerrit.asterisk.org/9180


Change subject: app_queue: Add option for predial handlers on caller and callee channels
......................................................................

app_queue: Add option for predial handlers on caller and callee channels

ASTERISK-27912: Add predial handler to app_queue
app_dial (ASTERISK-19548) and app_originate (ASTERISK-26587) have the
possibility to execute predial handlers on caller and callee channel.
This patch adds predial handler on app_queue and uses same options
as Dial and Originate (b and B).
Gosub is executed on originating channel when it gets first in line
and on each newly created outgoing channel.

Change-Id: I5acf5c32587ee008658d12e8a8049eb8fa4d0f24
---
M apps/app_queue.c
1 file changed, 52 insertions(+), 11 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/80/9180/1

diff --git a/apps/app_queue.c b/apps/app_queue.c
index 3047648..5c03e46 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -133,6 +133,27 @@
 			<parameter name="queuename" required="true" />
 			<parameter name="options">
 				<optionlist>
+					<option name="b" argsep="^">
+						<para>Before initiating an outgoing call, <literal>Gosub</literal> to the specified
+						location using the newly created channel.  The <literal>Gosub</literal> will be
+						executed for each destination channel.</para>
+						<argument name="context" required="false" />
+						<argument name="exten" required="false" />
+						<argument name="priority" required="true" hasparams="optional" argsep="^">
+							<argument name="arg1" multiple="true" required="true" />
+							<argument name="argN" />
+						</argument>
+					</option>
+					<option name="B" argsep="^">
+						<para>Before initiating the outgoing call(s), <literal>Gosub</literal> to the
+						specified location using the current channel.</para>
+						<argument name="context" required="false" />
+						<argument name="exten" required="false" />
+						<argument name="priority" required="true" hasparams="optional" argsep="^">
+							<argument name="arg1" multiple="true" required="true" />
+							<argument name="argN" />
+						</argument>
+					</option>
 					<option name="C">
 						<para>Mark all calls as "answered elsewhere" when cancelled.</para>
 					</option>
@@ -1325,15 +1346,21 @@
 	OPT_CALLER_AUTOMIXMON =      (1 << 16),
 	OPT_CALLEE_AUTOMON =         (1 << 17),
 	OPT_CALLER_AUTOMON =         (1 << 18),
+	OPT_PREDIAL_CALLEE =         (1 << 19),
+	OPT_PREDIAL_CALLER =         (1 << 20),
 };
 
 enum {
 	OPT_ARG_CALLEE_GO_ON = 0,
+	OPT_ARG_PREDIAL_CALLEE,
+	OPT_ARG_PREDIAL_CALLER,
 	/* note: this entry _MUST_ be the last one in the enum */
 	OPT_ARG_ARRAY_SIZE
 };
 
 AST_APP_OPTIONS(queue_exec_options, BEGIN_OPTIONS
+	AST_APP_OPTION_ARG('b', OPT_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLEE),
+	AST_APP_OPTION_ARG('B', OPT_PREDIAL_CALLER, OPT_ARG_PREDIAL_CALLER),
 	AST_APP_OPTION('C', OPT_MARK_AS_ANSWERED),
 	AST_APP_OPTION('c', OPT_GO_ON),
 	AST_APP_OPTION('d', OPT_DATA_QUALITY),
@@ -4462,7 +4489,7 @@
  * \retval 1 on success to reach a free agent
  * \retval 0 on failure to get agent.
  */
-static int ring_entry(struct queue_ent *qe, struct callattempt *tmp, int *busies)
+static int ring_entry(struct queue_ent *qe, struct callattempt *tmp, int *busies, struct ast_flags opts, char **opt_args)
 {
 	int res;
 	int status;
@@ -4559,6 +4586,13 @@
 	ast_channel_unlock(tmp->chan);
 	ast_channel_unlock(qe->chan);
 
+	/* PREDIAL: Run gosub on the callee's channel */
+	if (ast_test_flag(&opts, OPT_PREDIAL_CALLEE)
+		&& !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLEE])) {
+		ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLEE]);
+		ast_app_exec_sub(NULL, tmp->chan, opt_args[OPT_ARG_PREDIAL_CALLEE], 0);
+	}
+
 	/* Place the call, but don't wait on the answer */
 	if ((res = ast_call(tmp->chan, location, 0))) {
 		/* Again, keep going even if there's an error */
@@ -4612,7 +4646,7 @@
  * \retval 1 if a member was called successfully
  * \retval 0 otherwise
  */
-static int ring_one(struct queue_ent *qe, struct callattempt *outgoing, int *busies)
+static int ring_one(struct queue_ent *qe, struct callattempt *outgoing, int *busies, struct ast_flags opts, char **opt_args)
 {
 	int ret = 0;
 
@@ -4628,13 +4662,13 @@
 			for (cur = outgoing; cur; cur = cur->q_next) {
 				if (cur->stillgoing && !cur->chan && cur->metric <= best->metric) {
 					ast_debug(1, "(Parallel) Trying '%s' with metric %d\n", cur->interface, cur->metric);
-					ret |= ring_entry(qe, cur, busies);
+					ret |= ring_entry(qe, cur, busies, opts, opt_args);
 				}
 			}
 		} else {
 			/* Ring just the best channel */
 			ast_debug(1, "Trying '%s' with metric %d\n", best->interface, best->metric);
-			ret = ring_entry(qe, best, busies);
+			ret = ring_entry(qe, best, busies, opts, opt_args);
 		}
 
 		/* If we have timed out, break out */
@@ -4887,7 +4921,7 @@
  *
  * \todo eventually all call forward logic should be intergerated into and replaced by ast_call_forward()
  */
-static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callattempt *outgoing, int *to, char *digit, int prebusies, int caller_disconnect, int forwardsallowed)
+static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callattempt *outgoing, int *to, char *digit, int prebusies, int caller_disconnect, int forwardsallowed, struct ast_flags opts, char **opt_args)
 {
 	const char *queue = qe->parent->name;
 	struct callattempt *o, *start = NULL, *prev = NULL;
@@ -4947,7 +4981,7 @@
 			}
 			/* On "ringall" strategy we only move to the next penalty level
 			   when *all* ringing phones are done in the current penalty level */
-			ring_one(qe, outgoing, &numbusies);
+			ring_one(qe, outgoing, &numbusies, opts, opt_args);
 			/* and retry... */
 		}
 		if (pos == 1 /* not found */) {
@@ -5208,7 +5242,7 @@
 								}
 								/* Have enough time for a queue member to answer? */
 								if (ast_remaining_ms(start_time_tv, orig) > 500) {
-									ring_one(qe, outgoing, &numbusies);
+									ring_one(qe, outgoing, &numbusies, opts, opt_args);
 									starttime = (long) time(NULL);
 								}
 							}
@@ -5226,7 +5260,7 @@
 									start_time_tv = ast_tvnow();
 								}
 								if (ast_remaining_ms(start_time_tv, orig) > 500) {
-									ring_one(qe, outgoing, &numbusies);
+									ring_one(qe, outgoing, &numbusies, opts, opt_args);
 									starttime = (long) time(NULL);
 								}
 							}
@@ -5324,7 +5358,7 @@
 							start_time_tv = ast_tvnow();
 						}
 						if (ast_remaining_ms(start_time_tv, orig) > 500) {
-							ring_one(qe, outgoing, &numbusies);
+							ring_one(qe, outgoing, &numbusies, opts, opt_args);
 							starttime = (long) time(NULL);
 						}
 					}
@@ -6831,10 +6865,10 @@
 	orig = to;
 	++qe->pending;
 	ao2_unlock(qe->parent);
-	ring_one(qe, outgoing, &numbusies);
+	ring_one(qe, outgoing, &numbusies, opts, opt_args);
 	lpeer = wait_for_answer(qe, outgoing, &to, &digit, numbusies,
 		ast_test_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT),
-		forwardsallowed);
+		forwardsallowed, opts, opt_args);
 
 	ao2_lock(qe->parent);
 	if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY || qe->parent->strategy == QUEUE_STRATEGY_RRORDERED) {
@@ -8287,6 +8321,13 @@
 
 	makeannouncement = qe.parent->announce_to_first_user;
 
+	/* PREDIAL: Run gosub on the caller's channel */
+	if (ast_test_flag(&opts, OPT_PREDIAL_CALLER)
+		&& !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
+		ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLER]);
+		ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
+	}
+
 	for (;;) {
 		/* This is the wait loop for the head caller*/
 		/* To exit, they may get their call answered; */

-- 
To view, visit https://gerrit.asterisk.org/9180
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5acf5c32587ee008658d12e8a8049eb8fa4d0f24
Gerrit-Change-Number: 9180
Gerrit-PatchSet: 1
Gerrit-Owner: Kristian Høgh <kfh at uni-tel.dk>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180613/d1f360bc/attachment.html>


More information about the asterisk-code-review mailing list