summaryrefslogtreecommitdiff
path: root/source4/build
diff options
context:
space:
mode:
Diffstat (limited to 'source4/build')
-rw-r--r--source4/build/pidl/eparser.pm290
1 files changed, 61 insertions, 229 deletions
diff --git a/source4/build/pidl/eparser.pm b/source4/build/pidl/eparser.pm
index 90af3c8665..f32e1b9842 100644
--- a/source4/build/pidl/eparser.pm
+++ b/source4/build/pidl/eparser.pm
@@ -7,264 +7,93 @@
package IdlEParser;
use strict;
+use dump;
+use Data::Dumper;
-my($res);
-
-sub has_property($$)
+sub ParamSimpleNdrType($)
{
- my($props) = shift;
my($p) = shift;
+ my($res);
- foreach my $d (@{$props}) {
- if (ref($d) ne "HASH") {
- return 1, if ($d eq $p);
- return 1, if ($d eq "in,out" && ($p eq "in" || $p eq "out"));
- } else {
- foreach my $k (keys %{$d}) {
- return $d->{$k}, if ($k eq $p);
- }
- }
- }
-
- return 0;
-}
-
-#####################################################################
-# parse a properties list
-sub ParseProperties($)
-{
- my($props) = shift;
- foreach my $d (@{$props}) {
- if (ref($d) ne "HASH") {
- $res .= "[$d] ";
- } else {
- foreach my $k (keys %{$d}) {
- $res .= "[$k($d->{$k})] ";
- }
- }
- }
-}
-
-#####################################################################
-# parse an array - called in buffers context
-sub ParseArray($)
-{
- my($elt) = shift;
-
- $res .= "\tfor (i = 0; i < count; i++) {\n";
- if (util::is_scalar_type($elt)) {
- $res .= "\t\toffset = prs_$elt->{TYPE}(tvb, offset, pinfo, tree, NULL, \"$elt->{NAME});\n";
- $res .= "\t}\n\n";
- } else {
- $res .= "\t\toffset = prs_$elt->{TYPE}(tvb, offset, pinfo, tree, \"PARSE_SCALARS\", \"$elt->{NAME}\");\n";
- $res .= "\t}\n\n";
-
- $res .= "\tfor (i = 0; i < count; i++) {\n";
- $res .= "\t\toffset = prs_$elt->{TYPE}(tvb, offset, pinfo, tree, \"PARSE_BUFFERS\", \"$elt->{NAME}\");\n";
- $res .= "\t}\n\n";
- }
-}
-
-#####################################################################
-# parse a structure element
-sub ParseElement($$)
-{
- my($elt) = shift;
- my($flags) = shift;
-
- # Arg is a policy handle
-
- if (util::has_property($elt, "context_handle")) {
- $res .= "\toffset = prs_policy_hnd(tvb, offset, pinfo, tree);\n";
- return;
- }
-
- # Parse type
-
- if ($flags =~ /scalars/) {
+ $res .= "\toffset = dissect_ndr_$p->{TYPE}(tvb, offset, pinfo, tree, drep, hf_$p->{NAME}, NULL);\n";
- # Pointers are scalars
-
- if ($elt->{POINTERS}) {
- $res .= "\t\toffset = prs_ptr(tvb, offset, pinfo, tree, &ptr_$elt->{NAME}, \"$elt->{NAME}\");\n";
- } else {
-
- # Simple type are scalars too
-
- if (util::is_scalar_type($elt->{TYPE})) {
- $res .= "\t\toffset = prs_$elt->{TYPE}(tvb, offset, pinfo, tree, NULL, \"$elt->{NAME}\");\n\n";
- }
- }
-
- }
-
- if ($flags =~ /buffers/) {
-
- # Scalars are not buffers, except if they are pointed to
-
- if (!util::is_scalar_type($elt->{TYPE}) || $elt->{POINTERS}) {
-
- # If we have a pointer, check it
-
- if ($elt->{POINTERS}) {
- $res .= "\t\tif (ptr_$elt->{NAME})\n\t";
- }
-
- if (util::has_property($elt, "size_is")) {
- ParseArray($elt);
- } else {
- $res .= "\t\toffset = prs_$elt->{TYPE}(tvb, offset, pinfo, tree, ";
- if (util::is_scalar_type($elt->{TYPE})) {
- $res .= "NULL, ";
- } else {
- $res .= "flags, ";
- }
- $res .= "\"$elt->{NAME}\");\n\n";
- }
- }
- }
-
- return;
+ return $res;
}
-#####################################################################
-# parse a struct
-sub ParseStruct($)
+sub ParamPolicyHandle($)
{
- my($struct) = shift;
-
- if (defined $struct->{ELEMENTS}) {
-
- # Parse scalars
-
- $res .= "\tif (flags & PARSE_SCALARS) {\n";
-
- foreach my $e (@{$struct->{ELEMENTS}}) {
- ParseElement($e, "scalars");
- }
-
- $res .= "\t}\n\n";
-
- # Parse buffers
-
- $res .= "\tif (flags & PARSE_BUFFERS) {\n";
+ my($p) = shift;
+ my($res);
- foreach my $e (@{$struct->{ELEMENTS}}) {
- ParseElement($e, "buffers");
- }
+ $res .= "\toffset = dissect_nt_policy_handle(tvb, offset, pinfo, tree, drep, hf_policy_hnd, NULL, NULL, FALSE, FALSE);\n";
- $res .= "\t}\n\n";
- }
+ return $res;
}
+my %param_handlers = (
+ 'uint16' => \&ParamSimpleNdrType,
+ 'uint32' => \&ParamSimpleNdrType,
+ 'policy_handle' => \&ParamPolicyHandle,
+ );
#####################################################################
-# parse a union element
-sub ParseUnionElement($)
-{
- my($element) = shift;
-
- $res .= "\tcase $element->{DATA}->{NAME}: \n";
- $res .= "\t\toffset = prs_$element->{DATA}->{TYPE}(tvb, offset, pinfo, tree, \"$element->{DATA}->{NAME}\");\n\t\tbreak;\n";
-
-}
-
-#####################################################################
-# parse a union
-sub ParseUnion($)
-{
- my($union) = shift;
-
- $res .= "\tswitch (level) {\n";
-
- (defined $union->{PROPERTIES}) && ParseProperties($union->{PROPERTIES});
- foreach my $e (@{$union->{DATA}}) {
- ParseUnionElement($e);
- }
-
- $res .= "\t}\n";
-}
+# parse a function
+sub ParseParameter($)
+{
+ my($p) = shift;
+ my($res);
-#####################################################################
-# parse a type
-sub ParseType($)
-{
- my($data) = shift;
-
- if (ref($data) eq "HASH") {
- ($data->{TYPE} eq "STRUCT") &&
- ParseStruct($data);
- ($data->{TYPE} eq "UNION") &&
- ParseUnion($data);
- } else {
- $res .= "$data";
+ if (defined($param_handlers{$p->{TYPE}})) {
+ $res .= &{$param_handlers{$p->{TYPE}}}($p);
+ return $res;
}
-}
-#####################################################################
-# parse a typedef
-sub ParseTypedef($)
-{
- my($typedef) = shift;
+ $res .= "\t/* Unhandled IDL type '$p->{TYPE}' in $p->{PARENT}->{NAME} */\n";
- $res .= "static int prs_$typedef->{NAME}(tvbuff_t *tvb, int offset,\
-\tpacket_info *pinfo, proto_tree *tree, int flags, char *name)\n{\n";
- ParseType($typedef->{DATA});
- $res .= "\treturn offset;\n";
- $res .= "}\n\n";
+ return $res;
+ # exit(1);
}
#####################################################################
# parse a function
-sub ParseFunctionArg($$)
+sub ParseFunction($)
{
- my($arg) = shift;
- my($io) = shift; # "in" or "out"
+ my($f) = shift;
+ my($res);
- if (util::has_property($arg, $io)) {
+ $res .= "/*\n\n";
+ $res .= IdlDump::DumpFunction($f);
+ $res .= "*/\n\n";
- # For some reason, pointers to elements in function definitions
- # aren't parsed.
+ # Request function
- if (defined($arg->{POINTERS}) && !util::is_scalar_type($arg->{TYPE})) {
- $arg->{POINTERS} -= 1, if ($arg->{POINTERS} > 0);
- delete($arg->{POINTERS}), if ($arg->{POINTERS} == 0);
- }
+ $res .= "static int\n";
+ $res .= "$f->{NAME}_rqst(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n";
+ $res .= "{\n";
- ParseElement($arg, "scalars|buffers");
+ my($d);
+ foreach $d (@{$f->{DATA}}) {
+ $res .= ParseParameter($d), if defined($d->{PROPERTIES}{in});
}
-}
-
-#####################################################################
-# parse a function
-sub ParseFunction($)
-{
- my($function) = shift;
- # Input function
+ $res .= "\treturn offset;\n";
+ $res .= "}\n\n";
- $res .= "static int $function->{NAME}_q(tvbuff_t *tvb, int offset,\
-\tpacket_info *pinfo, proto_tree *tree, char *drep)\n{\n";
+ # Response function
- foreach my $arg (@{$function->{DATA}}) {
- ParseFunctionArg($arg, "in");
- }
-
- $res .= "\n\treturn offset;\n}\n\n";
-
- # Output function
+ $res .= "static int\n";
+ $res .= "$f->{NAME}_resp(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n";
+ $res .= "{\n";
- $res .= "static int $function->{NAME}_r(tvbuff_t *tvb, int offset,\
-\tpacket_info *pinfo, proto_tree *tree, char *drep)\n{\n";
-
- foreach my $arg (@{$function->{DATA}}) {
- ParseFunctionArg($arg, "out");
+ foreach $d (@{$f->{DATA}}) {
+ $res .= ParseParameter($d), if defined($d->{PROPERTIES}{out});
}
- $res .= "\n\toffset = prs_ntstatus(tvb, offset, pinfo, tree);\n";
- $res .= "\n\treturn offset;\n}\n\n";
+ $res .= "\treturn offset;\n";
+ $res .= "}\n\n";
+ return $res;
}
#####################################################################
@@ -273,12 +102,13 @@ sub ParseInterface($)
{
my($interface) = shift;
my($data) = $interface->{DATA};
+ my($res) = "";
+
foreach my $d (@{$data}) {
- ($d->{TYPE} eq "TYPEDEF") &&
- ParseTypedef($d);
- ($d->{TYPE} eq "FUNCTION") &&
- ParseFunction($d);
+ $res .= ParseFunction($d), if $d->{TYPE} eq "FUNCTION";
}
+
+ return $res;
}
@@ -287,11 +117,13 @@ sub ParseInterface($)
sub Parse($)
{
my($idl) = shift;
+ my($res);
+
$res = "/* parser auto-generated by pidl */\n\n";
- foreach my $x (@{$idl}) {
- ($x->{TYPE} eq "INTERFACE") &&
- ParseInterface($x);
+ foreach my $d (@{$idl}) {
+ $res .= ParseInterface($d), if $d->{TYPE} eq "INTERFACE";
}
+
return $res;
}