1 ###################################################
2 # parse an ethereal conformance file
3 # Copyright jelmer@samba.org 2005
4 # released under the GNU GPL
10 Parse::Pidl::Ethereal::Conformance - Conformance file parser for Wireshark
14 This module supports parsing Ethereal conformance files (*.cnf).
18 Pidl needs additional data for ethereal output. This data is read from
19 so-called conformance files. This section describes the format of these
22 Conformance files are simple text files with a single command on each line.
23 Empty lines and lines starting with a '#' character are ignored.
24 Arguments to commands are seperated by spaces.
26 The following commands are currently supported:
30 =item I<TYPE> name dissector ft_type base_type mask valsstring alignment
32 Register new data type with specified name, what dissector function to call
33 and what properties to give header fields for elements of this type.
37 Suppress emitting a dissect_type function for the specified type
39 =item I<PARAM_VALUE> type param
41 Set parameter to specify to dissector function for given type.
43 =item I<HF_FIELD> hf title filter ft_type base_type valsstring mask description
45 Generate a custom header field with specified properties.
47 =item I<HF_RENAME> old_hf_name new_hf_name
49 Force the use of new_hf_name when the parser generator was going to
52 This can be used in conjunction with HF_FIELD in order to make more then
53 one element use the same filter name.
55 =item I<STRIP_PREFIX> prefix
57 Remove the specified prefix from all function names (if present).
59 =item I<PROTOCOL> longname shortname filtername
61 Change the short-, long- and filter-name for the current interface in
64 =item I<FIELD_DESCRIPTION> field desc
66 Change description for the specified header field. `field' is the hf name of the field.
68 =item I<IMPORT> dissector code...
70 Code to insert when generating the specified dissector. @HF@ and
71 @PARAM@ will be substituted.
73 =item I<TFS> hf_name "true string" "false string"
75 Override the text shown when a bitmap boolean value is enabled or disabled.
85 package Parse::Pidl::Ethereal::Conformance;
88 use vars qw($VERSION);
92 @EXPORT_OK = qw(ReadConformance);
96 use Parse::Pidl::Util qw(has_property);
98 sub handle_type($$$$$$$$$$)
100 my ($pos,$data,$name,$dissectorname,$ft_type,$base_type,$mask,$valsstring,$alignment) = @_;
102 unless(defined($alignment)) {
103 print "$pos: error incomplete TYPE command\n";
107 unless ($dissectorname =~ /.*dissect_.*/) {
108 print "$pos: warning: dissector name does not contain `dissect'\n";
111 unless(valid_ft_type($ft_type)) {
112 print "$pos: warning: invalid FT_TYPE `$ft_type'\n";
115 unless (valid_base_type($base_type)) {
116 print "$pos: warning: invalid BASE_TYPE `$base_type'\n";
119 $data->{types}->{$name} = {
123 DISSECTOR_NAME => $dissectorname,
125 BASE_TYPE => $base_type,
127 VALSSTRING => $valsstring,
128 ALIGNMENT => $alignment
132 sub handle_tfs($$$$$)
134 my ($pos,$data,$hf,$trues,$falses) = @_;
136 unless(defined($falses)) {
137 print "$pos: error: incomplete TFS command\n";
141 $data->{tfs}->{$hf} = {
142 TRUE_STRING => $trues,
143 FALSE_STRING => $falses
147 sub handle_hf_rename($$$$)
149 my ($pos,$data,$old,$new) = @_;
151 unless(defined($new)) {
152 print "$pos: error: incomplete HF_RENAME command\n";
156 $data->{hf_renames}->{$old} = {
164 sub handle_param_value($$$$)
166 my ($pos,$data,$dissector_name,$value) = @_;
168 unless(defined($value)) {
169 print "$pos: error: incomplete PARAM_VALUE command\n";
173 $data->{dissectorparams}->{$dissector_name} = {
174 DISSECTOR => $dissector_name,
181 sub valid_base_type($)
184 return 0 unless($t =~ /^BASE_.*/);
191 return 0 unless($t =~ /^FT_.*/);
195 sub handle_hf_field($$$$$$$$$$)
197 my ($pos,$data,$index,$name,$filter,$ft_type,$base_type,$valsstring,$mask,$blurb) = @_;
199 unless(defined($blurb)) {
200 print "$pos: error: incomplete HF_FIELD command\n";
204 unless(valid_ft_type($ft_type)) {
205 print "$pos: warning: invalid FT_TYPE `$ft_type'\n";
208 unless(valid_base_type($base_type)) {
209 print "$pos: warning: invalid BASE_TYPE `$base_type'\n";
212 $data->{header_fields}->{$index} = {
219 BASE_TYPE => $base_type,
220 VALSSTRING => $valsstring,
226 sub handle_strip_prefix($$$)
228 my ($pos,$data,$x) = @_;
230 push (@{$data->{strip_prefixes}}, $x);
233 sub handle_noemit($$$)
239 if (defined($type)) {
240 $data->{noemit}->{$type} = 1;
242 $data->{noemit_dissector} = 1;
246 sub handle_protocol($$$$$$)
248 my ($pos, $data, $name, $longname, $shortname, $filtername) = @_;
250 $data->{protocols}->{$name} = {
251 LONGNAME => $longname,
252 SHORTNAME => $shortname,
253 FILTERNAME => $filtername
257 sub handle_fielddescription($$$$)
259 my ($pos,$data,$field,$desc) = @_;
261 $data->{fielddescription}->{$field} = {
262 DESCRIPTION => $desc,
272 my $dissectorname = shift @_;
274 unless(defined($dissectorname)) {
275 print "$pos: error: no dissectorname specified\n";
279 $data->{imports}->{$dissectorname} = {
280 NAME => $dissectorname,
281 DATA => join(' ', @_),
287 my %field_handlers = (
288 TYPE => \&handle_type,
289 NOEMIT => \&handle_noemit,
290 PARAM_VALUE => \&handle_param_value,
291 HF_FIELD => \&handle_hf_field,
292 HF_RENAME => \&handle_hf_rename,
294 STRIP_PREFIX => \&handle_strip_prefix,
295 PROTOCOL => \&handle_protocol,
296 FIELD_DESCRIPTION => \&handle_fielddescription,
297 IMPORT => \&handle_import
300 sub ReadConformance($$)
304 $data->{override} = "";
308 open(IN,"<$f") or return undef;
319 if ($_ eq "CODE START") {
322 } elsif ($incodeblock and $_ eq "CODE END") {
325 } elsif ($incodeblock) {
326 $data->{override}.="$_\n";
330 my @fields = /([^ "]+|"[^"]+")/g;
332 my $cmd = $fields[0];
336 if (not defined($field_handlers{$cmd})) {
337 print "$f:$ln: Warning: Unknown command `$cmd'\n";
341 $field_handlers{$cmd}("$f:$ln", $data, @fields);