diff --git a/tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 4aa19a69e6..66c5e52fba 100644 --- a/tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -412,6 +412,29 @@ sub ElementLevel($$$$$$$$) } } +sub SwitchType($$;$) +{ + my ($e, $type, $nodiscriminant) = @_; + + my $switch_dt = getType($type); + my $switch_type = undef; + if ($switch_dt->{DATA}->{TYPE} eq "ENUM") { + $switch_type = Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA}); + } elsif ($switch_dt->{DATA}->{TYPE} eq "BITMAP") { + $switch_type = Parse::Pidl::Typelist::bitmap_type_fn($switch_dt->{DATA}); + } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") { + if (defined $e->{SWITCH_TYPE}) { + $switch_type = "$e->{SWITCH_TYPE}"; + } else { + $switch_type = "$switch_dt->{DATA}->{NAME}"; + } + } elsif (not defined $e->{SWITCH_TYPE}) { + $switch_type = $nodiscriminant; + } + + return $switch_type +} + sub Element($$$$$$) { my ($self,$e,$pn,$ifname,$isoruseswitch,%switchvars) = @_; @@ -425,27 +448,23 @@ sub Element($$$$$$) my $name = $isoruseswitch->[1]; my $switch_dt = getType($type); - my $switch_type; - if ($switch_dt->{DATA}->{TYPE} eq "ENUM") { - $switch_type = "g".Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA}); - } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") { - $switch_type = "g$type"; + my $switch_raw_type = SwitchType($e, $type, "uint32"); + if (not defined($switch_raw_type)) { + die("Unknown type[$type]\n"); } - if ($switch_type ne "") { - $moreparam = ", $switch_type *".$name; + my $switch_type = "g${switch_raw_type}"; - if (($e->{PROPERTIES}->{switch_is} eq "") && ($switchvars{$name}) && - #not a "native" type - (!($type =~ /^uint(8|16|1632|32|3264|64)/))) { - $param = $name; - } elsif ( $switch_dt->{DATA}->{TYPE} eq "ENUM") { - $param = $name; - } else { - $param = "*".$name; - } + $moreparam = ", $switch_type *".$name; + + if (($e->{PROPERTIES}->{switch_is} eq "") && ($switchvars{$name}) && + #not a "native" type + (!($type =~ /^uint(8|16|1632|32|3264|64)/))) { + $param = $name; + } elsif ( $switch_dt->{DATA}->{TYPE} eq "ENUM") { + $param = $name; } else { - $moreparam = ""; + $param = "*".$name; } if ($name ne "") { @@ -654,13 +673,11 @@ sub Struct($$$$) my $v = $_->{NAME}; if (scalar(grep {/^$v$/} keys(%$varswitchs)) == 1) { # This element is one of the switch attribute - my $switch_dt = getType($_->{TYPE}); - my $switch_type; - if ($switch_dt->{DATA}->{TYPE} eq "ENUM") { - $switch_type = "g".Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA}); - } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") { - $switch_type = "g$_->{TYPE}"; + my $switch_raw_type = SwitchType($e, $_->{TYPE}, "uint32"); + if (not defined($switch_raw_type)) { + die("Unknown type[$_->{TYPE}]\n"); } + my $switch_type = "g${switch_raw_type}"; if ($switch_type ne "") { push @$vars, "$switch_type $v = 0;"; @@ -771,15 +788,12 @@ sub Union($$$$) $res.="\t\tbreak;\n"; } - my $switch_type; - my $switch_dissect; - my $switch_dt = getType($e->{SWITCH_TYPE}); - if ($switch_dt->{DATA}->{TYPE} eq "ENUM") { - $switch_type = "g".Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA}); - $switch_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA}); - } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") { - $switch_type = "g$e->{SWITCH_TYPE}"; - $switch_dissect = "dissect_ndr_$e->{SWITCH_TYPE}"; + my $switch_type = undef; + my $switch_dissect = undef; + my $switch_raw_type = SwitchType($e, $e->{SWITCH_TYPE}); + if (defined($switch_raw_type)) { + $switch_type = "g${switch_raw_type}"; + $switch_dissect = "dissect_ndr_${switch_raw_type}"; } $self->pidl_fn_start($dissectorname);