1 /***********************************************************************************************************************************
2 Parse Configuration Yaml
3 ***********************************************************************************************************************************/
4 #ifndef BUILD_CONFIG_PARSE_H
5 #define BUILD_CONFIG_PARSE_H
6 
7 #include "common/type/stringList.h"
8 
9 /***********************************************************************************************************************************
10 Command role constants
11 ***********************************************************************************************************************************/
12 #define CMD_ROLE_ASYNC                                              "async"
13     STRING_DECLARE(CMD_ROLE_ASYNC_STR);
14 #define CMD_ROLE_LOCAL                                              "local"
15     STRING_DECLARE(CMD_ROLE_LOCAL_STR);
16 #define CMD_ROLE_MAIN                                               "main"
17     STRING_DECLARE(CMD_ROLE_MAIN_STR);
18 #define CMD_ROLE_REMOTE                                             "remote"
19     STRING_DECLARE(CMD_ROLE_REMOTE_STR);
20 
21 /***********************************************************************************************************************************
22 Command constants
23 ***********************************************************************************************************************************/
24 #define CMD_HELP                                                    "help"
25     STRING_DECLARE(CMD_HELP_STR);
26 #define CMD_VERSION                                                 "version"
27     STRING_DECLARE(CMD_VERSION_STR);
28 
29 /***********************************************************************************************************************************
30 Option type constants
31 ***********************************************************************************************************************************/
32 #define OPT_TYPE_BOOLEAN                                            "boolean"
33     STRING_DECLARE(OPT_TYPE_BOOLEAN_STR);
34 #define OPT_TYPE_HASH                                               "hash"
35     STRING_DECLARE(OPT_TYPE_HASH_STR);
36 #define OPT_TYPE_LIST                                               "list"
37     STRING_DECLARE(OPT_TYPE_LIST_STR);
38 #define OPT_TYPE_STRING                                             "string"
39     STRING_DECLARE(OPT_TYPE_STRING_STR);
40 #define OPT_TYPE_TIME                                               "time"
41     STRING_DECLARE(OPT_TYPE_TIME_STR);
42 
43 /***********************************************************************************************************************************
44 Option constants
45 ***********************************************************************************************************************************/
46 #define OPT_STANZA                                                  "stanza"
47     STRING_DECLARE(OPT_STANZA_STR);
48 
49 /***********************************************************************************************************************************
50 Section constants
51 ***********************************************************************************************************************************/
52 #define SECTION_COMMAND_LINE                                        "command-line"
53     STRING_DECLARE(SECTION_COMMAND_LINE_STR);
54 #define SECTION_GLOBAL                                              "global"
55     STRING_DECLARE(SECTION_GLOBAL_STR);
56 #define SECTION_STANZA                                              "stanza"
57     STRING_DECLARE(SECTION_STANZA_STR);
58 
59 /***********************************************************************************************************************************
60 Types
61 ***********************************************************************************************************************************/
62 typedef struct BldCfgCommand
63 {
64     const String *const name;                                       // Name
65     const bool logFile;                                             // Does the command write automatically to a log file?
66     const String *const logLevelDefault;                            // Default log level
67     const bool lockRequired;                                        // Is a lock required
68     const bool lockRemoteRequired;                                  // Is a remote lock required?
69     const String *const lockType;                                   // Lock type
70     const bool parameterAllowed;                                    // Are command line parameters allowed?
71     const StringList *const roleList;                               // Roles valid for the command
72 } BldCfgCommand;
73 
74 typedef struct BldCfgOptionGroup
75 {
76     const String *const name;                                       // Name
77     const unsigned int indexTotal;                                  // Total indexes for option
78 } BldCfgOptionGroup;
79 
80 typedef struct BldCfgOption BldCfgOption;                           // Forward declaration
81 
82 typedef struct BldCfgOptionDepend
83 {
84     const BldCfgOption *const option;                               // Option dependency is on
85     const StringList *const valueList;                              // Allowed value list
86 } BldCfgOptionDepend;
87 
88 typedef struct BldCfgOptionDeprecate
89 {
90     const String *const name;                                       // Deprecated option name
91     const unsigned int index;                                       // Option index to deprecate
92     const bool reset;                                               // Does the deprecated option allow reset
93 } BldCfgOptionDeprecate;
94 
95 typedef struct BldCfgOptionCommand
96 {
97     const String *const name;                                       // Name
98     const bool required;                                            // Is the option required?
99     const String *const defaultValue;                               // Default value, if any
100     const BldCfgOptionDepend *const depend;                         // Dependency, if any
101     const StringList *const allowList;                              // Allowed value list
102     const StringList *const roleList;                               // Roles valid for the command
103 } BldCfgOptionCommand;
104 
105 struct BldCfgOption
106 {
107     const String *const name;                                       // Name
108     const String *const type;                                       // Option type, e.g. integer
109     const String *const section;                                    // Option section, i.e. stanza or global
110     const bool required;                                            // Is the option required?
111     const bool negate;                                              // Can the option be negated?
112     const bool reset;                                               // Can the option be reset?
113     const String *const defaultValue;                               // Default value, if any
114     const bool defaultLiteral;                                      // Should default be interpreted literally, i.e. not a string
115     const String *const group;                                      // Option group, if any
116     const bool secure;                                              // Does the option contain a secret?
117     const BldCfgOptionDepend *const depend;                         // Dependency, if any
118     const StringList *const allowList;                              // Allowed value list
119     const String *const allowRangeMin;                              // Allow range min, if any
120     const String *const allowRangeMax;                              // Allow range max, if any
121     const List *const cmdList;                                      // Command override list
122     const List *const deprecateList;                                // List of option deprecations
123 };
124 
125 typedef struct BldCfg
126 {
127     const List *const cmdList;                                      // Command list
128     const List *const optGrpList;                                   // Option group list
129     const List *const optList;                                      // Option list
130     const List *const optResolveList;                               // Option list in resolved dependency order
131 } BldCfg;
132 
133 /***********************************************************************************************************************************
134 Functions
135 ***********************************************************************************************************************************/
136 // Parse config.yaml
137 BldCfg bldCfgParse(const Storage *const storageRepo);
138 
139 #endif
140