1 /***********************************************************************************************************************************
2 Parse Configuration
3 ***********************************************************************************************************************************/
4 #ifndef CONFIG_PARSE_H
5 #define CONFIG_PARSE_H
6 
7 #include "config/config.h"
8 #include "storage/storage.h"
9 
10 /***********************************************************************************************************************************
11 Option type enum
12 ***********************************************************************************************************************************/
13 typedef enum
14 {
15     cfgOptTypeBoolean,                                              // Boolean
16     cfgOptTypeHash,                                                 // Associative array, e.g. key1=val1,key2=val2
17     cfgOptTypeInteger,                                              // Signed 64-bit integer
18     cfgOptTypeList,                                                 // String list, e.g. val1,val2
19     cfgOptTypePath,                                                 // Path string with validation
20     cfgOptTypeSize,                                                 // Size, e.g. 1m, 2gb
21     cfgOptTypeString,                                               // String
22     cfgOptTypeTime,                                                 // Time in seconds, e.g. 23, 1.5
23 } ConfigOptionType;
24 
25 /***********************************************************************************************************************************
26 Functions
27 ***********************************************************************************************************************************/
28 // Parse the command-line arguments and config file to produce final config data
29 void configParse(const Storage *storage, unsigned int argListSize, const char *argList[], bool resetLogLevel);
30 
31 // Get command name by id
32 const char *cfgParseCommandName(ConfigCommand commandId);
33 
34 // Get command/role name with custom separator
35 String *cfgParseCommandRoleName(
36     const ConfigCommand commandId, const ConfigCommandRole commandRoleId, const String *separator);
37 
38 // Convert command role enum to String
39 const String *cfgParseCommandRoleStr(ConfigCommandRole commandRole);
40 
41 // Parse option name and return option info
42 typedef struct CfgParseOptionParam
43 {
44     VAR_PARAM_HEADER;
45     bool prefixMatch;                                               // Allow prefix matches, e.g. 'stanz' for 'stanza'
46 } CfgParseOptionParam;
47 
48 typedef struct CfgParseOptionResult
49 {
50     bool found;                                                     // Was the option found?
51     ConfigOption id;                                                // Option ID
52     unsigned int keyIdx;                                            // Option key index, i.e. option key - 1
53     bool negate;                                                    // Was the option negated?
54     bool reset;                                                     // Was the option reset?
55     bool deprecated;                                                // Is the option deprecated?
56 } CfgParseOptionResult;
57 
58 #define cfgParseOptionP(optionName, ...)                                                                                            \
59     cfgParseOption(optionName, (CfgParseOptionParam){VAR_PARAM_INIT, __VA_ARGS__})
60 
61 CfgParseOptionResult cfgParseOption(const String *const optionName, const CfgParseOptionParam param);
62 
63 // Default value for the option
64 const char *cfgParseOptionDefault(ConfigCommand commandId, ConfigOption optionId);
65 
66 // Option id from name
67 int cfgParseOptionId(const char *optionName);
68 
69 // Option name from id
70 const char *cfgParseOptionName(ConfigOption optionId);
71 
72 // Option name from id and key
73 const char *cfgParseOptionKeyIdxName(ConfigOption optionId, unsigned int keyIdx);
74 
75 // Does the option need to be protected from showing up in logs, command lines, etc?
76 bool cfgParseOptionSecure(ConfigOption optionId);
77 
78 // Option data type
79 ConfigOptionType cfgParseOptionType(ConfigOption optionId);
80 
81 // Is the option required?
82 bool cfgParseOptionRequired(ConfigCommand commandId, ConfigOption optionId);
83 
84 // Is the option valid for the command?
85 bool cfgParseOptionValid(ConfigCommand commandId, ConfigCommandRole commandRoleId, ConfigOption optionId);
86 
87 #endif
88