summaryrefslogtreecommitdiff
path: root/lib/Vyatta/ConfigOutput.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Vyatta/ConfigOutput.pm')
-rwxr-xr-xlib/Vyatta/ConfigOutput.pm230
1 files changed, 128 insertions, 102 deletions
diff --git a/lib/Vyatta/ConfigOutput.pm b/lib/Vyatta/ConfigOutput.pm
index 1218a8d..acb2bb3 100755
--- a/lib/Vyatta/ConfigOutput.pm
+++ b/lib/Vyatta/ConfigOutput.pm
@@ -70,7 +70,9 @@ sub displayValues {
my $prefix = $_[2];
my $name = $_[3];
my $simple_show = $_[4];
- my ($is_multi, $is_text, $default) = $config->parseTmpl(\@cur_path);
+
+ $config->setLevel(join ' ', @cur_path);
+ my ($is_multi, $is_text, $default) = $config->parseTmpl();
if ($is_text) {
$default =~ /^"(.*)"$/;
my $txt = $1;
@@ -81,11 +83,10 @@ sub displayValues {
my $is_password = ($name =~ /^.*(passphrase|password|pre-shared-secret|key)$/);
my $HIDE_PASSWORD = '****************';
- $config->setLevel(join ' ', @cur_path);
if ($is_multi) {
- my @ovals = $config->returnOrigValues('','true');
- my @nvals = $config->returnValues('','true');
+ my @ovals = $config->returnOrigValuesDA();
+ my @nvals = $config->returnValuesDA();
if ($is_text) {
@ovals = map { (txt_need_quotes($_)) ? "\"$_\"" : "$_"; } @ovals;
@nvals = map { (txt_need_quotes($_)) ? "\"$_\"" : "$_"; } @nvals;
@@ -128,8 +129,8 @@ sub displayValues {
print "$dis$diff$prefix$name $nval\n";
}
} else {
- my $oval = $config->returnOrigValue('','true');
- my $nval = $config->returnValue('','true');
+ my $oval = $config->returnOrigValueDA();
+ my $nval = $config->returnValueDA();
if ($is_text) {
if (defined($oval) && txt_need_quotes($oval)) {
$oval = "\"$oval\"";
@@ -139,7 +140,7 @@ sub displayValues {
}
}
- my %cnodes = $config->listNodeStatus(undef,'true');
+ my %cnodes = $config->listNodeStatusDA();
my @cnames = sort keys %cnodes;
if (defined($simple_show)) {
@@ -189,16 +190,19 @@ sub displayDeletedOrigChildren {
if (defined($dont_show_as_deleted)) {
$dprefix = '';
}
- $config->setLevel('');
- my @children = $config->listOrigNodes(join(' ', @cur_path),'true');
+ $config->setLevel('');
+ my @children = $config->listOrigNodesDA(join(' ', @cur_path));
for my $child (sort @children) {
+ # reset level
+ $config->setLevel('');
+
if ($child eq 'node.val') {
# should not happen!
next;
}
- my $is_tag = $config->isTagNode([ @cur_path, $child ]);
+ my $is_tag = $config->isTagNode(join(' ', @cur_path, $child));
if (!defined $is_tag) {
my $path = join(' ',( @cur_path, $child ));
@@ -207,31 +211,37 @@ sub displayDeletedOrigChildren {
print "$prefix /* $comment */\n";
}
- my ($state, $n) = $config->getDeactivated($path);
- if (defined $state) {
- if ($state eq 'active') {
- $dis = '! ';
- }
- elsif ($state eq 'local') {
- if (defined($dont_show_as_deleted)) {
- $dis = ' ';
- }
- else {
- $dis = 'D ';
- }
- }
- else {
- $dis = '! ';
- }
- }
- else {
- $dis = ' ';
- }
+ # check deactivate state
+ my $de_working = $config->deactivated($path);
+ my $de_active = $config->deactivatedOrig($path);
+ if ($de_active) {
+ if ($de_working) {
+ # deactivated in both
+ $dis = '! ';
+ } else {
+ # deactivated only in active
+ $dis = '! ';
+ }
+ } else {
+ if ($de_working) {
+ # deactivated only in working
+ if (defined($dont_show_as_deleted)) {
+ $dis = ' ';
+ } else {
+ $dis = 'D ';
+ }
+ } else {
+ # deactivated in neither
+ $dis = ' ';
+ }
+ }
}
$config->setLevel(join ' ', (@cur_path, $child));
- my @cnames = grep(!/^def$/, sort($config->listOrigNodes(undef,'true')));
+ # remove listOrigNodesNoDef so it's one fewer function that uses
+ # the cstore implementation details at the perl API level.
+ my @cnames = grep(!/^def$/, sort($config->listOrigNodesDA()));
if ($cnames[0] eq 'node.val') {
displayValues([ @cur_path, $child ], $dis, $prefix, $child,
@@ -248,33 +258,37 @@ sub displayDeletedOrigChildren {
}
my $path = join(' ',( @cur_path, $child, $cname ));
+ $config->setLevel($path);
- my $comment = $config->returnComment($path);
+ my $comment = $config->returnComment();
if (defined $comment) {
print "$prefix /* $comment */\n";
}
- #need separate check here
- my ($state, $n) = $config->getDeactivated($path);
- if (defined $state) {
- if ($state eq 'active') {
- $dis = '! ';
- }
- elsif ($state eq 'local') {
- if (defined($dont_show_as_deleted)) {
- $dis = ' ';
- }
- else {
- $dis = 'D ';
- }
- }
- else {
- $dis = '! ';
- }
- }
- else {
- $dis = ' ';
- }
+ # check deactivate state
+ my $de_working = $config->deactivated();
+ my $de_active = $config->deactivatedOrig();
+ if ($de_active) {
+ if ($de_working) {
+ # deactivated in both
+ $dis = '! ';
+ } else {
+ # deactivated only in active
+ $dis = '! ';
+ }
+ } else {
+ if ($de_working) {
+ # deactivated only in working
+ if (defined($dont_show_as_deleted)) {
+ $dis = ' ';
+ } else {
+ $dis = 'D ';
+ }
+ } else {
+ # deactivated in neither
+ $dis = ' ';
+ }
+ }
print "$dis$dprefix$prefix$child $cname {\n";
displayDeletedOrigChildren([ @cur_path, $child, $cname ],
@@ -288,7 +302,7 @@ sub displayDeletedOrigChildren {
print "$dis$dprefix$prefix}\n";
}
} else {
- my $has_tmpl_children = $config->hasTmplChildren([ @cur_path, $child ]);
+ my $has_tmpl_children = $config->hasTmplChildren();
print "$dis$dprefix$prefix$child"
. ($has_tmpl_children ? " {\n$dis$dprefix$prefix}\n" : "\n");
}
@@ -323,7 +337,9 @@ sub displayChildren {
} elsif ($child_hash{$child} eq 'changed') {
$vdiff = '>';
}
- my $is_tag = $config->isTagNode([ @cur_path, $child ]);
+
+ $config->setLevel('');
+ my $is_tag = $config->isTagNode(join(' ', @cur_path, $child));
if (!defined($is_tag)) {
my $path = join(' ',( @cur_path, $child ));
@@ -332,30 +348,34 @@ sub displayChildren {
print "$prefix /* $comment */\n";
}
- my ($state, $n) = $config->getDeactivated($path);
- if (defined $state) {
- if ($state eq 'active') {
- if ($child_hash{$child} eq 'deleted') {
- $dis = '! ';
- }
- else {
- $dis = 'A ';
- }
- }
- elsif ($state eq 'local') {
- $dis = 'D ';
- }
- else {
- $dis = '! ';
- }
- }
- else {
- $dis = ' ';
- }
+ # check deactivate state
+ my $de_working = $config->deactivated($path);
+ my $de_active = $config->deactivatedOrig($path);
+ if ($de_active) {
+ if ($de_working) {
+ # deactivated in both
+ $dis = '! ';
+ } else {
+ # deactivated only in active
+ if ($child_hash{$child} eq 'deleted') {
+ $dis = '! ';
+ } else {
+ $dis = 'A ';
+ }
+ }
+ } else {
+ if ($de_working) {
+ # deactivated only in working
+ $dis = 'D ';
+ } else {
+ # deactivated in neither
+ $dis = ' ';
+ }
+ }
}
$config->setLevel(join ' ', (@cur_path, $child));
- my %cnodes = $config->listNodeStatus(undef,'true');
+ my %cnodes = $config->listNodeStatusDA();
my @cnames = sort keys %cnodes;
#if node.val exists and ct == 0 w/o def or ct ==1 w/ def
@@ -382,31 +402,36 @@ sub displayChildren {
}
my $path = join(' ',( @cur_path, $child, $cname ));
- my $comment = $config->returnComment($path);
+ $config->setLevel($path);
+ my $comment = $config->returnComment();
if (defined $comment) {
print "$prefix /* $comment */\n";
}
- my ($state, $n) = $config->getDeactivated($path);
- if (defined $state) {
- if ($state eq 'active') {
- if ($cnodes{$cname} eq 'deleted') {
- $dis = '! ';
- }
- else {
- $dis = 'A ';
- }
- }
- elsif ($state eq 'local') {
- $dis = 'D ';
- }
- else {
- $dis = '! ';
- }
- }
- else {
- $dis = ' ';
- }
+ # check deactivate state
+ my $de_working = $config->deactivated();
+ my $de_active = $config->deactivatedOrig();
+ if ($de_active) {
+ if ($de_working) {
+ # deactivated in both
+ $dis = '! ';
+ } else {
+ # deactivated only in active
+ if ($cnodes{$cname} eq 'deleted') {
+ $dis = '! ';
+ } else {
+ $dis = 'A ';
+ }
+ }
+ } else {
+ if ($de_working) {
+ # deactivated only in working
+ $dis = 'D ';
+ } else {
+ # deactivated in neither
+ $dis = ' ';
+ }
+ }
my $tdiff = ' ';
if ($cnodes{$cname} eq 'deleted') {
@@ -420,7 +445,7 @@ sub displayChildren {
$dis, "$prefix ");
} else {
$config->setLevel(join ' ', (@cur_path, $child, $cname));
- my %ccnodes = $config->listNodeStatus(undef,'true');
+ my %ccnodes = $config->listNodeStatusDA();
displayChildren(\%ccnodes, [ @cur_path, $child, $cname ],
$dis, "$prefix ");
}
@@ -439,7 +464,7 @@ sub displayChildren {
} else {
if ($child_hash{$child} eq 'deleted') {
$config->setLevel('');
- my @onodes = $config->listOrigNodes(join ' ', (@cur_path, $child), 'true');
+ my @onodes = $config->listOrigNodesDA(join ' ', (@cur_path, $child));
if ($#onodes == 0 && $onodes[0] eq 'node.val') {
displayValues([ @cur_path, $child ], $dis, $prefix, $child);
} else {
@@ -449,7 +474,7 @@ sub displayChildren {
}
} else {
my $has_tmpl_children
- = $config->hasTmplChildren([ @cur_path, $child ]);
+ = $config->hasTmplChildren();
print "$dis$diff$prefix$child"
. ($has_tmpl_children ? " {\n$dis$diff$prefix}\n" : "\n");
}
@@ -462,7 +487,7 @@ sub displayChildren {
sub outputNewConfig {
$config = new Vyatta::Config;
$config->setLevel(join ' ', @_);
- my %rnodes = $config->listNodeStatus(undef,'true');
+ my %rnodes = $config->listNodeStatusDA();
if (scalar(keys %rnodes) > 0) {
my @rn = keys %rnodes;
@@ -489,7 +514,8 @@ sub outputNewConfig {
if ($config->existsOrig() && ! $config->exists()) {
# this is a deleted node
print 'Configuration under "' . (join ' ', @_) . "\" has been deleted\n";
- } elsif (!defined($config->getTmplPath(\@_))) {
+ } elsif (!$config->validateTmplPath('', 1)) {
+ # validation of current path (including values) failed
print "Specified configuration path is not valid\n";
} else {
print 'Configuration under "' . (join ' ', @_) . "\" is empty\n";