r356: Start of auto-generated client functions. Tridge can you take a look
authorTim Potter <tpot@samba.org>
Sun, 25 Apr 2004 22:58:18 +0000 (22:58 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:51:34 +0000 (12:51 -0500)
and tell me what you think?  Output does not compile yet.

source/build/pidl/clientfns.pm [new file with mode: 0644]
source/build/pidl/pidl.pl
source/script/build_idl.sh

diff --git a/source/build/pidl/clientfns.pm b/source/build/pidl/clientfns.pm
new file mode 100644 (file)
index 0000000..9f5f0ea
--- /dev/null
@@ -0,0 +1,127 @@
+###################################################
+# clientfs boilerplate generator
+# Copyright tpot@samba.org 2004
+# released under the GNU GPL
+
+package IdlClientFns;
+
+use strict;
+
+my($res);
+
+sub pidl($)
+{
+       $res .= shift;
+}
+
+use Data::Dumper;
+
+#####################################################################
+# produce boilerplate code for a interface
+sub Boilerplate_ClientFns($)
+{
+       my($interface) = shift;
+       my($data) = $interface->{DATA};
+       my $name = $interface->{NAME};
+
+       foreach my $d (@{$data}) {
+               if ($d->{TYPE} eq "FUNCTION") {
+
+                   pidl "/*\n";
+                   pidl Dumper($d);
+                   pidl "\n*/\n\n";
+
+                   pidl "$d->{RETURN_TYPE} $d->{NAME}(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx";
+                   
+                   my $count = 0, my $i = 0;
+
+                   foreach my $a (@{$d->{DATA}}) {
+                       $count++;
+                   }
+
+                   pidl ", ", if $count > 0;
+                   
+                   foreach my $a (@{$d->{DATA}}) {
+
+                       pidl "/* [";
+                       if ($a->{PROPERTIES}->{in}) {
+                           pidl "in";
+                           if ($a->{PROPERTIES}->{out} or
+                               $a->{PROPERTIES}->{ref}) {
+                               pidl ",";
+                           }
+                       }
+                       if ($a->{PROPERTIES}->{out}) {
+                           pidl "out";
+                           if ($a->{PROPERTIES}->{ref}) {
+                               pidl ",";
+                           }
+                       }
+                       if ($a->{PROPERTIES}->{ref}) {
+                           pidl "ref";
+                       }
+                       pidl "] */ ";
+
+                       pidl "struct ", if $a->{TYPE} eq "policy_handle";
+
+                       pidl "$a->{TYPE} ";
+                       if ($a->{PROPERTIES}->{out}) {
+                           pidl "*";
+                       }
+
+                       if (!$a->{PROPERTIES}->{ref}) {
+                           pidl "*", if $a->{POINTERS};
+                       }
+
+                       pidl "$a->{NAME}";
+                       
+                       $i++;
+
+                       pidl ", ", if $i < $count;
+                   }
+                   pidl ")\n";
+                   pidl "{\n";
+
+                   pidl "\tstruct $d->{NAME} r;\n";
+                   pidl "\tNTSTATUS status;\n";
+                   pidl "\n";
+
+                   foreach $a (@{$d->{DATA}}) {
+                       if ($a->{PROPERTIES}->{in}) {
+                           pidl "\tr.in.$a->{NAME} = $a->{NAME};\n";
+                       }
+                       if ($a->{PROPERTIES}->{out}) {
+                           pidl "\tr.out.$a->{NAME} = $a->{NAME};\n";
+                       }
+                   }               
+                   pidl "\n";
+
+                   pidl "\tstatus = dcerpc_$d->{NAME}(p, mem_ctx, &r);\n";
+                   pidl "\n";
+
+                   pidl "\treturn NT_STATUS_OK;\n";
+
+                   pidl "}\n\n";
+               }
+       }
+}
+
+#####################################################################
+# parse a parsed IDL structure back into an IDL file
+sub Parse($)
+{
+       my($idl) = shift;
+       $res = "/* dcerpc client functions generated by pidl */\n\n";
+
+       $res .= "#include \"includes.h\"\n\n";
+
+       foreach my $x (@{$idl}) {
+               if ($x->{TYPE} eq "INTERFACE") { 
+                       Boilerplate_ClientFns($x);
+               }
+       }
+
+       return $res;
+}
+
+1;
index 9b870d7263f07de6b120310cfe8a764851e1fa0a..c43d042b57a0c294452e3d0b6445fd75df569b2d 100755 (executable)
@@ -17,6 +17,7 @@ use idl;
 use dump;
 use header;
 use server;
+use clientfns;
 use parser;
 use eparser;
 use validator;
@@ -31,6 +32,7 @@ my($opt_header) = 0;
 my($opt_template) = 0;
 my($opt_server) = 0;
 my($opt_parser) = 0;
+my($opt_clientfns) = 0;
 my($opt_eparser) = 0;
 my($opt_keep) = 0;
 my($opt_output);
@@ -84,6 +86,7 @@ GetOptions (
            'server' => \$opt_server,
            'template' => \$opt_template,
            'parser' => \$opt_parser,
+           'clientfns' => \$opt_clientfns,
            'eparser' => \$opt_eparser,
            'diff' => \$opt_diff,
            'keep' => \$opt_keep
@@ -142,6 +145,11 @@ sub process_file($)
                IdlParser::Parse($pidl, $parser);
        }
        
+       if ($opt_clientfns) {
+               my($clientfns) = util::ChangeExtension($output, "_c.c");
+               util::FileSave($clientfns, IdlClientFns::Parse($pidl));
+       }
+
        if ($opt_eparser) {
                my($parser) = util::ChangeExtension($output, ".c");
                util::FileSave($parser, IdlEParser::Parse($pidl));
index a51a48761213f82cc4e9589d57d50449d5048cb5..51175d771a2e26f3c1c6e882669867a2c8429caa 100755 (executable)
@@ -4,7 +4,7 @@ FULLBUILD=$1
 
 [ -d librpc/gen_ndr ] || mkdir -p librpc/gen_ndr || exit 1
 
-PIDL="./build/pidl/pidl.pl --output librpc/gen_ndr/ndr_ --parse --header --parser --server"
+PIDL="./build/pidl/pidl.pl --output librpc/gen_ndr/ndr_ --parse --header --parser --server --clientfns"
 TABLES="./build/pidl/tables.pl --output librpc/gen_ndr/tables"
 
 if [ x$FULLBUILD = xFULL ]; then