summaryrefslogtreecommitdiff
path: root/source4/build/pidl/dcom_proxy.pm
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-02-21 14:30:49 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:10:50 -0500
commit80d3047333fceb3805ccd10a08cdf95021f57ff4 (patch)
tree16ccb10ace9efe6b52d80e8bfd3f0fd483762f23 /source4/build/pidl/dcom_proxy.pm
parent6b4cac2c00bd77c34bfe47f35729a60782b8c9c2 (diff)
downloadsamba-80d3047333fceb3805ccd10a08cdf95021f57ff4.tar.gz
samba-80d3047333fceb3805ccd10a08cdf95021f57ff4.tar.bz2
samba-80d3047333fceb3805ccd10a08cdf95021f57ff4.zip
r5490: The big (D)COM commit! :-) Contains most of the changes described in the
DCOM paper in lorikeet. This is the result of 1.5 months work (mainly figuring out how things *really* work) at the end of 2004. In general: - Clearer distinction between COM and DCOM. DCOM is now merely the glue between DCE/RPC+ORPC and COM. COM can also work without DCOM now. This makes the code a lot clearer. - Clearer distinction between NDR and DCOM. Before, NDR had a couple of "if"s to cope with DCOM, which are now gone. - Use "real" arguments rather then structures for function arguments in COM, mainly because most of these calls are local so packing/unpacking data for every call is too much overhead (both speed- and code-wise) - Support several mechanisms to load class objects: - from memory (e.g. part of the current executable, registered at start-up) - from shared object files - remotely - Most things are now also named COM rather then DCOM because that's what it really is. After an object is created, it no longer matters whether it was created locally or remotely. There is a very simple example class that contains both a class factory and a class that implements the IStream interface. It can be tested (locally only, remotely is broken at the moment) by running the COM-SIMPLE smbtorture test. Still to-do: - Autogenerate parts of the class implementation code (using the coclass definitions in IDL) - Test server-side - Implement some of the common classes, add definitions for common interfaces. (This used to be commit 71fd3e5c3aac5f0002001ab29d2248e6c6842d6f)
Diffstat (limited to 'source4/build/pidl/dcom_proxy.pm')
-rw-r--r--source4/build/pidl/dcom_proxy.pm203
1 files changed, 203 insertions, 0 deletions
diff --git a/source4/build/pidl/dcom_proxy.pm b/source4/build/pidl/dcom_proxy.pm
new file mode 100644
index 0000000000..1a1b8de064
--- /dev/null
+++ b/source4/build/pidl/dcom_proxy.pm
@@ -0,0 +1,203 @@
+###################################################
+# DCOM parser for Samba
+# Basically the glue between COM and DCE/RPC with NDR
+# Copyright jelmer@samba.org 2003-2005
+# released under the GNU GPL
+
+package DCOMProxy;
+
+use com_header;
+
+use strict;
+
+my($res);
+
+sub ParseVTable($$)
+{
+ my $interface = shift;
+ my $name = shift;
+
+ # Generate the vtable
+ $res .="\tstruct $interface->{NAME}_vtable $name = {";
+
+ if (defined($interface->{BASE})) {
+ $res .= "\n\t\t{},";
+ }
+
+ my $data = $interface->{DATA};
+
+ foreach my $d (@{$data}) {
+ if ($d->{TYPE} eq "FUNCTION") {
+ $res .= "\n\t\tdcom_proxy_$interface->{NAME}_$d->{NAME}";
+ $res .= ",";
+ }
+ }
+
+ $res .= "\n\t};\n\n";
+}
+
+sub ParseRegFunc($)
+{
+ my $interface = shift;
+
+ $res .= "static NTSTATUS dcom_proxy_$interface->{NAME}_init(void)
+{
+ struct GUID base_iid;
+ struct GUID iid;
+ struct $interface->{NAME}_vtable proxy_vtable;";
+
+ if (defined($interface->{BASE})) {
+ $res.= "
+ const void *base_vtable;
+
+ GUID_from_string(DCERPC_" . (uc $interface->{BASE}) . "_UUID, &base_iid);
+
+ base_vtable = dcom_proxy_vtable_by_iid(&base_iid);
+ if (base_vtable == NULL) {
+ DEBUG(0, (\"No proxy registered for base interface\n\"));
+ return NT_STATUS_FOOBAR;
+ }
+
+ memcpy(&proxy_vtable, base_vtable, sizeof(struct $interface->{BASE}_vtable));
+
+";
+ }
+ foreach my $x (@{$interface->{DATA}}) {
+ next unless ($x->{TYPE} eq "FUNCTION");
+
+ $res .= "\tproxy_vtable.$x->{NAME} = dcom_proxy_$interface->{NAME}_$x->{NAME};\n";
+ }
+
+ $res.= "
+ GUID_from_string(DCERPC_" . (uc $interface->{NAME}) . "_UUID, &iid);
+
+ return dcom_register_proxy(&iid, &proxy_vtable);
+}\n\n";
+}
+
+#####################################################################
+# parse a function
+sub ParseFunction($$)
+{
+ my $interface = shift;
+ my $fn = shift;
+ my $name = $fn->{NAME};
+ my $uname = uc $name;
+
+ $res.="
+static $fn->{RETURN_TYPE} dcom_proxy_$interface->{NAME}_$name(struct $interface->{NAME} *d, TALLOC_CTX *mem_ctx" . COMHeader::GetArgumentProtoList($fn) . ")
+{
+ struct dcerpc_pipe *p;
+ NTSTATUS status = dcom_get_pipe(d, &p);
+ struct $name r;
+ struct rpc_request *req;
+
+ if (NT_STATUS_IS_ERR(status)) {
+ return status;
+ }
+
+ ZERO_STRUCT(r.in.ORPCthis);
+ r.in.ORPCthis.version.MajorVersion = COM_MAJOR_VERSION;
+ r.in.ORPCthis.version.MinorVersion = COM_MINOR_VERSION;
+";
+
+ # Put arguments into r
+ foreach my $a (@{$fn->{DATA}}) {
+ next if ($a->{NAME} eq "ORPCthis");
+ next unless (util::has_property($a, "in"));
+ $res .= "\tr.in.$a->{NAME} = $a->{NAME};\n";
+ }
+
+ $res .="
+ if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) {
+ NDR_PRINT_IN_DEBUG($name, &r);
+ }
+
+ status = dcerpc_ndr_request(p, &d->ipid, &dcerpc_table_$interface->{NAME}, DCERPC_$uname, mem_ctx, &r);
+
+ if (NT_STATUS_IS_OK(status) && (p->conn->flags & DCERPC_DEBUG_PRINT_OUT)) {
+ NDR_PRINT_OUT_DEBUG($name, r);
+ }
+
+";
+
+ # Put r info back into arguments
+ foreach my $a (@{$fn->{DATA}}) {
+ next if ($a->{NAME} eq "ORPCthat");
+ next unless (util::has_property($a, "out"));
+ $res .= "\t*$a->{NAME} = r.out.$a->{NAME};\n";
+ }
+
+ if ($fn->{RETURN_TYPE} eq "NTSTATUS") {
+ $res .= "\tif (NT_STATUS_IS_OK(status)) status = r.out.result;\n";
+ }
+
+ $res .=
+ "
+ return r.out.result;
+}\n\n";
+}
+
+#####################################################################
+# parse the interface definitions
+sub ParseInterface($)
+{
+ my($interface) = shift;
+ my($data) = $interface->{DATA};
+ $res = "/* DCOM proxy for $interface->{NAME} generated by pidl */\n\n";
+ foreach my $d (@{$data}) {
+ ($d->{TYPE} eq "FUNCTION") &&
+ ParseFunction($interface, $d);
+ }
+
+ ParseRegFunc($interface);
+}
+
+sub RegistrationFunction($$)
+{
+ my $idl = shift;
+ my $basename = shift;
+
+ my $res = "\n\nNTSTATUS dcom_$basename\_init(void)\n";
+ $res .= "{\n";
+ $res .="\tNTSTATUS status = NT_STATUS_OK;\n";
+ foreach my $interface (@{$idl}) {
+ next if $interface->{TYPE} ne "INTERFACE";
+ next if not util::has_property($interface, "object");
+
+ my $data = $interface->{INHERITED_DATA};
+ my $count = 0;
+ foreach my $d (@{$data}) {
+ if ($d->{TYPE} eq "FUNCTION") { $count++; }
+ }
+
+ next if ($count == 0);
+
+ $res .= "\tstatus = dcom_$interface->{NAME}_init();\n";
+ $res .= "\tif (NT_STATUS_IS_ERR(status)) {\n";
+ $res .= "\t\treturn status;\n";
+ $res .= "\t}\n\n";
+ }
+ $res .= "\treturn status;\n";
+ $res .= "}\n\n";
+
+ return $res;
+}
+
+sub Parse($)
+{
+ my $pidl = shift;
+ my $res = "";
+
+ foreach my $x (@{$pidl}) {
+ next if ($x->{TYPE} ne "INTERFACE");
+ next if util::has_property($x, "local");
+ next unless util::has_property($x, "object");
+
+ $res .= ParseInterface($x);
+ }
+
+ return $res;
+}
+
+1;