Skip to content

Commit 0da7131

Browse files
InterLinked1Friendly Automation
authored and
Friendly Automation
committed
app_mf: Add max digits option to ReceiveMF.
Adds an option to the ReceiveMF application to allow specifying a maximum number of digits. Originally, this capability was not added to ReceiveMF as it was with ReceiveSF because typically a ST digit is used to denote that sending of digits is complete. However, there are certain signaling protocols which simply transmit a digit (such as Expanded In-Band Signaling) and for these, it's necessary to be able to read a certain number of digits, as opposed to until receiving a ST digit. This capability is added as an option, as opposed to as a parameter, to remain compatible with existing usage (and not shift the parameters). ASTERISK-29877 #close Change-Id: I4229167c9aa69b87402c3c2a9065bd8dfa973a0b
1 parent 585c2d1 commit 0da7131

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

apps/app_mf.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
<option name="m">
7272
<para>Mute conference.</para>
7373
</option>
74+
<option name="n">
75+
<para>Maximum number of digits, regardless of the sequence.</para>
76+
</option>
7477
<option name="o">
7578
<para>Enable override. Repeated KPs will clear all previous digits.</para>
7679
</option>
@@ -179,13 +182,21 @@ enum read_option_flags {
179182
OPT_NO_KP = (1 << 6),
180183
OPT_NO_ST = (1 << 7),
181184
OPT_KP_OVERRIDE = (1 << 8),
185+
OPT_MAXDIGITS = (1 << 9),
186+
};
187+
188+
enum {
189+
OPT_ARG_MAXDIGITS,
190+
/* Must be the last element */
191+
OPT_ARG_ARRAY_SIZE,
182192
};
183193

184194
AST_APP_OPTIONS(read_app_options, {
185195
AST_APP_OPTION('d', OPT_DELAY),
186196
AST_APP_OPTION('l', OPT_LAX_KP),
187197
AST_APP_OPTION('k', OPT_NO_KP),
188198
AST_APP_OPTION('m', OPT_MUTE),
199+
AST_APP_OPTION_ARG('n', OPT_MAXDIGITS, OPT_ARG_MAXDIGITS),
189200
AST_APP_OPTION('o', OPT_KP_OVERRIDE),
190201
AST_APP_OPTION('p', OPT_PROCESS),
191202
AST_APP_OPTION('q', OPT_QUELCH),
@@ -212,11 +223,12 @@ static const char sendmf_name[] = "SendMF";
212223
* \param override Start over if we receive additional KPs
213224
* \param no_kp Don't include KP in the output
214225
* \param no_st Don't include start digits in the output
226+
* \param maxdigits If greater than 0, only read this many digits no matter what
215227
*
216228
* \retval 0 if successful
217229
* \retval -1 if unsuccessful.
218230
*/
219-
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) {
231+
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) {
220232
struct ast_dsp *dsp;
221233
struct ast_frame *frame = NULL;
222234
struct timeval start;
@@ -245,7 +257,7 @@ static int read_mf_digits(struct ast_channel *chan, char *buf, int buflen, int t
245257
break;
246258
}
247259
}
248-
if (digits_read >= (buflen - 1)) { /* we don't have room to store any more digits (very unlikely to happen for a legitimate reason) */
260+
if ((maxdigits && digits_read >= maxdigits) || digits_read >= (buflen - 1)) { /* we don't have room to store any more digits (very unlikely to happen for a legitimate reason) */
249261
/* This result will probably not be usable, so status should not be START */
250262
pbx_builtin_setvar_helper(chan, "RECEIVEMFSTATUS", "MAXDIGITS");
251263
break;
@@ -320,8 +332,9 @@ static int read_mf_exec(struct ast_channel *chan, const char *data)
320332
int to = 0;
321333
double tosec;
322334
struct ast_flags flags = {0};
335+
char *optargs[OPT_ARG_ARRAY_SIZE];
323336
char *argcopy = NULL;
324-
int features = 0;
337+
int features = 0, maxdigits = 0;
325338

326339
AST_DECLARE_APP_ARGS(arglist,
327340
AST_APP_ARG(variable);
@@ -339,7 +352,7 @@ static int read_mf_exec(struct ast_channel *chan, const char *data)
339352
AST_STANDARD_APP_ARGS(arglist, argcopy);
340353

341354
if (!ast_strlen_zero(arglist.options)) {
342-
ast_app_parse_options(read_app_options, &flags, NULL, arglist.options);
355+
ast_app_parse_options(read_app_options, &flags, optargs, arglist.options);
343356
}
344357

345358
if (!ast_strlen_zero(arglist.timeout)) {
@@ -355,6 +368,13 @@ static int read_mf_exec(struct ast_channel *chan, const char *data)
355368
ast_log(LOG_WARNING, "Invalid! Usage: ReceiveMF(variable[,timeout][,option])\n");
356369
return -1;
357370
}
371+
if (ast_test_flag(&flags, OPT_MAXDIGITS) && !ast_strlen_zero(optargs[OPT_ARG_MAXDIGITS])) {
372+
maxdigits = atoi(optargs[OPT_ARG_MAXDIGITS]);
373+
if (maxdigits <= 0) {
374+
ast_log(LOG_WARNING, "Invalid maximum number of digits, ignoring: '%s'\n", optargs[OPT_ARG_MAXDIGITS]);
375+
maxdigits = 0;
376+
}
377+
}
358378

359379
if (ast_test_flag(&flags, OPT_DELAY)) {
360380
features |= DSP_DIGITMODE_MUTEMAX;
@@ -373,7 +393,7 @@ static int read_mf_exec(struct ast_channel *chan, const char *data)
373393
}
374394

375395
read_mf_digits(chan, tmp, BUFFER_SIZE, to, features, (ast_test_flag(&flags, OPT_LAX_KP)),
376-
(ast_test_flag(&flags, OPT_KP_OVERRIDE)), (ast_test_flag(&flags, OPT_NO_KP)), (ast_test_flag(&flags, OPT_NO_ST)));
396+
(ast_test_flag(&flags, OPT_KP_OVERRIDE)), (ast_test_flag(&flags, OPT_NO_KP)), (ast_test_flag(&flags, OPT_NO_ST)), maxdigits);
377397
pbx_builtin_setvar_helper(chan, arglist.variable, tmp);
378398
if (!ast_strlen_zero(tmp)) {
379399
ast_verb(3, "MF digits received: '%s'\n", tmp);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Subject: app_mf
2+
3+
Adds an option to ReceiveMF to cap the
4+
number of digits read at a user-specified
5+
maximum.

0 commit comments

Comments
 (0)