summaryrefslogtreecommitdiff
path: root/source4/build/pidl/clientfns.pm
blob: 9f5f0ea8830296abbba263370cfa1a22b3d6ca28 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
###################################################
# clientfs boilerplate generator
# Copyright tpot@samba.org 2004
# released under the GNU GPL

package IdlClientFns;

use strict;

my($res);

sub pidl($)
{
	$res .= shift;
}

use Data::Dumper;

#####################################################################
# produce boilerplate code for a interface
sub Boilerplate_ClientFns($)
{
	my($interface) = shift;
	my($data) = $interface->{DATA};
	my $name = $interface->{NAME};

	foreach my $d (@{$data}) {
		if ($d->{TYPE} eq "FUNCTION") {

		    pidl "/*\n";
		    pidl Dumper($d);
		    pidl "\n*/\n\n";

		    pidl "$d->{RETURN_TYPE} $d->{NAME}(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx";
		    
		    my $count = 0, my $i = 0;

		    foreach my $a (@{$d->{DATA}}) {
			$count++;
		    }

		    pidl ", ", if $count > 0;
		    
		    foreach my $a (@{$d->{DATA}}) {

			pidl "/* [";
			if ($a->{PROPERTIES}->{in}) {
			    pidl "in";
			    if ($a->{PROPERTIES}->{out} or
				$a->{PROPERTIES}->{ref}) {
				pidl ",";
			    }
			}
			if ($a->{PROPERTIES}->{out}) {
			    pidl "out";
			    if ($a->{PROPERTIES}->{ref}) {
				pidl ",";
			    }
			}
			if ($a->{PROPERTIES}->{ref}) {
			    pidl "ref";
			}
			pidl "] */ ";

			pidl "struct ", if $a->{TYPE} eq "policy_handle";

			pidl "$a->{TYPE} ";
			if ($a->{PROPERTIES}->{out}) {
			    pidl "*";
			}

			if (!$a->{PROPERTIES}->{ref}) {
			    pidl "*", if $a->{POINTERS};
			}

			pidl "$a->{NAME}";
			
			$i++;

			pidl ", ", if $i < $count;
		    }
		    pidl ")\n";
		    pidl "{\n";

		    pidl "\tstruct $d->{NAME} r;\n";
		    pidl "\tNTSTATUS status;\n";
		    pidl "\n";

		    foreach $a (@{$d->{DATA}}) {
			if ($a->{PROPERTIES}->{in}) {
			    pidl "\tr.in.$a->{NAME} = $a->{NAME};\n";
			}
			if ($a->{PROPERTIES}->{out}) {
			    pidl "\tr.out.$a->{NAME} = $a->{NAME};\n";
			}
		    }		    
		    pidl "\n";

		    pidl "\tstatus = dcerpc_$d->{NAME}(p, mem_ctx, &r);\n";
		    pidl "\n";

		    pidl "\treturn NT_STATUS_OK;\n";

		    pidl "}\n\n";
		}
	}
}

#####################################################################
# parse a parsed IDL structure back into an IDL file
sub Parse($)
{
	my($idl) = shift;
	$res = "/* dcerpc client functions generated by pidl */\n\n";

	$res .= "#include \"includes.h\"\n\n";

	foreach my $x (@{$idl}) {
		if ($x->{TYPE} eq "INTERFACE") { 
			Boilerplate_ClientFns($x);
		}
	}

	return $res;
}

1;