#ifndef _SK_CONFIG_H #define _SK_CONFIG_H #include "log.h" #include #if HAVE_STDBOOL_H #include #endif typedef char * command_t; typedef char * path_t; typedef char * dir_t; typedef char ** searchpath_t; 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, SK_ARCHIVING_MIN = SK_ARCHIVING_NONE, SK_ARCHIVING_MAX = 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; sk_log_level verbosity_level; enum sk_archiving_mode archiving; bool save_output_streams; bool log_timestamp; }; struct sk_config { struct sk_config_global global; }; /* type conversion functions */ /** * sk_archiving_mode_to_string: * return the string representation of an sk_archiving_mode. * * @param a: an sk_archiving_mode. * @return the string representation of a. */ const char *sk_archiving_mode_to_string(enum sk_archiving_mode a); /** * sk_archiving_mode_of_string: * returns an sk_archiving_mode of a string representation. * * In case an invalid string representation is given, * SK_ARCHIVING_NONE is returned. * * @param s: the string representation of an sk_archiving_mode. * @return an sk_archiving_mode. */ enum sk_archiving_mode sk_archiving_mode_of_string(const char *s); /** * sk_colour_output_to_string: * returns the string representation of an sk_colour_output. * * @param c: the sk_colour_output. * @return the string representation of c. */ const char *sk_colour_output_to_string(enum sk_colour_output c); /** * sk_colour_output_of_string: * convert a string to sk_colour_output. * * s is interpreted case-insensitively. * In case an invalid string representation is given, * SK_COLOUR_NEVER is returned. * * @param s: the string representation of an sk_colour_output. * @return sk_colour_output */ enum sk_colour_output sk_colour_output_of_string(const char *s); /* 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