diff options
-rw-r--r-- | source4/build/smb_build/output.pm | 1 | ||||
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm | 129 | ||||
-rwxr-xr-x | source4/pidl/pidl | 14 | ||||
-rw-r--r-- | source4/scripting/swig/config.mk | 2 |
4 files changed, 90 insertions, 56 deletions
diff --git a/source4/build/smb_build/output.pm b/source4/build/smb_build/output.pm index 351dff521a..7accad92da 100644 --- a/source4/build/smb_build/output.pm +++ b/source4/build/smb_build/output.pm @@ -19,6 +19,7 @@ sub add_dir($$) if (substr($_, 0, 1) ne "\$") { $_ = "$dir/$_"; s/([^\/\.]+)\/\.\.\///g; + s/([^\/\.]+)\/\.\.\///g; } push (@ret, $_); } 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; diff --git a/source4/pidl/pidl b/source4/pidl/pidl index e3fd434e9b..a7838791b5 100755 --- a/source4/pidl/pidl +++ b/source4/pidl/pidl @@ -661,7 +661,7 @@ sub process_file($) defined($opt_dump_ndr_tree) or defined($opt_samba3_header) or defined($opt_samba3_parser) or defined($opt_samba3_server) or defined($opt_samba3_template) or defined($opt_samba3_client) or - defined($opt_samba3_ndr_client)) { + defined($opt_swig) or defined($opt_samba3_ndr_client)) { require Parse::Pidl::NDR; $ndr = Parse::Pidl::NDR::Parse($pidl); } @@ -691,6 +691,13 @@ sub process_file($) FileSave($c_header, $hdrd); } + if (defined($opt_swig)) { + require Parse::Pidl::Samba4::SWIG; + my($filename) = ($opt_swig or "$outputdir/$basename.i"); + my $code = Parse::Pidl::Samba4::SWIG::Parse($ndr, $basename, "$outputdir/ndr_$basename\_c.h", $gen_header); + FileSave($filename, $code); + } + if (defined($opt_ejs)) { require Parse::Pidl::Samba4::EJS; my ($hdr,$prsr) = Parse::Pidl::Samba4::EJS::Parse($ndr, $h_filename); @@ -735,11 +742,6 @@ $dcom FileSave($parser_fname, $parser); FileSave($h_filename, $header); - if (defined($opt_swig)) { - require Parse::Pidl::Samba4::SWIG; - my($filename) = ($opt_swig or "$outputdir/$basename.i"); - Parse::Pidl::Samba4::SWIG::RewriteHeader($pidl, $h_filename, $filename); - } } if (defined($opt_eth_parser)) { diff --git a/source4/scripting/swig/config.mk b/source4/scripting/swig/config.mk index 6c62d3ded8..970c6ed71a 100644 --- a/source4/scripting/swig/config.mk +++ b/source4/scripting/swig/config.mk @@ -14,7 +14,7 @@ swig: lib/tdb/swig/_tdb.$(SHLIBEXT) lib/ldb/swig/_ldb.$(SHLIBEXT) \ .SUFFIXES: _wrap.c .i .i_wrap.c: - swig -python $< + swig -I$(srcdir)/scripting/swig -python $< SWIG_INCLUDES = librpc/gen_ndr/samr.i librpc/gen_ndr/lsa.i librpc/gen_ndr/spoolss.i |