Note: make test for the following update generates 1 error:

---------
tests/header..............NOK 14#   Failed test 'struct declaration'
#   in tests/header.pl at line 49.
#                   '/* header auto-generated by pidl */
#
# #include <core.h>
# #include <stdint.h>
#
# #ifndef _HEADER_p
# #define _HEADER_p
#
# struct x#endif /* _HEADER_p */
# '
#     doesn't match '(?ms-xi:struct x;)'
# Looks like you failed 1 test of 15.
tests/header..............dubious
        Test returned status 1 (wstat 256, 0x100)
DIED. FAILED test 14
---------

Update from samba tree revision 22314 to 22657
============================ Samba log start ============
------------------------------------------------------------------------
r22357 | jelmer | 2007-04-19 03:26:15 +0200 (Thu, 19 Apr 2007) | 2 lines
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/ClientNDR.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/NDR/Parser.pm
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/TDR.pm
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Wireshark/NDR.pm
   M /branches/SAMBA_4_0/source/pidl/tests/wireshark-ndr.pl

Don't use 'our'

------------------------------------------------------------------------
r22453 | jelmer | 2007-04-22 12:42:33 +0200 (Sun, 22 Apr 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/TDR.pm
   M /branches/SAMBA_4_0/source/pidl/tests/tdr.pl

Fix TDR testsuite without using our.
------------------------------------------------------------------------
r22456 | jelmer | 2007-04-22 15:57:07 +0200 (Sun, 22 Apr 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/lib/Parse/Pidl/Wireshark/NDR.pm
   M /branches/SAMBA_4_0/source/pidl/pidl
   M /branches/SAMBA_4_0/source/pidl/tests/samba-ejs.pl
   M /branches/SAMBA_4_0/source/pidl/tests/wireshark-ndr.pl

Merge wireshark and ejs test improvements.
------------------------------------------------------------------------
r22457 | jelmer | 2007-04-22 16:19:22 +0200 (Sun, 22 Apr 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
   M /branches/SAMBA_4_0/source/pidl/pidl
   M /branches/SAMBA_4_0/source/pidl/tests/samba3-cli.pl

Fix tests for Samba3 client generator.
------------------------------------------------------------------------
r22462 | jelmer | 2007-04-22 17:59:34 +0200 (Sun, 22 Apr 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/pidl
   M /branches/SAMBA_4_0/source/pidl/tests/Util.pm
   M /branches/SAMBA_4_0/source/pidl/tests/samba-ndr.pl

Fix test suite for ndr parser without using 'our'
------------------------------------------------------------------------
r22520 | jelmer | 2007-04-25 18:10:54 +0200 (Wed, 25 Apr 2007) | 1 line
Changed paths:
   M /branches/SAMBA_4_0
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Wireshark/NDR.pm
   M /branches/SAMBA_4_0/source/pidl/tests/wireshark-conf.pl

Fix the TYPE command.
------------------------------------------------------------------------
r22617 | metze | 2007-05-01 03:57:17 +0200 (Tue, 01 May 2007) | 4 lines
Changed paths:
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/NDR.pm

assume we have defered elements if the type is just provides via
'declare' this should fix the problem with the winbind IRPC calls

metze
------------------------------------------------------------------------
r22618 | metze | 2007-05-01 04:00:57 +0200 (Tue, 01 May 2007) | 8 lines
Changed paths:
   M /branches/SAMBA_4_0/source/pidl/idl.yp
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/IDL.pm

handle the properties related to the type
and not to 'declare' to avoid a pidl warning with:

declare [switch_type(uint16)] union netr_Validation;

void foo([in] uint16 level, [in,switch_is(level)] netrValidation info);

metze
------------------------------------------------------------------------
r22640 | metze | 2007-05-02 20:00:02 +0200 (Wed, 02 May 2007) | 4 lines
Changed paths:
   M /branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Header.pm

- generate nicer output
- fix compiler warning about unused ';'

metze
------------------------------------------------------------------------
------------------------------------------------------------------------
============================ Samba log end ==============

svn path=/trunk/; revision=21671
This commit is contained in:
Jörg Mayer 2007-05-03 21:56:22 +00:00
parent 98cb9db12d
commit 904640fdb4
18 changed files with 2591 additions and 2545 deletions

View File

@ -122,12 +122,11 @@ function: property_list type identifier '(' element_list2 ')' ';'
}}
;
declare: 'declare' property_list decl_type identifier';'
declare: 'declare' decl_type identifier';'
{{
"TYPE" => "DECLARE",
"PROPERTIES" => $_[2],
"NAME" => $_[4],
"DATA" => $_[3],
"NAME" => $_[3],
"DATA" => $_[2],
"FILE" => $_[0]->YYData->{FILE},
"LINE" => $_[0]->YYData->{LINE},
}}
@ -136,21 +135,24 @@ declare: 'declare' property_list decl_type identifier';'
decl_type: decl_enum | decl_bitmap | decl_union
;
decl_enum: 'enum'
decl_enum: property_list 'enum'
{{
"TYPE" => "ENUM"
"TYPE" => "ENUM",
"PROPERTIES" => $_[1]
}}
;
decl_bitmap: 'bitmap'
decl_bitmap: property_list 'bitmap'
{{
"TYPE" => "BITMAP"
"TYPE" => "BITMAP",
"PROPERTIES" => $_[1]
}}
;
decl_union: 'union'
decl_union: property_list 'union'
{{
"TYPE" => "UNION"
"TYPE" => "UNION",
"PROPERTIES" => $_[1]
}}
;

File diff suppressed because it is too large Load Diff

View File

@ -281,6 +281,8 @@ sub can_contain_deferred($)
my $type = getType($e->{TYPE});
return 1 if ($type->{TYPE} eq "DECLARE"); # assume the worst
foreach my $x (@{$type->{DATA}->{ELEMENTS}}) {
return 1 if ($x->{POINTERS});
return 1 if (can_contain_deferred ($x));

View File

@ -20,14 +20,18 @@ use Parse::Pidl::Samba4 qw(DeclLong);
use vars qw($VERSION);
$VERSION = '0.01';
our $res;
our $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 fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; }
sub indent($) { my ($self) = @_; $self->{tabs}.="\t"; }
sub deindent($) { my ($self) = @_; $self->{tabs} = substr($self->{tabs}, 1); }
sub pidl($$) { my ($self,$txt) = @_; $self->{res} .= "$self->{tabs}$txt\n"; }
sub pidl_hdr($$) { my ($self, $txt) = @_; $self->{res_hdr} .= "$txt\n"; }
sub fn_declare($$) { my ($self,$n) = @_; $self->pidl($n); $self->pidl_hdr("$n;"); }
sub new($)
{
my ($class) = shift;
my $self = { res => "", res_hdr => "", tabs => "" };
bless($self, $class);
}
sub GenerateFunctionInEnv($)
{
@ -43,9 +47,9 @@ sub GenerateFunctionInEnv($)
return \%env;
}
sub ParseFunction($$)
sub ParseFunction($$$)
{
my ($uif, $fn) = @_;
my ($self, $uif, $fn) = @_;
my $inargs = "";
my $defargs = "";
@ -54,42 +58,42 @@ sub ParseFunction($$)
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 */";
$self->fn_declare("NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)");
$self->pidl("{");
$self->indent;
$self->pidl("struct $fn->{NAME} r;");
$self->pidl("NTSTATUS status;");
$self->pidl("");
$self->pidl("/* In parameters */");
foreach (@{$fn->{ELEMENTS}}) {
if (grep(/in/, @{$_->{DIRECTION}})) {
pidl "r.in.$_->{NAME} = $_->{NAME};";
$self->pidl("r.in.$_->{NAME} = $_->{NAME};");
}
}
pidl "";
pidl "if (DEBUGLEVEL >= 10)";
pidl "\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);";
pidl "";
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 "";
$self->pidl("");
$self->pidl("if (DEBUGLEVEL >= 10)");
$self->pidl("\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);");
$self->pidl("");
$self->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});");
$self->pidl("");
pidl "if (!NT_STATUS_IS_OK(status)) {";
indent;
pidl "return status;";
deindent;
pidl "}";
$self->pidl("if (!NT_STATUS_IS_OK(status)) {");
$self->indent;
$self->pidl("return status;");
$self->deindent;
$self->pidl("}");
pidl "";
pidl "if (DEBUGLEVEL >= 10)";
pidl "\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);";
pidl "";
pidl "if (NT_STATUS_IS_ERR(status)) {";
pidl "\treturn status;";
pidl "}";
pidl "";
pidl "/* Return variables */";
$self->pidl("");
$self->pidl("if (DEBUGLEVEL >= 10)");
$self->pidl("\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);");
$self->pidl("");
$self->pidl("if (NT_STATUS_IS_ERR(status)) {");
$self->pidl("\treturn status;");
$self->pidl("}");
$self->pidl("");
$self->pidl("/* Return variables */");
foreach my $e (@{$fn->{ELEMENTS}}) {
next unless (grep(/out/, @{$e->{DIRECTION}}));
@ -97,8 +101,8 @@ sub ParseFunction($$)
if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") and
($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") ) {
pidl "if ( $e->{NAME} ) {";
indent;
$self->pidl("if ( $e->{NAME} ) {");
$self->indent;
}
if ($e->{LEVELS}[0]->{TYPE} eq "ARRAY") {
@ -108,70 +112,67 @@ sub ParseFunction($$)
# to allocate a structure of the right size.
my $env = GenerateFunctionInEnv($fn);
my $size_is = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env, $e);
pidl "memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is);";
$self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is);");
} else {
pidl "*$e->{NAME} = *r.out.$e->{NAME};";
$self->pidl("*$e->{NAME} = *r.out.$e->{NAME};");
}
if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") and
($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") ) {
deindent;
pidl "}";
$self->deindent;
$self->pidl("}");
}
}
pidl"";
pidl "/* Return result */";
$self->pidl("");
$self->pidl("/* Return result */");
if (not $fn->{RETURN_TYPE}) {
pidl "return NT_STATUS_OK;";
$self->pidl("return NT_STATUS_OK;");
} elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") {
pidl "return r.out.result;";
$self->pidl("return r.out.result;");
} elsif ($fn->{RETURN_TYPE} eq "WERROR") {
pidl "return werror_to_ntstatus(r.out.result);";
$self->pidl("return werror_to_ntstatus(r.out.result);");
} else {
warning($fn->{ORIGINAL}, "Unable to convert $fn->{RETURN_TYPE} to NTSTATUS");
pidl "return NT_STATUS_OK;";
$self->pidl("return NT_STATUS_OK;");
}
deindent;
pidl "}";
pidl "";
$self->deindent;
$self->pidl("}");
$self->pidl("");
}
sub ParseInterface($)
sub ParseInterface($$)
{
my $if = shift;
my ($self, $if) = @_;
my $uif = uc($if->{NAME});
pidl_hdr "#ifndef __CLI_$uif\__";
pidl_hdr "#define __CLI_$uif\__";
ParseFunction(uc($if->{NAME}), $_) foreach (@{$if->{FUNCTIONS}});
pidl_hdr "#endif /* __CLI_$uif\__ */";
$self->pidl_hdr("#ifndef __CLI_$uif\__");
$self->pidl_hdr("#define __CLI_$uif\__");
$self->ParseFunction(uc($if->{NAME}), $_) foreach (@{$if->{FUNCTIONS}});
$self->pidl_hdr("#endif /* __CLI_$uif\__ */");
}
sub Parse($$$)
sub Parse($$$$)
{
my($ndr,$header,$ndr_header) = @_;
my($self,$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 "";
$self->pidl("/*");
$self->pidl(" * Unix SMB/CIFS implementation.");
$self->pidl(" * client auto-generated by pidl. DO NOT MODIFY!");
$self->pidl(" */");
$self->pidl("");
$self->pidl("#include \"includes.h\"");
$self->pidl("#include \"$header\"");
$self->pidl_hdr("#include \"$ndr_header\"");
$self->pidl("");
foreach (@$ndr) {
ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");
$self->ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");
}
return ($res, $res_hdr);
return ($self->{res}, $self->{res_hdr});
}
1;

File diff suppressed because it is too large Load Diff

View File

@ -43,7 +43,7 @@ sub HeaderProperties($$)
}
if ($ret) {
pidl "/* [" . substr($ret, 0, -1) . "] */";
pidl " /* [" . substr($ret, 0, -1) . "] */";
}
}
@ -108,10 +108,12 @@ sub HeaderStruct($$)
pidl tabs()."char _empty_;\n";
}
$tab_depth--;
pidl tabs()."}";
pidl "};";
if (defined $struct->{PROPERTIES}) {
HeaderProperties($struct->{PROPERTIES}, []);
}
pidl "\n\n";
}
#####################################################################
@ -132,10 +134,10 @@ sub HeaderEnum($$)
}
pidl "\n";
$tab_depth--;
pidl "}\n";
pidl "};\n";
pidl "#else\n";
my $count = 0;
pidl "enum $name { __donnot_use_enum_$name=0x7FFFFFFF}\n";
pidl "enum $name { __donnot_use_enum_$name=0x7FFFFFFF};\n";
my $with_val = 0;
my $without_val = 0;
foreach my $e (@{$enum->{ELEMENTS}}) {
@ -191,11 +193,12 @@ sub HeaderUnion($$)
}
}
$tab_depth--;
pidl "}";
pidl "};";
if (defined $union->{PROPERTIES}) {
HeaderProperties($union->{PROPERTIES}, []);
}
pidl "\n\n";
}
#####################################################################
@ -297,7 +300,7 @@ sub HeaderFunction($)
HeaderFunctionInOut($fn, "in");
HeaderFunctionInOut($fn, "inout");
$tab_depth--;
pidl tabs()."} in;\n\n";
pidl tabs()."} in;\n";
$needed++;
}
@ -311,7 +314,7 @@ sub HeaderFunction($)
pidl tabs().mapTypeName($fn->{RETURN_TYPE}) . " result;\n";
}
$tab_depth--;
pidl tabs()."} out;\n\n";
pidl tabs()."} out;\n";
$needed++;
}
@ -362,11 +365,6 @@ sub HeaderInterface($)
HeaderUnion($d, $d->{NAME}) if ($d->{TYPE} eq "UNION");
HeaderEnum($d, $d->{NAME}) if ($d->{TYPE} eq "ENUM");
HeaderBitmap($d, $d->{NAME}) if ($d->{TYPE} eq "BITMAP");
pidl ";\n\n" if ($d->{TYPE} eq "BITMAP" or
$d->{TYPE} eq "STRUCT" or
$d->{TYPE} eq "TYPEDEF" or
$d->{TYPE} eq "UNION" or
$d->{TYPE} eq "ENUM");
}
foreach my $d (@{$interface->{DATA}}) {

File diff suppressed because it is too large Load Diff

View File

@ -17,14 +17,16 @@ $VERSION = '0.01';
use strict;
our $ret;
our $ret_hdr;
my $tabs = "";
sub new($) {
my ($class) = shift;
my $self = { ret => "", ret_hdr => "", tabs => "" };
bless($self, $class);
}
sub indent() { $tabs.="\t"; }
sub deindent() { $tabs = substr($tabs, 1); }
sub pidl($) { $ret .= $tabs.(shift)."\n"; }
sub pidl_hdr($) { $ret_hdr .= (shift)."\n"; }
sub indent($) { my $self = shift; $self->{tabs}.="\t"; }
sub deindent($) { my $self = shift; $self->{tabs} = substr($self->{tabs}, 1); }
sub pidl($$) { my $self = shift; $self->{ret} .= $self->{tabs}.(shift)."\n"; }
sub pidl_hdr($$) { my $self = shift; $self->{ret_hdr} .= (shift)."\n"; }
sub typearg($) {
my $t = shift;
return(", const char *name") if ($t eq "print");
@ -32,10 +34,14 @@ sub typearg($) {
return("");
}
sub fn_declare($$)
sub fn_declare($$$)
{
my ($p, $d) = @_;
if ($p) { pidl $d; pidl_hdr "$d;"; } else { pidl "static $d"; }
my ($self, $p, $d) = @_;
if ($p) {
$self->pidl($d); $self->pidl_hdr("$d;");
} else {
$self->pidl("static $d");
}
}
sub ContainsArray($)
@ -50,9 +56,9 @@ sub ContainsArray($)
return 0;
}
sub ParserElement($$$)
sub ParserElement($$$$)
{
my ($e,$t,$env) = @_;
my ($self, $e,$t,$env) = @_;
my $switch = "";
my $array = "";
my $name = "";
@ -67,10 +73,10 @@ sub ParserElement($$$)
}
if (has_property($e, "flag")) {
pidl "{";
indent;
pidl "uint32_t saved_flags = tdr->flags;";
pidl "tdr->flags |= $e->{PROPERTIES}->{flag};";
$self->pidl("{");
$self->indent;
$self->pidl("uint32_t saved_flags = tdr->flags;");
$self->pidl("tdr->flags |= $e->{PROPERTIES}->{flag};");
}
if (has_property($e, "charset")) {
@ -79,7 +85,7 @@ sub ParserElement($$$)
my $len = ParseExpr(@{$e->{ARRAY_LEN}}[0], $env, $e);
if ($len eq "*") { $len = "-1"; }
$name = ", mem_ctx" if ($t eq "pull");
pidl "TDR_CHECK(tdr_$t\_charset(tdr$name, &v->$e->{NAME}, $len, sizeof($e->{TYPE}_t), CH_$e->{PROPERTIES}->{charset}));";
$self->pidl("TDR_CHECK(tdr_$t\_charset(tdr$name, &v->$e->{NAME}, $len, sizeof($e->{TYPE}_t), CH_$e->{PROPERTIES}->{charset}));");
return;
}
@ -91,12 +97,12 @@ sub ParserElement($$$)
my $len = ParseExpr($e->{ARRAY_LEN}[0], $env, $e);
if ($t eq "pull" and not is_constant($len)) {
pidl "TDR_ALLOC(mem_ctx, v->$e->{NAME}, $len);";
$self->pidl("TDR_ALLOC(mem_ctx, v->$e->{NAME}, $len);");
$mem_ctx = "v->$e->{NAME}";
}
pidl "for (i = 0; i < $len; i++) {";
indent;
$self->pidl("for (i = 0; i < $len; i++) {");
$self->indent;
$array = "[i]";
}
@ -105,116 +111,116 @@ sub ParserElement($$$)
}
if (has_property($e, "value") && $t eq "push") {
pidl "v->$e->{NAME} = ".ParseExpr($e->{PROPERTIES}->{value}, $env, $e).";";
$self->pidl("v->$e->{NAME} = ".ParseExpr($e->{PROPERTIES}->{value}, $env, $e).";");
}
pidl "TDR_CHECK(tdr_$t\_$e->{TYPE}(tdr$name$switch, &v->$e->{NAME}$array));";
$self->pidl("TDR_CHECK(tdr_$t\_$e->{TYPE}(tdr$name$switch, &v->$e->{NAME}$array));");
if ($array) { deindent; pidl "}"; }
if ($array) { $self->deindent; $self->pidl("}"); }
if (has_property($e, "flag")) {
pidl "tdr->flags = saved_flags;";
deindent;
pidl "}";
$self->pidl("tdr->flags = saved_flags;");
$self->deindent;
$self->pidl("}");
}
}
sub ParserStruct($$$$)
sub ParserStruct($$$$$)
{
my ($e,$t,$p) = @_;
my ($self, $e,$t,$p) = @_;
fn_declare($p,"NTSTATUS tdr_$t\_$e->{NAME} (struct tdr_$t *tdr".typearg($t).", struct $e->{NAME} *v)");
pidl "{"; indent;
pidl "int i;" if (ContainsArray($e));
$self->fn_declare($p,"NTSTATUS tdr_$t\_$e->{NAME} (struct tdr_$t *tdr".typearg($t).", struct $e->{NAME} *v)");
$self->pidl("{"); $self->indent;
$self->pidl("int i;") if (ContainsArray($e));
if ($t eq "print") {
pidl "tdr->print(tdr, \"\%-25s: struct $e->{NAME}\", name);";
pidl "tdr->level++;";
$self->pidl("tdr->print(tdr, \"\%-25s: struct $e->{NAME}\", name);");
$self->pidl("tdr->level++;");
}
my %env = map { $_->{NAME} => "v->$_->{NAME}" } @{$e->{ELEMENTS}};
$env{"this"} = "v";
ParserElement($_, $t, \%env) foreach (@{$e->{ELEMENTS}});
$self->ParserElement($_, $t, \%env) foreach (@{$e->{ELEMENTS}});
if ($t eq "print") {
pidl "tdr->level--;";
$self->pidl("tdr->level--;");
}
pidl "return NT_STATUS_OK;";
$self->pidl("return NT_STATUS_OK;");
deindent; pidl "}";
$self->deindent; $self->pidl("}");
}
sub ParserUnion($$$)
sub ParserUnion($$$$)
{
my ($e,$t,$p) = @_;
my ($self, $e,$t,$p) = @_;
fn_declare($p,"NTSTATUS tdr_$t\_$e->{NAME}(struct tdr_$t *tdr".typearg($t).", int level, union $e->{NAME} *v)");
pidl "{"; indent;
pidl "int i;" if (ContainsArray($e));
$self->fn_declare($p,"NTSTATUS tdr_$t\_$e->{NAME}(struct tdr_$t *tdr".typearg($t).", int level, union $e->{NAME} *v)");
$self->pidl("{"); $self->indent;
$self->pidl("int i;") if (ContainsArray($e));
if ($t eq "print") {
pidl "tdr->print(tdr, \"\%-25s: union $e->{NAME}\", name);";
pidl "tdr->level++;";
$self->pidl("tdr->print(tdr, \"\%-25s: union $e->{NAME}\", name);");
$self->pidl("tdr->level++;");
}
pidl "switch (level) {"; indent;
$self->pidl("switch (level) {"); $self->indent;
foreach (@{$e->{ELEMENTS}}) {
if (has_property($_, "case")) {
pidl "case " . $_->{PROPERTIES}->{case} . ":";
$self->pidl("case " . $_->{PROPERTIES}->{case} . ":");
} elsif (has_property($_, "default")) {
pidl "default:";
$self->pidl("default:");
}
indent; ParserElement($_, $t, {}); deindent;
pidl "break;";
$self->indent; $self->ParserElement($_, $t, {}); $self->deindent;
$self->pidl("break;");
}
deindent; pidl "}";
$self->deindent; $self->pidl("}");
if ($t eq "print") {
pidl "tdr->level--;";
$self->pidl("tdr->level--;");
}
pidl "return NT_STATUS_OK;\n";
deindent; pidl "}";
$self->pidl("return NT_STATUS_OK;\n");
$self->deindent; $self->pidl("}");
}
sub ParserBitmap($$$)
sub ParserBitmap($$$$)
{
my ($e,$t,$p) = @_;
my ($self,$e,$t,$p) = @_;
return if ($p);
pidl "#define tdr_$t\_$e->{NAME} tdr_$t\_" . Parse::Pidl::Typelist::bitmap_type_fn($e);
$self->pidl("#define tdr_$t\_$e->{NAME} tdr_$t\_" . Parse::Pidl::Typelist::bitmap_type_fn($e));
}
sub ParserEnum($$$)
sub ParserEnum($$$$)
{
my ($e,$t,$p) = @_;
my ($self,$e,$t,$p) = @_;
my $bt = ($e->{PROPERTIES}->{base_type} or "uint8");
fn_declare($p, "NTSTATUS tdr_$t\_$e->{NAME} (struct tdr_$t *tdr".typearg($t).", enum $e->{NAME} *v)");
pidl "{";
$self->fn_declare($p, "NTSTATUS tdr_$t\_$e->{NAME} (struct tdr_$t *tdr".typearg($t).", enum $e->{NAME} *v)");
$self->pidl("{");
if ($t eq "pull") {
pidl "\t$bt\_t r;";
pidl "\tTDR_CHECK(tdr_$t\_$bt(tdr, mem_ctx, \&r));";
pidl "\t*v = r;";
$self->pidl("\t$bt\_t r;");
$self->pidl("\tTDR_CHECK(tdr_$t\_$bt(tdr, mem_ctx, \&r));");
$self->pidl("\t*v = r;");
} elsif ($t eq "push") {
pidl "\tTDR_CHECK(tdr_$t\_$bt(tdr, ($bt\_t *)v));";
$self->pidl("\tTDR_CHECK(tdr_$t\_$bt(tdr, ($bt\_t *)v));");
} elsif ($t eq "print") {
pidl "\t/* FIXME */";
$self->pidl("\t/* FIXME */");
}
pidl "\treturn NT_STATUS_OK;";
pidl "}";
$self->pidl("\treturn NT_STATUS_OK;");
$self->pidl("}");
}
sub ParserTypedef($$$)
sub ParserTypedef($$$$)
{
my ($e,$t,$p) = @_;
my ($self, $e,$t,$p) = @_;
ParserType($e->{DATA},$t);
$self->ParserType($e->{DATA},$t);
}
sub ParserType($$)
sub ParserType($$$)
{
my ($e,$t) = @_;
my ($self, $e,$t) = @_;
return if (has_property($e, "no$t"));
@ -224,53 +230,52 @@ sub ParserType($$)
TYPEDEF => \&ParserTypedef
};
$handlers->{$e->{TYPE}}->($e, $t, has_property($e, "public"))
$handlers->{$e->{TYPE}}->($self, $e, $t, has_property($e, "public"))
if (defined($handlers->{$e->{TYPE}}));
pidl "";
$self->pidl("");
}
sub ParserInterface($)
sub ParserInterface($$)
{
my $x = shift;
my ($self,$x) = @_;
pidl_hdr "#ifndef __TDR_$x->{NAME}_HEADER__";
pidl_hdr "#define __TDR_$x->{NAME}_HEADER__";
$self->pidl_hdr("#ifndef __TDR_$x->{NAME}_HEADER__");
$self->pidl_hdr("#define __TDR_$x->{NAME}_HEADER__");
foreach (@{$x->{DATA}}) {
ParserType($_, "pull");
ParserType($_, "push");
ParserType($_, "print");
$self->ParserType($_, "pull");
$self->ParserType($_, "push");
$self->ParserType($_, "print");
}
pidl_hdr "#endif /* __TDR_$x->{NAME}_HEADER__ */";
$self->pidl_hdr("#endif /* __TDR_$x->{NAME}_HEADER__ */");
}
sub Parser($$$)
sub Parser($$$$)
{
my ($idl,$hdrname,$baseheader) = @_;
$ret = ""; $ret_hdr = "";
pidl "/* autogenerated by pidl */";
my ($self,$idl,$hdrname,$baseheader) = @_;
$self->pidl("/* autogenerated by pidl */");
if (is_intree()) {
pidl "#include \"includes.h\"";
$self->pidl("#include \"includes.h\"");
} else {
pidl "#include <stdio.h>";
pidl "#include <stdbool.h>";
pidl "#include <stdlib.h>";
pidl "#include <stdint.h>";
pidl "#include <stdarg.h>";
pidl "#include <string.h>";
pidl "#include <core/nterr.h>";
$self->pidl("#include <stdio.h>");
$self->pidl("#include <stdbool.h>");
$self->pidl("#include <stdlib.h>");
$self->pidl("#include <stdint.h>");
$self->pidl("#include <stdarg.h>");
$self->pidl("#include <string.h>");
$self->pidl("#include <core/nterr.h>");
}
pidl "#include \"$hdrname\"";
pidl "";
pidl_hdr "/* autogenerated by pidl */";
pidl_hdr "#include \"$baseheader\"";
pidl_hdr choose_header("tdr/tdr.h", "tdr.h");
pidl_hdr "";
$self->pidl("#include \"$hdrname\"");
$self->pidl("");
$self->pidl_hdr("/* autogenerated by pidl */");
$self->pidl_hdr("#include \"$baseheader\"");
$self->pidl_hdr(choose_header("tdr/tdr.h", "tdr.h"));
$self->pidl_hdr("");
foreach (@$idl) { ParserInterface($_) if ($_->{TYPE} eq "INTERFACE"); }
return ($ret_hdr, $ret);
foreach (@$idl) { $self->ParserInterface($_) if ($_->{TYPE} eq "INTERFACE"); }
return ($self->{ret_hdr}, $self->{ret});
}
1;

