12#include "kcontacts_debug.h"
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)
65 result = fieldname.
toUtf8() +
":< " + value;
70 if (value.
size() > 0 && value[0] > 0 && value[0] !=
'\n'
71 && value[0] !=
'\r' && value[0] !=
':' && value[0] !=
'<') {
77 for (
int i = 1; i < value.
size(); ++i) {
79 if ((isDn && value[i] == 0)
80 || (!isDn && value[i] <= 0)
81 || value[i] ==
'\r' || value[i] ==
'\n') {
93 result = fieldname.
toUtf8() +
": " + value;
99 int i = (uint)(fieldname.
length() + 2) > linelen ? fieldname.
length() + 2 : linelen;
100 while (i < result.
length()) {
111 return assembleLine(fieldname, value.
toUtf8(), linelen, url);
122 if (position == -1) {
130 linelen = line.
size();
133 if (linelen > (position + 1) && line[position + 1] ==
':') {
135 if (linelen <= (position + 3)) {
143 if (linelen > (position + 1) && line[position + 1] ==
'<') {
145 if (linelen <= (position + 3)) {
153 if (linelen <= (position + 2)) {
157 value = line.
mid(position + 2);
165 bool url = splitLine(line, tmp, value);
183Ldif::ParseValue Ldif::processLine()
189 ParseValue retval =
None;
190 if (d->mLastParseValue == EndEntry) {
191 d->mEntryType = Entry_None;
194 d->mUrl = splitLine(d->mLine, d->mAttr, d->mValue);
198 switch (d->mEntryType) {
201 if (!d->mDn.isEmpty()) {
207 d->mModType = Mod_None;
210 if (d->mDn.isEmpty()) {
214 qCDebug(KCONTACTS_LOG) <<
"changetype:" << tmpval;
216 d->mEntryType = Entry_Add;
218 d->mEntryType = Entry_Del;
222 d->mDelOldRdn =
true;
223 d->mEntryType = Entry_Modrdn;
225 d->mEntryType = Entry_Mod;
231 d->mUrl = splitControl(d->mValue, d->mOid, d->mCritical, d->mValue);
233 }
else if (!d->mAttr.isEmpty() && !d->mValue.isEmpty()) {
234 d->mEntryType = Entry_Add;
239 if (d->mAttr.isEmpty() && d->mValue.isEmpty()) {
246 if (d->mAttr.isEmpty() && d->mValue.isEmpty()) {
253 if (d->mModType == Mod_None) {
254 qCDebug(KCONTACTS_LOG) <<
"new modtype" << d->mAttr;
255 if (d->mAttr.isEmpty() && d->mValue.isEmpty()) {
258 d->mModType = Mod_Add;
260 d->mModType = Mod_Replace;
265 d->mModType = Mod_Del;
273 if (d->mAttr.isEmpty()) {
275 d->mModType = Mod_None;
276 }
else if (d->mValue.isEmpty()) {
287 if (d->mAttr.isEmpty() && d->mValue.isEmpty()) {
294 if (d->mValue.size() > 0 && d->mValue[0] ==
'0') {
295 d->mDelOldRdn =
false;
296 }
else if (d->mValue.size() > 0 && d->mValue[0] ==
'1') {
297 d->mDelOldRdn =
true;
309Ldif::ParseValue Ldif::nextItem()
311 ParseValue retval =
None;
314 while (retval == None) {
315 if (d->mPos < (uint)d->mLdif.size()) {
316 c = d->mLdif[d->mPos];
318 if (d->mIsNewLine && c ==
'\r') {
321 if (d->mIsNewLine && (c ==
' ' || c ==
'\t')) {
322 d->mIsNewLine =
false;
326 d->mIsNewLine =
false;
327 retval = processLine();
328 d->mLastParseValue = retval;
330 d->mIsComment = (c ==
'#');
332 if (c ==
'\n' || c ==
'\r') {
334 d->mIsNewLine =
true;
342 if (!d->mIsComment) {
356void Ldif::startParsing()
358 d->mPos = d->mLineNumber = 0;
359 d->mDelOldRdn =
false;
360 d->mEntryType = Entry_None;
361 d->mModType = Mod_None;
363 d->mNewSuperior.clear();
365 d->mIsNewLine =
false;
366 d->mIsComment =
false;
367 d->mLastParseValue =
None;
376Ldif::EntryType Ldif::entryType()
const
378 return d->mEntryType;
381int Ldif::modType()
const
391QString Ldif::newSuperior()
const
393 return d->mNewSuperior;
396bool Ldif::delOldRdn()
const
398 return d->mDelOldRdn;
411bool Ldif::isUrl()
const
416bool Ldif::isCritical()
const
426uint Ldif::lineNumber()
const
428 return d->mLineNumber;
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