pidl/ws: Add HEADER START/HEADER END in ws dissector
authorAurelien Aptel <aaptel@suse.com>
Tue, 9 Feb 2016 17:52:30 +0000 (18:52 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 20 Jun 2016 10:08:21 +0000 (12:08 +0200)
Port Wireshark commit a297950

Author: Guy Harris <guy@alum.mit.edu>
Date:   Mon Jan 13 21:05:44 2014 +0000

    Add HEADER START and HEADER END, similar to CODE START and CODE END, to
    allow stuff to be put into the .h file; that way, if you put helper
    functions into the .c file, for use by dissectors other than the one
    being generated, you can put declarations for them into the .h file.

    Do some checks for mis-nesting of CODE and HEADER blocks.

    Clean up the "this is generated code" header.

    svn path=/trunk/; revision=54720

Signed-off-by: Aurelien Aptel <aaptel@suse.com>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
pidl/lib/Parse/Pidl/Wireshark/Conformance.pm
pidl/lib/Parse/Pidl/Wireshark/NDR.pm

index b81cf5edaf52a99e88e1bf0b098b6dee747f6bfe..8057ab3b7ee9ba7c0888b131631a0121dd97e1fb 100644 (file)
@@ -396,6 +396,7 @@ sub ReadConformanceFH($$$)
        my ($fh,$data,$f) = @_;
 
        my $incodeblock = 0;
        my ($fh,$data,$f) = @_;
 
        my $incodeblock = 0;
+       my $inheaderblock = 0;
 
        my $ln = 0;
 
 
        my $ln = 0;
 
@@ -407,9 +408,27 @@ sub ReadConformanceFH($$$)
                s/[\r\n]//g;
 
                if ($_ eq "CODE START") {
                s/[\r\n]//g;
 
                if ($_ eq "CODE START") {
+                       if ($incodeblock) {
+                               warning({ FILE => $f, LINE => $ln }, 
+                                       "CODE START inside CODE section");
+                       }
+                       if ($inheaderblock) {
+                               error({ FILE => $f, LINE => $ln }, 
+                                       "CODE START inside HEADER section");
+                               return undef;
+                       }
                        $incodeblock = 1;
                        next;
                        $incodeblock = 1;
                        next;
-               } elsif ($incodeblock and $_ eq "CODE END") {
+               } elsif ($_ eq "CODE END") {
+                       if (!$incodeblock) {
+                               warning({ FILE => $f, LINE => $ln }, 
+                                       "CODE END outside CODE section");
+                       }
+                       if ($inheaderblock) {
+                               error({ FILE => $f, LINE => $ln }, 
+                                       "CODE END inside HEADER section");
+                               return undef;
+                       }
                        $incodeblock = 0;
                        next;
                } elsif ($incodeblock) {
                        $incodeblock = 0;
                        next;
                } elsif ($incodeblock) {
@@ -419,6 +438,37 @@ sub ReadConformanceFH($$$)
                                $data->{override} = "$_\n";
                        }
                        next;
                                $data->{override} = "$_\n";
                        }
                        next;
+               } elsif ($_ eq "HEADER START") {
+                       if ($inheaderblock) {
+                               warning({ FILE => $f, LINE => $ln }, 
+                                       "HEADER START inside HEADER section");
+                       }
+                       if ($incodeblock) {
+                               error({ FILE => $f, LINE => $ln }, 
+                                       "HEADER START inside CODE section");
+                               return undef;
+                       }
+                       $inheaderblock = 1;
+                       next;
+               } elsif ($_ eq "HEADER END") {
+                       if (!$inheaderblock) {
+                               warning({ FILE => $f, LINE => $ln }, 
+                                       "HEADER END outside HEADER section");
+                       }
+                       if ($incodeblock) {
+                               error({ FILE => $f, LINE => $ln }, 
+                                       "CODE END inside HEADER section");
+                               return undef;
+                       }
+                       $inheaderblock = 0;
+                       next;
+               } elsif ($inheaderblock) {
+                       if (exists $data->{header}) {
+                               $data->{header}.="$_\n";
+                       } else {
+                               $data->{header} = "$_\n";
+                       }
+                       next;
                }
 
                my @fields = /([^ "]+|"[^"]+")/g;
                }
 
                my @fields = /([^ "]+|"[^"]+")/g;
index f17efe7845425928f765d70a2d4fc6823bb5f01c..fee7f0654d10ae18d1fb3ba0b1cd2ec86e93b317 100644 (file)
@@ -1025,6 +1025,10 @@ sub ProcessInterface($$)
        $self->RegisterInterface($x);
        $self->RegisterInterfaceHandoff($x);
 
        $self->RegisterInterface($x);
        $self->RegisterInterfaceHandoff($x);
 
+       if (exists ($self->{conformance}->{header})) {
+               $self->pidl_hdr($self->{conformance}->{header});
+       }
+
        $self->pidl_hdr("#endif /* $define */");
 }
 
        $self->pidl_hdr("#endif /* $define */");
 }
 
@@ -1114,7 +1118,7 @@ sub Parse($$$$$)
 
        my $notice =
 "/* DO NOT EDIT
 
        my $notice =
 "/* DO NOT EDIT
-       This filter was automatically generated
+       This file was automatically generated by Pidl
        from $idl_file and $cnf_file.
 
        Pidl is a perl based IDL compiler for DCE/RPC idl files.
        from $idl_file and $cnf_file.
 
        Pidl is a perl based IDL compiler for DCE/RPC idl files.
@@ -1125,8 +1129,6 @@ sub Parse($$$$$)
 
 ";
 
 
 ";
 
-       $self->pidl_hdr($notice);
-
        $self->{res}->{headers} = "\n";
        $self->{res}->{headers} .= "#include \"config.h\"\n";
 
        $self->{res}->{headers} = "\n";
        $self->{res}->{headers} .= "#include \"config.h\"\n";
 
@@ -1168,7 +1170,7 @@ sub Parse($$$$$)
        }
        $parser.=$self->{res}->{code};
 
        }
        $parser.=$self->{res}->{code};
 
-       my $header = "/* autogenerated by pidl */\n\n";
+       my $header = $notice;
        $header.=$self->{res}->{hdr};
 
        $self->CheckUsed($self->{conformance});
        $header.=$self->{res}->{hdr};
 
        $self->CheckUsed($self->{conformance});