r18475: Start working on server code generator that uses libndr.
[samba.git] / source / pidl / lib / Parse / Pidl / Samba3 / ServerNDR.pm
1 ###################################################
2 # Samba3 server generator for IDL structures
3 # on top of Samba4 style NDR functions
4 # Copyright jelmer@samba.org 2005-2006
5 # released under the GNU GPL
6
7 package Parse::Pidl::Samba3::ServerNDR;
8
9 use strict;
10 use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference);
11 use Parse::Pidl::Util qw(has_property ParseExpr is_constant);
12 use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred);
13 use Parse::Pidl::Samba4 qw(DeclLong);
14
15 use vars qw($VERSION);
16 $VERSION = '0.01';
17
18 my $res;
19 my $res_hdr;
20 my $tabs = "";
21 sub indent() { $tabs.="\t"; }
22 sub deindent() { $tabs = substr($tabs, 1); }
23 sub pidl($) { $res .= $tabs.(shift)."\n"; }
24 sub pidl_hdr($) { $res_hdr .= (shift)."\n"; }
25 sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); }
26 sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); }
27 sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; }
28
29 sub ParseFunction($$)
30 {
31         my ($if,$fn) = @_;
32
33         pidl "static BOOL api_$fn->{NAME}(pipes_struct *p)";
34         pidl "{";
35         indent;
36
37         deindent;
38         pidl "}";
39         pidl "";
40 }
41
42 sub ParseInterface($)
43 {
44         my $if = shift;
45
46         my $uif = uc($if->{NAME});
47
48         pidl_hdr "#ifndef __SRV_$uif\__";
49         pidl_hdr "#define __SRV_$uif\__";
50         ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}});
51
52         pidl "";
53         pidl "/* Tables */";
54         pidl "static struct api_struct api_$if->{NAME}_cmds[] = ";
55         pidl "{";
56         indent;
57
58         foreach (@{$if->{FUNCTIONS}}) {
59                 pidl "{\"" . uc($_->{NAME}) . "\", DCERPC_" . uc($_->{NAME}) . ", api_$_->{NAME}},";
60         }
61
62         deindent;
63         pidl "};";
64
65         pidl "";
66
67         pidl_hdr "void $if->{NAME}_get_pipe_fns(struct api_struct **fns, int *n_fns);";
68         pidl "void $if->{NAME}_get_pipe_fns(struct api_struct **fns, int *n_fns)";
69         pidl "{";
70         indent;
71         pidl "*fns = api_$if->{NAME}_cmds;";
72         pidl "*n_fns = sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct);";
73         deindent;
74         pidl "}";
75         pidl "";
76
77         pidl_hdr "NTSTATUS rpc_netdfs_init(void);";
78         pidl "NTSTATUS rpc_netdfs_init(void)";
79         pidl "{";
80         pidl "\treturn rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, \"$if->{NAME}\", \"$if->{NAME}\", api_$if->{NAME}_cmds, sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct));";
81         pidl "}";
82
83         pidl_hdr "#endif /* __SRV_$uif\__ */";
84 }
85
86 sub Parse($$$)
87 {
88         my($ndr,$header,$ndr_header) = @_;
89
90         $res = "";
91         $res_hdr = "";
92
93         pidl "/*";
94         pidl " * Unix SMB/CIFS implementation.";
95         pidl " * server auto-generated by pidl. DO NOT MODIFY!";
96         pidl " */";
97         pidl "";
98         pidl "#include \"includes.h\"";
99         pidl "#include \"$header\"";
100         pidl_hdr "#include \"$ndr_header\"";
101         pidl "";
102         
103         foreach (@$ndr) {
104                 ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");
105         }
106
107         return ($res, $res_hdr);
108 }
109
110 1;