1 /***********************************************************************************************************************************
2 Command and Option Configuration Internals
3 
4 These structures and functions are generally used by modules that create configurations, e.g. config/parse, or modules that
5 manipulate the configuration as a whole, e.g. protocol/helper, in order to communicate with other processes.
6 
7 The general-purpose functions for querying the current configuration are found in config.h.
8 ***********************************************************************************************************************************/
9 #ifndef CONFIG_CONFIG_INTERN_H
10 #define CONFIG_CONFIG_INTERN_H
11 
12 #include "config/config.h"
13 #include "config/parse.h"
14 
15 /***********************************************************************************************************************************
16 The maximum number of keys that an indexed option can have, e.g. pg256-path would be the maximum pg-path option
17 ***********************************************************************************************************************************/
18 #define CFG_OPTION_KEY_MAX                                          256
19 
20 /***********************************************************************************************************************************
21 Configuration data. These structures are not directly user-created or accessible. configParse() creates the structures and uses
22 cfgInit() to load it as the current configuration. Various cfg*() functions provide access.
23 ***********************************************************************************************************************************/
24 typedef struct ConfigOptionValue
25 {
26     bool negate;                                                // Is the option negated?
27     bool reset;                                                 // Is the option reset?
28     unsigned int source;                                        // Where the option came from, i.e. ConfigSource enum
29     const String *display;                                      // Current display value, if any. Used for messages, etc.
30     const Variant *value;                                       // Value
31 } ConfigOptionValue;
32 
33 typedef struct Config
34 {
35     MemContext *memContext;                                         // Mem context for config data
36 
37     // Generally set by the command parser but can also be set during execute to change commands, i.e. backup -> expire
38     ConfigCommand command;                                          // Current command
39     ConfigCommandRole commandRole;                                  // Current command role
40 
41     String *exe;                                                    // Location of the executable
42     bool help;                                                      // Was help requested for the command?
43     bool lockRequired;                                              // Is an immediate lock required?
44     bool lockRemoteRequired;                                        // Is a lock required on the remote?
45     LockType lockType;                                              // Lock type required
46     bool logFile;                                                   // Will the command log to a file?
47     LogLevel logLevelDefault;                                       // Default log level
48     StringList *paramList;                                          // Parameters passed to the command (if any)
49 
50     // Group options that are related together to allow valid and test checks across all options in the group
51     struct
52     {
53         const char *name;                                           // Name
54         bool valid;                                                 // Is option group valid for the current command?
55         unsigned int indexTotal;                                    // Total number of indexes with values in option group
56         bool indexDefaultExists;                                    // Is there a default index for non-indexed functions?
57         unsigned int indexDefault;                                  // Default index (usually 0)
58         unsigned int indexMap[CFG_OPTION_KEY_MAX];                  // List of index to key index mappings
59     } optionGroup[CFG_OPTION_GROUP_TOTAL];
60 
61     // Option data
62     struct
63     {
64         const char *name;                                           // Name
65         bool valid;                                                 // Is option valid for current command?
66         bool group;                                                 // In a group?
67         unsigned int groupId;                                       // Id if in a group
68         const Variant *defaultValue;                                // Default value
69         ConfigOptionValue *index;                                   // List of indexed values (only 1 unless the option is indexed)
70     } option[CFG_OPTION_TOTAL];
71 } Config;
72 
73 /***********************************************************************************************************************************
74 Init Function
75 ***********************************************************************************************************************************/
76 // Init with new configuration
77 void cfgInit(Config *config);
78 
79 /***********************************************************************************************************************************
80 Command Functions
81 ***********************************************************************************************************************************/
82 // List of retry intervals for local jobs. The interval for the first retry will always be 0. NULL if there are no retries.
83 VariantList *cfgCommandJobRetry(void);
84 
85 /***********************************************************************************************************************************
86 Option Group Functions
87 ***********************************************************************************************************************************/
88 // Is the option in a group?
89 bool cfgOptionGroup(ConfigOption optionId);
90 
91 // Group id if the option is in a group
92 unsigned int cfgOptionGroupId(ConfigOption optionId);
93 
94 /***********************************************************************************************************************************
95 Option Functions
96 ***********************************************************************************************************************************/
97 // Format a variant for display using the supplied option type. cfgOptionDisplay()/cfgOptionIdxDisplay() should be used whenever
98 // possible, but sometimes the variant needs to be manipulated before being formatted.
99 const String *cfgOptionDisplayVar(const Variant *const value, const ConfigOptionType optionType);
100 
101 // Convert the key used in the original configuration to a group index. This is used when an option key must be translated into the
102 // local group index, e.g. during parsing or when getting the value of specific options from a remote.
103 unsigned int cfgOptionKeyToIdx(ConfigOption optionId, unsigned int key);
104 
105 // Total indexes for the option if in a group, 1 otherwise.
106 unsigned int cfgOptionIdxTotal(ConfigOption optionId);
107 
108 // Invalidate an option so it will not be passed to other processes. This is used to manage deprecated options that have a newer
109 // option that should be used when possible, e.g. compress and compress-type.
110 void cfgOptionInvalidate(ConfigOption optionId);
111 
112 #endif
113