10#include "ldap_core_debug.h"
12using namespace KLDAPCore;
14class Q_DECL_HIDDEN
Ldif::LdifPrivate
18 bool mDelOldRdn, mUrl;
20 QString mAttr, mNewRdn, mNewSuperior, mOid;
24 bool mIsNewLine, mIsComment, mCritical;
25 ParseValue mLastParseValue;
26 uint mPos, mLineNumber;
36Ldif::Ldif(
const Ldif &that)
44Ldif &Ldif::operator=(
const Ldif &that)
55Ldif::~Ldif() =
default;
65 bool isDn = fieldname.
toLower() ==
"dn"_L1;
75 if ((isDn &&
value[i] == 0) || (!isDn &&
value[i] <= 0) ||
value[i] ==
'\r' ||
value[i] ==
'\n') {
93 int i = (uint)(fieldname.
length() + 2) > linelen ? fieldname.
length() + 2 : linelen;
94 while (i < result.
length()) {
116 if (position == -1) {
124 linelen = line.
size();
127 if (linelen > (position + 1) && line[position + 1] ==
':') {
129 if (linelen <= (position + 3)) {
137 if (linelen > (position + 1) && line[position + 1] ==
'<') {
139 if (linelen <= (position + 3)) {
147 if (linelen <= (position + 2)) {
169 }
else if (tmp.
endsWith(
"false"_L1)) {
183 ParseValue retval = None;
184 if (d->mLastParseValue == EndEntry) {
185 d->mEntryType = Entry_None;
188 d->mUrl =
splitLine(d->mLine, d->mAttr, d->mValue);
190 const QString attrLower = d->mAttr.toLower();
192 switch (d->mEntryType) {
194 if (attrLower ==
"version"_L1) {
195 if (!d->mDn.isEmpty()) {
198 }
else if (attrLower ==
"dn"_L1) {
201 d->mModType = Mod_None;
203 }
else if (attrLower ==
"changetype"_L1) {
204 if (d->mDn.isEmpty()) {
208 qCDebug(LDAP_CORE_LOG) <<
"changetype:" << tmpval;
209 if (tmpval ==
"add"_L1) {
210 d->mEntryType = Entry_Add;
211 }
else if (tmpval ==
"delete"_L1) {
212 d->mEntryType = Entry_Del;
213 }
else if (tmpval ==
"modrdn"_L1 || tmpval ==
"moddn"_L1) {
215 d->mNewSuperior.clear();
216 d->mDelOldRdn =
true;
217 d->mEntryType = Entry_Modrdn;
218 }
else if (tmpval ==
"modify"_L1) {
219 d->mEntryType = Entry_Mod;
224 }
else if (attrLower ==
"control"_L1) {
225 d->mUrl =
splitControl(d->mValue, d->mOid, d->mCritical, d->mValue);
227 }
else if (!d->mAttr.isEmpty() && !d->mValue.isEmpty()) {
228 d->mEntryType = Entry_Add;
233 if (d->mAttr.isEmpty() && d->mValue.isEmpty()) {
240 if (d->mAttr.isEmpty() && d->mValue.isEmpty()) {
247 if (d->mModType == Mod_None) {
248 qCDebug(LDAP_CORE_LOG) <<
"new modtype" << d->mAttr;
249 if (d->mAttr.isEmpty() && d->mValue.isEmpty()) {
251 }
else if (attrLower ==
"add"_L1) {
252 d->mModType = Mod_Add;
253 }
else if (attrLower ==
"replace"_L1) {
254 d->mModType = Mod_Replace;
258 }
else if (attrLower ==
"delete"_L1) {
259 d->mModType = Mod_Del;
267 if (d->mAttr.isEmpty()) {
269 d->mModType = Mod_None;
270 }
else if (d->mValue.isEmpty()) {
281 if (d->mAttr.isEmpty() && d->mValue.isEmpty()) {
283 }
else if (attrLower ==
"newrdn"_L1) {
285 }
else if (attrLower ==
"newsuperior"_L1) {
287 }
else if (attrLower ==
"deleteoldrdn"_L1) {
288 if (d->mValue.size() > 0 && d->mValue[0] ==
'0') {
289 d->mDelOldRdn =
false;
290 }
else if (d->mValue.size() > 0 && d->mValue[0] ==
'1') {
291 d->mDelOldRdn =
true;
305 ParseValue retval = None;
308 while (retval == None) {
309 if (d->mPos < (uint)d->mLdif.size()) {
310 c = d->mLdif.at(d->mPos);
312 if (d->mIsNewLine && c ==
'\r') {
315 if (d->mIsNewLine && (c ==
' ' || c ==
'\t')) {
316 d->mIsNewLine =
false;
320 d->mIsNewLine =
false;
322 d->mLastParseValue = retval;
324 d->mIsComment = (c ==
'#');
326 if (c ==
'\n' || c ==
'\r') {
328 d->mIsNewLine =
true;
336 if (!d->mIsComment) {
352 d->mPos = d->mLineNumber = 0;
353 d->mDelOldRdn =
false;
354 d->mEntryType = Entry_None;
355 d->mModType = Mod_None;
358 d->mNewSuperior.clear();
360 d->mIsNewLine =
false;
361 d->mIsComment =
false;
362 d->mLastParseValue = None;
373 return d->mEntryType;
393 return d->mNewSuperior;
398 return d->mDelOldRdn;
428 return d->mLineNumber;
int modType() const
Returns the LDAP modify request type if entryType() returned Entry_Mod.
ParseValue processLine()
Process one Ldif line.
static QByteArray assembleLine(const QString &fieldname, const QByteArray &value, uint linelen=0, bool url=false)
Assembles fieldname and value into a valid Ldif line, BASE64 encodes the value if necessary and optio...
void endLdif()
Indicates the end of the Ldif file/stream.
uint lineNumber() const
Returns the line number which the parser processes.
QByteArray value() const
Returns the attribute value.
ParseValue nextItem()
Process the Ldif until a complete item can be returned.
bool delOldRdn() const
Returns if the delete of the old RDN is required.
bool isUrl() const
Returns if val() is an url.
QString oid() const
Returns the OID when modType() returned Control.
QString attr() const
Returns the attribute name.
static bool splitControl(const QByteArray &line, QString &oid, bool &critical, QByteArray &value)
Splits a control specification (without the "control:" directive)
void startParsing()
Starts the parsing of a new Ldif.
void setLdif(const QByteArray &ldif)
Sets a chunk of Ldif.
LdapDN dn() const
Returns the Distinguished Name of the current entry.
bool isCritical() const
Returns the criticality level when modType() returned Control.
static bool splitLine(const QByteArray &line, QString &fieldname, QByteArray &value)
Splits one line from an Ldif file to attribute and value components.
QString newRdn() const
Returns the new Relative Distinguished Name if modType() returned Entry_Modrdn.
EntryType entryType() const
Returns the requested LDAP operation extracted from the current entry.
QString newSuperior() const
Returns the new parent of the entry if modType() returned Entry_Modrdn.
QByteArray fromBase64(const QByteArray &base64, Base64Options options)
qsizetype indexOf(QByteArrayView bv, qsizetype from) const const
QByteArray & insert(qsizetype i, QByteArrayView data)
bool isEmpty() const const
QByteArray left(qsizetype len) const const
qsizetype length() const const
QByteArray mid(qsizetype pos, qsizetype len) const const
void resize(qsizetype newSize, char c)
qsizetype size() const const
QByteArray toBase64(Base64Options options) const const
QByteArray trimmed() const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const
qsizetype length() const const
QString toLower() const const
QByteArray toUtf8() const const