svn commit: samba r26660 - in branches/SAMBA_4_0: . source/pidl/lib/Parse/Pidl/Samba4

jelmer at samba.org jelmer at samba.org
Thu Jan 3 23:58:39 GMT 2008


Author: jelmer
Date: 2008-01-03 23:58:38 +0000 (Thu, 03 Jan 2008)
New Revision: 26660

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=26660

Log:
pidl/python: Generate stub functions for DCE/RPC client functions, constructor for interface objects.

Modified:
   branches/SAMBA_4_0/
   branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Python.pm


Changeset:

Property changes on: branches/SAMBA_4_0
___________________________________________________________________
Name: bzr:revision-info
...skipped...
Name: bzr:revision-id:v3-trunk0
...skipped...

Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Python.pm
===================================================================
--- branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Python.pm	2008-01-03 21:57:44 UTC (rev 26659)
+++ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Python.pm	2008-01-03 23:58:38 UTC (rev 26660)
@@ -66,6 +66,41 @@
     $self->{constants}->{$const->{NAME}} = [$const->{DATA}->{TYPE}, $const->{VALUE}];
 }
 
+sub FromTypeToPythonFunction($$)
+{
+	my ($self, $type) = @_;
+
+	#FIXME
+}
+
+sub FromPythonToTypeFunction($$)
+{
+	my ($self, $type) = @_;
+
+	#FIXME
+}
+
+sub TypeConstructor($$)
+{
+	my ($self, $type) = @_;
+
+	#FIXME
+}
+
+sub PythonFunction($$)
+{
+	my ($self, $fn) = @_;
+
+	$self->pidl("static PyObject *py_$fn->{NAME}(PyObject *self, PyObject *args)");
+	$self->pidl("{");
+	$self->indent;
+	# FIXME
+	$self->pidl("return Py_None;");
+	$self->deindent;
+	$self->pidl("}");
+	$self->pidl("");
+}
+
 sub Interface($$)
 {
 	my($self,$interface) = @_;
@@ -77,6 +112,107 @@
 
 	$self->Const($_) foreach (@{$interface->{CONSTS}});
 
+	foreach (@{$interface->{TYPES}}) {
+		$self->FromTypeToPythonFunction($_);	
+		$self->FromPythonToTypeFunction($_);	
+		$self->TypeConstructor($_);
+	}
+
+	$self->pidl("staticforward PyTypeObject $interface->{NAME}_InterfaceType;");
+	$self->pidl("typedef struct {");
+	$self->indent;
+	$self->pidl("PyObject_HEAD");
+	$self->pidl("struct dcerpc_pipe *pipe;");
+	$self->deindent;
+	$self->pidl("} $interface->{NAME}_InterfaceObject;");
+
+	$self->pidl("");
+
+	foreach my $d (@{$interface->{FUNCTIONS}}) {
+		next if not defined($d->{OPNUM});
+		next if has_property($d, "nopython");
+
+		$self->PythonFunction($d, $interface->{NAME});
+	}
+
+	$self->pidl("static PyMethodDef interface_$interface->{NAME}\_methods[] = {");
+	$self->indent;
+	foreach my $d (@{$interface->{FUNCTIONS}}) {
+		next if not defined($d->{OPNUM});
+		next if has_property($d, "nopython");
+
+		my $fn_name = $d->{NAME};
+
+		$fn_name =~ s/^$interface->{NAME}_//;
+
+		$self->pidl("{ (char *)\"$fn_name\", (PyCFunction)py_$d->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },");
+	}
+	$self->pidl("{ NULL, NULL, 0, NULL }");
+	$self->deindent;
+	$self->pidl("};");
+	$self->pidl("");
+
+	$self->pidl("static void interface_$interface->{NAME}_dealloc(PyObject* self)");
+	$self->pidl("{");
+	$self->indent;
+	$self->pidl("$interface->{NAME}_InterfaceObject *interface;");
+	$self->pidl("talloc_free(interface->pipe);");
+	$self->pidl("PyObject_Del(self);");
+	$self->deindent;
+	$self->pidl("}");
+	$self->pidl("");
+
+	$self->pidl("static PyObject *interface_$interface->{NAME}_getattr(PyTypeObject *obj, char *name)");
+	$self->pidl("{");
+	$self->indent;
+	$self->pidl("return Py_FindMethod(interface_$interface->{NAME}\_methods, (PyObject *)obj, name);");
+	$self->deindent;
+	$self->pidl("}");
+
+	$self->pidl("");
+
+	$self->pidl("static PyTypeObject $interface->{NAME}_InterfaceType = {");
+	$self->indent;
+	$self->pidl("PyObject_HEAD_INIT(NULL) 0,");
+	$self->pidl(".tp_name = \"$interface->{NAME}\",");
+	$self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),");
+	$self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,");
+	$self->pidl(".tp_getattr = interface_$interface->{NAME}_getattr,");
+	$self->deindent;
+	$self->pidl("};");
+
+	$self->pidl("");
+
+	$self->pidl("static PyObject *interface_$interface->{NAME}(PyObject *self, PyObject *args)");
+	$self->pidl("{");
+	$self->indent;
+	$self->pidl("$interface->{NAME}_InterfaceObject *ret;");
+	$self->pidl("const char *binding_string;");
+	$self->pidl("struct cli_credentials *credentials;");
+	$self->pidl("struct loadparm_context *lp_ctx;");
+	$self->pidl("NTSTATUS status;");
+	$self->pidl("");
+
+	# FIXME: Arguments: binding string, credentials, loadparm context
+	$self->pidl("ret = PyObject_New($interface->{NAME}_InterfaceObject, &$interface->{NAME}_InterfaceType);");
+	$self->pidl("");
+
+	$self->pidl("status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, ");
+	$self->pidl("             &ndr_table_$interface->{NAME}, credentials, NULL, lp_ctx);");
+	$self->pidl("if (NT_STATUS_IS_ERR(status)) {");
+	$self->indent;
+	$self->pidl("PyErr_SetString(PyExc_RuntimeError, nt_errstr(status));");
+	$self->pidl("return NULL;");
+	$self->deindent;
+	$self->pidl("}");
+	$self->pidl("");
+
+	$self->pidl("return (PyObject *)ret;");
+	$self->deindent;
+	$self->pidl("}");
+	
+	$self->pidl("");
+
 	$self->pidl_hdr("\n");
 	$self->pidl_hdr("#endif /* _HEADER_NDR_$interface->{NAME} */\n");
 }
