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"
9using namespace Qt::Literals::StringLiterals;
10
11#include "ber.h"
12
13#include <QSharedData>
14
15using namespace KLDAPCore;
16
17class LdapControlPrivate : public QSharedData
18{
19public:
20 LdapControlPrivate() = default;
21
22 LdapControlPrivate(const LdapControlPrivate &other) = default;
23
24 QString mOid;
25 QByteArray mValue;
26 bool mCritical = false;
27};
28
30 : d(new LdapControlPrivate)
31{
32 setControl(QString(), QByteArray(), false);
33}
34
35LdapControl::LdapControl(const QString &oid, const QByteArray &value, bool critical)
36 : d(new LdapControlPrivate)
37{
39}
40
42 : d(that.d)
43{
44 setControl(that.d->mOid, that.d->mValue, that.d->mCritical);
45}
46
47LdapControl &LdapControl::operator=(const LdapControl &that)
48{
49 if (this != &that) {
50 d = that.d;
51 }
52
53 setControl(that.d->mOid, that.d->mValue, that.d->mCritical);
54
55 return *this;
56}
57
59
60void LdapControl::setControl(const QString &oid, const QByteArray &value, bool critical)
61{
62 d->mOid = oid;
63 d->mValue = value;
64 d->mCritical = critical;
65}
66
68{
69 return d->mOid;
70}
71
73{
74 return d->mValue;
75}
76
78{
79 return d->mCritical;
80}
81
83{
84 d->mOid = oid;
85}
86
88{
89 d->mValue = value;
90}
91
92void LdapControl::setCritical(bool critical)
93{
94 d->mCritical = critical;
95}
96
98{
99 if (d->mOid != "1.2.840.113556.1.4.319"_L1) {
100 return -1;
101 }
102
103 Ber ber(d->mValue);
104 int size;
105 if (ber.scanf(QStringLiteral("{iO}"), &size, &cookie) == -1) {
106 return -1;
107 } else {
108 return size;
109 }
110}
111
113{
114 LdapControl control;
115 Ber ber;
116
117 ber.printf(QStringLiteral("{iO}"), pagesize, &cookie);
118 control.setOid(QStringLiteral("1.2.840.113556.1.4.319"));
119 control.setValue(ber.flatten());
120 return control;
121}
122
124{
126 LdapControls::iterator endit = list.end();
127 const QString oid = ctrl.oid();
128
129 for (it = list.begin(); it != endit; ++it) {
130 if (it->oid() == oid) {
131 *it = ctrl;
132 return;
133 }
134 }
135 list.append(ctrl);
136}
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 Mon Nov 18 2024 12:16:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.