aboutsummaryrefslogtreecommitdiff
path: root/IdaliusConfig.pm
blob: 5827209c16fc976bd9f3fec28e9631ee6cb1190a (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
package IdaliusConfig;

use strict;
use warnings;
use Config::Tiny;

use ListParser;

sub check_config
{
	# FIXME to do: check that passed config is sane for core config vars
	my @scalar_configs = (
		'nick',
		'username',
		'ircname',
		'server',
		'port',
		'usessl',
		'sslcert',
		'sslkey',
		'password',
		'must_id',
		'quit_msg',
		'user',
		'group',
		'url_len',
		'prefix_nick',
		'prefix');
	my @list_configs = (
		'channels',
		'ignore',
		'admins',
		'plugins');
	my @optional_configs = (
		'password');

}

sub parse_config
{
	my $file = $_[0];
	my %built_config;
	my $config = Config::Tiny->read($file);

	foreach my $section (keys %{$config}) {
		foreach my $opt (keys %{$config->{$section}}) {
			# Detect list or hash config option
			my $c = substr $config->{$section}->{$opt}, 0, 1;
			if ($c eq "[") {
				my ($error, @listified) = ListParser::parse_list($config->{$section}->{$opt}, 0);
				die $error if $error;
				$config->{$section}->{$opt} = \@listified;
			} elsif ($c eq "{") {
				my ($error, %hashified) = ListParser::parse_list($config->{$section}->{$opt}, 1);
				die $error if $error;
				$config->{$section}->{$opt} = \%hashified;
			}
		}
	}

#	my ($error, @tmp) = ListParser::parse_list($config->{_}->{plugins});
#	$config->{_}->{plugins} = \@tmp;


	# Special case
	$config->{_}->{uid} = getpwnam($config->{_}->{user})
		or die "Cannot get uid of $config->{_}->{user}: $!\n";
	$config->{_}->{gid} = getgrnam($config->{_}->{group})
		or die "Cannot get gid of $config->{_}->{group}: $!\n";

	return $config;
}
1;