Index: res/res_features.c =================================================================== --- res/res_features.c (revision 49097) +++ res/res_features.c (working copy) @@ -92,6 +92,10 @@ static char xfersound[256]; /*!< Call transfer sound */ static char xferfailsound[256]; /*!< Call transfer failure sound */ +static char automon_name[256]; +static char automon_courtesy_start[256]; +static char automon_courtesy_stop[256]; + static int parking_offset; static int parkfindnext; @@ -526,7 +530,8 @@ static int builtin_automonitor(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense) { - char *caller_chan_id = NULL, *callee_chan_id = NULL, *args = NULL, *touch_filename = NULL; + char *caller_chan_id = NULL, *callee_chan_id = NULL, *args = NULL, *touch_filename = NULL, + *courtesy = NULL; int x = 0; size_t len; struct ast_channel *caller_chan, *callee_chan; @@ -544,11 +549,12 @@ set_peers(&caller_chan, &callee_chan, peer, chan, sense); - if (!ast_strlen_zero(courtesytone)) { + courtesy = S_OR((callee_chan->monitor) ? automon_courtesy_stop : automon_courtesy_start, courtesytone); + if (!ast_strlen_zero(courtesy)) { if (ast_autoservice_start(callee_chan)) return -1; - if (ast_stream_and_wait(caller_chan, courtesytone, "")) { - ast_log(LOG_WARNING, "Failed to play courtesy tone!\n"); + if (ast_stream_and_wait(caller_chan, courtesy, "")) { + ast_log(LOG_WARNING, "Failed to play courtesy tone : %s !\n", courtesy); ast_autoservice_stop(callee_chan); return -1; } @@ -573,21 +579,27 @@ if (!touch_monitor) touch_monitor = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MONITOR"); - if (touch_monitor) { - len = strlen(touch_monitor) + 50; - args = alloca(len); - touch_filename = alloca(len); - snprintf(touch_filename, len, "auto-%ld-%s", (long)time(NULL), touch_monitor); - snprintf(args, len, "%s|%s|m", (touch_format) ? touch_format : "wav", touch_filename); + caller_chan_id = ast_strdupa(S_OR(caller_chan->cid.cid_num, caller_chan->name)); + callee_chan_id = ast_strdupa(S_OR(callee_chan->cid.cid_num, callee_chan->name)); + pbx_builtin_setvar_helper(chan, "AUTOMON_CALLER", caller_chan_id); + pbx_builtin_setvar_helper(chan, "AUTOMON_CALLEE", callee_chan_id); + pbx_builtin_setvar_helper(chan, "AUTOMON_TOUCH_MONITOR", touch_monitor); + len = strlen(caller_chan_id) + strlen(callee_chan_id) + + ((touch_format) ? strlen(touch_format) : 0) + + ((touch_monitor) ? strlen(touch_monitor) : 0) + 256; + touch_filename = alloca(len); + if (!ast_strlen_zero(automon_name)) { + pbx_substitute_variables_helper(chan, automon_name, touch_filename, len); + } else if (touch_monitor) { + pbx_substitute_variables_helper(chan, "auto-${EPOCH}-${AUTOMON_TOUCH_MONITOR}", touch_filename, len); } else { - caller_chan_id = ast_strdupa(S_OR(caller_chan->cid.cid_num, caller_chan->name)); - callee_chan_id = ast_strdupa(S_OR(callee_chan->cid.cid_num, callee_chan->name)); - len = strlen(caller_chan_id) + strlen(callee_chan_id) + 50; - args = alloca(len); - touch_filename = alloca(len); - snprintf(touch_filename, len, "auto-%ld-%s-%s", (long)time(NULL), caller_chan_id, callee_chan_id); - snprintf(args, len, "%s|%s|m", S_OR(touch_format, "wav"), touch_filename); + pbx_substitute_variables_helper(chan, "auto-${EPOCH}-${AUTOMON_CALLER}-${AUTOMON_CALLEE}", touch_filename, len); } + pbx_builtin_setvar_helper(chan, "AUTOMON_CALLER", NULL); + pbx_builtin_setvar_helper(chan, "AUTOMON_CALLEE", NULL); + pbx_builtin_setvar_helper(chan, "AUTOMON_TOUCH_MONITOR", NULL); + args = alloca(len); + snprintf(args, len, "%s|%s|m", S_OR(touch_format, "wav"), touch_filename); for( x = 0; x < strlen(args); x++) { if (args[x] == '/') @@ -2108,6 +2120,9 @@ courtesytone[0] = '\0'; strcpy(xfersound, "beep"); strcpy(xferfailsound, "pbx-invalid"); + automon_name[0] = '\0'; + automon_courtesy_start[0] = '\0'; + automon_courtesy_stop[0] = '\0'; parking_start = 701; parking_stop = 750; parkfindnext = 0; @@ -2167,6 +2182,12 @@ atxfernoanswertimeout = atxfernoanswertimeout * 1000; } else if (!strcasecmp(var->name, "courtesytone")) { ast_copy_string(courtesytone, var->value, sizeof(courtesytone)); + } else if (!strcasecmp(var->name, "automon_courtesy_start")) { + ast_copy_string(automon_courtesy_start, var->value, sizeof(automon_courtesy_start)); + } else if (!strcasecmp(var->name, "automon_courtesy_stop")) { + ast_copy_string(automon_courtesy_stop, var->value, sizeof(automon_courtesy_stop)); + } else if (!strcasecmp(var->name, "automon_name")) { + ast_copy_string(automon_name, var->value, sizeof(automon_name)); } else if (!strcasecmp(var->name, "parkedplay")) { if (!strcasecmp(var->value, "both")) parkedplay = 2;