27 class 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 )
57 if (
this == &that ) {
73 uint linelen,
bool url )
80 result = fieldname.
toUtf8() +
":< " + value;
84 if ( value.
size() > 0 && value[0] > 0 && value[0] !=
'\n' &&
85 value[0] !=
'\r' && value[0] !=
':' && value[0] !=
'<' ) {
91 for (
int i=1; i < value.
size(); ++i ) {
93 if ( ( isDn && value[i] == 0 ) ||
94 ( !isDn && value[i] <= 0 ) ||
95 value[i] ==
'\r' || value[i] ==
'\n' ) {
102 if ( value.
size() == 0 ) {
107 result = fieldname.
toUtf8() +
": " + value;
113 int i = (uint)( fieldname.
length() + 2 ) > linelen ? fieldname.
length() + 2 : linelen;
114 while ( i < result.
length() ) {
115 result.
insert( i,
"\n " );
124 uint linelen,
bool url )
126 return assembleLine( fieldname, value.
toUtf8(), linelen, url );
137 position = line.
indexOf(
":" );
138 if ( position == -1 ) {
146 linelen = line.
size();
149 if ( linelen > ( position + 1 ) && line[ position + 1 ] ==
':' ) {
151 if ( linelen <= ( position + 3 ) ) {
159 if ( linelen > ( position + 1 ) && line[ position + 1 ] ==
'<' ) {
161 if ( linelen <= ( position + 3 ) ) {
169 if ( linelen <= ( position + 2 ) ) {
173 value = line.
mid( position + 2 );
182 bool url = splitLine( line, tmp, value );
203 if ( d->mIsComment ) {
207 ParseValue retval = None;
208 if ( d->mLastParseValue == EndEntry ) {
209 d->mEntryType = Entry_None;
212 d->mUrl = splitLine( d->mLine, d->mAttr, d->mValue );
216 switch ( d->mEntryType ) {
219 if ( !d->mDn.isEmpty() ) {
225 d->mModType = Mod_None;
228 if ( d->mDn.isEmpty() ) {
232 kDebug() <<
"changetype:" << tmpval;
234 d->mEntryType = Entry_Add;
236 d->mEntryType = Entry_Del;
240 d->mDelOldRdn =
true;
241 d->mEntryType = Entry_Modrdn;
243 d->mEntryType = Entry_Mod;
249 d->mUrl = splitControl( d->mValue, d->mOid, d->mCritical, d->mValue );
251 }
else if ( !d->mAttr.isEmpty() && d->mValue.size() > 0 ) {
252 d->mEntryType = Entry_Add;
257 if ( d->mAttr.isEmpty() && d->mValue.size() == 0 ) {
264 if ( d->mAttr.isEmpty() && d->mValue.size() == 0 ) {
271 if ( d->mModType == Mod_None ) {
272 kDebug() <<
"new modtype" << d->mAttr;
273 if ( d->mAttr.isEmpty() && d->mValue.size() == 0 ) {
276 d->mModType = Mod_Add;
278 d->mModType = Mod_Replace;
283 d->mModType = Mod_Del;
291 if ( d->mAttr.isEmpty() ) {
293 d->mModType = Mod_None;
294 }
else if ( d->mValue.size() == 0 ) {
305 if ( d->mAttr.isEmpty() && d->mValue.size() == 0 ) {
312 if ( d->mValue.size() > 0 && d->mValue[0] ==
'0' ) {
313 d->mDelOldRdn =
false;
314 }
else if ( d->mValue.size() > 0 && d->mValue[0] ==
'1' ) {
315 d->mDelOldRdn =
true;
329 ParseValue retval = None;
332 while ( retval == None ) {
333 if ( d->mPos < (uint)d->mLdif.size() ) {
334 c = d->mLdif[d->mPos];
336 if ( d->mIsNewLine && c ==
'\r' ) {
339 if ( d->mIsNewLine && ( c ==
' ' || c ==
'\t' ) ) {
340 d->mIsNewLine =
false;
343 if ( d->mIsNewLine ) {
344 d->mIsNewLine =
false;
345 retval = processLine();
346 d->mLastParseValue = retval;
347 d->mLine.resize( 0 );
348 d->mIsComment = ( c ==
'#' );
350 if ( c ==
'\n' || c ==
'\r' ) {
352 d->mIsNewLine =
true;
360 if ( !d->mIsComment ) {
376 d->mPos = d->mLineNumber = 0;
377 d->mDelOldRdn =
false;
378 d->mEntryType = Entry_None;
379 d->mModType = Mod_None;
382 d->mNewSuperior.clear();
384 d->mIsNewLine =
false;
385 d->mIsComment =
false;
386 d->mLastParseValue = None;
397 return d->mEntryType;
417 return d->mNewSuperior;
422 return d->mDelOldRdn;
452 return d->mLineNumber;
QByteArray value() const
Returns the attribute value.
void endLdif()
Indicates the end of the Ldif file/stream.
void truncate(int position)
QByteArray trimmed() const
uint lineNumber() const
Returns the line number which the parser processes.
bool isCritical() const
Returns the criticality level when modType() returned Control.
ParseValue nextItem()
Process the Ldif until a complete item can be returned.
static bool splitControl(const QByteArray &line, QString &oid, bool &critical, QByteArray &value)
Splits a control specification (without the "control:" directive)
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...
QByteArray & insert(int i, char ch)
QString newSuperior() const
Returns the new parent of the entry if modType() returned Entry_Modrdn.
int indexOf(char ch, int from) const
void setLdif(const QByteArray &ldif)
Sets a chunk of Ldif.
QString fromUtf8(const char *str, int size)
int modType() const
Returns the LDAP modify request type if entryType() returned Entry_Mod.
QString attr() const
Returns the attribute name.
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
ParseValue processLine()
Process one Ldif line.
QByteArray mid(int pos, int len) const
void startParsing()
Starts the parsing of a new Ldif.
bool isUrl() const
Returns if val() is an url.
QString oid() const
Returns the OID when modType() returned Control.
LdapDN dn() const
Returns the Distinguished Name of the current entry.
QString newRdn() const
Returns the new Relative Distinguished Name if modType() returned Entry_Modrdn.
QByteArray left(int len) const
EntryType entryType() const
Returns the requested LDAP operation extracted from the current entry.
QByteArray fromBase64(const QByteArray &base64)
bool delOldRdn() const
Returns if the delete of the old RDN is required.
QByteArray toBase64() const
static bool splitLine(const QByteArray &line, QString &fieldname, QByteArray &value)
Splits one line from an Ldif file to attribute and value components.
QByteArray toUtf8() const