Fix timestamp issue with features (bug #4760 with mods)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6268 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.2-netsec
Mark Spencer 20 years ago
parent 6e825f933d
commit 8712d1d7f1

@ -2874,7 +2874,7 @@ static void bridge_playfile(struct ast_channel *chan, struct ast_channel *peer,
check = ast_autoservice_stop(peer); check = ast_autoservice_stop(peer);
} }
static int ast_generic_bridge(int *playitagain, int *playit, struct timeval *start_time, struct ast_channel *c0, struct ast_channel *c1, struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc) static int ast_generic_bridge(int *playitagain, int *playit, struct ast_channel *c0, struct ast_channel *c1, struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc)
{ {
/* Copy voice back and forth between the two channels. Give the peer /* Copy voice back and forth between the two channels. Give the peer
the ability to transfer calls with '#<extension' syntax. */ the ability to transfer calls with '#<extension' syntax. */
@ -2905,7 +2905,7 @@ static int ast_generic_bridge(int *playitagain, int *playit, struct timeval *sta
/* timestamp */ /* timestamp */
if (config->timelimit) { if (config->timelimit) {
/* If there is a time limit, return now */ /* If there is a time limit, return now */
elapsed_ms = ast_tvdiff_ms(ast_tvnow(), *start_time); elapsed_ms = ast_tvdiff_ms(ast_tvnow(), config->start_time);
time_left_ms = config->timelimit - elapsed_ms; time_left_ms = config->timelimit - elapsed_ms;
if (*playitagain && ((ast_test_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING)) || (ast_test_flag(&(config->features_callee), AST_FEATURE_PLAY_WARNING))) && (config->play_warning && time_left_ms <= config->play_warning)) { if (*playitagain && ((ast_test_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING)) || (ast_test_flag(&(config->features_callee), AST_FEATURE_PLAY_WARNING))) && (config->play_warning && time_left_ms <= config->play_warning)) {
@ -3027,7 +3027,6 @@ int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, struct as
int firstpass; int firstpass;
int o0nativeformats; int o0nativeformats;
int o1nativeformats; int o1nativeformats;
struct timeval start_time;
long elapsed_ms=0, time_left_ms=0; long elapsed_ms=0, time_left_ms=0;
int playit=0, playitagain=1, first_time=1; int playit=0, playitagain=1, first_time=1;
@ -3036,7 +3035,8 @@ int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, struct as
config->firstpass = 0; config->firstpass = 0;
/* timestamp */ /* timestamp */
start_time = ast_tvnow(); if (! (config->start_time.tv_sec && config->start_time.tv_usec))
config->start_time = ast_tvnow();
time_left_ms = config->timelimit; time_left_ms = config->timelimit;
if ((ast_test_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING)) && config->start_sound && firstpass) if ((ast_test_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING)) && config->start_sound && firstpass)
@ -3078,7 +3078,7 @@ int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, struct as
for (/* ever */;;) { for (/* ever */;;) {
/* timestamp */ /* timestamp */
if (config->timelimit) { if (config->timelimit) {
elapsed_ms = ast_tvdiff_ms(ast_tvnow(), start_time); elapsed_ms = ast_tvdiff_ms(ast_tvnow(), config->start_time);
time_left_ms = config->timelimit - elapsed_ms; time_left_ms = config->timelimit - elapsed_ms;
if (playitagain && ((ast_test_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING)) || (ast_test_flag(&(config->features_callee), AST_FEATURE_PLAY_WARNING))) && (config->play_warning && time_left_ms <= config->play_warning)) { if (playitagain && ((ast_test_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING)) || (ast_test_flag(&(config->features_callee), AST_FEATURE_PLAY_WARNING))) && (config->play_warning && time_left_ms <= config->play_warning)) {
@ -3195,7 +3195,7 @@ int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, struct as
o0nativeformats = c0->nativeformats; o0nativeformats = c0->nativeformats;
o1nativeformats = c1->nativeformats; o1nativeformats = c1->nativeformats;
} }
res = ast_generic_bridge(&playitagain, &playit, &start_time, c0, c1, config, fo, rc); res = ast_generic_bridge(&playitagain, &playit, c0, c1, config, fo, rc);
if (res != -3) if (res != -3)
break; break;
} }

@ -370,6 +370,8 @@ struct ast_channel {
struct ast_bridge_config { struct ast_bridge_config {
struct ast_flags features_caller; struct ast_flags features_caller;
struct ast_flags features_callee; struct ast_flags features_callee;
struct timeval start_time;
long feature_timer;
long timelimit; long timelimit;
long play_warning; long play_warning;
long warning_freq; long warning_freq;

@ -1118,6 +1118,8 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
memset(&backup_config, 0, sizeof(backup_config)); memset(&backup_config, 0, sizeof(backup_config));
config->start_time = ast_tvnow();
if (chan && peer) { if (chan && peer) {
pbx_builtin_setvar_helper(chan, "BRIDGEPEER", peer->name); pbx_builtin_setvar_helper(chan, "BRIDGEPEER", peer->name);
pbx_builtin_setvar_helper(peer, "BRIDGEPEER", chan->name); pbx_builtin_setvar_helper(peer, "BRIDGEPEER", chan->name);
@ -1161,26 +1163,28 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
peer->cdr = NULL; peer->cdr = NULL;
} }
for (;;) { for (;;) {
if (config->timelimit) if (config->feature_timer)
start = ast_tvnow(); start = ast_tvnow();
res = ast_channel_bridge(chan, peer, config, &f, &who); res = ast_channel_bridge(chan, peer, config, &f, &who);
if (config->timelimit) {
if (config->feature_timer) {
/* Update time limit for next pass */ /* Update time limit for next pass */
diff = ast_tvdiff_ms(ast_tvnow(), start); diff = ast_tvdiff_ms(ast_tvnow(), start);
config->timelimit -= diff; config->feature_timer -= diff;
if (hasfeatures) { if (hasfeatures) {
/* Running on backup config, meaning a feature might be being /* Running on backup config, meaning a feature might be being
activated, but that's no excuse to keep things going activated, but that's no excuse to keep things going
indefinitely! */ indefinitely! */
if (backup_config.timelimit && ((backup_config.timelimit -= diff) <= 0)) { if (backup_config.feature_timer && ((backup_config.feature_timer -= diff) <= 0)) {
ast_log(LOG_DEBUG, "Timed out, realtime this time!\n"); ast_log(LOG_DEBUG, "Timed out, realtime this time!\n");
config->timelimit = 0; config->feature_timer = 0;
who = chan; who = chan;
if (f) if (f)
ast_frfree(f); ast_frfree(f);
f = NULL; f = NULL;
res = 0; res = 0;
} else if (config->timelimit <= 0) { } else if (config->feature_timer <= 0) {
/* Not *really* out of time, just out of time for /* Not *really* out of time, just out of time for
digits to come in for features. */ digits to come in for features. */
ast_log(LOG_DEBUG, "Timed out for feature!\n"); ast_log(LOG_DEBUG, "Timed out for feature!\n");
@ -1205,9 +1209,9 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
continue; continue;
} }
} else { } else {
if (config->timelimit <=0) { if (config->feature_timer <=0) {
/* We ran out of time */ /* We ran out of time */
config->timelimit = 0; config->feature_timer = 0;
who = chan; who = chan;
if (f) if (f)
ast_frfree(f); ast_frfree(f);
@ -1272,7 +1276,7 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
featurecode = peer_featurecode; featurecode = peer_featurecode;
} }
featurecode[strlen(featurecode)] = f->subclass; featurecode[strlen(featurecode)] = f->subclass;
config->timelimit = backup_config.timelimit; config->feature_timer = backup_config.feature_timer;
res = ast_feature_interpret(chan, peer, config, featurecode, sense); res = ast_feature_interpret(chan, peer, config, featurecode, sense);
switch(res) { switch(res) {
case FEATURE_RETURN_PASSDIGITS: case FEATURE_RETURN_PASSDIGITS:
@ -1307,8 +1311,8 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
config->start_sound = NULL; config->start_sound = NULL;
config->firstpass = 0; config->firstpass = 0;
} }
config->timelimit = featuredigittimeout; config->feature_timer = featuredigittimeout;
ast_log(LOG_DEBUG, "Set time limit to %ld\n", config->timelimit); ast_log(LOG_DEBUG, "Set time limit to %ld\n", config->feature_timer);
} }
} }
if (f) if (f)

Loading…
Cancel
Save