You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
202 lines
4.7 KiB
202 lines
4.7 KiB
15 years ago
|
/*
|
||
|
This file is part of libkabc.
|
||
|
Copyright (c) 2004 Szombathelyi György <gyurco@freemail.hu>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <kdebug.h>
|
||
15 years ago
|
#include <tqstringlist.h>
|
||
|
#include <tqdir.h>
|
||
15 years ago
|
|
||
|
#include "ldapurl.h"
|
||
|
|
||
|
using namespace KABC;
|
||
|
|
||
|
LDAPUrl::LDAPUrl()
|
||
|
{
|
||
|
m_scope = Base;
|
||
|
}
|
||
|
|
||
|
LDAPUrl::LDAPUrl(const KURL &_url)
|
||
|
: KURL(_url), m_extensions()
|
||
|
{
|
||
|
m_dn = path();
|
||
15 years ago
|
if ( !TQDir::isRelativePath(m_dn) )
|
||
15 years ago
|
#ifdef Q_WS_WIN
|
||
|
m_dn.remove(0,3); // e.g. "c:/"
|
||
|
#else
|
||
|
m_dn.remove(0,1);
|
||
|
#endif
|
||
|
parseQuery();
|
||
|
}
|
||
|
|
||
15 years ago
|
void LDAPUrl::setDn( const TQString &dn)
|
||
15 years ago
|
{
|
||
|
m_dn = dn;
|
||
15 years ago
|
if ( !TQDir::isRelativePath(m_dn) )
|
||
15 years ago
|
#ifdef Q_WS_WIN
|
||
|
m_dn.remove(0,3); // e.g. "c:/"
|
||
|
#else
|
||
|
m_dn.remove(0,1);
|
||
|
#endif
|
||
|
setPath(m_dn);
|
||
|
}
|
||
|
|
||
15 years ago
|
bool LDAPUrl::hasExtension( const TQString &key ) const
|
||
15 years ago
|
{
|
||
13 years ago
|
return m_extensions.contains( key );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
LDAPUrl::Extension LDAPUrl::extension( const TQString &key ) const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQMap<TQString, Extension>::const_iterator it;
|
||
15 years ago
|
|
||
13 years ago
|
it = m_extensions.find( key );
|
||
15 years ago
|
if ( it != m_extensions.constEnd() )
|
||
|
return (*it);
|
||
|
else {
|
||
|
Extension ext;
|
||
|
ext.value = "";
|
||
|
ext.critical = false;
|
||
|
return ext;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString LDAPUrl::extension( const TQString &key, bool &critical ) const
|
||
15 years ago
|
{
|
||
|
Extension ext;
|
||
|
|
||
|
ext = extension( key );
|
||
|
critical = ext.critical;
|
||
|
return ext.value;
|
||
|
}
|
||
|
|
||
15 years ago
|
void LDAPUrl::setExtension( const TQString &key, const LDAPUrl::Extension &ext )
|
||
15 years ago
|
{
|
||
|
m_extensions[ key ] = ext;
|
||
|
updateQuery();
|
||
|
}
|
||
|
|
||
15 years ago
|
void LDAPUrl::setExtension( const TQString &key, const TQString &value, bool critical )
|
||
15 years ago
|
{
|
||
|
Extension ext;
|
||
|
ext.value = value;
|
||
|
ext.critical = critical;
|
||
|
setExtension( key, ext );
|
||
|
}
|
||
|
|
||
15 years ago
|
void LDAPUrl::removeExtension( const TQString &key )
|
||
15 years ago
|
{
|
||
|
m_extensions.remove( key );
|
||
|
updateQuery();
|
||
|
}
|
||
|
|
||
|
void LDAPUrl::updateQuery()
|
||
|
{
|
||
|
Extension ext;
|
||
15 years ago
|
TQMap<TQString, Extension>::iterator it;
|
||
|
TQString q = "?";
|
||
15 years ago
|
|
||
|
// set the attributes to query
|
||
|
if ( m_attributes.count() > 0 ) q += m_attributes.join(",");
|
||
|
|
||
|
// set the scope
|
||
|
q += "?";
|
||
|
switch( m_scope ) {
|
||
|
case Sub:
|
||
|
q += "sub";
|
||
|
break;
|
||
|
case One:
|
||
|
q += "one";
|
||
|
break;
|
||
|
case Base:
|
||
|
q += "base";
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
// set the filter
|
||
|
q += "?";
|
||
|
if ( m_filter != "(objectClass=*)" && !m_filter.isEmpty() )
|
||
|
q += m_filter;
|
||
|
|
||
|
// set the extensions
|
||
|
q += "?";
|
||
|
for ( it = m_extensions.begin(); it != m_extensions.end(); ++it ) {
|
||
|
if ( it.data().critical ) q += "!";
|
||
|
q += it.key();
|
||
|
if ( !it.data().value.isEmpty() )
|
||
|
q += "=" + it.data().value;
|
||
|
q += ",";
|
||
|
}
|
||
|
while ( q.endsWith("?") || q.endsWith(",") )
|
||
|
q.remove( q.length() - 1, 1 );
|
||
|
|
||
|
setQuery(q);
|
||
|
kdDebug(5700) << "LDAP URL updateQuery(): " << prettyURL() << endl;
|
||
|
}
|
||
|
|
||
|
void LDAPUrl::parseQuery()
|
||
|
{
|
||
|
Extension ext;
|
||
15 years ago
|
TQStringList extensions;
|
||
|
TQString q = query();
|
||
15 years ago
|
// remove first ?
|
||
|
if (q.startsWith("?"))
|
||
|
q.remove(0,1);
|
||
|
|
||
|
// split into a list
|
||
15 years ago
|
TQStringList url_items = TQStringList::split("?", q, true);
|
||
15 years ago
|
|
||
|
m_attributes.clear();
|
||
|
m_scope = Base;
|
||
|
m_filter = "(objectClass=*)";
|
||
|
m_extensions.clear();
|
||
|
|
||
|
int i = 0;
|
||
15 years ago
|
for ( TQStringList::Iterator it = url_items.begin(); it != url_items.end(); ++it, i++ ) {
|
||
15 years ago
|
switch (i) {
|
||
|
case 0:
|
||
15 years ago
|
m_attributes = TQStringList::split(",", (*it), false);
|
||
15 years ago
|
break;
|
||
|
case 1:
|
||
|
if ( (*it) == "sub" ) m_scope = Sub; else
|
||
|
if ( (*it) == "one") m_scope = One;
|
||
|
break;
|
||
|
case 2:
|
||
|
m_filter = decode_string( *it );
|
||
|
break;
|
||
|
case 3:
|
||
15 years ago
|
extensions = TQStringList::split(",", (*it), false);
|
||
15 years ago
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString name,value;
|
||
|
for ( TQStringList::Iterator it = extensions.begin(); it != extensions.end(); ++it ) {
|
||
15 years ago
|
ext.critical = false;
|
||
|
name = decode_string( (*it).section('=',0,0) ).lower();
|
||
|
value = decode_string( (*it).section('=',1) );
|
||
|
if ( name.startsWith("!") ) {
|
||
|
ext.critical = true;
|
||
|
name.remove(0, 1);
|
||
|
}
|
||
|
kdDebug(5700) << "LDAPUrl extensions name= " << name << " value: " << value << endl;
|
||
14 years ago
|
ext.value = value.replace( "%2", "," );
|
||
15 years ago
|
setExtension( name, ext );
|
||
|
}
|
||
|
}
|