2 # parse-config: Parse an XML-format
3 # ACS configuration file and build the configuration
7 package Sip::Configuration;
12 use XML::Simple qw(:strict);
14 use Sip::Configuration::Institution;
15 use Sip::Configuration::Account;
16 use Sip::Configuration::Service;
18 my $parser = new XML::Simple( KeyAttr => { login => '+id',
21 GroupTags => { listeners => 'service',
23 institutions => 'institution', },
24 ForceArray=> [ 'service',
27 ValueAttr => { 'error-detect' => 'enabled',
28 'min_servers' => 'value',
29 'max_servers' => 'value'} );
32 my ($class, $config_file) = @_;
33 my $cfg = $parser->XMLin($config_file);
36 foreach my $acct (values %{$cfg->{accounts}}) {
37 new Sip::Configuration::Account $acct;
40 # The key to the listeners hash is the 'port' component of the
41 # configuration, which is of the form '[host]:[port]/proto', and
42 # the 'proto' component could be upper-, lower-, or mixed-cased.
43 # Regularize it here to lower-case, and then do the same below in
44 # find_server() when building the keys to search the hash.
46 foreach my $service (values %{$cfg->{listeners}}) {
47 new Sip::Configuration::Service $service;
48 $listeners{lc $service->{port}} = $service;
50 $cfg->{listeners} = \%listeners;
52 foreach my $inst (values %{$cfg->{institutions}}) {
53 new Sip::Configuration::Institution $inst;
55 return bless $cfg, $class;
60 return $self->{'error-detect'};
64 return values %{$self->{accounts}};
69 # return values %{$self->{policy}};
73 my ($self, $sockaddr, $port, $proto) = @_;
75 foreach my $addr ('', '*:', "$sockaddr:") {
76 $portstr = sprintf("%s%s/%s", $addr, $port, lc $proto);
77 Sys::Syslog::syslog("LOG_DEBUG", "Configuration::find_service: Trying $portstr");
78 last if (exists(($self->{listeners})->{$portstr}));
80 return $self->{listeners}->{$portstr};
89 eval join('',<main::DATA>) || die $@ unless caller();
95 my $config = new Sip::Configuration $ARGV[0];
98 foreach my $acct ($config->accounts) {
99 print "Found account '", $acct->name, "', part of '"
100 print $acct->institution, "'\n";