This file is indexed.

/usr/share/perl5/Lire/XMLSpecContainer.pm is in lire 2:2.1.1-2.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
package Lire::XMLSpecContainer;

use strict;

use Lire::DlfSchema;
use Lire::DataTypes qw/ check_superservice check_xml_name /;
use Lire::Utils qw/ xml_encode check_param check_object_param /;
use Lire::I18N qw/ dgettext dgettext_para /;
use Lire::Config::XMLSpecListSpec;
use Lire::XMLSpecParser;

use Carp;


=pod

=head1 NAME

Lire::XMLSpecContainer - Base clase for XML report and filter specifications

=head1 SYNOPSIS

  use base qw/Lire::XMLSpecContainer/;

=head1 DESCRIPTION

This is the base class for Lire::ReportSpec and Lire::FilterSpec which
are XML specifications used to compute reports. This man page document
the attributes common to both type of specification.

=cut

sub load {
    my ( $self, $super, $id ) = @_;

    check_param( $super, 'super', \&check_superservice );

    check_param( $id, 'id', \&check_xml_name );

    my $file = $self->file_from_id( $super, $id );
    my $parser = new Lire::XMLSpecParser();
    my $spec = eval { $parser->parsefile( $file ) };
    croak "error while parsing XML specification $id: $@"
      if $@;

    # Some sanity checks
    croak "$file has superservice '", $spec->superservice(), "' when it
      should be '", $super, "'\n" unless $spec->superservice() eq $super;
    croak "$file has id '", $spec->id(), "' when it should be '", $id, "'\n"
      unless $spec->id() eq $id;

    return $spec;
}

sub new {
    return bless { 'params' => {},
                   '_joined_schemas' => [],
                 }, shift;
}

=pod

=head2 id( [ $new_id ] )

Returns the type id of this specification. It $new_id is set, it will
change the id of the specification.

=cut

sub id {
    my ( $self, $id ) = @_;

    if ( defined $id ) {
        check_param( $id, 'id', \&check_xml_name );

	$self->{'id'}	= $id;
    }

    return $self->{'id'};
}

=pod

=head2 superservice( [ $new_superservice ] )

Returns the superservice (aka base DLF schema) used by this
specification. It $new_superservice is set, it will change the
superservice of the specification.

=cut

sub superservice {
    my ( $self, $superservice ) = @_;

    if ( defined $superservice ) {
        check_param( $superservice, 'superservice', \&check_superservice );

	# Schema can't be valid if we switch superservice
	delete $self->{'schema'}
	  if defined $self->{'superservice'} &&
	    $self->{'superservice'} ne $superservice;

	$self->{'superservice'} = $superservice;
    }

    return $self->{'superservice'};
}

=pod

=head2 schema( [ $new_schema ] )

Returns the Lire::DLfSchema object used by this specification. This
can be the superservice or any of its Lire::ExtendedSchema or
Lire::DerivedSchema.

If $new_schema is a string, the specification's schema will be changed
to that schema. If $new_schema is undef, the base DlfSchema (aka
superservice) will be used.


=cut

sub schema {
    my ( $self, $schema ) = @_;

    if ( @_ == 2 ) {
	if (defined $schema) {
	    my ( $super ) = $schema =~ /^(\w+)-/;
	    croak "invalid schema identifier: $schema"
	      unless $super;
	    croak "superservice of schema isn't correct: $super != $self->{'superservice'}"
	      unless $super eq $self->{'superservice'};
	    $self->{'schema'} = $schema;
	} else {
	    delete $self->{'schema'};
	}
    }

    return Lire::DlfSchema::load_schema( $self->{'schema'} ||
					 $self->{'superservice'} );
}


=pod

=head2 joined_schemas( [ $new_schemas ] )

Returns as an array reference, the list of schemas that are joined in
this specification.

If $new_schemas is set, the list of joined schemas will be changed to
that list. This is an array reference of schema name. All of these
schemas should be join compatible with the schema specified in the
schema() attribute.

=cut

