summaryrefslogtreecommitdiff
path: root/source4/pidl/lib/Parse/Pidl
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-10-14 16:40:47 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:44:43 -0500
commit6f3caf73e13f32e5482d09b3fd2fbcf61ac88bc1 (patch)
tree01bc12b328a3dc538dec5d5d4e2add672d84d820 /source4/pidl/lib/Parse/Pidl
parentebe6f9ea490b686cef393c9b31c2c975dfac0be8 (diff)
downloadsamba-6f3caf73e13f32e5482d09b3fd2fbcf61ac88bc1.tar.gz
samba-6f3caf73e13f32e5482d09b3fd2fbcf61ac88bc1.tar.bz2
samba-6f3caf73e13f32e5482d09b3fd2fbcf61ac88bc1.zip
r11061: Samba3 parser generator fixes:
* Add (limited) support for [string] * Don't generate (and set) header elements for top level ref pointers as they don't appear on the wire (This used to be commit 765adaf19be264e2d23a22eaed3027faededf8b6)
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba3/Header.pm8
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm28
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba3/Types.pm16
3 files changed, 40 insertions, 12 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm
index d14bac2df7..b49e64c337 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm
@@ -9,7 +9,7 @@ use strict;
use Parse::Pidl::Typelist qw(hasType getType);
use Parse::Pidl::Util qw(has_property ParseExpr);
use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred);
-use Parse::Pidl::Samba3::Types qw(DeclShort);
+use Parse::Pidl::Samba3::Types qw(DeclShort StringType);
use vars qw($VERSION);
$VERSION = '0.01';
@@ -28,11 +28,15 @@ sub ParseElement($)
foreach my $l (@{$e->{LEVELS}}) {
if ($l->{TYPE} eq "POINTER") {
- return if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "top");
+ next if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP");
pidl "\tuint32 ptr$l->{POINTER_INDEX}_$e->{NAME};";
} elsif ($l->{TYPE} eq "SWITCH") {
} elsif ($l->{TYPE} eq "DATA") {
pidl "\t" . DeclShort($e) . ";";
+ } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}) {
+ my ($t,$f) = StringType($e,$l);
+ pidl "\t" . uc($t) . " $e->{NAME};";
+ return;
} elsif ($l->{TYPE} eq "ARRAY") {
if ($l->{IS_CONFORMANT}) {
pidl "\tuint32 size_$e->{NAME};";
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm
index b87951adee..d582305326 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm
@@ -9,7 +9,7 @@ use strict;
use Parse::Pidl::Typelist qw(hasType getType mapType);
use Parse::Pidl::Util qw(has_property ParseExpr);
use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred);
-use Parse::Pidl::Samba3::Types qw(DeclShort DeclLong InitType DissectType);
+use Parse::Pidl::Samba3::Types qw(DeclShort DeclLong InitType DissectType StringType);
use vars qw($VERSION);
$VERSION = '0.01';
@@ -27,7 +27,7 @@ sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); }
#TODO:
# - Add some security checks (array sizes, memory alloc == NULL, etc)
# - Don't add seperate _p and _d functions if there is no deferred data
-# - [string]
+# - [string] with non-varying arrays
# - subcontext()
# - DATA_BLOB
@@ -58,7 +58,7 @@ sub DeclareArrayVariables
next if ($l->{IS_DEFERRED} and $what == PRIMITIVES);
next if (not $l->{IS_DEFERRED} and $what == DEFERRED);
}
- if ($l->{TYPE} eq "ARRAY") {
+ if ($l->{TYPE} eq "ARRAY" and not $l->{IS_ZERO_TERMINATED}) {
pidl "uint32 i_$e->{NAME}_$l->{LEVEL_INDEX};";
$output = 1;
}
@@ -90,9 +90,14 @@ sub ParseElementLevelArray($$$$$$$)
my ($e,$l,$nl,$env,$varname,$what,$align) = @_;
if ($l->{IS_ZERO_TERMINATED}) {
- fatal($e, "[string] attribute not supported for Samba3 yet");
-
- #FIXME
+ my ($t,$f) = StringType($e,$l);
+
+ pidl "if (!prs_io_$t(\"$e->{VARNAME}\", ps, depth, $varname))";
+ pidl "\treturn False;";
+ pidl "";
+
+ $$align = 0;
+ return;
}
my $len = ParseExpr($l->{LENGTH_IS}, $env);
@@ -228,7 +233,9 @@ sub InitLevel($$$$)
indent;
}
- pidl ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . " = 1;";
+ unless ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP") {
+ pidl ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . " = 1;";
+ }
InitLevel($e, GetNextLevel($e,$l), "*$varname", $env);
if ($l->{POINTER_TYPE} ne "ref") {
@@ -237,6 +244,9 @@ sub InitLevel($$$$)
pidl "\t" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . " = 0;";
pidl "}";
}
+ } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}) {
+ my ($t,$f) = StringType($e,$l);
+ pidl "init_$t(" . ParseExpr($e->{NAME}, $env) . ", $varname, $f);";
} elsif ($l->{TYPE} eq "ARRAY") {
pidl ParseExpr($e->{NAME}, $env) . " = $varname;";
} elsif ($l->{TYPE} eq "DATA") {
@@ -256,7 +266,7 @@ sub GenerateEnvElement($$)
} elsif ($l->{TYPE} eq "POINTER") {
$env->{"ptr$l->{POINTER_INDEX}_$e->{NAME}"} = "v->ptr$l->{POINTER_INDEX}_$e->{NAME}";
} elsif ($l->{TYPE} eq "SWITCH") {
- } elsif ($l->{TYPE} eq "ARRAY") {
+ } elsif ($l->{TYPE} eq "ARRAY" and not $l->{IS_ZERO_TERMINATED}) {
$env->{"length_$e->{NAME}"} = "v->length_$e->{NAME}";
$env->{"size_$e->{NAME}"} = "v->size_$e->{NAME}";
$env->{"offset_$e->{NAME}"} = "v->offset_$e->{NAME}";
@@ -360,7 +370,7 @@ sub UnionGenerateEnvElement($)
} elsif ($l->{TYPE} eq "POINTER") {
$env->{"ptr$l->{POINTER_INDEX}_$e->{NAME}"} = "v->ptr$l->{POINTER_INDEX}";
} elsif ($l->{TYPE} eq "SWITCH") {
- } elsif ($l->{TYPE} eq "ARRAY") {
+ } elsif ($l->{TYPE} eq "ARRAY" and not $l->{IS_ZERO_TERMINATED}) {
$env->{"length_$e->{NAME}"} = "v->length";
$env->{"size_$e->{NAME}"} = "v->size";
$env->{"offset_$e->{NAME}"} = "v->offset";
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm
index 135b02f1e3..db20372bba 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm
@@ -7,7 +7,7 @@ package Parse::Pidl::Samba3::Types;
require Exporter;
@ISA = qw(Exporter);
-@EXPORT_OK = qw(DeclShort DeclLong InitType DissectType AddType);
+@EXPORT_OK = qw(DeclShort DeclLong InitType DissectType AddType StringType);
use strict;
use Parse::Pidl::Util qw(has_property ParseExpr property_matches);
@@ -104,6 +104,20 @@ sub dissect_string($$$$$)
return "smb_io_$t(\"$e->{NAME}\", &$n, 1, ps, depth)";
}
+sub StringType($$)
+{
+ my ($e,$l) = @_;
+ my $nl = GetNextLevel($e,$l);
+
+ if ($l->{IS_VARYING} and $l->{IS_CONFORMANT} and $nl->{DATA_TYPE} eq "uint16") {
+ return ("unistr2", 0);
+ } elsif ($l->{IS_CONFORMANT} and $l->{IS_VARYING} and $nl->{DATA_TYPE} eq "uint8") {
+ return ("string2", 0);
+ } else {
+ fatal($e, "[string] non-varying string not supported for Samba3 yet");
+ }
+}
+
my $known_types =
{
uint8 =>