@@ -94,6 +230,7 @@
 /* Python wrapper functions auto-generated by pidl */
 #include \"includes.h\"
 #include <Python.h>
+#include \"librpc/rpc/dcerpc.h\"
 #include \"$hdr\"
 #include \"$py_hdr\"
 
@@ -106,6 +243,11 @@
 	
 	$self->pidl("static PyMethodDef $basename\_methods[] = {");
 	$self->indent;
+	foreach my $x (@$ndr) {
+	    next if ($x->{TYPE} ne "INTERFACE");
+		$self->pidl("{ (char *)\"$x->{NAME}\", (PyCFunction)interface_$x->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },");
+	}
+	
 	$self->pidl("{ NULL, NULL, 0, NULL }");
 	$self->deindent;
 	$self->pidl("};");
@@ -115,12 +257,11 @@
 	$self->pidl("void init$basename(void)");
 	$self->pidl("{");
 	$self->indent;
-	$self->pidl("PyObject *m, *d;");
+	$self->pidl("PyObject *m;");
 	$self->pidl("m = Py_InitModule((char *)\"$basename\", $basename\_methods);");
-	$self->pidl("d = PyModule_GetDict(m);");
 	foreach (keys %{$self->{constants}}) {
 		# FIXME: Handle non-string constants
-		$self->pidl("PyDict_SetItemString(d, \"$_\", PyString_FromString(" . $self->{constants}->{$_}->[1] . "));");
+		$self->pidl("PyModule_AddObject(m, \"$_\", PyString_FromString(" . $self->{constants}->{$_}->[1] . "));");
 	}
 	$self->deindent;
 	$self->pidl("}");



More information about the samba-cvs mailing list