5 Vcard2Ldap - Stuff for convert LDAP entries to Jabberd roster ones.
10 my $ldap = Vcard2Ldap::ldap_open ();
11 my $users = Vcard2Ldap::jabber_get_users ($ldap);
16 This module isn't intend for general usage, it was made for the sole purpose of
17 working together with vcard2ldap jabberd module.
19 See http://repo.or.cz/w/vcard2ldap.git for details.
25 List of global variables.
29 The jabberd server hostname
33 The name of the roster group where jids will be stored.
37 List of public functions.
41 Open connection. Returns a LDAP handler.
43 =item C<jabber_get_users>
45 Returns a list of records: {jid,group}
49 Returns a jid from an LDAP entry.
51 =item C<vcard_get_map>
53 Returns the "vCard map". This hash maps XML vCard tags to LDAP attributes.
58 our $jabberd = "jabber.domain.com";
59 our $groupname = "Iris";
61 my $vcardtpl = "../ldap/vcard.xml";
63 my $basedn = "dc=nodomain";
64 my $ldapserver = "localhost";
65 my $disname="cn=admin,dc=nodomain";
66 my $ldappass= "secret";
67 my $ldapperson = "irisPerson";
70 my $ldapjidattr = "irisUserPresenceID";
71 my $ldapjidmatch = qr/urn:mace:rediris.es:presence:xmpp:([\w\-_\.]+@.+)/;
73 ##########################
78 use Net
::LDAP
::Control
;
83 my $ldap = Net
::LDAP
->new ($ldapserver, debug
=> 0) or die "$@";
84 my $mesg = $ldap->bind (
86 password
=> $ldappass,
87 version
=> 3) or die "Cannot bind to ldap server. $!";
89 die $mesg->error if $mesg->code;
97 my $us = $ldap->search(
100 filter
=> "(&(objectClass=$ldapperson)($ldapgroup=*))"
102 die $us->error if $us->code;
111 sub jabber_get_users
{
114 ldap_get_users
($ldap);
125 foreach (@
{$user->get_value ($ldapjidattr, asref
=> 1)}) {
126 if (length ($ldapjidmatch) == 0) {
129 $jid = $_ =~ $ldapjidmatch;
131 if (length ($jid) != 0) {
137 die user
->get_value ("cn") . ": user with no jid!";
141 my $xs = new XML
::Simple
(keeproot
=> 0, suppressempty
=> 1);
142 my $vcard = $xs->XMLin($vcardtpl);
145 while (my ($key, $value) = each (%$vcard)) {
146 for (split(/\n/, parse_vcard
($key, $value))) {
147 my @sp = split(/ /, $_);
148 $vcard2ldap->{$sp[0]} = $sp[1];
160 foreach ($us->entries) {
162 "jid" => jabber_jid
($_),
163 "rostergroup" => $_->get_value ($ldapgroup)
173 if (!ref ($value) && !($key eq "xmlns")) {
174 $ret = $ret . $key ." " . $value . "\n";
175 } elsif (ref ($value) eq "HASH" ) {
176 for my $k2 ( keys %$value ) {
179 } elsif ($k2 eq "content") {
180 $ret = $ret . "$key". parse_vcard
('', $value->{$k2});
182 $ret = $ret . "$key/". parse_vcard
($k2, $value->{$k2});
185 } elsif (ref ($value) eq "ARRAY") {
187 $ret = $ret . "$key" . parse_vcard
('', $_);