TODO not needed??? tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm Function switch levels
authorStefan Metzmacher <metze@samba.org>
Thu, 2 Feb 2023 15:43:07 +0000 (16:43 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 3 Feb 2023 09:31:32 +0000 (10:31 +0100)
tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm

index 30cab8a410bdb6400ab33d743ab14c9cc85fa85b..6e18daee507628c8c3413d4b2a76ab13160ee2f2 100644 (file)
@@ -704,8 +704,60 @@ sub Function($$$)
 
        my %dissectornames;
 
+       my $paramsrefs = {};
+       # will contain the switch var declaration;
+       my $vars = [];
+       my %paramshash;
        foreach (@{$fn->{ELEMENTS}}) {
-           $dissectornames{$_->{NAME}} = $self->Element($_, $fn->{NAME}, $ifname, undef, undef) if not defined($dissectornames{$_->{NAME}});
+               my $paramvar = undef;
+
+               if (has_property($_, "switch_is")) {
+                       $paramvar = $_->{PROPERTIES}->{switch_is};
+               }
+
+               if ($_->{LEVELS}[0]{IS_INLINE}) {
+                       $paramvar = $_->{LEVELS}[0]{SIZE_IS};
+               }
+
+               if (defined($paramvar)) {
+                       $paramsrefs->{$paramvar} = [];
+                       $paramshash{$paramvar} = $paramvar;
+               }
+       }
+
+       foreach (@{$fn->{ELEMENTS}}) {
+               my $paraminfo = undef;
+
+               my $v = $_->{NAME};
+               if (scalar(grep {/^$v$/} keys(%$paramsrefs)) == 1) {
+                       # This element is one of the switch attribute
+                       my $switch_raw_type = SwitchType($_, $_->{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;";
+                       }
+                       $paraminfo = [ $_->{TYPE}, $v ];
+                       $paramsrefs->{$v} = $paraminfo;
+               }
+
+               my $paramvar = undef;
+               if (has_property($_, "switch_is")) {
+                       $paramvar = $_->{PROPERTIES}->{switch_is};
+               }
+
+               if ($_->{LEVELS}[0]{IS_INLINE}) {
+                       $paramvar = $_->{LEVELS}[0]{SIZE_IS};
+               }
+
+               if (defined($paramvar)) {
+                       $paraminfo = $paramsrefs->{$paramvar};
+               }
+
+               $dissectornames{$_->{NAME}} = $self->Element($_, $fn->{NAME}, $ifname, $paraminfo, %paramshash) if not defined($dissectornames{$_->{NAME}});
        }
 
        my $fn_name = $_->{NAME};
@@ -717,6 +769,7 @@ sub Function($$$)
        $self->pidl_code("$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, guint8 *drep _U_)");
        $self->pidl_code("{");
        $self->indent;
+       $self->pidl_code($_) foreach (@$vars);
        if ( not defined($fn->{RETURN_TYPE})) {
        } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS" or $fn->{RETURN_TYPE} eq "WERROR" or $fn->{RETURN_TYPE} eq "HRESULT")
        {
@@ -786,6 +839,7 @@ sub Function($$$)
        $self->pidl_code("$ifname\_dissect\_${fn_name}_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, guint8 *drep _U_)");
        $self->pidl_code("{");
        $self->indent;
+       $self->pidl_code($_) foreach (@$vars);
        $self->pidl_code("di->dcerpc_procedure_name=\"${fn_name}\";");
        foreach (@{$fn->{ELEMENTS}}) {
                if (grep(/in/,@{$_->{DIRECTION}})) {