summaryrefslogtreecommitdiff
path: root/src/config.h
blob: 3e941a50bde4873e7f7ad8c7e308aa5939a95c36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#ifndef _SK_CONFIG_H
#define _SK_CONFIG_H

#include "log.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_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;
};


#if HAVE_FUNC_ATTRIBUTE_MALLOC
/* pre-declare free function for SK_MALLOC_FREE(sk_config_free) */
extern void sk_config_free(struct sk_config *);
#endif

/* 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_NONNULL(1);

/**
 * 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_RETURNS_NONNULL;

/**
 * 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) SK_NONNULL(1);


/* 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_MALLOC_FREE(sk_config_free, 1) SK_WARN_UNUSED_RESULT;

/**
 * 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_NONNULL(1, 2);

/**
 * 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_WARN_UNUSED_RESULT;

/**
 * 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) SK_NONNULL(1, 2);

int sk_config_parse_file(struct sk_config *config, FILE *fh) SK_NONNULL(1, 2);

/**
 * 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_NONNULL(1);

/**
 * 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 *) SK_NONNULL(1);

#endif