38 uint linelen,
bool url )
46 result = fieldname.utf8() +
":< " + TQCString( value.data(), value.size()+1 );
48 isDn = fieldname.lower() ==
"dn";
50 if ( value.size() > 0 && value[0] > 0 && value[0] !=
'\n' &&
51 value[0] !=
'\r' && value[0] !=
':' && value[0] !=
'<' ) safe =
true;
55 for ( i=1; i < value.size(); i++ ) {
57 if ( ( isDn && value[i] == 0 ) ||
58 ( !isDn && value[i] <= 0 ) ||
59 value[i] ==
'\r' || value[i] ==
'\n' ) {
66 if ( value.size() == 0 ) safe =
true;
69 result = fieldname.utf8() +
": " + TQCString( value.data(), value.size()+1 );
75 i = (fieldname.length()+2) > linelen ? fieldname.length()+2 : linelen;
76 while ( i < result.length() ) {
77 result.insert( i,
"\n " );
86 uint linelen,
bool url )
90 uint valuelen = value.length();
91 const char *data = value.data();
93 tmp.setRawData( data, valuelen );
95 tmp.resetRawData( data, valuelen );
101 uint linelen,
bool url )
103 return assembleLine( fieldname, value.utf8(), linelen, url );
106 bool LDIF::splitLine(
const TQCString &line, TQString &fieldname, TQByteArray &value )
115 position = line.find(
":" );
116 if ( position == -1 ) {
120 str = line.stripWhiteSpace();
121 linelen = str.length();
123 tmp.setRawData( data, linelen );
125 tmp.resetRawData( data, linelen );
130 linelen = line.length();
132 if ( linelen > ( position + 1 ) && line[ position + 1 ] ==
':' ) {
134 fieldname = TQString::fromUtf8(
135 line.left( position ).stripWhiteSpace() );
136 if ( linelen <= ( position + 3 ) ) {
140 data = &line.data()[ position + 3 ];
141 tmp.setRawData( data, linelen - position - 3 );
143 tmp.resetRawData( data, linelen - position - 3 );
147 if ( linelen > ( position + 1 ) && line[ position + 1 ] ==
'<' ) {
149 fieldname = TQString::fromUtf8(
150 line.left( position ).stripWhiteSpace() );
151 if ( linelen <= ( position + 3 ) ) {
155 data = &line.data()[ position + 3];
156 tmp.setRawData( data, linelen - position - 3 );
158 tmp.resetRawData( data, linelen - position - 3 );
162 fieldname = TQString::fromUtf8(line.left( position ).stripWhiteSpace());
163 if ( linelen <= ( position + 2 ) ) {
167 data = &line.data()[ position + 2 ];
168 tmp.setRawData( data, linelen - position - 2 );
170 tmp.resetRawData( data, linelen - position - 2 );
179 bool url =
splitLine( line, tmp, value );
181 kdDebug(5700) <<
"splitControl: value: " << TQString(TQString::fromUtf8(value, value.size())) <<
endl;
182 if ( tmp.isEmpty() ) {
183 tmp = TQString::fromUtf8( value, value.size() );
186 if ( tmp.right( 4 ) ==
"true" ) {
188 tmp.truncate( tmp.length() - 5 );
189 }
else if ( tmp.right( 5 ) ==
"false" ) {
191 tmp.truncate( tmp.length() - 6 );
200 if ( mIsComment )
return None;
202 ParseVal retval = None;
203 if ( mLastParseVal == EndEntry ) mEntryType = Entry_None;
207 TQString attrLower = mAttr.lower();
209 switch ( mEntryType ) {
211 if ( attrLower ==
"version" ) {
212 if ( !mDn.isEmpty() ) retval = Err;
213 }
else if ( attrLower ==
"dn" ) {
214 kdDebug(5700) <<
"ldapentry dn: " << TQString(TQString::fromUtf8( mVal, mVal.size() )) <<
endl;
215 mDn = TQString::fromUtf8( mVal, mVal.size() );
218 }
else if ( attrLower ==
"changetype" ) {
222 TQString tmpval = TQString::fromUtf8( mVal, mVal.size() );
224 if ( tmpval ==
"add" ) mEntryType = Entry_Add;
225 else if ( tmpval ==
"delete" ) mEntryType = Entry_Del;
226 else if ( tmpval ==
"modrdn" || tmpval ==
"moddn" ) {
230 mEntryType = Entry_Modrdn;
232 else if ( tmpval ==
"modify" ) mEntryType = Entry_Mod;
235 }
else if ( attrLower ==
"control" ) {
236 mUrl =
splitControl( TQCString( mVal, mVal.size() + 1 ), mOid, mCritical, mVal );
238 }
else if ( !mAttr.isEmpty() && mVal.size() > 0 ) {
239 mEntryType = Entry_Add;
244 if ( mAttr.isEmpty() && mVal.size() == 0 )
250 if ( mAttr.isEmpty() && mVal.size() == 0 )
256 if ( mModType == Mod_None ) {
257 kdDebug(5700) <<
"tdeio_ldap: new modtype " << mAttr <<
endl;
258 if ( mAttr.isEmpty() && mVal.size() == 0 ) {
260 }
else if ( attrLower ==
"add" ) {
262 }
else if ( attrLower ==
"replace" ) {
263 mModType = Mod_Replace;
264 mAttr = TQString::fromUtf8( mVal, mVal.size() );
267 }
else if ( attrLower ==
"delete" ) {
269 mAttr = TQString::fromUtf8( mVal, mVal.size() );
276 if ( mAttr.isEmpty() ) {
277 if ( TQString::fromUtf8( mVal, mVal.size() ) ==
"-" ) {
279 }
else if ( mVal.size() == 0 ) {
288 if ( mAttr.isEmpty() && mVal.size() == 0 )
290 else if ( attrLower ==
"newrdn" )
291 mNewRdn = TQString::fromUtf8( mVal, mVal.size() );
292 else if ( attrLower ==
"newsuperior" )
293 mNewSuperior = TQString::fromUtf8( mVal, mVal.size() );
294 else if ( attrLower ==
"deleteoldrdn" ) {
295 if ( mVal.size() > 0 && mVal[0] ==
'0' )
297 else if ( mVal.size() > 0 && mVal[0] ==
'1' )
310 ParseVal retval = None;
313 while( retval == None ) {
314 if ( mPos < mLdif.size() ) {
317 if ( mIsNewLine && c ==
'\r' )
continue;
318 if ( mIsNewLine && ( c ==
' ' || c ==
'\t' ) ) {
325 mLastParseVal = retval;
327 mIsComment = ( c ==
'#' );
329 if ( c ==
'\n' || c ==
'\r' ) {
339 if ( !mIsComment ) line += c;
346 TQByteArray tmp( 3 );
358 mEntryType = Entry_None;
360 mDn = mNewRdn = mNewSuperior =
"";
364 mLastParseVal = None;
static TQCString base64Decode(const TQByteArray &in)
static TQCString base64Encode(const TQByteArray &in, bool insertLFs=false)
bool critical() const
Returns the criticality level when modType() returned Control.
static bool splitLine(const TQCString &line, TQString &fieldname, TQByteArray &value)
Splits one line from an LDIF file to attribute and value components.
static TQCString assembleLine(const TQString &fieldname, const TQByteArray &value, uint linelen=0, bool url=false)
Assembles fieldname and value into a valid LDIF line, BASE64 encodes the value if neccessary and opti...
void startParsing()
Starts the parsing of a new LDIF.
ParseVal processLine()
Process one LDIF line.
void endLDIF()
Indicates the end of the LDIF file/stream.
ParseVal nextItem()
Process the LDIF until a complete item can be returned.
const TQString & oid() const
Returns the OID when modType() returned Control.
static bool splitControl(const TQCString &line, TQString &oid, bool &critical, TQByteArray &value)
Splits a control specification (without the "control:" directive)
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
static data, shared by ALL addressee objects