# MTLDAPImpl

The MTLDAPImpl object is a COM encapsulation around the Netscape's C LDAP SDK API. This object opens the connection to the LDAP server and binds to the LDAP server with a distinguished name (dn). The dn, login and password are stored in the LDAPServer.xml file under config\development\serveraccess. This object allows you to add, modify, delete and get data from the LDAP server. The object that stores MetraTech specific contact data is called the contact object.

## Program ID

MTLDAP.MTLDAPImpl

## MTLDAP Methods

Add | Adds the given data set to the LDAP directory.
AddContact | Adds a contact to the LDAP directory given various information.
AddData | Adds the given account property collection to the LDAP directory.
DeleteContact | Deletes a contact from the LDAP directory given its DN.
Initialize | Initializes the LDAP object. It gets the hostname, the distinguished name, domain organization and password.
ModifyContact | Modifies a contact in the LDAP directory identified by the given DN.
RetrieveContact | Retrieves the contact associated with the given account ID.
RetrieveContactByAttribute | Retrieves the given attribute for the contact associated with the account ID passed in.
Search | Searches the LDAP directory to find and retrieve all contacts that match any of the given personal information.

## Example

Example to be provided in a future release of this online help system.

# Method Detail

## Initialize

Initializes the LDAP object. It gets the hostname, distinguished name, domain organization and password. It also opens a connection to the LDAP server and binds the distinguished name.

### Visual Basic Syntax

Sub Initialize()

### C++ Syntax

STDMETHODIMP CMTLDAPImpl::Initialize()

### Errors Raised

Unable to create instance of MTServerAccessDataSet object.

Initialize method failed on MTServerAccessDataSet object.

No records found in the MTServerAccessDataSet object.

Exception in Initialize method of MTLDAPImpl object.

ldap_open failed!

ldap_bind failed!

## Add

Adds the given data set to the LDAP directory.

### Visual Basic Syntax

Sub Add(pDataSet As MTLDAPDataSet)

### C++ Syntax

STDMETHODIMP CMTLDAPImpl::Add(IMTLDAPDataSet *pDataSet)

## AddData

Adds the given account property collection to the LDAP directory.

### Visual Basic Syntax

Sub AddData(mtptr As IMTAccountPropertyCollection)

### C++ Syntax

STDMETHODIMP CMTLDAPImpl::AddData(::IMTAccountPropertyCollection* mtptr)

### Arguments

IMTAccountPropertyCollection* mtptr

The account property collection to be added.

### Errors Raised

Unable to iterate.

Unknown variant type.

Last name not found.

First name not found.

Account Type not found.

Account ID not found.

Unknown account type ...

... contact already exists for account ID...

One of the required fields for LDAP server is missing for ... Please check Netscapes Directory server console.

ldap_add failed with error code ... and error string ... for ... and ...

## AddContact

Adds a contact to the LDAP directory given various information.

### Visual Basic Syntax

Sub AddContact(FirstName As String, LastName As String,
Email As String, TelephoneNumber As String, AccountType As String, AccountID As Long, TariffID As Long, GeoCode As Long,
TaxExempt As String, TimezoneID As Long,
TimezoneOffset As Double, Company As String, Address1 As String, Address2 As String, Address3 As String, City As String,
State As String, Zip As String, Country As String, Fax As String, MiddleInitial As String)

### C++ Syntax

STDMETHODIMP CMTLDAPImpl::AddContact(BSTR FirstName,BSTR LastName,BSTR Email,BSTR PhoneNumber,BSTR AccountType,long AccountID,long TariffID,long GeoCode,BSTR TaxExempt,long TimezoneID.double TimezoneOffset,BSTR Company,BSTR Address1,BSTR Address2,BSTR Address3,BSTR City,BSTR State,BSTR Zip,BSTR Country,BSTR Fax,BSTR MiddleInitial)

### Arguments

BSTR FirstName

First name.

BSTR LastName

Last name.

BSTR Email

Email address.

BSTR PhoneNumber

Phone number.

BSTR AccountType

Account's type.

long AccountID

Account ID.

long TariffID

Tariff ID.

long GeoCode

GeoCode.

BSTR TaxExempt

Tax exempt status.

long TimezoneID

Time zone ID.

double TimezoneOffset

Time zone offset.

BSTR Company

Company.

BSTR Address1

Address (line 1).

BSTR Address2

Address (line 2).

BSTR Address3

Address (line 3).

BSTR City

City.

BSTR State

State.

BSTR Zip

Zipcode.

BSTR Country

Country.

BSTR Fax

Fax number.

BSTR MiddleInitial

Middle initial.

### Errors Raised

ldap_delete failed

