/usr/share/perl5/SyncUtil/StandAloneHost.pm is in syncbbdb 2.3-6.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | #------------------------------------------------------------------------------
# $Date: 2000/08/06 19:45:02 $
# RCS: $Id: StandAloneHost.pm,v 1.7 2000/08/06 19:45:02 deweese Exp $
#------------------------------------------------------------------------------
package StandAloneHost;
require 5.000;
use strict;
use SyncUtil::ConduitHost;
use FileHandle;
my @ISA = qw(ConduitHost);
sub new {
my $type = shift;
my $self = ConduitHost->new();
$self->{'name'} = shift;
$self->{'port'} = shift;
$self->{'prefs'} = shift;
bless($self, $type);
$self->{'last status msg'} = "";
$self->{'last status percent'} = 0;
$self->{'last status time'} = 0;
if (!defined($self->{'port'})) {
$self->{'port'} = "/dev/ttyb";
}
my $conduitdir = $self->{'name'};
if ($conduitdir !~ m/"^\."/) {
$conduitdir = ".$conduitdir";
}
$self->{'conduitdir'} = $ENV{'HOME'} . "/" . $conduitdir;
if (! defined $self->{'prefs'}) {
$self->{'prefs'} = $self->{'conduitdir'} . "/prefs";
}
## Load Pilot Hash's this lets us know if a pilot entry is new or if
## the record was deleted from BBDB. Also in the case of a full
## sync it lets us decide if the record has been modified.
my $prefs = new FileHandle($self->{'prefs'});
if ($prefs)
{
$self->output("Prefs: $self->{'prefs'}\n");
chop($self->{'pcid'} = <$prefs>);
chop($self->{'syncTime'} = <$prefs>);
}
else
{
$self->{'pcid'} = rand(2147483648) + 1;
$self->{'syncTime'} = 0;
}
$prefs = undef;
$self->output("Please start HotSync now.\n");
$self->{'psocket'} = PDA::Pilot::openPort($self->{'port'});
die "Unable to open Pilot port $self->{'port'}\n" if (!$self->{'psocket'});
$self->{'dlp'} = PDA::Pilot::accept($self->{'psocket'});
die "Cancelled.\n" if (!$self->{'dlp'} ||
$self->{'dlp'}->getStatus()<0);
$self->{'info'} = $self->{'dlp'}->getUserInfo();
return $self;
}
sub finish {
my $self = shift;
$self->{'syncTime'} = time;
$self->{'info'}->{"lastSyncDate"} = $self->{'syncTime'};
$self->{'info'}->{'lastSyncPC'} = $self->{'pcid'};
$self->{'dlp'}->setUserInfo($self->{'info'});
$self->{'dlp'}->close();
my $prefs = new FileHandle(">$self->{'prefs'}");
print $prefs "$self->{'pcid'}\n";
print $prefs "$self->{'syncTime'}\n";
$prefs = undef;
if ($self->{'last status msg'}) {
print STDOUT "\n";
}
}
sub output {
my $self = shift;
my $str = shift;
if (!$self->{'last status msg'}) {
print STDOUT ($self->{'prefix'} . $str);
return;
}
if ($str !~ m/\n$/) {
my $len = (length(": %") +
length($self->{'last status msg'}) +
length($self->{'last status percent'})) - length($str);
print STDOUT ("\r" . $str . (" "x$len));
return;
}
chop($str); # Drop the newline
my $len = (length(": %") +
length($self->{'last status msg'}) +
length($self->{'last status percent'})) - length($str);
my $msg = $self->{'last status msg'};
my $done = $self->{'last status percent'};
my $prevBar = $|;
$| = 1;
print STDOUT ("\r" . $str . (" "x$len) . "\n" .
"$msg: $done%");
$|=$prevBar;
}
sub status {
my $self = shift;
my $msg = shift;
my $done = shift;
my $ctime = time;
# Update at the earliest of 1 sec, 5 percent or new message...
if (($self->{'last status msg'} ne $msg) ||
($self->{'last status percent'}+5 < $done) ||
($self->{'last status time'}+1 < $ctime)) {
my $pad = (" " x
(length($self->{'last status msg'}) -length($msg)+
length($self->{'last status percent'})-length($done)));
my $prevBar = $|;
$| = 1;
print STDOUT "\r$msg: $done%" . $pad;
print STDOUT "\r$msg: $done%";
$|=$prevBar;
$self->{'last status msg'} = $msg;
$self->{'last status percent'} = $done;
$self->{'last status time'} = $ctime;
}
}
sub thisPC {
my $self = shift;
return $self->{'pcid'};
}
sub lastSyncDate {
my $self = shift;
return $self->{'syncTime'};
}
sub getUserID {
my $self = shift;
return $self->{'info'}->{'userID'};
}
sub getUserName {
my $self = shift;
return $self->{'info'}->{'name'};
}
sub getConduitDir {
my $self = shift;
return $self->{'conduitdir'};
}
sub update {
my $self = shift;
$self->{'dlp'}->tickle();
}
1;
|