AddressBook
view release on metacpan or search on metacpan
examples/SyncAbook.pm view on Meta::CPAN
PilotMgr::status("Opening Pilot AddressBook",0);
$self->{ldap} = AddressBook->new(source => "LDAP:localhost"
) || die;
$self->{pilot} = AddressBook->new(source => "PDB",
config=>$self->{ldap}->{config},
dlp=>$pilot_sock,
);
PilotMgr::status("Starting Synchronization",10);
AddressBook::sync(master=>$self->{ldap},slave=>$self->{pilot},msg_function=>\&PilotMgr::msg);
PilotMgr::status("Synchronization Complete",100);
$self->{ldap} = undef;
$self->{pilot} = undef;
return;
}
sub conduitQuit {
return;
}
sub conduitInfo {
my $ret = {
version => "0.100",
lib/AddressBook/DB/BBDB.pm view on Meta::CPAN
[ '\]', 'closing ]']
);
my $i;
foreach $i (@subpats) {
$pat .= $i->[0];
printf STDERR "No match at %s\n", $i->[1] and last unless
$str =~ m/^$pat/x;
$pat .= '\ ' unless $i->[0] eq '\[' or $i->[0] eq 'nil' ;
}
}
return undef;
}
my $i;
local($_);
foreach $i (@field_names) {
$fields[$field_index{$i}] = ''
if (!defined $fields[$field_index{$i}] or
$fields[$field_index{$i}] eq 'nil');
lib/AddressBook/DB/BBDB.pm view on Meta::CPAN
If called with two arguments, the first is the filename to create, and
the second is a reference to an array of BBDB objects, such as was
returned in the one argument version. The objects are scanned for
unique user defined fields, which are written out as the 2nd line in
the BBDB file, and then the individual records are written out.
=item decode(string)
Takes a string as written in a BBDB file of a single BBDB record
and decodes it into its PERL representation. Returns undef if
it couldn't decode the record for some reason, otherwise returns
true.
$bbdb->decode($entry);
=item encode()
This is the inverse of decode. Takes an internal PERL version of
a BBDB records and returns a string which is a lisp version of the
data that BBDB understands. There are some ambiguities, noted in
lib/AddressBook/DB/DBI.pm view on Meta::CPAN
if (! defined ($self->{so})) {
$self->reset;
}
if(defined ($_ = $self->{so}->fetchrow_hashref)) {
my $entry = AddressBook::Entry->new(db => $self->{db_name},
attr=>{%$_},
config=>$self->{config});
$entry->{timestamp} = $self->_get_timestamp;
return $entry;
}
return undef;
}
sub _get_timestamp {
my $self = shift;
my $class = ref $self || croak "Not a method call";
if ($self->{dbi_driver} =~ /^CSV/) {
my @stat = stat($self->{dbh}->{f_dir} . "/" . $self->{table});
return ParseDateString("epoch $stat[9]");
} else {
croak "Error: Don't know how to determine timestamp for this database type";
lib/AddressBook/DB/LDAP.pm view on Meta::CPAN
} else {
# We need to return everything;
$self->{so} = $self->{ldap}->search(base => $self->{base} || '',
async => 1,
filter => "objectclass=" . $self->{objectclass});
if ($self->{so}->code) {
$self->{code} = ldap_error_text($self->{so}->code) ;
return 0;
}
}
undef $self->{code};
return $self->{so}->count;
}
sub read {
my $self = shift;
my $class = ref $self || croak "Not a method call";
if (! defined $self->{so}) {
$self->reset;
}
if (defined (my $entry = $self->{so}->shift_entry)) {
my $attr;
my $ret = AddressBook::Entry->new(config=>$self->{config});
foreach $attr ($entry->attributes) {
if (exists $self->{config}->{db2generic}->{$self->{db_name}}->{$attr}) {
$ret->add(db=>$self->{db_name},attr=>{$attr=>[$entry->get_value($attr)]});
}
}
$ret->{timestamp} = _get_timestamp($entry);
undef $self->{code};
return $ret;
} else {
$self->{code} = ldap_error_text($self->{so}->code) ;
return undef;
}
}
sub _get_timestamp {
my $entry=shift;
my $timestamp;
if ($entry->exists("modifytimestamp")) {
($timestamp) = $entry->get_value("modifytimestamp");
} elsif ($entry->exists("createtimestamp")) {
($timestamp) = $entry->get_value("createtimestamp");
lib/AddressBook/DB/LDAP.pm view on Meta::CPAN
$self->{code} = ldap_error_text($result->code) ;
return 0;
}
}
my %attr = %{$entry->get(db=>$self->{db_name},values_only=>'1')};
$result=$self->{ldap}->modify("$rdn," . $self->{base},replace=>[%attr]);
if ($result->code) {
$self->{code} = ldap_error_text($result->code) ;
return 0;
}
undef $self->{code};
return 1;
}
sub add {
my $self = shift;
my $class = ref $self || croak "Not a method call";
my $entry = shift;
$entry->calculate;
my $dn = $self->_rdn_from_entry($entry) . "," . $self->{base};
my %attr = %{$entry->get(db=>$self->{db_name},values_only=>'1')};
$attr{objectclass} = [$self->{objectclass}];
my $result = $self->{ldap}->add($dn, attrs => [%attr]);
if ($result->code) {
$self->{code} = ldap_error_text($result->code) ;
return 0;
}
undef $self->{code};
return 1;
}
sub write {
my $self = shift;
my $class = ref $self || croak "Not a method call";
return $self->add(@_);
}
sub delete {
my $self = shift;
my $class = ref $self || croak "Not a method call.";
my $entry=shift;
$entry->calculate;
my $dn = $self->_rdn_from_entry($entry) . "," . $self->{base};
my $result = $self->{ldap}->delete($dn);
if ($result->code) {
$self->{code} = ldap_error_text($result->code) ;
return 0;
}
undef $self->{code};
return 1;
}
sub code {
my $self = shift;
my $class = ref $self || croak "Not a method call.";
return $self->{code};
}
sub _rdn_from_entry {
lib/AddressBook/DB/LDIF.pm view on Meta::CPAN
if (my $ldap_entry = $self->{ldif}->read) {
my $ret = AddressBook::Entry->new(config=>$self->{config});
foreach ($ldap_entry->attributes) {
if (exists $self->{config}->{db2generic}->{$self->{db_name}}->{$_}) {
$ret->add(db=>$self->{db_name},attr=>{$_=>[$ldap_entry->get_value($_)]});
}
}
$ret->{timestamp} = $self->_get_timestamp;
return $ret;
} else {
return undef;
}
}
sub write {
my $self = shift;
my $class = ref $self || croak "Not a method call";
$self->{fh}->seek(0,2); # jump to the end of the file
$self->{mode} = "w";
my $entry = shift;
$entry->calculate;
lib/AddressBook/DB/PDB.pm view on Meta::CPAN
}
my $entry = AddressBook::Entry->new(config=>$self->{config},
db=>$self->{db_name},
attr=>\%attr);
$entry->add(db=>$self->{db_name},
attr=>{category=>$reverse_category_hash{$record->{category}}});
if ($record->{modified}) {$entry->{timestamp} = ParseDate("Today")}
else {$entry->{timestamp} = 0}
return $entry;
} else {
return undef;
}
}
sub _insert_phone_labels {
my $self = shift;
my $class = ref $self || croak "Not a method call";
my ($phoneLayout) = @_;
my $i;
my %labels = reverse %{$self->{field_labels}};
my %phone_labels = reverse %{$self->{phone_labels}};
lib/AddressBook/DB/PDB.pm view on Meta::CPAN
# now process phone fields
foreach $field (sort {$attrs->{$a}->{meta}->{order} <=> $attrs->{$b}->{meta}->{order}} @phone_attrs) {
# for the time being, we will concatenate like phone fields
$value = join $self->{intra_attr_sep_char}, @{$attrs->{$field}->{value}};
$record->{phoneLabel}->[$phone_index] = $self->{phone_labels}->{$field};
$record->{entry}->[$phone_index+3] = $value;
$phone_index++;
if ($phone_index == 5) {last} # there is only room for 5 "phone" fields
}
for ($i=0;$i<=keys %labels;$i++) {
unless ($record->{entry}->[$i]) {$record->{entry}->[$i] = undef}
}
($phone_display_calc = $self->{phone_display}) =~ s/\$([\w-]+)/\$attrs->{$1}->{value}->[0]/g;
eval qq{ \$phone_display = $phone_display_calc }; warn "Syntax error in phone_display_calc: $@" if $@;
@phone_display = split ",",$phone_display;
find_phone: for ($i=0;$i<=$#phone_display;$i++) {
if ($attrs->{$phone_display[$i]}->{value}->[0]) {
$phone_target = $self->{phone_labels}->{$phone_display[$i]};
for ($j=0;$j<=$#{$record->{phoneLabel}};$j++) {
if ($record->{phoneLabel}->[$j] == $phone_target) {
$record->{showPhone} = $j;
lib/AddressBook/Entry.pm view on Meta::CPAN
=head2 compare
AddressBook::Entry::compare($entry1,$entry2)
Returns true if all attributes in both entries match, false otherwise.
=cut
sub compare {
my ($entry1,$entry2) = @_;
_compare_oneway($entry1,$entry2) || return undef;
_compare_oneway($entry2,$entry1) || return undef;
return 1;
}
sub _compare_oneway {
my ($entry1,$entry2) = @_;
my ($key,$i);
foreach $key (keys %{$entry1->{attr}}) {
if (defined $entry2->{attr}->{$key}) {
for ($i=0;$i<=$#{$entry1->{attr}->{$key}};$i++) {
if ($entry1->{attr}->{$key}->[$i] ne $entry2->{attr}->{$key}->[$i]) {
return undef;
}
}
return undef if ($#{$entry1->{attr}->{$key}} != $#{$entry2->{attr}->{$key}});
} else {
return undef;
}
}
return 1;
}
=head2 fill
$entry->fill(db=>$db);
$entry->fill(db=>$db,defaults=>1);
( run in 1.951 second using v1.01-cache-2.11-cpan-d80b1682f3f )