Logo ROOT   6.16/01
Reference Guide
TLDAPEntry.cxx
Go to the documentation of this file.
1// @(#)root/ldap:$Id$
2// Author: Evgenia Smirnova 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 "TLDAPEntry.h"
10#include "TLDAPAttribute.h"
11#include "Riostream.h"
12
13
15
16////////////////////////////////////////////////////////////////////////////////
17/// Creates the new TLDAPEntry object with the specified DN (distinguished
18/// name) and the empty list of attributes.
19/// const char *dn: The DN of the entry. You can change it later by calling
20/// the SetDn() member function
21
22TLDAPEntry::TLDAPEntry(const char *dn) : fNCount(0)
23{
24 SetDn(dn);
25 fAttr = new TList;
26 fAttr->SetOwner();
27}
28
29////////////////////////////////////////////////////////////////////////////////
30/// Copy ctor.
31
32TLDAPEntry::TLDAPEntry(const TLDAPEntry &e) : TObject(e), fNCount(e.fNCount)
33{
34 SetDn(e.GetDn());
35 fAttr = new TList;
36 fAttr->SetOwner();
37
38 TIter next(e.fAttr);
39 while (TLDAPAttribute *att = (TLDAPAttribute *)next()) {
40 fAttr->AddLast(new TLDAPAttribute(*att));
41 }
42}
43
44////////////////////////////////////////////////////////////////////////////////
45/// Equal operator
46
48{
49 if(this!=&lde) {
51 fDn=lde.fDn;
52 fAttr=lde.fAttr;
53 fNCount=lde.fNCount;
54 } return *this;
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// Deletes all the attributes of the entry.
59
61{
62 delete fAttr;
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Add an attribute to the entry.
67/// TLDAPAtrribute attr: attribute to be added.
68
70{
71 fAttr->AddLast(new TLDAPAttribute(attr));
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Print entry in LDIF format.
76
78{
79 std::cout << "dn: "<< fDn << std::endl;
80 TLDAPAttribute *attr = GetAttribute("objectClass");
81 if (attr != 0)
82 attr->Print();
83 Int_t n = GetCount();
84 for (Int_t i = 0; i < n; i++) {
85 attr = (TLDAPAttribute*) fAttr->At(i);
86 if (TString(attr->GetName()).CompareTo("objectClass", TString::kIgnoreCase) != 0)
87 attr->Print();
88 }
89 std::cout << std::endl;
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Get next attribute of the entry. Returns zero after the last attribute,
94/// then returns the first attribute again.
95
97{
98 Int_t n = GetCount();
99 if (n > fNCount) {
100 return (TLDAPAttribute*)fAttr->At(fNCount++);
101 } else {
102 fNCount = 0;
103 return 0;
104 }
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Get attribute by name.
109/// Doesn't affect the order of attributes to be returned from the
110/// next GetAttribute() call. Attribute name is case insensitive.
111
113{
114 Int_t n = GetCount();
115 for (Int_t i = 0; i < n; i++) {
116 if (TString(((TLDAPAttribute*)fAttr->At(i))->GetName()).CompareTo(name, TString::kIgnoreCase) == 0) {
117 return (TLDAPAttribute*)fAttr->At(i);
118 }
119 }
120 return 0;
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Delete attribute by name.
125/// Attribute name is case insensitive.
126
128{
129 Int_t n = GetCount();
130 for (Int_t i = 0; i < n; i++) {
131 if (TString(((TLDAPAttribute*)fAttr->At(i))->GetName()).CompareTo(name, TString::kIgnoreCase) == 0) {
132 delete fAttr->Remove(fAttr->At(i));
133 if (fNCount > i) fNCount--;
134 return;
135 }
136 }
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// Check if entry is referal.
141
143{
144 Bool_t att = kFALSE;
145 Bool_t obj = kFALSE;
146 Int_t n = GetCount();
148 for (Int_t i = 0; (i < n) && (!att || !obj); i++) {
149 name = TString(((TLDAPAttribute*) fAttr->At(i))->GetName());
150 if (name.CompareTo("ref", TString::kIgnoreCase) == 0) {
151 att = kTRUE;
152 } else {
153 if (name.CompareTo("objectclass", TString::kIgnoreCase) == 0) {
155 Int_t valcnt = attr->GetCount() + 1;
156 for (Int_t j = 0; (j < valcnt) && (!obj); j++)
157 obj |= (Bool_t)TString(attr->GetValue()).CompareTo("referral", TString::kIgnoreCase);
158 }
159 }
160 }
161 return (att && obj);
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Get the TList of referrals.
166/// Returns an empty list if entry is not referral.
167/// User is responsible for deleting returned TList.
168
170{
171 TList *list = new TList;
172 TLDAPAttribute *ref = GetAttribute("ref");
173 if (ref != 0) {
174 Int_t n = ref->GetCount();
175 for (Int_t i = 0; i < n; i++) {
176 list->Add(ref->fValues->At(i));
177 }
178 }
179 return list;
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Get array of "LDAPMod" structures for entry.
184
186{
187 Int_t n = GetCount();
188 LDAPMod **mods = new LDAPMod* [n + 1];
189 for (Int_t i = 0; i < n; i++)
190 mods[i] = ((TLDAPAttribute*)(fAttr->At(i)))->GetMod(op);
191 mods[n] = 0;
192 return mods;
193}
#define e(i)
Definition: RSha256.hxx:103
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:363
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Int_t GetCount() const
void Print(Option_t *="") const
Print an attribute.
const char * GetValue() const
Get next value of the attribute.
void AddAttribute(const TLDAPAttribute &attr)
Add an attribute to the entry.
Definition: TLDAPEntry.cxx:69
TLDAPAttribute * GetAttribute() const
Get next attribute of the entry.
Definition: TLDAPEntry.cxx:96
TList * GetReferrals() const
Get the TList of referrals.
Definition: TLDAPEntry.cxx:169
LDAPMod ** GetMods(Int_t op)
Get array of "LDAPMod" structures for entry.
Definition: TLDAPEntry.cxx:185
void Print(Option_t *="") const
Print entry in LDIF format.
Definition: TLDAPEntry.cxx:77
TString fDn
Definition: TLDAPEntry.h:27
Int_t fNCount
Definition: TLDAPEntry.h:29
TLDAPEntry & operator=(const TLDAPEntry &)
Equal operator.
Definition: TLDAPEntry.cxx:47
Int_t GetCount() const
Definition: TLDAPEntry.h:47
void SetDn(const char *dn)
Definition: TLDAPEntry.h:42
TList * fAttr
Definition: TLDAPEntry.h:28
Bool_t IsReferral() const
Check if entry is referal.
Definition: TLDAPEntry.cxx:142
TLDAPEntry(const char *dn)
Creates the new TLDAPEntry object with the specified DN (distinguished name) and the empty list of at...
Definition: TLDAPEntry.cxx:22
void DeleteAttribute(const char *name)
Delete attribute by name.
Definition: TLDAPEntry.cxx:127
virtual ~TLDAPEntry()
Deletes all the attributes of the entry.
Definition: TLDAPEntry.cxx:60
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:818
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:354
virtual void AddLast(TObject *obj)
Add object at the end of the list.
Definition: TList.cxx:149
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.h:271
Basic string class.
Definition: TString.h:131
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:406
@ kIgnoreCase
Definition: TString.h:263
const Int_t n
Definition: legend1.C:16