aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/app_macro.c22
-rw-r--r--include/asterisk/channel.h32
-rw-r--r--include/asterisk/frame.h1
-rw-r--r--main/channel.c112
-rw-r--r--main/pbx.c24
5 files changed, 134 insertions, 57 deletions
diff --git a/apps/app_macro.c b/apps/app_macro.c
index faf97a83a..7c0f616dd 100644
--- a/apps/app_macro.c
+++ b/apps/app_macro.c
@@ -520,20 +520,20 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
}
if (!strcasecmp(chan->context, fullmacro)) {
+ const char *offsets;
+
/* If we're leaving the macro normally, restore original information */
chan->priority = oldpriority;
ast_copy_string(chan->context, oldcontext, sizeof(chan->context));
- if (!(ast_check_hangup(chan) & AST_SOFTHANGUP_ASYNCGOTO)) {
- /* Copy the extension, so long as we're not in softhangup, where we could be given an asyncgoto */
- const char *offsets;
- ast_copy_string(chan->exten, oldexten, sizeof(chan->exten));
- if ((offsets = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"))) {
- /* Handle macro offset if it's set by checking the availability of step n + offset + 1, otherwise continue
- normally if there is any problem */
- if (sscanf(offsets, "%30d", &offset) == 1) {
- if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + offset + 1, chan->cid.cid_num)) {
- chan->priority += offset;
- }
+ ast_copy_string(chan->exten, oldexten, sizeof(chan->exten));
+ if ((offsets = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"))) {
+ /* Handle macro offset if it's set by checking the availability of step n + offset + 1, otherwise continue
+ normally if there is any problem */
+ if (sscanf(offsets, "%30d", &offset) == 1) {
+ if (ast_exists_extension(chan, chan->context, chan->exten,
+ chan->priority + offset + 1,
+ chan->cid.cid_num)) {
+ chan->priority += offset;
}
}
}
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 88d1748c8..11fc9b67c 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -647,14 +647,42 @@ enum {
};
enum {
- /*! Soft hangup by device */
+ /*!
+ * Soft hangup requested by device or other internal reason.
+ * Actual hangup needed.
+ */
AST_SOFTHANGUP_DEV = (1 << 0),
- /*! Soft hangup for async goto */
+ /*!
+ * Used to break the normal frame flow so an async goto can be
+ * done instead of actually hanging up.
+ */
AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
+ /*!
+ * Soft hangup requested by system shutdown. Actual hangup
+ * needed.
+ */
AST_SOFTHANGUP_SHUTDOWN = (1 << 2),
+ /*!
+ * Used to break the normal frame flow after a timeout so an
+ * implicit async goto can be done to the 'T' exten if it exists
+ * instead of actually hanging up. If the exten does not exist
+ * then actually hangup.
+ */
AST_SOFTHANGUP_TIMEOUT = (1 << 3),
+ /*!
+ * Soft hangup requested by application/channel-driver being
+ * unloaded. Actual hangup needed.
+ */
AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
+ /*!
+ * Soft hangup requested by non-associated party. Actual hangup
+ * needed.
+ */
AST_SOFTHANGUP_EXPLICIT = (1 << 5),
+ /*!
+ * Used to break a bridge so the channel can be spied upon
+ * instead of actually hanging up.
+ */
AST_SOFTHANGUP_UNBRIDGE = (1 << 6),
};
diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h
index ed9ff9665..e1270eec3 100644
--- a/include/asterisk/frame.h
+++ b/include/asterisk/frame.h
@@ -318,6 +318,7 @@ enum ast_control_frame_type {
AST_CONTROL_SRCUPDATE = 20, /*!< Indicate source of media has changed */
AST_CONTROL_T38_PARAMETERS = 24, /*!< T38 state change request/notification with parameters */
AST_CONTROL_SRCCHANGE = 25, /*!< Media source has changed and requires a new RTP SSRC */
+ AST_CONTROL_END_OF_Q = 29, /*!< Indicate that this position was the end of the channel queue for a softhangup. */
};
enum ast_control_t38 {
diff --git a/main/channel.c b/main/channel.c
index 1e06bd4df..d067222a4 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -1013,15 +1013,42 @@ static int __ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin, in
ast_channel_lock(chan);
- /* See if the last frame on the queue is a hangup, if so don't queue anything */
- if ((cur = AST_LIST_LAST(&chan->readq)) &&
- (cur->frametype == AST_FRAME_CONTROL) &&
- (cur->subclass == AST_CONTROL_HANGUP)) {
- ast_channel_unlock(chan);
- return 0;
+ /*
+ * Check the last frame on the queue if we are queuing the new
+ * frames after it.
+ */
+ cur = AST_LIST_LAST(&chan->readq);
+ if (cur && cur->frametype == AST_FRAME_CONTROL && !head && (!after || after == cur)) {
+ switch (cur->subclass) {
+ case AST_CONTROL_END_OF_Q:
+ if (fin->frametype == AST_FRAME_CONTROL
+ && fin->subclass == AST_CONTROL_HANGUP) {
+ /*
+ * Destroy the end-of-Q marker frame so we can queue the hangup
+ * frame in its place.
+ */
+ AST_LIST_REMOVE(&chan->readq, cur, frame_list);
+ ast_frfree(cur);
+
+ /*
+ * This has degenerated to a normal queue append anyway. Since
+ * we just destroyed the last frame in the queue we must make
+ * sure that "after" is NULL or bad things will happen.
+ */
+ after = NULL;
+ break;
+ }
+ /* Fall through */
+ case AST_CONTROL_HANGUP:
+ /* Don't queue anything. */
+ ast_channel_unlock(chan);
+ return 0;
+ default:
+ break;
+ }
}
- /* Build copies of all the frames and count them */
+ /* Build copies of all the new frames and count them */
AST_LIST_HEAD_INIT_NOLOCK(&frames);
for (cur = fin; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
if (!(f = ast_frdup(cur))) {
@@ -2734,14 +2761,17 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
if (chan->generator)
ast_deactivate_generator(chan);
- /* It is possible for chan->_softhangup to be set, yet there still be control
- * frames that still need to be read. Instead of just going to 'done' in the
- * case of ast_check_hangup(), we instead need to send the HANGUP frame so that
- * it can mark the end of the read queue. If there are frames to be read,
- * ast_queue_control will be called repeatedly, but will only queue one hangup
- * frame. */
- if (ast_check_hangup(chan)) {
- ast_queue_control(chan, AST_CONTROL_HANGUP);
+ /*
+ * It is possible for chan->_softhangup to be set and there
+ * still be control frames that need to be read. Instead of
+ * just going to 'done' in the case of ast_check_hangup(), we
+ * need to queue the end-of-Q frame so that it can mark the end
+ * of the read queue. If there are frames to be read,
+ * ast_queue_control() will be called repeatedly, but will only
+ * queue the first end-of-Q frame.
+ */
+ if (chan->_softhangup) {
+ ast_queue_control(chan, AST_CONTROL_END_OF_Q);
} else {
goto done;
}
@@ -2862,12 +2892,21 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
}
}
- /* Interpret hangup and return NULL */
+ /* Interpret hangup and end-of-Q frames to return NULL */
/* XXX why not the same for frames from the channel ? */
- if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) {
- cause = f->data.uint32;
- ast_frfree(f);
- f = NULL;
+ if (f->frametype == AST_FRAME_CONTROL) {
+ switch (f->subclass) {
+ case AST_CONTROL_HANGUP:
+ chan->_softhangup |= AST_SOFTHANGUP_DEV;
+ cause = f->data.uint32;
+ /* Fall through */
+ case AST_CONTROL_END_OF_Q:
+ ast_frfree(f);
+ f = NULL;
+ break;
+ default:
+ break;
+ }
}
} else {
chan->blocker = pthread_self();
@@ -3164,7 +3203,9 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
}
} else {
/* Make sure we always return NULL in the future */
- chan->_softhangup |= AST_SOFTHANGUP_DEV;
+ if (!chan->_softhangup) {
+ chan->_softhangup |= AST_SOFTHANGUP_DEV;
+ }
if (cause)
chan->hangupcause = cause;
if (chan->generator)
@@ -3232,6 +3273,7 @@ static int attribute_const is_visible_indication(enum ast_control_frame_type con
case AST_CONTROL_HANGUP:
case AST_CONTROL_T38_PARAMETERS:
case _XXX_AST_CONTROL_T38:
+ case AST_CONTROL_END_OF_Q:
break;
case AST_CONTROL_CONGESTION:
@@ -3340,6 +3382,7 @@ int ast_indicate_data(struct ast_channel *chan, int _condition,
case AST_CONTROL_RING:
case AST_CONTROL_HOLD:
case AST_CONTROL_UNHOLD:
+ case AST_CONTROL_END_OF_Q:
/* Nothing left to do for these. */
res = 0;
break;
@@ -5130,11 +5173,13 @@ static enum ast_bridge_result ast_generic_bridge(struct ast_channel *c0, struct
/* No frame received within the specified timeout - check if we have to deliver now */
if (jb_in_use)
ast_jb_get_and_deliver(c0, c1);
- if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) {
- if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
- c0->_softhangup = 0;
- if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
- c1->_softhangup = 0;
+ if ((c0->_softhangup | c1->_softhangup) & AST_SOFTHANGUP_UNBRIDGE) {/* Bit operators are intentional. */
+ if (c0->_softhangup & AST_SOFTHANGUP_UNBRIDGE) {
+ c0->_softhangup &= ~AST_SOFTHANGUP_UNBRIDGE;
+ }
+ if (c1->_softhangup & AST_SOFTHANGUP_UNBRIDGE) {
+ c1->_softhangup &= ~AST_SOFTHANGUP_UNBRIDGE;
+ }
c0->_bridge = c1;
c1->_bridge = c0;
}
@@ -5444,11 +5489,13 @@ enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_cha
ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE);
}
- if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) {
- if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
- c0->_softhangup = 0;
- if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
- c1->_softhangup = 0;
+ if ((c0->_softhangup | c1->_softhangup) & AST_SOFTHANGUP_UNBRIDGE) {/* Bit operators are intentional. */
+ if (c0->_softhangup & AST_SOFTHANGUP_UNBRIDGE) {
+ c0->_softhangup &= ~AST_SOFTHANGUP_UNBRIDGE;
+ }
+ if (c1->_softhangup & AST_SOFTHANGUP_UNBRIDGE) {
+ c1->_softhangup &= ~AST_SOFTHANGUP_UNBRIDGE;
+ }
c0->_bridge = c1;
c1->_bridge = c0;
ast_debug(1, "Unbridge signal received. Ending native bridge.\n");
@@ -5499,8 +5546,9 @@ enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_cha
ast_clear_flag(c0, AST_FLAG_NBRIDGE);
ast_clear_flag(c1, AST_FLAG_NBRIDGE);
- if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
+ if ((c0->_softhangup | c1->_softhangup) & AST_SOFTHANGUP_UNBRIDGE) {/* Bit operators are intentional. */
continue;
+ }
c0->_bridge = NULL;
c1->_bridge = NULL;
diff --git a/main/pbx.c b/main/pbx.c
index acf7297f2..92259fae5 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -4249,8 +4249,8 @@ static int collect_digits(struct ast_channel *c, int waittime, char *buf, int bu
/* As long as we're willing to wait, and as long as it's not defined,
keep reading digits until we can't possibly get a right answer anymore. */
digit = ast_waitfordigit(c, waittime);
- if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
- c->_softhangup = 0;
+ if (c->_softhangup & AST_SOFTHANGUP_ASYNCGOTO) {
+ c->_softhangup &= ~AST_SOFTHANGUP_ASYNCGOTO;
} else {
if (!digit) /* No entry */
break;
@@ -4317,18 +4317,18 @@ static enum ast_pbx_result __ast_pbx_run(struct ast_channel *c,
/* loop on priorities in this context/exten */
while ( !(res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num, &found,1))) {
- if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "T", 1, c->cid.cid_num)) {
+ if (c->_softhangup & AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "T", 1, c->cid.cid_num)) {
set_ext_pri(c, "T", 0); /* 0 will become 1 with the c->priority++; at the end */
/* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
memset(&c->whentohangup, 0, sizeof(c->whentohangup));
c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT;
- } else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "e", 1, c->cid.cid_num)) {
+ } else if (c->_softhangup & AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "e", 1, c->cid.cid_num)) {
pbx_builtin_raise_exception(c, "ABSOLUTETIMEOUT");
/* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
memset(&c->whentohangup, 0, sizeof(c->whentohangup));
c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT;
- } else if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
- c->_softhangup = 0;
+ } else if (c->_softhangup & AST_SOFTHANGUP_ASYNCGOTO) {
+ c->_softhangup &= ~AST_SOFTHANGUP_ASYNCGOTO;
continue;
} else if (ast_check_hangup(c)) {
ast_debug(1, "Extension %s, priority %d returned normally even though call was hung up\n",
@@ -4372,10 +4372,10 @@ static enum ast_pbx_result __ast_pbx_run(struct ast_channel *c,
}
}
- if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
- c->_softhangup = 0;
+ if (c->_softhangup & AST_SOFTHANGUP_ASYNCGOTO) {
+ c->_softhangup &= ~AST_SOFTHANGUP_ASYNCGOTO;
continue;
- } else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "T", 1, c->cid.cid_num)) {
+ } else if (c->_softhangup & AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "T", 1, c->cid.cid_num)) {
set_ext_pri(c, "T", 1);
/* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
memset(&c->whentohangup, 0, sizeof(c->whentohangup));
@@ -4415,9 +4415,9 @@ static enum ast_pbx_result __ast_pbx_run(struct ast_channel *c,
error = 1; /* we know what to do with it */
break;
}
- } else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
+ } else if (c->_softhangup & AST_SOFTHANGUP_TIMEOUT) {
/* If we get this far with AST_SOFTHANGUP_TIMEOUT, then we know that the "T" extension is next. */
- c->_softhangup = 0;
+ c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT;
} else { /* keypress received, get more digits for a full extension */
int waittime = 0;
if (digit)
@@ -8838,7 +8838,7 @@ static int pbx_builtin_waitexten(struct ast_channel *chan, void *data)
if (!res) {
if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 1, chan->cid.cid_num)) {
ast_verb(3, "Timeout on %s, continuing...\n", chan->name);
- } else if (chan->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
+ } else if (chan->_softhangup & AST_SOFTHANGUP_TIMEOUT) {
ast_verb(3, "Call timeout on %s, checking for 'T'\n", chan->name);
res = -1;
} else if (ast_exists_extension(chan, chan->context, "t", 1, chan->cid.cid_num)) {