... contact already exists for account ID ...

One of the required fields for LDAP server is missing for... account ID ... Please check Netscapes Directory server console.

ldap_add failed with error code ... and error string ...for ... and ...

## ModifyContact

Modifies a contact in the LDAP directory identified by the given DN. Modification is performed by first deleting the contact from the directory and then adding the new contact information.

### Visual Basic Syntax

Sub ModifyContact(FirstName As String, LastName As String,
Email As String, TelephoneNumber As String, AccountType As String, AccountID As Long, TariffID As Long, TaxExempt As String, TimezoneID As Long, TimezoneOffset As Double,
Company As String, Address1 As String, Address2 As String, Address3 As String, City As String, State As String, Zip As String, Country As String, Fax As String, MiddleInitial As String,
DN As String)

### C++ Syntax

STDMETHODIMP CMTLDAPImpl::ModifyContact(BSTR FirstName,BSTR LastName,BSTR Email,BSTR PhoneNumber,BSTR AccountType,long AccountID,long TariffID,BSTR TaxExempt,long TimezoneID,double TimezoneOffset,BSTR Company,BSTR Address1,BSTR Address2,BSTR Address3,BSTR City,BSTR State,BSTR Zip,BSTR Country,BSTR Fax,BSTR MiddleInitial,BSTR DN)

### Arguments

BSTR FirstName

First name.

BSTR LastName

Last name.

BSTR Email

Email address.

BSTR PhoneNumber

Phone number.

BSTR AccountType

Account's type.

long AccountID

Account ID.

long TariffID

Tariff ID.

long GeoCode

GeoCode.

BSTR TaxExempt

Tax exempt status.

long TimezoneID

Time zone ID.

double TimezoneOffset

Time zone offset.

BSTR Company

Company.

BSTR Address1

Address (line 1).

BSTR Address2

Address (line 2).

BSTR Address3

Address (line 3).

BSTR City

City.

BSTR State

State.

BSTR Zip

Zipcode.

BSTR Country

Country.

BSTR Fax

Fax number.

BSTR MiddleInitial

Middle initial.

### Errors Raised

ldap_delete failed

... contact already exists for account ID ...

One of the required fields for LDAP server is missing for... account ID ... Please check Netscapes Directory server console.

ldap_add failed with error code ... and error string ...for ... and ...

## DeleteContact

Deletes a contact from the LDAP directory given its DN.

### Visual Basic Syntax

Sub DeleteContact(DN As String)

### C++ Syntax

STDMETHODIMP CMTLDAPImpl::DeleteContact(BSTR DN)

### Arguments

BSTR DN

The distinguished name of the contact to delete.

### Errors Raised

Attempt to delete non existing contact. DN = ...

ldap_delete failed with error code ... and error string... for DN ...

## RetrieveContactbyAttribute

Retrieves the given attribute for the contact associated with the account ID passed in.

### Visual Basic Syntax

Function RetrieveContactByAttribute(AccountID As Long,
Attribute As String) As String

### C++ Syntax

STDMETHODIMP CMTLDAPImpl::RetrieveContactByAttribute (long AccountID,BSTR Attribute,BSTR* pVal)

### Arguments

Long AccountID

The account ID.

BSTR Attribute

The name of the attribute to retrieve.

### Return Value

BSTR* pVal

The value of the attribute.

### Errors Raised

ldap_open failed! Host ... on port ...

ldap_bind failed! DN ... Password ...

Search resulted in no contacts.

## RetrieveContact

Retrieves the contact associated with the given account ID.

### Visual Basic Syntax

Sub RetrieveContact(AccountID As Long)

### C++ Syntax

STDMETHODIMP CMTLDAPImpl::RetrieveContact(long AccountID)

### Arguments

Long AccountID

The account ID.

### Errors Raised

ldap_open failed! Host ... on port ...

ldap_bind failed! DN ... Password ...

Search resulted in no contacts.

## Search

Searches the LDAP directory to find and retrieves all contacts that match any of the given personal information.

### Visual Basic Syntax

Sub Search(FirstName As String, LastName As String,
Email As String, Company As String, TelephoneNumber As String)

### C++ Syntax

STDMETHODIMP CMTLDAPImpl::Search(BSTR FirstName, BSTR LastName, BSTR Email, BSTR Company, BSTR PhoneNumber)

### Arguments

BSTR FirstName

First name.

BSTR LastName

Last name.

BSTR Email

Email address.

BSTR PhoneNumber

Phone number.

BSTR Company

Company name.

### Errors Raised

ldap_open failed! Host ... on port ...

ldap_bind failed! DN ... Password ...

Search resulted in no contacts.

##