25 #include "kcontacts_debug.h" 27 class Q_DECL_HIDDEN
Ldif::LdifPrivate
31 bool mDelOldRdn, mUrl;
33 QString mAttr, mNewRdn, mNewSuperior, mOid;
37 bool mIsNewLine, mIsComment, mCritical;
38 ParseValue mLastParseValue;
39 uint mPos, mLineNumber;
43 Ldif::Ldif() : d(new LdifPrivate)
48 Ldif::Ldif(
const Ldif &that) : d(new LdifPrivate)
55 Ldif &Ldif::operator=(
const Ldif &that)
76 result = fieldname.
toUtf8() +
":< " + value;
81 if (value.
size() > 0 && value[0] > 0 && value[0] !=
'\n' 82 && value[0] !=
'\r' && value[0] !=
':' && value[0] !=
'<') {
88 for (
int i = 1; i < value.
size(); ++i) {
90 if ((isDn && value[i] == 0)
91 || (!isDn && value[i] <= 0)
92 || value[i] ==
'\r' || value[i] ==
'\n') {
104 result = fieldname.
toUtf8() +
": " + value;
110 int i = (uint)(fieldname.
length() + 2) > linelen ? fieldname.
length() + 2 : linelen;
111 while (i < result.
length()) {
122 return assembleLine(fieldname, value.
toUtf8(), linelen, url);
133 if (position == -1) {
141 linelen = line.
size();
144 if (linelen > (position + 1) && line[ position + 1 ] ==
':') {
146 if (linelen <= (position + 3)) {
154 if (linelen > (position + 1) && line[ position + 1 ] ==
'<') {
156 if (linelen <= (position + 3)) {
164 if (linelen <= (position + 2)) {
168 value = line.
mid(position + 2);
176 bool url = splitLine(line, tmp, value);
194 Ldif::ParseValue Ldif::processLine()
200 ParseValue retval =
None;
201 if (d->mLastParseValue == EndEntry) {
202 d->mEntryType = Entry_None;
205 d->mUrl = splitLine(d->mLine, d->mAttr, d->mValue);
207 QString attrLower = d->mAttr.toLower();
209 switch (d->mEntryType) {
212 if (!d->mDn.isEmpty()) {
218 d->mModType = Mod_None;
221 if (d->mDn.isEmpty()) {
225 qCDebug(KCONTACTS_LOG) <<
"changetype:" << tmpval;
227 d->mEntryType = Entry_Add;
229 d->mEntryType = Entry_Del;
233 d->mDelOldRdn =
true;
234 d->mEntryType = Entry_Modrdn;
236 d->mEntryType = Entry_Mod;
242 d->mUrl = splitControl(d->mValue, d->mOid, d->mCritical, d->mValue);
244 }
else if (!d->mAttr.isEmpty() && !d->mValue.isEmpty()) {
245 d->mEntryType = Entry_Add;
250 if (d->mAttr.isEmpty() && d->mValue.isEmpty()) {
257 if (d->mAttr.isEmpty() && d->mValue.isEmpty()) {
264 if (d->mModType == Mod_None) {
265 qCDebug(KCONTACTS_LOG) <<
"new modtype" << d->mAttr;
266 if (d->mAttr.isEmpty() && d->mValue.isEmpty()) {
269 d->mModType = Mod_Add;
271 d->mModType = Mod_Replace;
276 d->mModType = Mod_Del;
284 if (d->mAttr.isEmpty()) {
286 d->mModType = Mod_None;
287 }
else if (d->mValue.isEmpty()) {
298 if (d->mAttr.isEmpty() && d->mValue.isEmpty()) {
305 if (d->mValue.size() > 0 && d->mValue[0] ==
'0') {
306 d->mDelOldRdn =
false;
307 }
else if (d->mValue.size() > 0 && d->mValue[0] ==
'1') {
308 d->mDelOldRdn =
true;
320 Ldif::ParseValue Ldif::nextItem()
322 ParseValue retval =
None;
325 while (retval == None) {
326 if (d->mPos < (uint)d->mLdif.size()) {
327 c = d->mLdif[d->mPos];
329 if (d->mIsNewLine && c ==
'\r') {
332 if (d->mIsNewLine && (c ==
' ' || c ==
'\t')) {
333 d->mIsNewLine =
false;
337 d->mIsNewLine =
false;
338 retval = processLine();
339 d->mLastParseValue = retval;
341 d->mIsComment = (c ==
'#');
343 if (c ==
'\n' || c ==
'\r') {
345 d->mIsNewLine =
true;
353 if (!d->mIsComment) {
367 void Ldif::startParsing()
369 d->mPos = d->mLineNumber = 0;
370 d->mDelOldRdn =
false;
371 d->mEntryType = Entry_None;
372 d->mModType = Mod_None;
374 d->mNewSuperior.clear();
376 d->mIsNewLine =
false;
377 d->mIsComment =
false;
378 d->mLastParseValue =
None;
387 Ldif::EntryType Ldif::entryType()
const 389 return d->mEntryType;
392 int Ldif::modType()
const 402 QString Ldif::newSuperior()
const 404 return d->mNewSuperior;
407 bool Ldif::delOldRdn()
const 409 return d->mDelOldRdn;
422 bool Ldif::isUrl()
const 427 bool Ldif::isCritical()
const 437 uint Ldif::lineNumber()
const 439 return d->mLineNumber;
QByteArray trimmed() const
QByteArray fromBase64(const QByteArray &base64, QFlags< QByteArray::Base64Option > options)
QByteArray & insert(int i, char ch)
int indexOf(char ch, int from) const
QString fromUtf8(const char *str, int size)
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QByteArray mid(int pos, int len) const
QByteArray left(int len) const
QByteArray toBase64(QFlags< QByteArray::Base64Option > options) const
QByteArray toUtf8() const