summaryrefslogtreecommitdiff
path: root/tools/pidl
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-11-04 02:07:30 -0800
committerGuy Harris <guy@alum.mit.edu>2014-11-04 10:08:20 +0000
commite41f08858bc86a4ecd4c33365917d27e1b8ca12e (patch)
tree0f9a0a7953e38061f40485cf16c3e0d68b9608a6 /tools/pidl
parent5025bc258cdeabbd498919d5c6b4554accdad842 (diff)
downloadwireshark-e41f08858bc86a4ecd4c33365917d27e1b8ca12e.tar.gz
SWITCH_TYPE is not always defined, SwitchType() will try to find a fallback
Pick up change from Samba: commit 4b09df897803e78265fd19f6ff19be6e3d8a3944 Author: Matthieu Patou <mat@matws.net> Date: Tue Oct 1 12:10:18 2013 -0700 pidl-wireshark: SWITCH_TYPE is not always defined, SwitchType() will try to find a fallback Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Change-Id: I1f41ece23e8fec30f9cd89a2203ad63ee6e21e36 Reviewed-on: https://code.wireshark.org/review/5105 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'tools/pidl')
-rw-r--r--tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm78
1 files changed, 46 insertions, 32 deletions
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);