[Asterisk-code-review] app_directory: add ability to specify configuration file (asterisk[certified/18.9])
Friendly Automation
asteriskteam at digium.com
Mon Jan 30 11:52:24 CST 2023
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/19868 )
Change subject: app_directory: add ability to specify configuration file
......................................................................
app_directory: add ability to specify configuration file
Adds option to app_directory to specify a filename from which to
read configuration instead of voicemail.conf ie;
same => n,Directory(,,c(directory.conf))
This configuration should contain a list of extensions using the
voicemail.conf format, ie;
2020=2020,Dog Dog,,,,attach=no|saycid=no|envelope=no|delete=no
ASTERISK-30404
Change-Id: Id58ccb1344ad1e563fa10db12f172fbd104a9d13
(cherry picked from commit ef6901e1372b6951ab5ccd0206546413aff95c55)
---
M apps/app_directory.c
1 file changed, 37 insertions(+), 6 deletions(-)
Approvals:
Michael Bradeen: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/apps/app_directory.c b/apps/app_directory.c
index 36da702..847710b 100644
--- a/apps/app_directory.c
+++ b/apps/app_directory.c
@@ -103,6 +103,10 @@
receiver to their ear while entering DTMF.</para>
<argument name="n" required="true" />
</option>
+ <option name="c">
+ <para>Load the specified config file instead of voicemail.conf</para>
+ <argument name="filename" required="true" />
+ </option>
</optionlist>
<note><para>Only one of the <replaceable>f</replaceable>, <replaceable>l</replaceable>, or <replaceable>b</replaceable>
options may be specified. <emphasis>If more than one is specified</emphasis>, then Directory will act as
@@ -114,7 +118,7 @@
<description>
<para>This application will present the calling channel with a directory of extensions from which they can search
by name. The list of names and corresponding extensions is retrieved from the
- voicemail configuration file, <filename>voicemail.conf</filename>.</para>
+ voicemail configuration file, <filename>voicemail.conf</filename>, or from the specified filename.</para>
<para>This application will immediately exit if one of the following DTMF digits are
received and the extension to jump to exists:</para>
<para><literal>0</literal> - Jump to the 'o' extension, if it exists.</para>
@@ -153,6 +157,7 @@
OPT_PAUSE = (1 << 5),
OPT_NOANSWER = (1 << 6),
OPT_ALIAS = (1 << 7),
+ OPT_CONFIG_FILE = (1 << 8),
};
enum {
@@ -160,8 +165,9 @@
OPT_ARG_LASTNAME = 1,
OPT_ARG_EITHER = 2,
OPT_ARG_PAUSE = 3,
+ OPT_ARG_FILENAME = 4,
/* This *must* be the last value in this enum! */
- OPT_ARG_ARRAY_SIZE = 4,
+ OPT_ARG_ARRAY_SIZE = 5,
};
struct directory_item {
@@ -183,6 +189,7 @@
AST_APP_OPTION('m', OPT_SELECTFROMMENU),
AST_APP_OPTION('n', OPT_NOANSWER),
AST_APP_OPTION('a', OPT_ALIAS),
+ AST_APP_OPTION_ARG('c', OPT_CONFIG_FILE, OPT_ARG_FILENAME),
});
static int compare(const char *text, const char *template)
@@ -458,7 +465,7 @@
AST_THREADSTORAGE(commonbuf);
-static struct ast_config *realtime_directory(char *context)
+static struct ast_config *realtime_directory(char *context, const char *filename)
{
struct ast_config *cfg;
struct ast_config *rtdata = NULL;
@@ -475,14 +482,14 @@
}
/* Load flat file config. */
- cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
+ cfg = ast_config_load(filename, config_flags);
if (!cfg) {
/* Loading config failed. */
ast_log(LOG_WARNING, "Loading config failed.\n");
return NULL;
} else if (cfg == CONFIG_STATUS_FILEINVALID) {
- ast_log(LOG_ERROR, "Config file %s is in an invalid format. Aborting.\n", VOICEMAIL_CONFIG);
+ ast_log(LOG_ERROR, "Config file %s is in an invalid format. Aborting.\n", filename);
return NULL;
}
@@ -867,7 +874,9 @@
if (args.options && ast_app_parse_options(directory_app_options, &flags, opts, args.options))
return -1;
- if (!(cfg = realtime_directory(args.vmcontext))) {
+ cfg = realtime_directory(args.vmcontext, S_OR(opts[OPT_ARG_FILENAME], VOICEMAIL_CONFIG));
+
+ if (!cfg) {
ast_log(LOG_ERROR, "Unable to read the configuration data!\n");
return -1;
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19868
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: certified/18.9
Gerrit-Change-Id: Id58ccb1344ad1e563fa10db12f172fbd104a9d13
Gerrit-Change-Number: 19868
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230130/a4fe5482/attachment.html>
More information about the asterisk-code-review
mailing list