From 70856e865f76b3447eaa07379f77b857f8e86615 Mon Sep 17 00:00:00 2001 From: Mike Bradeen Date: Wed, 25 Jan 2023 15:27:31 -0700 Subject: [PATCH] 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 --- apps/app_directory.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/app_directory.c b/apps/app_directory.c index 36da702a5e..847710b7a6 100644 --- a/apps/app_directory.c +++ b/apps/app_directory.c @@ -103,6 +103,10 @@ receiver to their ear while entering DTMF. + Only one of the f, l, or b options may be specified. If more than one is specified, then Directory will act as @@ -114,7 +118,7 @@ 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, voicemail.conf. + voicemail configuration file, voicemail.conf, or from the specified filename. This application will immediately exit if one of the following DTMF digits are received and the extension to jump to exists: 0 - Jump to the 'o' extension, if it exists. @@ -153,6 +157,7 @@ enum { OPT_PAUSE = (1 << 5), OPT_NOANSWER = (1 << 6), OPT_ALIAS = (1 << 7), + OPT_CONFIG_FILE = (1 << 8), }; enum { @@ -160,8 +165,9 @@ enum { 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_OPTIONS(directory_app_options, { 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 @@ static int select_item_menu(struct ast_channel *chan, struct directory_item **it 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 @@ static struct ast_config *realtime_directory(char *context) } /* 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 @@ static int directory_exec(struct ast_channel *chan, const char *data) 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; }