summaryrefslogtreecommitdiff
path: root/source4/build/pidl
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-12-14 13:22:12 +0000
committerAndrew Tridgell <tridge@samba.org>2003-12-14 13:22:12 +0000
commitf6eb8342cba87c7c8f17471ed9783b567d36b0ed (patch)
tree40484486513e10f1fb4764ce62f7fdc3f8df17ff /source4/build/pidl
parent4cd6b8a64b5d995190a28b2a8308e688847df49c (diff)
downloadsamba-f6eb8342cba87c7c8f17471ed9783b567d36b0ed.tar.gz
samba-f6eb8342cba87c7c8f17471ed9783b567d36b0ed.tar.bz2
samba-f6eb8342cba87c7c8f17471ed9783b567d36b0ed.zip
added auto-generation of the server side boilerplate code for each
pipe. The server side code gets generated as librpc/gen_ndr/ndr_NAME_s.c and gets included in the pipe module (This used to be commit bd3dcfe5820489a838e19b244266bd9126af5eb4)
Diffstat (limited to 'source4/build/pidl')
-rw-r--r--source4/build/pidl/header.pm3
-rwxr-xr-xsource4/build/pidl/pidl.pl19
-rw-r--r--source4/build/pidl/server.pm108
-rw-r--r--source4/build/pidl/util.pm4
4 files changed, 126 insertions, 8 deletions
diff --git a/source4/build/pidl/header.pm b/source4/build/pidl/header.pm
index 3277525487..4fa5969d3f 100644
--- a/source4/build/pidl/header.pm
+++ b/source4/build/pidl/header.pm
@@ -239,7 +239,8 @@ sub HeaderInterface($)
$res .= "#define DCERPC_$name\_UUID \"$if_uuid\"\n";
$res .= "#define DCERPC_$name\_VERSION $if_version\n";
$res .= "#define DCERPC_$name\_NAME \"$interface->{NAME}\"\n\n";
- $res .= "extern const struct dcerpc_interface_table dcerpc_table_$interface->{NAME};\n\n";
+ $res .= "extern const struct dcerpc_interface_table dcerpc_table_$interface->{NAME};\n";
+ $res .= "void rpc_$interface->{NAME}_init(void *);\n\n";
}
foreach my $d (@{$data}) {
diff --git a/source4/build/pidl/pidl.pl b/source4/build/pidl/pidl.pl
index 30dcde929a..ce8250826a 100755
--- a/source4/build/pidl/pidl.pl
+++ b/source4/build/pidl/pidl.pl
@@ -16,6 +16,7 @@ use File::Basename;
use idl;
use dump;
use header;
+use server;
use parser;
use eparser;
use validator;
@@ -26,6 +27,7 @@ my($opt_parse) = 0;
my($opt_dump) = 0;
my($opt_diff) = 0;
my($opt_header) = 0;
+my($opt_server) = 0;
my($opt_parser) = 0;
my($opt_eparser) = 0;
my($opt_keep) = 0;
@@ -61,6 +63,7 @@ sub ShowHelp()
--dump dump a pidl file back to idl
--header create a C header file
--parser create a C parser
+ --server create server boilterplate
--eparser create an ethereal parser
--diff run diff on the idl and dumped output
--keep keep the .pidl file
@@ -75,6 +78,7 @@ GetOptions (
'parse' => \$opt_parse,
'dump' => \$opt_dump,
'header' => \$opt_header,
+ 'server' => \$opt_server,
'parser' => \$opt_parser,
'eparser' => \$opt_eparser,
'diff' => \$opt_diff,
@@ -100,7 +104,7 @@ sub process_file($)
$output = $opt_output . $basename;
}
- my($pidl_file) = util::ChangeExtension($output, "pidl");
+ my($pidl_file) = util::ChangeExtension($output, ".pidl");
print "Compiling $idl_file\n";
@@ -120,22 +124,27 @@ sub process_file($)
}
if ($opt_header) {
- my($header) = util::ChangeExtension($output, "h");
+ my($header) = util::ChangeExtension($output, ".h");
util::FileSave($header, IdlHeader::Parse($pidl));
}
+
+ if ($opt_server) {
+ my($server) = util::ChangeExtension($output, "_s.c");
+ util::FileSave($server, IdlServer::Parse($pidl));
+ }
if ($opt_parser) {
- my($parser) = util::ChangeExtension($output, "c");
+ my($parser) = util::ChangeExtension($output, ".c");
IdlParser::Parse($pidl, $parser);
}
if ($opt_eparser) {
- my($parser) = util::ChangeExtension($output, "c");
+ my($parser) = util::ChangeExtension($output, ".c");
util::FileSave($parser, IdlEParser::Parse($pidl));
}
if ($opt_diff) {
- my($tempfile) = util::ChangeExtension($output, "tmp");
+ my($tempfile) = util::ChangeExtension($output, ".tmp");
util::FileSave($tempfile, IdlDump::Dump($pidl));
system("diff -wu $idl_file $tempfile");
unlink($tempfile);
diff --git a/source4/build/pidl/server.pm b/source4/build/pidl/server.pm
new file mode 100644
index 0000000000..e6d996b95d
--- /dev/null
+++ b/source4/build/pidl/server.pm
@@ -0,0 +1,108 @@
+
+
+###################################################
+# server boilerplate generator
+# Copyright tridge@samba.org 2003
+# released under the GNU GPL
+
+package IdlServer;
+
+use strict;
+use Data::Dumper;
+
+my($res);
+
+sub pidl($)
+{
+ $res .= shift;
+}
+
+#####################################################################
+# produce boilerplate code for a interface
+sub Boilerplate($)
+{
+ my($interface) = shift;
+ my($data) = $interface->{DATA};
+ my $count = 0;
+ my $name = $interface->{NAME};
+ my $uname = uc $name;
+
+ foreach my $d (@{$data}) {
+ if ($d->{TYPE} eq "FUNCTION") { $count++; }
+ }
+
+ if ($count == 0) {
+ return;
+ }
+
+ pidl "static const dcesrv_dispatch_fn_t dispatch_table[] = {\n";
+ foreach my $d (@{$data}) {
+ if ($d->{TYPE} eq "FUNCTION") {
+ pidl "\t(dcesrv_dispatch_fn_t)$d->{NAME},\n";
+ }
+ }
+ pidl "\tNULL};\n\n";
+
+ pidl "
+static BOOL op_query_endpoint(const struct dcesrv_endpoint *ep)
+{
+ return dcesrv_table_query(&dcerpc_table_$name, ep);
+}
+
+static BOOL op_set_interface(struct dcesrv_state *dce,
+ const char *uuid, uint32 if_version)
+{
+ return dcesrv_set_interface(dce, uuid, if_version,
+ &dcerpc_table_$name, dispatch_table);
+}
+
+static NTSTATUS op_connect(struct dcesrv_state *dce)
+{
+ return NT_STATUS_OK;
+}
+
+static void op_disconnect(struct dcesrv_state *dce)
+{
+ /* nothing to do */
+}
+
+static int op_lookup_endpoints(TALLOC_CTX *mem_ctx, struct dcesrv_ep_iface **e)
+{
+ return dcesrv_lookup_endpoints(&dcerpc_table_$name, mem_ctx, e);
+}
+
+static const struct dcesrv_endpoint_ops $name\_ops = {
+ op_query_endpoint,
+ op_set_interface,
+ op_connect,
+ op_disconnect,
+ op_lookup_endpoints
+};
+
+void rpc_$name\_init(void *v)
+{
+ struct dcesrv_context *dce = v;
+ if (!dcesrv_endpoint_register(dce, &$name\_ops,
+ &dcerpc_table_$name)) {
+ DEBUG(1,(\"Failed to register rpcecho endpoint\\n\"));
+ }
+}
+";
+}
+
+
+#####################################################################
+# parse a parsed IDL structure back into an IDL file
+sub Parse($)
+{
+ my($idl) = shift;
+ $res = "/* dcerpc server boilerplate generated by pidl */\n\n";
+ foreach my $x (@{$idl}) {
+ ($x->{TYPE} eq "INTERFACE") &&
+ Boilerplate($x);
+ }
+ return $res;
+}
+
+1;
+
diff --git a/source4/build/pidl/util.pm b/source4/build/pidl/util.pm
index 57ce80253f..dc6fd35f0c 100644
--- a/source4/build/pidl/util.pm
+++ b/source4/build/pidl/util.pm
@@ -127,9 +127,9 @@ sub ChangeExtension($$)
my($fname) = shift;
my($ext) = shift;
if ($fname =~ /^(.*)\.(.*?)$/) {
- return "$1.$ext";
+ return "$1$ext";
}
- return "$fname.$ext";
+ return "$fname$ext";
}
#####################################################################