1/*
2 A temporary copy to break dependency to KLDAP
3
4 This file is part of libkldap.
5 SPDX-FileCopyrightText: 2004-2006 Szombathelyi György <gyurco@freemail.hu>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#ifndef LDIF_P_H
11#define LDIF_P_H
12
13#include <QByteArray>
14#include <QString>
15
16/**
17 * Ldif
18 *
19 * Ldif implements an RFC 2849 compliant Ldif parser. Ldif files are used to
20 * represent directory information on LDAP-based servers, or to describe a set
21 * of changes which are to be applied to a directory.
22 */
23class Ldif
24{
25public:
26 typedef enum { None, NewEntry, EndEntry, Item, Control, Err, MoreData } ParseValue;
27
28 typedef enum { Entry_None, Entry_Add, Entry_Del, Entry_Mod, Entry_Modrdn } EntryType;
29
30 typedef enum { Mod_None, Mod_Add, Mod_Replace, Mod_Del } ModType;
31
32 Ldif();
33
34 Ldif(const Ldif &that);
35 Ldif &operator=(const Ldif &that);
36
37 virtual ~Ldif();
38
39 /**
40 * Assembles fieldname and value into a valid Ldif line, BASE64 encodes the
41 * value if necessary and optionally splits into more lines.
42 * @param fieldname The name of the entry.
43 * @param value The value of the entry.
44 * @param linelen Maximum length of the lines in the result.
45 * @param url If true, encode value as url ( use :< ).
46 */
47 static QByteArray assembleLine(const QString &fieldname, const QByteArray &value, uint linelen = 0, bool url = false);
48 /**
49 * This is the same as the above function, the only difference that
50 * this accepts QString as the value.
51 */
52 static QByteArray assembleLine(const QString &fieldname, const QString &value, uint linelen = 0, bool url = false);
53
54 /**
55 * Splits one line from an Ldif file to attribute and value components.
56 * @return true if value is an URL, false otherwise
57 */
58 static bool splitLine(const QByteArray &line, QString &fieldname, QByteArray &value);
59
60 /**
61 * Splits a control specification (without the "control:" directive)
62 * @param line is the control directive
63 * @param oid will contain the OID
64 * @param critical will contain the criticality of control
65 * @param value is the control value
66 */
67 static bool splitControl(const QByteArray &line, QString &oid, bool &critical, QByteArray &value);
68
69 /**
70 * Starts the parsing of a new Ldif
71 */
72 void startParsing();
73
74 /**
75 * Process one Ldif line
76 */
77 ParseValue processLine();
78
79 /**
80 * Process the Ldif until a complete item can be returned
81 * @return NewEntry if a new DN encountered, Item if a new item returned,
82 * Err if the Ldif contains error, EndEntry if the parser reached the end
83 * of the current entry and MoreData if the parser encountered the end of
84 * the current chunk of the Ldif.
85 *
86 * If you want to finish the parsing after receiving MoreData, then call
87 * endLdif(), so the parser can safely flush the current entry.
88 */
89 ParseValue nextItem();
90
91 /**
92 * Sets a chunk of Ldif. Call before startParsing(), or if nextItem()
93 * returned MoreData.
94 */
95 void setLdif(const QByteArray &ldif);
96
97 /**
98 * Indicates the end of the Ldif file/stream. Call if nextItem() returned
99 * MoreData, but actually you don't have more data.
100 */
101 void endLdif();
102
103 /**
104 * Returns the requested LDAP operation extracted from the current entry.
105 */
106 EntryType entryType() const;
107
108 /**
109 * Returns the LDAP modify request type if entryType() returned Entry_Mod.
110 */
111 int modType() const;
112
113 /**
114 * Returns the new Relative Distinguished Name if modType() returned
115 * Entry_Modrdn.
116 */
117 QString newRdn() const;
118
119 /**
120 * Returns the new parent of the entry if modType() returned Entry_Modrdn.
121 */
122 QString newSuperior() const;
123
124 /**
125 * Returns if the delete of the old RDN is required.
126 */
127 bool delOldRdn() const;
128
129 /**
130 * Returns the attribute name.
131 */
132 QString attr() const;
133
134 /**
135 * Returns the attribute value.
136 */
137 QByteArray value() const;
138
139 /**
140 * Returns if val() is an url
141 */
142 bool isUrl() const;
143
144 /**
145 * Returns the criticality level when modType() returned Control.
146 */
147 bool isCritical() const;
148
149 /**
150 * Returns the OID when modType() returned Control.
151 */
152 QString oid() const;
153
154 /**
155 * Returns the line number which the parser processes.
156 */
157 uint lineNumber() const;
158
159private:
160 class LdifPrivate;
161 LdifPrivate *const d;
162};
163
164#endif
165

source code of kcontacts/src/ldif_p.h