Skip to content

Commit

Permalink
pidl-wireshark: SWITCH_TYPE is not always defined, SwitchType() will …
Browse files Browse the repository at this point in the history
…try to find a fallback

Pair-Programmed-With: Stefan Metzmacher <[email protected]>

Signed-off-by: Matthieu Patou <[email protected]>
Signed-off-by: Stefan Metzmacher <[email protected]>

Autobuild-User(master): Stefan Metzmacher <[email protected]>
Autobuild-Date(master): Fri Oct 24 01:39:16 CEST 2014 on sn-devel-104
  • Loading branch information
ekacnet authored and metze-samba committed Oct 23, 2014
1 parent 93f262e commit 4b09df8
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions pidl/lib/Parse/Pidl/Wireshark/NDR.pm
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,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) = @_;
Expand All @@ -426,13 +449,12 @@ sub Element($$$$$)
my $type = $isoruseswitch->[0];
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$e->{SWITCH_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}";

$moreparam = ", $switch_type *".$name;
$param = $name;
$call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep, &$name);";
Expand Down Expand Up @@ -632,13 +654,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$e->{SWITCH_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}";

push @$vars, "$switch_type $v;";
$switch_info = [ $_->{TYPE}, $v ];
Expand Down Expand Up @@ -741,15 +761,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);
Expand Down

0 comments on commit 4b09df8

Please sign in to comment.