1/* 2 * Copyright (c) 2008-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::Application" 23%include "amglue/amglue.swg" 24%include "exception.i" 25%include "cstring.i" 26 27%include "Amanda/Application.pod" 28 29%perlcode %{ 30push @ISA, qw(Amanda::Script_App); 31require Amanda::Script_App; 32 33use strict; 34use warnings; 35use IO::Handle; 36use Amanda::Config qw( :init :getconf config_dir_relative ); 37 38 39sub new { 40 my $class = shift @_; 41 my $config_name = shift @_; 42 43 my $self = Amanda::Script_App::new($class, "client", "application", $config_name); 44 45 $self->{known_commands} = { 46 support => 1, 47 discover => 1, 48 selfcheck => 1, 49 estimate => 1, 50 backup => 1, 51 restore => 1, 52 validate => 1, 53 }; 54 return $self; 55} 56 57sub run_calcsize { 58 my $self = shift; 59 my $program = shift; 60 61 run_calcsize_C($self->{config}, $program, $self->{disk}, $self->{device}, $self->{level}, undef, undef); 62 63} 64 65sub default_validate { 66 my $self = shift; 67 my $buffer; 68 69 do { 70 sysread STDIN, $buffer, 1048576; 71 } while (defined $buffer and length($buffer) > 0); 72} 73 74sub write_magic_block { 75 my $self = shift; 76 my $type = shift; 77 78 my $dump_str = pack("a512", $type); 79 print STDOUT $dump_str; 80} 81 82sub read_magic_block { 83 my $self = shift; 84 85 my $magic_block = Amanda::Util::full_read(0, 512); 86 #remove '\0' bytes 87 $magic_block =~ /^([^\0]*)/; 88 my $type = $1; 89 90 return $type; 91} 92 93sub _set_mesgout { 94 my $self = shift; 95 96 my $mesgout = IO::Handle->new(); 97 $mesgout->fdopen(3,"a") || die("Can't open mesgout_fd: $!"); 98 $mesgout->autoflush(1); 99 $self->{mesgout} = $mesgout; 100} 101 102%} 103 104/* C interfaces used by the above */ 105 106%{ 107#include "amanda.h" 108#include "client_util.h" 109%} 110 111%typemap(in) GSList *levels { 112 AV *tempav; 113 GSList *level = NULL; 114 int num; 115 int i; 116 SV **tv; 117 118 if (!SvROK($input)) 119 croak("Argument $argnum is not a reference."); 120 if (SvTYPE(SvRV($input)) != SVt_PVAV) 121 croak("Argument $argnum is not an array."); 122 tempav = (AV*)SvRV($input); 123 num = av_len(tempav); 124 for (i=0; i <= num; i++) { 125 tv = av_fetch(tempav, i, 0); 126 /* (gint) cast is required because sizeof(IV) may not be sizeof(gint). 127 * Both will be >= 32 bits, though, and that's sufficient for a level. */ 128 level = g_slist_append(level, GINT_TO_POINTER((gint)SvIV(*tv))); 129 } 130 $1 = level; 131} 132/* free the list */ 133%typemap(freearg) GSList *levels { 134 if($1) 135 g_slist_free($1); 136} 137 138%rename(run_calcsize_C) run_calcsize; 139void 140run_calcsize(char *config, char *program, char *disk, char *dirname, 141 GSList *levels, char *file_exclude, char *file_include); 142 143%typemap(in) GSList *levels; 144%typemap(freearg) GSList *levels; 145