pidl: merge multiple 'genpad' implementations into one.
[metze/samba/wip.git] / pidl / lib / Parse / Pidl / Samba4 / 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::Samba4::Template;
7
8 use vars qw($VERSION);
9 $VERSION = '0.01';
10
11 use Parse::Pidl::Util qw(genpad);
12
13 use strict;
14
15 my($res);
16
17 #####################################################################
18 # produce boilerplate code for a interface
19 sub Template($)
20 {
21         my($interface) = shift;
22         my($data) = $interface->{DATA};
23         my $name = $interface->{NAME};
24
25         $res .=
26 "/*
27    Unix SMB/CIFS implementation.
28
29    endpoint server for the $name pipe
30
31    Copyright (C) YOUR NAME HERE YEAR
32
33    This program is free software; you can redistribute it and/or modify
34    it under the terms of the GNU General Public License as published by
35    the Free Software Foundation; either version 3 of the License, or
36    (at your option) any later version.
37
38    This program is distributed in the hope that it will be useful,
39    but WITHOUT ANY WARRANTY; without even the implied warranty of
40    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
41    GNU General Public License for more details.
42
43    You should have received a copy of the GNU General Public License
44    along with this program.  If not, see <http://www.gnu.org/licenses/>.
45 */
46
47 #include \"includes.h\"
48 #include \"rpc_server/dcerpc_server.h\"
49 #include \"librpc/gen_ndr/ndr_$name.h\"
50 #include \"rpc_server/common/common.h\"
51
52 ";
53
54         foreach my $d (@{$data}) {
55                 if ($d->{TYPE} eq "FUNCTION") {
56                         my $fname = $d->{NAME};
57                         my $pad = genpad("static $d->{RETURN_TYPE} dcesrv_$fname");
58                         $res .=
59 "
60 /*
61   $fname
62 */
63
64 static $d->{RETURN_TYPE} dcesrv_$fname(struct dcesrv_call_state *dce_call,
65 $pad"."TALLOC_CTX *mem_ctx,
66 $pad"."struct $fname *r)
67 {
68 ";
69
70         if ($d->{RETURN_TYPE} eq "void") {
71                 $res .= "\tDCESRV_FAULT_VOID(DCERPC_FAULT_OP_RNG_ERROR);\n";
72         } else {
73                 $res .= "\tDCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);\n";
74         }
75
76         $res .= "}
77
78 ";
79                 }
80         }
81
82         $res .=
83 "
84 /* include the generated boilerplate */
85 #include \"librpc/gen_ndr/ndr_$name\_s.c\"
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;