[Asterisk-code-review] app_read: Allow reading # as a digit (asterisk[master])
N A
asteriskteam at digium.com
Wed Aug 25 06:51:08 CDT 2021
N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/16352 )
Change subject: app_read: Allow reading # as a digit
......................................................................
app_read: Allow reading # as a digit
Allows for the digit # to be read as a digit,
just like any other DTMF digit, as opposed to
forcing it to be used as an end of input
indicator. The default behavior remains
unchanged.
ASTERISK-29615 #close
Change-Id: I3033432adb9d296ad227e76b540b8b4a2417665b
---
M apps/app_authenticate.c
M apps/app_confbridge.c
M apps/app_dictate.c
M apps/app_meetme.c
M apps/app_read.c
M apps/app_test.c
M apps/app_voicemail.c
A doc/CHANGES-staging/app_read.txt
M include/asterisk/app.h
M main/app.c
10 files changed, 31 insertions(+), 15 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/52/16352/1
diff --git a/apps/app_authenticate.c b/apps/app_authenticate.c
index 3ec04b7..7fd6a0b 100644
--- a/apps/app_authenticate.c
+++ b/apps/app_authenticate.c
@@ -159,7 +159,7 @@
/* Start asking for password */
for (retries = 0; retries < 3; retries++) {
- if ((res = ast_app_getdata(chan, prompt, passwd, maxdigits, 0)) < 0)
+ if ((res = ast_app_getdata(chan, prompt, passwd, maxdigits, 0, NULL)) < 0)
break;
res = 0;
diff --git a/apps/app_confbridge.c b/apps/app_confbridge.c
index 4290521..1eff43a 100644
--- a/apps/app_confbridge.c
+++ b/apps/app_confbridge.c
@@ -2364,7 +2364,7 @@
for (i = 0; i < 3; i++) {
if (ast_app_getdata(chan,
conf_get_sound(CONF_SOUND_GET_PIN, user->b_profile.sounds),
- tmp, len, 0) >= 0) {
+ tmp, len, 0, NULL) >= 0) {
if (!strcasecmp(pin, pin_guess)) {
return 0;
}
diff --git a/apps/app_dictate.c b/apps/app_dictate.c
index c64f275..d19bfe9 100644
--- a/apps/app_dictate.c
+++ b/apps/app_dictate.c
@@ -137,7 +137,7 @@
ast_safe_sleep(chan, 200);
for (res = 0; !res;) {
if (ast_strlen_zero(filename)) {
- if (ast_app_getdata(chan, "dictate/enter_filename", filein, sizeof(filein), 0) ||
+ if (ast_app_getdata(chan, "dictate/enter_filename", filein, sizeof(filein), 0, NULL) ||
ast_strlen_zero(filein)) {
res = -1;
break;
diff --git a/apps/app_meetme.c b/apps/app_meetme.c
index 27d985b..28eab5d 100644
--- a/apps/app_meetme.c
+++ b/apps/app_meetme.c
@@ -4721,7 +4721,7 @@
if (dynamic_pin) {
if (dynamic_pin[0] == 'q') {
/* Query the user to enter a PIN */
- if (ast_app_getdata(chan, "conf-getpin", dynamic_pin, pin_buf_len - 1, 0) < 0)
+ if (ast_app_getdata(chan, "conf-getpin", dynamic_pin, pin_buf_len - 1, 0, NULL) < 0)
return NULL;
}
cnf = build_conf(confno, dynamic_pin, "", make, dynamic, refcount, chan, NULL);
@@ -5015,7 +5015,7 @@
while (allowretry && (ast_strlen_zero(confno)) && (++retrycnt < 4)) {
/* Prompt user for conference number */
- res = ast_app_getdata(chan, "conf-getconfno", confno, sizeof(confno) - 1, 0);
+ res = ast_app_getdata(chan, "conf-getconfno", confno, sizeof(confno) - 1, 0, NULL);
if (res < 0) {
/* Don't try to validate when we catch an error */
confno[0] = '\0';
@@ -5079,7 +5079,7 @@
ast_test_suite_event_notify("PLAYBACK", "Message: conf-getpin\r\n"
"Channel: %s",
ast_channel_name(chan));
- res = ast_app_getdata(chan, "conf-getpin", pin + strlen(pin), sizeof(pin) - 1 - strlen(pin), 0);
+ res = ast_app_getdata(chan, "conf-getpin", pin + strlen(pin), sizeof(pin) - 1 - strlen(pin), 0, NULL);
}
if (res >= 0) {
if ((!strcasecmp(pin, cnf->pin) &&
diff --git a/apps/app_read.c b/apps/app_read.c
index 6398281..95890f1 100644
--- a/apps/app_read.c
+++ b/apps/app_read.c
@@ -75,6 +75,13 @@
<option name="n">
<para>to read digits even if the line is not up.</para>
</option>
+ <option name="p">
+ <para>to read <literal>#</literal> as a digit and not
+ an end of input indicator. This will not terminate
+ input and will include <literal>#</literal> in the
+ string of digits entered. You will need to rely
+ on duration and max digits for ending input.</para>
+ </option>
</optionlist>
</parameter>
<parameter name="attempts">
@@ -114,12 +121,14 @@
OPT_SKIP = (1 << 0),
OPT_INDICATION = (1 << 1),
OPT_NOANSWER = (1 << 2),
+ OPT_POUND = (1 << 3),
};
AST_APP_OPTIONS(read_app_options, {
AST_APP_OPTION('s', OPT_SKIP),
AST_APP_OPTION('i', OPT_INDICATION),
AST_APP_OPTION('n', OPT_NOANSWER),
+ AST_APP_OPTION('p', OPT_POUND),
});
static char *app = "Read";
@@ -223,7 +232,7 @@
break;
}
tmp[x++] = res;
- if (tmp[x-1] == '#') {
+ if (tmp[x-1] == '#' && !ast_test_flag(&flags, OPT_POUND)) {
tmp[x-1] = '\0';
status = "OK";
break;
@@ -233,7 +242,7 @@
}
}
} else {
- res = ast_app_getdata(chan, arglist.filename, tmp, maxdigits, to);
+ res = ast_app_getdata(chan, arglist.filename, tmp, maxdigits, to, (ast_test_flag(&flags, OPT_POUND) ? "" : NULL));
if (res == AST_GETDATA_COMPLETE || res == AST_GETDATA_EMPTY_END_TERMINATED)
status = "OK";
else if (res == AST_GETDATA_TIMEOUT)
diff --git a/apps/app_test.c b/apps/app_test.c
index 9677270..9289bca 100644
--- a/apps/app_test.c
+++ b/apps/app_test.c
@@ -178,7 +178,7 @@
/* Read server version */
ast_debug(1, "Read server version\n");
if (!res)
- res = ast_app_getdata(chan, NULL, serverver, sizeof(serverver) - 1, 0);
+ res = ast_app_getdata(chan, NULL, serverver, sizeof(serverver) - 1, 0, NULL);
if (res > 0)
res = 0;
ast_debug(1, "server version: %s\n", serverver);
@@ -336,7 +336,7 @@
/* Read version */
ast_debug(1, "Read client version\n");
if (!res)
- res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0);
+ res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0, NULL);
if (res > 0)
res = 0;
@@ -350,7 +350,7 @@
res = 0;
if (!res)
- res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0);
+ res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0, NULL);
ast_debug(1, "read test identifier: %s\n", testid);
/* Check for sneakyness */
if (strchr(testid, '/'))
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index db531e9..4b242ef 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -12318,7 +12318,7 @@
}
} else {
char temp[256];
- res = ast_app_getdata(chan, "vm-whichbox", temp, sizeof(temp) - 1, 0);
+ res = ast_app_getdata(chan, "vm-whichbox", temp, sizeof(temp) - 1, 0, NULL);
if (res < 0)
return res;
if (ast_strlen_zero(temp))
diff --git a/doc/CHANGES-staging/app_read.txt b/doc/CHANGES-staging/app_read.txt
new file mode 100644
index 0000000..df3247c
--- /dev/null
+++ b/doc/CHANGES-staging/app_read.txt
@@ -0,0 +1,5 @@
+Subject: app_read
+
+A new option allows the digit '#' to be read literally,
+rather than used exclusively as the input terminator
+character.
diff --git a/include/asterisk/app.h b/include/asterisk/app.h
index 7690364..9555184 100644
--- a/include/asterisk/app.h
+++ b/include/asterisk/app.h
@@ -129,13 +129,14 @@
* \param s The location where the DTMF data will be stored
* \param maxlen Max Length of the data
* \param timeout Timeout length waiting for data(in milliseconds). Set to 0 for standard timeout(six seconds), or -1 for no time out.
+ * \param terminator A string of characters that may be used as terminators to end input. If NULL, "#" will be used.
*
* This function was designed for application programmers for situations where they need
* to play a message and then get some DTMF data in response to the message. If a digit
* is pressed during playback, it will immediately break out of the message and continue
* execution of your code.
*/
-int ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout);
+int ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout, char *terminator);
/*! \brief Full version with audiofd and controlfd. NOTE: returns '2' on ctrlfd available, not '1' like other full functions */
int ast_app_getdata_full(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd);
diff --git a/main/app.c b/main/app.c
index 09c0123..324e544 100644
--- a/main/app.c
+++ b/main/app.c
@@ -193,8 +193,9 @@
* \param s The string to read in to. Must be at least the size of your length
* \param maxlen How many digits to read (maximum)
* \param timeout set timeout to 0 for "standard" timeouts. Set timeout to -1 for
+ * \param terminator A string of characters that may be used as terminators to end input. Typically "#"
* "ludicrous time" (essentially never times out) */
-enum ast_getdata_result ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout)
+enum ast_getdata_result ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout, char *terminator)
{
int res = 0, to, fto;
char *front, *filename;
@@ -232,7 +233,7 @@
fto = 50;
to = ast_channel_pbx(c) ? ast_channel_pbx(c)->dtimeoutms : 2000;
}
- res = ast_readstring(c, s, maxlen, to, fto, "#");
+ res = ast_readstring(c, s, maxlen, to, fto, (terminator ? terminator : "#"));
if (res == AST_GETDATA_EMPTY_END_TERMINATED) {
return res;
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16352
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I3033432adb9d296ad227e76b540b8b4a2417665b
Gerrit-Change-Number: 16352
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210825/9d4b9357/attachment-0001.html>
More information about the asterisk-code-review
mailing list