aboutsummaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
authorToni <matzeton@googlemail.com>2024-10-16 14:13:55 +0200
committerGitHub <noreply@github.com>2024-10-16 14:13:55 +0200
commitefed6f196ecab333b76b83a5d256c9e4e6b75867 (patch)
treed8e5963a07a1ea87f3547a0e9ae8d370e6cb06f5 /utils.h
parent3e2ce661f01545daeb311d671bf222d378729bca (diff)
Read and parse configuration files. Fixes #41. (#42)1.7rc1
Read and parse configuration files. Fixes #41. * supports nDPId / nDPIsrvd via command line parameter `-f` * nDPId: read general/tuning and libnDPI settings * support for settings risk domains libnDPI option via config file or via `-R` (Fixes #45, thanks to @UnveilTech) * added some documentation in the config file * adjusted Systemd and Debian packaging to make use of config files Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h87
1 files changed, 74 insertions, 13 deletions
diff --git a/utils.h b/utils.h
index 8dca5e469..0a78264c3 100644
--- a/utils.h
+++ b/utils.h
@@ -2,27 +2,86 @@
#define UTILS_H 1
#include <stdarg.h>
+#include <stdint.h>
+#include <sys/types.h>
#define WARN_UNUSED __attribute__((__warn_unused_result__))
-#define CMDARG(_default_value) \
+#define INI_MAX_SECTION 50
+#define INI_MAX_NAME 50
+
+#define CMDARG_STR(_default_value) \
+ { \
+ .is_set = 0, .type = CMDTYPE_STRING, .string.value = NULL, .string.default_value = (_default_value) \
+ }
+#define CMDARG_BOOL(_default_value) \
{ \
- .value = NULL, .default_value = (_default_value) \
+ .is_set = 0, .type = CMDTYPE_BOOLEAN, .boolean.value = 0, .boolean.default_value = (_default_value) \
}
+#define CMDARG_ULL(_default_value) \
+ { \
+ .is_set = 0, .type = CMDTYPE_ULL, .ull.value = 0ull, .ull.default_value = (_default_value) \
+ }
+#define CONFOPT(_key, _opt) \
+ { \
+ .key = _key, .opt = _opt \
+ }
+#define GET_CMDARG_STR(cmdarg) ((cmdarg).string.value)
+#define GET_CMDARG_BOOL(cmdarg) ((cmdarg).boolean.value)
+#define GET_CMDARG_ULL(cmdarg) ((cmdarg).ull.value)
+#define IS_CMDARG_SET(cmdarg) ((cmdarg).is_set)
+
+enum cmdtype
+{
+ CMDTYPE_INVALID = 0,
+ CMDTYPE_STRING,
+ CMDTYPE_BOOLEAN,
+ CMDTYPE_ULL
+};
struct cmdarg
{
- char * value;
- char const * const default_value;
+ enum cmdtype type;
+ int is_set;
+ union
+ {
+ struct
+ {
+ char * value;
+ char const * const default_value;
+ } string;
+ struct
+ {
+ uint8_t value;
+ uint8_t const default_value;
+ } boolean;
+ struct
+ {
+ unsigned long long int value;
+ unsigned long long int const default_value;
+ } ull;
+ };
};
-void set_cmdarg(struct cmdarg * const ca, char const * const val);
+struct confopt
+{
+ char const * const key;
+ struct cmdarg * const opt;
+};
-WARN_UNUSED
-char const * get_cmdarg(struct cmdarg const * const ca);
+typedef int (*config_line_callback)(
+ int lineno, char const * const section, char const * const key, char const * const value, void * const user_data);
+
+void set_config_defaults(struct confopt * const co_array, size_t array_length);
WARN_UNUSED
-int is_cmdarg_set(struct cmdarg const * const ca);
+int set_config_from(struct confopt * const co, char const * const from);
+
+void set_cmdarg_string(struct cmdarg * const ca, char const * const val);
+
+void set_cmdarg_boolean(struct cmdarg * const ca, uint8_t val);
+
+void set_cmdarg_ull(struct cmdarg * const ca, unsigned long long int val);
WARN_UNUSED
int is_path_absolute(char const * const prefix, char const * const path);
@@ -38,11 +97,10 @@ int daemonize_with_pidfile(char const * const pidfile);
int daemonize_shutdown(char const * const pidfile);
WARN_UNUSED
-int change_user_group(char const * const user,
- char const * const group,
- char const * const pidfile,
- char const * const uds_collector_path,
- char const * const uds_distributor_path);
+int change_user_group(char const * const user, char const * const group, char const * const pidfile);
+
+WARN_UNUSED
+int chmod_chown(char const * const path, mode_t mode, char const * const user, char const * const group);
void init_logging(char const * const daemon_name);
@@ -73,4 +131,7 @@ int set_fd_cloexec(int fd);
WARN_UNUSED
char const * get_nDPId_version(void);
+WARN_UNUSED
+int parse_config_file(char const * const config_file, config_line_callback cb, void * const user_data);
+
#endif