• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

KLDAP Library

ldapserver.cpp

00001 /*
00002   This file is part of libkldap.
00003   Copyright (c) 2004-2006 Szombathelyi György <gyurco@freemail.hu>
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Library General  Public
00007   License as published by the Free Software Foundation; either
00008   version 2 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Library General Public License for more details.
00014 
00015   You should have received a copy of the GNU Library General Public License
00016   along with this library; see the file COPYING.LIB.  If not, write to
00017   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018   Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "ldapserver.h"
00022 
00023 #include <kdebug.h>
00024 
00025 using namespace KLDAP;
00026 
00027 class LdapServer::LdapServerPrivate
00028 {
00029   public:
00030     QString mHost;
00031     int mPort;
00032     LdapDN mBaseDn;
00033     QString mUser;
00034     QString mBindDn;
00035     QString mRealm;
00036     QString mPassword;
00037     QString mMech;
00038     QString mFilter;
00039     int mTimeLimit, mSizeLimit, mVersion, mPageSize, mTimeout;
00040     Security mSecurity;
00041     Auth mAuth;
00042     LdapUrl::Scope mScope;
00043 };
00044 
00045 LdapServer::LdapServer()
00046   : d( new LdapServerPrivate )
00047 {
00048   clear();
00049 }
00050 
00051 LdapServer::LdapServer( const LdapUrl &url )
00052   : d( new LdapServerPrivate )
00053 {
00054   clear();
00055 
00056   setUrl( url );
00057 }
00058 
00059 LdapServer::LdapServer( const LdapServer &that )
00060   : d( new LdapServerPrivate )
00061 {
00062   *d = *that.d;
00063 }
00064 
00065 LdapServer &LdapServer::operator= ( const LdapServer &that )
00066 {
00067   if ( this == &that ) {
00068     return *this;
00069   }
00070 
00071   *d = *that.d;
00072 
00073   return *this;
00074 }
00075 
00076 LdapServer::~LdapServer()
00077 {
00078   delete d;
00079 }
00080 
00081 void LdapServer::clear()
00082 {
00083   d->mPort = 389;
00084   d->mHost = d->mUser = d->mBindDn = d->mMech = d->mPassword = QString();
00085   d->mSecurity = None;
00086   d->mAuth = Anonymous;
00087   d->mVersion = 3;
00088   d->mTimeout = 0;
00089   d->mSizeLimit = d->mTimeLimit = d->mPageSize = 0;
00090 }
00091 
00092 QString LdapServer::host() const
00093 {
00094   return d->mHost;
00095 }
00096 
00097 int LdapServer::port() const
00098 {
00099   return d->mPort;
00100 }
00101 
00102 LdapDN LdapServer::baseDn() const
00103 {
00104   return d->mBaseDn;
00105 }
00106 
00107 QString LdapServer::user() const
00108 {
00109   return d->mUser;
00110 }
00111 
00112 QString LdapServer::bindDn() const
00113 {
00114   return d->mBindDn;
00115 }
00116 
00117 QString LdapServer::realm() const
00118 {
00119   return d->mRealm;
00120 }
00121 
00122 QString LdapServer::password() const
00123 {
00124   return d->mPassword;
00125 }
00126 
00127 QString LdapServer::filter() const
00128 {
00129   return d->mFilter;
00130 }
00131 
00132 LdapUrl::Scope LdapServer::scope() const
00133 {
00134   return d->mScope;
00135 }
00136 
00137 int LdapServer::timeLimit() const
00138 {
00139   return d->mTimeLimit;
00140 }
00141 
00142 int LdapServer::sizeLimit() const
00143 {
00144   return d->mSizeLimit;
00145 }
00146 
00147 int LdapServer::pageSize() const
00148 {
00149   return d->mPageSize;
00150 }
00151 
00152 int LdapServer::version() const
00153 {
00154   return d->mVersion;
00155 }
00156 
00157 LdapServer::Security LdapServer::security() const
00158 {
00159   return d->mSecurity;
00160 }
00161 
00162 LdapServer::Auth LdapServer::auth() const
00163 {
00164   return d->mAuth;
00165 }
00166 
00167 QString LdapServer::mech() const
00168 {
00169   return d->mMech;
00170 }
00171 
00172 int LdapServer::timeout() const
00173 {
00174   return d->mTimeout;
00175 }
00176 
00177 void LdapServer::setHost( const QString &host )
00178 {
00179   d->mHost = host;
00180 }
00181 
00182 void LdapServer::setPort( int port )
00183 {
00184   d->mPort = port;
00185 }
00186 
00187 void LdapServer::setBaseDn( const LdapDN &baseDn )
00188 {
00189   d->mBaseDn = baseDn;
00190 }
00191 
00192 void LdapServer::setUser( const QString &user )
00193 {
00194   d->mUser = user;
00195 }
00196 
00197 void LdapServer::setBindDn( const QString &bindDn )
00198 {
00199   d->mBindDn = bindDn;
00200 }
00201 
00202 void LdapServer::setRealm( const QString &realm )
00203 {
00204   d->mRealm = realm;
00205 }
00206 
00207 void LdapServer::setPassword( const QString &password )
00208 {
00209   d->mPassword = password;
00210 }
00211 
00212 void LdapServer::setTimeLimit( int timelimit )
00213 {
00214   d->mTimeLimit = timelimit;
00215 }
00216 
00217 void LdapServer::setSizeLimit( int sizelimit )
00218 {
00219   d->mSizeLimit = sizelimit;
00220 }
00221 
00222 void LdapServer::setPageSize( int pagesize )
00223 {
00224   d->mPageSize = pagesize;
00225 }
00226 
00227 void LdapServer::setFilter( const QString &filter )
00228 {
00229   d->mFilter = filter;
00230 }
00231 
00232 void LdapServer::setScope( LdapUrl::Scope scope )
00233 {
00234   d->mScope = scope;
00235 }
00236 
00237 void LdapServer::setVersion( int version )
00238 {
00239   d->mVersion = version;
00240 }
00241 
00242 void LdapServer::setSecurity( Security security )
00243 {
00244   d->mSecurity = security;
00245 }
00246 
00247 void LdapServer::setAuth( Auth auth )
00248 {
00249   d->mAuth = auth;
00250 }
00251 
00252 void LdapServer::setMech( const QString &mech )
00253 {
00254   d->mMech = mech;
00255 }
00256 
00257 void LdapServer::setTimeout( int timeout )
00258 {
00259   d->mTimeout = timeout;
00260 }
00261 
00262 void LdapServer::setUrl( const LdapUrl &url )
00263 {
00264   bool critical;
00265 
00266   d->mHost = url.host();
00267   int port = url.port();
00268   if ( port <= 0 ) {
00269     d->mPort = 389;
00270   } else {
00271     d->mPort = port;
00272   }
00273   d->mBaseDn = url.dn();
00274   d->mScope = url.scope();
00275 
00276   d->mFilter = url.filter();
00277 
00278   d->mSecurity = None;
00279   if ( url.protocol() == "ldaps" ) {
00280     d->mSecurity = SSL;
00281   } else if ( url.hasExtension( "x-tls" ) ) {
00282     d->mSecurity = TLS;
00283   }
00284   kDebug() << "security:" << d->mSecurity;
00285 
00286   d->mMech = d->mUser = d->mBindDn = QString();
00287   if ( url.hasExtension( "x-sasl" ) ) {
00288     d->mAuth = SASL;
00289     if ( url.hasExtension( "x-mech" ) ) {
00290       d->mMech = url.extension( "x-mech", critical );
00291     }
00292     if ( url.hasExtension( "x-realm" ) ) {
00293       d->mRealm = url.extension( "x-realm", critical );
00294     }
00295     if ( url.hasExtension( "bindname" ) ) {
00296       d->mBindDn = url.extension( "bindname", critical );
00297     }
00298     d->mUser = url.user();
00299   } else if ( url.hasExtension( "bindname" ) ) {
00300     d->mAuth = Simple;
00301     d->mBindDn = url.extension( "bindname", critical );
00302   } else {
00303     QString user = url.user();
00304     if ( user.isEmpty() ) {
00305       d->mAuth = Anonymous;
00306     } else {
00307       d->mAuth = Simple;
00308       d->mBindDn = user;
00309     }
00310   }
00311   d->mPassword = url.password();
00312   if ( url.hasExtension( "x-version" ) ) {
00313     d->mVersion = url.extension( "x-version", critical ).toInt();
00314   } else {
00315     d->mVersion = 3;
00316   }
00317 
00318   if ( url.hasExtension( "x-timeout" ) ) {
00319     d->mTimeout = url.extension( "x-timeout", critical ).toInt();
00320   } else {
00321     d->mTimeout = 0;
00322   }
00323 
00324   if ( url.hasExtension( "x-timelimit" ) ) {
00325     d->mTimeLimit = url.extension( "x-timelimit", critical ).toInt();
00326   } else {
00327     d->mTimeLimit = 0;
00328   }
00329 
00330   if ( url.hasExtension( "x-sizelimit" ) ) {
00331     d->mSizeLimit = url.extension( "x-sizelimit", critical ).toInt();
00332   } else {
00333     d->mSizeLimit = 0;
00334   }
00335 
00336   if ( url.hasExtension( "x-pagesize" ) ) {
00337     d->mPageSize = url.extension( "x-pagesize", critical ).toInt();
00338   } else {
00339     d->mPageSize = 0;
00340   }
00341 }
00342 
00343 LdapUrl LdapServer::url() const
00344 {
00345   LdapUrl url;
00346   url.setProtocol( d->mSecurity == SSL ? "ldaps" : "ldap" );
00347   url.setPort( d->mPort );
00348   url.setHost( d->mHost );
00349   url.setPassword( d->mPassword );
00350   url.setDn( d->mBaseDn );
00351   url.setFilter( d->mFilter );
00352   url.setScope( d->mScope );
00353   if ( d->mAuth == SASL ) {
00354     url.setUser( d->mUser );
00355     url.setExtension( "bindname", d->mBindDn, true );
00356     url.setExtension( "x-sasl", QString() );
00357     if ( !d->mMech.isEmpty() ) {
00358       url.setExtension( "x-mech", d->mMech );
00359     }
00360     if ( !d->mRealm.isEmpty() ) {
00361       url.setExtension( "x-realm", d->mRealm );
00362     }
00363   } else {
00364     url.setUser( d->mBindDn );
00365   }
00366   if ( d->mVersion == 2 ) {
00367     url.setExtension( "x-version", d->mVersion );
00368   }
00369   if ( d->mTimeout ) {
00370     url.setExtension( "x-timeout", d->mTimeout );
00371   }
00372   if ( d->mTimeLimit != 0 ) {
00373     url.setExtension( "x-timelimit", d->mTimeLimit );
00374   }
00375   if ( d->mSizeLimit != 0 ) {
00376     url.setExtension( "x-sizelimit", d->mSizeLimit );
00377   }
00378   if ( d->mPageSize != 0 ) {
00379     url.setExtension( "x-pagesize", d->mPageSize );
00380   }
00381   if ( d->mSecurity == TLS ) {
00382     url.setExtension( "x-tls", 1, true );
00383   }
00384 
00385   return url;
00386 }

KLDAP Library

Skip menu "KLDAP Library"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.6
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal