1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

- include includes.h

- fix ref ptrs in push

- add NTSTATUS return
This commit is contained in:
Andrew Tridgell 0001-01-01 00:00:00 +00:00
parent 47a17e5a08
commit cba9df9aa4
3 changed files with 73 additions and 19 deletions

View File

@ -55,10 +55,6 @@ sub DumpElement($)
$res .= " ";
if ($element->{POINTERS}) {
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 .= "*";
}

View File

@ -67,7 +67,12 @@ sub ParseElementPushScalar($$$)
!util::has_property($e->{PROPERTIES}, "ref")) {
$res .= "\tNDR_CHECK(ndr_push_ptr(ndr, $var_prefix$e->{NAME}));\n";
} elsif (util::is_builtin_type($e->{TYPE})) {
$res .= "\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $var_prefix$e->{NAME}));\n";
if (util::is_scalar_type($e->{TYPE}) &&
util::has_property($e->{PROPERTIES}, "ref")) {
$res .= "\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, *$var_prefix$e->{NAME}));\n";
} else {
$res .= "\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $var_prefix$e->{NAME}));\n";
}
} else {
$res .= "\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $ndr_flags, $var_prefix$e->{NAME}));\n";
}
@ -75,10 +80,11 @@ sub ParseElementPushScalar($$$)
#####################################################################
# parse scalars in a structure element - pull size
sub ParseElementPullScalar($$)
sub ParseElementPullScalar($$$)
{
my($e) = shift;
my($var_prefix) = shift;
my($ndr_flags) = shift;
if (defined $e->{VALUE}) {
$res .= "\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $e->{VALUE}));\n";
@ -90,8 +96,23 @@ sub ParseElementPullScalar($$)
$res .= "\t} else {\n";
$res .= "\t\t$var_prefix$e->{NAME} = NULL;\n";
$res .= "\t}\n";
} elsif (!util::is_scalar_type($e->{TYPE}) &&
util::has_property($e->{PROPERTIES}, "ref")) {
if (util::is_builtin_type($e->{TYPE})) {
$res .= "\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $var_prefix$e->{NAME}));\n";
} else {
$res .= "\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $ndr_flags, $var_prefix$e->{NAME}));\n";
}
} else {
$res .= "\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, &$var_prefix$e->{NAME}));\n";
if (util::is_builtin_type($e->{TYPE})) {
if (!util::has_property($e->{PROPERTIES}, "ref")) {
$res .= "\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, &$var_prefix$e->{NAME}));\n";
} else {
$res .= "\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $var_prefix$e->{NAME}));\n";
}
} else {
$res .= "\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $ndr_flags, &$var_prefix$e->{NAME}));\n";
}
}
}
@ -119,7 +140,7 @@ sub ParseElementPushBuffer($$)
} else {
if (util::is_scalar_type($e->{TYPE})) {
$res .= "\t\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, *$var_prefix$e->{NAME}));\n";
} elsif (util::has_property($e->{PROPERTIES}, "ref") || !$e->{POINTERS}) {
} elsif (!$e->{POINTERS}) {
$res .= "\t\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, ndr_flags, *$var_prefix$e->{NAME}));\n";
} elsif (util::is_builtin_type($e->{TYPE})) {
$res .= "\t\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $var_prefix$e->{NAME}));\n";
@ -156,10 +177,9 @@ sub ParseElementPullBuffer($$)
if (util::has_property($e->{PROPERTIES}, "size_is")) {
ParseArrayPull($e);
} else {
if (util::has_property($e->{PROPERTIES}, "ref") ||
!$e->{POINTERS} ||
if (!$e->{POINTERS} ||
$e->{TYPE} =~ "unistr") {
$res .= "\t\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, \&$var_prefix$e->{NAME}));\n";
$res .= "\t\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, &$var_prefix$e->{NAME}));\n";
} elsif (util::is_builtin_type($e->{TYPE})) {
$res .= "\t\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $var_prefix$e->{NAME}));\n";
} else {
@ -263,7 +283,7 @@ sub ParseStructPull($)
$res .= "\tif (!(ndr_flags & NDR_SCALARS)) goto buffers;\n";
foreach my $e (@{$struct->{ELEMENTS}}) {
ParseElementPullScalar($e, "r->");
ParseElementPullScalar($e, "r->", "NDR_SCALARS");
if (defined($struct_len) && $e == $struct_len) {
$res .= "\tNDR_CHECK(ndr_pull_limit_size(ndr, _size, 4));\n";
}
@ -386,6 +406,29 @@ sub ParseFunctionPush($)
# parse a function
sub ParseFunctionPull($)
{
my($fn) = shift;
# pull function args
$res .= "NTSTATUS ndr_pull_$fn->{NAME}(struct ndr_pull *ndr, struct $fn->{NAME} *r)\n{\n";
foreach my $arg (@{$fn->{DATA}}) {
if (util::has_property($arg->{PROPERTIES}, "out")) {
if ($arg->{POINTERS} &&
!util::has_property($arg->{PROPERTIES}, "ref")) {
$res .= "\tNDR_ALLOC(ndr, r->out.$arg->{NAME});\n";
}
ParseElementPullScalar($arg, "r->out.", "NDR_SCALARS|NDR_BUFFERS");
ParseElementPullBuffer($arg, "r->out.");
}
}
if ($fn->{RETURN_TYPE}) {
$res .= "\tNDR_CHECK(ndr_pull_$fn->{RETURN_TYPE}(ndr, &r->out.result));\n";
}
$res .= "\n\treturn NT_STATUS_OK;\n}\n\n";
}
#####################################################################
@ -427,6 +470,7 @@ sub Parse($)
{
my($idl) = shift;
$res = "/* parser auto-generated by pidl */\n\n";
$res .= "#include \"includes.h\"\n\n";
foreach my $x (@{$idl}) {
($x->{TYPE} eq "INTERFACE") &&
ParseInterface($x);

View File

@ -27,6 +27,8 @@ my($opt_diff) = 0;
my($opt_header) = 0;
my($opt_parser) = 0;
my($opt_eparser) = 0;
my($opt_keep) = 0;
my($opt_output);
#####################################################################
# parse an IDL file returning a structure containing all the data
@ -63,12 +65,14 @@ sub ShowHelp()
Options:
--help this help page
--output OUTNAME put output in OUTNAME.*
--parse parse a idl file to a .pidl file
--dump dump a pidl file back to idl
--header create a C header file
--parser create a C parser
--eparser create an ethereal parser
--diff run diff on the idl and dumped output
--keep keep the .pidl file
\n";
exit(0);
}
@ -76,12 +80,14 @@ sub ShowHelp()
# main program
GetOptions (
'help|h|?' => \$opt_help,
'output=s' => \$opt_output,
'parse' => \$opt_parse,
'dump' => \$opt_dump,
'header' => \$opt_header,
'parser' => \$opt_parser,
'eparser' => \$opt_eparser,
'diff' => \$opt_diff
'diff' => \$opt_diff,
'keep' => \$opt_keep
);
if ($opt_help) {
@ -92,10 +98,14 @@ if ($opt_help) {
my($idl_file) = shift;
die "ERROR: You must specify an idl file to process" unless ($idl_file);
my($pidl_file) = util::ChangeExtension($idl_file, "pidl");
if (!defined($opt_output)) {
$opt_output = $idl_file;
}
my($pidl_file) = util::ChangeExtension($opt_output, "pidl");
if ($opt_parse) {
print "Generating $pidl_file\n";
print "Generating $pidl_file from $idl_file\n";
my($idl) = IdlParse($idl_file);
util::SaveStructure($pidl_file, $idl) || die "Failed to save $pidl_file";
}
@ -107,29 +117,33 @@ if ($opt_dump) {
if ($opt_header) {
my($idl) = util::LoadStructure($pidl_file);
my($header) = util::ChangeExtension($idl_file, "h");
my($header) = util::ChangeExtension($opt_output, "h");
print "Generating $header\n";
util::FileSave($header, IdlHeader::Dump($idl));
}
if ($opt_parser) {
my($idl) = util::LoadStructure($pidl_file);
my($parser) = util::ChangeExtension($idl_file, "c");
my($parser) = util::ChangeExtension($opt_output, "c");
print "Generating $parser\n";
util::FileSave($parser, IdlParser::Parse($idl));
}
if ($opt_eparser) {
my($idl) = util::LoadStructure($pidl_file);
my($parser) = util::ChangeExtension($idl_file, "c");
my($parser) = util::ChangeExtension($opt_output, "c");
print "Generating $parser for ethereal\n";
util::FileSave($parser, IdlEParser::Parse($idl));
}
if ($opt_diff) {
my($idl) = util::LoadStructure($pidl_file);
my($tempfile) = util::ChangeExtension($idl_file, "tmp");
my($tempfile) = util::ChangeExtension($opt_output, "tmp");
util::FileSave($tempfile, IdlDump::Dump($idl));
system("diff -wu $idl_file $tempfile");
unlink($tempfile);
}
if (!$opt_keep) {
system("rm -f $pidl_file");
}