View File

@ -124,6 +124,12 @@ sub handle_type($$$$$$$$$$)
warning($pos, "invalid BASE_TYPE `$base_type'");
}
$dissectorname =~ s/^\"(.*)\"$/$1/g;
if (not ($dissectorname =~ /;$/)) {
warning($pos, "missing semicolon");
}
$data->{types}->{$name} = {
NAME => $name,
POS => $pos,

File diff suppressed because it is too large Load Diff

View File

@ -645,7 +645,8 @@ sub process_file($)
if (defined($opt_ejs)) {
require Parse::Pidl::Samba4::EJS;
my ($hdr,$prsr) = Parse::Pidl::Samba4::EJS::Parse($ndr, $h_filename);
my $generator = new Parse::Pidl::Samba4::EJS();
my ($hdr,$prsr) = $generator->Parse($ndr, $h_filename);
FileSave("$outputdir/ndr_$basename\_ejs.c", $prsr);
FileSave("$outputdir/ndr_$basename\_ejs.h", $hdr);
}
@ -659,8 +660,8 @@ sub process_file($)
if (defined($opt_ndr_parser)) {
my $parser_fname = ($opt_ndr_parser or "$outputdir/ndr_$basename.c");
require Parse::Pidl::Samba4::NDR::Parser;
my ($header,$parser) = Parse::Pidl::Samba4::NDR::Parser::Parse($ndr, $gen_header, $h_filename);
my $generator = new Parse::Pidl::Samba4::NDR::Parser();
my ($header,$parser) = $generator->Parse($ndr, $gen_header, $h_filename);
FileSave($parser_fname, $parser);
FileSave($h_filename, $header);
@ -675,7 +676,8 @@ sub process_file($)
my $cnffile = $idl_file;
$cnffile =~ s/\.idl$/\.cnf/;
my ($dp, $dh) = Parse::Pidl::Wireshark::NDR::Parse($ndr, $idl_file, $eheader, $cnffile);
my $generator = new Parse::Pidl::Wireshark::NDR();
my ($dp, $dh) = $generator->Parse($ndr, $idl_file, $eheader, $cnffile);
FileSave($eparser, $dp) if defined($dp);
FileSave($eheader, $dh) if defined($dh);
}
@ -685,7 +687,8 @@ sub process_file($)
my $tdr_header = $tdr_parser;
$tdr_header =~ s/\.c$/\.h/;
require Parse::Pidl::Samba4::TDR;
my ($hdr,$prsr) = Parse::Pidl::Samba4::TDR::Parser($pidl, $tdr_header, $gen_header);
my $generator = new Parse::Pidl::Samba4::TDR();
my ($hdr,$prsr) = $generator->Parser($pidl, $tdr_header, $gen_header);
FileSave($tdr_parser, $prsr);
FileSave($tdr_header, $hdr);
}
@ -699,7 +702,8 @@ sub process_file($)
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);
my $generator = new Parse::Pidl::Samba3::ClientNDR();
my ($c_code,$h_code) = $generator->Parse($ndr, $header, $h_filename);
FileSave($client, $c_code);
FileSave($header, $h_code);
}

