Imported Upstream version 3.2.0
[debian/amanda] / perl / Amanda / Header.pm
1 # This file was automatically generated by SWIG (http://www.swig.org).
2 # Version 1.3.39
3 #
4 # Do not make changes to this file unless you know what you are doing--modify
5 # the SWIG interface file instead.
6
7 package Amanda::Header;
8 use base qw(Exporter);
9 use base qw(DynaLoader);
10 package Amanda::Headerc;
11 bootstrap Amanda::Header;
12 package Amanda::Header;
13 @EXPORT = qw();
14
15 # ---------- BASE METHODS -------------
16
17 package Amanda::Header;
18
19 sub TIEHASH {
20     my ($classname,$obj) = @_;
21     return bless $obj, $classname;
22 }
23
24 sub CLEAR { }
25
26 sub FIRSTKEY { }
27
28 sub NEXTKEY { }
29
30 sub FETCH {
31     my ($self,$field) = @_;
32     my $member_func = "swig_${field}_get";
33     $self->$member_func();
34 }
35
36 sub STORE {
37     my ($self,$field,$newval) = @_;
38     my $member_func = "swig_${field}_set";
39     $self->$member_func($newval);
40 }
41
42 sub this {
43     my $ptr = shift;
44     return tied(%$ptr);
45 }
46
47
48 # ------- FUNCTION WRAPPERS --------
49
50 package Amanda::Header;
51
52 *C_from_string = *Amanda::Headerc::C_from_string;
53
54 ############# Class : Amanda::Header::Header ##############
55
56 package Amanda::Header::Header;
57 use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
58 @ISA = qw( Amanda::Header );
59 %OWNER = ();
60 %ITERATORS = ();
61 *swig_type_get = *Amanda::Headerc::Header_type_get;
62 *swig_type_set = *Amanda::Headerc::Header_type_set;
63 *swig_datestamp_get = *Amanda::Headerc::Header_datestamp_get;
64 *swig_datestamp_set = *Amanda::Headerc::Header_datestamp_set;
65 *swig_dumplevel_get = *Amanda::Headerc::Header_dumplevel_get;
66 *swig_dumplevel_set = *Amanda::Headerc::Header_dumplevel_set;
67 *swig_compressed_get = *Amanda::Headerc::Header_compressed_get;
68 *swig_compressed_set = *Amanda::Headerc::Header_compressed_set;
69 *swig_encrypted_get = *Amanda::Headerc::Header_encrypted_get;
70 *swig_encrypted_set = *Amanda::Headerc::Header_encrypted_set;
71 *swig_comp_suffix_get = *Amanda::Headerc::Header_comp_suffix_get;
72 *swig_comp_suffix_set = *Amanda::Headerc::Header_comp_suffix_set;
73 *swig_encrypt_suffix_get = *Amanda::Headerc::Header_encrypt_suffix_get;
74 *swig_encrypt_suffix_set = *Amanda::Headerc::Header_encrypt_suffix_set;
75 *swig_name_get = *Amanda::Headerc::Header_name_get;
76 *swig_name_set = *Amanda::Headerc::Header_name_set;
77 *swig_disk_get = *Amanda::Headerc::Header_disk_get;
78 *swig_disk_set = *Amanda::Headerc::Header_disk_set;
79 *swig_program_get = *Amanda::Headerc::Header_program_get;
80 *swig_program_set = *Amanda::Headerc::Header_program_set;
81 *swig_application_get = *Amanda::Headerc::Header_application_get;
82 *swig_application_set = *Amanda::Headerc::Header_application_set;
83 *swig_srvcompprog_get = *Amanda::Headerc::Header_srvcompprog_get;
84 *swig_srvcompprog_set = *Amanda::Headerc::Header_srvcompprog_set;
85 *swig_clntcompprog_get = *Amanda::Headerc::Header_clntcompprog_get;
86 *swig_clntcompprog_set = *Amanda::Headerc::Header_clntcompprog_set;
87 *swig_srv_encrypt_get = *Amanda::Headerc::Header_srv_encrypt_get;
88 *swig_srv_encrypt_set = *Amanda::Headerc::Header_srv_encrypt_set;
89 *swig_clnt_encrypt_get = *Amanda::Headerc::Header_clnt_encrypt_get;
90 *swig_clnt_encrypt_set = *Amanda::Headerc::Header_clnt_encrypt_set;
91 *swig_recover_cmd_get = *Amanda::Headerc::Header_recover_cmd_get;
92 *swig_recover_cmd_set = *Amanda::Headerc::Header_recover_cmd_set;
93 *swig_uncompress_cmd_get = *Amanda::Headerc::Header_uncompress_cmd_get;
94 *swig_uncompress_cmd_set = *Amanda::Headerc::Header_uncompress_cmd_set;
95 *swig_decrypt_cmd_get = *Amanda::Headerc::Header_decrypt_cmd_get;
96 *swig_decrypt_cmd_set = *Amanda::Headerc::Header_decrypt_cmd_set;
97 *swig_srv_decrypt_opt_get = *Amanda::Headerc::Header_srv_decrypt_opt_get;
98 *swig_srv_decrypt_opt_set = *Amanda::Headerc::Header_srv_decrypt_opt_set;
99 *swig_clnt_decrypt_opt_get = *Amanda::Headerc::Header_clnt_decrypt_opt_get;
100 *swig_clnt_decrypt_opt_set = *Amanda::Headerc::Header_clnt_decrypt_opt_set;
101 *swig_cont_filename_get = *Amanda::Headerc::Header_cont_filename_get;
102 *swig_cont_filename_set = *Amanda::Headerc::Header_cont_filename_set;
103 *swig_dle_str_get = *Amanda::Headerc::Header_dle_str_get;
104 *swig_dle_str_set = *Amanda::Headerc::Header_dle_str_set;
105 *swig_is_partial_get = *Amanda::Headerc::Header_is_partial_get;
106 *swig_is_partial_set = *Amanda::Headerc::Header_is_partial_set;
107 *swig_partnum_get = *Amanda::Headerc::Header_partnum_get;
108 *swig_partnum_set = *Amanda::Headerc::Header_partnum_set;
109 *swig_totalparts_get = *Amanda::Headerc::Header_totalparts_get;
110 *swig_totalparts_set = *Amanda::Headerc::Header_totalparts_set;
111 *swig_blocksize_get = *Amanda::Headerc::Header_blocksize_get;
112 *swig_blocksize_set = *Amanda::Headerc::Header_blocksize_set;
113 *swig_orig_size_get = *Amanda::Headerc::Header_orig_size_get;
114 *swig_orig_size_set = *Amanda::Headerc::Header_orig_size_set;
115 sub new {
116     my $pkg = shift;
117     my $self = Amanda::Headerc::new_Header(@_);
118     bless $self, $pkg if defined($self);
119 }
120
121 *to_string = *Amanda::Headerc::Header_to_string;
122 *debug_dump = *Amanda::Headerc::Header_debug_dump;
123 *summary = *Amanda::Headerc::Header_summary;
124 sub DESTROY {
125     return unless $_[0]->isa('HASH');
126     my $self = tied(%{$_[0]});
127     return unless defined $self;
128     delete $ITERATORS{$self};
129     if (exists $OWNER{$self}) {
130         Amanda::Headerc::delete_Header($self);
131         delete $OWNER{$self};
132     }
133 }
134
135 sub DISOWN {
136     my $self = shift;
137     my $ptr = tied(%$self);
138     delete $OWNER{$ptr};
139 }
140
141 sub ACQUIRE {
142     my $self = shift;
143     my $ptr = tied(%$self);
144     $OWNER{$ptr} = 1;
145 }
146
147
148 # ------- VARIABLE STUBS --------
149
150 package Amanda::Header;
151
152 *F_UNKNOWN = *Amanda::Headerc::F_UNKNOWN;
153 *F_WEIRD = *Amanda::Headerc::F_WEIRD;
154 *F_TAPESTART = *Amanda::Headerc::F_TAPESTART;
155 *F_TAPEEND = *Amanda::Headerc::F_TAPEEND;
156 *F_DUMPFILE = *Amanda::Headerc::F_DUMPFILE;
157 *F_CONT_DUMPFILE = *Amanda::Headerc::F_CONT_DUMPFILE;
158 *F_SPLIT_DUMPFILE = *Amanda::Headerc::F_SPLIT_DUMPFILE;
159 *F_EMPTY = *Amanda::Headerc::F_EMPTY;
160
161 @EXPORT_OK = ();
162 %EXPORT_TAGS = ();
163
164
165 =head1 NAME
166
167 Amanda::Header - Amanda-specific headers prepended to dump files
168
169 =head1 SYNOPSIS
170
171   # create a header
172   my $hdr = Amanda::Header->new();
173   $hdr->{type} = $Amanda::Header::F_DUMPFILE;
174   $hdr->{name} = "localhost";
175   $hdr->{disk} = "/home";
176
177   # make a string suitable for use in a dumpfile (NUL-padded)
178   my $block = $hdr->to_string(32768, 32768);
179
180   # parse a string into a header
181   $hdr = Amanda::Header->from_string($block);
182
183   print "Working on: ", $hdr->summary(), "\n";
184
185 =head1 Header Objects
186
187 Note that, due to the vagaries of SWIG wrapping, headers actually have
188 class C<Amanda::Header::Header>.
189
190 The constructor creates a new, blank header, which will need at least
191 some of its attributes set before being used.  These are set just like
192 any hashref-based object:
193
194  $hdr->{'dumplevel'} = 13;
195
196 To construct a new object from a bytestring (as read from the
197 beginning of a dumpfile), use
198
199  Amanda::Header->from_string($data);
200
201 To convert a header object into a bytestring, use the C<to_string(min,
202 max)> method.  This method takes a minimum and maximum size.  If the
203 header is smaller than the minimum size, it is padded with NUL bytes;
204 if it would be larger than the maximum size, the method returns
205 C<undef>.
206
207 The C<summary> method returns a single-line summary of the header, with
208 no trailing newline.
209
210 As a debugging utility, the C<debug_dump> method dumps the contents of
211 the object to the debug log.
212
213 To compare a header to a list of dumpspecs (see L<Amanda::Cmdline>), use
214
215   if ($hdr->matches_dumpspecs([@dumpspecs])) { ... }
216
217 which is really a call to C<Amanda::Cmdline::header_matches_dumpspecs>.
218
219 A header object has the following keys:
220
221  type
222  datestamp
223  dumplevel
224  compressed
225  encrypted
226  comp_suffix
227  encrypt_suffix
228  name               hostname (F_DUMPFILE) or label (F_TAPESTART)
229  disk
230  program
231  application
232  srvcompprog
233  clntcompprog
234  srv_encrypt
235  clnt_encrypt
236  recover_cmd
237  uncompress_cmd
238  decrypt_cmd
239  srv_decrypt_opt
240  clnt_decrypt_opt
241  cont_filename
242  dle_str
243  is_partial
244  partnum
245  totalparts         (-1 == UNKNOWN)
246  blocksize
247  orig_size
248
249 C<type> is one of the following constants, which are availble for
250 import in the tag C<:constants>:
251
252  F_UNKNOWN
253  F_WEIRD
254  F_TAPESTART
255  F_TAPEEND
256  F_DUMPFILE
257  F_CONT_DUMPFILE
258  F_SPLIT_DUMPFILE
259  F_EMPTY
260  F_NOOP
261
262 Some of the header fields are interrelated.  The following restrictions apply.
263
264 =over 4
265
266 =item *
267
268 C<comp_suffix> is set if and only if C<compressed> is true; the suffix "N" is
269 reserved and cannot be used.
270
271 =item *
272
273 C<encrypt_suffix> is set if and only if C<encrypted> is true; the suffix "N" is
274 reserved and cannot be used.
275
276 =item *
277
278 If C<totalparts> is not -1, then C<partnum> must be less than or equal to
279 C<totalparts>.  Neither parameter can be zero.  These parameters are only
280 recorded in a C<F_SPLIT_DUMPFILE> header.
281
282 =item *
283
284 The C<blocksize> is intended for the user's convenience only.  It is written to
285 the header string, but not parsed on return.  C<from_string> will always return
286 a header with blocksize=0.
287
288 =item *
289
290 Like C<blocksize>, C<recover_cmd>, C<uncompress_cmd> and C<decrypt_cmd> are
291 intended for the user's convenience noly.  The C<uncompress_cmd> and
292 C<decrypt_cmd>, if specified, must end with C<|> (the shell pipe character).
293 Neither can be nonempty unless C<recover_cmd> is also nonempty.  When parsing a
294 header with only two commands from a string, it is ambiguous whether the first
295 string is for decryption or uncompression, and this package assumes
296 uncompression.
297
298 =back
299
300 =cut
301
302
303
304 push @EXPORT_OK, qw(filetype_t_to_string);
305 push @{$EXPORT_TAGS{"filetype_t"}}, qw(filetype_t_to_string);
306
307 my %_filetype_t_VALUES;
308 #Convert an enum value to a single string
309 sub filetype_t_to_string {
310     my ($enumval) = @_;
311
312     for my $k (keys %_filetype_t_VALUES) {
313         my $v = $_filetype_t_VALUES{$k};
314
315         #is this a matching flag?
316         if ($enumval == $v) {
317             return $k;
318         }
319     }
320
321 #default, just return the number
322     return $enumval;
323 }
324
325 push @EXPORT_OK, qw($F_UNKNOWN);
326 push @{$EXPORT_TAGS{"filetype_t"}}, qw($F_UNKNOWN);
327
328 $_filetype_t_VALUES{"F_UNKNOWN"} = $F_UNKNOWN;
329
330 push @EXPORT_OK, qw($F_WEIRD);
331 push @{$EXPORT_TAGS{"filetype_t"}}, qw($F_WEIRD);
332
333 $_filetype_t_VALUES{"F_WEIRD"} = $F_WEIRD;
334
335 push @EXPORT_OK, qw($F_TAPESTART);
336 push @{$EXPORT_TAGS{"filetype_t"}}, qw($F_TAPESTART);
337
338 $_filetype_t_VALUES{"F_TAPESTART"} = $F_TAPESTART;
339
340 push @EXPORT_OK, qw($F_TAPEEND);
341 push @{$EXPORT_TAGS{"filetype_t"}}, qw($F_TAPEEND);
342
343 $_filetype_t_VALUES{"F_TAPEEND"} = $F_TAPEEND;
344
345 push @EXPORT_OK, qw($F_DUMPFILE);
346 push @{$EXPORT_TAGS{"filetype_t"}}, qw($F_DUMPFILE);
347
348 $_filetype_t_VALUES{"F_DUMPFILE"} = $F_DUMPFILE;
349
350 push @EXPORT_OK, qw($F_CONT_DUMPFILE);
351 push @{$EXPORT_TAGS{"filetype_t"}}, qw($F_CONT_DUMPFILE);
352
353 $_filetype_t_VALUES{"F_CONT_DUMPFILE"} = $F_CONT_DUMPFILE;
354
355 push @EXPORT_OK, qw($F_SPLIT_DUMPFILE);
356 push @{$EXPORT_TAGS{"filetype_t"}}, qw($F_SPLIT_DUMPFILE);
357
358 $_filetype_t_VALUES{"F_SPLIT_DUMPFILE"} = $F_SPLIT_DUMPFILE;
359
360 push @EXPORT_OK, qw($F_EMPTY);
361 push @{$EXPORT_TAGS{"filetype_t"}}, qw($F_EMPTY);
362
363 $_filetype_t_VALUES{"F_EMPTY"} = $F_EMPTY;
364
365 #copy symbols in filetype_t to constants
366 push @{$EXPORT_TAGS{"constants"}},  @{$EXPORT_TAGS{"filetype_t"}};
367
368
369 # SWIG produces a sub-package for the Header "class", in this case named
370 # Amanda::Header::Header.  For user convenience, we allow Amanda::Header->new(..) to
371 # do the same thing.  This is a wrapper function, and not just a typeglob assignment,
372 # because we want to get the right blessing.
373 sub new {
374     shift; # ignore class
375     Amanda::Header::Header->new(@_);
376 }
377
378 sub from_string {
379     shift; # ignore class
380     return C_from_string(@_);
381 }
382
383 package Amanda::Header::Header;
384
385 # point $hdr->matches_dumpspecs() to Amanda::Cmdline::header_matches_dumpspecs.  When
386 # Amanda is built with --without-server, Amanda::Cmdline is missing, so this will fail.
387 # Note that this assumes the user has already use'd Amanda::Cmdline.
388 sub matches_dumpspecs {
389     Amanda::Cmdline::header_matches_dumpspecs(@_);
390 }
391
392 package Amanda::Header;
393 1;