summaryrefslogtreecommitdiffstats
path: root/PICA_nodeconfig.c
blob: 68439bb3cd6b06e6b51b1deea5ffb23a397d60a6 (plain) (blame)
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
/*
	(c) Copyright  2012 - 2018 Anton Sviridenko
	https://picapica.im

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

#include "PICA_nodeconfig.h"

#include "iniparser/src/iniparser.h"
#include "iniparser/src/dictionary.h"

#include <string.h>

struct nodeconfig nodecfg;

int PICA_nodeconfig_load(const char *config_file)
{
	dictionary *d;

	d = iniparser_load(config_file);

	if (!d)
		return 0;

	nodecfg.announced_addr = strdup(iniparser_getstring(d, "pica-node:announced_addr", PICA_NODECONFIG_DEF_ANNOUNCED_ADDR));
	nodecfg.listen_port = strdup(iniparser_getstring(d, "pica-node:listen_port", PICA_NODECONFIG_DEF_LISTEN_PORT));
	nodecfg.nodes_db_file = strdup(iniparser_getstring(d, "pica-node:nodes_db_file", PICA_NODECONFIG_DEF_NODES_DB_FILE));
	nodecfg.dh_param_file = strdup(iniparser_getstring(d, "pica-node:dh_param_file", PICA_NODECONFIG_DEF_DH_PARAM_FILE));
	nodecfg.disable_reserved_addrs = iniparser_getboolean(d, "pica-node:disable_reserved_addrs", 1);

	iniparser_freedict(d);

	return 1;
}