X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FXfer.pm;fp=lib%2FBackupPC%2FXfer.pm;h=b585e25cad6a523326d27cd0d692cc1add3864e8;hp=0000000000000000000000000000000000000000;hb=5b79f9a3c01bca16dd4d211e76fc53daa549e421;hpb=f8c20efc11f400acafb7833947bae6c299467ef6 diff --git a/lib/BackupPC/Xfer.pm b/lib/BackupPC/Xfer.pm new file mode 100644 index 0000000..b585e25 --- /dev/null +++ b/lib/BackupPC/Xfer.pm @@ -0,0 +1,152 @@ +#============================================================= -*-perl-*- +# +# BackupPC::Xfer package +# +# DESCRIPTION +# +# This library defines a Factory for invoking transfer protocols in +# a polymorphic manner. This libary allows for easier expansion of +# supported protocols. +# +# AUTHOR +# Paul Mantz +# +# COPYRIGHT +# Copyright (C) 2008 Zmanda +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +#======================================================================== +# +# Version 3.1.0+ +# +# See http://backuppc.sourceforge.net. +# +#======================================================================== + + +package BackupPC::Xfer; + +use strict; +use Encode qw/from_to encode/; + +use BackupPC::Xfer::Archive; +use BackupPC::Xfer::BackupPCd; +use BackupPC::Xfer::Ftp; +use BackupPC::Xfer::Protocol; +use BackupPC::Xfer::Rsync; +use BackupPC::Xfer::Smb; +use BackupPC::Xfer::Tar; + +use vars qw( $errStr ); + +sub create +{ + my($protocol, $bpc, $args) = @_; + my $xfer; + + $errStr = undef; + + if ( $protocol eq 'archive' ) { + + $xfer = BackupPC::Xfer::Archive->new( $bpc, $args ); + $errStr = BackupPC::Xfer::Archive::errStr() if ( !defined($xfer) ); + return $xfer; + + } elsif ( $protocol eq 'backuppcd' ) { + + $xfer = BackupPC::Xfer::BackupPCd->new( $bpc, $args ); + $errStr = BackupPC::Xfer::BackupPCd::errStr() if ( !defined($xfer) ); + return $xfer; + + } elsif ( $protocol eq 'ftp' ) { + + $xfer = BackupPC::Xfer::Ftp->new( $bpc, $args ); + $errStr = BackupPC::Xfer::Ftp::errStr() if ( !defined($xfer) ); + return $xfer; + + } elsif ( $protocol eq 'rsync' || $protocol eq 'rsyncd' ) { + + $xfer = BackupPC::Xfer::Rsync->new( $bpc, $args ); + $errStr = BackupPC::Xfer::Rsync::errStr() if ( !defined($xfer) ); + return $xfer; + + } elsif ( $protocol eq 'smb' ) { + + $xfer = BackupPC::Xfer::Smb->new( $bpc, $args ); + $errStr = BackupPC::Xfer::Smb::errStr() if ( !defined($xfer) ); + return $xfer; + + } elsif ( $protocol eq 'tar' ) { + + $xfer = BackupPC::Xfer::Tar->new( $bpc, $args ); + $errStr = BackupPC::Xfer::Tar::errStr() if ( !defined($xfer) ); + return $xfer; + + } elsif ( $protocol eq 'protocol') { + + $xfer = BackupPC::Xfer::Protocol->new( $bpc, $args ); + $errStr = BackupPC::Xfer::Protocol::errStr() if ( !defined($xfer) ); + return $xfer; + + } else { + + $xfer = undef; + $errStr = "$protocol is not a supported protocol."; + return $xfer; + } +} + +# +# getShareNames() loads the correct shares dependent on the +# transfer type. +# +sub getShareNames +{ + my($conf) = @_; + my $ShareNames; + + if ( $conf->{XferMethod} eq "tar" ) { + $ShareNames = $conf->{TarShareName}; + + } elsif ( $conf->{XferMethod} eq "ftp" ) { + $ShareNames = $conf->{FtpShareName}; + + } elsif ( $conf->{XferMethod} eq "rsync" || $conf->{XferMethod} eq "rsyncd" ) { + $ShareNames = $conf->{RsyncShareName}; + + } elsif ( $conf->{XferMethod} eq "backuppcd" ) { + $ShareNames = $conf->{BackupPCdShareName}; + + } elsif ( $conf->{XferMethod} eq "smb" ) { + $ShareNames = $conf->{SmbShareName}; + + } else { + # + # default to smb shares + # + $ShareNames = $conf->{SmbShareName}; + } + + $ShareNames = [$ShareNames] unless ref($ShareNames) eq "ARRAY"; + return $ShareNames; +} + +sub errStr +{ + return $errStr; +} + +1;