2 * Copyright (c) 2009, 2010 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
21 %module "Amanda::Header"
22 %include "amglue/amglue.swg"
23 %include "exception.i"
25 %include "Amanda/Header.pod"
28 #include "fileheader.h"
31 amglue_add_enum_tag_fns(filetype_t);
32 amglue_add_constant(F_UNKNOWN, filetype_t);
33 amglue_add_constant(F_WEIRD, filetype_t);
34 amglue_add_constant(F_TAPESTART, filetype_t);
35 amglue_add_constant(F_TAPEEND, filetype_t);
36 amglue_add_constant(F_DUMPFILE, filetype_t);
37 amglue_add_constant(F_CONT_DUMPFILE, filetype_t);
38 amglue_add_constant(F_SPLIT_DUMPFILE, filetype_t);
39 amglue_add_constant(F_EMPTY, filetype_t);
40 amglue_copy_to_tag(filetype_t, constants);
42 typedef char string_t[STRMAX];
43 %typemap(memberin) string_t {
44 strncpy($1, $input, STRMAX);
45 if ($1[STRMAX-1] != '\0')
46 SWIG_exception(SWIG_ValueError, "String too large for Amanda::Header");
49 %rename(Header) dumpfile_t;
57 string_t encrypt_suffix;
58 string_t name; /* hostname or label */
63 string_t clntcompprog;
65 string_t clnt_encrypt;
67 string_t uncompress_cmd;
69 string_t srv_decrypt_opt;
70 string_t clnt_decrypt_opt;
71 string_t cont_filename;
75 int totalparts; /* -1 == UNKNOWN */
82 dumpfile_t *df = g_new(dumpfile_t, 1);
84 /* some default values */
95 /* the usual "cheater's typemap" */
96 %typemap(out) SV * "$result = $1; argvi++;";
97 SV *to_string(size_t min_size, size_t max_size) {
98 size_t size = min_size;
101 result = build_header(self, &size, max_size);
103 /* header didn't fit -> return undef; */
106 STRLEN strlen_size = (STRLEN)size;
108 g_assert((size_t)strlen_size == size); /* check for casting overflow */
109 sv = sv_2mortal(newSVpvn(result, (STRLEN)size));
115 void debug_dump(void) {
116 dump_dumpfile_t(self);
120 char *summary(void) {
121 return summarize_header(self);
126 %newobject C_from_string;
128 static dumpfile_t *C_from_string(const char *string) {
129 dumpfile_t *result = g_new(dumpfile_t, 1);
130 parse_file_header(string, result, strlen(string));
137 # SWIG produces a sub-package for the Header "class", in this case named
138 # Amanda::Header::Header. For user convenience, we allow Amanda::Header->new(..) to
139 # do the same thing. This is a wrapper function, and not just a typeglob assignment,
140 # because we want to get the right blessing.
142 shift; # ignore class
143 Amanda::Header::Header->new(@_);
147 shift; # ignore class
148 return C_from_string(@_);
151 package Amanda::Header::Header;
153 # point $hdr->matches_dumpspecs() to Amanda::Cmdline::header_matches_dumpspecs. When
154 # Amanda is built with --without-server, Amanda::Cmdline is missing, so this will fail.
155 # Note that this assumes the user has already use'd Amanda::Cmdline.
156 sub matches_dumpspecs {
157 Amanda::Cmdline::header_matches_dumpspecs(@_);
160 package Amanda::Header;