Add a configuration system to the server
Until now configuring mwserv has been limited to command line options and build configuration. This config system should make things a bit more flexible by adding the ability to load bits and pieces from a json config file (or many json config files). This is how it works: 1. A json object 'cfg' is built containing the build-time defaults for each config option recognised by mwserv. This will be used to validate the options in config files later. 2. A json config file in the user's home directory is loaded if it exists. It does not have to be complete: its contents will be merged into the defaults. Unrecognised options are ignored. 3. Otherwise, a config file in /etc is loaded and used similarly. 4. Command line options are parsed and the cfg object is updated with cfg_set_* in the order in which the options are found. 4a. If the [--config|-c <file>] option is encountered, the file is loaded and merged into the cfg object as before. 5. Once all of the config information is gathered and merged into the cfg object, if the [--print-config|-P] option was given, the final merged config is printed in json format (mwserv then exits). 6. Config options are then accessed using the cfg_get_* type-specific functions. This should allow the build system to be simplified in future, e.g. 'make test' could go away in favour of using ~/.mwserv.conf to store the test environment configuration. For now, the place to add new config options and their default values is in cfg_init_defaults() in servercfg.c.
Loading
Please register or sign in to comment