KLDAP Library
ldapcontrol.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 "ldapcontrol.h" 00022 #include "ber.h" 00023 00024 #include <QtCore/QSharedData> 00025 00026 using namespace KLDAP; 00027 00028 class LdapControl::Private : public QSharedData 00029 { 00030 public: 00031 Private() 00032 { 00033 } 00034 00035 Private( const Private &other ) 00036 : QSharedData( other ) 00037 { 00038 mOid = other.mOid; 00039 mValue = other.mValue; 00040 mCritical = other.mCritical; 00041 } 00042 00043 QString mOid; 00044 QByteArray mValue; 00045 bool mCritical; 00046 }; 00047 00048 LdapControl::LdapControl() 00049 : d( new Private ) 00050 { 00051 setControl( QString(), QByteArray(), false ); 00052 } 00053 00054 LdapControl::LdapControl( QString &oid, QByteArray &value, bool critical ) 00055 : d( new Private ) 00056 { 00057 setControl( oid, value, critical ); 00058 } 00059 00060 LdapControl::LdapControl( const LdapControl &that ) 00061 : d( that.d ) 00062 { 00063 setControl( that.d->mOid, that.d->mValue, that.d->mCritical ); 00064 } 00065 00066 LdapControl &LdapControl::operator= ( const LdapControl &that ) 00067 { 00068 if ( this != &that ) { 00069 d = that.d; 00070 } 00071 00072 setControl( that.d->mOid, that.d->mValue, that.d->mCritical ); 00073 00074 return *this; 00075 } 00076 00077 LdapControl::~LdapControl() 00078 { 00079 } 00080 00081 void LdapControl::setControl( const QString &oid, const QByteArray &value, bool critical ) 00082 { 00083 d->mOid = oid; 00084 d->mValue = value; 00085 d->mCritical = critical; 00086 } 00087 00088 QString LdapControl::oid() const 00089 { 00090 return d->mOid; 00091 } 00092 00093 QByteArray LdapControl::value() const 00094 { 00095 return d->mValue; 00096 } 00097 00098 bool LdapControl::critical() const 00099 { 00100 return d->mCritical; 00101 } 00102 00103 void LdapControl::setOid( const QString &oid ) 00104 { 00105 d->mOid = oid; 00106 } 00107 00108 void LdapControl::setValue( const QByteArray &value ) 00109 { 00110 d->mValue = value; 00111 } 00112 00113 void LdapControl::setCritical( bool critical ) 00114 { 00115 d->mCritical = critical; 00116 } 00117 00118 int LdapControl::parsePageControl( QByteArray &cookie ) const 00119 { 00120 if ( d->mOid != "1.2.840.113556.1.4.319" ) { 00121 return -1; 00122 } 00123 00124 Ber ber( d->mValue ); 00125 int size; 00126 if ( ber.scanf( "{iO}", &size, &cookie ) == -1 ) { 00127 return -1; 00128 } else { 00129 return size; 00130 } 00131 } 00132 00133 LdapControl LdapControl::createPageControl( int pagesize, const QByteArray &cookie ) 00134 { 00135 LdapControl control; 00136 Ber ber; 00137 00138 ber.printf( "{iO}", pagesize, &cookie ); 00139 control.setOid( "1.2.840.113556.1.4.319" ); 00140 control.setValue( ber.flatten() ); 00141 return control; 00142 } 00143 00144 void LdapControl::insert( LdapControls &list, const LdapControl &ctrl ) 00145 { 00146 LdapControls::iterator it; 00147 LdapControls::iterator endit = list.end(); 00148 const QString oid = ctrl.oid(); 00149 00150 for ( it = list.begin(); it != endit; ++it ) { 00151 if ( it->oid() == oid ) { 00152 *it = ctrl; 00153 return; 00154 } 00155 } 00156 list.append( ctrl ); 00157 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:51:55 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:51:55 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.