added a module for auto-generating the client calls. We can now go
authorAndrew Tridgell <tridge@samba.org>
Sun, 9 Nov 2003 08:28:47 +0000 (08:28 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 9 Nov 2003 08:28:47 +0000 (08:28 +0000)
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 [new file with mode: 0644]
source4/build/pidl/parser.pm
source4/build/pidl/pidl.pl

diff --git a/source4/build/pidl/client.pm b/source4/build/pidl/client.pm
new file mode 100644 (file)
index 0000000..b3afb25
--- /dev/null
@@ -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;
index d768eaa6c8871c7c1a2b31344eba8fa2608b828a..7c691c61bc2141424e4d48f73b139e94a2905dcd 100644 (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;
index a3333da70abce14b53bf02ab5065ff92d5ecf046..8d15d86347d7320d9c4387118a31d48b32e5408c 100755 (executable)
@@ -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");