sub joined_schemas {
    my ( $self, $new_schemas ) = @_;

    if ( defined $new_schemas ) {
        check_object_param( $new_schemas, 'new_schemas', 'ARRAY' );

        my $schema = $self->schema();
        foreach my $name ( @$new_schemas ) {
            croak "no schema '$name'"
              unless Lire::DlfSchema->has_schema( $name );
            my $joined = Lire::DlfSchema::load_schema( $name );
            croak "cannot join '$name' schema with '" . $schema->id() . "'"
              unless $self->schema()->can_join_schema( $joined );
        }
        @{$self->{'_joined_schemas'}} = @$new_schemas;
    }
    return $self->{'_joined_schemas'};
}

=pod

=head2 schemas()

Returns in an array reference all the schemas used by this
specification. This will include the base schema as well as any
joined schemas.

=cut

sub schemas {
    my $self = $_[0];

    return [ $self->schema()->id(), @{$self->{'_joined_schemas'}} ];
}

=pod

=head2 has_field( $name ) 

Returns whether the field named $name is available in this
specification's schema or any of its joined schema.

=cut

sub has_field {
    my ( $self, $name ) = @_;

    check_param( $name, 'name' );

    return 1 if $self->schema()->has_field( $name );

    foreach my $schema_name ( @{$self->{'_joined_schemas'}} ) {
        my $schema = Lire::DlfSchema::load_schema( $schema_name );
        return 1 if $schema->has_field( $name );
    }

    return 0;
}

=pod

=head2 field( $name )

Returns the Lire::Field object named $name present in one of
the specification's joined schema.

=cut

sub field {
    my ( $self, $name ) = @_;

    check_param( $name, 'name' );

    croak ( "no field '$name' in this specification's schemas: " .
            join( ", ", $self->schema()->id(), @{$self->{'_joined_schemas'}} ))
      unless $self->has_field( $name );

    return $self->schema()->field( $name )
      if $self->schema()->has_field( $name );

    foreach my $schema_name ( @{$self->{'_joined_schemas'}} ) {
        my $schema = Lire::DlfSchema::load_schema( $schema_name );
        return $schema->field( $name ) if $schema->has_field( $name );
    }

    die "ASSERT: shouldn't be reached";
}

=pod

