25#include <QtCore/QStringList>
29class LdapUrl::LdapUrlPrivate
37 QMap<QString, Extension> m_extensions;
38 QStringList m_attributes;
44 : d( new LdapUrlPrivate )
49 : KUrl( _url ), d( new LdapUrlPrivate )
52 if ( tmp.startsWith( QLatin1Char(
'/') ) ) {
60 : KUrl( that ), d( new LdapUrlPrivate )
67 if (
this == &that ) {
71 KUrl::operator=( that );
84 QString tmp =
dn.toString();
85 if ( tmp.startsWith( QLatin1Char(
'/') ) ) {
94 if ( tmp.startsWith( QLatin1Char(
'/') ) ) {
103 return d->m_attributes;
136 return d->m_extensions.contains( key );
141 QMap<QString, Extension>::const_iterator it;
143 it = d->m_extensions.constFind( key );
144 if ( it != d->m_extensions.constEnd() ) {
148 ext.value = QLatin1String(
"");
149 ext.critical =
false;
159 critical = ext.critical;
165 d->m_extensions[ key ] = ext;
173 ext.critical = critical;
180 ext.value = QString::number( value );
181 ext.critical = critical;
187 d->m_extensions.remove( key );
193 QMap<QString, Extension>::const_iterator it;
194 QString q( QLatin1Char(
'?') );
197 if ( !d->m_attributes.isEmpty() ) {
198 q += d->m_attributes.join( QLatin1String(
",") );
202 q += QLatin1Char(
'?');
203 switch ( d->m_scope ) {
205 q += QLatin1String(
"sub");
208 q += QLatin1String(
"one");
211 q += QLatin1String(
"base");
216 q += QLatin1Char(
'?');
217 if ( d->m_filter != QLatin1String(
"(objectClass=*)") && !d->m_filter.isEmpty() ) {
218 q += QLatin1String(toPercentEncoding( d->m_filter ));
222 q += QLatin1Char(
'?');
223 for ( it = d->m_extensions.constBegin(); it != d->m_extensions.constEnd(); ++it ) {
224 if ( it.value().critical ) {
225 q += QLatin1Char(
'!');
228 if ( !it.value().value.isEmpty() ) {
229 q += QLatin1Char(
'=') + QLatin1String(toPercentEncoding( it.value().value ));
231 q += QLatin1Char(
',');
233 while ( q.endsWith( QLatin1Char(
'?') ) || q.endsWith( QLatin1Char(
',') ) ) {
234 q.remove( q.length() - 1, 1 );
238 kDebug() <<
"LDAP URL updateQuery():" << prettyUrl();
244 QStringList extensions;
247 if ( q.startsWith( QLatin1Char(
'?') ) ) {
252 QStringList url_items = q.split( QLatin1Char(
'?') );
254 d->m_attributes.clear();
256 d->m_filter = QLatin1String(
"(objectClass=*)");
257 d->m_extensions.clear();
260 QStringList::const_iterator end( url_items.constEnd() );
261 for ( QStringList::const_iterator it=url_items.constBegin();
262 it != end; ++it, i++ ) {
265 d->m_attributes = ( *it ).split( QLatin1Char(
','), QString::SkipEmptyParts );
268 if ( ( *it ) == QLatin1String(
"sub" ) ) {
270 }
else if ( ( *it ) == QLatin1String(
"one" ) ) {
275 d->m_filter = fromPercentEncoding( ( *it ).toLatin1() );
278 extensions = ( *it ).split( QLatin1Char(
','), QString::SkipEmptyParts );
284 QStringList::const_iterator end2( extensions.constEnd() );
285 for ( QStringList::const_iterator it=extensions.constBegin();
287 ext.critical =
false;
288 name = fromPercentEncoding( ( *it ).section( QLatin1Char(
'='), 0, 0 ).toLatin1() ).toLower();
289 value = fromPercentEncoding( ( *it ).section( QLatin1Char(
'='), 1 ).toLatin1() );
290 if ( name.startsWith( QLatin1Char(
'!') ) ) {
294 kDebug() <<
"LdapUrl extensions name=" << name <<
"value:" << value;
295 ext.value = value.replace( QLatin1String(
"%2"), QLatin1String(
",") );
A special url class for LDAP.
void setExtension(const QString &key, const Extension &extension)
Sets the specified extension key with the value and criticality in extension.
void setFilter(const QString &filter)
Sets the filter part of the LDAP url.
void setScope(Scope scope)
Sets the scope part of the LDAP url.
LdapUrl & operator=(const LdapUrl &other)
Overwrites the values of the LDAP url with values from an other url.
Scope
Describes the scope of the LDAP url.
@ One
The level of the url and the one below.
@ Sub
All levels below the url's level.
@ Base
Only the same level as the url.
Scope scope() const
Returns the scope part of the LDAP url.
virtual ~LdapUrl()
Destroys the LDAP url.
LdapDN dn() const
Returns the dn part of the LDAP url.
void setAttributes(const QStringList &attributes)
Sets the attributes part of the LDAP url.
QStringList attributes() const
Returns the attributes part of the LDAP url.
QString filter() const
Returns the filter part of the LDAP url.
void setDn(const LdapDN &dn)
Sets the dn part of the LDAP url.
LdapUrl()
Constructs an empty LDAP url.
void updateQuery()
Updates the query component from the attributes, scope, filter and extensions.
bool hasExtension(const QString &extension) const
Returns whether the specified extension exists in the LDAP url.
Extension extension(const QString &extension) const
Returns the specified extension.
void removeExtension(const QString &extension)
Removes the specified extension.
void parseQuery()
Parses the query argument of the URL and makes it available via the attributes(), extension(),...
A class holding the extension name and state whether the extension is critical.