mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 11:42:27 +00:00
app_mf, app_sf: Return -1 if channel hangs up.
The ReceiveMF and ReceiveSF applications currently always return 0, even if a channel has hung up. The call will still end but generally applications are expected to return -1 if the channel has hung up. We now return -1 if a hangup occured to bring this behavior in line with this norm. This has no functional impact, but merely increases conformity with how these modules interact with the PBX core. ASTERISK-29951 #close Change-Id: I234d755050ab8ed58f197c6925b968ba26b14033
This commit is contained in:
committed by
Kevin Harwell
parent
ede4e2099f
commit
b87c5f5124
@@ -226,7 +226,7 @@ static const char sendmf_name[] = "SendMF";
|
|||||||
* \param maxdigits If greater than 0, only read this many digits no matter what
|
* \param maxdigits If greater than 0, only read this many digits no matter what
|
||||||
*
|
*
|
||||||
* \retval 0 if successful
|
* \retval 0 if successful
|
||||||
* \retval -1 if unsuccessful.
|
* \retval -1 if unsuccessful (including hangup).
|
||||||
*/
|
*/
|
||||||
static int read_mf_digits(struct ast_channel *chan, char *buf, int buflen, int timeout, int features, int laxkp, int override, int no_kp, int no_st, int maxdigits) {
|
static int read_mf_digits(struct ast_channel *chan, char *buf, int buflen, int timeout, int features, int laxkp, int override, int no_kp, int no_st, int maxdigits) {
|
||||||
struct ast_dsp *dsp;
|
struct ast_dsp *dsp;
|
||||||
@@ -236,6 +236,7 @@ static int read_mf_digits(struct ast_channel *chan, char *buf, int buflen, int t
|
|||||||
int digits_read = 0;
|
int digits_read = 0;
|
||||||
int is_start_digit = 0;
|
int is_start_digit = 0;
|
||||||
char *str = buf;
|
char *str = buf;
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
if (!(dsp = ast_dsp_new())) {
|
if (!(dsp = ast_dsp_new())) {
|
||||||
ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
|
ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
|
||||||
@@ -318,11 +319,12 @@ static int read_mf_digits(struct ast_channel *chan, char *buf, int buflen, int t
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pbx_builtin_setvar_helper(chan, "RECEIVEMFSTATUS", "HANGUP");
|
pbx_builtin_setvar_helper(chan, "RECEIVEMFSTATUS", "HANGUP");
|
||||||
|
res = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast_dsp_free(dsp);
|
ast_dsp_free(dsp);
|
||||||
ast_debug(3, "channel '%s' - event loop stopped { timeout: %d, remaining_time: %d }\n", ast_channel_name(chan), timeout, remaining_time);
|
ast_debug(3, "channel '%s' - event loop stopped { timeout: %d, remaining_time: %d }\n", ast_channel_name(chan), timeout, remaining_time);
|
||||||
return 0;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_mf_exec(struct ast_channel *chan, const char *data)
|
static int read_mf_exec(struct ast_channel *chan, const char *data)
|
||||||
@@ -334,7 +336,7 @@ static int read_mf_exec(struct ast_channel *chan, const char *data)
|
|||||||
struct ast_flags flags = {0};
|
struct ast_flags flags = {0};
|
||||||
char *optargs[OPT_ARG_ARRAY_SIZE];
|
char *optargs[OPT_ARG_ARRAY_SIZE];
|
||||||
char *argcopy = NULL;
|
char *argcopy = NULL;
|
||||||
int features = 0, maxdigits = 0;
|
int res, features = 0, maxdigits = 0;
|
||||||
|
|
||||||
AST_DECLARE_APP_ARGS(arglist,
|
AST_DECLARE_APP_ARGS(arglist,
|
||||||
AST_APP_ARG(variable);
|
AST_APP_ARG(variable);
|
||||||
@@ -392,15 +394,15 @@ static int read_mf_exec(struct ast_channel *chan, const char *data)
|
|||||||
features |= DSP_DIGITMODE_RELAXDTMF;
|
features |= DSP_DIGITMODE_RELAXDTMF;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_mf_digits(chan, tmp, BUFFER_SIZE, to, features, (ast_test_flag(&flags, OPT_LAX_KP)),
|
res = read_mf_digits(chan, tmp, BUFFER_SIZE, to, features, (ast_test_flag(&flags, OPT_LAX_KP)),
|
||||||
(ast_test_flag(&flags, OPT_KP_OVERRIDE)), (ast_test_flag(&flags, OPT_NO_KP)), (ast_test_flag(&flags, OPT_NO_ST)), maxdigits);
|
(ast_test_flag(&flags, OPT_KP_OVERRIDE)), (ast_test_flag(&flags, OPT_NO_KP)), (ast_test_flag(&flags, OPT_NO_ST)), maxdigits);
|
||||||
pbx_builtin_setvar_helper(chan, arglist.variable, tmp);
|
pbx_builtin_setvar_helper(chan, arglist.variable, tmp);
|
||||||
if (!ast_strlen_zero(tmp)) {
|
if (!ast_strlen_zero(tmp)) {
|
||||||
ast_verb(3, "MF digits received: '%s'\n", tmp);
|
ast_verb(3, "MF digits received: '%s'\n", tmp);
|
||||||
} else {
|
} else if (!res) { /* if channel hung up, don't print anything out */
|
||||||
ast_verb(3, "No MF digits received.\n");
|
ast_verb(3, "No MF digits received.\n");
|
||||||
}
|
}
|
||||||
return 0;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sendmf_exec(struct ast_channel *chan, const char *vdata)
|
static int sendmf_exec(struct ast_channel *chan, const char *vdata)
|
||||||
|
@@ -155,6 +155,21 @@ AST_APP_OPTIONS(read_app_options, {
|
|||||||
static const char *readsf_name = "ReceiveSF";
|
static const char *readsf_name = "ReceiveSF";
|
||||||
static const char sendsf_name[] = "SendSF";
|
static const char sendsf_name[] = "SendSF";
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Detects SF digits on channel using DSP
|
||||||
|
*
|
||||||
|
* \param chan channel on which to read digits
|
||||||
|
* \param buf Buffer in which to store digits
|
||||||
|
* \param buflen Size of buffer
|
||||||
|
* \param timeout ms to wait for all digits before giving up
|
||||||
|
* \param maxdigits Maximum number of digits
|
||||||
|
* \param freq Frequency to use
|
||||||
|
* \param features DSP features
|
||||||
|
* \param extrapulses Whether to recognize extra pulses
|
||||||
|
*
|
||||||
|
* \retval 0 if successful
|
||||||
|
* \retval -1 if unsuccessful (including hangup).
|
||||||
|
*/
|
||||||
static int read_sf_digits(struct ast_channel *chan, char *buf, int buflen, int timeout, int maxdigits, int freq, int features, int extrapulses) {
|
static int read_sf_digits(struct ast_channel *chan, char *buf, int buflen, int timeout, int maxdigits, int freq, int features, int extrapulses) {
|
||||||
/* Bell System Technical Journal 39 (Nov. 1960) */
|
/* Bell System Technical Journal 39 (Nov. 1960) */
|
||||||
#define SF_MIN_OFF 25
|
#define SF_MIN_OFF 25
|
||||||
@@ -169,6 +184,7 @@ static int read_sf_digits(struct ast_channel *chan, char *buf, int buflen, int t
|
|||||||
char *str = buf;
|
char *str = buf;
|
||||||
int hits = 0, digits_read = 0;
|
int hits = 0, digits_read = 0;
|
||||||
unsigned short int sf_on = 0;
|
unsigned short int sf_on = 0;
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
if (!(dsp = ast_dsp_new())) {
|
if (!(dsp = ast_dsp_new())) {
|
||||||
ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
|
ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
|
||||||
@@ -261,7 +277,7 @@ static int read_sf_digits(struct ast_channel *chan, char *buf, int buflen, int t
|
|||||||
ast_debug(2, "Got more than 10 pulses, truncating to 10\n");
|
ast_debug(2, "Got more than 10 pulses, truncating to 10\n");
|
||||||
hits = 0; /* 10 dial pulses = digit 0 */
|
hits = 0; /* 10 dial pulses = digit 0 */
|
||||||
*str++ = hits + '0';
|
*str++ = hits + '0';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (hits == 10) {
|
if (hits == 10) {
|
||||||
hits = 0; /* 10 dial pulses = digit 0 */
|
hits = 0; /* 10 dial pulses = digit 0 */
|
||||||
@@ -281,13 +297,14 @@ static int read_sf_digits(struct ast_channel *chan, char *buf, int buflen, int t
|
|||||||
ast_frfree(frame);
|
ast_frfree(frame);
|
||||||
} else {
|
} else {
|
||||||
pbx_builtin_setvar_helper(chan, "RECEIVESFSTATUS", "HANGUP");
|
pbx_builtin_setvar_helper(chan, "RECEIVESFSTATUS", "HANGUP");
|
||||||
|
res = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dsp) {
|
if (dsp) {
|
||||||
ast_dsp_free(dsp);
|
ast_dsp_free(dsp);
|
||||||
}
|
}
|
||||||
ast_debug(3, "channel '%s' - event loop stopped { timeout: %d, remaining_time: %d }\n", ast_channel_name(chan), timeout, remaining_time);
|
ast_debug(3, "channel '%s' - event loop stopped { timeout: %d, remaining_time: %d }\n", ast_channel_name(chan), timeout, remaining_time);
|
||||||
return 0;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_sf_exec(struct ast_channel *chan, const char *data)
|
static int read_sf_exec(struct ast_channel *chan, const char *data)
|
||||||
@@ -297,7 +314,7 @@ static int read_sf_exec(struct ast_channel *chan, const char *data)
|
|||||||
double tosec;
|
double tosec;
|
||||||
struct ast_flags flags = {0};
|
struct ast_flags flags = {0};
|
||||||
char *argcopy = NULL;
|
char *argcopy = NULL;
|
||||||
int features = 0, digits = 0, to = 0, freq = 2600;
|
int res, features = 0, digits = 0, to = 0, freq = 2600;
|
||||||
|
|
||||||
AST_DECLARE_APP_ARGS(arglist,
|
AST_DECLARE_APP_ARGS(arglist,
|
||||||
AST_APP_ARG(variable);
|
AST_APP_ARG(variable);
|
||||||
@@ -360,14 +377,14 @@ static int read_sf_exec(struct ast_channel *chan, const char *data)
|
|||||||
features |= DSP_DIGITMODE_RELAXDTMF;
|
features |= DSP_DIGITMODE_RELAXDTMF;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_sf_digits(chan, tmp, BUFFER_SIZE, to, digits, freq, features, ast_test_flag(&flags, OPT_EXTRAPULSES));
|
res = read_sf_digits(chan, tmp, BUFFER_SIZE, to, digits, freq, features, ast_test_flag(&flags, OPT_EXTRAPULSES));
|
||||||
pbx_builtin_setvar_helper(chan, arglist.variable, tmp);
|
pbx_builtin_setvar_helper(chan, arglist.variable, tmp);
|
||||||
if (!ast_strlen_zero(tmp)) {
|
if (!ast_strlen_zero(tmp)) {
|
||||||
ast_verb(3, "SF digits received: '%s'\n", tmp);
|
ast_verb(3, "SF digits received: '%s'\n", tmp);
|
||||||
} else {
|
} else if (!res) { /* if channel hung up, don't print anything out */
|
||||||
ast_verb(3, "No SF digits received.\n");
|
ast_verb(3, "No SF digits received.\n");
|
||||||
}
|
}
|
||||||
return 0;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sendsf_exec(struct ast_channel *chan, const char *vdata)
|
static int sendsf_exec(struct ast_channel *chan, const char *vdata)
|
||||||
|
Reference in New Issue
Block a user