summaryrefslogtreecommitdiff
path: root/source4/build/pidl/client.pm
blob: b3afb2573a3e59f67217472bedb03cb31c3034d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
###################################################
# client calls generator
# Copyright tridge@samba.org 2003
# released under the GNU GPL

package IdlClient;

use Data::Dumper;

my($res);

#####################################################################
# parse a function
sub ParseFunction($)
{
	my $fn = shift;
	my $name = $fn->{NAME};
	my $uname = uc $name;

	if ($fn->{RETURN_TYPE} eq "void") {
		$res .= "
NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
{
	return dcerpc_ndr_request(p, DCERPC_$uname, mem_ctx,
				  (ndr_push_fn_t) ndr_push_$name,
				  (ndr_pull_fn_t) ndr_pull_$name,
				  r);
}
";
	} else {
		$res .= "
NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
{
	NTSTATUS status;
	status = dcerpc_ndr_request(p, DCERPC_$uname, mem_ctx,
				    (ndr_push_fn_t) ndr_push_$name,
				    (ndr_pull_fn_t) ndr_pull_$name,
				    r);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}
	
	return r->out.result;
}
";
}
}

#####################################################################
# parse the interface definitions
sub ParseInterface($)
{
	my($interface) = shift;
	my($data) = $interface->{DATA};
	foreach my $d (@{$data}) {
		($d->{TYPE} eq "FUNCTION") && 
		    ParseFunction($d);
	}
}


#####################################################################
# parse a parsed IDL structure back into an IDL file
sub Parse($)
{
	my($idl) = shift;
	$res = "/* dcerpc client calls auto-generated by pidl */\n\n";
	$res .= "#include \"includes.h\"\n\n";
	foreach my $x (@{$idl}) {
		($x->{TYPE} eq "INTERFACE") && 
		    ParseInterface($x);
	}
	return $res;
}

1;