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 { None, NewEntry, EndEntry, Item, Control, Err, MoreData };
32
33 using EntryType = enum { Entry_None, Entry_Add, Entry_Del, Entry_Mod, Entry_Modrdn };
34
35 using ModType = enum { Mod_None, Mod_Add, Mod_Replace, Mod_Del };
36
37 Ldif();
38
39 Ldif(const Ldif &that);
40 Ldif &operator=(const Ldif &that);
41
42 ~Ldif();
43
44 /**
45 * Assembles fieldname and value into a valid Ldif line, BASE64 encodes the
46 * value if necessary and optionally splits into more lines.
47 * @param fieldname The name of the entry.
48 * @param value The value of the entry.
49 * @param linelen Maximum length of the lines in the result.
50 * @param url If true, encode value as url ( use :< ).
51 */
52 [[nodiscard]] static QByteArray assembleLine(const QString &fieldname, const QByteArray &value, uint linelen = 0, bool url = false);
53 /**
54 * This is the same as the above function, the only difference that
55 * this accepts QString as the value.
56 */
57 [[nodiscard]] static QByteArray assembleLine(const QString &fieldname, const QString &value, uint linelen = 0, bool url = false);
58
59 /**
60 * Splits one line from an Ldif file to attribute and value components.
61 * @return true if value is an URL, false otherwise
62 */
63 [[nodiscard]] static bool splitLine(const QByteArray &line, QString &fieldname, QByteArray &value);
64
65 /**
66 * Splits a control specification (without the "control:" directive)
67 * @param line is the control directive
68 * @param oid will contain the OID
69 * @param critical will contain the criticality of control
70 * @param value is the control value
71 */
72 [[nodiscard]] static bool splitControl(const QByteArray &line, QString &oid, bool &critical, QByteArray &value);
73
74 /**
75 * Starts the parsing of a new Ldif
76 */
77 void startParsing();
78
79 /**
80 * Process one Ldif line
81 */
82 [[nodiscard]] ParseValue processLine();
83
84 /**
85 * Process the Ldif until a complete item can be returned
86 * @return NewEntry if a new DN encountered, Item if a new item returned,
87 * Err if the Ldif contains error, EndEntry if the parser reached the end
88 * of the current entry and MoreData if the parser encountered the end of
89 * the current chunk of the Ldif.
90 *
91 * If you want to finish the parsing after receiving MoreData, then call
92 * endLdif(), so the parser can safely flush the current entry.
93 */
94 [[nodiscard]] ParseValue nextItem();
95
96 /**
97 * Sets a chunk of Ldif. Call before startParsing(), or if nextItem()
98 * returned MoreData.
99 * @param ldif the Ldif chunk to set
100 */
101 void setLdif(const QByteArray &ldif);
102
103 /**
104 * Indicates the end of the Ldif file/stream. Call if nextItem() returned
105 * MoreData, but actually you don't have more data.
106 */
107 void endLdif();
108
109 /**
110 * Returns the requested LDAP operation extracted from the current entry.
111 */
112 [[nodiscard]] EntryType entryType() const;
113
114 /**
115 * Returns the LDAP modify request type if entryType() returned Entry_Mod.
116 */
117 [[nodiscard]] int modType() const;
118
119 /**
120 * Returns the Distinguished Name of the current entry.
121 */
122 [[nodiscard]] LdapDN dn() const;
123
124 /**
125 * Returns the new Relative Distinguished Name if modType() returned
126 * Entry_Modrdn.
127 */
128 [[nodiscard]] QString newRdn() const;
129
130 /**
131 * Returns the new parent of the entry if modType() returned Entry_Modrdn.
132 */
133 [[nodiscard]] QString newSuperior() const;
134
135 /**
136 * Returns if the delete of the old RDN is required.
137 */
138 [[nodiscard]] bool delOldRdn() const;
139
140 /**
141 * Returns the attribute name.
142 */
143 [[nodiscard]] QString attr() const;
144
145 /**
146 * Returns the attribute value.
147 */
148 [[nodiscard]] QByteArray value() const;
149
150 /**
151 * Returns if val() is an url
152 */
153 [[nodiscard]] bool isUrl() const;
154
155 /**
156 * Returns the criticality level when modType() returned Control.
157 */
158 [[nodiscard]] bool isCritical() const;
159
160 /**
161 * Returns the OID when modType() returned Control.
162 */
163 [[nodiscard]] QString oid() const;
164
165 /**
166 * Returns the line number which the parser processes.
167 */
168 [[nodiscard]] uint lineNumber() const;
169
170private:
171 class LdifPrivate;
172 std::unique_ptr<LdifPrivate> const d;
173};
174}
Ldif.
Definition ldif.h:29
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.