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($$$$$$$$$)
#
if (!$istunnel) {
foreach my $ref (@interfaces) {
my $node_nickname =
GeniXML::GetText("virtual_node_id", $ref) ||
GeniXML::GetText("node_nickname", $ref);
my $node_nickname = GeniXML::GetInterfaceNodeId($ref);
if (exists($lannodes{$node_nickname})) {
$lanname = $node_nickname;
......@@ -1035,11 +1033,8 @@ sub GetTicketAuxAux($$$$$$$$$)
}
foreach my $ref (@interfaces) {
my $node_nickname = GeniXML::GetText("virtual_node_id", $ref) ||
GeniXML::GetText("node_nickname", $ref);
my $iface_id = GeniXML::GetText("virtual_interface_id", $ref) ||
GeniXML::GetText("iface_name", $ref) ||
GeniXML::GetText("client_id", $ref);
my $node_nickname = GeniXML::GetInterfaceNodeId($ref);
my $iface_id = GeniXML::GetInterfaceId($ref);
if (!defined($iface_id)) {
$response =
......@@ -1348,19 +1343,13 @@ sub GetTicketAuxAux($$$$$$$$$)
$ref)->get_nodelist();
foreach my $iface_ref (@interfaces) {
my $virtual_port_id =
GeniXML::GetText("virtual_interface_id", $iface_ref)
|| GeniXML::GetText("virtual_port_id", $iface_ref);
# TODO: Fix all foo || bar declarations. They do not work correctly in
# the presence of an attribute which is '0'.
# || GeniXML::GetText("client_id", $iface_ref);
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 $virtual_port_id = GeniXML::GetInterfaceId($iface_ref);
my $virtual_node_id = GeniXML::GetInterfaceNodeId($iface_ref);
if (! GeniXML::IsVersion0($iface_ref)
&& defined($virtual_port_id)) {
$virtual_node_id = $iface2node{$virtual_port_id};
}
my $component_id = GeniXML::GetText("component_id",
$iface_ref);
if (!defined($virtual_node_id) || !defined($virtual_port_id)) {
......@@ -2041,8 +2030,7 @@ sub SliverWorkAux($$$$$$$)
foreach my $linkref (GeniXML::FindNodes("n:interface",
$ref)->get_nodelist()) {
my $component_id = GeniXML::GetText("component_id", $linkref);
my $virtual_iface_id = GeniXML::GetText("virtual_id", $linkref)
|| GeniXML::GetText("client_id", $linkref);
my $virtual_iface_id = GeniXML::GetInterfaceId($linkref);
$ifacemap{$virtual_id} = {}
if (!exists($ifacemap{$virtual_id}));
......@@ -2147,8 +2135,7 @@ sub SliverWorkAux($$$$$$$)
# The aggregate needs to get rebuilt, so delete the existing
# one. Needs a lot more thought.
#
my $sliver_urn = GeniXML::GetText("sliver_urn", $linkref)
|| GeniXML::GetText("sliver_id", $linkref);
my $sliver_urn = GeniXML::GetSliverId($linkref);
if (!defined($sliver_urn)) {
print STDERR
"Could not find sliver_urn in existing link $linkname\n";
......@@ -2242,11 +2229,8 @@ sub SliverWorkAux($$$$$$$)
}
foreach my $ifaceref (@interfaces) {
my $iface_id = GeniXML::GetText("virtual_interface_id",
$ifaceref)
|| GeniXML::GetText("client_id", $ifaceref);
my $node_id = GeniXML::GetText("virtual_node_id",
$ifaceref);
my $iface_id = GeniXML::GetInterfaceId($ifaceref);
my $node_id = GeniXML::GetInterfaceNode($ifaceref);
if (! GeniXML::IsVersion0($ifaceref) && defined($iface_id)) {
$node_id = $iface2node{$iface_id};
}
......
......@@ -13,7 +13,8 @@ use vars qw(@ISA @EXPORT);
@ISA = "Exporter";
@EXPORT = qw(Parse ParseFile IsVersion0 FindNodes FindNodesNS
FindFirst FindElement FindAttr IsLanNode IsLocalNode IsTunnel GetExpires
GetNodeId GetVirtualId GetSliverId GetManagerId GetColocate GetSubnodeOf
GetNodeId GetVirtualId GetInterfaceId GetInterfaceNodeId GetSliverId
GetManagerId GetColocate GetSubnodeOf
GetVirtualizationType SetVirtualizationType GetVirtualizationSubtype
GetExclusive SetExclusive GetLinkManager SetText GetText Serialize
CreateDocument AddElement RemoveChild PolicyExists);
......@@ -196,8 +197,7 @@ sub IsLanNode($)
if (defined($node) && $node->localname() eq "node") {
foreach my $lan (FindNodes("n:node_type | n:hardware_type",
$node)->get_nodelist()) {
my $typeName = GetText("type_name", $lan) ||
GetText("name", $lan);
my $typeName = GetFirstText($lan, "type_name", "name");
if (defined($typeName) && $typeName eq "lan") {
$result = 1;
last;
......@@ -249,8 +249,7 @@ sub IsTunnel($)
sub GetExpires($)
{
my ($node) = @_;
return GetText("valid_until", $node) ||
GetText("expires", $node);
return GetFirstText($node, "valid_until", "expires");
}
sub SetExpires($$)
......@@ -267,40 +266,46 @@ sub SetExpires($$)
sub GetNodeId($)
{
my ($node) = @_;
return GetText("component_uuid", $node) ||
GetText("component_urn", $node) ||
GetText("uuid", $node) ||
GetText("component_id", $node);
return GetFirstText($node, "component_uuid", "component_urn", "uuid",
"component_id");
}
sub GetVirtualId($)
{
my ($node) = @_;
return GetText("virtual_id", $node) ||
GetText("nickname", $node) ||
GetText("client_id", $node);
return GetFirstText($node, "virtual_id", "nickname", "client_id");
}
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($)
{
my ($node) = @_;
return GetText("sliver_urn", $node)
|| GetText("sliver_id", $node);
return GetFirstText($node, "sliver_urn", "sliver_id");
}
sub GetManagerId($)
{
my ($node) = @_;
return GetText("component_manager_uuid", $node) ||
GetText("component_manager_urn", $node) ||
GetText("component_manager_id", $node);
return GetFirstText($node, "component_manager_uuid",
"component_manager_urn", "component_manager_id");
}
sub GetColocate($)
{
my ($node) = @_;
my $result = GetText("colocate", $node) ||
GetText("phys_nickname", $node);
my $result = GetFirstText($node, "colocate", "phys_nickname");
return $result;
}
......@@ -459,6 +464,23 @@ sub GetText($$)
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
# outputs it as a complete XML document.
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