Logo ROOT   6.16/01
Reference Guide
LDAPExample.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_net
3///
4/// \macro_code
5///
6/// \author
7
8void LDAPExample()
9{
10 gSystem->Load("libRLDAP.so");
11
12 TLDAPServer *server = new TLDAPServer("ldap.cern.ch");
13 if (!server->IsConnected()) {
14 printf("Could not connect to ldap.cern.ch\n");
15 delete server;
16 return;
17 }
18
19 TLDAPResult *result = server.Search();
20
21 if (result == 0) {
22 printf("Search failed\n");
23 return;
24 }
25 result->Print();
26 delete result;
27
28 const char *namingcontexts = server.GetNamingContexts();
29 result = server.Search(namingcontexts, LDAP_SCOPE_ONELEVEL, 0, 0, 1);
30 TLDAPEntry *entry = result.GetNext();
31 entry->Print();
32
33 TString dn = entry->GetDn();
34
35 delete result;
36 delete entry;
37
38 cout << "The DN of the entry is " << dn << endl;
39
40 result = server.Search(dn, LDAP_SCOPE_SUBTREE, 0, 0, 0);
41
42 if (result == 0) {
43 printf("Search failed\n");
44 return;
45 }
46
47 result->Print();
48 Int_t counter = result.GetCount();
49 cout << "The result contains " << counter << " entries !!!" << endl;
50
51 entry = result.GetNext();
52
53 TLDAPAttribute *attribute = entry.GetAttribute("member");
54
55 Int_t counter2 = attribute.GetCount();
56 cout << "The attribute " << attribute.GetName() << " contains "
57 << counter2 << " values !!!" << endl;
58 const char *value = attribute.GetValue();
59 cout << "The first value of the attribute is " << endl;
60 cout << value << endl;
61
62 delete result;
63 delete entry;
64}
int Int_t
Definition: RtypesCore.h:41
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
Int_t GetCount() const
const char * GetValue() const
Get next value of the attribute.
TLDAPAttribute * GetAttribute() const
Get next attribute of the entry.
Definition: TLDAPEntry.cxx:96
void Print(Option_t *="") const
Print entry in LDIF format.
Definition: TLDAPEntry.cxx:77
const char * GetDn() const
Definition: TLDAPEntry.h:41
TLDAPEntry * GetNext()
Returns next entry from the search result.
Definition: TLDAPResult.cxx:68
Int_t GetCount() const
Returns the number of entries in the search result.
void Print(Option_t *option="") const
Prints all entries.
Bool_t IsConnected() const
Definition: TLDAPServer.h:45
TLDAPResult * Search(const char *base="", Int_t scope=LDAP_SCOPE_BASE, const char *filter=0, TList *attrs=0, Bool_t attrsonly=0)
Performs searching at the LDAP directory.
const char * GetNamingContexts()
Performs an LDAPSearch with the attribute "namingContexts" to be returned with the result.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:131
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1843