summaryrefslogtreecommitdiff
path: root/source4/build/pidl/server.pm
blob: 33c0e7f45237c821d0d70b52f8857537cb24ec98 (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


###################################################
# server boilerplate generator
# Copyright tridge@samba.org 2003
# released under the GNU GPL

package IdlServer;

use strict;

my($res);

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

#####################################################################
# produce boilerplate code for a interface
sub Boilerplate($)
{
	my($interface) = shift;
	my($data) = $interface->{DATA};
	my $count = 0;
	my $name = $interface->{NAME};
	my $uname = uc $name;

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

	if ($count == 0) {
		return;
	}

	pidl "static const dcesrv_dispatch_fn_t dispatch_table[] = {\n";
	foreach my $d (@{$data}) {
		if ($d->{TYPE} eq "FUNCTION") {
			pidl "\t(dcesrv_dispatch_fn_t)$d->{NAME},\n";
		}
	}
	pidl "\tNULL};\n\n";

	pidl "
static BOOL op_query_endpoint(const struct dcesrv_endpoint *ep)
{
	return dcesrv_table_query(&dcerpc_table_$name, ep);
}

static BOOL op_set_interface(struct dcesrv_state *dce, 
			     const char *uuid, uint32 if_version)
{
	return dcesrv_set_interface(dce, uuid, if_version, 
				    &dcerpc_table_$name, dispatch_table);
}

static NTSTATUS op_connect(struct dcesrv_state *dce)
{
	return NT_STATUS_OK;
}

static void op_disconnect(struct dcesrv_state *dce)
{
	/* nothing to do */
}

static int op_lookup_endpoints(TALLOC_CTX *mem_ctx, struct dcesrv_ep_iface **e)
{
	return dcesrv_lookup_endpoints(&dcerpc_table_$name, mem_ctx, e);
}

static const struct dcesrv_endpoint_ops $name\_ops = {
	op_query_endpoint,
	op_set_interface,
	op_connect,
	op_disconnect,
	op_lookup_endpoints
};

void rpc_$name\_init(void *v)
{
	struct dcesrv_context *dce = v;
	if (!dcesrv_endpoint_register(dce, &$name\_ops, 
				      &dcerpc_table_$name)) {
		DEBUG(1,(\"Failed to register rpcecho endpoint\\n\"));
	}
}
";
}


#####################################################################
# parse a parsed IDL structure back into an IDL file
sub Parse($)
{
	my($idl) = shift;
	$res = "/* dcerpc server boilerplate generated by pidl */\n\n";
	foreach my $x (@{$idl}) {
		($x->{TYPE} eq "INTERFACE") && 
		    Boilerplate($x);
	}
	return $res;
}

1;