View File

@ -54,7 +54,8 @@ sub test_samba4_ndr
ok(defined($header), "($name) generate generic header");
my $pndr = Parse::Pidl::NDR::Parse($pidl);
ok(defined($pndr), "($name) generate NDR tree");
my ($ndrheader,$ndrparser) = Parse::Pidl::Samba4::NDR::Parser::Parse($pndr, undef, undef);
my $generator = new Parse::Pidl::Samba4::NDR::Parser();
my ($ndrheader,$ndrparser) = $generator->Parse($pndr, undef, undef);
ok(defined($ndrparser), "($name) generate NDR parser");
ok(defined($ndrheader), "($name) generate NDR header");

View File

@ -10,7 +10,7 @@ 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 TypeFunctionName);
fn_declare TypeFunctionName);
is("&foo", get_pointer_to("foo"));
is("&(&foo)", get_pointer_to(get_pointer_to("foo")));
@ -21,25 +21,24 @@ is("foo", get_value_of("&foo"));
is("*foo", get_value_of("foo"));
is("**foo", get_value_of("*foo"));
$res = "";
check_null_pointer("bla");
is($res, "");
my $ejs = new Parse::Pidl::Samba4::EJS();
$res = "";
check_null_pointer("*bla");
is($res, "if (bla == NULL) return NT_STATUS_INVALID_PARAMETER_MIX;\n");
$ejs->check_null_pointer("bla");
is($ejs->{res}, "");
$res = "";
$res_hdr = "";
fn_declare({ PROPERTIES => { public => 1 } }, "myproto(int x)");
is($res, "_PUBLIC_ myproto(int x)\n");
is($res_hdr, "myproto(int x);\n");
$ejs = new Parse::Pidl::Samba4::EJS();
$ejs->check_null_pointer("*bla");
is($ejs->{res}, "if (bla == NULL) return NT_STATUS_INVALID_PARAMETER_MIX;\n");
$res = "";
$res_hdr = "";
fn_declare({ PROPERTIES => {} }, "mybla(int foo)");
is($res, "static mybla(int foo)\n");
is($res_hdr, "");
$ejs = new Parse::Pidl::Samba4::EJS();
$ejs->fn_declare({ PROPERTIES => { public => 1 } }, "myproto(int x)");
is($ejs->{res}, "_PUBLIC_ myproto(int x)\n");
is($ejs->{res_hdr}, "myproto(int x);\n");
$ejs = new Parse::Pidl::Samba4::EJS();
$ejs->fn_declare({ PROPERTIES => {} }, "mybla(int foo)");
is($ejs->{res}, "static mybla(int foo)\n");
is($ejs->{res_hdr}, "");
is(TypeFunctionName("ejs_pull", "uint32"), "ejs_pull_uint32");
is(TypeFunctionName("ejs_pull", {TYPE => "ENUM", NAME => "bar"}), "ejs_pull_ENUM_bar");

