[Asterisk-code-review] app_directory: add ability to specify configuration file (asterisk[18])

Michael Bradeen asteriskteam at digium.com
Wed Jan 25 16:30:15 CST 2023


Michael Bradeen has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19794 )


Change subject: app_directory: add ability to specify configuration file
......................................................................

app_directory: add ability to specify configuration file

Adds 4th, optional parameter to app_directory to specify a filename
from which to read configuration instead of voicemail.conf ie;

same => n,Directory(,,,directory.conf)

This configuration can allow a separate listing using the
voicemail.conf format, ie;

2020=2020,Dog Dog,,,,attach=no|saycid=no|envelope=no|delete=no

ASTERISK-30404

Change-Id: Id58ccb1344ad1e563fa10db12f172fbd104a9d13
---
M apps/app_directory.c
1 file changed, 42 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/94/19794/1

diff --git a/apps/app_directory.c b/apps/app_directory.c
index 36da702..47c5c75 100644
--- a/apps/app_directory.c
+++ b/apps/app_directory.c
@@ -110,11 +110,14 @@
 				of characters for the user to type defaults to <literal>3</literal>.</para></note>
 
 			</parameter>
+			<parameter name="filename" required="false">
+				<para>Load the specified config file instead of voicemail.conf</para>
+			</parameter>
 		</syntax>
 		<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>
@@ -458,7 +461,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,7 +478,12 @@
 	}
 
 	/* Load flat file config. */
-	cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
+	if (!ast_strlen_zero(filename)){
+		cfg = ast_config_load(filename, config_flags);
+	}
+	else {
+		cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
+	}
 
 	if (!cfg) {
 		/* Loading config failed. */
@@ -858,6 +866,7 @@
 		AST_APP_ARG(vmcontext);
 		AST_APP_ARG(dialcontext);
 		AST_APP_ARG(options);
+		AST_APP_ARG(filename);
 	);
 
 	parse = ast_strdupa(data);
@@ -867,7 +876,15 @@
 	if (args.options && ast_app_parse_options(directory_app_options, &flags, opts, args.options))
 		return -1;
 
-	if (!(cfg = realtime_directory(args.vmcontext))) {
+	if (!ast_strlen_zero(args.filename)) {
+		ast_log(LOG_NOTICE, "Load custom directory file: %s\n", args.filename);
+		cfg = realtime_directory(args.vmcontext, args.filename);
+	}
+	else {
+		cfg = realtime_directory(args.vmcontext, NULL);
+	}
+
+	if (!cfg) {
 		ast_log(LOG_ERROR, "Unable to read the configuration data!\n");
 		return -1;
 	}

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19794
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: Id58ccb1344ad1e563fa10db12f172fbd104a9d13
Gerrit-Change-Number: 19794
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230125/be8f7a70/attachment.html>


More information about the asterisk-code-review mailing list