LDAPget application module for asterisk
(c)2004 Sven Slezak <sunny@mezzo.net>
Version: 0.9.3

LDAPget is an asterisk application which can lookup data 
in an LDAP directory (e.g. OpenLDAP or ActiveDirectory).
LDAPget does not require you to use a specific LDAP schema.
If the requested data is found in the directory it is assigned 
to a given variable an the priority is increased by 101.

The syntax for LDAPget in extensions.conf is as follows:

LDAPget(VARIABLE=config-file-section/lookup-key,lookup-key2,...)

If you would like to lookup the caller-id's name you could 
configure your extensions.conf like this:

exten => 1234,1,LDAPget(CIDNAME=cidname/${CALLERIDNUM})
exten => 1234,2,SetCIDName(${CIDNAME})
exten => 1234,3,Dial(Zap/11/${EXTEN},15)

Now you have to configure the corresponding section in your 
ldap.conf file. (an example file is included in this package)
Because we called the section 'cidname' we have to add a section
'cidname' to our ldap.conf file.

[cidname]
host = ldap.mydomain.com
user = cn=root,ou=People,o=mydomain.com
pass = secret
base = ou=Addressbook,o=mydomain.com
convert = UTF-8,ISO-8859-1

LDAPget will connect to ldap.mydomain.com on port 389 
(which you can change with 'port = <port>') and bind as 
user 'cn=root,ou=People,o=mydomain.com' with password 'secret'.
(if you ommit user and pass LDAPget will bind anonymously to the LDAP server.)

After successful bind it executes an LDAP search with a subdirectory scope 
from base 'ou=Addressbook,o=mydomain.com' with the default filter 
'(&(objectClass=person)(telephoneNumber=<lookup-key>))' 
You can change this with 'filter = <ldap filter>' where you have to use '%s' 
as a place holder for the lookup-key. 
For example if you want to lookup mobile telefon numbers as well you can change 
the filter to: (&(objectClass=person)(|(telephoneNumber=%s)(mobile=%s)))
the according entry in extensions.conf could look like this:
exten => 1234,1,LDAPget(CIDNAME=cidname/${CALLERIDNUM},${CALLERIDNUM})

When an object is found LDAPget sets the given variable 'CIDNAME' to the text found 
in the commonName attribute. (you can change the attribute to use with 
'attribute = <ldap attribute>').

And at last If the charset which is used by your directory server is not supported by 
your handset (like mine) you can have LDAPget convert the text into the required charset.


HOW TO COMPILE?

You will need the openldap client libraries and header files included in openldap-devel
and the iconv library and header file included in glibc-headers.
And asterisk of course.
Unpack the package
tar -xzf app_ldap-0.9.1.tgz

copy app_ldap.c into the apps directory of your asterisk distribution.

Add app_ldap to the targets in asterisk/apps/Makefile like:
APPS += app_ldap.so

and the following rule to the same Makefile:
app_ldap.so : app_ldap.o
  $(CC) $(SOLINK) -o $@ $< -llber -lldap

Finally in the asterisk directory execute:
make install


Restart asterisk or load the application with: 
load app_ldap.so

you're done. 'show application LDAPget' should print the description.
