Logo ROOT   6.10/09
Reference Guide
TLDAPResult.cxx
Go to the documentation of this file.
1 // @(#)root/ldap:$Id$
2 // Author: Oleksandr Grebenyuk 21/09/2001
3 
4 /*************************************************************************
5  * For the licensing terms see $ROOTSYS/LICENSE. *
6  * For the list of contributors see $ROOTSYS/README/CREDITS. *
7  *************************************************************************/
8 
9 #include "TLDAPResult.h"
10 #include "TLDAPEntry.h"
11 #include "TLDAPAttribute.h"
12 
13 
15 
16 ////////////////////////////////////////////////////////////////////////////////
17 /// TLDAPResult object is just a wrapper of the LDAPMessage structure.
18 /// LDAP *ld: The current session handler
19 /// LDAPMessage *searchresult: The LDAPMessage structure returned from
20 /// the ldap_search_s() call
21 
22 TLDAPResult::TLDAPResult(LDAP *ld, LDAPMessage *searchresult)
23  : fLd(ld), fSearchResult(searchresult), fCurrentEntry(searchresult)
24 {
25  if (!GetCount())
26  fCurrentEntry = 0;
27 }
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// Copy constructor
31 
33  TObject(ldr),
34  fLd(ldr.fLd),
35  fSearchResult(ldr.fSearchResult),
36  fCurrentEntry(ldr.fCurrentEntry)
37 {
38 }
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Equal operator
42 
44 {
45  if(this!=&ldr) {
46  TObject::operator=(ldr);
47  fLd=ldr.fLd;
50  } return *this;
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Deletes the LDAPMessage structure
55 
57 {
58  if (fSearchResult)
59  ldap_msgfree(fSearchResult);
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// Returns next entry from the search result.
64 /// After the last entry it returns a zero pointer
65 /// and after this it returns the first entry again.
66 /// The user is responsable for deleting the returned object after use.
67 
69 {
71  fCurrentEntry = (fCurrentEntry != 0 ? ldap_next_entry(fLd, fCurrentEntry) :
72  (GetCount() != 0 ? fSearchResult : 0));
73  return entry;
74 }
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Creates TLDAPEntry object from the data containing in the LDAPMessage
78 /// structure and returns pointer to it.
79 /// The user is responsable for deleting the returned object after use.
80 /// LDAPMessage *entry: Pointer to the LDAPMessage structure containing
81 /// the entry data.
82 
84 {
85  if (entry == 0)
86  return 0;
87 
88  char *dn;
89  char *attr;
90  BerValue **vals;
91  BerElement *ptr;
92 
93  dn = ldap_get_dn(fLd, entry);
94  TLDAPEntry *ldapentry = new TLDAPEntry(dn);
95  for (attr = ldap_first_attribute(fLd, entry, &ptr); attr != 0;
96  attr = ldap_next_attribute(fLd, entry, ptr)) {
97  TLDAPAttribute attribute(attr);
98  vals = ldap_get_values_len(fLd, entry, attr);
99  if (vals) {
100  for (Int_t i = 0; vals[i] != 0; i++) {
101  attribute.AddValue(vals[i]->bv_val);
102  }
103  ldap_value_free_len(vals);
104  }
105  ldapentry->AddAttribute(attribute);
106  }
107 
108  return ldapentry;
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Returns the number of entries in the search result
113 
115 {
116  LDAP *ld = fLd;
117  LDAPMessage *result = fSearchResult;
118 
119  return ldap_count_entries(ld, result);
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Prints all entries.
124 /// Calls the Print() member function of the each entry.
125 
127 {
128  TLDAPEntry *e;
129  Int_t count = GetCount() + 1;
130  for (Int_t i = 0; i < count; i++) {
131  e = const_cast<TLDAPResult*>(this)->GetNext();
132  if (e) {
133  e->Print();
134  delete e;
135  }
136  }
137 }
void AddValue(const char *value)
Add a value to the attribute.
const char Option_t
Definition: RtypesCore.h:62
TLDAPEntry * CreateEntry(LDAPMessage *entry)
Creates TLDAPEntry object from the data containing in the LDAPMessage structure and returns pointer t...
Definition: TLDAPResult.cxx:83
int Int_t
Definition: RtypesCore.h:41
void AddAttribute(const TLDAPAttribute &attr)
Add an attribute to the entry.
Definition: TLDAPEntry.cxx:69
Int_t GetCount() const
Returns the number of entries in the search result.
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.h:250
TLDAPResult & operator=(const TLDAPResult &)
Equal operator.
Definition: TLDAPResult.cxx:43
void Print(Option_t *="") const
Print entry in LDIF format.
Definition: TLDAPEntry.cxx:77
LDAPMessage * fCurrentEntry
Definition: TLDAPResult.h:27
void Print(Option_t *option="") const
Prints all entries.
TLDAPEntry * GetNext()
Returns next entry from the search result.
Definition: TLDAPResult.cxx:68
#define ClassImp(name)
Definition: Rtypes.h:336
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
Mother of all ROOT objects.
Definition: TObject.h:37
virtual ~TLDAPResult()
Deletes the LDAPMessage structure.
Definition: TLDAPResult.cxx:56
double result[121]
LDAPMessage * fSearchResult
Definition: TLDAPResult.h:26
LDAP * fLd
Definition: TLDAPResult.h:25