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

added a module for auto-generating the client calls. We can now go

from IDL file to working Samba4 RPC client library in a completely
automated fashion.
(This used to be commit 566476b3ff)
This commit is contained in:
Andrew Tridgell 2003-11-09 08:28:47 +00:00
parent adf6142953
commit 5eb907f1d4
3 changed files with 90 additions and 3 deletions

View File

@ -0,0 +1,76 @@
###################################################
# client calls generator
# Copyright tridge@samba.org 2003
# released under the GNU GPL
package IdlClient;
use Data::Dumper;
my($res);
#####################################################################
# parse a function
sub ParseFunction($)
{
my $fn = shift;
my $name = $fn->{NAME};
my $uname = uc $name;
if ($fn->{RETURN_TYPE} eq "void") {
$res .= "
NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
{
return dcerpc_ndr_request(p, DCERPC_$uname, mem_ctx,
(ndr_push_fn_t) ndr_push_$name,
(ndr_pull_fn_t) ndr_pull_$name,
r);
}
";
} else {
$res .= "
NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
{
NTSTATUS status;
status = dcerpc_ndr_request(p, DCERPC_$uname, mem_ctx,
(ndr_push_fn_t) ndr_push_$name,
(ndr_pull_fn_t) ndr_pull_$name,
r);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
return r->out.result;
}
";
}
}
#####################################################################
# parse the interface definitions
sub ParseInterface($)
{
my($interface) = shift;
my($data) = $interface->{DATA};
foreach my $d (@{$data}) {
($d->{TYPE} eq "FUNCTION") &&
ParseFunction($d);
}
}
#####################################################################
# parse a parsed IDL structure back into an IDL file
sub Parse($)
{
my($idl) = shift;
$res = "/* dcerpc client calls auto-generated by pidl */\n\n";
$res .= "#include \"includes.h\"\n\n";
foreach my $x (@{$idl}) {
($x->{TYPE} eq "INTERFACE") &&
ParseInterface($x);
}
return $res;
}
1;

View File

@ -1,7 +1,7 @@
###################################################
# Ethereal parser generator for IDL structures
# Samba4 parser generator for IDL structures
# Copyright tridge@samba.org 2000-2003
# Copyright tpot@samba.org 2001
# Copyright tridge@samba.org 2000
# released under the GNU GPL
package IdlParser;

View File

@ -18,6 +18,7 @@ use dump;
use header;
use parser;
use eparser;
use client;
use util;
my($opt_help) = 0;
@ -27,6 +28,7 @@ my($opt_diff) = 0;
my($opt_header) = 0;
my($opt_parser) = 0;
my($opt_eparser) = 0;
my($opt_client);
my($opt_keep) = 0;
my($opt_output);
@ -59,7 +61,7 @@ sub ShowHelp()
{
print "
perl IDL parser and code generator
Copyright tridge\@samba.org
Copyright (C) tridge\@samba.org
Usage: pidl.pl [options] <idlfile>
@ -71,6 +73,7 @@ sub ShowHelp()
--header create a C header file
--parser create a C parser
--eparser create an ethereal parser
--client FILENAME create client calls in FILENAME
--diff run diff on the idl and dumped output
--keep keep the .pidl file
\n";
@ -86,6 +89,7 @@ GetOptions (
'header' => \$opt_header,
'parser' => \$opt_parser,
'eparser' => \$opt_eparser,
'client=s' => \$opt_client,
'diff' => \$opt_diff,
'keep' => \$opt_keep
);
@ -136,6 +140,13 @@ if ($opt_eparser) {
util::FileSave($parser, IdlEParser::Parse($idl));
}
if ($opt_client) {
my($idl) = util::LoadStructure($pidl_file);
my($client) = util::ChangeExtension($opt_client, "c");
print "Generating $client client calls\n";
util::FileSave($client, IdlClient::Parse($idl));
}
if ($opt_diff) {
my($idl) = util::LoadStructure($pidl_file);
my($tempfile) = util::ChangeExtension($opt_output, "tmp");