source: A2P/a2p/AFPDS/MODCA/BOC.pm @ 3

Last change on this file since 3 was 3, checked in by guillaume, 17 years ago
  • AUTHORS: Ajout des différents contributeurs
  • COPYING: Ajout de la licence GPL v3
  • a2p: Préparation des sources pour leur publication sous GPL
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1#
2# Copyright (c) 2004-2007 - Consultas, PKG.fr
3#
4# This file is part of A2P.
5#
6# A2P is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# A2P is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with A2P; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19#
20# $Id: BOC.pm 3 2007-10-18 16:20:19Z guillaume $
21#
22# Class to export Begin Object Container members
23#
24# cf ref #2, p. 129
25#
26
27package AFPDS::MODCA::BOC ;
28
29use strict ;
30use A2P::Globals ;
31use A2P::Syslog ;
32use AFPDS::MODCA::Common ;
33
34BEGIN {
35    our $VERSION = sprintf "%s", q$Rev: 1030 $ =~ /([0-9.]+)\s+/ ;
36}
37our $VERSION ;
38our @ISA = ("AFPDS::MODCA");
39our $IDENTS ;
40
41sub _ID { 0xD3A892 }
42
43sub _supported_triplets {
44    return [
45            0x10, # Mandatory object classification
46        ], [
47            # TODO support needed for next
48            # 0x01, # Coded charset GID
49            # 0x02, # FQN
50            # 0x57, # object byte extent
51            # 0x62, # local timestamp
52            # 0x65, # comment
53            # 0x72, # universal timestamp
54        ];
55}
56
57sub new {
58    my $class = shift ;
59    &Debug("new " . __PACKAGE__ . " v$VERSION object");
60
61    my $self = {
62        FLUX     => 0,        # Associated flux
63        IDENT    => _ID,      # MO:DCA identity
64        FLAG     => 0,        # MO:DCA flags
65        RESERVED => 0,        # MO:DCA reserved
66        LONG     => 0,        # MO:DCA buffer length
67        BUFFER   => ''        # MO:DCA content buffer
68    };
69
70    return bless $self , $class ;
71}
72
73sub validate {
74    my $self = shift ;
75
76    &Debug("Found BOC as new integrated resource");
77    &UPSTAT('GET-RESOURCE');
78
79    # Check minimal buffer size
80    return ( 251, "BOC is malformed as too short (" . $self->{LONG} . "<9)" )
81        if ( $self->{LONG} < 9 );
82
83    # Check FLUX is a Flux object
84    return ( 251, "BOC needs to be used with Flux object" )
85        unless ( ref($self->{FLUX}) =~ /^AFPDS::Flux$/ );
86
87    return () ;
88}
89
90sub create {
91    my $self = shift ;
92    my $flux = $self->{FLUX} ;
93
94    # Set resource name
95    my $resname = substr( $self->{BUFFER}, 0, 8 );
96    $resname = $self->convert( $resname );
97    return ( 252, "Invalid resource name found" ) unless $resname ;
98
99    # Set resource name as member as it can be later overrided by X'02' triplet
100    $self->name( $resname );
101
102    # Analyse now authorized triplets as it is mandatory
103    my @err = $self->check_triplets(substr( $self->{BUFFER}, 8 ));
104    return @err if @err ;
105
106    my $struct = $self->{STRUCT} || 0 ;
107    return ( 253, "Unexpected '$struct' structure found for BOC object" )
108        unless ( $struct == 0xDC00 );
109
110    my $class = $self->{CLASS} || 0 ;
111    return ( 253, "Unexpected '$class' class found for BOC object" )
112        unless ( $class == 0x01 );
113
114    # Add an empty buffer to the resource object
115    $self->{RESOURCE_BUFFER} = "" ;
116
117    # Set a new resource in flux object
118    $flux->set_resource($self) unless @err ;
119
120    return @err ;
121}
122
123sub teximage {
124    my $self = shift ;
125    my $reso = shift || 240 ;
126
127    # Affect image if the first argument is defined
128    $self->{TEXIMAGE}->{$reso} = shift if ( @_ and defined($_[0]) );
129
130    return ( exists($self->{TEXIMAGE}) and exists($self->{TEXIMAGE}->{$reso}) )?
131        $self->{TEXIMAGE}->{$reso} : '' ;
132}
133
134
135sub DESTROY {
136    my $self = shift;
137
138    # Output resource if not retrieved by inclusion and in DEBUG mode
139    if ( $ADVANCED_DEBUGGING or ! exists($self->{TEXIMAGE})
140    and ref($self->{FLUX}) =~ /^AFPDS::Flux/ ) {
141        my $flux = $self->{FLUX} ;
142        my $file = $flux->getoutbase . '_' . $self->name ;
143        $file .= '.' . lc($self->{FORMAT}) if (exists($self->{FORMAT}));
144        $flux->toclean( $file );
145        if ( open( OBJ, '>', $file ) ) {
146            binmode(OBJ);
147            print OBJ $self->{RESOURCE_BUFFER} ;
148            close(OBJ);
149        }
150    }
151}
152
153&Debug("Module " . __PACKAGE__ . " v$VERSION loaded");
154
155( $IDENTS->{&_ID} ) = __PACKAGE__ =~ /(\w+)$/ ;
Note: See TracBrowser for help on using the repository browser.