KLdap

ldapcontrol.cpp
1/*
2 This file is part of libkldap.
3 SPDX-FileCopyrightText: 2004-2006 Szombathelyi György <gyurco@freemail.hu>
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
13using namespace KLDAPCore;
14
15class LdapControlPrivate : public QSharedData
16{
17public:
18 LdapControlPrivate() = default;
19
20 LdapControlPrivate(const LdapControlPrivate &other) = default;
21
22 QString mOid;
23 QByteArray mValue;
24 bool mCritical = false;
25};
26
28 : d(new LdapControlPrivate)
29{
30 setControl(QString(), QByteArray(), false);
31}
32
33LdapControl::LdapControl(const QString &oid, const QByteArray &value, bool critical)
34 : d(new LdapControlPrivate)
35{
37}
38
40 : d(that.d)
41{
42 setControl(that.d->mOid, that.d->mValue, that.d->mCritical);
43}
44
45LdapControl &LdapControl::operator=(const LdapControl &that)
46{
47 if (this != &that) {
48 d = that.d;
49 }
50
51 setControl(that.d->mOid, that.d->mValue, that.d->mCritical);
52
53 return *this;
54}
55
57
58void LdapControl::setControl(const QString &oid, const QByteArray &value, bool critical)
59{
60 d->mOid = oid;
61 d->mValue = value;
62 d->mCritical = critical;
63}
64
66{
67 return d->mOid;
68}
69
71{
72 return d->mValue;
73}
74
76{
77 return d->mCritical;
78}
79
81{
82 d->mOid = oid;
83}
84
86{
87 d->mValue = value;
88}
89
90void LdapControl::setCritical(bool critical)
91{
92 d->mCritical = critical;
93}
94
96{
97 if (d->mOid != QLatin1StringView("1.2.840.113556.1.4.319")) {
98 return -1;
99 }
100
101 Ber ber(d->mValue);
102 int size;
103 if (ber.scanf(QStringLiteral("{iO}"), &size, &cookie) == -1) {
104 return -1;
105 } else {
106 return size;
107 }
108}
109
111{
112 LdapControl control;
113 Ber ber;
114
115 ber.printf(QStringLiteral("{iO}"), pagesize, &cookie);
116 control.setOid(QStringLiteral("1.2.840.113556.1.4.319"));
117 control.setValue(ber.flatten());
118 return control;
119}
120
122{
124 LdapControls::iterator endit = list.end();
125 const QString oid = ctrl.oid();
126
127 for (it = list.begin(); it != endit; ++it) {
128 if (it->oid() == oid) {
129 *it = ctrl;
130 return;
131 }
132 }
133 list.append(ctrl);
134}
This class allows encoding and decoding Qt structures using Basic Encoding Rules.
Definition ber.h:23
QByteArray flatten() const
Returns the Ber object as a flat QByteArray.
Definition ber.cpp:402
int printf(QString format,...)
Appends the data with the specified format to the Ber object.
Definition ber.cpp:408
This class represents an LDAP Control.
Definition ldapcontrol.h:29
static void insert(LdapControls &list, const LdapControl &ctrl)
Inserts a unique control against a list of controls.
void setValue(const QByteArray &value)
Sets the control's value.
bool critical() const
Returns the control's criticality.
void setOid(const QString &oid)
Sets the control's OID.
QString oid() const
Returns the control's OID.
void setCritical(bool critical)
Sets the control's criticality.
~LdapControl()
Destroys the control object.
int parsePageControl(QByteArray &cookie) const
Parses a paging results control, which the server returned.
void setControl(const QString &oid, const QByteArray &value, bool critical=false)
Sets the control's OID, value and criticality.
LdapControl()
Creates an empty control.
static LdapControl createPageControl(int pagesize, const QByteArray &cookie=QByteArray())
Creates a paging search control.
QByteArray value() const
Returns the control's value.
void append(QList< T > &&value)
iterator begin()
iterator end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.