summaryrefslogtreecommitdiff
path: root/source4/pidl/lib/Parse/Pidl
diff options
context:
space:
mode:
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl')
-rw-r--r--source4/pidl/lib/Parse/Pidl/NDR.pm1
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm65
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm54
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm37
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/Python.pm362
5 files changed, 356 insertions, 163 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/NDR.pm b/source4/pidl/lib/Parse/Pidl/NDR.pm
index 86ed1a8d10..33e5ad3196 100644
--- a/source4/pidl/lib/Parse/Pidl/NDR.pm
+++ b/source4/pidl/lib/Parse/Pidl/NDR.pm
@@ -866,6 +866,7 @@ my %property_list = (
"nosize" => ["FUNCTION", "TYPEDEF"],
"noprint" => ["FUNCTION", "TYPEDEF"],
"noejs" => ["FUNCTION", "TYPEDEF"],
+ "todo" => ["FUNCTION"],
# union
"switch_is" => ["ELEMENT"],
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
index 7a2575b897..87ed29b54e 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
@@ -9,7 +9,7 @@ package Parse::Pidl::Samba3::ClientNDR;
use Exporter;
@ISA = qw(Exporter);
-@EXPORT_OK = qw(ParseFunction $res $res_hdr);
+@EXPORT_OK = qw(ParseFunction $res $res_hdr ParseOutputArgument);
use strict;
use Parse::Pidl qw(fatal warning);
@@ -73,6 +73,40 @@ sub HeaderProperties($$)
}
}
+sub ParseOutputArgument($$$)
+{
+ my ($self, $fn, $e) = @_;
+ my $level = 0;
+
+ fatal($e->{ORIGINAL}, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY");
+
+ if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") {
+ $level = 1;
+ if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") {
+ $self->pidl("if ($e->{NAME} && r.out.$e->{NAME}) {");
+ $self->indent;
+ }
+ }
+
+ if ($e->{LEVELS}[$level]->{TYPE} eq "ARRAY") {
+ # This is a call to GenerateFunctionInEnv intentionally.
+ # Since the data is being copied into a user-provided data
+ # structure, the user should be able to know the size beforehand
+ # to allocate a structure of the right size.
+ my $env = GenerateFunctionInEnv($fn, "r.");
+ my $size_is = ParseExpr($e->{LEVELS}[$level]->{SIZE_IS}, $env, $e->{ORIGINAL});
+ $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is * sizeof(*$e->{NAME}));");
+ } else {
+ $self->pidl("*$e->{NAME} = *r.out.$e->{NAME};");
+ }
+
+ if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") {
+ if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") {
+ $self->deindent;
+ $self->pidl("}");
+ }
+ }
+}
sub ParseFunction($$$)
{
@@ -147,36 +181,9 @@ sub ParseFunction($$$)
$self->pidl("/* Return variables */");
foreach my $e (@{$fn->{ELEMENTS}}) {
next unless (grep(/out/, @{$e->{DIRECTION}}));
- my $level = 0;
- fatal($e->{ORIGINAL}, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY");
-
- if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") {
- $level = 1;
- if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") {
- $self->pidl("if ($e->{NAME} && r.out.$e->{NAME}) {");
- $self->indent;
- }
- }
+ $self->ParseOutputArgument($fn, $e);
- if ($e->{LEVELS}[$level]->{TYPE} eq "ARRAY") {
- # This is a call to GenerateFunctionInEnv intentionally.
- # Since the data is being copied into a user-provided data
- # structure, the user should be able to know the size beforehand
- # to allocate a structure of the right size.
- my $env = GenerateFunctionInEnv($fn, "r.");
- my $size_is = ParseExpr($e->{LEVELS}[$level]->{SIZE_IS}, $env, $e->{ORIGINAL});
- $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is);");
- } else {
- $self->pidl("*$e->{NAME} = *r.out.$e->{NAME};");
- }
-
- if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") {
- if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") {
- $self->deindent;
- $self->pidl("}");
- }
- }
}
$self->pidl("");
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm
index e9c158e933..f8209be654 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm
@@ -7,6 +7,7 @@
package Parse::Pidl::Samba4::NDR::Client;
use Parse::Pidl::Samba4 qw(choose_header is_intree);
+use Parse::Pidl::Util qw(has_property);
use vars qw($VERSION);
$VERSION = '0.01';
@@ -15,30 +16,45 @@ use strict;
my($res,$res_hdr);
-#####################################################################
-# parse a function
-sub ParseFunction($$)
+sub ParseFunctionSend($$$)
{
- my ($interface, $fn) = @_;
- my $name = $fn->{NAME};
+ my ($interface, $fn, $name) = @_;
my $uname = uc $name;
- $res_hdr .= "\nstruct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r);
-NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r);
-";
+ my $proto = "struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)";
- $res .= "
-struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
-{
+ $res_hdr .= "\n$proto;\n";
+
+ $res .= "$proto\n{\n";
+
+ if (has_property($fn, "todo")) {
+ $res .= "\treturn NULL;\n";
+ } else {
+ $res .= "
if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) {
NDR_PRINT_IN_DEBUG($name, r);
}
return dcerpc_ndr_request_send(p, NULL, &ndr_table_$interface->{NAME}, NDR_$uname, mem_ctx, r);
+";
+ }
+
+ $res .= "}\n\n";
}
-NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
+sub ParseFunctionSync($$$)
{
+ my ($interface, $fn, $name) = @_;
+
+ my $proto = "NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)";
+
+ $res_hdr .= "\n$proto;\n";
+ $res .= "$proto\n{\n";
+
+ if (has_property($fn, "todo")) {
+ $res .= "\treturn NT_STATUS_NOT_IMPLEMENTED;\n";
+ } else {
+ $res .= "
struct rpc_request *req;
NTSTATUS status;
@@ -58,8 +74,20 @@ NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *
$res .=
"
return status;
-}
";
+ }
+
+ $res .= "}\n\n";
+}
+
+#####################################################################
+# parse a function
+sub ParseFunction($$)
+{
+ my ($interface, $fn) = @_;
+
+ ParseFunctionSend($interface, $fn, $fn->{NAME});
+ ParseFunctionSync($interface, $fn, $fn->{NAME});
}
my %done;
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
index a959dc84f6..0d1806a0fa 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
@@ -2190,6 +2190,26 @@ sub ParseFunctionPull($$)
$self->pidl("");
}
+sub AuthServiceStruct($$$)
+{
+ my ($self, $ifacename, $authservice) = @_;
+ my @a = split /,/, $authservice;
+ my $authservice_count = $#a + 1;
+
+ $self->pidl("static const char * const $ifacename\_authservice_strings[] = {");
+ foreach my $ap (@a) {
+ $self->pidl("\t$ap, ");
+ }
+ $self->pidl("};");
+ $self->pidl("");
+
+ $self->pidl("static const struct ndr_interface_string_array $ifacename\_authservices = {");
+ $self->pidl("\t.count\t= $authservice_count,");
+ $self->pidl("\t.names\t= $ifacename\_authservice_strings");
+ $self->pidl("};");
+ $self->pidl("");
+}
+
#####################################################################
# produce a function call table
sub FunctionTable($$)
@@ -2237,21 +2257,8 @@ sub FunctionTable($$)
$interface->{PROPERTIES}->{authservice} = "\"host\"";
}
- my @a = split /,/, $interface->{PROPERTIES}->{authservice};
- my $authservice_count = $#a + 1;
-
- $self->pidl("static const char * const $interface->{NAME}\_authservice_strings[] = {");
- foreach my $ap (@a) {
- $self->pidl("\t$ap, ");
- }
- $self->pidl("};");
- $self->pidl("");
-
- $self->pidl("static const struct ndr_interface_string_array $interface->{NAME}\_authservices = {");
- $self->pidl("\t.count\t= $endpoint_count,");
- $self->pidl("\t.names\t= $interface->{NAME}\_authservice_strings");
- $self->pidl("};");
- $self->pidl("");
+ $self->AuthServiceStruct($interface->{NAME},
+ $interface->{PROPERTIES}->{authservice});
$self->pidl("\nconst struct ndr_interface_table ndr_table_$interface->{NAME} = {");
$self->pidl("\t.name\t\t= \"$interface->{NAME}\",");
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 2475925377..440b1bff97 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -21,7 +21,7 @@ $VERSION = '0.01';
sub new($) {
my ($class) = @_;
my $self = { res => "", res_hdr => "", tabs => "", constants => {},
- module_methods => []};
+ module_methods => [], module_objects => [], module_types => []};
bless($self, $class);
}
@@ -163,46 +163,35 @@ sub FromPythonToUnionFunction($$$$$)
$self->pidl("return ret;");
}
-sub PythonStruct($$$$)
+sub PythonStruct($$$$$$)
{
- my ($self, $name, $cname, $d) = @_;
+ my ($self, $modulename, $prettyname, $name, $cname, $d) = @_;
my $env = GenerateStructEnv($d, "object");
$self->pidl("");
- $self->pidl("static PyObject *py_$name\_getattr(PyObject *obj, char *name)");
- $self->pidl("{");
- $self->indent;
+ my $getsetters = "NULL";
+
if ($#{$d->{ELEMENTS}} > -1) {
- $self->pidl("$cname *object = py_talloc_get_ptr(obj);");
foreach my $e (@{$d->{ELEMENTS}}) {
- $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {");
my $varname = "object->$e->{NAME}";
+ $self->pidl("static PyObject *py_$name\_get_$e->{NAME}(PyObject *obj, void *closure)");
+ $self->pidl("{");
$self->indent;
+ $self->pidl("$cname *object = py_talloc_get_ptr(obj);");
$self->pidl("PyObject *py_$e->{NAME};");
$self->ConvertObjectToPython("py_talloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}");
$self->pidl("return py_$e->{NAME};");
$self->deindent;
$self->pidl("}");
- }
- }
- $self->pidl("PyErr_SetString(PyExc_AttributeError, \"no such attribute\");");
- $self->pidl("return NULL;");
- $self->deindent;
- $self->pidl("}");
- $self->pidl("");
+ $self->pidl("");
- $self->pidl("static int py_$name\_setattr(PyObject *py_obj, char *name, PyObject *value)");
- $self->pidl("{");
- $self->indent;
- if ($#{$d->{ELEMENTS}} > -1) {
- $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);");
- my $mem_ctx = "py_talloc_get_mem_ctx(py_obj)";
- foreach my $e (@{$d->{ELEMENTS}}) {
- $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {");
- my $varname = "object->$e->{NAME}";
+ $self->pidl("static int py_$name\_set_$e->{NAME}(PyObject *py_obj, PyObject *value, void *closure)");
+ $self->pidl("{");
$self->indent;
+ $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);");
+ my $mem_ctx = "py_talloc_get_mem_ctx(py_obj)";
my $l = $e->{LEVELS}[0];
my $nl = GetNextLevel($e, $l);
if ($l->{TYPE} eq "POINTER" and
@@ -214,52 +203,74 @@ sub PythonStruct($$$$)
$self->pidl("return 0;");
$self->deindent;
$self->pidl("}");
+ $self->pidl("");
}
+
+ $getsetters = "py_$name\_getsetters";
+ $self->pidl("static PyGetSetDef ".$getsetters."[] = {");
+ $self->indent;
+ foreach my $e (@{$d->{ELEMENTS}}) {
+ $self->pidl("{ discard_const_p(char, \"$e->{NAME}\"), py_$name\_get_$e->{NAME}, py_$name\_set_$e->{NAME} },");
+ }
+ $self->pidl("{ NULL }");
+ $self->deindent;
+ $self->pidl("};");
+ $self->pidl("");
}
- $self->pidl("PyErr_SetString(PyExc_AttributeError, \"no such attribute\");");
- $self->pidl("return -1;");
+
+ $self->pidl("static PyObject *py_$name\_new(PyTypeObject *self, PyObject *args, PyObject *kwargs)");
+ $self->pidl("{");
+ $self->indent;
+ $self->pidl("$cname *ret = talloc_zero(NULL, $cname);");
+ $self->pidl("return py_talloc_import(&$name\_Type, ret);");
$self->deindent;
$self->pidl("}");
+
$self->pidl("");
$self->pidl_hdr("PyAPI_DATA(PyTypeObject) $name\_Type;\n");
$self->pidl_hdr("#define $name\_Check(op) PyObject_TypeCheck(op, &$name\_Type)\n");
$self->pidl_hdr("#define $name\_CheckExact(op) ((op)->ob_type == &$name\_Type)\n");
$self->pidl_hdr("\n");
- $self->pidl("PyTypeObject $name\_Type = {");
+ my $docstring = ($self->DocString($d, $name) or "NULL");
+ my $typeobject = "$name\_Type";
+ $self->pidl("PyTypeObject $typeobject = {");
$self->indent;
$self->pidl("PyObject_HEAD_INIT(NULL) 0,");
- $self->pidl(".tp_name = \"$name\",");
+ $self->pidl(".tp_name = \"$modulename.$prettyname\",");
$self->pidl(".tp_basicsize = sizeof(py_talloc_Object),");
$self->pidl(".tp_dealloc = py_talloc_dealloc,");
- $self->pidl(".tp_getattr = py_$name\_getattr,");
- $self->pidl(".tp_setattr = py_$name\_setattr,");
+ $self->pidl(".tp_getset = $getsetters,");
$self->pidl(".tp_repr = py_talloc_default_repr,");
+ $self->pidl(".tp_doc = $docstring,");
+ $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,");
+ $self->pidl(".tp_new = py_$name\_new,");
$self->deindent;
$self->pidl("};");
$self->pidl("");
- my $py_fnname = "py_$name";
- $self->pidl("static PyObject *$py_fnname(PyObject *self, PyObject *args)");
- $self->pidl("{");
- $self->indent;
- $self->pidl("$cname *ret = talloc_zero(NULL, $cname);");
- $self->pidl("return py_talloc_import(&$name\_Type, ret);");
- $self->deindent;
- $self->pidl("}");
- $self->pidl("");
+ return "&$typeobject";
+}
- return $py_fnname;
+sub get_metadata_var($)
+{
+ my ($e) = @_;
+ sub get_var($) { my $x = shift; $x =~ s/\*//g; return $x; }
+
+ if (has_property($e, "length_is")) {
+ return get_var($e->{PROPERTIES}->{length_is});
+ } elsif (has_property($e, "size_is")) {
+ return get_var($e->{PROPERTIES}->{size_is});
+ }
+
+ return undef;
}
-sub PythonFunction($$$)
+sub PythonFunctionBody($$$)
{
- my ($self, $fn, $iface) = @_;
+ my ($self, $fn, $iface, $prettyname) = @_;
- $self->pidl("static PyObject *py_$fn->{NAME}(PyObject *self, PyObject *args, PyObject *kwargs)");
- $self->pidl("{");
- $self->indent;
$self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;");
$self->pidl("NTSTATUS status;");
$self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);");
@@ -273,7 +284,23 @@ sub PythonFunction($$$)
my $args_string = "";
my $args_names = "";
+ my $signature = "S.$prettyname(";
+
+ my $metadata_args = { in => {}, out => {} };
+
+ # Determine arguments that are metadata for other arguments (size_is/length_is)
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ foreach my $dir (@{$e->{DIRECTION}}) {
+ my $main = get_metadata_var($e);
+ if ($main) {
+ $metadata_args->{$dir}->{$main} = $e->{NAME};
+ }
+ }
+ }
+
foreach my $e (@{$fn->{ELEMENTS}}) {
+ next if (($metadata_args->{in}->{$e->{NAME}} and grep(/in/, @{$e->{DIRECTION}})) or
+ ($metadata_args->{out}->{$e->{NAME}}) and grep(/out/, @{$e->{DIRECTION}}));
$self->pidl("PyObject *py_$e->{NAME};");
if (grep(/out/,@{$e->{DIRECTION}})) {
$result_size++;
@@ -282,8 +309,14 @@ sub PythonFunction($$$)
$args_format .= "O";
$args_string .= ", &py_$e->{NAME}";
$args_names .= "\"$e->{NAME}\", ";
+ $signature .= "$e->{NAME}, ";
}
}
+ if (substr($signature, -2) eq ", ") {
+ $signature = substr($signature, 0, -2);
+ }
+ $signature.= ") -> ";
+
$self->pidl("const char *kwnames[] = {");
$self->indent;
$self->pidl($args_names . "NULL");
@@ -296,14 +329,27 @@ sub PythonFunction($$$)
$self->pidl("return NULL;");
$self->deindent;
$self->pidl("}");
+ $self->pidl("");
if ($fn->{RETURN_TYPE}) {
$result_size++ unless ($fn->{RETURN_TYPE} eq "WERROR" or $fn->{RETURN_TYPE} eq "NTSTATUS");
}
+ my $fail = "talloc_free(mem_ctx); return NULL;";
foreach my $e (@{$fn->{ELEMENTS}}) {
- if (grep(/in/,@{$e->{DIRECTION}})) {
- $self->ConvertObjectFromPython($env, "mem_ctx", $e, "py_$e->{NAME}", "r->in.$e->{NAME}", "talloc_free(mem_ctx); return NULL;");
+ next unless (grep(/in/,@{$e->{DIRECTION}}));
+ if ($metadata_args->{in}->{$e->{NAME}}) {
+ my $py_var = "py_".$metadata_args->{in}->{$e->{NAME}};
+ $self->pidl("PY_CHECK_TYPE(PyList, $py_var, $fail);");
+ my $val = "PyList_Size($py_var)";
+ if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") {
+ $self->pidl("r->in.$e->{NAME} = talloc_ptrtype(mem_ctx, r->in.$e->{NAME});");
+ $self->pidl("*r->in.$e->{NAME} = $val;");
+ } else {
+ $self->pidl("r->in.$e->{NAME} = $val;");
+ }
+ } else {
+ $self->ConvertObjectFromPython($env, "mem_ctx", $e, "py_$e->{NAME}", "r->in.$e->{NAME}", $fail);
}
}
$self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, r);");
@@ -314,17 +360,23 @@ sub PythonFunction($$$)
if ($result_size > 1) {
$self->pidl("result = PyTuple_New($result_size);");
+ $signature .= "(";
+ } elsif ($result_size == 0) {
+ $signature .= "None";
}
foreach my $e (@{$fn->{ELEMENTS}}) {
+ next if ($metadata_args->{out}->{$e->{NAME}});
my $py_name = "py_$e->{NAME}";
if (grep(/out/,@{$e->{DIRECTION}})) {
$self->ConvertObjectToPython("r", $env, $e, "r->out.$e->{NAME}", $py_name);
if ($result_size > 1) {
$self->pidl("PyTuple_SetItem(result, $i, $py_name);");
$i++;
+ $signature .= "$e->{NAME}, ";
} else {
$self->pidl("result = $py_name;");
+ $signature .= $e->{NAME};
}
}
}
@@ -340,13 +392,51 @@ sub PythonFunction($$$)
} else {
$self->pidl("result = $conv;");
}
+ $signature .= "result";
+ }
+
+ if (substr($signature, -2) eq ", ") {
+ $signature = substr($signature, 0, -2);
+ }
+ if ($result_size > 1) {
+ $signature .= ")";
}
$self->pidl("talloc_free(mem_ctx);");
$self->pidl("return result;");
+
+ return $signature;
+}
+
+sub PythonFunction($$$)
+{
+ my ($self, $fn, $iface, $prettyname) = @_;
+
+ my $fnname = "py_$fn->{NAME}";
+ my $docstring = $self->DocString($fn, $fn->{NAME});
+
+ $self->pidl("static PyObject *$fnname(PyObject *self, PyObject *args, PyObject *kwargs)");
+ $self->pidl("{");
+ $self->indent;
+ if (has_property($fn, "todo")) {
+ $self->pidl("PyErr_SetString(PyExc_NotImplementedError, \"No marshalling code available yet for $prettyname\");");
+ $self->pidl("return NULL;");
+ unless ($docstring) { $docstring = "NULL"; }
+ } else {
+ my $signature = $self->PythonFunctionBody($fn, $iface, $prettyname);
+
+ if ($docstring) {
+ $docstring = "\"$signature\\n\\n\"$docstring";
+ } else {
+ $docstring = "\"$signature\"";
+ }
+ }
+
$self->deindent;
$self->pidl("}");
$self->pidl("");
+
+ return ($fnname, $docstring);
}
sub handle_werror($$$$)
@@ -377,9 +467,9 @@ sub handle_ntstatus($$$$)
$self->pidl("");
}
-sub PythonType($$$)
+sub PythonType($$$$)
{
- my ($self, $d, $interface, $basename) = @_;
+ my ($self, $modulename, $d, $interface, $basename) = @_;
my $actual_ctype = $d;
if ($actual_ctype->{TYPE} eq "TYPEDEF") {
@@ -387,19 +477,20 @@ sub PythonType($$$)
}
if ($actual_ctype->{TYPE} eq "STRUCT") {
- my $py_fnname;
- if ($d->{TYPE} eq "STRUCT") {
- $py_fnname = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d);
- } else {
- $py_fnname = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d->{DATA});
- }
-
+ my $typeobject;
my $fn_name = $d->{NAME};
$fn_name =~ s/^$interface->{NAME}_//;
$fn_name =~ s/^$basename\_//;
- $self->register_module_method($fn_name, $py_fnname, "METH_NOARGS", "NULL");
+
+ if ($d->{TYPE} eq "STRUCT") {
+ $typeobject = $self->PythonStruct($modulename, $fn_name, $d->{NAME}, mapTypeName($d), $d);
+ } else {
+ $typeobject = $self->PythonStruct($modulename, $fn_name, $d->{NAME}, mapTypeName($d), $d->{DATA});
+ }
+
+ $self->register_module_typeobject($fn_name, $typeobject);
}
if ($d->{TYPE} eq "ENUM" or $d->{TYPE} eq "BITMAP") {
@@ -429,6 +520,18 @@ sub PythonType($$$)
}
}
+sub DocString($$$)
+{
+ my ($self, $d, $name) = @_;
+ if (has_property($d, "helpstring")) {
+ my $docstring = uc("py_doc_$name");
+ $self->pidl("#define $docstring ".has_property($d, "helpstring"));
+ return $docstring;
+ }
+
+ return undef;
+}
+
sub Interface($$$)
{
my($self,$interface,$basename) = @_;
@@ -443,7 +546,7 @@ sub Interface($$$)
foreach my $d (@{$interface->{TYPES}}) {
next if has_property($d, "nopython");
- $self->PythonType($d, $interface, $basename);
+ $self->PythonType($basename, $d, $interface, $basename);
}
if (defined $interface->{PROPERTIES}->{uuid}) {
@@ -457,25 +560,27 @@ sub Interface($$$)
$self->pidl("");
+ my @fns = ();
+
foreach my $d (@{$interface->{FUNCTIONS}}) {
next if not defined($d->{OPNUM});
next if has_property($d, "nopython");
- $self->PythonFunction($d, $interface->{NAME});
- }
+ my $prettyname = $d->{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");
+ $prettyname =~ s/^$interface->{NAME}_//;
+ $prettyname =~ s/^$basename\_//;
- my $fn_name = $d->{NAME};
+ my ($fnname, $fndocstring) = $self->PythonFunction($d, $interface->{NAME}, $prettyname);
- $fn_name =~ s/^$interface->{NAME}_//;
- $fn_name =~ s/^$basename\_//;
+ push (@fns, [$fnname, $prettyname, $fndocstring]);
+ }
- $self->pidl("{ \"$fn_name\", (PyCFunction)py_$d->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },");
+ $self->pidl("static PyMethodDef interface_$interface->{NAME}\_methods[] = {");
+ $self->indent;
+ foreach my $d (@fns) {
+ my ($c_fn, $prettyname, $docstring) = @$d;
+ $self->pidl("{ \"$prettyname\", (PyCFunction)$c_fn, METH_VARARGS|METH_KEYWORDS, $docstring },");
}
$self->pidl("{ NULL, NULL, 0, NULL }");
$self->deindent;
@@ -492,37 +597,16 @@ sub Interface($$$)
$self->pidl("}");
$self->pidl("");
- $self->pidl("static PyObject *interface_$interface->{NAME}_getattr(PyObject *obj, char *name)");
- $self->pidl("{");
- $self->indent;
- $self->pidl("return Py_FindMethod(interface_$interface->{NAME}\_methods, obj, name);");
- $self->deindent;
- $self->pidl("}");
-
- $self->pidl("");
-
- $self->pidl("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->register_module_method($interface->{NAME}, "interface_$interface->{NAME}", "METH_VARARGS|METH_KEYWORDS", "NULL");
- $self->pidl("static PyObject *interface_$interface->{NAME}(PyObject *self, PyObject *args, PyObject *kwargs)");
+ $self->pidl("static PyObject *interface_$interface->{NAME}_new(PyTypeObject *self, PyObject *args, PyObject *kwargs)");
$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 = NULL;");
- $self->pidl("PyObject *py_lp_ctx = NULL, *py_credentials = Py_None;");
+ $self->pidl("PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None;");
$self->pidl("TALLOC_CTX *mem_ctx = NULL;");
+ $self->pidl("struct event_context *event_ctx;");
$self->pidl("NTSTATUS status;");
$self->pidl("");
$self->pidl("const char *kwnames[] = {");
@@ -533,14 +617,12 @@ sub Interface($$$)
$self->pidl("extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);");
$self->pidl("extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj);");
$self->pidl("");
- $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"sO|O:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials)) {");
+ $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s|OO:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials)) {");
$self->indent;
$self->pidl("return NULL;");
$self->deindent;
$self->pidl("}");
$self->pidl("");
- $self->pidl("if (py_lp_ctx != NULL) {");
- $self->indent;
$self->pidl("lp_ctx = lp_from_py_object(py_lp_ctx);");
$self->pidl("if (lp_ctx == NULL) {");
$self->indent;
@@ -548,8 +630,6 @@ sub Interface($$$)
$self->pidl("return NULL;");
$self->deindent;
$self->pidl("}");
- $self->deindent;
- $self->pidl("}");
$self->pidl("");
$self->pidl("credentials = cli_credentials_from_py_object(py_credentials);");
@@ -562,9 +642,11 @@ sub Interface($$$)
$self->pidl("ret = PyObject_New($interface->{NAME}_InterfaceObject, &$interface->{NAME}_InterfaceType);");
$self->pidl("");
+ $self->pidl("event_ctx = event_context_init(mem_ctx);");
+ $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(" &ndr_table_$interface->{NAME}, credentials, event_ctx, lp_ctx);");
$self->handle_ntstatus("status", "NULL", "mem_ctx");
$self->pidl("ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC;");
@@ -574,6 +656,38 @@ sub Interface($$$)
$self->pidl("}");
$self->pidl("");
+
+ my $signature =
+"\"$interface->{NAME}(binding, lp_ctx=None, credentials=None) -> connection\\n\"
+\"\\n\"
+\"binding should be a DCE/RPC binding string (for example: ncacn_ip_tcp:127.0.0.1)\\n\"
+\"lp_ctx should be a path to a smb.conf file or a param.LoadParm object\\n\"
+\"credentials should be a credentials.Credentials object.\\n\\n\"";
+
+ my $docstring = $self->DocString($interface, $interface->{NAME});
+
+ if ($docstring) {
+ $docstring = "$signature$docstring";
+ } else {
+ $docstring = $signature;
+ }
+
+ $self->pidl("PyTypeObject $interface->{NAME}_InterfaceType = {");
+ $self->indent;
+ $self->pidl("PyObject_HEAD_INIT(NULL) 0,");
+ $self->pidl(".tp_name = \"$basename.$interface->{NAME}\",");
+ $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),");
+ $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,");
+ $self->pidl(".tp_methods = interface_$interface->{NAME}_methods,");
+ $self->pidl(".tp_doc = $docstring,");
+ $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,");
+ $self->pidl(".tp_new = interface_$interface->{NAME}_new,");
+ $self->deindent;
+ $self->pidl("};");
+
+ $self->pidl("");
+
+ $self->register_module_typeobject($interface->{NAME}, "&$interface->{NAME}_InterfaceType");
}
$self->pidl_hdr("\n");
@@ -587,6 +701,22 @@ sub register_module_method($$$$$)
push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc])
}
+sub register_module_typeobject($$$)
+{
+ my ($self, $name, $py_name) = @_;
+
+ $self->register_module_object($name, "(PyObject *)$py_name");
+
+ push (@{$self->{module_types}}, [$name, $py_name])
+}
+
+sub register_module_object($$$)
+{
+ my ($self, $name, $py_name) = @_;
+
+ push (@{$self->{module_objects}}, [$name, $py_name])
+}
+
sub assign($$$)
{
my ($self, $dest, $src) = @_;
@@ -828,16 +958,15 @@ sub ConvertObjectToPythonLevel($$$$$)
$self->pidl("}");
}
} elsif ($l->{TYPE} eq "ARRAY") {
- if (is_charset_array($e, $l)) {
+ my $pl = GetPrevLevel($e, $l);
+ if ($pl && $pl->{TYPE} eq "POINTER") {
$var_name = get_pointer_to($var_name);
+ }
+
+ if (is_charset_array($e, $l)) {
# FIXME: Use Unix charset setting rather than utf-8
$self->pidl("$py_var = PyUnicode_Decode($var_name, strlen($var_name), \"utf-8\", \"ignore\");");
} else {
- my $pl = GetPrevLevel($e, $l);
- if ($pl && $pl->{TYPE} eq "POINTER") {
- $var_name = get_pointer_to($var_name);
- }
-
die("No SIZE_IS for array $var_name") unless (defined($l->{SIZE_IS}));
my $length = $l->{SIZE_IS};
if (defined($l->{LENGTH_IS})) {
@@ -901,6 +1030,7 @@ sub Parse($$$$$)
#include \"librpc/rpc/dcerpc.h\"
#include \"scripting/python/pytalloc.h\"
#include \"scripting/python/pyrpc.h\"
+#include \"lib/events/events.h\"
#include \"$hdr\"
#include \"$ndr_hdr\"
#include \"$py_hdr\"
@@ -929,7 +1059,20 @@ sub Parse($$$$$)
$self->pidl("{");
$self->indent;
$self->pidl("PyObject *m;");
- $self->pidl("m = Py_InitModule(\"$basename\", $basename\_methods);");
+ $self->pidl("");
+
+ foreach (@{$self->{module_types}}) {
+ my ($object_name, $c_name) = @$_;
+ $self->pidl("if (PyType_Ready($c_name) < 0)");
+ $self->pidl("\treturn;");
+ }
+
+ $self->pidl("");
+
+ $self->pidl("m = Py_InitModule3(\"$basename\", $basename\_methods, \"$basename DCE/RPC\");");
+ $self->pidl("if (m == NULL)");
+ $self->pidl("\treturn;");
+ $self->pidl("");
foreach my $name (keys %{$self->{constants}}) {
my $py_obj;
my ($ctype, $cvar) = @{$self->{constants}->{$name}};
@@ -943,6 +1086,13 @@ sub Parse($$$$$)
$self->pidl("PyModule_AddObject(m, \"$name\", $py_obj);");
}
+
+ foreach (@{$self->{module_objects}}) {
+ my ($object_name, $c_name) = @$_;
+ $self->pidl("Py_INCREF($c_name);");
+ $self->pidl("PyModule_AddObject(m, \"$object_name\", $c_name);");
+ }
+
$self->deindent;
$self->pidl("}");
return ($self->{res_hdr}, $self->{res});