mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-07 13:49:18 +00:00
Recent CDR fixes moved execution of the 'h' exten into the bridging code, so variables that were set after ast_bridge_call was called would not show up in the 'h' exten. Added a callback function to handle setting variables, etc. from w/in the bridging code. Calls back into a nested function within the function calling ast_bridge_call
(closes issue #13793) Reported by: greenfieldtech git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@153181 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1277,7 +1277,6 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
|
|||||||
int sentringing = 0, moh = 0;
|
int sentringing = 0, moh = 0;
|
||||||
const char *outbound_group = NULL;
|
const char *outbound_group = NULL;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
time_t start_time;
|
|
||||||
char *parse;
|
char *parse;
|
||||||
int opermode = 0;
|
int opermode = 0;
|
||||||
AST_DECLARE_APP_ARGS(args,
|
AST_DECLARE_APP_ARGS(args,
|
||||||
@@ -1639,7 +1638,6 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time(&start_time);
|
|
||||||
peer = wait_for_answer(chan, outgoing, &to, peerflags, &pa, &num, &result);
|
peer = wait_for_answer(chan, outgoing, &to, peerflags, &pa, &num, &result);
|
||||||
|
|
||||||
/* The ast_channel_datastore_remove() function could fail here if the
|
/* The ast_channel_datastore_remove() function could fail here if the
|
||||||
@@ -1668,10 +1666,9 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
|
|||||||
/* almost done, although the 'else' block is 400 lines */
|
/* almost done, although the 'else' block is 400 lines */
|
||||||
} else {
|
} else {
|
||||||
const char *number;
|
const char *number;
|
||||||
time_t end_time, answer_time = time(NULL);
|
|
||||||
char toast[80]; /* buffer to set variables */
|
|
||||||
|
|
||||||
strcpy(pa.status, "ANSWER");
|
strcpy(pa.status, "ANSWER");
|
||||||
|
pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
|
||||||
/* Ah ha! Someone answered within the desired timeframe. Of course after this
|
/* Ah ha! Someone answered within the desired timeframe. Of course after this
|
||||||
we will always return with -1 so that it is hung up properly after the
|
we will always return with -1 so that it is hung up properly after the
|
||||||
conversation. */
|
conversation. */
|
||||||
@@ -1905,8 +1902,28 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
|
|||||||
|
|
||||||
if (res) { /* some error */
|
if (res) { /* some error */
|
||||||
res = -1;
|
res = -1;
|
||||||
end_time = time(NULL);
|
|
||||||
} else {
|
} else {
|
||||||
|
auto void end_bridge_callback(void);
|
||||||
|
void end_bridge_callback (void)
|
||||||
|
{
|
||||||
|
char buf[80];
|
||||||
|
time_t end;
|
||||||
|
|
||||||
|
time(&end);
|
||||||
|
|
||||||
|
ast_channel_lock(chan);
|
||||||
|
if (chan->cdr->answer.tv_sec) {
|
||||||
|
snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->answer.tv_sec);
|
||||||
|
pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chan->cdr->start.tv_sec) {
|
||||||
|
snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->start.tv_sec);
|
||||||
|
pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
|
||||||
|
}
|
||||||
|
ast_channel_unlock(chan);
|
||||||
|
}
|
||||||
|
|
||||||
if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
|
if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
|
||||||
ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
|
ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
|
||||||
if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
|
if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
|
||||||
@@ -1930,6 +1947,8 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
|
|||||||
if (ast_test_flag64(peerflags, OPT_GO_ON))
|
if (ast_test_flag64(peerflags, OPT_GO_ON))
|
||||||
ast_set_flag(&(config.features_caller), AST_FEATURE_NO_H_EXTEN);
|
ast_set_flag(&(config.features_caller), AST_FEATURE_NO_H_EXTEN);
|
||||||
|
|
||||||
|
config.end_bridge_callback = end_bridge_callback;
|
||||||
|
|
||||||
if (moh) {
|
if (moh) {
|
||||||
moh = 0;
|
moh = 0;
|
||||||
ast_moh_stop(chan);
|
ast_moh_stop(chan);
|
||||||
@@ -1956,14 +1975,8 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
|
|||||||
ast_channel_setoption(chan, AST_OPTION_OPRMODE, &oprmode, sizeof(oprmode), 0);
|
ast_channel_setoption(chan, AST_OPTION_OPRMODE, &oprmode, sizeof(oprmode), 0);
|
||||||
}
|
}
|
||||||
res = ast_bridge_call(chan, peer, &config);
|
res = ast_bridge_call(chan, peer, &config);
|
||||||
end_time = time(NULL);
|
|
||||||
snprintf(toast, sizeof(toast), "%ld", (long)(end_time - answer_time));
|
|
||||||
pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", toast);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(toast, sizeof(toast), "%ld", (long)(end_time - start_time));
|
|
||||||
pbx_builtin_setvar_helper(chan, "DIALEDTIME", toast);
|
|
||||||
|
|
||||||
if (res != AST_PBX_NO_HANGUP_PEER_PARKED && ast_test_flag64(&opts, OPT_PEER_H)) {
|
if (res != AST_PBX_NO_HANGUP_PEER_PARKED && ast_test_flag64(&opts, OPT_PEER_H)) {
|
||||||
ast_log(LOG_NOTICE, "PEER context: %s; PEER exten: %s; PEER priority: %d\n",
|
ast_log(LOG_NOTICE, "PEER context: %s; PEER exten: %s; PEER priority: %d\n",
|
||||||
peer->context, peer->exten, peer->priority);
|
peer->context, peer->exten, peer->priority);
|
||||||
|
@@ -148,7 +148,6 @@ AST_APP_OPTIONS(followme_opts, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
static int ynlongest = 0;
|
static int ynlongest = 0;
|
||||||
static time_t start_time, answer_time, end_time;
|
|
||||||
|
|
||||||
static const char *featuredigittostr;
|
static const char *featuredigittostr;
|
||||||
static int featuredigittimeout = 5000; /*!< Feature Digit Timeout */
|
static int featuredigittimeout = 5000; /*!< Feature Digit Timeout */
|
||||||
@@ -788,7 +787,6 @@ static void findmeexec(struct fm_args *tpargs)
|
|||||||
while (nm) {
|
while (nm) {
|
||||||
|
|
||||||
ast_debug(2, "Number %s timeout %ld\n", nm->number,nm->timeout);
|
ast_debug(2, "Number %s timeout %ld\n", nm->number,nm->timeout);
|
||||||
time(&start_time);
|
|
||||||
|
|
||||||
number = ast_strdupa(nm->number);
|
number = ast_strdupa(nm->number);
|
||||||
ast_debug(3, "examining %s\n", number);
|
ast_debug(3, "examining %s\n", number);
|
||||||
@@ -964,7 +962,6 @@ static int app_exec(struct ast_channel *chan, void *data)
|
|||||||
int duration = 0;
|
int duration = 0;
|
||||||
struct ast_channel *caller;
|
struct ast_channel *caller;
|
||||||
struct ast_channel *outbound;
|
struct ast_channel *outbound;
|
||||||
static char toast[80];
|
|
||||||
AST_DECLARE_APP_ARGS(args,
|
AST_DECLARE_APP_ARGS(args,
|
||||||
AST_APP_ARG(followmeid);
|
AST_APP_ARG(followmeid);
|
||||||
AST_APP_ARG(options);
|
AST_APP_ARG(options);
|
||||||
@@ -1067,6 +1064,27 @@ static int app_exec(struct ast_channel *chan, void *data)
|
|||||||
ast_stream_and_wait(chan, targs.sorryprompt, "");
|
ast_stream_and_wait(chan, targs.sorryprompt, "");
|
||||||
res = 0;
|
res = 0;
|
||||||
} else {
|
} else {
|
||||||
|
auto void end_bridge_callback(void);
|
||||||
|
void end_bridge_callback (void)
|
||||||
|
{
|
||||||
|
char buf[80];
|
||||||
|
time_t end;
|
||||||
|
|
||||||
|
time(&end);
|
||||||
|
|
||||||
|
ast_channel_lock(chan);
|
||||||
|
if (chan->cdr->answer.tv_sec) {
|
||||||
|
snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->answer.tv_sec);
|
||||||
|
pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chan->cdr->start.tv_sec) {
|
||||||
|
snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->start.tv_sec);
|
||||||
|
pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
|
||||||
|
}
|
||||||
|
ast_channel_unlock(chan);
|
||||||
|
}
|
||||||
|
|
||||||
caller = chan;
|
caller = chan;
|
||||||
outbound = targs.outbound;
|
outbound = targs.outbound;
|
||||||
/* Bridge the two channels. */
|
/* Bridge the two channels. */
|
||||||
@@ -1075,6 +1093,7 @@ static int app_exec(struct ast_channel *chan, void *data)
|
|||||||
ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
|
ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
|
||||||
ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
|
ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
|
||||||
ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
|
ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
|
||||||
|
config.end_bridge_callback = end_bridge_callback;
|
||||||
|
|
||||||
ast_moh_stop(caller);
|
ast_moh_stop(caller);
|
||||||
/* Be sure no generators are left on it */
|
/* Be sure no generators are left on it */
|
||||||
@@ -1086,13 +1105,7 @@ static int app_exec(struct ast_channel *chan, void *data)
|
|||||||
ast_hangup(outbound);
|
ast_hangup(outbound);
|
||||||
goto outrun;
|
goto outrun;
|
||||||
}
|
}
|
||||||
time(&answer_time);
|
|
||||||
res = ast_bridge_call(caller, outbound, &config);
|
res = ast_bridge_call(caller, outbound, &config);
|
||||||
time(&end_time);
|
|
||||||
snprintf(toast, sizeof(toast), "%ld", (long)(end_time - start_time));
|
|
||||||
pbx_builtin_setvar_helper(caller, "DIALEDTIME", toast);
|
|
||||||
snprintf(toast, sizeof(toast), "%ld", (long)(end_time - answer_time));
|
|
||||||
pbx_builtin_setvar_helper(caller, "ANSWEREDTIME", toast);
|
|
||||||
if (outbound)
|
if (outbound)
|
||||||
ast_hangup(outbound);
|
ast_hangup(outbound);
|
||||||
}
|
}
|
||||||
|
@@ -3159,6 +3159,13 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
|
|||||||
int callcompletedinsl;
|
int callcompletedinsl;
|
||||||
struct ao2_iterator memi;
|
struct ao2_iterator memi;
|
||||||
struct ast_datastore *datastore;
|
struct ast_datastore *datastore;
|
||||||
|
auto void end_bridge_callback(void);
|
||||||
|
void end_bridge_callback(void)
|
||||||
|
{
|
||||||
|
ao2_lock(qe->parent);
|
||||||
|
set_queue_variables(qe);
|
||||||
|
ao2_unlock(qe->parent);
|
||||||
|
}
|
||||||
|
|
||||||
ast_channel_lock(qe->chan);
|
ast_channel_lock(qe->chan);
|
||||||
datastore = ast_channel_datastore_find(qe->chan, &dialed_interface_info, NULL);
|
datastore = ast_channel_datastore_find(qe->chan, &dialed_interface_info, NULL);
|
||||||
@@ -3229,6 +3236,8 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bridge_config.end_bridge_callback = end_bridge_callback;
|
||||||
|
|
||||||
/* Hold the lock while we setup the outgoing calls */
|
/* Hold the lock while we setup the outgoing calls */
|
||||||
if (use_weight)
|
if (use_weight)
|
||||||
ao2_lock(queues);
|
ao2_lock(queues);
|
||||||
|
@@ -584,6 +584,7 @@ struct ast_bridge_config {
|
|||||||
const char *start_sound;
|
const char *start_sound;
|
||||||
int firstpass;
|
int firstpass;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
|
void (* end_bridge_callback)(void); /*!< A callback that is called after a bridge attempt */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct chanmon;
|
struct chanmon;
|
||||||
|
@@ -2119,6 +2119,7 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
|
|||||||
int diff;
|
int diff;
|
||||||
int hasfeatures=0;
|
int hasfeatures=0;
|
||||||
int hadfeatures=0;
|
int hadfeatures=0;
|
||||||
|
int autoloopflag;
|
||||||
struct ast_option_header *aoh;
|
struct ast_option_header *aoh;
|
||||||
struct ast_bridge_config backup_config;
|
struct ast_bridge_config backup_config;
|
||||||
struct ast_cdr *bridge_cdr = NULL;
|
struct ast_cdr *bridge_cdr = NULL;
|
||||||
@@ -2379,11 +2380,16 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
|
|||||||
|
|
||||||
}
|
}
|
||||||
before_you_go:
|
before_you_go:
|
||||||
|
if (res != AST_PBX_KEEPALIVE && config->end_bridge_callback) {
|
||||||
|
config->end_bridge_callback();
|
||||||
|
}
|
||||||
|
|
||||||
/* run the hangup exten on the chan object IFF it was NOT involved in a parking situation
|
/* run the hangup exten on the chan object IFF it was NOT involved in a parking situation
|
||||||
* if it were, then chan belongs to a different thread now, and might have been hung up long
|
* if it were, then chan belongs to a different thread now, and might have been hung up long
|
||||||
* ago.
|
* ago.
|
||||||
*/
|
*/
|
||||||
|
autoloopflag = ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP);
|
||||||
|
ast_set_flag(chan, AST_FLAG_IN_AUTOLOOP);
|
||||||
if (res != AST_PBX_KEEPALIVE && !ast_test_flag(&(config->features_caller),AST_FEATURE_NO_H_EXTEN) && ast_exists_extension(chan, chan->context, "h", 1, chan->cid.cid_num)) {
|
if (res != AST_PBX_KEEPALIVE && !ast_test_flag(&(config->features_caller),AST_FEATURE_NO_H_EXTEN) && ast_exists_extension(chan, chan->context, "h", 1, chan->cid.cid_num)) {
|
||||||
struct ast_cdr *swapper;
|
struct ast_cdr *swapper;
|
||||||
char savelastapp[AST_MAX_EXTENSION];
|
char savelastapp[AST_MAX_EXTENSION];
|
||||||
@@ -2427,6 +2433,7 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
|
|||||||
ast_copy_string(bridge_cdr->lastapp, savelastapp, sizeof(bridge_cdr->lastapp));
|
ast_copy_string(bridge_cdr->lastapp, savelastapp, sizeof(bridge_cdr->lastapp));
|
||||||
ast_copy_string(bridge_cdr->lastdata, savelastdata, sizeof(bridge_cdr->lastdata));
|
ast_copy_string(bridge_cdr->lastdata, savelastdata, sizeof(bridge_cdr->lastdata));
|
||||||
}
|
}
|
||||||
|
ast_set2_flag(chan, autoloopflag, AST_FLAG_IN_AUTOLOOP);
|
||||||
|
|
||||||
/* obey the NoCDR() wishes. -- move the DISABLED flag to the bridge CDR if it was set on the channel during the bridge... */
|
/* obey the NoCDR() wishes. -- move the DISABLED flag to the bridge CDR if it was set on the channel during the bridge... */
|
||||||
if (res != AST_PBX_KEEPALIVE) {
|
if (res != AST_PBX_KEEPALIVE) {
|
||||||
|
Reference in New Issue
Block a user