Commit e55f33a2 authored by Jonathon Duerig's avatar Jonathon Duerig

Fixed XML parsing so that it works even for strings considered false by Perl.

parent bf6ef45d
...@@ -1020,9 +1020,7 @@ sub GetTicketAuxAux($$$$$$$$$) ...@@ -1020,9 +1020,7 @@ sub GetTicketAuxAux($$$$$$$$$)
# #
if (!$istunnel) { if (!$istunnel) {
foreach my $ref (@interfaces) { foreach my $ref (@interfaces) {
my $node_nickname = my $node_nickname = GeniXML::GetInterfaceNodeId($ref);
GeniXML::GetText("virtual_node_id", $ref) ||
GeniXML::GetText("node_nickname", $ref);
if (exists($lannodes{$node_nickname})) { if (exists($lannodes{$node_nickname})) {
$lanname = $node_nickname; $lanname = $node_nickname;
...@@ -1035,11 +1033,8 @@ sub GetTicketAuxAux($$$$$$$$$) ...@@ -1035,11 +1033,8 @@ sub GetTicketAuxAux($$$$$$$$$)
} }
foreach my $ref (@interfaces) { foreach my $ref (@interfaces) {
my $node_nickname = GeniXML::GetText("virtual_node_id", $ref) || my $node_nickname = GeniXML::GetInterfaceNodeId($ref);
GeniXML::GetText("node_nickname", $ref); my $iface_id = GeniXML::GetInterfaceId($ref);
my $iface_id = GeniXML::GetText("virtual_interface_id", $ref) ||
GeniXML::GetText("iface_name", $ref) ||
GeniXML::GetText("client_id", $ref);
if (!defined($iface_id)) { if (!defined($iface_id)) {
$response = $response =
...@@ -1348,19 +1343,13 @@ sub GetTicketAuxAux($$$$$$$$$) ...@@ -1348,19 +1343,13 @@ sub GetTicketAuxAux($$$$$$$$$)
$ref)->get_nodelist(); $ref)->get_nodelist();
foreach my $iface_ref (@interfaces) { foreach my $iface_ref (@interfaces) {
my $virtual_port_id = my $virtual_port_id = GeniXML::GetInterfaceId($iface_ref);
GeniXML::GetText("virtual_interface_id", $iface_ref) my $virtual_node_id = GeniXML::GetInterfaceNodeId($iface_ref);
|| GeniXML::GetText("virtual_port_id", $iface_ref);
# TODO: Fix all foo || bar declarations. They do not work correctly in if (! GeniXML::IsVersion0($iface_ref)
# the presence of an attribute which is '0'. && defined($virtual_port_id)) {
# || GeniXML::GetText("client_id", $iface_ref); $virtual_node_id = $iface2node{$virtual_port_id};
my $virtual_node_id = GeniXML::GetText("virtual_node_id", }
$iface_ref);
# TODO: Fix this for RSpec V2.
# if (! GeniXML::IsVersion0($iface_ref)
# && defined($virtual_port_id)) {
# $virtual_node_id = $iface2node{$virtual_port_id};
# }
my $component_id = GeniXML::GetText("component_id", my $component_id = GeniXML::GetText("component_id",
$iface_ref); $iface_ref);
if (!defined($virtual_node_id) || !defined($virtual_port_id)) { if (!defined($virtual_node_id) || !defined($virtual_port_id)) {
...@@ -2041,8 +2030,7 @@ sub SliverWorkAux($$$$$$$) ...@@ -2041,8 +2030,7 @@ sub SliverWorkAux($$$$$$$)
foreach my $linkref (GeniXML::FindNodes("n:interface", foreach my $linkref (GeniXML::FindNodes("n:interface",
$ref)->get_nodelist()) { $ref)->get_nodelist()) {
my $component_id = GeniXML::GetText("component_id", $linkref); my $component_id = GeniXML::GetText("component_id", $linkref);
my $virtual_iface_id = GeniXML::GetText("virtual_id", $linkref) my $virtual_iface_id = GeniXML::GetInterfaceId($linkref);
|| GeniXML::GetText("client_id", $linkref);
$ifacemap{$virtual_id} = {} $ifacemap{$virtual_id} = {}
if (!exists($ifacemap{$virtual_id})); if (!exists($ifacemap{$virtual_id}));
...@@ -2147,8 +2135,7 @@ sub SliverWorkAux($$$$$$$) ...@@ -2147,8 +2135,7 @@ sub SliverWorkAux($$$$$$$)
# The aggregate needs to get rebuilt, so delete the existing # The aggregate needs to get rebuilt, so delete the existing
# one. Needs a lot more thought. # one. Needs a lot more thought.
# #
my $sliver_urn = GeniXML::GetText("sliver_urn", $linkref) my $sliver_urn = GeniXML::GetSliverId($linkref);
|| GeniXML::GetText("sliver_id", $linkref);
if (!defined($sliver_urn)) { if (!defined($sliver_urn)) {
print STDERR print STDERR
"Could not find sliver_urn in existing link $linkname\n"; "Could not find sliver_urn in existing link $linkname\n";
...@@ -2242,11 +2229,8 @@ sub SliverWorkAux($$$$$$$) ...@@ -2242,11 +2229,8 @@ sub SliverWorkAux($$$$$$$)
} }
foreach my $ifaceref (@interfaces) { foreach my $ifaceref (@interfaces) {
my $iface_id = GeniXML::GetText("virtual_interface_id", my $iface_id = GeniXML::GetInterfaceId($ifaceref);
$ifaceref) my $node_id = GeniXML::GetInterfaceNode($ifaceref);
|| GeniXML::GetText("client_id", $ifaceref);
my $node_id = GeniXML::GetText("virtual_node_id",
$ifaceref);
if (! GeniXML::IsVersion0($ifaceref) && defined($iface_id)) { if (! GeniXML::IsVersion0($ifaceref) && defined($iface_id)) {
$node_id = $iface2node{$iface_id}; $node_id = $iface2node{$iface_id};
} }
......
...@@ -13,7 +13,8 @@ use vars qw(@ISA @EXPORT); ...@@ -13,7 +13,8 @@ use vars qw(@ISA @EXPORT);
@ISA = "Exporter"; @ISA = "Exporter";
@EXPORT = qw(Parse ParseFile IsVersion0 FindNodes FindNodesNS @EXPORT = qw(Parse ParseFile IsVersion0 FindNodes FindNodesNS
FindFirst FindElement FindAttr IsLanNode IsLocalNode IsTunnel GetExpires FindFirst FindElement FindAttr IsLanNode IsLocalNode IsTunnel GetExpires
GetNodeId GetVirtualId GetSliverId GetManagerId GetColocate GetSubnodeOf GetNodeId GetVirtualId GetInterfaceId GetInterfaceNodeId GetSliverId
GetManagerId GetColocate GetSubnodeOf
GetVirtualizationType SetVirtualizationType GetVirtualizationSubtype GetVirtualizationType SetVirtualizationType GetVirtualizationSubtype
GetExclusive SetExclusive GetLinkManager SetText GetText Serialize GetExclusive SetExclusive GetLinkManager SetText GetText Serialize
CreateDocument AddElement RemoveChild PolicyExists); CreateDocument AddElement RemoveChild PolicyExists);
...@@ -196,8 +197,7 @@ sub IsLanNode($) ...@@ -196,8 +197,7 @@ sub IsLanNode($)
if (defined($node) && $node->localname() eq "node") { if (defined($node) && $node->localname() eq "node") {
foreach my $lan (FindNodes("n:node_type | n:hardware_type", foreach my $lan (FindNodes("n:node_type | n:hardware_type",
$node)->get_nodelist()) { $node)->get_nodelist()) {
my $typeName = GetText("type_name", $lan) || my $typeName = GetFirstText($lan, "type_name", "name");
GetText("name", $lan);
if (defined($typeName) && $typeName eq "lan") { if (defined($typeName) && $typeName eq "lan") {
$result = 1; $result = 1;
last; last;
...@@ -249,8 +249,7 @@ sub IsTunnel($) ...@@ -249,8 +249,7 @@ sub IsTunnel($)
sub GetExpires($) sub GetExpires($)
{ {
my ($node) = @_; my ($node) = @_;
return GetText("valid_until", $node) || return GetFirstText($node, "valid_until", "expires");
GetText("expires", $node);
} }
sub SetExpires($$) sub SetExpires($$)
...@@ -267,40 +266,46 @@ sub SetExpires($$) ...@@ -267,40 +266,46 @@ sub SetExpires($$)
sub GetNodeId($) sub GetNodeId($)
{ {
my ($node) = @_; my ($node) = @_;
return GetText("component_uuid", $node) || return GetFirstText($node, "component_uuid", "component_urn", "uuid",
GetText("component_urn", $node) || "component_id");
GetText("uuid", $node) ||
GetText("component_id", $node);
} }
sub GetVirtualId($) sub GetVirtualId($)
{ {
my ($node) = @_; my ($node) = @_;
return GetText("virtual_id", $node) || return GetFirstText($node, "virtual_id", "nickname", "client_id");
GetText("nickname", $node) || }
GetText("client_id", $node);
sub GetInterfaceId($)
{
my ($node) = @_;
return GetFirstText($node, "virtual_interface_id", "iface_name",
"client_id", "virtual_port_id", "virtual_id");
}
sub GetInterfaceNodeId($)
{
my ($node) = @_;
return GetFirstText($node, "virtual_node_id", "node_nickname");
} }
sub GetSliverId($) sub GetSliverId($)
{ {
my ($node) = @_; my ($node) = @_;
return GetText("sliver_urn", $node) return GetFirstText($node, "sliver_urn", "sliver_id");
|| GetText("sliver_id", $node);
} }
sub GetManagerId($) sub GetManagerId($)
{ {
my ($node) = @_; my ($node) = @_;
return GetText("component_manager_uuid", $node) || return GetFirstText($node, "component_manager_uuid",
GetText("component_manager_urn", $node) || "component_manager_urn", "component_manager_id");
GetText("component_manager_id", $node);
} }
sub GetColocate($) sub GetColocate($)
{ {
my ($node) = @_; my ($node) = @_;
my $result = GetText("colocate", $node) || my $result = GetFirstText($node, "colocate", "phys_nickname");
GetText("phys_nickname", $node);
return $result; return $result;
} }
...@@ -459,6 +464,23 @@ sub GetText($$) ...@@ -459,6 +464,23 @@ sub GetText($$)
return $result; return $result;
} }
# Run GetText serially using the initial argument as an XML node
# reference and the remaining arguments as names and return the first
# defined result. Returns undefined if there are no names or if all
# GetText calls return undefined.
sub GetFirstText($@)
{
my $node = shift(@_);
my $result = undef;
foreach $name (@_) {
$result = GetText($name, $node);
if (defined($result)) {
last;
}
}
return $result;
}
# Converts the XML representation of a node to a UTF-8 string and # Converts the XML representation of a node to a UTF-8 string and
# outputs it as a complete XML document. # outputs it as a complete XML document.
sub Serialize($;$) sub Serialize($;$)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment