25 using namespace KLDAP;
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 )
84 if ( value.
size() > 0 && value[0] > 0 && value[0] !=
'\n' &&
85 value[0] !=
'\r' && value[0] !=
':' && value[0] !=
'<' ) safe =
true;
89 for (
int i=1; i < value.
size(); i++ ) {
91 if ( ( isDn && value[i] == 0 ) ||
92 ( !isDn && value[i] <= 0 ) ||
93 value[i] ==
'\r' || value[i] ==
'\n' ) {
100 if ( value.
size() == 0 ) {
111 int i = (uint)( fieldname.
length() + 2 ) > linelen ? fieldname.
length() + 2 : linelen;
112 while ( i < result.
length() ) {
113 result.
insert( i,
"\n " );
122 uint linelen,
bool url )
135 position = line.
indexOf(
":" );
136 if ( position == -1 ) {
144 linelen = line.
size();
147 if ( linelen > ( position + 1 ) && line[ position + 1 ] ==
':' ) {
149 if ( linelen <= ( position + 3 ) ) {
157 if ( linelen > ( position + 1 ) && line[ position + 1 ] ==
'<' ) {
159 if ( linelen <= ( position + 3 ) ) {
167 if ( linelen <= ( position + 2 ) ) {
171 value = line.
mid( position + 2 );
180 bool url =
splitLine( line, tmp, value );
201 if ( d->mIsComment ) {
205 ParseValue retval = None;
206 if ( d->mLastParseValue == EndEntry ) {
207 d->mEntryType = Entry_None;
210 d->mUrl =
splitLine( d->mLine, d->mAttr, d->mValue );
212 QString attrLower = d->mAttr.toLower();
214 switch ( d->mEntryType ) {
217 if ( !d->mDn.isEmpty() ) {
223 d->mModType = Mod_None;
226 if ( d->mDn.isEmpty() ) {
230 kDebug() <<
"changetype:" << tmpval;
232 d->mEntryType = Entry_Add;
234 d->mEntryType = Entry_Del;
237 d->mNewSuperior.clear();
238 d->mDelOldRdn =
true;
239 d->mEntryType = Entry_Modrdn;
241 d->mEntryType = Entry_Mod;
247 d->mUrl =
splitControl( d->mValue, d->mOid, d->mCritical, d->mValue );
249 }
else if ( !d->mAttr.isEmpty() && d->mValue.size() > 0 ) {
250 d->mEntryType = Entry_Add;
255 if ( d->mAttr.isEmpty() && d->mValue.size() == 0 ) {
262 if ( d->mAttr.isEmpty() && d->mValue.size() == 0 ) {
269 if ( d->mModType == Mod_None ) {
270 kDebug() <<
"new modtype" << d->mAttr;
271 if ( d->mAttr.isEmpty() && d->mValue.size() == 0 ) {
274 d->mModType = Mod_Add;
276 d->mModType = Mod_Replace;
281 d->mModType = Mod_Del;
289 if ( d->mAttr.isEmpty() ) {
291 d->mModType = Mod_None;
292 }
else if ( d->mValue.size() == 0 ) {
303 if ( d->mAttr.isEmpty() && d->mValue.size() == 0 ) {
310 if ( d->mValue.size() > 0 && d->mValue[0] ==
'0' ) {
311 d->mDelOldRdn =
false;
312 }
else if ( d->mValue.size() > 0 && d->mValue[0] ==
'1' ) {
313 d->mDelOldRdn =
true;
327 ParseValue retval = None;
330 while ( retval == None ) {
331 if ( d->mPos < (uint)d->mLdif.size() ) {
332 c = d->mLdif[d->mPos];
334 if ( d->mIsNewLine && c ==
'\r' ) {
337 if ( d->mIsNewLine && ( c ==
' ' || c ==
'\t' ) ) {
338 d->mIsNewLine =
false;
341 if ( d->mIsNewLine ) {
342 d->mIsNewLine =
false;
344 d->mLastParseValue = retval;
345 d->mLine.resize( 0 );
346 d->mIsComment = ( c ==
'#' );
348 if ( c ==
'\n' || c ==
'\r' ) {
350 d->mIsNewLine =
true;
358 if ( !d->mIsComment ) {
374 d->mPos = d->mLineNumber = 0;
375 d->mDelOldRdn =
false;
376 d->mEntryType = Entry_None;
377 d->mModType = Mod_None;
380 d->mNewSuperior.clear();
382 d->mIsNewLine =
false;
383 d->mIsComment =
false;
384 d->mLastParseValue = None;
395 return d->mEntryType;
415 return d->mNewSuperior;
420 return d->mDelOldRdn;
450 return d->mLineNumber;
void truncate(int position)
QString oid() const
Returns the OID when modType() returned Control.
QByteArray trimmed() const
uint lineNumber() const
Returns the line number which the parser processes.
QString newRdn() const
Returns the new Relative Distinguished Name if modType() returned Entry_Modrdn.
bool isUrl() const
Returns if val() is an url.
QByteArray & insert(int i, char ch)
void endLdif()
Indicates the end of the Ldif file/stream.
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...
int indexOf(char ch, int from) const
QString fromUtf8(const char *str, int size)
QByteArray value() const
Returns the attribute value.
void startParsing()
Starts the parsing of a new Ldif.
int modType() const
Returns the LDAP modify request type if entryType() returned Entry_Mod.
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QString attr() const
Returns the attribute name.
static bool splitLine(const QByteArray &line, QString &fieldname, QByteArray &value)
Splits one line from an Ldif file to attribute and value components.
QByteArray mid(int pos, int len) const
LdapDN dn() const
Returns the Distinguished Name of the current entry.
void setLdif(const QByteArray &ldif)
Sets a chunk of Ldif.
bool delOldRdn() const
Returns if the delete of the old RDN is required.
QByteArray left(int len) const
ParseValue nextItem()
Process the Ldif until a complete item can be returned.
QByteArray fromBase64(const QByteArray &base64)
QString newSuperior() const
Returns the new parent of the entry if modType() returned Entry_Modrdn.
EntryType entryType() const
Returns the requested LDAP operation extracted from the current entry.
QByteArray toBase64() const
static bool splitControl(const QByteArray &line, QString &oid, bool &critical, QByteArray &value)
Splits a control specification (without the "control:" directive)
bool isCritical() const
Returns the criticality level when modType() returned Control.
QByteArray toUtf8() const