View File

@ -8,10 +8,11 @@ use Test::More tests => 41;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use strict;
use Parse::Pidl::Util qw(MyDumper);
use Parse::Pidl::Samba4::NDR::Parser qw(check_null_pointer
GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv
EnvSubstituteValue NeededFunction NeededElement NeededType $res
EnvSubstituteValue NeededFunction NeededElement NeededType
NeededInterface TypeFunctionName ParseElementPrint);
my $output;
@ -260,21 +261,21 @@ is_deeply($needed, { ndr_pull_bla => 1, ndr_push_bla => 1, ndr_print_bla => 1,
ndr_pull_bar => 1, ndr_push_bar => 1,
ndr_bar_to_rep => 1, ndr_rep_to_bar => 1});
$res = "";
Parse::Pidl::Samba4::NDR::Parser::ParseStructPush({
my $generator = new Parse::Pidl::Samba4::NDR::Parser();
$generator->ParseStructPush({
NAME => "mystruct",
TYPE => "STRUCT",
PROPERTIES => {},
ALIGN => 4,
ELEMENTS => [ ]}, "x");
is($res, "if (ndr_flags & NDR_SCALARS) {
is($generator->{res}, "if (ndr_flags & NDR_SCALARS) {
NDR_CHECK(ndr_push_align(ndr, 4));
}
if (ndr_flags & NDR_BUFFERS) {
}
");
$res = "";
$generator = new Parse::Pidl::Samba4::NDR::Parser();
my $e = {
NAME => "el1",
TYPE => "mytype",
@ -283,14 +284,14 @@ my $e = {
LEVELS => [
{ LEVEL_INDEX => 0, TYPE => "DATA", DATA_TYPE => "mytype" }
] };
Parse::Pidl::Samba4::NDR::Parser::ParseStructPush({
$generator->ParseStructPush({
NAME => "mystruct",
TYPE => "STRUCT",
PROPERTIES => {},
ALIGN => 4,
SURROUNDING_ELEMENT => $e,
ELEMENTS => [ $e ]}, "x");
is($res, "if (ndr_flags & NDR_SCALARS) {
is($generator->{res}, "if (ndr_flags & NDR_SCALARS) {
NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_string_array_size(ndr, x->el1)));
NDR_CHECK(ndr_push_align(ndr, 4));
NDR_CHECK(ndr_push_mytype(ndr, NDR_SCALARS, &x->el1));
@ -305,21 +306,21 @@ is(TypeFunctionName("ndr_pull", {TYPE => "TYPEDEF", NAME => "bar", DATA => undef
is(TypeFunctionName("ndr_push", {TYPE => "STRUCT", NAME => "bar"}), "ndr_push_STRUCT_bar");
# check noprint works
$res = "";
ParseElementPrint({ NAME => "x", TYPE => "rt", REPRESENTATION_TYPE => "rt",
$generator = new Parse::Pidl::Samba4::NDR::Parser();
$generator->ParseElementPrint({ NAME => "x", TYPE => "rt", REPRESENTATION_TYPE => "rt",
PROPERTIES => { noprint => 1},
LEVELS => [ { TYPE => "DATA", DATA_TYPE => "rt"} ]}, "var", { "x" => "r->foobar" } );
is($res, "");
is($generator->{res}, "");
$res = "";
ParseElementPrint({ NAME => "x", TYPE => "rt", REPRESENTATION_TYPE => "rt",
$generator = new Parse::Pidl::Samba4::NDR::Parser();
$generator->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");
is($generator->{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",
$generator = new Parse::Pidl::Samba4::NDR::Parser();
$generator->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");
is($generator->{res}, "ndr_print_uint32(ndr, \"x\", (ndr->flags & LIBNDR_PRINT_SET_VALUES)?23:var);\n");

View File

@ -9,8 +9,7 @@ use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use Parse::Pidl::Util qw(MyDumper);
use Parse::Pidl::Samba3::ClientNDR qw(GenerateFunctionInEnv ParseFunction $res
$res_hdr);
use Parse::Pidl::Samba3::ClientNDR qw(GenerateFunctionInEnv ParseFunction);
# Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work
my $fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
@ -22,9 +21,11 @@ is_deeply({ "foo" => "r.in.foo" }, GenerateFunctionInEnv($fn));
$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] };
is_deeply({ }, GenerateFunctionInEnv($fn));
my $x = new Parse::Pidl::Samba3::ClientNDR();
$fn = { NAME => "bar", ELEMENTS => [ ] };
ParseFunction("foo", $fn);
is($res, "NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx)
$x->ParseFunction("foo", $fn);
is($x->{res}, "NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx)
{
\tstruct bar r;
\tNTSTATUS status;

View File

@ -8,21 +8,23 @@ use Test::More tests => 6;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use Parse::Pidl::Samba4::TDR qw($ret $ret_hdr ParserType);
use Parse::Pidl::Samba4::TDR qw(ParserType);
ParserType({TYPE => "STRUCT", NAME => "foo", PROPERTIES => {public => 1}}, "pull");
is($ret, "NTSTATUS tdr_pull_foo (struct tdr_pull *tdr, TALLOC_CTX *mem_ctx, struct foo *v)
my $tdr = new Parse::Pidl::Samba4::TDR();
$tdr->ParserType({TYPE => "STRUCT", NAME => "foo", PROPERTIES => {public => 1}}, "pull");
is($tdr->{ret}, "NTSTATUS tdr_pull_foo (struct tdr_pull *tdr, TALLOC_CTX *mem_ctx, struct foo *v)
{
return NT_STATUS_OK;
}
");
is($ret_hdr, "NTSTATUS tdr_pull_foo (struct tdr_pull *tdr, TALLOC_CTX *mem_ctx, struct foo *v);\n");
is($tdr->{ret_hdr}, "NTSTATUS tdr_pull_foo (struct tdr_pull *tdr, TALLOC_CTX *mem_ctx, struct foo *v);\n");
$ret = ""; $ret_hdr = "";
ParserType({TYPE => "UNION", NAME => "bar", PROPERTIES => {public => 1}}, "pull");
is($ret, "NTSTATUS tdr_pull_bar(struct tdr_pull *tdr, TALLOC_CTX *mem_ctx, int level, union bar *v)
$tdr = new Parse::Pidl::Samba4::TDR();
$tdr->ParserType({TYPE => "UNION", NAME => "bar", PROPERTIES => {public => 1}}, "pull");
is($tdr->{ret}, "NTSTATUS tdr_pull_bar(struct tdr_pull *tdr, TALLOC_CTX *mem_ctx, int level, union bar *v)
{
switch (level) {
}
@ -31,12 +33,11 @@ is($ret, "NTSTATUS tdr_pull_bar(struct tdr_pull *tdr, TALLOC_CTX *mem_ctx, int l
}
");
is($ret_hdr, "NTSTATUS tdr_pull_bar(struct tdr_pull *tdr, TALLOC_CTX *mem_ctx, int level, union bar *v);\n");
is($tdr->{ret_hdr}, "NTSTATUS tdr_pull_bar(struct tdr_pull *tdr, TALLOC_CTX *mem_ctx, int level, union bar *v);\n");
$ret = ""; $ret_hdr = "";
ParserType({TYPE => "UNION", NAME => "bar", PROPERTIES => {}}, "pull");
is($ret, "static NTSTATUS tdr_pull_bar(struct tdr_pull *tdr, TALLOC_CTX *mem_ctx, int level, union bar *v)
$tdr = new Parse::Pidl::Samba4::TDR();
$tdr->ParserType({TYPE => "UNION", NAME => "bar", PROPERTIES => {}}, "pull");
is($tdr->{ret}, "static NTSTATUS tdr_pull_bar(struct tdr_pull *tdr, TALLOC_CTX *mem_ctx, int level, union bar *v)
{
switch (level) {
}
@ -45,4 +46,4 @@ is($ret, "static NTSTATUS tdr_pull_bar(struct tdr_pull *tdr, TALLOC_CTX *mem_ctx
}
");
is($ret_hdr, "");
is($tdr->{ret_hdr}, "");

View File

@ -5,7 +5,7 @@
use strict;
use warnings;
use Test::More tests => 45;
use Test::More tests => 47;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
@ -61,11 +61,11 @@ is_deeply(parse_conf("CODE START\ndata\nmore data\nCODE END\n"), { override => "
test_warnings("nofile:1: Unknown command `CODE'\n",
sub { parse_conf("CODE END\n"); } );
is_deeply(parse_conf("TYPE winreg_String dissect_myminregstring FT_STRING BASE_DEC 0 0 2\n"), { types => { winreg_String => {
is_deeply(parse_conf("TYPE winreg_String dissect_myminregstring(); FT_STRING BASE_DEC 0 0 2\n"), { types => { winreg_String => {
NAME => "winreg_String",
POS => { FILE => "nofile", LINE => 1 },
USED => 0,
DISSECTOR_NAME => "dissect_myminregstring",
DISSECTOR_NAME => "dissect_myminregstring();",
FT_TYPE => "FT_STRING",
BASE_TYPE => "BASE_DEC",
MASK => 0,
@ -87,13 +87,13 @@ test_errors("nofile:1: incomplete TYPE command\n",
sub { parse_conf("TYPE mytype dissector\n"); });
test_warnings("nofile:1: dissector name does not contain `dissect'\n",
sub { parse_conf("TYPE winreg_String myminregstring FT_STRING BASE_DEC 0 0 2\n"); });
sub { parse_conf("TYPE winreg_String myminregstring; FT_STRING BASE_DEC 0 0 2\n"); });
test_warnings("nofile:1: invalid FT_TYPE `BLA'\n",
sub { parse_conf("TYPE winreg_String dissect_myminregstring BLA BASE_DEC 0 0 2\n"); });
sub { parse_conf("TYPE winreg_String dissect_myminregstring; BLA BASE_DEC 0 0 2\n"); });
test_warnings("nofile:1: invalid BASE_TYPE `BLOE'\n",
sub { parse_conf("TYPE winreg_String dissect_myminregstring FT_UINT32 BLOE 0 0 2\n"); });
sub { parse_conf("TYPE winreg_String dissect_myminregstring; FT_UINT32 BLOE 0 0 2\n"); });
is_deeply(parse_conf("TFS hf_bla \"True string\" \"False String\"\n"),
{ tfs => { hf_bla => {
@ -163,3 +163,38 @@ test_errors("nofile:1: no dissectorname specified\n",
test_errors("nofile:1: incomplete HF_FIELD command\n",
sub { parse_conf("HF_FIELD hf_idx\n"); });
is_deeply(parse_conf("TYPE winreg_String dissect_myminregstring(); FT_STRING BASE_DEC 0 0 0 2\n"), {
types => {
winreg_String => {
NAME => "winreg_String",
POS => { FILE => "nofile", LINE => 1 },
USED => 0,
DISSECTOR_NAME => "dissect_myminregstring();",
FT_TYPE => "FT_STRING",
BASE_TYPE => "BASE_DEC",
MASK => 0,
VALSSTRING => 0,
ALIGNMENT => 0
}
}
}
);
is_deeply(parse_conf("TYPE winreg_String \"offset = dissect_myminregstring(\@HF\@);\" FT_STRING BASE_DEC 0 0 0 2\n"), {
types => {
winreg_String => {
NAME => "winreg_String",
POS => { FILE => "nofile", LINE => 1 },
USED => 0,
DISSECTOR_NAME => "offset = dissect_myminregstring(\@HF\@);",
FT_TYPE => "FT_STRING",
BASE_TYPE => "BASE_DEC",
MASK => 0,
VALSSTRING => 0,
ALIGNMENT => 0
}
}
}
);

View File

@ -10,44 +10,44 @@ 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 ProcessImport ProcessInclude find_type DumpEttList DumpEttDeclaration DumpHfList DumpHfDeclaration DumpFunctionTable register_type @ett register_ett);
use strict;
use Parse::Pidl::Wireshark::NDR qw(field2name %res PrintIdl StripPrefixes RegisterInterfaceHandoff register_hf_field ProcessImport ProcessInclude find_type DumpEttList DumpEttDeclaration DumpHfList DumpHfDeclaration DumpFunctionTable register_type register_ett);
is("Access Mask", field2name("access_mask"));
is("Accessmask", field2name("AccessMask"));
$res{code} = "";
PrintIdl("foo\nbar\n");
my $x = new Parse::Pidl::Wireshark::NDR();
$x->PrintIdl("foo\nbar\n");
is("/* IDL: foo */
/* IDL: bar */
", $res{code});
", $x->{res}->{code});
is("bla_foo", StripPrefixes("bla_foo", []));
is("foo", StripPrefixes("bla_foo", ["bla"]));
is("foo_bla", StripPrefixes("foo_bla", ["bla"]));
%hf_used = ();
$res{code} = "";
RegisterInterfaceHandoff({});
is($res{code}, "");
ok(not defined($hf_used{hf_bla_opnum}));
$x = new Parse::Pidl::Wireshark::NDR();
$x->RegisterInterfaceHandoff({});
is($x->{res}->{code}, "");
ok(not defined($x->{hf_used}->{hf_bla_opnum}));
%hf_used = ();
$res{code} = "";
RegisterInterfaceHandoff({UUID => "uuid", NAME => "bla"});
is($res{code}, 'void proto_reg_handoff_dcerpc_bla(void)
$x = new Parse::Pidl::Wireshark::NDR();
$x->{res}->{code} = "";
$x->RegisterInterfaceHandoff({UUID => "uuid", NAME => "bla"});
is($x->{res}->{code}, 'void proto_reg_handoff_dcerpc_bla(void)
{
dcerpc_init_uuid(proto_dcerpc_bla, ett_dcerpc_bla,
&uuid_dcerpc_bla, ver_dcerpc_bla,
bla_dissectors, hf_bla_opnum);
}
');
is($hf_used{hf_bla_opnum}, 1);
is($x->{hf_used}->{hf_bla_opnum}, 1);
$conformance = {};
$x->{conformance} = {};
is("hf_bla_idx",
register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef));
is_deeply($conformance, {
$x->register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef));
is_deeply($x->{conformance}, {
header_fields => {
"hf_bla_idx" => {
INDEX => "hf_bla_idx",
@ -64,10 +64,10 @@ is_deeply($conformance, {
fielddescription => {}
});
$conformance = { fielddescription => { hf_bla_idx => { DESCRIPTION => "Some Description" }}};
$x->{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, {
$x->register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef));
is_deeply($x->{conformance}, {
fielddescription => {
hf_bla_idx => {
DESCRIPTION => "Some Description",
@ -89,11 +89,11 @@ is_deeply($conformance, {
hf_renames => {},
});
$conformance = { fielddescription => { hf_bla_idx => { DESCRIPTION => "Some Description" }}};
$x->{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,
$x->register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF,
"Actual Description"));
is_deeply($conformance, {
is_deeply($x->{conformance}, {
fielddescription => {
hf_bla_idx => { DESCRIPTION => "Some Description" }
},
@ -114,21 +114,21 @@ is_deeply($conformance, {
$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, {
$x->{conformance} = { hf_renames => { "hf_bla_idx" => { NEWNAME => "hf_bloe_idx" } } };
$x->register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef);
is_deeply($x->{conformance}, {
hf_renames => { hf_bla_idx => { USED => 1, NEWNAME => "hf_bloe_idx" } } });
%hf_used = ( hf_bla => 1 );
$x->{hf_used} = { hf_bla => 1 };
test_warnings("", sub {
CheckUsed({ header_fields => { foo => { INDEX => "hf_bla" }}})});
$x->CheckUsed({ header_fields => { foo => { INDEX => "hf_bla" }}})});
%hf_used = ( );
$x->{hf_used} = { };
test_warnings("hf field `hf_bla' not used\n", sub {
CheckUsed({ header_fields => { foo => { INDEX => "hf_bla" }}})});
$x->CheckUsed({ header_fields => { foo => { INDEX => "hf_bla" }}})});
test_warnings("hf field `hf_id' not used\n",
sub { CheckUsed({
sub { $x->CheckUsed({
hf_renames => {
hf_id => {
OLDNAME => "hf_id",
@ -139,7 +139,7 @@ test_warnings("hf field `hf_id' not used\n",
}); } );
test_warnings("dissector param never used\n",
sub { CheckUsed({
sub { $x->CheckUsed({
dissectorparams => {
dissect_foo => {
PARAM => 42,
@ -149,7 +149,7 @@ test_warnings("dissector param never used\n",
}); } );
test_warnings("description never used\n",
sub { CheckUsed({
sub { $x->CheckUsed({
fielddescription => {
hf_bla => {
USED => 0
@ -158,7 +158,7 @@ test_warnings("description never used\n",
}); } );
test_warnings("import never used\n",
sub { CheckUsed({
sub { $x->CheckUsed({
imports => {
bla => {
USED => 0
@ -167,7 +167,7 @@ test_warnings("import never used\n",
}); } );
test_warnings("nofile:1: type never used\n",
sub { CheckUsed({
sub { $x->CheckUsed({
types => {
bla => {
USED => 0,
@ -177,7 +177,7 @@ test_warnings("nofile:1: type never used\n",
}); } );
test_warnings("True/False description never used\n",
sub { CheckUsed({
sub { $x->CheckUsed({
tfs => {
hf_bloe => {
USED => 0
@ -185,34 +185,34 @@ test_warnings("True/False description never used\n",
}
}); } );
$res{hdr} = "";
ProcessImport("security", "bla");
is($res{hdr}, "#include \"packet-dcerpc-bla.h\"\n\n");
$x = new Parse::Pidl::Wireshark::NDR();
$x->ProcessImport("security", "bla");
is($x->{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" .
$x = new Parse::Pidl::Wireshark::NDR();
$x->ProcessImport("\"bla.idl\"", "\"foo.idl\"");
is($x->{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" .
$x = new Parse::Pidl::Wireshark::NDR();
$x->ProcessInclude("foo.h", "bla.h", "bar.h");
is($x->{res}->{hdr}, "#include \"foo.h\"\n" .
"#include \"bla.h\"\n" .
"#include \"bar.h\"\n\n");
$conformance = {types => { bla => "brainslug" } };
is("brainslug", find_type("bla"));
$x->{conformance} = {types => { bla => "brainslug" } };
is("brainslug", $x->find_type("bla"));
is(DumpEttList("ett_t1", "ett_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(DumpEttList(["bla"]), "\tstatic gint *ett[] = {\n\t\t&bla,\n\t};\n");
is(DumpEttDeclaration("void", "zoid"),
is(DumpEttDeclaration(["void", "zoid"]),
"\n/* Ett declarations */\n" .
"static gint void = -1;\n" .
"static gint zoid = -1;\n" .
@ -220,19 +220,19 @@ is(DumpEttDeclaration("void", "zoid"),
is(DumpEttDeclaration(), "\n/* Ett declarations */\n\n");
$conformance = {
$x->{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[] = {
is($x->DumpHfList(), "\tstatic hf_register_info hf[] = {
{ &hf_bla,
{ \"Bla\", \"bla.field\", FT_UINT32, BASE_DEC, NULL, 255, \"NULL\", HFILL }},
};
");
is(DumpHfDeclaration(), "
is($x->DumpHfDeclaration(), "
/* Header field declarations */
static gint hf_bla = -1;
@ -250,9 +250,9 @@ is(DumpFunctionTable({
};
');
$conformance = {};
register_type("bla_type", "dissect_bla", "FT_UINT32", "BASE_HEX", 0xFF, "NULL", 4);
is_deeply($conformance, {
$x->{conformance} = {};
$x->register_type("bla_type", "dissect_bla", "FT_UINT32", "BASE_HEX", 0xFF, "NULL", 4);
is_deeply($x->{conformance}, {
types => {
bla_type => {
NAME => "bla_type",
@ -267,8 +267,8 @@ is_deeply($conformance, {
}
);
@ett = ();
register_ett("name");
is_deeply(\@ett, ["name"]);
register_ett("leela");
is_deeply(\@ett, ["name", "leela"]);
$x->{ett} = [];
$x->register_ett("name");
is_deeply($x->{ett}, ["name"]);
$x->register_ett("leela");
is_deeply($x->{ett}, ["name", "leela"]);