KLdap

ldapcontrol.cpp
1 /*
2  This file is part of libkldap.
3  SPDX-FileCopyrightText: 2004-2006 Szombathelyi Gy├Ârgy <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "ldapcontrol.h"
9 #include "ber.h"
10 
11 #include <QSharedData>
12 
13 using namespace KLDAP;
14 
15 class LdapControlPrivate : public QSharedData
16 {
17 public:
18  LdapControlPrivate()
19  {
20  }
21 
22  LdapControlPrivate(const LdapControlPrivate &other)
23  : QSharedData(other)
24  {
25  mOid = other.mOid;
26  mValue = other.mValue;
27  mCritical = other.mCritical;
28  }
29 
30  QString mOid;
31  QByteArray mValue;
32  bool mCritical = false;
33 };
34 
36  : d(new LdapControlPrivate)
37 {
38  setControl(QString(), QByteArray(), false);
39 }
40 
42  : d(new LdapControlPrivate)
43 {
44  setControl(oid, value, critical);
45 }
46 
48  : d(that.d)
49 {
50  setControl(that.d->mOid, that.d->mValue, that.d->mCritical);
51 }
52 
53 LdapControl &LdapControl::operator=(const LdapControl &that)
54 {
55  if (this != &that) {
56  d = that.d;
57  }
58 
59  setControl(that.d->mOid, that.d->mValue, that.d->mCritical);
60 
61  return *this;
62 }
63 
65 {
66 }
67 
69 {
70  d->mOid = oid;
71  d->mValue = value;
72  d->mCritical = critical;
73 }
74 
76 {
77  return d->mOid;
78 }
79 
81 {
82  return d->mValue;
83 }
84 
86 {
87  return d->mCritical;
88 }
89 
91 {
92  d->mOid = oid;
93 }
94 
96 {
97  d->mValue = value;
98 }
99 
101 {
102  d->mCritical = critical;
103 }
104 
106 {
107  if (d->mOid != QLatin1String("1.2.840.113556.1.4.319")) {
108  return -1;
109  }
110 
111  Ber ber(d->mValue);
112  int size;
113  if (ber.scanf(QStringLiteral("{iO}"), &size, &cookie) == -1) {
114  return -1;
115  } else {
116  return size;
117  }
118 }
119 
121 {
122  LdapControl control;
123  Ber ber;
124 
125  ber.printf(QStringLiteral("{iO}"), pagesize, &cookie);
126  control.setOid(QStringLiteral("1.2.840.113556.1.4.319"));
127  control.setValue(ber.flatten());
128  return control;
129 }
130 
132 {
134  LdapControls::iterator endit = list.end();
135  const QString oid = ctrl.oid();
136 
137  for (it = list.begin(); it != endit; ++it) {
138  if (it->oid() == oid) {
139  *it = ctrl;
140  return;
141  }
142  }
143  list.append(ctrl);
144 }
void setCritical(bool critical)
Sets the control&#39;s criticality.
void append(const T &value)
QVector::iterator begin()
typedef iterator
static LdapControl createPageControl(int pagesize, const QByteArray &cookie=QByteArray())
Creates a paging search control.
This class allows encoding and decoding Qt structures using Basic Encoding Rules. ...
Definition: ber.h:22
void setOid(const QString &oid)
Sets the control&#39;s OID.
Definition: ldapcontrol.cpp:90
QByteArray flatten() const
Returns the Ber object as a flat QByteArray.
Definition: ber.cpp:422
Definition: ber.h:17
bool critical() const
Returns the control&#39;s criticality.
Definition: ldapcontrol.cpp:85
void setControl(const QString &oid, const QByteArray &value, bool critical=false)
Sets the control&#39;s OID, value and criticality.
Definition: ldapcontrol.cpp:68
void setValue(const QByteArray &value)
Sets the control&#39;s value.
Definition: ldapcontrol.cpp:95
This class represents an LDAP Control.
Definition: ldapcontrol.h:28
QString oid() const
Returns the control&#39;s OID.
Definition: ldapcontrol.cpp:75
int printf(QString format,...)
Appends the data with the specified format to the Ber object.
Definition: ber.cpp:428
QVector::iterator end()
QByteArray value() const
Returns the control&#39;s value.
Definition: ldapcontrol.cpp:80
static void insert(LdapControls &list, const LdapControl &ctrl)
Inserts a unique control against a list of controls.
~LdapControl()
Destroys the control object.
Definition: ldapcontrol.cpp:64
int parsePageControl(QByteArray &cookie) const
Parses a paging results control, which the server returned.
LdapControl()
Creates an empty control.
Definition: ldapcontrol.cpp:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 12 2020 23:10:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.