Update from samba tree revision 21565 to 21739

============================ Samba log start ============
------------------------------------------------------------------------
r21567 | jelmer | 2007-02-27 21:35:56 +0100 (Tue, 27 Feb 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Wireshark/NDR.pm
   M /branches/SAMBA_4_0/source/pidl/tests/wireshark-ndr.pl

Add some more wireshark tests.
------------------------------------------------------------------------
r21568 | jelmer | 2007-02-27 22:37:31 +0100 (Tue, 27 Feb 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Wireshark/NDR.pm
   M /branches/SAMBA_4_0/source/pidl/tests/wireshark-ndr.pl

More tests.
------------------------------------------------------------------------
r21572 | jelmer | 2007-02-28 00:47:07 +0100 (Wed, 28 Feb 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/NDR.pm
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Typelist.pm
   M /branches/SAMBA_4_0/source/pidl/tests/ndr.pl
   M /branches/SAMBA_4_0/source/pidl/tests/ndr_tagtype.pl
   M /branches/SAMBA_4_0/source/pidl/tests/typelist.pl

More work towards supporting tagged types.
------------------------------------------------------------------------
r21573 | jelmer | 2007-02-28 01:19:57 +0100 (Wed, 28 Feb 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/NDR.pm
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Typelist.pm
   M /branches/SAMBA_4_0/source/pidl/tests/ndr.pl
   M /branches/SAMBA_4_0/source/pidl/tests/typelist.pl

Remove more code that assumed all types are typedefs.
------------------------------------------------------------------------
r21574 | jelmer | 2007-02-28 01:28:14 +0100 (Wed, 28 Feb 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/NDR.pm
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Typelist.pm
   M /branches/SAMBA_4_0/source/pidl/tests/ndr.pl

Fix handling of DECLARE.
------------------------------------------------------------------------
r21575 | jelmer | 2007-02-28 01:35:21 +0100 (Wed, 28 Feb 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Typelist.pm
   M /branches/SAMBA_4_0/source/pidl/tests/typelist.pl

Fix handling of is_scalar() for declares.
------------------------------------------------------------------------
r21578 | jelmer | 2007-02-28 02:51:37 +0100 (Wed, 28 Feb 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/README
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
   M /branches/SAMBA_4_0/source/pidl/tests/ndr_tagtype.pl
   M /branches/SAMBA_4_0/source/pidl/tests/samba-ndr.pl

Use utility function for naming pull/push/print functions.
------------------------------------------------------------------------
r21579 | jelmer | 2007-02-28 03:01:58 +0100 (Wed, 28 Feb 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/EJS.pm
   M /branches/SAMBA_4_0/source/pidl/tests/samba-ejs.pl

Use utility function to determine function names in ejs code.
------------------------------------------------------------------------
r21584 | jelmer | 2007-02-28 14:25:53 +0100 (Wed, 28 Feb 2007) | 6 lines
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/librpc/idl/echo.idl
   M /branches/SAMBA_4_0/source/pidl/README
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/NDR.pm
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/EJS.pm
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Header.pm
   M /branches/SAMBA_4_0/source/pidl/tests/header.pl
   M /branches/SAMBA_4_0/source/pidl/tests/ndr.pl
   M /branches/SAMBA_4_0/source/pidl/tests/typelist.pl

Support for tagged types has landed!

It's now possible to use "struct foo" without a typedef in IDL files.

echo_info4 is the first type that's been converted.

------------------------------------------------------------------------
r21586 | jelmer | 2007-02-28 15:56:46 +0100 (Wed, 28 Feb 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/MANIFEST

update manifest
------------------------------------------------------------------------
r21654 | jelmer | 2007-03-02 15:05:52 +0100 (Fri, 02 Mar 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
   M /branches/SAMBA_4_0/source/pidl/tests/samba-ndr.pl

Add simple test for print functions.
------------------------------------------------------------------------
r21656 | jelmer | 2007-03-02 15:53:09 +0100 (Fri, 02 Mar 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   A /branches/SAMBA_4_0/source/lib/registry/tests
   A /branches/SAMBA_4_0/source/lib/registry/tests/generic.c (from /branches/SAMBA_4_0/source/torture/local/registry.c:21654)
   A /branches/SAMBA_4_0/source/lib/socket/testsuite.c (from /branches/SAMBA_4_0/source/torture/local/socket.c:21654)
   A /branches/SAMBA_4_0/source/lib/tdr/testsuite.c (from /branches/SAMBA_4_0/source/torture/local/tdr.c:21654)
   A /branches/SAMBA_4_0/source/lib/util/tests
   A /branches/SAMBA_4_0/source/lib/util/tests/file.c (from /branches/SAMBA_4_0/source/torture/local/util_file.c:21654)
   A /branches/SAMBA_4_0/source/lib/util/tests/idtree.c (from /branches/SAMBA_4_0/source/torture/local/idtree.c:21654)
   A /branches/SAMBA_4_0/source/lib/util/tests/strlist.c (from /branches/SAMBA_4_0/source/torture/local/util_strlist.c:21654)
   A /branches/SAMBA_4_0/source/librpc/tests
   A /branches/SAMBA_4_0/source/librpc/tests/binding_string.c (from /branches/SAMBA_4_0/source/torture/local/binding_string.c:21654)
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
   D /branches/SAMBA_4_0/source/torture/local/binding_string.c
   M /branches/SAMBA_4_0/source/torture/local/config.mk
   D /branches/SAMBA_4_0/source/torture/local/idtree.c
   D /branches/SAMBA_4_0/source/torture/local/registry.c
   D /branches/SAMBA_4_0/source/torture/local/socket.c
   D /branches/SAMBA_4_0/source/torture/local/tdr.c
   D /branches/SAMBA_4_0/source/torture/local/util_file.c
   D /branches/SAMBA_4_0/source/torture/local/util_strlist.c

Move tests a bit closer to the things they test, should make syncing with samba3 easier.
------------------------------------------------------------------------
r21681 | jelmer | 2007-03-04 15:16:52 +0100 (Sun, 04 Mar 2007) | 5 lines
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/TODO
   M /branches/SAMBA_4_0/source/pidl/idl.yp
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/IDL.pm
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/NDR.pm
   M /branches/SAMBA_4_0/source/pidl/tests/header.pl
   M /branches/SAMBA_4_0/source/pidl/tests/parse_idl.pl

Fix bug in the parsing code that parsed "struct foo;" the same as 
"struct foo {};". 

Reported by one of the OpenChange folks, thanks!

------------------------------------------------------------------------
r21682 | jelmer | 2007-03-04 15:31:18 +0100 (Sun, 04 Mar 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/NDR.pm

Remove accidently committed debug command.
------------------------------------------------------------------------
r21690 | jelmer | 2007-03-05 01:03:44 +0100 (Mon, 05 Mar 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/tests/header.pl
   M /branches/SAMBA_4_0/source/pidl/tests/parse_idl.pl

Test use of typedef /and/ struct name
------------------------------------------------------------------------
------------------------------------------------------------------------
============================ Samba log end ==============

svn path=/trunk/; revision=20992
This commit is contained in:
Jörg Mayer 2007-03-07 07:55:00 +00:00
parent 83ee2dbcfa
commit d4ead590a1
19 changed files with 1758 additions and 1413 deletions

View File

@ -15,19 +15,12 @@ tests/ndr_represent.pl
tests/ndr_compat.pl
tests/ndr_fullptr.pl
tests/ndr_tagtype.pl
lib/Parse/Pidl/Samba3/Client.pm
tests/header.pl
lib/Parse/Pidl/Samba3/ClientNDR.pm
lib/Parse/Pidl/Samba3/Header.pm
lib/Parse/Pidl/Samba3/Parser.pm
lib/Parse/Pidl/Samba3/Server.pm
lib/Parse/Pidl/Samba3/Template.pm
lib/Parse/Pidl/Samba3/Types.pm
lib/Parse/Pidl/Samba3/ServerNDR.pm
lib/Parse/Pidl/Samba4/NDR/Server.pm
lib/Parse/Pidl/Samba4/NDR/Parser.pm
lib/Parse/Pidl/Samba4/NDR/Client.pm
lib/Parse/Pidl/Samba4/COM/Header.pm
lib/Parse/Pidl/Samba4/COM/Stub.pm
lib/Parse/Pidl/Samba4/COM/Proxy.pm
lib/Parse/Pidl/Samba4/Header.pm
lib/Parse/Pidl/Samba4/SWIG.pm
lib/Parse/Pidl/Samba4/TDR.pm
@ -40,7 +33,6 @@ lib/Parse/Pidl/Typelist.pm
lib/Parse/Pidl/Dump.pm
lib/Parse/Pidl/Compat.pm
lib/Parse/Pidl/Util.pm
lib/Parse/Pidl/ODL.pm
lib/Parse/Pidl/NDR.pm
lib/Parse/Pidl.pm
Makefile.PL

View File

@ -4,7 +4,7 @@ This directory contains the source code of the pidl (Perl IDL)
compiler for Samba 4.
The main sources for pidl are available by Subversion on
svn+ssh://svnanon.samba.org/samba/branches/SAMBA_4_0/source/pidl
svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/pidl
Pidl works by building a parse tree from a .pidl file (a simple
dump of it's internal parse tree) or a .idl file

View File

@ -1,5 +1,3 @@
- allow [public] on typedefs only
- EJS output backend shouldn't use the NDR levels stuff but instead
as the "C levels" and NDR levels don't necessarily match.
@ -8,14 +6,19 @@
- compatibility mode for generating MIDL-readable data:
- strip out pidl-specific properties
- remove declare in favor of typedef
- make bitmap an optional attribute on enum
- support nested elements
- support typedefs properly
- improve represent_as(): allow it to be used for arrays and other complex
types
- support typedefs properly (e.g. allow "typedef void **bla;")
- make typedefs generate real typedefs
- improve represent_as(): allow it to be used for arrays and other complex
types
- --explain-ndr option that dumps out parse tree ?
- seperate tables for NDR and DCE/RPC
- maybe no tables for NDR at all? we only need them for ndrdump
and that can use dlsym()
- allow data structures outside of interfaces

View File

@ -66,23 +66,17 @@ interface_names:
| interface_names 'interface' identifier ';' { push(@{$_[1]}, $_[2]); $_[1] }
;
interface: property_list 'interface' identifier base_interface '{' definitions '}' optional_semicolon
interface: property_list 'interface' identifier '{' definitions '}' optional_semicolon
{{
"TYPE" => "INTERFACE",
"PROPERTIES" => $_[1],
"NAME" => $_[3],
"BASE" => $_[4],
"DATA" => $_[6],
"DATA" => $_[5],
"FILE" => $_[0]->YYData->{FILE},
"LINE" => $_[0]->YYData->{LINE},
}}
;
base_interface:
#empty
| ':' identifier { $_[2] }
;
definitions:
definition { [ $_[1] ] }
| definitions definition { push(@{$_[1]}, $_[2]); $_[1] }
@ -293,7 +287,7 @@ pointers:
;
element_list1:
#empty
{ [] }
| element_list1 base_element ';' { push(@{$_[1]}, $_[2]); $_[1] }
;
@ -407,10 +401,6 @@ sub CleanData($)
if (ref($v) eq "ARRAY") {
foreach my $i (0 .. $#{$v}) {
CleanData($v->[$i]);
if (ref($v->[$i]) eq "ARRAY" && $#{$v->[$i]}==-1) {
$v->[$i] = undef;
next;
}
}
# this removes any undefined elements from the array
@{$v} = grep { defined $_ } @{$v};
@ -418,7 +408,6 @@ sub CleanData($)
foreach my $x (keys %{$v}) {
CleanData($v->{$x});
if (!defined $v->{$x}) { delete($v->{$x}); next; }
if (ref($v->{$x}) eq "ARRAY" && $#{$v->{$x}}==-1) { delete($v->{$x}); next; }
}
}
return $v;

File diff suppressed because it is too large Load Diff

View File

@ -35,7 +35,7 @@ use vars qw($VERSION);
$VERSION = '0.01';
@ISA = qw(Exporter);
@EXPORT = qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsString);
@EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement);
@EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type mapToScalar ParseType);
use strict;
use Parse::Pidl qw(warning fatal);
@ -271,8 +271,9 @@ sub GetElementLevelTable($)
#####################################################################
# see if a type contains any deferred data
sub can_contain_deferred
sub can_contain_deferred($)
{
sub can_contain_deferred($);
my $e = shift;
return 0 if (Parse::Pidl::Typelist::is_scalar($e->{TYPE}));
@ -335,7 +336,11 @@ sub find_largest_alignment($)
sub align_type($)
{
sub align_type($);
my $e = shift;
my ($e) = @_;
if (ref($e) eq "HASH" and $e->{TYPE} eq "SCALAR") {
return $scalar_alignment->{$e->{NAME}};
}
unless (hasType($e)) {
# it must be an external type - all we can do is guess
@ -343,16 +348,16 @@ sub align_type($)
return 4;
}
my $dt = getType($e)->{DATA};
my $dt = getType($e);
if ($dt->{TYPE} eq "ENUM") {
if ($dt->{TYPE} eq "TYPEDEF" or $dt->{TYPE} eq "DECLARE") {
return align_type($dt->{DATA});
} elsif ($dt->{TYPE} eq "ENUM") {
return align_type(Parse::Pidl::Typelist::enum_type_fn($dt));
} elsif ($dt->{TYPE} eq "BITMAP") {
return align_type(Parse::Pidl::Typelist::bitmap_type_fn($dt));
} elsif (($dt->{TYPE} eq "STRUCT") or ($dt->{TYPE} eq "UNION")) {
return find_largest_alignment($dt);
} elsif ($dt->{TYPE} eq "SCALAR") {
return $scalar_alignment->{$dt->{NAME}};
}
die("Unknown data type type $dt->{TYPE}");
@ -495,6 +500,7 @@ sub ParseType($$)
my ($d, $pointer_default) = @_;
if ($d->{TYPE} eq "STRUCT" or $d->{TYPE} eq "UNION") {
return $d if (not defined($d->{ELEMENTS}));
CheckPointerTypes($d, $pointer_default);
}
@ -876,17 +882,19 @@ sub ValidProperties($$)
sub mapToScalar($)
{
sub mapToScalar($);
my $t = shift;
return $t->{NAME} if (ref($t) eq "HASH" and $t->{TYPE} eq "SCALAR");
my $ti = getType($t);
if (not defined ($ti)) {
return undef;
} elsif ($ti->{DATA}->{TYPE} eq "ENUM") {
return Parse::Pidl::Typelist::enum_type_fn($ti->{DATA});
} elsif ($ti->{DATA}->{TYPE} eq "BITMAP") {
return Parse::Pidl::Typelist::enum_type_fn($ti->{DATA});
} elsif ($ti->{DATA}->{TYPE} eq "SCALAR") {
return $t;
} elsif ($ti->{TYPE} eq "TYPEDEF") {
return mapToScalar($ti->{DATA});
} elsif ($ti->{TYPE} eq "ENUM") {
return Parse::Pidl::Typelist::enum_type_fn($ti);
} elsif ($ti->{TYPE} eq "BITMAP") {
return Parse::Pidl::Typelist::bitmap_type_fn($ti);
}
return undef;

View File

@ -9,7 +9,7 @@ package Parse::Pidl::Samba4::EJS;
use Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(get_pointer_to get_value_of check_null_pointer $res
$res_hdr fn_declare);
$res_hdr fn_declare TypeFunctionName);
use strict;
use Parse::Pidl::Typelist;
@ -426,14 +426,7 @@ sub EjsPushScalar($$$$$)
$var = get_pointer_to($var);
}
my $t;
if (ref($e->{TYPE}) eq "HASH") {
$t = "$e->{TYPE}->{TYPE}_$e->{TYPE}->{NAME}";
} else {
$t = $e->{TYPE};
}
pidl "NDR_CHECK(ejs_push_$t(ejs, v, $name, $var));";
pidl "NDR_CHECK(".TypeFunctionName("ejs_push", $e->{TYPE})."(ejs, v, $name, $var));";
}
}
@ -619,21 +612,22 @@ sub EjsTypePushFunction($$)
my ($d, $name) = @_;
return if (has_property($d, "noejs"));
if ($d->{TYPE} eq "TYPEDEF") {
EjsTypePushFunction($d->{DATA}, $name);
return;
my $var = undef;
my $dt = $d;
if ($dt->{TYPE} eq "TYPEDEF") {
$dt = $dt->{DATA};
}
if ($d->{TYPE} eq "STRUCT") {
fn_declare($d, "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const struct $name *r)");
} elsif ($d->{TYPE} eq "UNION") {
fn_declare($d, "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const union $name *r)");
} elsif ($d->{TYPE} eq "ENUM") {
fn_declare($d, "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const enum $name *r)");
} elsif ($d->{TYPE} eq "BITMAP") {
my($type_decl) = Parse::Pidl::Typelist::mapTypeName($d->{BASE_TYPE});
fn_declare($d, "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const $type_decl *r)");
if ($dt->{TYPE} eq "STRUCT") {
$var = "const struct $name *r";
} elsif ($dt->{TYPE} eq "UNION") {
$var = "const union $name *r";
} elsif ($dt->{TYPE} eq "ENUM") {
$var = "const enum $name *r";
} elsif ($dt->{TYPE} eq "BITMAP") {
my($type_decl) = Parse::Pidl::Typelist::mapTypeName($dt->{BASE_TYPE});
$var = "const $type_decl *r";
}
fn_declare($d, "NTSTATUS ".TypeFunctionName("ejs_push", $d) . "(struct ejs_rpc *ejs, struct MprVar *v, const char *name, $var)");
pidl "{";
indent;
EjsTypePush($d, "r");
@ -644,6 +638,7 @@ sub EjsTypePushFunction($$)
sub EjsTypePush($$)
{
sub EjsTypePush($$);
my ($d, $varname) = @_;
if ($d->{TYPE} eq 'STRUCT') {
@ -654,6 +649,8 @@ sub EjsTypePush($$)
EjsEnumPush($d, $varname);
} elsif ($d->{TYPE} eq 'BITMAP') {
EjsBitmapPush($d, $varname);
} elsif ($d->{TYPE} eq 'TYPEDEF') {
EjsTypePush($d->{DATA}, $varname);
} else {
warn "Unhandled push $varname of type $d->{TYPE}";
}
@ -677,8 +674,7 @@ sub EjsPushFunction($)
}
if ($d->{RETURN_TYPE}) {
my $t = $d->{RETURN_TYPE};
pidl "NDR_CHECK(ejs_push_$t(ejs, v, \"result\", &r->out.result));";
pidl "NDR_CHECK(".TypeFunctionName("ejs_push", $d->{RETURN_TYPE})."(ejs, v, \"result\", &r->out.result));";
}
pidl "return NT_STATUS_OK;";
@ -737,8 +733,8 @@ sub EjsInterface($$)
pidl_hdr "\n";
foreach my $d (@{$interface->{TYPES}}) {
($needed->{"push_$d->{NAME}"}) && EjsTypePushFunction($d, $d->{NAME});
($needed->{"pull_$d->{NAME}"}) && EjsTypePullFunction($d, $d->{NAME});
($needed->{TypeFunctionName("ejs_push", $d)}) && EjsTypePushFunction($d, $d->{NAME});
($needed->{TypeFunctionName("ejs_pull", $d)}) && EjsTypePullFunction($d, $d->{NAME});
}
foreach my $d (@{$interface->{FUNCTIONS}}) {
@ -831,16 +827,16 @@ sub NeededFunction($$)
{
my ($fn,$needed) = @_;
$needed->{"pull_$fn->{NAME}"} = 1;
$needed->{"push_$fn->{NAME}"} = 1;
$needed->{"ejs_pull_$fn->{NAME}"} = 1;
$needed->{"ejs_push_$fn->{NAME}"} = 1;
foreach (@{$fn->{ELEMENTS}}) {
next if (has_property($_, "subcontext")); #FIXME: Support subcontexts
if (grep(/in/, @{$_->{DIRECTION}})) {
$needed->{"pull_$_->{TYPE}"} = 1;
$needed->{TypeFunctionName("ejs_pull", $_->{TYPE})} = 1;
}
if (grep(/out/, @{$_->{DIRECTION}})) {
$needed->{"push_$_->{TYPE}"} = 1;
$needed->{TypeFunctionName("ejs_push", $_->{TYPE})} = 1;
}
}
}
@ -858,10 +854,8 @@ sub NeededType($$$)
foreach (@{$t->{ELEMENTS}}) {
next if (has_property($_, "subcontext")); #FIXME: Support subcontexts
my $n;
if (ref($_->{TYPE}) eq "HASH" and defined($_->{TYPE}->{NAME})) {
$needed->{"$req\_$_->{TYPE}->{TYPE}_$_->{TYPE}->{NAME}"} = 1;
} elsif (ref($_->{TYPE}) ne "HASH") {
$needed->{$req."_".$_->{TYPE}} = 1;
if (ref($_->{TYPE}) ne "HASH" or defined($_->{TYPE}->{NAME})) {
$needed->{TypeFunctionName("ejs_$req", $_->{TYPE})} = 1;
}
NeededType($_->{TYPE}, $needed, $req) if (ref($_->{TYPE}) eq "HASH");
}
@ -877,13 +871,25 @@ sub NeededInterface($$)
foreach (reverse @{$interface->{TYPES}}) {
if (has_property($_, "public")) {
$needed->{"pull_$_->{NAME}"} = not has_property($_, "noejs");
$needed->{"push_$_->{NAME}"} = not has_property($_, "noejs");
$needed->{TypeFunctionName("ejs_pull", $_)} = not has_property($_, "noejs");
$needed->{TypeFunctionName("ejs_push", $_)} = not has_property($_, "noejs");
}
NeededType($_, $needed, "pull") if ($needed->{"pull_$_->{NAME}"});
NeededType($_, $needed, "push") if ($needed->{"push_$_->{NAME}"});
NeededType($_, $needed, "pull") if ($needed->{TypeFunctionName("ejs_pull", $_)});
NeededType($_, $needed, "push") if ($needed->{TypeFunctionName("ejs_push", $_)});
}
}
sub TypeFunctionName($$)
{
my ($prefix, $t) = @_;
return "$prefix\_$t->{NAME}" if (ref($t) eq "HASH" and
($t->{TYPE} eq "TYPEDEF" or $t->{TYPE} eq "DECLARE"));
return "$prefix\_$t->{TYPE}_$t->{NAME}" if (ref($t) eq "HASH");
return "$prefix\_$t";
}
1;

View File

@ -57,7 +57,11 @@ sub HeaderElement($)
if (has_property($element, "represent_as")) {
pidl mapTypeName($element->{PROPERTIES}->{represent_as})." ";
} else {
HeaderType($element, $element->{TYPE}, "");
if (ref($element->{TYPE}) eq "HASH") {
HeaderType($element, $element->{TYPE}, $element->{TYPE}->{NAME});
} else {
HeaderType($element, $element->{TYPE}, "");
}
pidl " ";
my $numstar = $element->{POINTERS};
if ($numstar >= 1) {
@ -90,14 +94,14 @@ sub HeaderElement($)
sub HeaderStruct($$)
{
my($struct,$name) = @_;
pidl "struct $name {\n";
pidl "struct $name";
return if (not defined($struct->{ELEMENTS}));
pidl " {\n";
$tab_depth++;
my $el_count=0;
if (defined $struct->{ELEMENTS}) {
foreach (@{$struct->{ELEMENTS}}) {
HeaderElement($_);
$el_count++;
}
foreach (@{$struct->{ELEMENTS}}) {
HeaderElement($_);
$el_count++;
}
if ($el_count == 0) {
# some compilers can't handle empty structures
@ -174,7 +178,9 @@ sub HeaderUnion($$)
my($union,$name) = @_;
my %done = ();
pidl "union $name {\n";
pidl "union $name";
return if (not defined($union->{ELEMENTS}));
pidl " {\n";
$tab_depth++;
foreach my $e (@{$union->{ELEMENTS}}) {
if ($e->{TYPE} ne "EMPTY") {

View File

@ -12,7 +12,7 @@ require Exporter;
@EXPORT = qw(is_charset_array);
@EXPORT_OK = qw(check_null_pointer GenerateFunctionInEnv
GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv NeededFunction
NeededElement NeededType $res NeededInterface);
NeededElement NeededType $res NeededInterface TypeFunctionName ParseElementPrint);
use strict;
use Parse::Pidl::Typelist qw(hasType getType mapTypeName);
@ -898,20 +898,14 @@ sub ParseDataPull($$$$$$)
defined($l->{DATA_TYPE}->{NAME})) {
my $ndr_flags = CalcNdrFlags($l, $primitives, $deferred);
my $t;
if (ref($l->{DATA_TYPE}) eq "HASH") {
$t = "$l->{DATA_TYPE}->{TYPE}_$l->{DATA_TYPE}->{NAME}";
} else {
$t = $l->{DATA_TYPE};
}
if (Parse::Pidl::Typelist::scalar_is_reference($t)) {
if (Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) {
$var_name = get_pointer_to($var_name);
}
$var_name = get_pointer_to($var_name);
pidl "NDR_CHECK(ndr_pull_$t($ndr, $ndr_flags, $var_name));";
pidl "NDR_CHECK(".TypeFunctionName("ndr_pull", $l->{DATA_TYPE})."($ndr, $ndr_flags, $var_name));";
if (my $range = has_property($e, "range")) {
$var_name = get_value_of($var_name);
@ -1487,8 +1481,6 @@ sub ParseStructPrint($$$)
my $env = GenerateStructEnv($struct, $varname);
EnvSubstituteValue($env, $struct);
DeclareArrayVariables($_) foreach (@{$struct->{ELEMENTS}});
pidl "ndr_print_struct(ndr, name, \"$name\");";
@ -2055,7 +2047,6 @@ sub ParseFunctionPrint($)
pidl "ndr->depth++;";
my $env = GenerateFunctionInEnv($fn);
EnvSubstituteValue($env, $fn);
foreach my $e (@{$fn->{ELEMENTS}}) {
if (grep(/in/,@{$e->{DIRECTION}})) {
@ -2457,7 +2448,7 @@ sub ParseTypePushFunction($$)
my ($e, $varname) = @_;
my $args = $typefamily{$e->{TYPE}}->{DECL}->($e, "push", $e->{NAME}, $varname);
fn_declare("push", $e, "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, $args)") or return;
fn_declare("push", $e, "NTSTATUS ".TypeFunctionName("ndr_push", $e)."(struct ndr_push *ndr, int ndr_flags, $args)") or return;
pidl "{";
indent;
@ -2485,7 +2476,7 @@ sub ParseTypePullFunction($$)
my $args = $typefamily{$e->{TYPE}}->{DECL}->($e, "pull", $e->{NAME}, $varname);
fn_declare("pull", $e, "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, $args)") or return;
fn_declare("pull", $e, "NTSTATUS ".TypeFunctionName("ndr_pull", $e)."(struct ndr_pull *ndr, int ndr_flags, $args)") or return;
pidl "{";
indent;
@ -2508,11 +2499,11 @@ sub ParseTypePrintFunction($$)
my ($e, $varname) = @_;
my $args = $typefamily{$e->{TYPE}}->{DECL}->($e, "print", $e->{NAME}, $varname);
pidl_hdr "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args);";
pidl_hdr "void ".TypeFunctionName("ndr_print", $e)."(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 "_PUBLIC_ void ".TypeFunctionName("ndr_print", $e)."(struct ndr_print *ndr, const char *name, $args)";
pidl "{";
indent;
ParseTypePrint($e, $varname);
@ -2558,26 +2549,27 @@ sub ParseInterface($$)
# Typedefs
foreach my $d (@{$interface->{TYPES}}) {
($needed->{"push_$d->{NAME}"}) && ParseTypePushFunction($d, "r");
($needed->{"pull_$d->{NAME}"}) && ParseTypePullFunction($d, "r");
($needed->{"print_$d->{NAME}"}) && ParseTypePrintFunction($d, "r");
($needed->{TypeFunctionName("ndr_push", $d)}) && ParseTypePushFunction($d, "r");
($needed->{TypeFunctionName("ndr_pull", $d)}) && ParseTypePullFunction($d, "r");
($needed->{TypeFunctionName("ndr_print", $d)}) && ParseTypePrintFunction($d, "r");
# Make sure we don't generate a function twice...
$needed->{"push_$d->{NAME}"} = $needed->{"pull_$d->{NAME}"} =
$needed->{"print_$d->{NAME}"} = 0;
$needed->{TypeFunctionName("ndr_push", $d)} =
$needed->{TypeFunctionName("ndr_pull", $d)} =
$needed->{TypeFunctionName("ndr_print", $d)} = 0;
($needed->{"ndr_size_$d->{NAME}"}) && ParseTypeNdrSize($d);
}
# Functions
foreach my $d (@{$interface->{FUNCTIONS}}) {
($needed->{"push_$d->{NAME}"}) && ParseFunctionPush($d);
($needed->{"pull_$d->{NAME}"}) && ParseFunctionPull($d);
($needed->{"print_$d->{NAME}"}) && ParseFunctionPrint($d);
($needed->{"ndr_push_$d->{NAME}"}) && ParseFunctionPush($d);
($needed->{"ndr_pull_$d->{NAME}"}) && ParseFunctionPull($d);
($needed->{"ndr_print_$d->{NAME}"}) && ParseFunctionPrint($d);
# Make sure we don't generate a function twice...
$needed->{"push_$d->{NAME}"} = $needed->{"pull_$d->{NAME}"} =
$needed->{"print_$d->{NAME}"} = 0;
$needed->{"ndr_push_$d->{NAME}"} = $needed->{"ndr_pull_$d->{NAME}"} =
$needed->{"ndr_print_$d->{NAME}"} = 0;
}
FunctionTable($interface);
@ -2670,13 +2662,13 @@ sub NeededElement($$$)
my @fn = ();
if ($dir eq "print") {
push(@fn, "print_$rt");
push(@fn, TypeFunctionName("ndr_print", $e->{REPRESENTATION_TYPE}));
} elsif ($dir eq "pull") {
push (@fn, "pull_$t");
push (@fn, TypeFunctionName("ndr_pull", $e->{TYPE}));
push (@fn, "ndr_$t\_to_$rt")
if ($rt ne $t);
} elsif ($dir eq "push") {
push (@fn, "push_$t");
push (@fn, TypeFunctionName("ndr_push", $e->{TYPE}));
push (@fn, "ndr_$rt\_to_$t")
if ($rt ne $t);
} else {
@ -2693,9 +2685,9 @@ sub NeededElement($$$)
sub NeededFunction($$)
{
my ($fn,$needed) = @_;
$needed->{"pull_$fn->{NAME}"} = 1;
$needed->{"push_$fn->{NAME}"} = 1;
$needed->{"print_$fn->{NAME}"} = 1;
$needed->{"ndr_pull_$fn->{NAME}"} = 1;
$needed->{"ndr_push_$fn->{NAME}"} = 1;
$needed->{"ndr_print_$fn->{NAME}"} = 1;
foreach my $e (@{$fn->{ELEMENTS}}) {
$e->{PARENT} = $fn;
NeededElement($e, $_, $needed) foreach ("pull", "push", "print");
@ -2729,17 +2721,27 @@ sub NeededInterface($$)
NeededFunction($_, $needed) foreach (@{$interface->{FUNCTIONS}});
foreach (reverse @{$interface->{TYPES}}) {
if (has_property($_, "public")) {
$needed->{"pull\_$_->{NAME}"} = $needed->{"push\_$_->{NAME}"} =
$needed->{"print\_$_->{NAME}"} = 1;
$needed->{TypeFunctionName("ndr_pull", $_)} = $needed->{TypeFunctionName("ndr_push", $_)} =
$needed->{TypeFunctionName("ndr_print", $_)} = 1;
}
NeededType($_, $needed, "pull") if ($needed->{"pull_$_->{NAME}"});
NeededType($_, $needed, "push") if ($needed->{"push_$_->{NAME}"});
NeededType($_, $needed, "print") if ($needed->{"print_$_->{NAME}"});
NeededType($_, $needed, "pull") if ($needed->{TypeFunctionName("ndr_pull", $_)});
NeededType($_, $needed, "push") if ($needed->{TypeFunctionName("ndr_push", $_)});
NeededType($_, $needed, "print") if ($needed->{TypeFunctionName("ndr_print", $_)});
if (has_property($_, "gensize")) {
$needed->{"ndr_size_$_->{NAME}"} = 1;
}
}
}
sub TypeFunctionName($$)
{
my ($prefix, $t) = @_;
return "$prefix\_$t->{NAME}" if (ref($t) eq "HASH" and
($t->{TYPE} eq "TYPEDEF" or $t->{TYPE} eq "DECLARE"));
return "$prefix\_$t->{TYPE}_$t->{NAME}" if (ref($t) eq "HASH");
return "$prefix\_$t";
}
1;

View File

@ -98,33 +98,50 @@ sub addType($)
sub getType($)
{
my $t = shift;
return ($t) if (ref($t) eq "HASH" and not defined($t->{NAME}));
return undef if not hasType($t);
return $types{$t->{NAME}} if (ref($t) eq "HASH");
return $types{$t};
}
sub typeIs($$)
{
my ($t,$tt) = @_;
return 1 if (hasType($t) and getType($t)->{DATA}->{TYPE} eq $tt);
if (ref($t) eq "HASH") {
return 1 if ($t->{TYPE} eq $tt);
return 0;
}
return 1 if (hasType($t) and getType($t)->{TYPE} eq "TYPEDEF" and
getType($t)->{DATA}->{TYPE} eq $tt);
return 0;
}
sub hasType($)
{
my $t = shift;
if (ref($t) eq "HASH") {
return 1 if (not defined($t->{NAME}));
return 1 if (defined($types{$t->{NAME}}) and
$types{$t->{NAME}}->{TYPE} eq $t->{TYPE});
return 0;
}
return 1 if defined($types{$t});
return 0;
}
sub is_scalar($)
{
sub is_scalar($);
my $type = shift;
return 0 unless(hasType($type));
return 1 if (ref($type) eq "HASH" and $type->{TYPE} eq "SCALAR");
if (my $dt = getType($type)->{DATA}->{TYPE}) {
return 1 if ($dt eq "SCALAR" or $dt eq "ENUM" or $dt eq "BITMAP");
if (my $dt = getType($type)) {
return is_scalar($dt->{DATA}) if ($dt->{TYPE} eq "TYPEDEF" or
$dt->{TYPE} eq "DECLARE");
return 1 if ($dt->{TYPE} eq "SCALAR" or $dt->{TYPE} eq "ENUM" or
$dt->{TYPE} eq "BITMAP");
}
return 0;

View File

@ -18,7 +18,7 @@ package Parse::Pidl::Wireshark::NDR;
use Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(field2name @ett %res PrintIdl StripPrefixes %hf_used RegisterInterfaceHandoff $conformance register_hf_field CheckUsed);
@EXPORT_OK = qw(field2name @ett %res PrintIdl StripPrefixes %hf_used RegisterInterfaceHandoff $conformance register_hf_field CheckUsed ProcessImport ProcessInclude find_type DumpEttList DumpEttDeclaration DumpHfList DumpHfDeclaration DumpFunctionTable register_type register_ett);
use strict;
use Parse::Pidl qw(error warning);
@ -671,7 +671,7 @@ sub RegisterInterface($)
indent;
$res{code}.=DumpHfList()."\n";
$res{code}.="\n".DumpEttList()."\n";
$res{code}.="\n".DumpEttList(@ett)."\n";
if (defined($x->{UUID})) {
# These can be changed to non-pidl_code names if the old dissectors
@ -730,8 +730,9 @@ sub ProcessInclude
{
my @includes = @_;
foreach (@includes) {
pidl_hdr "#include \"$_\"\n";
pidl_hdr "#include \"$_\"";
}
pidl_hdr "";
}
sub ProcessImport
@ -741,8 +742,9 @@ sub ProcessImport
next if($_ eq "security");
s/\.idl\"$//;
s/^\"//;
pidl_hdr "#include \"packet-dcerpc-$_\.h\"\n";
pidl_hdr "#include \"packet-dcerpc-$_\.h\"";
}
pidl_hdr "";
}
sub ProcessInterface($)
@ -924,7 +926,7 @@ sub Parse($$$$)
ProcessInclude(@{$_->{PATHS}}) if ($_->{TYPE} eq "INCLUDE");
}
$res{ett} = DumpEttDeclaration();
$res{ett} = DumpEttDeclaration(@ett);
$res{hf} = DumpHfDeclaration();
my $parser = $notice;
@ -956,8 +958,9 @@ sub register_ett($)
push (@ett, $name);
}
sub DumpEttList()
sub DumpEttList
{
my @ett = @_;
my $res = "\tstatic gint *ett[] = {\n";
foreach (@ett) {
$res .= "\t\t&$_,\n";
@ -966,8 +969,9 @@ sub DumpEttList()
return "$res\t};\n";
}
sub DumpEttDeclaration()
sub DumpEttDeclaration
{
my @ett = @_;
my $res = "\n/* Ett declarations */\n";
foreach (@ett) {
$res .= "static gint $_ = -1;\n";

View File

@ -4,7 +4,7 @@
use strict;
use warnings;
use Test::More tests => 10;
use Test::More tests => 15;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
@ -36,3 +36,18 @@ like(parse_idl("interface x { void foo ([in,out] uint32 x); };"),
like(parse_idl("interface x { void foo (uint32 x); };"), qr/struct foo.*{.*struct\s+{\s+uint32_t x;\s+} in;\s+struct\s+{\s+uint32_t x;\s+} out;.*};/sm, "fn with no props implies in,out");
like(parse_idl("interface p { struct x { int y; }; };"),
qr/struct x.*{.*int32_t y;.*}.*;/sm, "interface member generated properly");
like(parse_idl("interface p { struct x { struct y z; }; };"),
qr/struct x.*{.*struct y z;.*}.*;/sm, "tagged type struct member");
like(parse_idl("interface p { struct x { union y z; }; };"),
qr/struct x.*{.*union y z;.*}.*;/sm, "tagged type union member");
like(parse_idl("interface p { struct x { }; };"),
qr/struct x.*{.*char _empty_;.*}.*;/sm, "empty struct");
like(parse_idl("interface p { struct x; };"),
qr/struct x;/sm, "struct declaration");
like(parse_idl("interface p { typedef struct x { int p; } x; };"),
qr/struct x.*{.*int32_t p;.*};/sm, "double struct declaration");

View File

@ -4,12 +4,12 @@
use strict;
use warnings;
use Test::More tests => 12;
use Test::More tests => 26;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use Parse::Pidl::Util qw(MyDumper);
use Parse::Pidl::NDR qw(GetElementLevelTable ParseElement);
use Parse::Pidl::NDR qw(GetElementLevelTable ParseElement align_type mapToScalar ParseType);
# Case 1
@ -203,3 +203,27 @@ $e = {
$ne = ParseElement($e, undef);
is($ne->{REPRESENTATION_TYPE}, "uint8");
is(align_type("hyper"), 8);
is(align_type("uint32"), 4);
is(align_type("uint16"), 2);
is(align_type("uint8"), 1);
is(align_type({ TYPE => "STRUCT", "NAME" => "bla",
ELEMENTS => [ { TYPE => "uint16" } ] }), 4);
is(align_type({ TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "hyper" } ] }), 8);
is(align_type({ TYPE => "DECLARE", DATA => {
TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "hyper" } ] }}), 8);
is(align_type({ TYPE => "STRUCT", "NAME" => "bla",
ELEMENTS => [ { TYPE => "uint8" } ] }), 4);
is(mapToScalar("someverymuchnotexistingtype"), undef);
is(mapToScalar("uint32"), "uint32");
is(mapToScalar({TYPE => "ENUM", PARENT => { PROPERTIES => { enum8bit => 1 } } }), "uint8");
is(mapToScalar({TYPE => "BITMAP", PROPERTIES => { bitmap64bit => 1 } }),
"hyper");
is(mapToScalar({TYPE => "TYPEDEF", DATA => {TYPE => "ENUM", PARENT => { PROPERTIES => { enum8bit => 1 } } }}), "uint8");
is_deeply(ParseType({TYPE => "STRUCT", NAME => "foo" }, "ref"),
{TYPE => "STRUCT", NAME => "foo" });

View File

@ -3,7 +3,7 @@
# (C) 2005 Jelmer Vernooij. Published under the GNU GPL
use strict;
use Test::More tests => 1 * 8;
use Test::More tests => 3 * 8;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util qw(test_samba4_ndr);
@ -17,7 +17,46 @@ test_samba4_ndr('struct-notypedef', '[public] struct bla { uint8 x; }; ',
DATA_BLOB result_blob;
r.x = 13;
if (NT_STATUS_IS_ERR(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
if (NT_STATUS_IS_ERR(ndr_push_STRUCT_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
return 1;
result_blob = ndr_push_blob(ndr);
if (!data_blob_equal(&result_blob, &expected_blob))
return 2;
');
test_samba4_ndr('struct-notypedef-used', '[public] struct bla { uint8 x; };
[public] void myfn([in] struct bla r); ',
'
struct ndr_push *ndr = ndr_push_init_ctx(NULL);
struct bla r;
uint8_t expected[] = { 0x0D };
DATA_BLOB expected_blob = { expected, 1 };
DATA_BLOB result_blob;
r.x = 13;
if (NT_STATUS_IS_ERR(ndr_push_myfn(ndr, NDR_IN, &r)))
return 1;
result_blob = ndr_push_blob(ndr);
if (!data_blob_equal(&result_blob, &expected_blob))
return 2;
');
test_samba4_ndr('struct-notypedef-embedded', 'struct bla { uint8 x; };
[public] struct myfn { struct bla r; }; ',
'
struct ndr_push *ndr = ndr_push_init_ctx(NULL);
struct bla r;
uint8_t expected[] = { 0x0D };
DATA_BLOB expected_blob = { expected, 1 };
DATA_BLOB result_blob;
r.x = 13;
if (NT_STATUS_IS_ERR(ndr_push_STRUCT_myfn(ndr, NDR_IN, &r)))
return 1;
result_blob = ndr_push_blob(ndr);

View File

@ -4,7 +4,7 @@
# Published under the GNU General Public License
use strict;
use Test::More tests => 62 * 2;
use Test::More tests => 64 * 2 + 2;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util qw(test_errors);
@ -107,3 +107,18 @@ testfail "import-nosemicolon", "import \"foo.idl\"",
"<import-nosemicolon>:0: Syntax error near 'foo.idl'\n";
testok "import-multiple", "import \"foo.idl\", \"bar.idl\";";
testok "include-multiple", "include \"foo.idl\", \"bar.idl\";";
testok "empty-struct", "interface test { struct foo { }; }";
testok "typedef-double", "interface test { typedef struct foo { } foo; }";
my $x = Parse::Pidl::IDL::parse_string("interface foo { struct x {}; }", "<foo>");
is_deeply($x,
[ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [
{ 'NAME' => 'x', 'TYPE' => 'STRUCT', ELEMENTS => [] } ],
'TYPE' => 'INTERFACE', 'LINE' => 0 } ]);
$x = Parse::Pidl::IDL::parse_string("interface foo { struct x; }", "<foo>");
is_deeply($x,
[ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [
{ 'NAME' => 'x', 'TYPE' => 'STRUCT' } ],
'TYPE' => 'INTERFACE', 'LINE' => 0 } ]);

View File

@ -4,13 +4,13 @@
use strict;
use warnings;
use Test::More tests => 13;
use Test::More tests => 17;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use Parse::Pidl::Util qw(MyDumper);
use Parse::Pidl::Samba4::EJS qw(get_pointer_to get_value_of check_null_pointer
$res $res_hdr fn_declare);
$res $res_hdr fn_declare TypeFunctionName);
is("&foo", get_pointer_to("foo"));
is("&(&foo)", get_pointer_to(get_pointer_to("foo")));
@ -40,3 +40,8 @@ $res_hdr = "";
fn_declare({ PROPERTIES => {} }, "mybla(int foo)");
is($res, "static mybla(int foo)\n");
is($res_hdr, "");
is(TypeFunctionName("ejs_pull", "uint32"), "ejs_pull_uint32");
is(TypeFunctionName("ejs_pull", {TYPE => "ENUM", NAME => "bar"}), "ejs_pull_ENUM_bar");
is(TypeFunctionName("ejs_pull", {TYPE => "TYPEDEF", NAME => "bar", DATA => undef}), "ejs_pull_bar");
is(TypeFunctionName("ejs_push", {TYPE => "STRUCT", NAME => "bar"}), "ejs_push_STRUCT_bar");

View File

@ -4,7 +4,7 @@
use strict;
use warnings;
use Test::More tests => 34;
use Test::More tests => 41;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
@ -12,7 +12,7 @@ use Parse::Pidl::Util qw(MyDumper);
use Parse::Pidl::Samba4::NDR::Parser qw(check_null_pointer
GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv
EnvSubstituteValue NeededFunction NeededElement NeededType $res
NeededInterface);
NeededInterface TypeFunctionName ParseElementPrint);
my $output;
sub print_fn($) { my $x = shift; $output.=$x; }
@ -185,28 +185,28 @@ is_deeply($env, { foo => 0, this => "r" });
my $needed = {};
NeededElement({ TYPE => "foo", REPRESENTATION_TYPE => "foo" }, "pull", $needed);
is_deeply($needed, { pull_foo => 1 });
is_deeply($needed, { ndr_pull_foo => 1 });
# old settings should be kept
$needed = { pull_foo => 0 };
$needed = { ndr_pull_foo => 0 };
NeededElement({ TYPE => "foo", REPRESENTATION_TYPE => "foo" }, "pull", $needed);
is_deeply($needed, { pull_foo => 0 });
is_deeply($needed, { ndr_pull_foo => 0 });
# print/pull/push are independent of each other
$needed = { pull_foo => 0 };
$needed = { ndr_pull_foo => 0 };
NeededElement({ TYPE => "foo", REPRESENTATION_TYPE => "foo" }, "print", $needed);
is_deeply($needed, { pull_foo => 0, print_foo => 1 });
is_deeply($needed, { ndr_pull_foo => 0, ndr_print_foo => 1 });
$needed = { };
NeededFunction({ NAME => "foo", ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "bar" } ] }, $needed);
is_deeply($needed, { pull_foo => 1, print_foo => 1, push_foo => 1,
pull_bar => 1, print_bar => 1, push_bar => 1});
is_deeply($needed, { ndr_pull_foo => 1, ndr_print_foo => 1, ndr_push_foo => 1,
ndr_pull_bar => 1, ndr_print_bar => 1, ndr_push_bar => 1});
# push/pull/print are always set for functions
$needed = { pull_foo => 0 };
$needed = { ndr_pull_foo => 0 };
NeededFunction({ NAME => "foo", ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "bar" } ] }, $needed);
is_deeply($needed, { pull_foo => 1, print_foo => 1, push_foo => 1,
pull_bar => 1, push_bar => 1, print_bar => 1});
is_deeply($needed, { ndr_pull_foo => 1, ndr_print_foo => 1, ndr_push_foo => 1,
ndr_pull_bar => 1, ndr_push_bar => 1, ndr_print_bar => 1});
# public structs are always needed
$needed = {};
@ -220,7 +220,7 @@ NeededInterface({ TYPES => [ { PROPERTIES => { public => 1 }, NAME => "bla",
TYPE => "TYPEDEF",
DATA => { TYPE => "STRUCT", ELEMENTS => [] } } ] },
$needed);
is_deeply($needed, { pull_bla => 1, push_bla => 1, print_bla => 1 });
is_deeply($needed, { ndr_pull_bla => 1, ndr_push_bla => 1, ndr_print_bla => 1 });
# make sure types for elements are set too
$needed = {};
@ -229,8 +229,8 @@ NeededInterface({ TYPES => [ { PROPERTIES => { public => 1 }, NAME => "bla",
DATA => { TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "bar" } ] } } ] },
$needed);
is_deeply($needed, { pull_bla => 1, pull_bar => 1, push_bla => 1, push_bar => 1,
print_bla => 1, print_bar => 1});
is_deeply($needed, { ndr_pull_bla => 1, ndr_pull_bar => 1, ndr_push_bla => 1, ndr_push_bar => 1,
ndr_print_bla => 1, ndr_print_bar => 1});
$needed = {};
NeededInterface({ TYPES => [ { PROPERTIES => { gensize => 1}, NAME => "bla",
@ -241,13 +241,13 @@ NeededInterface({ TYPES => [ { PROPERTIES => { gensize => 1}, NAME => "bla",
is_deeply($needed, { ndr_size_bla => 1 });
# make sure types for elements are set too
$needed = { pull_bla => 1 };
$needed = { ndr_pull_bla => 1 };
NeededType({ NAME => "bla",
TYPE => "TYPEDEF",
DATA => { TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "bar" } ] } },
$needed, "pull");
is_deeply($needed, { pull_bla => 1, pull_bar => 1 });
is_deeply($needed, { ndr_pull_bla => 1, ndr_pull_bar => 1 });
$needed = {};
NeededInterface({ TYPES => [ { PROPERTIES => { public => 1},
@ -255,8 +255,9 @@ NeededInterface({ TYPES => [ { PROPERTIES => { public => 1},
TYPE => "TYPEDEF",
DATA => { TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "rep" } ] } } ] }, $needed);
is_deeply($needed, { pull_bla => 1, push_bla => 1, print_bla => 1, print_rep => 1,
pull_bar => 1, push_bar => 1,
is_deeply($needed, { ndr_pull_bla => 1, ndr_push_bla => 1, ndr_print_bla => 1,
ndr_print_rep => 1,
ndr_pull_bar => 1, ndr_push_bar => 1,
ndr_bar_to_rep => 1, ndr_rep_to_bar => 1});
$res = "";
@ -297,3 +298,28 @@ is($res, "if (ndr_flags & NDR_SCALARS) {
if (ndr_flags & NDR_BUFFERS) {
}
");
is(TypeFunctionName("ndr_pull", "uint32"), "ndr_pull_uint32");
is(TypeFunctionName("ndr_pull", {TYPE => "ENUM", NAME => "bar"}), "ndr_pull_ENUM_bar");
is(TypeFunctionName("ndr_pull", {TYPE => "TYPEDEF", NAME => "bar", DATA => undef}), "ndr_pull_bar");
is(TypeFunctionName("ndr_push", {TYPE => "STRUCT", NAME => "bar"}), "ndr_push_STRUCT_bar");
# check noprint works
$res = "";
ParseElementPrint({ NAME => "x", TYPE => "rt", REPRESENTATION_TYPE => "rt",
PROPERTIES => { noprint => 1},
LEVELS => [ { TYPE => "DATA", DATA_TYPE => "rt"} ]}, "var", { "x" => "r->foobar" } );
is($res, "");
$res = "";
ParseElementPrint({ NAME => "x", TYPE => "rt", REPRESENTATION_TYPE => "rt",
PROPERTIES => {},
LEVELS => [ { TYPE => "DATA", DATA_TYPE => "rt" }]}, "var", { "x" => "r->foobar" } );
is($res, "ndr_print_rt(ndr, \"x\", &var);\n");
# make sure that a print function for an element with value() set works
$res = "";
ParseElementPrint({ NAME => "x", TYPE => "uint32", REPRESENTATION_TYPE => "uint32",
PROPERTIES => { value => "23" },
LEVELS => [ { TYPE => "DATA", DATA_TYPE => "uint32"} ]}, "var", { "x" => "r->foobar" } );
is($res, "ndr_print_uint32(ndr, \"x\", (ndr->flags & LIBNDR_PRINT_SET_VALUES)?23:var);\n");

View File

@ -4,7 +4,7 @@
use strict;
use warnings;
use Test::More tests => 33;
use Test::More tests => 53;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
@ -22,21 +22,45 @@ is("uint32_t", mapScalarType("uint32"));
is("void", mapScalarType("void"));
is("uint64_t", mapScalarType("hyper"));
my $x = { TYPE => "ENUM", NAME => "foo" };
my $x = { TYPE => "ENUM", NAME => "foo", EXTRADATA => 1 };
addType($x);
is($x, getType("foo"));
is_deeply($x, getType("foo"));
is(undef, getType("bloebla"));
is_deeply(getType({ TYPE => "STRUCT" }), { TYPE => "STRUCT" });
is_deeply(getType({ TYPE => "ENUM", NAME => "foo" }), $x);
is_deeply(getType("uint16"), {
NAME => "uint16",
TYPE => "TYPEDEF",
DATA => { NAME => "uint16", TYPE => "SCALAR" }});
is(0, typeIs("someUnknownType", "ENUM"));
is(0, typeIs("foo", "ENUM"));
addType({NAME => "mytypedef", TYPE => "TYPEDEF", DATA => { TYPE => "ENUM" }});
is(1, typeIs("mytypedef", "ENUM"));
is(0, typeIs("mytypedef", "BITMAP"));
is(1, typeIs({ TYPE => "ENUM"}, "ENUM"));
is(0, typeIs({ TYPE => "BITMAP"}, "ENUM"));
is(1, typeIs("uint32", "SCALAR"));
is(0, typeIs("uint32", "ENUM"));
is(1, hasType("foo"));
is(0, hasType("nonexistant"));
is(0, hasType({TYPE => "ENUM", NAME => "someUnknownType"}));
is(1, hasType({TYPE => "ENUM", NAME => "foo"}));
is(1, hasType({TYPE => "ENUM"}));
is(1, hasType({TYPE => "STRUCT"}));
is(1, is_scalar("uint32"));
is(0, is_scalar("nonexistant"));
is(1, is_scalar({TYPE => "ENUM"}));
is(0, is_scalar({TYPE => "STRUCT"}));
is(1, is_scalar({TYPE => "TYPEDEF", DATA => {TYPE => "ENUM" }}));
is(1, is_scalar("mytypedef"));
is(1, is_scalar({TYPE => "DECLARE", DATA => {TYPE => "ENUM" }}));
is(1, scalar_is_reference("string"));
is(0, scalar_is_reference("uint32"));
is(0, scalar_is_reference({TYPE => "STRUCT", NAME => "echo_foobar"}));
is("uint8", enum_type_fn({TYPE => "ENUM", PARENT=>{PROPERTIES => {enum8bit => 1}}}));
is("uint32", enum_type_fn({TYPE => "ENUM", PARENT=>{PROPERTIES => {v1_enum => 1}}}));

View File

@ -5,12 +5,12 @@
use strict;
use warnings;
use Test::More tests => 13;
use Test::More tests => 40;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use Parse::Pidl::Util qw(MyDumper);
use Parse::Pidl::Wireshark::NDR qw(field2name %res PrintIdl StripPrefixes %hf_used RegisterInterfaceHandoff $conformance register_hf_field CheckUsed);
use Parse::Pidl::Wireshark::NDR qw(field2name %res PrintIdl StripPrefixes %hf_used RegisterInterfaceHandoff $conformance register_hf_field CheckUsed ProcessImport ProcessInclude find_type DumpEttList DumpEttDeclaration DumpHfList DumpHfDeclaration DumpFunctionTable register_type @ett register_ett);
is("Access Mask", field2name("access_mask"));
is("Accessmask", field2name("AccessMask"));
@ -45,7 +45,8 @@ is($res{code}, 'void proto_reg_handoff_dcerpc_bla(void)
is($hf_used{hf_bla_opnum}, 1);
$conformance = {};
register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef);
is("hf_bla_idx",
register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef));
is_deeply($conformance, {
header_fields => {
"hf_bla_idx" => {
@ -63,6 +64,61 @@ is_deeply($conformance, {
fielddescription => {}
});
$conformance = { fielddescription => { hf_bla_idx => { DESCRIPTION => "Some Description" }}};
is("hf_bla_idx",
register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef));
is_deeply($conformance, {
fielddescription => {
hf_bla_idx => {
DESCRIPTION => "Some Description",
USED => 1
}
},
header_fields => {
"hf_bla_idx" => {
INDEX => "hf_bla_idx",
NAME => "bla",
FILTER => "my.filter",
BASE_TYPE => "BASE_HEX",
FT_TYPE => "FT_UINT32",
VALSSTRING => "NULL",
BLURB => "Some Description",
MASK => 0xF
}
},
hf_renames => {},
});
$conformance = { fielddescription => { hf_bla_idx => { DESCRIPTION => "Some Description" }}};
is("hf_bla_idx",
register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF,
"Actual Description"));
is_deeply($conformance, {
fielddescription => {
hf_bla_idx => { DESCRIPTION => "Some Description" }
},
header_fields => {
"hf_bla_idx" => {
INDEX => "hf_bla_idx",
NAME => "bla",
FILTER => "my.filter",
BASE_TYPE => "BASE_HEX",
FT_TYPE => "FT_UINT32",
VALSSTRING => "NULL",
BLURB => "Actual Description",
MASK => 0xF
}
},
hf_renames => {},
});
$conformance = { hf_renames => { "hf_bla_idx" => { NEWNAME => "hf_bloe_idx" } } };
register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef);
is_deeply($conformance, {
hf_renames => { hf_bla_idx => { USED => 1, NEWNAME => "hf_bloe_idx" } } });
%hf_used = ( hf_bla => 1 );
test_warnings("", sub {
CheckUsed({ header_fields => { foo => { INDEX => "hf_bla" }}})});
@ -70,3 +126,149 @@ test_warnings("", sub {
%hf_used = ( );
test_warnings("hf field `hf_bla' not used\n", sub {
CheckUsed({ header_fields => { foo => { INDEX => "hf_bla" }}})});
test_warnings("hf field `hf_id' not used\n",
sub { CheckUsed({
hf_renames => {
hf_id => {
OLDNAME => "hf_id",
NEWNAME => "hf_newid",
USED => 0
}
}
}); } );
test_warnings("dissector param never used\n",
sub { CheckUsed({
dissectorparams => {
dissect_foo => {
PARAM => 42,
USED => 0
}
}
}); } );
test_warnings("description never used\n",
sub { CheckUsed({
fielddescription => {
hf_bla => {
USED => 0
}
}
}); } );
test_warnings("import never used\n",
sub { CheckUsed({
imports => {
bla => {
USED => 0
}
}
}); } );
test_warnings("nofile:1: type never used\n",
sub { CheckUsed({
types => {
bla => {
USED => 0,
POS => { FILE => "nofile", LINE => 1 }
}
}
}); } );
test_warnings("True/False description never used\n",
sub { CheckUsed({
tfs => {
hf_bloe => {
USED => 0
}
}
}); } );
$res{hdr} = "";
ProcessImport("security", "bla");
is($res{hdr}, "#include \"packet-dcerpc-bla.h\"\n\n");
$res{hdr} = "";
ProcessImport("\"bla.idl\"", "\"foo.idl\"");
is($res{hdr}, "#include \"packet-dcerpc-bla.h\"\n" .
"#include \"packet-dcerpc-foo.h\"\n\n");
$res{hdr} = "";
ProcessInclude("foo.h", "bla.h", "bar.h");
is($res{hdr}, "#include \"foo.h\"\n" .
"#include \"bla.h\"\n" .
"#include \"bar.h\"\n\n");
$conformance = {types => { bla => "brainslug" } };
is("brainslug", find_type("bla"));
is(DumpEttList("ett_t1", "ett_bla"),
"\tstatic gint *ett[] = {\n" .
"\t\t&ett_t1,\n" .
"\t\t&ett_bla,\n" .
"\t};\n");
is(DumpEttList(), "\tstatic gint *ett[] = {\n\t};\n");
is(DumpEttList("bla"), "\tstatic gint *ett[] = {\n\t\t&bla,\n\t};\n");
is(DumpEttDeclaration("void", "zoid"),
"\n/* Ett declarations */\n" .
"static gint void = -1;\n" .
"static gint zoid = -1;\n" .
"\n");
is(DumpEttDeclaration(), "\n/* Ett declarations */\n\n");
$conformance = {
header_fields => {
hf_bla => { INDEX => "hf_bla", NAME => "Bla", FILTER => "bla.field", FT_TYPE => "FT_UINT32", BASE_TYPE => "BASE_DEC", VALSSTRING => "NULL", MASK => 0xFF, BLURB => "NULL" }
}
};
is(DumpHfList(), "\tstatic hf_register_info hf[] = {
{ &hf_bla,
{ \"Bla\", \"bla.field\", FT_UINT32, BASE_DEC, NULL, 255, \"NULL\", HFILL }},
};
");
is(DumpHfDeclaration(), "
/* Header field declarations */
static gint hf_bla = -1;
");
is(DumpFunctionTable({
NAME => "someif",
FUNCTIONS => [ { NAME => "fn1", OPNUM => 3 }, { NAME => "someif_fn2", OPNUM => 2 } ] }),
'static dcerpc_sub_dissector someif_dissectors[] = {
{ 3, "fn1",
someif_dissect_fn1_request, someif_dissect_fn1_response},
{ 2, "fn2",
someif_dissect_fn2_request, someif_dissect_fn2_response},
{ 0, NULL, NULL, NULL }
};
');
$conformance = {};
register_type("bla_type", "dissect_bla", "FT_UINT32", "BASE_HEX", 0xFF, "NULL", 4);
is_deeply($conformance, {
types => {
bla_type => {
NAME => "bla_type",
DISSECTOR_NAME => "dissect_bla",
FT_TYPE => "FT_UINT32",
BASE_TYPE => "BASE_HEX",
MASK => 255,
VALSSTRING => "NULL",
ALIGNMENT => 4
}
}
}
);
@ett = ();
register_ett("name");
is_deeply(\@ett, ["name"]);
register_ett("leela");
is_deeply(\@ett, ["name", "leela"]);