From fa3db33a5441ed31f9d8c19dc6984d160b86e4da Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Nov 2003 12:29:23 +0000 Subject: updated pidl to auto-generate the ndr_push_*() functions for the Samba4 rpc framework not complete, but sufficient for a number of lsa functions (This used to be commit 42cd6904f51bac1ff92f0aea0deffb11864dfac2) --- source4/build/pidl/header.pm | 116 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 99 insertions(+), 17 deletions(-) (limited to 'source4/build/pidl/header.pm') diff --git a/source4/build/pidl/header.pm b/source4/build/pidl/header.pm index 34707f8672..783fff2204 100644 --- a/source4/build/pidl/header.pm +++ b/source4/build/pidl/header.pm @@ -7,12 +7,23 @@ package IdlHeader; use Data::Dumper; my($res); +my($tab_depth); + +sub tabs() +{ + for (my($i)=0; $i < $tab_depth; $i++) { + $res .= "\t"; + } +} ##################################################################### # dump a properties list sub DumpProperties($) { my($props) = shift; + + return; + foreach my $d (@{$props}) { if (ref($d) ne "HASH") { $res .= "/* [$d] */ "; @@ -29,30 +40,48 @@ sub DumpProperties($) sub DumpElement($) { my($element) = shift; + + if (util::has_property($element->{PROPERTIES}, "struct_len")) { + # a struct_len is an internal artifact - it is put on the + # wire but not exposed via the api, which means it does + # not appear in the header file + return; + } + + (defined $element->{PROPERTIES}) && DumpProperties($element->{PROPERTIES}); - DumpType($element->{TYPE}); + $res .= tabs(); + DumpType($element->{TYPE}, ""); $res .= " "; if ($element->{POINTERS}) { - for (my($i)=0; $i < $element->{POINTERS}; $i++) { - $res .= "*"; - } + my($n) = $element->{POINTERS}; + if (util::is_scalar_type($element->{TYPE}) && + util::has_property($element->{PROPERTIES}, "ref")) { + $n--; + } + for (my($i)=$n; $i > 0; $i--) { + $res .= "*"; + } } $res .= "$element->{NAME}"; (defined $element->{ARRAY_LEN}) && ($res .= "[$element->{ARRAY_LEN}]"); + $res .= ";\n"; } ##################################################################### # dump a struct -sub DumpStruct($) +sub DumpStruct($$) { my($struct) = shift; - $res .= "struct {\n"; + my($name) = shift; + $res .= "struct $name {\n"; + $tab_depth++; if (defined $struct->{ELEMENTS}) { foreach my $e (@{$struct->{ELEMENTS}}) { DumpElement($e); - $res .= ";\n"; } } + $tab_depth--; $res .= "}"; } @@ -64,16 +93,16 @@ sub DumpUnionElement($) my($element) = shift; $res .= "/* [case($element->{CASE})] */ "; DumpElement($element->{DATA}); - $res .= ";\n"; } ##################################################################### # dump a union -sub DumpUnion($) +sub DumpUnion($$) { my($union) = shift; + my($name) = shift; (defined $union->{PROPERTIES}) && DumpProperties($union->{PROPERTIES}); - $res .= "union {\n"; + $res .= "union $name {\n"; foreach my $e (@{$union->{DATA}}) { DumpUnionElement($e); } @@ -82,16 +111,23 @@ sub DumpUnion($) ##################################################################### # dump a type -sub DumpType($) +sub DumpType($$) { my($data) = shift; + my($name) = shift; if (ref($data) eq "HASH") { ($data->{TYPE} eq "STRUCT") && - DumpStruct($data); + DumpStruct($data, $name); ($data->{TYPE} eq "UNION") && - DumpUnion($data); + DumpUnion($data, $name); + return; + } + if ($data =~ "unistr") { + $res .= "const char"; + } elsif (util::is_scalar_type($data)) { + $res .= "$data"; } else { - $res .= "$data"; + $res .= "struct $data"; } } @@ -100,9 +136,51 @@ sub DumpType($) sub DumpTypedef($) { my($typedef) = shift; - $res .= "typedef "; - DumpType($typedef->{DATA}); - $res .= " $typedef->{NAME};\n\n"; + DumpType($typedef->{DATA}, $typedef->{NAME}); + $res .= ";\n\n"; +} + +##################################################################### +# dump a function +sub DumpFunctionInOut($$) +{ + my($fn) = shift; + my($prop) = shift; + foreach my $e (@{$fn->{DATA}}) { + if (util::has_property($e->{PROPERTIES}, $prop)) { + DumpElement($e); + } + } +} + + +##################################################################### +# dump a function +sub DumpFunction($) +{ + my($fn) = shift; + $res .= "struct $fn->{NAME} {\n"; + $tab_depth++; + tabs(); + $res .= "struct {\n"; + $tab_depth++; + DumpFunctionInOut($fn, "in"); + $tab_depth--; + tabs(); + $res .= "} in;\n\n"; + tabs(); + $res .= "struct {\n"; + $tab_depth++; + DumpFunctionInOut($fn, "out"); + if ($fn->{RETURN_TYPE}) { + tabs(); + $res .= "$fn->{RETURN_TYPE} result;\n"; + } + $tab_depth--; + tabs(); + $res .= "} out;\n\n"; + $tab_depth--; + $res .= "};\n\n"; } ##################################################################### @@ -114,6 +192,8 @@ sub DumpInterface($) foreach my $d (@{$data}) { ($d->{TYPE} eq "TYPEDEF") && DumpTypedef($d); + ($d->{TYPE} eq "FUNCTION") && + DumpFunction($d); } } @@ -123,6 +203,8 @@ sub DumpInterface($) sub Dump($) { my($idl) = shift; + $tab_depth = 0; + $res = "/* header auto-generated by pidl */\n\n"; foreach my $x (@{$idl}) { ($x->{TYPE} eq "INTERFACE") && -- cgit