diff options
| author | Dennis Camera <skonfig@dtnr.ch> | 2022-08-03 17:42:18 +0200 |
|---|---|---|
| committer | Dennis Camera <skonfig@dtnr.ch> | 2022-08-03 17:58:19 +0200 |
| commit | fdccc8b948a4df3b6a2c3dcd6990c05bf8afdb27 (patch) | |
| tree | 0f42c4d95649ba3e6a181659a0bd053604b499ec /src/config.h | |
| parent | 26f555c974cf49def75120dada596f421e15f1d4 (diff) | |
| download | skonfig-c-fdccc8b948a4df3b6a2c3dcd6990c05bf8afdb27.tar.gz skonfig-c-fdccc8b948a4df3b6a2c3dcd6990c05bf8afdb27.zip | |
[src/config.c] Add config module (does not parse INI files, yet)
Diffstat (limited to 'src/config.h')
| -rw-r--r-- | src/config.h | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..bfd7029 --- /dev/null +++ b/src/config.h @@ -0,0 +1,128 @@ +#ifndef _SK_CONFIG_H +#define _SK_CONFIG_H + +#include "../config.h" + +#include <stdio.h> + +#if HAVE_STDBOOL_H +#include <stdbool.h> +#endif + +typedef char * command_t; +typedef char * path_t; +typedef char * dir_t; +typedef char ** searchpath_t; + +enum sk_log_verb { + LOG_OFF = 0, + LOG_ERROR, + LOG_WARNING, + LOG_INFO, + LOG_VERBOSE, + LOG_DEBUG, + LOG_TRACE, + + SK_LOG_MIN = LOG_OFF, + SK_LOG_MAX = LOG_TRACE +}; + +enum sk_colour_output { + SK_COLOUR_NEVER = 0, + SK_COLOUR_ALWAYS, + SK_COLOUR_AUTO +}; + +enum sk_archiving_mode { + SK_ARCHIVING_NONE = 0, + SK_ARCHIVING_TAR, + SK_ARCHIVING_TGZ, + SK_ARCHIVING_TBZ2, + SK_ARCHIVING_TXZ +}; + +struct sk_config_global { + command_t local_shell; + command_t remote_shell; + char *cache_path_pattern; + searchpath_t conf_dir; + enum sk_colour_output coloured_output; + path_t init_manifest; + path_t out_path; + command_t remote_out_path; + command_t remote_exec; + dir_t inventory_dir; + unsigned int jobs; + enum sk_log_verb verbosity_level; + enum sk_archiving_mode archiving; + bool save_output_streams; + bool log_timestamp; +}; + +struct sk_config { + struct sk_config_global global; +}; + +/* functions */ + +/** + * sk_config_alloc: + * Allocates a new sk_config struct filled with defaults. + * + * @return pointer to a new sk_config struct + * (or NULL if it ran out of memory.) + */ +struct sk_config *sk_config_alloc(); + +/** + * sk_config_print: + * Prints a sk_config struct. + * + * @param config: the sk_config struct to print + * @param outstream: the stream to print to + */ +void sk_config_print(struct sk_config *config, FILE *outstream); + +/** + * sk_config_find: + * Finds the .skonfig/config file to use. + * + * The caller must free() the returned pointer. + * + * @return path to the .skonfig/config file to use, + * or NULL if none was found or an error occurred. + */ +const char *sk_config_find(); + +/** + * sk_config_cpy: + * Make a deep copy of the config struct. + * + * i.e. pointer values will be copied. + * + * @param dest: pointer to a newly allocated config struct + * @param src: pointer to the struct to copy to dest + */ +void sk_config_cpy(struct sk_config *restrict dest, const struct sk_config *restrict src); + +int sk_config_parse_file(struct sk_config *config, FILE *fh); + +/** + * sk_config_parse_env: + * Update an sk_config struct from environment variables. + * + * @param config: the struct to update + */ +void sk_config_parse_env(struct sk_config *config); + +/** + * sk_config_free: + * Frees an sk_config struct allocated using sk_config_alloc. + * + * Pointer type struct fields will also be freed! + * + * @param config: the struct to free + */ +void sk_config_free(struct sk_config *); + +#endif |
