/usr/share/perl5/SyncUtil/pilotHashDB.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 | #------------------------------------------------------------------------------
# $Date: 2000/08/06 19:45:02 $
# RCS: $Id: pilotHashDB.pm,v 1.4 2000/08/06 19:45:02 deweese Exp $
#------------------------------------------------------------------------------
package pilotHashDB;
use strict;
require Digest::MD5;
require SyncUtil::pilotDB;
@pilotHashDB::ISA = qw(pilotDB);
sub new {
my $type = shift;
my $self = pilotDB->new(shift, shift, shift);
bless ($self, $type);
$self->{'hashObj'} = shift;
return $self;
}
##############################################################################
###
### This section contains methods that all subclasses MUST implement.
###
##############################################################################
sub dupRec {
my $self = shift;
my $rec = shift;
die ("Subclass must implement dupRec to copy $rec and return the\n" .
"copy. Care must be taken to clear the associated pilot-id in\n" .
"the new record");
}
sub syncRec {
my $self = shift;
my $local_rec = shift;
my $pilot_rec = shift;
die ("Subclass must implement syncRec to merge contents of other_rec\n".
"into this_rec (may be undef in which case create a new record).");
## You need to take care to put the new record into local data structures.
## Subclasses will need to tack the following into the end of there
## syncRec function.
## Example:
## # Send the modified record back to the Pilot...
## $self->setRec($pilotRec);
##
## # Let the Local database know the updated ID...
## $self->{'localDB'}->setPilotID($bbdbRec, $pilotRec->{'id'});
}
##############################################################################
###
### This section contains methods that many subclasses may want to
### override.
###
##############################################################################
sub hashPilotRecord {
my $self = shift;
my $record = shift;
my $hash = new Digest::MD5;
$hash->add($record->{raw});
return $hash->hexdigest;
}
##############################################################################
###
### This section contains methods that many subclasses may want to
### augment. You will probably want to call the base class version of these
### methods as well. Example:
###
### $self->pilotHashDB::setup($fast, $pilotDB).
###
##############################################################################
sub setRec {
my $self = shift;
my $rec = shift;
my $id = $self->pilotDB::setRec($rec);
if ($id) {
my $phash = $self->hashPilotRecord($rec);
$self->{'hashObj'}->setPilotHash($id, $phash);
}
return $id;
}
sub deleteRec {
my $self = shift;
my $id = shift;
my($result) = $self->pilotDB::deleteRec($id);
if ($result>=0) {
$self->{'hashObj'}->setPilotHash($id, undef);
}
return $result;
}
sub slowSync {
my $self = shift;
my $db = $self->{'db'};
$self->{'host'}->status("Reading Pilot Addresses [full sync]", 0);
my $numRecs = $db->getRecords();
my $r;
my $i=0;
while (defined($r = $db->getRecord($i++))) {
$self->{'host'}->status("Reading Pilot Addresses [full sync]",
int(100 * $i / $numRecs));
# Basicly we can't trust the pilot to send us all the records that have
# changed. So we load them all up and diff the MD5 flags
# (and look for new/deletec ids relative to the hashObj).
# Record was 'just' deleted on palm we'll catch this down below
# Or else we don't care (it was added and deleted since we last
# synced).
next if ($r->{'deleted'});
$self->{'hash'}{$r->{'id'}} = $r;
my $hash = $self->{'hashObj'}->getPilotHash($r->{'id'});
my $newHash = $self->hashPilotRecord($r);
if (!defined $hash)
{
my $bbdbRec = $self->{'localDB'}->getRec($r->{'id'});
if (!defined $bbdbRec) {
# New entry, wasn't in local hash, or BBDB
push(@{$self->{'new'}}, $r);
} else {
# In this case we have an associated BBDB record,
# however neither is listed in the ids list. This means
# that something bad probably happened to our ids list.
# These records will get listed as modified in BBDB.
# So we will do nothing here....
}
$self->{'hashObj'}->setPilotHash($r->{'id'},$newHash);
}
elsif ($newHash ne $hash)
{
push(@{$self->{'mod'}}, $r); # Modified, current hash != last hash...
$self->{'hashObj'}->setPilotHash($r->{'id'},$newHash);
}
$self->update(); # Give our host some time...
}
foreach my $id (keys %{$self->{'hashObj'}->{'ids'}}) {
## ID was defined in local store but isn't on palm (or is but is
## marked for deletion), implies deleted from the palm.
my $rec = $self->getRec($id);
if (((!defined $rec) || $rec->{'deleted'}) &&
(defined $self->{'hashObj'}->getPilotHash($id)))
{
push(@{$self->{'del'}}, $id);
#Remove $id from the hash since it is going away...
$self->{'hashObj'}->setPilotHash($id, undef);
}
$self->update(); # Give our host some time...
}
$self->{'host'}->status("Reading Pilot Addresses [full sync]", 100);
}
1;
|