pidl: add --template3 option to generate s3 server stubs.
[sfrench/samba-autobuild/.git] / pidl / lib / Parse / Pidl / Samba3 / Template.pm
1 ###################################################
2 # server template function generator
3 # Copyright tridge@samba.org 2003
4 # released under the GNU GPL
5
6 package Parse::Pidl::Samba3::Template;
7
8 use vars qw($VERSION);
9 $VERSION = '0.01';
10
11 use strict;
12
13 my($res);
14
15 sub genpad($)
16 {
17         my ($s) = @_;
18         my $nt = int((length($s)+1)/8);
19         my $lt = ($nt*8)-1;
20         my $ns = (length($s)-$lt);
21         return "\t"x($nt)." "x($ns);
22 }
23
24 #####################################################################
25 # produce boilerplate code for a interface
26 sub Template($)
27 {
28         my($interface) = shift;
29         my($data) = $interface->{DATA};
30         my $name = $interface->{NAME};
31
32         $res .=
33 "/*
34    Unix SMB/CIFS implementation.
35
36    endpoint server for the $name pipe
37
38    Copyright (C) YOUR NAME HERE YEAR
39
40    This program is free software; you can redistribute it and/or modify
41    it under the terms of the GNU General Public License as published by
42    the Free Software Foundation; either version 3 of the License, or
43    (at your option) any later version.
44
45    This program is distributed in the hope that it will be useful,
46    but WITHOUT ANY WARRANTY; without even the implied warranty of
47    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
48    GNU General Public License for more details.
49
50    You should have received a copy of the GNU General Public License
51    along with this program.  If not, see <http://www.gnu.org/licenses/>.
52 */
53
54 #include \"includes.h\"
55 #include \"ntdomain.h\"
56 #include \"../librpc/gen_ndr/srv_$name.h\"
57
58 ";
59
60         foreach my $d (@{$data}) {
61                 if ($d->{TYPE} eq "FUNCTION") {
62                         my $fname = $d->{NAME};
63                         my $pad = genpad("$d->{RETURN_TYPE} _$fname");
64                         $res .=
65 "
66 /****************************************************************
67  _$fname
68 ****************************************************************/
69
70 $d->{RETURN_TYPE} _$fname(struct pipes_struct *p,
71 $pad"."struct $fname *r)
72 {
73 ";
74
75         $res .= "\tp->fault_state = DCERPC_FAULT_OP_RNG_ERROR;\n";
76         if ($d->{RETURN_TYPE} eq "NTSTATUS") {
77                 $res .= "\treturn NT_STATUS_NOT_IMPLEMENTED;\n";
78         } elsif ($d->{RETURN_TYPE} eq "WERROR") {
79                 $res .= "\treturn WERR_NOT_SUPPORTED;\n";
80         }
81
82         $res .= "}
83
84 ";
85                 }
86         }
87 }
88
89
90 #####################################################################
91 # parse a parsed IDL structure back into an IDL file
92 sub Parse($)
93 {
94         my($idl) = shift;
95         $res = "";
96         foreach my $x (@{$idl}) {
97                 ($x->{TYPE} eq "INTERFACE") &&
98                     Template($x);
99         }
100         return $res;
101 }
102
103 1;