~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###################################################
 
2
# client calls generator
 
3
# Copyright tridge@samba.org 2003
 
4
# Copyright jelmer@samba.org 2005-2006
 
5
# released under the GNU GPL
 
6
 
 
7
package Parse::Pidl::Samba4::NDR::Client;
 
8
 
 
9
use Parse::Pidl::Samba4 qw(choose_header is_intree);
 
10
use Parse::Pidl::Util qw(has_property);
 
11
 
 
12
use vars qw($VERSION);
 
13
$VERSION = '0.01';
 
14
 
 
15
use strict;
 
16
 
 
17
my($res,$res_hdr);
 
18
 
 
19
sub ParseFunctionSend($$$)
 
20
{
 
21
        my ($interface, $fn, $name) = @_;
 
22
        my $uname = uc $name;
 
23
 
 
24
        my $proto = "struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)";
 
25
 
 
26
        $res_hdr .= "\n$proto;\n";
 
27
 
 
28
        $res .= "$proto\n{\n";
 
29
 
 
30
        if (has_property($fn, "todo")) {
 
31
                $res .= "\treturn NULL;\n";
 
32
        } else {
 
33
                $res .= "
 
34
        if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) {
 
35
                NDR_PRINT_IN_DEBUG($name, r);
 
36
        }
 
37
        
 
38
        return dcerpc_ndr_request_send(p, NULL, &ndr_table_$interface->{NAME}, NDR_$uname, mem_ctx, r);
 
39
";
 
40
        }
 
41
 
 
42
        $res .= "}\n\n";
 
43
}
 
44
 
 
45
sub ParseFunctionSync($$$)
 
46
{
 
47
        my ($interface, $fn, $name) = @_;
 
48
 
 
49
        my $proto = "NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)";
 
50
 
 
51
        $res_hdr .= "\n$proto;\n";
 
52
        $res .= "$proto\n{\n";
 
53
 
 
54
        if (has_property($fn, "todo")) {
 
55
                $res .= "\treturn NT_STATUS_NOT_IMPLEMENTED;\n";
 
56
        } else {
 
57
                $res .= "
 
58
        struct rpc_request *req;
 
59
        NTSTATUS status;
 
60
        
 
61
        req = dcerpc_$name\_send(p, mem_ctx, r);
 
62
        if (req == NULL) return NT_STATUS_NO_MEMORY;
 
63
 
 
64
        status = dcerpc_ndr_request_recv(req);
 
65
 
 
66
        if (NT_STATUS_IS_OK(status) && (p->conn->flags & DCERPC_DEBUG_PRINT_OUT)) {
 
67
                NDR_PRINT_OUT_DEBUG($name, r);          
 
68
        }
 
69
";
 
70
    
 
71
        if (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "NTSTATUS") {
 
72
             $res .= "\tif (NT_STATUS_IS_OK(status)) status = r->out.result;\n";
 
73
        }
 
74
        $res .= 
 
75
"
 
76
        return status;
 
77
";
 
78
        }
 
79
 
 
80
        $res .= "}\n\n";
 
81
}
 
82
 
 
83
#####################################################################
 
84
# parse a function
 
85
sub ParseFunction($$)
 
86
{
 
87
        my ($interface, $fn) = @_;
 
88
 
 
89
        ParseFunctionSend($interface, $fn, $fn->{NAME});
 
90
        ParseFunctionSync($interface, $fn, $fn->{NAME});
 
91
}
 
92
 
 
93
my %done;
 
94
 
 
95
#####################################################################
 
96
# parse the interface definitions
 
97
sub ParseInterface($)
 
98
{
 
99
        my($interface) = shift;
 
100
 
 
101
        $res_hdr .= "#ifndef _HEADER_RPC_$interface->{NAME}\n";
 
102
        $res_hdr .= "#define _HEADER_RPC_$interface->{NAME}\n\n";
 
103
 
 
104
        if (defined $interface->{PROPERTIES}->{uuid}) {
 
105
                $res_hdr .= "extern const struct ndr_interface_table ndr_table_$interface->{NAME};\n";
 
106
        }
 
107
 
 
108
        $res .= "/* $interface->{NAME} - client functions generated by pidl */\n\n";
 
109
 
 
110
        foreach my $fn (@{$interface->{FUNCTIONS}}) {
 
111
                next if not defined($fn->{OPNUM});
 
112
                next if defined($done{$fn->{NAME}});
 
113
                ParseFunction($interface, $fn);
 
114
                $done{$fn->{NAME}} = 1;
 
115
        }
 
116
 
 
117
        $res_hdr .= "#endif /* _HEADER_RPC_$interface->{NAME} */\n";
 
118
 
 
119
        return $res;
 
120
}
 
121
 
 
122
sub Parse($$$$)
 
123
{
 
124
        my($ndr,$header,$ndr_header,$client_header) = @_;
 
125
 
 
126
        $res = "";
 
127
        $res_hdr = "";
 
128
 
 
129
        $res .= "/* client functions auto-generated by pidl */\n";
 
130
        $res .= "\n";
 
131
        if (is_intree()) {
 
132
                $res .= "#include \"includes.h\"\n";
 
133
        } else {
 
134
                $res .= "#ifndef _GNU_SOURCE\n";
 
135
                $res .= "#define _GNU_SOURCE\n";
 
136
                $res .= "#endif\n";
 
137
                $res .= "#include <stdio.h>\n";
 
138
                $res .= "#include <stdbool.h>\n";
 
139
                $res .= "#include <stdlib.h>\n";
 
140
                $res .= "#include <stdint.h>\n";
 
141
                $res .= "#include <stdarg.h>\n";
 
142
                $res .= "#include <core/ntstatus.h>\n";
 
143
        }
 
144
        $res .= "#include \"$ndr_header\"\n";
 
145
        $res .= "#include \"$client_header\"\n";
 
146
        $res .= "\n";
 
147
 
 
148
        $res_hdr .= choose_header("librpc/rpc/dcerpc.h", "dcerpc.h")."\n";
 
149
        $res_hdr .= "#include \"$header\"\n";
 
150
 
 
151
        foreach my $x (@{$ndr}) {
 
152
                ($x->{TYPE} eq "INTERFACE") && ParseInterface($x);
 
153
        }
 
154
 
 
155
        return ($res,$res_hdr);
 
156
}
 
157
 
 
158
1;