-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.c
73 lines (63 loc) · 1.64 KB
/
config.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "inih/ini.h"
static int configHandler(void* user, const char* section, const char* name, const char* value)
{
configuration* pconfig = (configuration*)user;
#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
if (MATCH("config", "debug")) {
pconfig->debug = atoi(value);
} else if (MATCH("config", "gpio_warning_light")) {
pconfig->gpioWarningLight = atoi(value);
} else if (MATCH("config", "gpio_buzzer")) {
pconfig->gpioBuzzer = atoi(value);
} else if (MATCH("config", "credential")) {
pconfig->credential = strdup(value);
} else if (MATCH("config", "test_url")) {
pconfig->testUrl = strdup(value);
} else if (MATCH("config", "bash_success")) {
pconfig->bashSuccess = strdup(value);
} else if (MATCH("config", "bash_fail")) {
pconfig->bashFail = strdup(value);
} else {
return 0;
}
return 1;
}
void setupConfig(char* configFilePath)
{
if (ini_parse(configFilePath, configHandler, &config) < 0) {
fprintf(stderr, "Can't load '%s' config file.\n", configFilePath);
exit(-1);
}
}
int getConfigDebug()
{
return config.debug;
}
int getConfigGpioWarningLight()
{
return config.gpioWarningLight;
}
int getConfigGpioBuzzer()
{
return config.gpioBuzzer;
}
const char* getConfigCredential()
{
return config.credential;
}
const char* getConfigTestUrl()
{
return config.testUrl;
}
const char* getConfigBashSuccess()
{
return config.bashSuccess;
}
const char* getConfigBashFail()
{
return config.bashFail;
}