Skip to content

Commit b87c5f5

Browse files
InterLinked1kharwell
authored andcommitted
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
1 parent ede4e20 commit b87c5f5

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

apps/app_mf.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static const char sendmf_name[] = "SendMF";
226226
* \param maxdigits If greater than 0, only read this many digits no matter what
227227
*
228228
* \retval 0 if successful
229-
* \retval -1 if unsuccessful.
229+
* \retval -1 if unsuccessful (including hangup).
230230
*/
231231
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) {
232232
struct ast_dsp *dsp;
@@ -236,6 +236,7 @@ static int read_mf_digits(struct ast_channel *chan, char *buf, int buflen, int t
236236
int digits_read = 0;
237237
int is_start_digit = 0;
238238
char *str = buf;
239+
int res = 0;
239240

240241
if (!(dsp = ast_dsp_new())) {
241242
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
318319
}
319320
} else {
320321
pbx_builtin_setvar_helper(chan, "RECEIVEMFSTATUS", "HANGUP");
322+
res = -1;
321323
}
322324
}
323325
ast_dsp_free(dsp);
324326
ast_debug(3, "channel '%s' - event loop stopped { timeout: %d, remaining_time: %d }\n", ast_channel_name(chan), timeout, remaining_time);
325-
return 0;
327+
return res;
326328
}
327329

328330
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)
334336
struct ast_flags flags = {0};
335337
char *optargs[OPT_ARG_ARRAY_SIZE];
336338
char *argcopy = NULL;
337-
int features = 0, maxdigits = 0;
339+
int res, features = 0, maxdigits = 0;
338340

339341
AST_DECLARE_APP_ARGS(arglist,
340342
AST_APP_ARG(variable);
@@ -392,15 +394,15 @@ static int read_mf_exec(struct ast_channel *chan, const char *data)
392394
features |= DSP_DIGITMODE_RELAXDTMF;
393395
}
394396

395-
read_mf_digits(chan, tmp, BUFFER_SIZE, to, features, (ast_test_flag(&flags, OPT_LAX_KP)),
397+
res = read_mf_digits(chan, tmp, BUFFER_SIZE, to, features, (ast_test_flag(&flags, OPT_LAX_KP)),
396398
(ast_test_flag(&flags, OPT_KP_OVERRIDE)), (ast_test_flag(&flags, OPT_NO_KP)), (ast_test_flag(&flags, OPT_NO_ST)), maxdigits);
397399
pbx_builtin_setvar_helper(chan, arglist.variable, tmp);
398400
if (!ast_strlen_zero(tmp)) {
399401
ast_verb(3, "MF digits received: '%s'\n", tmp);
400-
} else {
402+
} else if (!res) { /* if channel hung up, don't print anything out */
401403
ast_verb(3, "No MF digits received.\n");
402404
}
403-
return 0;
405+
return res;
404406
}
405407

406408
static int sendmf_exec(struct ast_channel *chan, const char *vdata)

apps/app_sf.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ AST_APP_OPTIONS(read_app_options, {
155155
static const char *readsf_name = "ReceiveSF";
156156
static const char sendsf_name[] = "SendSF";
157157

158+
/*!
159+
* \brief Detects SF digits on channel using DSP
160+
*
161+
* \param chan channel on which to read digits
162+
* \param buf Buffer in which to store digits
163+
* \param buflen Size of buffer
164+
* \param timeout ms to wait for all digits before giving up
165+
* \param maxdigits Maximum number of digits
166+
* \param freq Frequency to use
167+
* \param features DSP features
168+
* \param extrapulses Whether to recognize extra pulses
169+
*
170+
* \retval 0 if successful
171+
* \retval -1 if unsuccessful (including hangup).
172+
*/
158173
static int read_sf_digits(struct ast_channel *chan, char *buf, int buflen, int timeout, int maxdigits, int freq, int features, int extrapulses) {
159174
/* Bell System Technical Journal 39 (Nov. 1960) */
160175
#define SF_MIN_OFF 25
@@ -169,6 +184,7 @@ static int read_sf_digits(struct ast_channel *chan, char *buf, int buflen, int t
169184
char *str = buf;
170185
int hits = 0, digits_read = 0;
171186
unsigned short int sf_on = 0;
187+
int res = 0;
172188

173189
if (!(dsp = ast_dsp_new())) {
174190
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
261277
ast_debug(2, "Got more than 10 pulses, truncating to 10\n");
262278
hits = 0; /* 10 dial pulses = digit 0 */
263279
*str++ = hits + '0';
264-
}
280+
}
265281
} else {
266282
if (hits == 10) {
267283
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
281297
ast_frfree(frame);
282298
} else {
283299
pbx_builtin_setvar_helper(chan, "RECEIVESFSTATUS", "HANGUP");
300+
res = -1;
284301
}
285302
}
286303
if (dsp) {
287304
ast_dsp_free(dsp);
288305
}
289306
ast_debug(3, "channel '%s' - event loop stopped { timeout: %d, remaining_time: %d }\n", ast_channel_name(chan), timeout, remaining_time);
290-
return 0;
307+
return res;
291308
}
292309

293310
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)
297314
double tosec;
298315
struct ast_flags flags = {0};
299316
char *argcopy = NULL;
300-
int features = 0, digits = 0, to = 0, freq = 2600;
317+
int res, features = 0, digits = 0, to = 0, freq = 2600;
301318

302319
AST_DECLARE_APP_ARGS(arglist,
303320
AST_APP_ARG(variable);
@@ -360,14 +377,14 @@ static int read_sf_exec(struct ast_channel *chan, const char *data)
360377
features |= DSP_DIGITMODE_RELAXDTMF;
361378
}
362379

363-
read_sf_digits(chan, tmp, BUFFER_SIZE, to, digits, freq, features, ast_test_flag(&flags, OPT_EXTRAPULSES));
380+
res = read_sf_digits(chan, tmp, BUFFER_SIZE, to, digits, freq, features, ast_test_flag(&flags, OPT_EXTRAPULSES));
364381
pbx_builtin_setvar_helper(chan, arglist.variable, tmp);
365382
if (!ast_strlen_zero(tmp)) {
366383
ast_verb(3, "SF digits received: '%s'\n", tmp);
367-
} else {
384+
} else if (!res) { /* if channel hung up, don't print anything out */
368385
ast_verb(3, "No SF digits received.\n");
369386
}
370-
return 0;
387+
return res;
371388
}
372389

373390
static int sendsf_exec(struct ast_channel *chan, const char *vdata)

0 commit comments

Comments
 (0)