#!/usr/bin/perl # Author : Damien KROTKINE (damien@tuxfamily.org) # # Contributors : # Charles LONGEAU (chl@tuxfamily.org) # # Copyright (C) 2002 Damien KROTKINE (damien@tuxfamily.org) # Copyright (C) 2002 Charles LONGEAU (chl@tuxfamily.org) # # 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 2, 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, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package Libconf::Glueconf::Resolv; use strict; use vars qw(@ISA); use Libconf::Glueconf; use Libconf::Libconf; @ISA = qw(Libconf); sub new { my ($pkg, $filename) = @_; my %self; my $libconf = $pkg->Libconf::new($filename, 'resolv', ''); tie my @nameserver_wrapper, 'Libconf::Glueconf::Resolv::Nameserver::Wrapper', $libconf; $self{nameserver} = \@nameserver_wrapper; tie my $domain_wrapper, 'Libconf::Glueconf::Resolv::Domain::Wrapper', $libconf; $self{domain} = \$domain_wrapper; tie my @search_wrapper, 'Libconf::Glueconf::Resolv::Search::Wrapper', $libconf; $self{search} = \@search_wrapper; tie my @sortlist_wrapper, 'Libconf::Glueconf::Resolv::Sortlist::Wrapper', $libconf; $self{sortlist} = \@sortlist_wrapper; tie my @options_wrapper, 'Libconf::Glueconf::Resolv::Options::Wrapper', $libconf; $self{options} = \@options_wrapper; $self{libconf} = $libconf; bless \%self, $pkg; } sub readConf { my ($obj) = @_; $obj->{libconf}->readConf(); } sub writeConf { my ($obj) = @_; $obj->{libconf}->writeConf(); } package Libconf::Glueconf::Resolv::Nameserver::Wrapper; sub debug { $ENV{DEBUG} and print @_ } sub TIEARRAY { my ($pkg, $libconf) = @_; debug "NAMESERVER Wrapper - TIEARRAY\n"; bless { libconf => $libconf }, $pkg; } sub FETCH { my ($obj, $idx) = @_; debug "NAMESERVER Wrapper - FETCH - idx : $idx\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); $obj->{libconf}->getAtom($pos[$idx])->{value}; } sub FETCHSIZE { my ($obj) = @_; debug "NAMESERVER Wrapper - FETCHSIZE\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); # require Data::Dumper; # print Data::Dumper->Dump([@pos], ['pos']) . "\n"; # debug "NAMESERVER Wrapper - FETCHSIZE : " . scalar(@pos) . "\n"; scalar(@pos); } sub STORE { my ($obj, $idx, $value) = @_; debug "NAMESERVER Wrapper - STORE - idx : $idx - value : $value\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); if ($idx > $#pos) { $obj->{libconf}->insertAtom($pos[-1]+1, {type => 'VALUE', type2 => 'RESOLV_NAMESERVER', value => $value}); } else { $obj->{libconf}->ediAtom($pos[$idx], {type => 'VALUE', type2 => 'RESOLV_NAMESERVER', value => $value}); } } package Libconf::Glueconf::Resolv::Domain::Wrapper; sub debug { $ENV{DEBUG} and print @_ } sub TIESCALAR { my ($pkg, $libconf) = @_; debug "DOMAIN Wrapper - TIEARRAY\n"; bless { libconf => $libconf }, $pkg; } sub FETCH { my ($obj) = @_; debug "DOMAIN Wrapper - FETCH\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_DOMAIN' }); @pos > 0 or return undef; $obj->{libconf}->getAtom($pos[-1])->{value}; } sub STORE { my ($obj, $value) = @_; debug "DOMAIN Wrapper - STORE - value : $value\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_DOMAIN' }); if (@pos > 0) { $obj->{libconf}->ediAtom($pos[-1], {type => 'VALUE', type2 => 'RESOLV_DOMAIN', value => $value}); } else { $obj->{libconf}->appendAtom({type => 'VALUE', type2 => 'RESOLV_DOMAIN', value => $value}); } } package Libconf::Glueconf::Resolv::Search::Wrapper; sub debug { $ENV{DEBUG} and print @_ } sub TIEARRAY { my ($pkg, $libconf) = @_; debug "SEARCH Wrapper - TIEARRAY\n"; bless { libconf => $libconf }, $pkg; } sub FETCH { my ($obj, $idx) = @_; debug "SEARCH Wrapper - FETCH - idx : $idx\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); $obj->{libconf}->getAtom($pos[-1])->{list}->[$idx]; } sub FETCHSIZE { my ($obj) = @_; debug "SEARCH Wrapper - FETCHSIZE\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); @pos > 0 or return 0; # require Data::Dumper; # print Data::Dumper->Dump([@pos], ['@pos']) . "\n"; my $pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); # print Data::Dumper->Dump([$pos], ['$pos']) . "\n"; # debug "SEARCH Wrapper - FETCHSIZE : " . scalar(@{$obj->{libconf}->getAtom($pos[-1])->{list}}) . "\n"; scalar @{$obj->{libconf}->getAtom($pos[-1])->{list}}; } sub STORE { my ($obj, $idx, $value) = @_; debug "SEARCH Wrapper - STORE - idx : $idx - value : $value\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; $tab[$idx] = $value; $obj->{libconf}->ediAtom($pos[-1], { list => \@tab }); } package Libconf::Glueconf::Resolv::Sortlist::Wrapper; sub debug { $ENV{DEBUG} and print @_ } sub TIEARRAY { my ($pkg, $libconf) = @_; debug "SORTLIST Wrapper - TIEARRAY\n"; bless { libconf => $libconf }, $pkg; } sub FETCH { my ($obj, $idx) = @_; debug "SORTLIST Wrapper - FETCH - idx : $idx\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); $obj->{libconf}->getAtom($pos[-1])->{list}->[$idx]; } sub FETCHSIZE { my ($obj) = @_; debug "SORTLIST Wrapper - FETCHSIZE\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); @pos > 0 or return 0; scalar @{$obj->{libconf}->getAtom($pos[-1])->{list}}; } sub STORE { my ($obj, $idx, $value) = @_; debug "SORTLIST Wrapper - STORE - idx : $idx - value : $value\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; $tab[$idx] = $value; $obj->{libconf}->ediAtom($pos[-1], { list => \@tab }); } package Libconf::Glueconf::Resolv::Options::Wrapper; sub debug { $ENV{DEBUG} and print @_ } sub TIEARRAY { my ($pkg, $libconf) = @_; debug "OPTIONS Wrapper - TIEARRAY\n"; bless { libconf => $libconf }, $pkg; } sub FETCH { my ($obj, $idx) = @_; debug "OPTIONS Wrapper - FETCH - idx : $idx\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); $obj->{libconf}->getAtom($pos[-1])->{list}->[$idx]; } sub FETCHSIZE { my ($obj) = @_; debug "OPTIONS Wrapper - FETCHSIZE\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); @pos > 0 or return 0; scalar @{$obj->{libconf}->getAtom($pos[-1])->{list}}; } sub STORE { my ($obj, $idx, $value) = @_; debug "OPTIONS Wrapper - STORE - idx : $idx - value : $value\n"; my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; $tab[$idx] = $value; $obj->{libconf}->ediAtom($pos[-1], { list => \@tab }); } 1;