1 ###################################################
2 # create C header files for an IDL structure
3 # Copyright tridge@samba.org 2000
4 # Copyright jelmer@samba.org 2005
5 # released under the GNU GPL
7 package Parse::Pidl::Samba::NDR::Header;
10 use Parse::Pidl::Typelist qw(mapType);
11 use Parse::Pidl::Util qw(has_property is_constant);
12 use Parse::Pidl::NDR qw(GetNextLevel GetPrevLevel);
13 use Parse::Pidl::Samba::NDR::Parser;
15 use vars qw($VERSION);
29 $res .="\t" foreach (1..$tab_depth);
33 #####################################################################
35 sub HeaderTypedefProto($)
39 my $tf = Parse::Pidl::Samba::NDR::Parser::get_typefamily($d->{DATA}{TYPE});
41 if (has_property($d, "gensize")) {
42 my $size_args = $tf->{SIZE_FN_ARGS}->($d);
43 pidl "size_t ndr_size_$d->{NAME}($size_args);\n";
46 return unless has_property($d, "public");
48 unless (has_property($d, "nopush")) {
49 pidl "NTSTATUS ndr_push_$d->{NAME}(struct ndr_push *ndr, int ndr_flags, " . $tf->{DECL}->($d, "push") . ");\n";
51 unless (has_property($d, "nopull")) {
52 pidl "NTSTATUS ndr_pull_$d->{NAME}(struct ndr_pull *ndr, int ndr_flags, " . $tf->{DECL}->($d, "pull") . ");\n";
54 unless (has_property($d, "noprint")) {
55 pidl "void ndr_print_$d->{NAME}(struct ndr_print *ndr, const char *name, " . $tf->{DECL}->($d, "print") . ");\n";
59 #####################################################################
60 # output prototypes for a IDL function
63 my ($interface,$fn) = @_;
64 my $name = $fn->{NAME};
66 pidl "void ndr_print_$name(struct ndr_print *ndr, const char *name, int flags, const struct $name *r);\n";
68 unless (has_property($fn, "noopnum")) {
69 pidl "NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r);\n";
70 pidl "struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r);\n";
73 return unless has_property($fn, "public");
75 pidl "NTSTATUS ndr_push_$name(struct ndr_push *ndr, int flags, const struct $name *r);\n";
76 pidl "NTSTATUS ndr_pull_$name(struct ndr_pull *ndr, int flags, struct $name *r);\n";
81 #####################################################################
82 # parse the interface definitions
83 sub HeaderInterface($)
85 my($interface) = shift;
87 if (defined $interface->{PROPERTIES}->{depends}) {
88 my @d = split / /, $interface->{PROPERTIES}->{depends};
90 pidl "#include \"librpc/gen_ndr/ndr_$i\.h\"\n";
96 pidl "#ifndef _HEADER_NDR_$interface->{NAME}\n";
97 pidl "#define _HEADER_NDR_$interface->{NAME}\n\n";
99 if (defined $interface->{PROPERTIES}->{uuid}) {
100 my $name = uc $interface->{NAME};
101 pidl "#define DCERPC_$name\_UUID " .
102 Parse::Pidl::Util::make_str(lc($interface->{PROPERTIES}->{uuid})) . "\n";
104 if(!defined $interface->{PROPERTIES}->{version}) { $interface->{PROPERTIES}->{version} = "0.0"; }
105 pidl "#define DCERPC_$name\_VERSION $interface->{PROPERTIES}->{version}\n";
107 pidl "#define DCERPC_$name\_NAME \"$interface->{NAME}\"\n";
109 if(!defined $interface->{PROPERTIES}->{helpstring}) { $interface->{PROPERTIES}->{helpstring} = "NULL"; }
110 pidl "#define DCERPC_$name\_HELPSTRING $interface->{PROPERTIES}->{helpstring}\n";
112 pidl "\nextern const struct dcerpc_interface_table dcerpc_table_$interface->{NAME};\n";
113 pidl "NTSTATUS dcerpc_server_$interface->{NAME}_init(void);\n\n";
116 foreach my $d (@{$interface->{DATA}}) {
117 next if $d->{TYPE} ne "FUNCTION";
118 next if has_property($d, "noopnum");
119 next if grep(/$d->{NAME}/,@{$interface->{INHERITED_FUNCTIONS}});
120 my $u_name = uc $d->{NAME};
121 pidl "#define DCERPC_$u_name (";
123 if (defined($interface->{BASE})) {
124 pidl "DCERPC_" . uc $interface->{BASE} . "_CALL_COUNT + ";
127 pidl sprintf("0x%02x", $count) . ")\n";
131 pidl "\n#define DCERPC_" . uc $interface->{NAME} . "_CALL_COUNT (";
133 if (defined($interface->{BASE})) {
134 pidl "DCERPC_" . uc $interface->{BASE} . "_CALL_COUNT + ";
139 foreach my $d (@{$interface->{DATA}}) {
140 next if ($d->{TYPE} ne "TYPEDEF");
141 HeaderTypedefProto($d);
144 foreach my $d (@{$interface->{DATA}}) {
145 next if ($d->{TYPE} ne "FUNCTION");
146 HeaderFnProto($interface, $d);
149 pidl "#endif /* _HEADER_NDR_$interface->{NAME} */\n";
152 #####################################################################
153 # parse a parsed IDL into a C header
156 my($idl,$basename) = @_;
160 pidl "/* header auto-generated by pidl */\n";
161 pidl "#include \"librpc/gen_ndr/$basename\.h\"\n\n";
163 foreach my $x (@{$idl}) {
164 ($x->{TYPE} eq "INTERFACE") && HeaderInterface($x);