From 5eb907f1d4d093f79998688a00c15b907e5d249a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 9 Nov 2003 08:28:47 +0000 Subject: 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 566476b3ff91eaa02c4f3c494afbf9ac7c200461) --- source4/build/pidl/client.pm | 76 ++++++++++++++++++++++++++++++++++++++++++++ source4/build/pidl/parser.pm | 4 +-- source4/build/pidl/pidl.pl | 13 +++++++- 3 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 source4/build/pidl/client.pm (limited to 'source4') diff --git a/source4/build/pidl/client.pm b/source4/build/pidl/client.pm new file mode 100644 index 0000000000..b3afb2573a --- /dev/null +++ b/source4/build/pidl/client.pm @@ -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; diff --git a/source4/build/pidl/parser.pm b/source4/build/pidl/parser.pm index d768eaa6c8..7c691c61bc 100644 --- a/source4/build/pidl/parser.pm +++ b/source4/build/pidl/parser.pm @@ -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; diff --git a/source4/build/pidl/pidl.pl b/source4/build/pidl/pidl.pl index a3333da70a..8d15d86347 100755 --- a/source4/build/pidl/pidl.pl +++ b/source4/build/pidl/pidl.pl @@ -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] @@ -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"); -- cgit