From 71f99b2a1ef9db44ddad1a554922ba0baae28c9e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 6 Dec 2001 03:59:51 +0000 Subject: Don't pass down drep (data representation) arg from top level fn. Decided to use tridge's PARSE_SCALARS and PARSE_BUFFERS pattern for generating code for structures and function calls. For functions, dissect sub-structures with PARSE_SCALARS|PARSE_BUFFERS. For arrays and structures in structures (?) use PARSE_SCALARS on each element of the structure then PARSE_BUFFERS. Determine whether a type is a "simple" type or a struct/union. (This used to be commit bb5bab58177fafd670dba8fe755b6c4753713efd) --- source4/build/pidl/eparser.pm | 44 ++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/source4/build/pidl/eparser.pm b/source4/build/pidl/eparser.pm index f9160f1fad..8a894139fb 100644 --- a/source4/build/pidl/eparser.pm +++ b/source4/build/pidl/eparser.pm @@ -10,6 +10,15 @@ use Data::Dumper; my($res); +sub is_simple_type($) +{ + my($type) = shift; + + return 1, if ($type eq "uint32"); + + return 0; +} + ##################################################################### # parse a properties list sub ParseProperties($) @@ -53,24 +62,28 @@ sub ParseStruct($) # Parse scalars - $res .= "\t/* Parse scalars */\n\n"; + $res .= "\tif (flags & PARSE_SCALARS) {\n"; foreach my $e (@{$struct->{ELEMENTS}}) { if (defined $e->{POINTERS}) { - $res .= "\toffset = dissect_ptr(tvb, offset, pinfo, tree, &ptr_$e->{NAME}, drep, \"$e->{NAME}\");\n"; + $res .= "\t\toffset = dissect_ptr(tvb, offset, pinfo, tree, &ptr_$e->{NAME}, \"$e->{NAME}\");\n"; } else { - $res .= "\toffset = dissect_$e->{TYPE}(tvb, offset, pinfo, tree, drep, \"$e->{NAME}\");\n"; + $res .= "\t\toffset = dissect_$e->{TYPE}(tvb, offset, pinfo, tree, \"$e->{NAME}\");\n"; } } + $res .= "\t}\n\n"; + # Parse buffers - $res .= "\n\t/* Parse buffers */\n\n"; + $res .= "\tif (flags & PARSE_BUFFERS) {\n"; foreach my $e (@{$struct->{ELEMENTS}}) { - $res .= "\tif (ptr_$e->{NAME})\n\t\toffset = dissect_$e->{TYPE}(tvb, offset, pinfo, tree, drep, \"$e->{NAME}\");\n\n", + $res .= "\t\tif (ptr_$e->{NAME})\n\t\t\toffset = dissect_$e->{TYPE}(tvb, offset, pinfo, tree, \"$e->{NAME}\");\n\n", if (defined $e->{POINTERS}); } + + $res .= "\t}\n\n"; } } @@ -86,7 +99,7 @@ sub ParseUnionElement($) # $res .= "}\n\n"; $res .= "\tcase $element->{DATA}->{NAME}: \n"; - $res .= "\t\toffset = dissect_$element->{DATA}->{TYPE}(tvb, offset, pinfo, tree, drep, \"$element->{DATA}->{NAME}\");\n\t\tbreak;\n"; + $res .= "\t\toffset = dissect_$element->{DATA}->{TYPE}(tvb, offset, pinfo, tree, \"$element->{DATA}->{NAME}\");\n\t\tbreak;\n"; # $res .= "[case($element->{CASE})] "; # ParseElement($element->{DATA}); @@ -132,7 +145,7 @@ sub ParseTypedef($) my($typedef) = shift; $res .= "static int dissect_$typedef->{NAME}(tvbuff_t *tvb, int offset,\ -\tpacket_info *pinfo, proto_tree *tree, char *drep)\n{\n"; +\tpacket_info *pinfo, proto_tree *tree)\n{\n"; ParseType($typedef->{DATA}); $res .= "}\n\n"; } @@ -151,18 +164,23 @@ sub ParseFunctionArg($$) foreach my $prop (@{$arg->{PROPERTIES}}) { if ($prop =~ /context_handle/) { - $res .= "\toffset = dissect_policy_hnd(tvb, offset, pinfo, tree, drep);\n"; + $res .= "\toffset = dissect_policy_hnd(tvb, offset, pinfo, tree);\n"; $is_pol = 1; } } if (!$is_pol) { if ($arg->{POINTERS}) { - $res .= "\tptr_$arg->{NAME} = dissect_dcerpc_ptr(tvb, offset, pinfo, tree, drep, \"$arg->{NAME}\");\n"; - $res .= "\tif (ptr_$arg->{NAME})\ -\t\toffset = dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, drep, \"$arg->{NAME}\");\n\n"; + $res .= "\tptr_$arg->{NAME} = dissect_dcerpc_ptr(tvb, offset, pinfo, tree, \"$arg->{NAME}\");\n"; + $res .= "\tif (ptr_$arg->{NAME})\n\t\toffset = "; + + if (is_simple_type($arg->{TYPE})) { + $res .= "dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, \"$arg->{NAME}}\");\n\n"; + } else { + $res .= "dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, PARSE_SCALARS|PARSE_BUFFERS, \"$arg->{NAME}\");\n\n"; + } } else { - $res .= "\toffset = dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, drep, \"$arg->{NAME}\");\n"; + $res .= "\toffset = dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, \"$arg->{NAME}\");\n"; } } } @@ -194,7 +212,7 @@ sub ParseFunction($) ParseFunctionArg($arg, "out"); } - $res .= "\n\toffset = dissect_ntstatus(tvb, offset, pinfo, tree, drep);\n"; + $res .= "\n\toffset = dissect_ntstatus(tvb, offset, pinfo, tree);\n"; $res .= "\n\treturn 0;\n}\n\n"; -- cgit