KLDAP Library
ldapcontrol.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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; d->mValue = value; d->mCritical = critical;
00084 }
00085
00086 QString LdapControl::oid() const
00087 {
00088 return d->mOid;
00089 }
00090
00091 QByteArray LdapControl::value() const
00092 {
00093 return d->mValue;
00094 }
00095
00096 bool LdapControl::critical() const
00097 {
00098 return d->mCritical;
00099 }
00100
00101 void LdapControl::setOid( const QString &oid )
00102 {
00103 d->mOid = oid;
00104 }
00105
00106 void LdapControl::setValue( const QByteArray &value )
00107 {
00108 d->mValue = value;
00109 }
00110
00111 void LdapControl::setCritical( bool critical )
00112 {
00113 d->mCritical = critical;
00114 }
00115
00116 int LdapControl::parsePageControl( QByteArray &cookie ) const
00117 {
00118 if ( d->mOid != "1.2.840.113556.1.4.319" ) {
00119 return -1;
00120 }
00121
00122 Ber ber( d->mValue );
00123 int size;
00124 if ( ber.scanf( "{iO}", &size, &cookie ) == -1 ) {
00125 return -1;
00126 } else {
00127 return size;
00128 }
00129 }
00130
00131 LdapControl LdapControl::createPageControl( int pagesize, const QByteArray &cookie )
00132 {
00133 LdapControl control;
00134 Ber ber;
00135
00136 ber.printf( "{iO}", pagesize, &cookie );
00137 control.setOid( "1.2.840.113556.1.4.319" );
00138 control.setValue( ber.flatten() );
00139 return control;
00140 }