r9459: Move pidl up one level (to prevent too much nesting)
[samba.git] / source / pidl / Parse / Pidl / Samba / 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::Samba::Template;
7
8 use strict;
9
10 my($res);
11
12 #####################################################################
13 # produce boilerplate code for a interface
14 sub Template($)
15 {
16         my($interface) = shift;
17         my($data) = $interface->{DATA};
18         my $name = $interface->{NAME};
19
20         $res .= 
21 "/* 
22    Unix SMB/CIFS implementation.
23
24    endpoint server for the $name pipe
25
26    Copyright (C) YOUR NAME HERE YEAR
27    
28    This program is free software; you can redistribute it and/or modify
29    it under the terms of the GNU General Public License as published by
30    the Free Software Foundation; either version 2 of the License, or
31    (at your option) any later version.
32    
33    This program is distributed in the hope that it will be useful,
34    but WITHOUT ANY WARRANTY; without even the implied warranty of
35    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36    GNU General Public License for more details.
37    
38    You should have received a copy of the GNU General Public License
39    along with this program; if not, write to the Free Software
40    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
41 */
42
43 #include \"includes.h\"
44 #include \"rpc_server/dcerpc_server.h\"
45 #include \"librpc/gen_ndr/ndr_$name.h\"
46
47 ";
48
49         foreach my $d (@{$data}) {
50                 if ($d->{TYPE} eq "FUNCTION") {
51                         my $fname = $d->{NAME};
52                         $res .=
53 "
54 /* 
55   $fname 
56 */
57 static $d->{RETURN_TYPE} $fname(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
58                        struct $fname *r)
59 {
60         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
61 }
62
63 ";
64                 }
65         }
66
67         $res .= 
68 "
69 /* include the generated boilerplate */
70 #include \"librpc/gen_ndr/ndr_$name\_s.c\"
71 "
72 }
73
74
75 #####################################################################
76 # parse a parsed IDL structure back into an IDL file
77 sub Parse($)
78 {
79         my($idl) = shift;
80         $res = "";
81         foreach my $x (@{$idl}) {
82                 ($x->{TYPE} eq "INTERFACE") && 
83                     Template($x);
84         }
85         return $res;
86 }
87
88 1;