=head2 title( [ $new_title ]

This method returns the title of this specification. If $new_title is
set, the specification's title will be changed to that value.

The returned value is localized if a translation string is available.
The domain used for translation is 'lire-<superservice'.

=cut

sub title {
    my ( $self, $title ) = @_;

    if ( defined $title ) {
	$self->{'title'} = $title;
    }

    return dgettext( 'lire-' . $self->superservice(),
                     $self->{'title'} );
}


=pod

=head2 description( [ $new_description ]

This method returns the description of this specification. If
$new_description is set, the specification's description will be
changed to that value. That description is a DocBook string describing
the specification's purpose.

The returned value is localized if a translation string is available.
The domain used for translation is 'lire-<superservice'.

=cut

sub description {
    my ( $self, $desc ) = @_;

    if ( defined $desc ) {
	$self->{'description'} = $desc;
    }

    return dgettext_para( 'lire-' . $self->superservice(),
                          $self->{'description'} );
}

sub has_param {
    my ( $self, $name ) = @_;

    return exists $self->{'params'}{$name};
}

sub param {
    my ( $self, $name, $param ) = @_;

    if ( defined $param ) {
	croak "param has invalid name $name != " . $param->name()
	  unless $name eq $param->name();
	$self->{'params'}{$name} = $param;
    }

    croak "Lire::XMLSpecContainer::param: no param $name defined"
      unless $self->has_param( $name );

    my $p = $self->{'params'}{$name};

    if ( @_ == 3 && ! defined $param) {
	# Remove it
	delete $self->{'params'}{$name};
    }

    return $p;
}

sub param_names {
    my ( $self ) = @_;

    return map { $_->name() } values %{$self->{'params'}};
}

sub resolve_param_ref {
    my ( $self, $value ) = @_;

    return undef unless (defined $value);

    if ( substr( $value, 0, 1) eq '$') {
        my $pname = substr( $value, 1);
        croak "no such parameter: '$pname'"
          unless (defined $self->{'params'}{$pname});
        return $self->{'params'}{$pname}->value();
    } else {
        return $value;
    }
}

=pod

=head2 display_title( [ $new_title ]

This method returns the title that will be displayed in the generated
specification. This value can contains reference to the
specification's parameters using the '$name' syntax.

If $new_title is set, the specification's display title will be changed
to that value.

The returned value is localized if a translation string is available.
The domain used for translation is 'lire-<superservice'.

=cut

sub display_title {
    my ( $self, $title ) = @_;

    if ( defined $title ) {
	my @wrong = $self->check_params( $title );
	if ( @wrong == 1 ) {
	    croak "non-existent parameter '", $wrong[0],
	      "' used in display title\n";
	} elsif ( @wrong > 1 ) {
	    croak "non-existent parameters (", join( ", ", @wrong ),
	      ") are used in display title\n";
	}
	$self->{'display_title'} = $title;
    }

    return dgettext( 'lire-' . $self->superservice(),
                     $self->{'display_title'} );
}

=pod

=head2 display_description( [ $new_description ]

This method returns the description that will be displayed in the
generated report. This value can contains reference to the
specification's parameters using the '$name' syntax.

If $new_description is set, the specification's description will be
changed to that value. That description is a DocBook string describing
the specification's purpose.

The returned value is localized if a translation string is available.
The domain used for translation is 'lire-<superservice'.

=cut

sub display_description {
    my ( $self, $desc ) = @_;

    if ( @_ == 2 ) {
	my @wrong = $self->check_params( $desc );
	if ( @wrong == 1 ) {
	    croak "non-existent parameter '", $wrong[0],
	      "' used in display description\n";
	} elsif ( @wrong > 1 ) {
	    croak "non-existent parameters (", join( ", ", @wrong ),
	      ") are used in display description\n";
	}

	# Modify the description
	$self->{'display_description'} = $desc;
    }

    return dgettext_para( 'lire-' . $self->superservice(),
                          $self->{'display_description'} );
}

=pod

=head2 expanded_display_title()

Returns display_title() with parameters reference expanded.

=cut

sub expanded_display_title {
    my $self = $_[0];

    return $self->expand_params( $self->display_title() );
}

=pod

=head2 expanded_display_description()

Returns display_description() with parameters reference expanded.

=cut

sub expanded_display_description {
    my ( $self ) = @_;

    return $self->expand_params( $self->display_description() );
}

# ------------------------------------------------------------------------
# Method check_params($str)
#
# Extracts the $ parameters contained in $str and returns the
# list of parameter which aren't available.
# 
# Returns the empty list if all parameters are valid
sub check_params {
    my ($self, $str ) = @_;

    my @wrong = ();
    my @params = $str =~ m|(?<!\$)\$([a-zA-Z]+[-:.\w]+)|g;
    foreach my $p ( @params ) {
	push @wrong, $p
	  unless $self->has_param( $p );
    }

    return @wrong;
}

sub expand_params {
    my ($self, $str) = @_;

    return $str if ( ! defined $str );

    # Replace all occurence of $name with the value of the
    # parameter with the same name. Ignore $$name which will become $name.
    # Will croak on non-existent parameters.
    $str =~ s{(?<!\$)\$([a-zA-Z]+[-:.\w]+)}{$self->param($1)->value()}eg;

    # Unescape $$
    $str =~ s{\$\$}{\$}g;

    return $str;
}

=pod

=head2 print( $fh )

Prints this specification as XML on $fh.

=cut

sub print {
    my ($self, $fh) = @_;
    $fh ||= \*STDOUT;

    my $root = $self->root_element();
#
# The header
#
    print $fh <<EOF;
<?xml version="1.0"?>
<!DOCTYPE lire:$root PUBLIC
  "-//LogReport.ORG//DTD Lire Report Specification Markup Language V2.1//EN"
  "http://www.logreport.org/LRSML/2.1/lrsml.dtd">
EOF
    print $fh qq{<lire:$root xmlns:lire="http://www.logreport.org/LRSML/" xmlns:lrcml="http://www.logreport.org/LRCML/" id="$self->{'id'}" superservice="$self->{'superservice'}"};
    print $fh qq{ schema="$self->{'schema'}"}
      if defined $self->{'schema'};
    print $fh $self->root_xml_attrs();
    print $fh ">\n\n";

#
# Title and description
#
    my $title = xml_encode( $self->{'title'} );
    print $fh <<EOF;
 <lire:title>$title</lire:title>
 <lire:description>$self->{'description'}</lire:description>

EOF

#
# Parameter specifications
#
    if ( keys %{$self->{'params'}}) {
	print $fh " <lire:param-spec>\n";

	foreach my $p ( values %{$self->{'params'}} ) {
	    my $name = $p->name();
	    my $type = $p->type();
	    my $default = xml_encode( $p->default() );
	    my $desc = $p->description();
	    print $fh qq{  <lire:param name="$name" type="$type"};
	    print $fh qq{ default="$default"}
	      if defined $default;
	    if (defined $desc ) {
		print $fh <<EOF;
>
   <lire:description>$desc</lire:description>
  </lire:param>

EOF
	    } else {
		print $fh "/>\n\n";
	    }
	}
	print $fh " </lire:param-spec>\n";
    }


#
# Display-spec
#
    my $display_title = xml_encode( $self->{'display_title'} );
    print $fh <<EOF;
 <lire:display-spec>
  <lire:title>$display_title</lire:title>

EOF

    print $fh "   <lire:description>\n", $self->display_description,
      "   </lire:description>\n\n"
	if $self->display_description;

    print $fh <<EOF;
 </lire:display-spec>

EOF

    $self->print_children( $fh, 1 );

    print $fh <<EOF;
</lire:$root>
EOF
    return;
}

sub has_spec {
    my ( $self, $super, $id ) = @_;

    check_param( $super, 'superservice', \&check_superservice );
    check_param( $id, 'id', \&check_xml_name );

    foreach my $dir ( @{$self->spec_path()} ) {
        return 1 if -f "$dir/$super/$id.xml";
    }

    return 0;
}

sub list_specs {
    my ( $self, $super ) = @_;

    check_param( $super, 'superservice', \&check_superservice );

    my %result = ();
    foreach my $dir ( @{$self->spec_path()} ) {
        next unless -d "$dir/$super" && -r "$dir/$super";
        opendir my $dh, "$dir/$super"
          or die "opendir failed: $!\n";
        foreach my $file ( readdir $dh ) {
            next unless $file =~ /^([a-zA-Z][a-zA-Z0-9._-]+)\.xml$/;
            $result{$1} = 1;
        }
        closedir $dh;
    }

    return [ keys %result ];

}

sub file_from_id {
    my ( $self, $super, $id ) = @_;

    check_param( $super, 'superservice', \&check_superservice );
    check_param( $id, 'id', \&check_xml_name );

    foreach my $dir ( @{$self->spec_path()} ) {
        return "$dir/$super/$id.xml" if -f "$dir/$super/$id.xml";
    }

    croak(  "can't find '$super' ", ref $self || $self,
            " XML specification '$id' in \"",
            join( ":", @{$self->spec_path()} ), '"' );
}

sub new_from_config {
    my ( $self, $value ) = @_;

    my $def = $value->Lire::Config::Dictionary::as_value();
    my ( $super, $type ) =
      $value->name() =~ qr/$Lire::Config::XMLSpecListSpec::NAME_RE/;
    my $spec = $self->load( $super, $type );

    $spec->display_title( $def->{'title'} ) if $def->{'title'};
    foreach my $name ( $spec->param_names() ) {
        $spec->param( $name )->value( $def->{$name} );
    }

    return $spec;
}

########################################################################
#			 METHODS TO OVERRIDE
########################################################################

sub print_children {
    my ( $self, $fh, $indent ) = @_;

    croak "unimplemented method: ", ref $self || $self, "::print_children\n";
}

sub spec_path {
    croak "unimplemented method: ", ref $_[0] || $_[0], "::spec_path\n";
}

sub root_element {
    my ( $self ) = @_;

    croak "unimplemented method: ", ref $self || $self, "::root_element\n";
}

sub root_xml_attrs {
    return "";
}

1;

__END__

=pod

=head1 SEE ALSO

 Lire::ReportSpec(3pm), Lire::FilterSpec(3pm), Lire::XMLSpecParser(3pm)

=head1 AUTHORS

  Francis J. Lacoste <flacoste@logreport.org>
  Wolfgang Sourdeau <wolfgang@logreport.org>

=head1 VERSION

$Id: XMLSpecContainer.pm,v 1.41 2006/07/23 13:16:30 vanbaal Exp $

=head1 COPYRIGHT

Copyright (C) 2001-2004 Stichting LogReport Foundation LogReport@LogReport.org

This file is part of Lire.

Lire is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html. 


=cut