summaryrefslogtreecommitdiff
path: root/source4/pidl/lib
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-01-03 23:58:38 -0600
committerStefan Metzmacher <metze@samba.org>2008-01-03 18:03:02 -0600
commit0d6dbcabe9c90f211c356155d21f9d3d630333a6 (patch)
treebadf0204e6ccef970e8b203c6abb2ddf09c25559 /source4/pidl/lib
parent935031309ac2f7a174c39caef5bc7b3d2f2508e2 (diff)
downloadsamba-0d6dbcabe9c90f211c356155d21f9d3d630333a6.tar.gz
samba-0d6dbcabe9c90f211c356155d21f9d3d630333a6.tar.bz2
samba-0d6dbcabe9c90f211c356155d21f9d3d630333a6.zip
r26660: pidl/python: Generate stub functions for DCE/RPC client functions, constructor for interface objects.
(This used to be commit 0ee0581f052d0b90b2697841aaa09e0955aff65a)
Diffstat (limited to 'source4/pidl/lib')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/Python.pm147
1 files changed, 144 insertions, 3 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 7c2c2c06c6..0a2fb0b0f3 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -66,6 +66,41 @@ sub Const($$)
$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 @@ sub Interface($$)
$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 @@ sub Parse($$$$)
/* 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 @@ sub Parse($$$$)
$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 @@ sub Parse($$$$)
$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("}");