summaryrefslogtreecommitdiff
path: root/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm
diff options
context:
space:
mode:
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm129
1 files changed, 80 insertions, 49 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm b/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm
index b6c268edeb..d42960be28 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm
@@ -1,6 +1,7 @@
###################################################
# Samba4 parser generator for swig wrappers
# Copyright tpot@samba.org 2004,2005
+# Copyright jelmer@samba.org 2006
# released under the GNU GPL
package Parse::Pidl::Samba4::SWIG;
@@ -10,70 +11,100 @@ $VERSION = '0.01';
use strict;
+my $ret = "";
+my $tabs = "";
+
sub pidl($)
{
- print OUT shift;
+ my $p = shift;
+ $ret .= $tabs. $p . "\n";
}
-#####################################################################
-# rewrite autogenerated header file
-sub RewriteHeader($$$)
-{
- my($idl) = shift;
- my($input) = shift;
- my($output) = shift;
-
- open(IN, "<$input") || die "can't open $input for reading";
- open(OUT, ">$output") || die "can't open $output for writing";
-
- pidl "%{\n";
- pidl "#define data_in in\n";
- pidl "#define data_out out\n";
- pidl "%}\n\n";
-
- while(<IN>) {
+sub indent() { $tabs.="\t"; }
+sub deindent() { $tabs = substr($tabs,0,-1); }
- # Rename dom_sid2 to dom_sid as we don't care about the difference
- # for the swig wrappers.
-
- s/dom_sid2/dom_sid/g;
+sub ParseInterface($)
+{
+ my $if = shift;
+
+ pidl "\%{";
+ pidl "struct $if->{NAME} {";
+ indent;
+ pidl "struct dcerpc_pipe *pipe;";
+ deindent;
+ pidl "};";
+ pidl "%}";
+ pidl "";
+
+ # FIXME: Generate ignores for all manual functions
+
+ pidl "\%extend $if->{NAME} {";
+ indent();
+ pidl "struct $if->{NAME} *$if->{NAME} (const char *binding, struct cli_credentials *cred = NULL, TALLOC_CTX *mem_ctx = NULL, struct event_context *event = NULL)";
+ pidl "{";
+ indent;
+ pidl "struct $if->{NAME} *ret = talloc(mem_ctx, struct $if->{NAME});";
+ pidl "NTSTATUS status;";
+ pidl "";
+ pidl "status = dcerpc_pipe_connect(mem_ctx, &ret->pipe, &dcerpc_table_$if->{NAME}, cred, event);";
+ pidl "if (NT_STATUS_IS_ERR(status)) {";
+ pidl "\tsamba_nt_status_exception(status);";
+ pidl "\treturn NULL;";
+ pidl "}";
+ pidl "";
+ pidl "return ret;";
+ deindent;
+ pidl "}";
+ pidl "";
+ pidl "~$if->{NAME}() {";
+ pidl "\ttalloc_free(self);";
+ pidl "}";
+ pidl "";
+
+ foreach (@{$if->{FUNCTIONS}}) {
+ pidl "/* $_->{NAME} */";
+ }
- # Copy structure and union definitions
+ deindent();
+ pidl "}";
+ pidl "";
- if (/^(struct|union) .*? {$/ .. /^\};$/) {
- s/\} (in|out);/\} data_$1;/; # "in" is a Python keyword
- pidl $_;
- next;
+ foreach (@{$if->{TYPES}}) {
+ pidl "/* $_->{NAME} */";
}
+
+ pidl "";
+}
- # Copy dcerpc functions
-
- pidl $_ if /^NTSTATUS dcerpc_.*?\(struct dcerpc_pipe/;
+sub Parse($$$$)
+{
+ my($ndr,$basename,$header,$gen_header) = @_;
- # Copy interface definitions
+ $ret = "";
- pidl $_
- if /^\#define DCERPC_.*?_UUID/ or /^\#define DCERPC_.*?_VERSION/;
- }
+ pidl "/* This file is autogenerated by pidl. DO NOT EDIT */";
- close(OUT);
-}
+ pidl "\%module $basename";
+
+ pidl "";
-#####################################################################
-# rewrite autogenerated header file
-sub RewriteC($$$)
-{
- my($idl) = shift;
- my($input) = shift;
- my($output) = shift;
+ pidl "\%{";
+ pidl "#include \"includes.h\"";
+ pidl "#include \"$header\"";
+ pidl "%}";
+ pidl "\%include \"samba.i\"";
+ pidl "\%include \"$gen_header\"";
- open(IN, "<$input") || die "can't open $input for reading";
- open(OUT, ">>$output") || die "can't open $output for writing";
-
- while(<IN>) {
- }
+ pidl "";
- close(OUT);
+ foreach (@$ndr) {
+ ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");
+ }
+ #FIXME: Foreach ref pointer, set NONNULL
+ #FIXME: Foreach unique/full pointer, set MAYBENULL
+ #FIXME: Foreach [out] parameter, set OUTPARAM
+ #
+ return $ret;
}
1;