1/* 2 * Copyright (c) 2009-2013 Zmanda, Inc. All Rights Reserved. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, but 10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * 18 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300 19 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com 20 */ 21 22%module "Amanda::Header" 23%include "amglue/amglue.swg" 24%include "exception.i" 25 26%include "Amanda/Header.pod" 27 28%{ 29#include "fileheader.h" 30%} 31 32amglue_add_enum_tag_fns(filetype_t); 33amglue_add_constant(F_UNKNOWN, filetype_t); 34amglue_add_constant(F_WEIRD, filetype_t); 35amglue_add_constant(F_TAPESTART, filetype_t); 36amglue_add_constant(F_TAPEEND, filetype_t); 37amglue_add_constant(F_DUMPFILE, filetype_t); 38amglue_add_constant(F_CONT_DUMPFILE, filetype_t); 39amglue_add_constant(F_SPLIT_DUMPFILE, filetype_t); 40amglue_add_constant(F_EMPTY, filetype_t); 41amglue_copy_to_tag(filetype_t, constants); 42 43typedef char string_t[STRMAX]; 44%typemap(memberin) string_t { 45 strncpy($1, $input, STRMAX); 46 if ($1[STRMAX-1] != '\0') 47 SWIG_exception(SWIG_ValueError, "String too large for Amanda::Header"); 48} 49 50%rename(Header) dumpfile_t; 51typedef struct { 52 filetype_t type; 53 string_t datestamp; 54 int dumplevel; 55 int compressed; 56 int encrypted; 57 string_t comp_suffix; 58 string_t encrypt_suffix; 59 string_t name; /* hostname or label */ 60 string_t disk; 61 string_t program; 62 string_t application; 63 string_t srvcompprog; 64 string_t clntcompprog; 65 string_t srv_encrypt; 66 string_t clnt_encrypt; 67 string_t recover_cmd; 68 string_t uncompress_cmd; 69 string_t decrypt_cmd; 70 string_t srv_decrypt_opt; 71 string_t clnt_decrypt_opt; 72 string_t cont_filename; 73 char *dle_str; 74 int is_partial; 75 int partnum; 76 int totalparts; /* -1 == UNKNOWN */ 77 size_t blocksize; 78 off_t orig_size; 79 80 %extend { 81 /* constructor */ 82 dumpfile_t(void) { 83 dumpfile_t *df = g_new(dumpfile_t, 1); 84 fh_init(df); 85 /* some default values */ 86 df->totalparts = -1; 87 df->partnum = 1; 88 return df; 89 } 90 91 /* destructor */ 92 ~dumpfile_t(void) { 93 dumpfile_free(self); 94 } 95 96 /* the usual "cheater's typemap" */ 97 %typemap(out) SV * "$result = $1; argvi++;"; 98 SV *to_string(size_t min_size, size_t max_size) { 99 size_t size = min_size; 100 char *result; 101 102 result = build_header(self, &size, max_size); 103 if (!result) { 104 /* header didn't fit -> return undef; */ 105 return &PL_sv_undef; 106 } else { 107 STRLEN strlen_size = (STRLEN)size; 108 SV *sv; 109 g_assert((size_t)strlen_size == size); /* check for casting overflow */ 110 sv = sv_2mortal(newSVpvn(result, (STRLEN)size)); 111 g_free(result); 112 return sv; 113 } 114 } 115 116 void debug_dump(void) { 117 dump_dumpfile_t(self); 118 } 119 120 %newobject summary; 121 char *summary(void) { 122 return summarize_header(self); 123 } 124 } 125} dumpfile_t; 126 127%inline %{ 128static 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)); 131 return result; 132} 133%} 134 135%perlcode %{ 136 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. 141sub new { 142 shift; # ignore class 143 Amanda::Header::Header->new(@_); 144} 145 146sub from_string { 147 shift; # ignore class 148 return C_from_string(@_); 149} 150 151sub get_dle { 152 my $self = shift; 153 154 if ($self->{'dle_str'}) { 155 return Amanda::Header::HeaderXML->new($self->{'dle_str'}); 156 } else { 157 return undef; 158 } 159} 160 161package Amanda::Header::Header; 162 163# point $hdr->matches_dumpspecs() to Amanda::Cmdline::header_matches_dumpspecs. When 164# Amanda is built with --without-server, Amanda::Cmdline is missing, so this will fail. 165# Note that this assumes the user has already use'd Amanda::Cmdline. 166sub matches_dumpspecs { 167 Amanda::Cmdline::header_matches_dumpspecs(@_); 168} 169 170package Amanda::Header; 171%} 172 173%{ 174#include "amxml.h" 175%} 176 177%rename(HeaderXML) dle_t; 178typedef struct { 179 char *disk; 180 char *device; 181 int program_is_application_api; 182 char *program; 183 estimatelist_t estimatelist; 184 int spindle; 185 int compress; 186 int encrypt; 187 int kencrypt; 188 levellist_t levellist; 189 int nb_level; 190 char *dumpdate; 191 char *compprog; 192 char *srv_encrypt; 193 char *clnt_encrypt; 194 char *srv_decrypt_opt; 195 char *clnt_decrypt_opt; 196 int record; 197 int create_index; 198 char *auth; 199 am_sl_t *exclude_file; 200 am_sl_t *exclude_list; 201 am_sl_t *include_file; 202 am_sl_t *include_list; 203 int exclude_optional; 204 int include_optional; 205 proplist_t application_property; 206 scriptlist_t scriptlist; 207 data_path_t data_path; 208 GSList *directtcp_list; 209 struct a_dle_s *next; 210 211 %extend { 212 /* constructor */ 213 dle_t(char *dle_str) { 214 char *errmsg = NULL; 215 dle_t *dle; 216 dle = amxml_parse_node_CHAR(dle_str, &errmsg); 217 amfree(errmsg); 218 219 return dle; 220 } 221 222 /* destructor */ 223 ~dle_t(void) { 224 amfree(self); 225 } 226 } 227} dle_t; 228 229