KLdap

ldif.h
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#pragma once
9
10#include <QByteArray>
11#include <QString>
12
13#include "kldap_core_export.h"
14#include "ldapdn.h"
15
16// clazy:excludeall=copyable-polymorphic
17
18namespace KLDAPCore
19{
20/**
21 * Ldif
22 *
23 * Ldif implements an RFC 2849 compliant Ldif parser. Ldif files are used to
24 * represent directory information on LDAP-based servers, or to describe a set
25 * of changes which are to be applied to a directory.
26 */
27
28class KLDAP_CORE_EXPORT Ldif
29{
30public:
31 using ParseValue = enum {
32 None,
33 NewEntry,
34 EndEntry,
35 Item,
36 Control,
37 Err,
38 MoreData
39 };
40
41 using EntryType = enum {
42 Entry_None,
43 Entry_Add,
44 Entry_Del,
45 Entry_Mod,
46 Entry_Modrdn
47 };
48
49 using ModType = enum {
50 Mod_None,
51 Mod_Add,
52 Mod_Replace,
53 Mod_Del
54 };
55
56 Ldif();
57
58 Ldif(const Ldif &that);
59 Ldif &operator=(const Ldif &that);
60
61 ~Ldif();
62
63 /**
64 * Assembles fieldname and value into a valid Ldif line, BASE64 encodes the
65 * value if necessary and optionally splits into more lines.
66 * @param fieldname The name of the entry.
67 * @param value The value of the entry.
68 * @param linelen Maximum length of the lines in the result.
69 * @param url If true, encode value as url ( use :< ).
70 */
71 [[nodiscard]] static QByteArray assembleLine(const QString &fieldname, const QByteArray &value, uint linelen = 0, bool url = false);
72 /**
73 * This is the same as the above function, the only difference that
74 * this accepts QString as the value.
75 */
76 [[nodiscard]] static QByteArray assembleLine(const QString &fieldname, const QString &value, uint linelen = 0, bool url = false);
77
78 /**
79 * Splits one line from an Ldif file to attribute and value components.
80 * @return true if value is an URL, false otherwise
81 */
82 [[nodiscard]] static bool splitLine(const QByteArray &line, QString &fieldname, QByteArray &value);
83
84 /**
85 * Splits a control specification (without the "control:" directive)
86 * @param line is the control directive
87 * @param oid will contain the OID
88 * @param critical will contain the criticality of control
89 * @param value is the control value
90 */
91 static bool splitControl(const QByteArray &line, QString &oid, bool &critical, QByteArray &value);
92
93 /**
94 * Starts the parsing of a new Ldif
95 */
96 void startParsing();
97
98 /**
99 * Process one Ldif line
100 */
101 [[nodiscard]] ParseValue processLine();
102
103 /**
104 * Process the Ldif until a complete item can be returned
105 * @return NewEntry if a new DN encountered, Item if a new item returned,
106 * Err if the Ldif contains error, EndEntry if the parser reached the end
107 * of the current entry and MoreData if the parser encountered the end of
108 * the current chunk of the Ldif.
109 *
110 * If you want to finish the parsing after receiving MoreData, then call
111 * endLdif(), so the parser can safely flush the current entry.
112 */
113 [[nodiscard]] ParseValue nextItem();
114
115 /**
116 * Sets a chunk of Ldif. Call before startParsing(), or if nextItem()
117 * returned MoreData.
118 * @param ldif the Ldif chunk to set
119 */
120 void setLdif(const QByteArray &ldif);
121
122 /**
123 * Indicates the end of the Ldif file/stream. Call if nextItem() returned
124 * MoreData, but actually you don't have more data.
125 */
126 void endLdif();
127
128 /**
129 * Returns the requested LDAP operation extracted from the current entry.
130 */
131 [[nodiscard]] EntryType entryType() const;
132
133 /**
134 * Returns the LDAP modify request type if entryType() returned Entry_Mod.
135 */
136 [[nodiscard]] int modType() const;
137
138 /**
139 * Returns the Distinguished Name of the current entry.
140 */
141 [[nodiscard]] LdapDN dn() const;
142
143 /**
144 * Returns the new Relative Distinguished Name if modType() returned
145 * Entry_Modrdn.
146 */
147 [[nodiscard]] QString newRdn() const;
148
149 /**
150 * Returns the new parent of the entry if modType() returned Entry_Modrdn.
151 */
152 [[nodiscard]] QString newSuperior() const;
153
154 /**
155 * Returns if the delete of the old RDN is required.
156 */
157 [[nodiscard]] bool delOldRdn() const;
158
159 /**
160 * Returns the attribute name.
161 */
162 [[nodiscard]] QString attr() const;
163
164 /**
165 * Returns the attribute value.
166 */
167 [[nodiscard]] QByteArray value() const;
168
169 /**
170 * Returns if val() is an url
171 */
172 [[nodiscard]] bool isUrl() const;
173
174 /**
175 * Returns the criticality level when modType() returned Control.
176 */
177 [[nodiscard]] bool isCritical() const;
178
179 /**
180 * Returns the OID when modType() returned Control.
181 */
182 [[nodiscard]] QString oid() const;
183
184 /**
185 * Returns the line number which the parser processes.
186 */
187 [[nodiscard]] uint lineNumber() const;
188
189private:
190 class LdifPrivate;
191 std::unique_ptr<LdifPrivate> const d;
192};
193}
Ldif.
Definition ldif.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:34:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.