--- app_dial.old 2009-03-04 09:40:12.000000000 -0500 +++ app_dial.c 2009-03-13 16:03:51.000000000 -0400 @@ -37,6 +37,7 @@ #include #include #include +#include #include #include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */ @@ -60,6 +61,7 @@ #include "asterisk/privacy.h" #include "asterisk/stringfields.h" #include "asterisk/global_datastores.h" +#include "asterisk/mod_format.h" static char *app = "Dial"; @@ -182,11 +184,11 @@ " will cause the phone to ring back immediately. With a 2 specified,\n" " when the \"operator\" flashes the trunk, it will ring their phone\n" " back.\n" -" p - This option enables screening mode. This is basically Privacy mode\n" -" without memory.\n" -" P([x]) - Enable privacy mode. Use 'x' as the family/key in the database if\n" -" it is provided. The current extension is used if a database\n" -" family/key is not specified.\n" +" p - This option enables screening mode for every call.\n" +" P([x]) - Enable privacy mode based on caller ID. For a first time caller,\n" +" the called party is given a choice for future actions for that\n" +" caller. Use 'x' as the family/key in the database if it is provided.\n" +" The current extension is used if a database family/key is not specified.\n" " r - Indicate ringing to the calling party. Pass no audio to the calling\n" " party until the called channel has answered.\n" " S(x) - Hang up the call after 'x' seconds *after* the called party has\n" @@ -1163,7 +1165,7 @@ } else if (ast_test_flag64(opts, OPT_SCREEN_NOCLID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) { ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val); } - + if (pa->privdb_val == AST_PRIVACY_DENY) { ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n"); ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status)); @@ -1187,7 +1189,25 @@ } snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid); - if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) { + + /* See if the recorded introduction file already exists. + If we don't want introductions to persist, get rid of any from a prior incompleted call + because it could be a different person calling from the same office. + However, if the dial plan allows trying additional extensions, don't ask more than once in the same call. + We determine this by checking the file time against the starting time of the call. */ + res = -1; + if (ast_openstream(chan, pa->privintro, NULL)) { + struct stat introstat; + res = 1; + fstat(fileno(chan->stream->f), &introstat); + ast_closestream(chan->stream); + if (ast_test_flag64(opts, OPT_SCREEN_NOINTRO) && chan->cdr && introstat.st_mtime <= chan->cdr->start.tv_sec) { + ast_filedelete(pa->privintro, NULL); + res = -1; + } + } + + if (res > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) { /* the DELUX version of this code would allow this caller the option to hear and retape their previously recorded intro. */ @@ -1318,7 +1338,7 @@ opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]); ast_verb(3, "Setting operator services mode to %d.\n", opermode); } - + if (ast_test_flag64(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) { calldurationlimit = atoi(opt_args[OPT_ARG_DURATION_STOP]); if (!calldurationlimit) { @@ -1477,7 +1497,7 @@ /* Setup outgoing SDP to match incoming one */ ast_rtp_make_compatible(tc, chan, !outgoing && !rest); - + /* Inherit specially named variables from parent channel */ ast_channel_inherit_variables(chan, tc); ast_channel_datastore_inherit(chan, tc); @@ -1490,7 +1510,7 @@ S_REPLACE(tc->cid.cid_name, ast_strdup(chan->cid.cid_name)); S_REPLACE(tc->cid.cid_ani, ast_strdup(chan->cid.cid_ani)); S_REPLACE(tc->cid.cid_rdnis, ast_strdup(chan->cid.cid_rdnis)); - + /* Copy language from incoming to outgoing */ ast_string_field_set(tc, language, chan->language); ast_string_field_set(tc, accountcode, chan->accountcode); @@ -1554,7 +1574,7 @@ if (outgoing->chan->_state == AST_STATE_UP) break; } - + if (ast_strlen_zero(args.timeout)) { to = -1; } else { @@ -1878,7 +1898,7 @@ config.end_bridge_callback = end_bridge_callback; config.end_bridge_callback_data = chan; config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup; - + if (moh) { moh = 0; ast_moh_stop(chan); @@ -1948,7 +1968,7 @@ pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status); senddialendevent(chan, pa.status); ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status); - + if (ast_test_flag64(peerflags, OPT_GO_ON) && !ast_check_hangup(chan)) { if (calldurationlimit) chan->whentohangup = 0;