From af57937760ed2be917e0920ac0def6a83e00efe3 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Tue, 17 Feb 2009 17:12:10 +0000 Subject: * Apply http://opensimulator.org/mantis/view.php?id=3068 * This enables parsing of xml files and files obtained via http for the -inimaster option as well as -inifile * Thanks StrawberryFride! --- OpenSim/Region/Application/ConfigurationLoader.cs | 132 +++++++++++----------- 1 file changed, 68 insertions(+), 64 deletions(-) diff --git a/OpenSim/Region/Application/ConfigurationLoader.cs b/OpenSim/Region/Application/ConfigurationLoader.cs index 638125c..f0c57e0 100644 --- a/OpenSim/Region/Application/ConfigurationLoader.cs +++ b/OpenSim/Region/Application/ConfigurationLoader.cs @@ -66,105 +66,109 @@ namespace OpenSim m_config.Source = new IniConfigSource(); m_config.Source.Merge(DefaultConfig()); - m_log.Info("Reading in config files now"); + m_log.Info("[CONFIG] Reading configuration settings"); + + Uri configUri; + String xmlPath = Path.Combine(Util.configDir(), "OpenSim.xml"); - //check for master .INI file (name passed in command line, no default) - if (masterFileName.Length != 0) // If a master file name is given ... + //check for master .INI file (name passed in command line, no default), or XML over http + if (masterFileName.Length > 0) // If a master file name is given ... { - m_log.InfoFormat("[CONFIG] Reading config master file {0}", Path.GetFullPath(masterfilePath)); - if (File.Exists(masterfilePath)) - { - m_config.Source.Merge(new IniConfigSource(masterfilePath)); - } - else + m_log.InfoFormat("[CONFIG] Reading config master file {0}", masterfilePath); + + bool isMasterUri = Uri.TryCreate(masterFileName, UriKind.Absolute, out configUri) && configUri.Scheme == Uri.UriSchemeHttp; + + if (!ReadConfig(masterFileName, masterfilePath, m_config, isMasterUri)) { - // IF(!) a master file is given it must exist, be readable, ...... - // Otherwise the application will hickup m_log.FatalFormat("[CONFIG] Could not open master config file {0}", masterfilePath); - Environment.Exit(1); } } // Check for .INI file (either default or name passed on command - // line) or XML config source - // - String xmlPath = Path.Combine(Util.configDir(), "OpenSim.xml"); - bool isUri = false; - Uri configUri; + // line) or XML config source over http + bool isIniUri = Uri.TryCreate(iniFileName, UriKind.Absolute, out configUri) && configUri.Scheme == Uri.UriSchemeHttp; + iniFileExists = ReadConfig(iniFileName, Application.iniFilePath, m_config, isIniUri); - if (Uri.TryCreate(startupConfig.GetString("inifile", "OpenSim.ini"), UriKind.Absolute, out configUri) && configUri.Scheme == Uri.UriSchemeHttp) + if (!iniFileExists) { - isUri = true; - } + // check for a xml config file + if (File.Exists(xmlPath)) + { + Application.iniFilePath = xmlPath; + + m_log.InfoFormat("Reading XML configuration from {0}", Path.GetFullPath(xmlPath)); + iniFileExists = true; + + m_config.Source = new XmlConfigSource(); + m_config.Source.Merge(new XmlConfigSource(Application.iniFilePath)); + } + } + + m_config.Source.Merge(configSource); - if (!isUri && File.Exists(Application.iniFilePath)) + if (!iniFileExists) { - m_log.InfoFormat("[CONFIG] Reading configuration file {0}", Path.GetFullPath(Application.iniFilePath)); + m_log.FatalFormat("[CONFIG] Could not load any configuration"); + if (!isIniUri) + m_log.FatalFormat("[CONFIG] Tried to load {0}, ", Path.GetFullPath(Application.iniFilePath)); + else + m_log.FatalFormat("[CONFIG] Tried to load from URI {0}, ", iniFileName); + m_log.FatalFormat("[CONFIG] and XML source {0}", Path.GetFullPath(xmlPath)); - iniFileExists = true; + m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?"); + Environment.Exit(1); + } + + ReadConfigSettings(); + + return m_config; + } + + /// + /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http + /// + /// The name of the ini to load + /// Full path to the ini + /// The current configuration source + /// Boolean representing whether the ini source is a URI path over http or a file on the system + /// + private bool ReadConfig(string iniName, string iniPath, OpenSimConfigSource m_config, bool isUri) + { + bool success = false; + + if (!isUri && File.Exists(iniPath)) + { + m_log.InfoFormat("[CONFIG] Reading configuration file {0}", Path.GetFullPath(iniPath)); // From reading Nini's code, it seems that later merged keys replace earlier ones. - m_config.Source.Merge(new IniConfigSource(Application.iniFilePath)); + m_config.Source.Merge(new IniConfigSource(iniPath)); + success = true; } else { if (isUri) { - m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...", startupConfig.GetString("inifile", "OpenSim.ini")); + m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...", iniName); // The ini file path is a http URI // Try to read it - // try { - XmlReader r = XmlReader.Create(startupConfig.GetString("inifile", "OpenSim.ini")); + XmlReader r = XmlReader.Create(iniName); XmlConfigSource cs = new XmlConfigSource(r); m_config.Source.Merge(cs); - iniFileExists = true; - m_log.InfoFormat("[CONFIG] Loaded config from {0}", startupConfig.GetString("inifile", "OpenSim.ini")); + success = true; + m_log.InfoFormat("[CONFIG] Loaded config from {0}", iniName); } catch (Exception e) { - m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), startupConfig.GetString("inifile", "OpenSim.ini")); + m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniName); Environment.Exit(1); } } - else - { - // check for a xml config file - - if (File.Exists(xmlPath)) - { - Application.iniFilePath = xmlPath; - - m_log.InfoFormat("Reading XML configuration from {0}", Path.GetFullPath(xmlPath)); - iniFileExists = true; - - m_config.Source = new XmlConfigSource(); - m_config.Source.Merge(new XmlConfigSource(Application.iniFilePath)); - } - } } - - m_config.Source.Merge(configSource); - - if (!iniFileExists) - { - m_log.FatalFormat("[CONFIG] Could not load any configuration"); - if (!isUri) - m_log.FatalFormat("[CONFIG] Tried to load {0}, ", Path.GetFullPath(Application.iniFilePath)); - else - m_log.FatalFormat("[CONFIG] Tried to load from URI {0}, ", startupConfig.GetString("inifile", "OpenSim.ini")); - m_log.FatalFormat("[CONFIG] and XML source {0}", Path.GetFullPath(xmlPath)); - - m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?"); - Environment.Exit(1); - } - - ReadConfigSettings(); - - return m_config; + return success; } /// -- cgit v1.1