aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJörg Mayer <jmayer@loplof.de>2006-05-16 15:45:07 +0000
committerJörg Mayer <jmayer@loplof.de>2006-05-16 15:45:07 +0000
commitee13215eb98bae80aada1cc7d39898e067eb235b (patch)
treee7618570971cad97cead0d1f0022096a8e8a0f89 /tools
parent5857560a7f18ea557228e3e796418164d3058f67 (diff)
Add eol-style, update to current samba tree
svn path=/trunk/; revision=18171
Diffstat (limited to 'tools')
-rw-r--r--tools/pidl/lib/Parse/Pidl/Ethereal/NDR.pm8
-rw-r--r--tools/pidl/lib/Parse/Pidl/NDR.pm6
-rw-r--r--tools/pidl/lib/Parse/Pidl/ODL.pm15
-rw-r--r--tools/pidl/lib/Parse/Pidl/Samba3/Client.pm5
-rw-r--r--tools/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm123
-rw-r--r--tools/pidl/lib/Parse/Pidl/Samba4.pm41
-rw-r--r--tools/pidl/lib/Parse/Pidl/Samba4/EJS.pm71
-rw-r--r--tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm40
-rw-r--r--tools/pidl/lib/Parse/Pidl/Samba4/SWIG.pm195
-rw-r--r--tools/pidl/lib/Parse/Pidl/Typelist.pm176
-rwxr-xr-xtools/pidl/pidl44
11 files changed, 484 insertions, 240 deletions
diff --git a/tools/pidl/lib/Parse/Pidl/Ethereal/NDR.pm b/tools/pidl/lib/Parse/Pidl/Ethereal/NDR.pm
index 0b81536795..371c35b374 100644
--- a/tools/pidl/lib/Parse/Pidl/Ethereal/NDR.pm
+++ b/tools/pidl/lib/Parse/Pidl/Ethereal/NDR.pm
@@ -180,7 +180,7 @@ sub Bitmap($$$)
pidl_code "";
- pidl_code "if(parent_tree) {";
+ pidl_code "if (parent_tree) {";
indent;
pidl_code "item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, TRUE);";
pidl_code "tree = proto_item_add_subtree(item,ett_$ifname\_$name);";
@@ -224,7 +224,7 @@ sub Bitmap($$$)
pidl_code "";
}
- pidl_code "if(flags){";
+ pidl_code "if (flags) {";
pidl_code "\tproto_item_append_text(item, \"Unknown bitmap value 0x%x\", flags);";
pidl_code "}\n";
pidl_code "return offset;";
@@ -489,7 +489,7 @@ sub Struct($$$)
pidl_code "old_offset = offset;";
pidl_code "";
- pidl_code "if(parent_tree){";
+ pidl_code "if (parent_tree) {";
indent;
pidl_code "item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);";
pidl_code "tree = proto_item_add_subtree(item, ett_$ifname\_$name);";
@@ -553,7 +553,7 @@ sub Union($$$)
pidl_code "";
pidl_code "old_offset = offset;";
- pidl_code "if(parent_tree){";
+ pidl_code "if (parent_tree) {";
indent;
pidl_code "item = proto_tree_add_text(parent_tree, tvb, offset, -1, \"$name\");";
pidl_code "tree = proto_item_add_subtree(item, ett_$ifname\_$name);";
diff --git a/tools/pidl/lib/Parse/Pidl/NDR.pm b/tools/pidl/lib/Parse/Pidl/NDR.pm
index 1efd0694e5..3cbf416488 100644
--- a/tools/pidl/lib/Parse/Pidl/NDR.pm
+++ b/tools/pidl/lib/Parse/Pidl/NDR.pm
@@ -540,6 +540,11 @@ sub ParseFunction($$$)
my $e = ParseElement($x);
push (@{$e->{DIRECTION}}, "in") if (has_property($x, "in"));
push (@{$e->{DIRECTION}}, "out") if (has_property($x, "out"));
+
+ nonfatal($x, "`$e->{NAME}' is [out] argument but not a pointer")
+ if ($e->{LEVELS}[0]->{TYPE} ne "POINTER") and
+ grep(/out/, @{$e->{DIRECTION}});
+
push (@elements, $e);
}
@@ -787,6 +792,7 @@ my %property_list = (
"public" => ["FUNCTION", "TYPEDEF"],
"nopush" => ["FUNCTION", "TYPEDEF"],
"nopull" => ["FUNCTION", "TYPEDEF"],
+ "nosize" => ["FUNCTION", "TYPEDEF"],
"noprint" => ["FUNCTION", "TYPEDEF"],
"noejs" => ["FUNCTION", "TYPEDEF"],
diff --git a/tools/pidl/lib/Parse/Pidl/ODL.pm b/tools/pidl/lib/Parse/Pidl/ODL.pm
index 082deaea1d..b5d65b6239 100644
--- a/tools/pidl/lib/Parse/Pidl/ODL.pm
+++ b/tools/pidl/lib/Parse/Pidl/ODL.pm
@@ -15,11 +15,10 @@ $VERSION = '0.01';
# find an interface in an array of interfaces
sub get_interface($$)
{
- my($if) = shift;
- my($n) = shift;
+ my($if,$n) = @_;
- foreach(@{$if}) {
- if($_->{NAME} eq $n) { return $_; }
+ foreach(@$if) {
+ return $_ if($_->{NAME} eq $n);
}
return 0;
@@ -33,13 +32,17 @@ sub FunctionAddObjArgs($)
'NAME' => 'ORPCthis',
'POINTERS' => 0,
'PROPERTIES' => { 'in' => '1' },
- 'TYPE' => 'ORPCTHIS'
+ 'TYPE' => 'ORPCTHIS',
+ 'FILE' => $e->{FILE},
+ 'LINE' => $e->{LINE}
});
unshift(@{$e->{ELEMENTS}}, {
'NAME' => 'ORPCthat',
'POINTERS' => 0,
'PROPERTIES' => { 'out' => '1' },
- 'TYPE' => 'ORPCTHAT'
+ 'TYPE' => 'ORPCTHAT',
+ 'FILE' => $e->{FILE},
+ 'LINE' => $e->{LINE}
});
}
diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/Client.pm b/tools/pidl/lib/Parse/Pidl/Samba3/Client.pm
index 59f0341d02..9e26e9a21e 100644
--- a/tools/pidl/lib/Parse/Pidl/Samba3/Client.pm
+++ b/tools/pidl/lib/Parse/Pidl/Samba3/Client.pm
@@ -85,11 +85,6 @@ sub ParseFunction($$)
foreach my $e (@{$fn->{ELEMENTS}}) {
next unless (grep(/out/, @{$e->{DIRECTION}}));
- if ($e->{LEVELS}[0]->{TYPE} ne "POINTER") {
- warning($e->{ORIGINAL}, "First element not a pointer for [out] argument");
- next;
- }
-
CopyLevel($e, $e->{LEVELS}[1], $e->{NAME}, "r.$e->{NAME}");
}
diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/tools/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
new file mode 100644
index 0000000000..fa629e6101
--- /dev/null
+++ b/tools/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
@@ -0,0 +1,123 @@
+###################################################
+# Samba3 client generator for IDL structures
+# on top of Samba4 style NDR functions
+# Copyright jelmer@samba.org 2005-2006
+# released under the GNU GPL
+
+package Parse::Pidl::Samba3::ClientNDR;
+
+use strict;
+use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference);
+use Parse::Pidl::Util qw(has_property ParseExpr is_constant);
+use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred);
+use Parse::Pidl::Samba4 qw(DeclLong);
+
+use vars qw($VERSION);
+$VERSION = '0.01';
+
+my $res;
+my $res_hdr;
+my $tabs = "";
+sub indent() { $tabs.="\t"; }
+sub deindent() { $tabs = substr($tabs, 1); }
+sub pidl($) { $res .= $tabs.(shift)."\n"; }
+sub pidl_hdr($) { $res_hdr .= (shift)."\n"; }
+sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); }
+sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); }
+sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; }
+
+sub ParseFunction($$)
+{
+ my ($if,$fn) = @_;
+
+ my $inargs = "";
+ my $defargs = "";
+ my $uif = uc($if->{NAME});
+ my $ufn = "DCERPC_".uc($fn->{NAME});
+
+ foreach (@{$fn->{ELEMENTS}}) {
+ $defargs .= ", " . DeclLong($_);
+ }
+ fn_declare "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)";
+ pidl "{";
+ indent;
+ pidl "struct $fn->{NAME} r;";
+ pidl "NTSTATUS status;";
+ pidl "";
+ pidl "/* In parameters */";
+
+ foreach (@{$fn->{ELEMENTS}}) {
+ if (grep(/in/, @{$_->{DIRECTION}})) {
+ pidl "r.in.$_->{NAME} = $_->{NAME};";
+ }
+ }
+
+ pidl "status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, $ufn, &r, (ndr_pull_flags_fn_t)ndr_pull_$fn->{NAME}, (ndr_push_flags_fn_t)ndr_push_$fn->{NAME});";
+ pidl "if (NT_STATUS_IS_ERR(status)) {";
+ pidl "\treturn status;";
+ pidl "}";
+ pidl "";
+ pidl "/* Return variables */";
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ next unless (grep(/out/, @{$e->{DIRECTION}}));
+
+ fatal($e, "[out] argument is not a pointer") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER");
+
+ pidl "*$e->{NAME} = *r.out.$e->{NAME};";
+ }
+
+ pidl"";
+ pidl "/* Return result */";
+ if (not $fn->{RETURN_TYPE}) {
+ pidl "return NT_STATUS_OK;";
+ } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") {
+ pidl "return r.out.result;";
+ } elsif ($fn->{RETURN_TYPE} eq "WERROR") {
+ pidl "return werror_to_ntstatus(r.out.result);";
+ } else {
+ pidl "/* Sorry, don't know how to convert $fn->{RETURN_TYPE} to NTSTATUS */";
+ pidl "return NT_STATUS_OK;";
+ }
+
+ deindent;
+ pidl "}";
+ pidl "";
+}
+
+sub ParseInterface($)
+{
+ my $if = shift;
+
+ my $uif = uc($if->{NAME});
+
+ pidl_hdr "#ifndef __CLI_$uif\__";
+ pidl_hdr "#define __CLI_$uif\__";
+ ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}});
+ pidl_hdr "#endif /* __CLI_$uif\__ */";
+}
+
+sub Parse($$$)
+{
+ my($ndr,$header,$ndr_header) = @_;
+
+ $res = "";
+ $res_hdr = "";
+
+ pidl "/*";
+ pidl " * Unix SMB/CIFS implementation.";
+ pidl " * client auto-generated by pidl. DO NOT MODIFY!";
+ pidl " */";
+ pidl "";
+ pidl "#include \"includes.h\"";
+ pidl "#include \"$header\"";
+ pidl_hdr "#include \"$ndr_header\"";
+ pidl "";
+
+ foreach (@$ndr) {
+ ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");
+ }
+
+ return ($res, $res_hdr);
+}
+
+1;
diff --git a/tools/pidl/lib/Parse/Pidl/Samba4.pm b/tools/pidl/lib/Parse/Pidl/Samba4.pm
index 0a284aa85b..2d710f3eb6 100644
--- a/tools/pidl/lib/Parse/Pidl/Samba4.pm
+++ b/tools/pidl/lib/Parse/Pidl/Samba4.pm
@@ -7,9 +7,10 @@ package Parse::Pidl::Samba4;
require Exporter;
@ISA = qw(Exporter);
-@EXPORT = qw(is_intree choose_header);
+@EXPORT = qw(is_intree choose_header DeclLong);
-use Parse::Pidl::Util qw(has_property);
+use Parse::Pidl::Util qw(has_property is_constant);
+use Parse::Pidl::Typelist qw(mapType scalar_is_reference);
use strict;
use vars qw($VERSION);
@@ -29,4 +30,40 @@ sub choose_header($$)
return "#include <$out>";
}
+sub DeclLong($)
+{
+ my($element) = shift;
+ my $ret = "";
+
+ if (has_property($element, "represent_as")) {
+ $ret.=mapType($element->{PROPERTIES}->{represent_as})." ";
+ } else {
+ if (has_property($element, "charset")) {
+ $ret.="const char";
+ } else {
+ $ret.=mapType($element->{TYPE});
+ }
+
+ $ret.=" ";
+ my $numstar = $element->{ORIGINAL}->{POINTERS};
+ if ($numstar >= 1) {
+ $numstar-- if scalar_is_reference($element->{TYPE});
+ }
+ foreach (@{$element->{ORIGINAL}->{ARRAY_LEN}})
+ {
+ next if is_constant($_) and
+ not has_property($element, "charset");
+ $numstar++;
+ }
+ $ret.="*" foreach (1..$numstar);
+ }
+ $ret.=$element->{NAME};
+ foreach (@{$element->{ARRAY_LEN}}) {
+ next unless (is_constant($_) and not has_property($element, "charset"));
+ $ret.="[$_]";
+ }
+
+ return $ret;
+}
+
1;
diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/EJS.pm b/tools/pidl/lib/Parse/Pidl/Samba4/EJS.pm
index 550499a5f3..218b882323 100644
--- a/tools/pidl/lib/Parse/Pidl/Samba4/EJS.pm
+++ b/tools/pidl/lib/Parse/Pidl/Samba4/EJS.pm
@@ -117,6 +117,18 @@ sub get_value_of($)
}
#####################################################################
+# check that a variable we get from ParseExpr isn't a null pointer
+sub check_null_pointer($)
+{
+ my $size = shift;
+ if ($size =~ /^\*/) {
+ my $size2 = substr($size, 1);
+ pidl "if ($size2 == NULL) return NT_STATUS_INVALID_PARAMETER_MIX;";
+ }
+}
+
+
+#####################################################################
# work out is a parse function should be declared static or not
sub fn_declare($$)
{
@@ -194,8 +206,10 @@ sub EjsPullArray($$$$$)
# uint8 arrays are treated as data blobs
if ($nl->{TYPE} eq 'DATA' && $e->{TYPE} eq 'uint8') {
if (!$l->{IS_FIXED}) {
+ check_null_pointer($size);
pidl "EJS_ALLOC_N(ejs, $var, $size);";
}
+ check_null_pointer($length);
pidl "ejs_pull_array_uint8(ejs, v, $name, $var, $length);";
return;
}
@@ -408,15 +422,13 @@ sub EjsPullFunction($)
# on the non-array elements
foreach my $e (@{$d->{ELEMENTS}}) {
next unless (grep(/in/, @{$e->{DIRECTION}}));
- next if (has_property($e, "length_is") ||
- has_property($e, "size_is"));
+ next if (has_property($e, "length_is") || has_property($e, "size_is"));
EjsPullElementTop($e, $env);
}
foreach my $e (@{$d->{ELEMENTS}}) {
next unless (grep(/in/, @{$e->{DIRECTION}}));
- next unless (has_property($e, "length_is") ||
- has_property($e, "size_is"));
+ next unless (has_property($e, "length_is") || has_property($e, "size_is"));
EjsPullElementTop($e, $env);
}
@@ -492,6 +504,7 @@ sub EjsPushArray($$$$$)
}
# uint8 arrays are treated as data blobs
if ($nl->{TYPE} eq 'DATA' && $e->{TYPE} eq 'uint8') {
+ check_null_pointer($length);
pidl "ejs_push_array_uint8(ejs, v, $name, $var, $length);";
return;
}
@@ -745,7 +758,7 @@ sub EjsInterface($$)
foreach my $d (@{$interface->{FUNCTIONS}}) {
next if not defined($d->{OPNUM});
- next if Parse::Pidl::Util::has_property($d, "noejs");
+ next if has_property($d, "noejs");
EjsPullFunction($d);
EjsPushFunction($d);
@@ -831,14 +844,17 @@ sub Parse($$)
sub NeededFunction($$)
{
my ($fn,$needed) = @_;
+
$needed->{"pull_$fn->{NAME}"} = 1;
$needed->{"push_$fn->{NAME}"} = 1;
- foreach my $e (@{$fn->{ELEMENTS}}) {
- if (grep (/in/, @{$e->{DIRECTION}})) {
- $needed->{"pull_$e->{TYPE}"} = 1;
+
+ foreach (@{$fn->{ELEMENTS}}) {
+ next if (has_property($_, "subcontext")); #FIXME: Support subcontexts
+ if (grep(/in/, @{$_->{DIRECTION}})) {
+ $needed->{"pull_$_->{TYPE}"} = 1;
}
- if (grep (/out/, @{$e->{DIRECTION}})) {
- $needed->{"push_$e->{TYPE}"} = 1;
+ if (grep(/out/, @{$_->{DIRECTION}})) {
+ $needed->{"push_$_->{TYPE}"} = 1;
}
}
}
@@ -846,20 +862,22 @@ sub NeededFunction($$)
sub NeededTypedef($$)
{
my ($t,$needed) = @_;
- if (Parse::Pidl::Util::has_property($t, "public")) {
- $needed->{"pull_$t->{NAME}"} = not Parse::Pidl::Util::has_property($t, "noejs");
- $needed->{"push_$t->{NAME}"} = not Parse::Pidl::Util::has_property($t, "noejs");
- }
- if ($t->{DATA}->{TYPE} ne "STRUCT" &&
- $t->{DATA}->{TYPE} ne "UNION") {
- return;
+
+ if (has_property($t, "public")) {
+ $needed->{"pull_$t->{NAME}"} = not has_property($t, "noejs");
+ $needed->{"push_$t->{NAME}"} = not has_property($t, "noejs");
}
- for my $e (@{$t->{DATA}->{ELEMENTS}}) {
- if ($needed->{"pull_$t->{NAME}"}) {
- $needed->{"pull_$e->{TYPE}"} = 1;
+
+ return if (($t->{DATA}->{TYPE} ne "STRUCT") and
+ ($t->{DATA}->{TYPE} ne "UNION"));
+
+ foreach (@{$t->{DATA}->{ELEMENTS}}) {
+ next if (has_property($_, "subcontext")); #FIXME: Support subcontexts
+ unless (defined($needed->{"pull_$_->{TYPE}"})) {
+ $needed->{"pull_$_->{TYPE}"} = $needed->{"pull_$t->{NAME}"};
}
- if ($needed->{"push_$t->{NAME}"}) {
- $needed->{"push_$e->{TYPE}"} = 1;
+ unless (defined($needed->{"push_$_->{TYPE}"})) {
+ $needed->{"push_$_->{TYPE}"} = $needed->{"push_$t->{NAME}"};
}
}
}
@@ -869,12 +887,9 @@ sub NeededTypedef($$)
sub NeededInterface($$)
{
my ($interface,$needed) = @_;
- foreach my $d (@{$interface->{FUNCTIONS}}) {
- NeededFunction($d, $needed);
- }
- foreach my $d (reverse @{$interface->{TYPES}}) {
- NeededTypedef($d, $needed);
- }
+
+ NeededFunction($_, $needed) foreach (@{$interface->{FUNCTIONS}});
+ NeededTypedef($_, $needed) foreach (reverse @{$interface->{TYPES}});
}
1;
diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
index 38e3268356..b7ae526e68 100644
--- a/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
+++ b/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
@@ -194,9 +194,14 @@ sub check_null_pointer_void($)
#####################################################################
# declare a function public or static, depending on its attributes
-sub fn_declare($$)
+sub fn_declare($$$)
{
- my ($fn,$decl) = @_;
+ my ($type,$fn,$decl) = @_;
+
+ if (has_property($fn, "no$type")) {
+ pidl_hdr "$decl;";
+ return 0;
+ }
if (has_property($fn, "public")) {
pidl_hdr "$decl;";
@@ -204,6 +209,8 @@ sub fn_declare($$)
} else {
pidl "static $decl";
}
+
+ return 1;
}
###################################################################
@@ -1814,7 +1821,7 @@ sub ParseTypedefPush($)
my($e) = shift;
my $args = $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e,"push");
- fn_declare($e, "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, $args)");
+ fn_declare("push", $e, "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, $args)") or return;
pidl "{";
indent;
@@ -1833,7 +1840,7 @@ sub ParseTypedefPull($)
my $args = $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e,"pull");
- fn_declare($e, "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, $args)");
+ fn_declare("pull", $e, "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, $args)") or return;
pidl "{";
indent;
@@ -1852,8 +1859,11 @@ sub ParseTypedefPrint($)
my $args = $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e,"print");
- pidl "_PUBLIC_ void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args)";
pidl_hdr "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args);";
+
+ return if (has_property($e, "noprint"));
+
+ pidl "_PUBLIC_ void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args)";
pidl "{";
indent;
$typefamily{$e->{DATA}->{TYPE}}->{PRINT_FN_BODY}->($e->{DATA}, $e->{NAME});
@@ -1871,7 +1881,7 @@ sub ParseTypedefNdrSize($)
my $tf = $typefamily{$t->{DATA}->{TYPE}};
my $args = $tf->{SIZE_FN_ARGS}->($t);
- fn_declare($t, "size_t ndr_size_$t->{NAME}($args)");
+ fn_declare("size", $t, "size_t ndr_size_$t->{NAME}($args)") or return;
pidl "{";
indent;
@@ -1887,10 +1897,11 @@ sub ParseFunctionPrint($)
{
my($fn) = shift;
+ pidl_hdr "void ndr_print_$fn->{NAME}(struct ndr_print *ndr, const char *name, int flags, const struct $fn->{NAME} *r);";
+
return if has_property($fn, "noprint");
pidl "_PUBLIC_ void ndr_print_$fn->{NAME}(struct ndr_print *ndr, const char *name, int flags, const struct $fn->{NAME} *r)";
- pidl_hdr "void ndr_print_$fn->{NAME}(struct ndr_print *ndr, const char *name, int flags, const struct $fn->{NAME} *r);";
pidl "{";
indent;
@@ -1952,9 +1963,9 @@ sub ParseFunctionPush($)
{
my($fn) = shift;
- return if has_property($fn, "nopush");
+ fn_declare("push", $fn, "NTSTATUS ndr_push_$fn->{NAME}(struct ndr_push *ndr, int flags, const struct $fn->{NAME} *r)") or return;
- fn_declare($fn, "NTSTATUS ndr_push_$fn->{NAME}(struct ndr_push *ndr, int flags, const struct $fn->{NAME} *r)");
+ return if has_property($fn, "nopush");
pidl "{";
indent;
@@ -2032,10 +2043,9 @@ sub ParseFunctionPull($)
{
my($fn) = shift;
- return if has_property($fn, "nopull");
-
# pull function args
- fn_declare($fn, "NTSTATUS ndr_pull_$fn->{NAME}(struct ndr_pull *ndr, int flags, struct $fn->{NAME} *r)");
+ fn_declare("pull", $fn, "NTSTATUS ndr_pull_$fn->{NAME}(struct ndr_pull *ndr, int flags, struct $fn->{NAME} *r)") or return;
+
pidl "{";
indent;
@@ -2404,9 +2414,9 @@ sub NeededTypedef($$)
{
my ($t,$needed) = @_;
if (has_property($t, "public")) {
- $needed->{"pull_$t->{NAME}"} = not has_property($t, "nopull");
- $needed->{"push_$t->{NAME}"} = not has_property($t, "nopush");
- $needed->{"print_$t->{NAME}"} = not has_property($t, "noprint");
+ $needed->{"pull_$t->{NAME}"} = 1;
+ $needed->{"push_$t->{NAME}"} = 1;
+ $needed->{"print_$t->{NAME}"} = 1;
}
if ($t->{DATA}->{TYPE} eq "STRUCT" or $t->{DATA}->{TYPE} eq "UNION") {
diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/SWIG.pm b/tools/pidl/lib/Parse/Pidl/Samba4/SWIG.pm
index b6c268edeb..57ff007d1b 100644
--- a/tools/pidl/lib/Parse/Pidl/Samba4/SWIG.pm
+++ b/tools/pidl/lib/Parse/Pidl/Samba4/SWIG.pm
@@ -1,79 +1,176 @@
###################################################
# Samba4 parser generator for swig wrappers
# Copyright tpot@samba.org 2004,2005
+# Copyright jelmer@samba.org 2006
# released under the GNU GPL
package Parse::Pidl::Samba4::SWIG;
use vars qw($VERSION);
+use Parse::Pidl::Samba4 qw(DeclLong);
+use Parse::Pidl::Typelist qw(mapType);
+use Parse::Pidl::Util qw(has_property);
$VERSION = '0.01';
use strict;
+my $ret = "";
+my $tabs = "";
+
sub pidl($)
{
- print OUT shift;
+ my $p = shift;
+ $ret .= $tabs. $p . "\n";
}
-#####################################################################
-# rewrite autogenerated header file
-sub RewriteHeader($$$)
-{
- my($idl) = shift;
- my($input) = shift;
- my($output) = shift;
-
- open(IN, "<$input") || die "can't open $input for reading";
- open(OUT, ">$output") || die "can't open $output for writing";
-
- pidl "%{\n";
- pidl "#define data_in in\n";
- pidl "#define data_out out\n";
- pidl "%}\n\n";
-
- while(<IN>) {
+sub indent() { $tabs.="\t"; }
+sub deindent() { $tabs = substr($tabs,0,-1); }
- # Rename dom_sid2 to dom_sid as we don't care about the difference
- # for the swig wrappers.
-
- s/dom_sid2/dom_sid/g;
-
- # Copy structure and union definitions
+sub IgnoreInterface($$)
+{
+ my ($basename,$if) = @_;
- if (/^(struct|union) .*? {$/ .. /^\};$/) {
- s/\} (in|out);/\} data_$1;/; # "in" is a Python keyword
- pidl $_;
- next;
+ foreach (@{$if->{TYPES}}) {
+ next unless (has_property($_, "public"));
+ pidl "\%types($_->{NAME});";
}
+}
- # Copy dcerpc functions
-
- pidl $_ if /^NTSTATUS dcerpc_.*?\(struct dcerpc_pipe/;
-
- # Copy interface definitions
+sub ParseInterface($$)
+{
+ my ($basename,$if) = @_;
+
+ pidl "\%inline {";
+ pidl "struct $if->{NAME} { struct dcerpc_pipe *pipe; };";
+ pidl "}";
+ pidl "";
+ pidl "\%extend $if->{NAME} {";
+ indent();
+ pidl "$if->{NAME} (const char *binding, struct cli_credentials *cred = NULL, TALLOC_CTX *mem_ctx = NULL, struct event_context *event = NULL)";
+ pidl "{";
+ indent;
+ pidl "struct $if->{NAME} *ret = talloc(mem_ctx, struct $if->{NAME});";
+ pidl "NTSTATUS status;";
+ pidl "";
+ pidl "status = dcerpc_pipe_connect(mem_ctx, &ret->pipe, binding, &dcerpc_table_$if->{NAME}, cred, event);";
+ pidl "if (NT_STATUS_IS_ERR(status)) {";
+ pidl "\tntstatus_exception(status);";
+ pidl "\treturn NULL;";
+ pidl "}";
+ pidl "";
+ pidl "return ret;";
+ deindent;
+ pidl "}";
+ pidl "";
+ pidl "~$if->{NAME}() {";
+ pidl "\ttalloc_free(self);";
+ pidl "}";
+ pidl "";
+
+ foreach my $fn (@{$if->{FUNCTIONS}}) {
+ pidl "/* $fn->{NAME} */";
+ my $args = "";
+ foreach (@{$fn->{ELEMENTS}}) {
+ $args .= DeclLong($_) . ", ";
+ }
+ my $name = $fn->{NAME};
+ $name =~ s/^$if->{NAME}_//g;
+ $name =~ s/^$basename\_//g;
+ $args .= "TALLOC_CTX *mem_ctx = NULL";
+ pidl mapType($fn->{RETURN_TYPE}) . " $name($args)";
+ pidl "{";
+ indent;
+ pidl "struct $fn->{NAME} r;";
+ pidl "NTSTATUS status;";
+ pidl "";
+ pidl "/* Fill r structure */";
+
+ foreach (@{$fn->{ELEMENTS}}) {
+ if (grep(/in/, @{$_->{DIRECTION}})) {
+ pidl "r.in.$_->{NAME} = $_->{NAME};";
+ }
+ }
+
+ pidl "";
+ pidl "status = dcerpc_$fn->{NAME}(self->pipe, mem_ctx, &r);";
+ pidl "if (NT_STATUS_IS_ERR(status)) {";
+ pidl "\tntstatus_exception(status);";
+ if (defined($fn->{RETURN_TYPE})) {
+ pidl "\treturn r.out.result;";
+ } else {
+ pidl "\treturn;";
+ }
+ pidl "}";
+ pidl "";
+ pidl "/* Set out arguments */";
+ foreach (@{$fn->{ELEMENTS}}) {
+ next unless (grep(/out/, @{$_->{DIRECTION}}));
+
+ pidl ("/* FIXME: $_->{NAME} [out] argument is not a pointer */") if ($_->{LEVELS}[0]->{TYPE} ne "POINTER");
+
+ pidl "*$_->{NAME} = *r.out.$_->{NAME};";
+ }
+
+ if (defined($fn->{RETURN_TYPE})) {
+ pidl "return r.out.result;";
+ }
+ deindent;
+ pidl "}";
+ pidl "";
+ }
- pidl $_
- if /^\#define DCERPC_.*?_UUID/ or /^\#define DCERPC_.*?_VERSION/;
- }
+ deindent();
+ pidl "};";
+ pidl "";
- close(OUT);
+ foreach (@{$if->{TYPES}}) {
+ pidl "/* $_->{NAME} */";
+ }
+
+ pidl "";
}
-#####################################################################
-# rewrite autogenerated header file
-sub RewriteC($$$)
+sub Parse($$$$)
{
- my($idl) = shift;
- my($input) = shift;
- my($output) = shift;
+ my($ndr,$basename,$header,$gen_header) = @_;
+
+ $ret = "";
+
+ pidl "/* This file is autogenerated by pidl. DO NOT EDIT */";
+
+ pidl "\%module $basename";
+
+ pidl "";
+
+ pidl "\%{";
+ pidl "#include \"includes.h\"";
+ pidl "#include \"auth/credentials/credentials.h\"";
+ pidl "#include \"$header\"";
+ pidl "#include \"$gen_header\"";
+ pidl "%}";
+ pidl "\%import \"samba.i\"";
+ pidl "";
+ pidl "\%inline {";
+ pidl "void ntstatus_exception(NTSTATUS status)";
+ pidl "{";
+ pidl "\t/* FIXME */";
+ pidl "}";
+ pidl "}";
+ pidl "";
+ foreach (@$ndr) {
+ IgnoreInterface($basename, $_) if ($_->{TYPE} eq "INTERFACE");
+ }
+ pidl "";
- open(IN, "<$input") || die "can't open $input for reading";
- open(OUT, ">>$output") || die "can't open $output for writing";
-
- while(<IN>) {
- }
+ pidl "";
- close(OUT);
+ foreach (@$ndr) {
+ ParseInterface($basename, $_) if ($_->{TYPE} eq "INTERFACE");
+ }
+ #FIXME: Foreach ref pointer, set NONNULL
+ #FIXME: Foreach unique/full pointer, set MAYBENULL
+ #FIXME: Foreach [out] parameter, set OUTPARAM
+ return $ret;
}
1;
diff --git a/tools/pidl/lib/Parse/Pidl/Typelist.pm b/tools/pidl/lib/Parse/Pidl/Typelist.pm
index b54badaeb6..ff8f18ee48 100644
--- a/tools/pidl/lib/Parse/Pidl/Typelist.pm
+++ b/tools/pidl/lib/Parse/Pidl/Typelist.pm
@@ -7,7 +7,7 @@ package Parse::Pidl::Typelist;
require Exporter;
@ISA = qw(Exporter);
-@EXPORT_OK = qw(hasType getType mapType);
+@EXPORT_OK = qw(hasType getType mapType scalar_is_reference);
use vars qw($VERSION);
$VERSION = '0.01';
@@ -16,132 +16,61 @@ use strict;
my %typedefs = ();
+my @reference_scalars = (
+ "string", "string_array", "nbt_string",
+ "wrepl_nbt_name", "ipv4address"
+);
+
# a list of known scalar types
-my $scalars = {
+my %scalars = (
# 0 byte types
- "void" => {
- C_TYPE => "void",
- IS_REFERENCE => 0,
- },
+ "void" => "void",
# 1 byte types
- "char" => {
- C_TYPE => "char",
- IS_REFERENCE => 0,
- },
- "int8" => {
- C_TYPE => "int8_t",
- IS_REFERENCE => 0,
- },
- "uint8" => {
- C_TYPE => "uint8_t",
- IS_REFERENCE => 0,
- },
+ "char" => "char",
+ "int8" => "int8_t",
+ "uint8" => "uint8_t",
# 2 byte types
- "int16" => {
- C_TYPE => "int16_t",
- IS_REFERENCE => 0,
- },
- "uint16" => { C_TYPE => "uint16_t",
- IS_REFERENCE => 0,
- },
+ "int16" => "int16_t",
+ "uint16" => "uint16_t",
# 4 byte types
- "int32" => {
- C_TYPE => "int32_t",
- IS_REFERENCE => 0,
- },
- "uint32" => { C_TYPE => "uint32_t",
- IS_REFERENCE => 0,
- },
+ "int32" => "int32_t",
+ "uint32" => "uint32_t",
# 8 byte types
- "hyper" => {
- C_TYPE => "uint64_t",
- IS_REFERENCE => 0,
- },
- "dlong" => {
- C_TYPE => "int64_t",
- IS_REFERENCE => 0,
- },
- "udlong" => {
- C_TYPE => "uint64_t",
- IS_REFERENCE => 0,
- },
- "udlongr" => {
- C_TYPE => "uint64_t",
- IS_REFERENCE => 0,
- },
+ "hyper" => "uint64_t",
+ "dlong" => "int64_t",
+ "udlong" => "uint64_t",
+ "udlongr" => "uint64_t",
+
# assume its a 8 byte type, but cope with either
- "pointer" => {
- C_TYPE => "void*",
- IS_REFERENCE => 0,
- },
+ "pointer" => "void*",
# DATA_BLOB types
- "DATA_BLOB" => {
- C_TYPE => "DATA_BLOB",
- IS_REFERENCE => 0,
- },
+ "DATA_BLOB" => "DATA_BLOB",
# string types
- "string" => {
- C_TYPE => "const char *",
- IS_REFERENCE => 1,
- },
- "string_array" => {
- C_TYPE => "const char **",
- IS_REFERENCE => 1,
- },
+ "string" => "const char *",
+ "string_array" => "const char **",
# time types
- "time_t" => {
- C_TYPE => "time_t",
- IS_REFERENCE => 0,
- },
- "NTTIME" => {
- C_TYPE => "NTTIME",
- IS_REFERENCE => 0,
- },
- "NTTIME_1sec" => {
- C_TYPE => "NTTIME",
- IS_REFERENCE => 0,
- },
- "NTTIME_hyper" => {
- C_TYPE => "NTTIME",
- IS_REFERENCE => 0,
- },
-
+ "time_t" => "time_t",
+ "NTTIME" => "NTTIME",
+ "NTTIME_1sec" => "NTTIME",
+ "NTTIME_hyper" => "NTTIME",
# error code types
- "WERROR" => {
- C_TYPE => "WERROR",
- IS_REFERENCE => 0,
- },
- "NTSTATUS" => {
- C_TYPE => "NTSTATUS",
- IS_REFERENCE => 0,
- },
- "COMRESULT" => {
- C_TYPE => "COMRESULT",
- IS_REFERENCE => 0,
- },
+ "WERROR" => "WERROR",
+ "NTSTATUS" => "NTSTATUS",
+ "COMRESULT" => "COMRESULT",
# special types
- "nbt_string" => {
- C_TYPE => "const char *",
- IS_REFERENCE => 1,
- },
- "wrepl_nbt_name"=> {
- C_TYPE => "struct nbt_name *",
- IS_REFERENCE => 1,
- },
- "ipv4address" => {
- C_TYPE => "const char *",
- IS_REFERENCE => 1,
- }
-};
+ "nbt_string" => "const char *",
+ "wrepl_nbt_name"=> "struct nbt_name *",
+ "ipv4address" => "const char *",
+);
# map from a IDL type to a C header type
sub mapScalarType($)
@@ -150,7 +79,7 @@ sub mapScalarType($)
# it's a bug when a type is not in the list
# of known scalars or has no mapping
- return $typedefs{$name}->{DATA}->{C_TYPE} if defined($typedefs{$name}) and defined($typedefs{$name}->{DATA}->{C_TYPE});
+ return $scalars{$name} if defined($scalars{$name});
die("Unknown scalar type $name");
}
@@ -170,8 +99,7 @@ sub getType($)
sub typeIs($$)
{
- my $t = shift;
- my $tt = shift;
+ my ($t,$tt) = @_;
return 1 if (hasType($t) and getType($t)->{DATA}->{TYPE} eq $tt);
return 0;
@@ -200,25 +128,27 @@ sub is_scalar($)
sub scalar_is_reference($)
{
my $name = shift;
-
- return $scalars->{$name}{IS_REFERENCE} if defined($scalars->{$name}) and defined($scalars->{$name}{IS_REFERENCE});
+
+ return 1 if (grep(/^$name$/, @reference_scalars));
return 0;
}
sub RegisterScalars()
{
- foreach my $k (keys %{$scalars}) {
- $typedefs{$k} = {
- NAME => $k,
+ foreach (keys %scalars) {
+ addType({
+ NAME => $_,
TYPE => "TYPEDEF",
- DATA => $scalars->{$k}
- };
- $typedefs{$k}->{DATA}->{TYPE} = "SCALAR";
- $typedefs{$k}->{DATA}->{NAME} = $k;
+ DATA => {
+ TYPE => "SCALAR",
+ NAME => $_
+ }
+ }
+ );
}
}
-my $aliases = {
+my %aliases = (
"DWORD" => "uint32",
"int" => "int32",
"WORD" => "uint16",
@@ -227,12 +157,12 @@ my $aliases = {
"short" => "int16",
"HYPER_T" => "hyper",
"HRESULT" => "COMRESULT",
-};
+);
sub RegisterAliases()
{
- foreach my $k (keys %{$aliases}) {
- $typedefs{$k} = $typedefs{$aliases->{$k}};
+ foreach (keys %aliases) {
+ $typedefs{$_} = $typedefs{$aliases{$_}};
}
}
@@ -264,7 +194,7 @@ sub bitmap_type_fn($)
sub mapType($)
{
my $t = shift;
- die("Undef passed to mapType") unless defined($t);
+ return "void" unless defined($t);
my $dt;
unless ($dt or ($dt = getType($t))) {
diff --git a/tools/pidl/pidl b/tools/pidl/pidl
index 314ab7c60b..a7838791b5 100755
--- a/tools/pidl/pidl
+++ b/tools/pidl/pidl
@@ -17,7 +17,7 @@ pidl - An IDL compiler written in Perl
pidl --help
-pidl [--outputdir[=OUTNAME]] [--parse-idl-tree] [--dump-idl-tree] [--dump-ndr-tree] [--header[=OUTPUT]] [--ejs[=OUTPUT]] [--swig[=OUTPUT]] [--uint-enums] [--ndr-parser[=OUTPUT]] [--client] [--server] [--dcom-proxy] [--com-header] [--warn-compat] [--quiet] [--verbose] [--template] [--eth-parser[=OUTPUT]] [--diff] [--dump-idl] [--tdr-parser[=OUTPUT]] [--samba3-header[=OUTPUT]] [--samba3-parser=[OUTPUT]] [--samba3-server=[OUTPUT]] [--samba3-template[=OUTPUT]] [--samba3-client[=OUTPUT]] [<idlfile>.idl]...
+pidl [--outputdir[=OUTNAME]] [--parse-idl-tree] [--dump-idl-tree] [--dump-ndr-tree] [--header[=OUTPUT]] [--ejs[=OUTPUT]] [--swig[=OUTPUT]] [--uint-enums] [--ndr-parser[=OUTPUT]] [--client] [--server] [--dcom-proxy] [--com-header] [--warn-compat] [--quiet] [--verbose] [--template] [--eth-parser[=OUTPUT]] [--diff] [--dump-idl] [--tdr-parser[=OUTPUT]] [--samba3-header[=OUTPUT]] [--samba3-parser=[OUTPUT]] [--samba3-server=[OUTPUT]] [--samba3-template[=OUTPUT]] [--samba3-client[=OUTPUT]] [--samba3-ndr-client[=OUTPUT]] [<idlfile>.idl]...
=head1 DESCRIPTION
@@ -144,6 +144,12 @@ rpc_server/. Filename defaults to srv_BASENAME_nt.c
Generate client calls for Samba 3, to be placed in rpc_client/. Filename
defaults to cli_BASENAME.c.
+=item I<--samba3-ndr-client>
+
+Generate client calls for Samba3, to be placed in rpc_client/. Instead of
+calling out to the code in Samba3's rpc_parse/, this will call out to
+Samba4's NDR code instead.
+
=back
=head1 IDL SYNTAX
@@ -465,6 +471,7 @@ my($opt_samba3_parser);
my($opt_samba3_server);
my($opt_samba3_template);
my($opt_samba3_client);
+my($opt_samba3_ndr_client);
my($opt_template) = 0;
my($opt_client);
my($opt_server);
@@ -523,6 +530,8 @@ Samba 3 output:
--samba3-template[=OUTF]create template implementation [srv_BASENAME_nt.c]
--samba3-server[=OUTF] create server side wrappers for Samba3 [srv_BASENAME.c]
--samba3-client[=OUTF] create client calls for Samba3 [cli_BASENAME.c]
+ --samba3-ndr-client[=OUTF] create client calls for Samba3
+ using Samba4's NDR code [cli_BASENAME.c]
Ethereal parsers:
--eth-parser[=OUTFILE] create ethereal parser and header
@@ -544,6 +553,7 @@ my $result = GetOptions (
'samba3-server:s' => \$opt_samba3_server,
'samba3-template:s' => \$opt_samba3_template,
'samba3-client:s' => \$opt_samba3_client,
+ 'samba3-ndr-client:s' => \$opt_samba3_ndr_client,
'header:s' => \$opt_header,
'server:s' => \$opt_server,
'tdr-parser:s' => \$opt_tdr_parser,
@@ -570,6 +580,11 @@ if ($opt_help) {
exit(0);
}
+if ($opt_samba3_client and $opt_samba3_ndr_client) {
+ print "--samba3-client and --samba3-ndr-client can not be used together\n";
+ exit(1);
+}
+
sub process_file($)
{
my $idl_file = shift;
@@ -645,7 +660,8 @@ sub process_file($)
defined($opt_ndr_parser) or defined($opt_ejs) or
defined($opt_dump_ndr_tree) or defined($opt_samba3_header) or
defined($opt_samba3_parser) or defined($opt_samba3_server) or
- defined($opt_samba3_template) or defined($opt_samba3_client)) {
+ defined($opt_samba3_template) or defined($opt_samba3_client) or
+ defined($opt_swig) or defined($opt_samba3_ndr_client)) {
require Parse::Pidl::NDR;
$ndr = Parse::Pidl::NDR::Parse($pidl);
}
@@ -675,6 +691,13 @@ sub process_file($)
FileSave($c_header, $hdrd);
}
+ if (defined($opt_swig)) {
+ require Parse::Pidl::Samba4::SWIG;
+ my($filename) = ($opt_swig or "$outputdir/$basename.i");
+ my $code = Parse::Pidl::Samba4::SWIG::Parse($ndr, $basename, "$outputdir/ndr_$basename\_c.h", $gen_header);
+ FileSave($filename, $code);
+ }
+
if (defined($opt_ejs)) {
require Parse::Pidl::Samba4::EJS;
my ($hdr,$prsr) = Parse::Pidl::Samba4::EJS::Parse($ndr, $h_filename);
@@ -719,11 +742,6 @@ $dcom
FileSave($parser_fname, $parser);
FileSave($h_filename, $header);
- if (defined($opt_swig)) {
- require Parse::Pidl::Samba4::SWIG;
- my($filename) = ($opt_swig or "$outputdir/$basename.i");
- Parse::Pidl::Samba4::SWIG::RewriteHeader($pidl, $h_filename, $filename);
- }
}
if (defined($opt_eth_parser)) {
@@ -756,7 +774,7 @@ $dcom
if (defined($opt_samba3_header) or defined($opt_samba3_parser) or
defined($opt_samba3_server) or defined($opt_samba3_client) or
- defined($opt_samba3_template)) {
+ defined($opt_samba3_ndr_client) or defined($opt_samba3_template)) {
require Parse::Pidl::Samba3::Types;
Parse::Pidl::Samba3::Types::LoadTypes($ndr);
}
@@ -791,6 +809,16 @@ $dcom
FileSave($header, Parse::Pidl::Samba3::Client::Parse($ndr, $basename));
}
+ if (defined($opt_samba3_ndr_client)) {
+ my $client = ($opt_samba3_ndr_client or "$outputdir/cli_$basename.c");
+ my $header = $client; $header =~ s/\.c$/\.h/;
+ require Parse::Pidl::Samba3::ClientNDR;
+ my ($c_code,$h_code) = Parse::Pidl::Samba3::ClientNDR::Parse($ndr, $header, $h_filename);
+ FileSave($client, $c_code);
+ FileSave($header, $h_code);
+ }
+
+
}
if (scalar(@ARGV) == 0) {