summaryrefslogtreecommitdiff
path: root/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-12-24 22:11:44 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:47:42 -0500
commitebfbb2a7abe33e47af48d69164c37f4c24b7f8ed (patch)
tree259c6b4bd5c79ed9112a07cc7e671775813c8f59 /source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm
parente791dd73b98308b949f4ecfb91b5c87183b5de76 (diff)
downloadsamba-ebfbb2a7abe33e47af48d69164c37f4c24b7f8ed.tar.gz
samba-ebfbb2a7abe33e47af48d69164c37f4c24b7f8ed.tar.bz2
samba-ebfbb2a7abe33e47af48d69164c37f4c24b7f8ed.zip
r12463: Rename 'Samba' namespace to 'Samba4'
(This used to be commit f25358270d44a5642adbb85ecaa50b2e5730d7f0)
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm169
1 files changed, 169 insertions, 0 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm
new file mode 100644
index 0000000000..d55a7a12af
--- /dev/null
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm
@@ -0,0 +1,169 @@
+###################################################
+# create C header files for an IDL structure
+# Copyright tridge@samba.org 2000
+# Copyright jelmer@samba.org 2005
+# released under the GNU GPL
+
+package Parse::Pidl::Samba4::NDR::Header;
+
+use strict;
+use Parse::Pidl::Typelist qw(mapType);
+use Parse::Pidl::Util qw(has_property is_constant);
+use Parse::Pidl::NDR qw(GetNextLevel GetPrevLevel);
+use Parse::Pidl::Samba4::NDR::Parser;
+
+use vars qw($VERSION);
+$VERSION = '0.01';
+
+my($res);
+my($tab_depth);
+
+sub pidl ($)
+{
+ $res .= shift;
+}
+
+sub tabs()
+{
+ my $res = "";
+ $res .="\t" foreach (1..$tab_depth);
+ return $res;
+}
+
+#####################################################################
+# prototype a typedef
+sub HeaderTypedefProto($)
+{
+ my($d) = shift;
+
+ my $tf = Parse::Pidl::Samba4::NDR::Parser::get_typefamily($d->{DATA}{TYPE});
+
+ if (has_property($d, "gensize")) {
+ my $size_args = $tf->{SIZE_FN_ARGS}->($d);
+ pidl "size_t ndr_size_$d->{NAME}($size_args);\n";
+ }
+
+ return unless has_property($d, "public");
+
+ unless (has_property($d, "nopush")) {
+ pidl "NTSTATUS ndr_push_$d->{NAME}(struct ndr_push *ndr, int ndr_flags, " . $tf->{DECL}->($d, "push") . ");\n";
+ }
+ unless (has_property($d, "nopull")) {
+ pidl "NTSTATUS ndr_pull_$d->{NAME}(struct ndr_pull *ndr, int ndr_flags, " . $tf->{DECL}->($d, "pull") . ");\n";
+ }
+ unless (has_property($d, "noprint")) {
+ pidl "void ndr_print_$d->{NAME}(struct ndr_print *ndr, const char *name, " . $tf->{DECL}->($d, "print") . ");\n";
+ }
+}
+
+#####################################################################
+# output prototypes for a IDL function
+sub HeaderFnProto($$)
+{
+ my ($interface,$fn) = @_;
+ my $name = $fn->{NAME};
+
+ pidl "void ndr_print_$name(struct ndr_print *ndr, const char *name, int flags, const struct $name *r);\n";
+
+ unless (has_property($fn, "noopnum")) {
+ pidl "NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r);\n";
+ pidl "struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r);\n";
+ }
+
+ return unless has_property($fn, "public");
+
+ pidl "NTSTATUS ndr_push_$name(struct ndr_push *ndr, int flags, const struct $name *r);\n";
+ pidl "NTSTATUS ndr_pull_$name(struct ndr_pull *ndr, int flags, struct $name *r);\n";
+
+ pidl "\n";
+}
+
+#####################################################################
+# parse the interface definitions
+sub HeaderInterface($)
+{
+ my($interface) = shift;
+
+ if (defined $interface->{PROPERTIES}->{depends}) {
+ my @d = split / /, $interface->{PROPERTIES}->{depends};
+ foreach my $i (@d) {
+ pidl "#include \"librpc/gen_ndr/ndr_$i\.h\"\n";
+ }
+ }
+
+ my $count = 0;
+
+ pidl "#ifndef _HEADER_NDR_$interface->{NAME}\n";
+ pidl "#define _HEADER_NDR_$interface->{NAME}\n\n";
+
+ if (defined $interface->{PROPERTIES}->{uuid}) {
+ my $name = uc $interface->{NAME};
+ pidl "#define DCERPC_$name\_UUID " .
+ Parse::Pidl::Util::make_str(lc($interface->{PROPERTIES}->{uuid})) . "\n";
+
+ if(!defined $interface->{PROPERTIES}->{version}) { $interface->{PROPERTIES}->{version} = "0.0"; }
+ pidl "#define DCERPC_$name\_VERSION $interface->{PROPERTIES}->{version}\n";
+
+ pidl "#define DCERPC_$name\_NAME \"$interface->{NAME}\"\n";
+
+ if(!defined $interface->{PROPERTIES}->{helpstring}) { $interface->{PROPERTIES}->{helpstring} = "NULL"; }
+ pidl "#define DCERPC_$name\_HELPSTRING $interface->{PROPERTIES}->{helpstring}\n";
+
+ pidl "\nextern const struct dcerpc_interface_table dcerpc_table_$interface->{NAME};\n";
+ pidl "NTSTATUS dcerpc_server_$interface->{NAME}_init(void);\n\n";
+ }
+
+ foreach my $d (@{$interface->{DATA}}) {
+ next if $d->{TYPE} ne "FUNCTION";
+ next if has_property($d, "noopnum");
+ next if grep(/$d->{NAME}/,@{$interface->{INHERITED_FUNCTIONS}});
+ my $u_name = uc $d->{NAME};
+ pidl "#define DCERPC_$u_name (";
+
+ if (defined($interface->{BASE})) {
+ pidl "DCERPC_" . uc $interface->{BASE} . "_CALL_COUNT + ";
+ }
+
+ pidl sprintf("0x%02x", $count) . ")\n";
+ $count++;
+ }
+
+ pidl "\n#define DCERPC_" . uc $interface->{NAME} . "_CALL_COUNT (";
+
+ if (defined($interface->{BASE})) {
+ pidl "DCERPC_" . uc $interface->{BASE} . "_CALL_COUNT + ";
+ }
+
+ pidl "$count)\n\n";
+
+ foreach my $d (@{$interface->{DATA}}) {
+ next if ($d->{TYPE} ne "TYPEDEF");
+ HeaderTypedefProto($d);
+ }
+
+ foreach my $d (@{$interface->{DATA}}) {
+ next if ($d->{TYPE} ne "FUNCTION");
+ HeaderFnProto($interface, $d);
+ }
+
+ pidl "#endif /* _HEADER_NDR_$interface->{NAME} */\n";
+}
+
+#####################################################################
+# parse a parsed IDL into a C header
+sub Parse($$)
+{
+ my($idl,$basename) = @_;
+ $tab_depth = 0;
+
+ $res = "";
+ pidl "/* header auto-generated by pidl */\n";
+ pidl "#include \"librpc/gen_ndr/$basename\.h\"\n\n";
+
+ foreach my $x (@{$idl}) {
+ ($x->{TYPE} eq "INTERFACE") && HeaderInterface($x);
+ }
+ return $res;
+}
+
+1;