-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.c
53 lines (44 loc) · 1.54 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
#include "main.h"
config_t *ConfigPrepare(notmon_t *notmon)
{
if(notmon->config)
{
char *config_contain = FileToBuffer(notmon->config->locate);
if(config_contain)
{
json_object *obj = json_tokener_parse(config_contain);
json_object *interval;
json_object_object_get_ex(obj, "interval", &interval);
if(json_object_get_string(interval))
notmon->config->interval = atoi(json_object_get_string(interval));
else
notmon->config->interval = 10;
json_object *line_count;
json_object_object_get_ex(obj, "line_count", &line_count);
if(json_object_get_string(line_count))
notmon->config->line_count = atoi(json_object_get_string(line_count));
else
notmon->config->line_count = 10;
json_object *temporary_dir;
json_object_object_get_ex(obj, "temporary_dir", &temporary_dir);
if(json_object_get_string(temporary_dir))
{
notmon->config->tmp_dir = malloc(sizeof(char) * (strlen(json_object_get_string(temporary_dir)) + 1));
strcpy(notmon->config->tmp_dir, json_object_get_string(temporary_dir));
}
json_object *telebot_module;
json_object_object_get_ex(obj, "telebot_module", &telebot_module);
if(telebot_module)
{
notmon->config->telebot_enable = 1;
TelebotConfigParse(notmon, json_object_get_string(telebot_module));
}
if(obj)
json_object_put(obj);
free(config_contain);
}
}
else
printf("-> Error: config memory is failure\n");
return notmon->config;
}