1 # This file was automatically generated by SWIG (http://www.swig.org).
4 # Do not make changes to this file unless you know what you are doing--modify
5 # the SWIG interface file instead.
7 package Amanda::Archive;
9 use base qw(DynaLoader);
10 package Amanda::Archivec;
11 bootstrap Amanda::Archive;
12 package Amanda::Archive;
15 # ---------- BASE METHODS -------------
17 package Amanda::Archive;
20 my ($classname,$obj) = @_;
21 return bless $obj, $classname;
31 my ($self,$field) = @_;
32 my $member_func = "swig_${field}_get";
33 $self->$member_func();
37 my ($self,$field,$newval) = @_;
38 my $member_func = "swig_${field}_set";
39 $self->$member_func($newval);
48 # ------- FUNCTION WRAPPERS --------
50 package Amanda::Archive;
52 *amar_new = *Amanda::Archivec::amar_new;
53 *amar_close = *Amanda::Archivec::amar_close;
54 *amar_new_file = *Amanda::Archivec::amar_new_file;
55 *amar_file_close = *Amanda::Archivec::amar_file_close;
56 *amar_new_attr = *Amanda::Archivec::amar_new_attr;
57 *amar_attr_close = *Amanda::Archivec::amar_attr_close;
58 *amar_attr_add_data_buffer = *Amanda::Archivec::amar_attr_add_data_buffer;
59 *amar_attr_add_data_fd = *Amanda::Archivec::amar_attr_add_data_fd;
60 *amar_read = *Amanda::Archivec::amar_read;
62 # ------- VARIABLE STUBS --------
64 package Amanda::Archive;
72 Amanda::Archive - Perl access to the amanda archive library
78 # Write to the file descriptor $fd, and add /etc/hosts to it
79 my $archive = Amanda::Archive->new($fd, ">");
80 my $file = $archive->new_file("/etc/hosts");
81 my $attr = $file->new_attr(16);
82 open(my $fh, "<", "/etc/hosts");
83 $attr->add_data_fd(fileno($fh), 1);
87 # Read from an archive
88 my $archive = Amanda::Archive->new($fd, "<");
91 my ($user_data, $filenum, $filename) = @_;
93 return "foo"; # this becomes $file_data
96 my ($user_data, $file_data, $filenum, $truncated) = @_;
99 21 => [ 32768, # buffer into 32k chunks
101 my ($user_data, $filenum, $file_data, $attrid,
102 $attr_data, $data, $eoa, $truncated) = @_;
103 return "pants"; # becomes the new $attr_data for
104 # any subsequent fragments
106 0 => sub { # note no buffering here; attrid 0 is "default"
107 my ($user_data, $filenum, $file_data, $attrid,
108 $attr_data, $data, $eoa, $truncated) = @_;
109 return "shorts"; # becomes the new $attr_data for
110 # any subsequent fragments
112 user_data => [ "mydata" ], # sent to all callbacks
117 =head2 Amanda::Archive::Archive Objects
119 Note that C<Amanda::Archive->new> and C<Amanda::Archive::Archive->new> are
124 =item C<new($fd, $mode)>
126 Create a new archive for reading ("<") or writing (">") from or to file
129 =item C<new_file($filename, $want_posn)>
131 Create a new C<Amanda::Archive::File> object with the given filename (writing
134 Amanda::Archive::File->new($archive, $filename, $want_posn);
136 if C<$want_posn> is false, then this method returns a new
137 C<Amanda::Archive::File> object. If C<$want_posn> is true, then it returns
138 C<($file, $posn)> where C<$file> is the object and C<$posn> is the offset into
139 the datastream at which this file begins. This offset can be stored in an
140 index and used later to seek into the file.
144 See I<READING>, below.
148 Flush all buffers and close this archive. This does not close the file descriptor.
152 =head2 Amanda::Archive::File Objects
156 =item C<new($archive, $filename, $want_posn)>
158 Create a new file in the given archive. See C<Amanda::Archive::Archive::new_file>, above.
160 =item C<new_attr($attrid)>
162 Create a new C<Amanda::Archive::Attribute> object. Equivalent to
164 Amanda::Archive::Attr->new($file, $attrid);
168 Close this file, writing an EOF record.
172 =head2 Amanda::Archive::Attribute Objects
176 =item C<add_data($data, $eoa)>
178 Add C<$data> to this attribute, adding an EOA (end-of-attribute) bit if C<$eoa> is true.
180 =item C<add_data_fd($fd, $eoa)>
182 Copy data from C<$fd> to this attribute, adding an EOA (end-of-attribute) bit if C<$eoa> is true.
186 Close this attribute, adding an EOA bit if none has been written already.
192 The C<Amanda::Archive::Archive> method C<read()> handles reading archives via a callback mechanism. It takes its arguments in hash form, with the following keys:
195 my ($user_data, $filenum, $filename) = @_;
199 C<file_start> gives a sub which is called for every file in the archive. It
200 can return an arbitrary value which will become the C<$file_data> for
201 subsequent callbacks in this file, or the string "IGNORE" which will cause the
202 reader to ignore all data for this file. In this case, no other callbacks will
203 be made for the file (not even C<file_finish>).
206 my ($user_data, $file_data, $filenum, $truncated) = @_;
210 C<file_finish> gives a sub which is called when an EOF record appears.
211 C<$file_data> comes from the return value of the C<file_start> callback.
212 C<$truncated> is true if the file may be missing data (e.g., when an early EOF
215 user_data => $my_object,
217 C<user_data> gives an arbitrary value which is passed to each callback as C<$user_data>.
220 my ($user_data, $filenum, $file_data, $attrid,
221 $attr_data, $data, $eoa, $truncated) = @_;
224 19 => [ 10240, sub { ... } ],
226 Any numeric key is treated as an attribute ID, and specifies the handling for
227 that attribute. Attribute ID zero is treated as a wildcard, and will match any
228 attribute without an explicit handler. The handler can be specified as a sub
229 (as for attribute ID 13 in the example above) or as an arrayref C<[$minsize,
230 $sub]>. In the latter case, the sub is only called when at least C<$minsize>
231 bytes of data are available for the attribute, or at the end of the attribute
234 The parameters to the callback include C<$file_data>, the value returned from
235 C<file_start>, and C<$attr_data>, which is the return value of the last
236 invocation of this sub for this attribute. If this is the last fragment of
237 data for this attribute, then C<$eoa> is true. The meaning of C<$truncated>
238 is similar to that in C<file_finish>.
243 my ($arch_fh, $basedir) = @_;
245 my $arch = Amanda::Archive->new(fileno($arch_fh), "<");
248 my ($user_data, $filenum, $filename) = @_;
249 return "$basedir/$filenum"; # becomes $file_data
252 my ($user_data, $filenum, $file_data, $attrid,
253 $attr_data, $data, $eoa, $truncated) = @_;
254 warn("file $filename attribute $attrid is truncated")
256 # store the open filehandle in $attr_data
258 open($attr_data, "$file_data.$attrid", ">")
261 print $attr_data $data;
272 package Amanda::Archive;
274 # Expose the Archive constructor at Amanda::Archive->new
277 Amanda::Archive::Archive->new(@_);
280 package Amanda::Archive::Archive;
283 my ($class, $fd, $mode) = @_;
284 my $arch = Amanda::Archive::amar_new($fd, $mode);
285 return bless (\$arch, $class);
291 Amanda::Archive::amar_close($$self);
302 my ($self, $filename, $want_offset) = @_;
303 return Amanda::Archive::File->new($self, $filename, $want_offset);
306 sub Amanda::Archive::Archive::read {
308 die "Archive is not open" unless ($$self);
309 # pass a hashref to the C code
311 Amanda::Archive::amar_read($$self, \%h);
314 package Amanda::Archive::File;
317 my ($class, $arch, $filename, $want_offset) = @_;
318 die "Archive is not open" unless ($$arch);
320 # note that posn is returned first by the SWIG wrapper
321 my ($file, $posn) = Amanda::Archive::amar_new_file($$arch, $filename, $want_offset);
322 return (bless([ $file, $arch ], $class), $posn);
324 my $file = Amanda::Archive::amar_new_file($$arch, $filename, $want_offset);
325 return bless([ $file, $arch ], $class);
332 Amanda::Archive::amar_file_close($self->[0]);
343 my ($self, $attrid) = @_;
344 return Amanda::Archive::Attr->new($self, $attrid);
347 package Amanda::Archive::Attr;
350 my ($class, $file, $attrid) = @_;
351 die "File is not open" unless ($file->[0]);
352 my $attr = Amanda::Archive::amar_new_attr($file->[0], $attrid);
353 return bless ([$attr, $file], $class);
359 Amanda::Archive::amar_attr_close($self->[0]);
370 my ($self, $data, $eoa) = @_;
371 die "Attr is not open" unless ($self->[0]);
372 Amanda::Archive::amar_attr_add_data_buffer($self->[0], $data, $eoa);
376 my ($self, $fd, $eoa) = @_;
377 die "Attr is not open" unless ($self->[0]);
378 return Amanda::Archive::amar_attr_add_data_fd($self->[0], $fd, $eoa);