22 #include "kldap_config.h"
26 #include <QtCore/QList>
27 #include <qvarlengtharray.h>
33 #ifdef Q_OS_SOLARIS //krazy:exclude=cpp
37 #ifndef HAVE_WINLDAP_H
41 #include <w32-ldap-help.h>
45 #define LBER_USE_DER 1
48 #ifndef HAVE_BER_MEMFREE
49 # ifndef HAVE_WINLDAP_H
50 # define ber_memfree(x) ldap_memfree(x)
52 # define ber_memfree(x) win_ldap_memfree(x)
58 using namespace KLDAP;
72 d->mBer = ber_alloc_t( LBER_USE_DER );
80 bv.bv_val = (
char *) value.
data();
81 bv.bv_len = value.
size();
82 d->mBer = ber_init( &bv );
88 ber_free( d->mBer, 1 );
96 if ( ber_flatten( that.d->mBer, &bv ) == 0 ) {
97 d->mBer = ber_init( bv );
102 Ber &Ber::operator=(
const Ber &that )
104 if (
this == &that ) {
109 if ( ber_flatten( that.d->mBer, &bv ) == 0 ) {
110 d->mBer = ber_init( bv );
120 if ( ber_flatten( d->mBer, &bv ) == 0 ) {
131 va_start ( args, format );
135 while ( i < format.
length() ) {
143 ber_int_t v = va_arg( args,
int );
144 ret = ber_printf( d->mBer, fmt, v );
151 int Bc = va_arg( args,
int );
152 ret = ber_printf( d->mBer, fmt, B->
data(), Bc );
158 ret = ber_printf( d->mBer, fmt, o->
data(), o->
size() );
165 bv.bv_val = (
char *) O->
data();
166 bv.bv_len = O->
size();
167 ret = ber_printf( d->mBer, fmt, &bv );
174 ret = ber_printf( d->mBer, fmt, s->
data() );
180 unsigned int t = va_arg( args,
unsigned int );
181 ret = ber_printf( d->mBer, fmt, t );
190 for ( j = 0; j < v->
count(); j++ ) {
191 l[j] = v->
at( j ).data();
194 ret = ber_printf( d->mBer, fmt, l.data() );
203 for ( j = 0; j < V->
count(); j++ ) {
204 bvs[j].bv_val = (
char *) V->
at( j ).data();
205 bvs[j].bv_len = V->
at( j ).size();
209 ret = ber_printf( d->mBer, fmt, bv.data() );
217 ret = ber_printf( d->mBer, fmt );
220 kWarning() <<
"Invalid BER format parameter: '" << fmt <<
"'";
223 kDebug() <<
"ber_printf format:" << fmt <<
"ret:" << ret;
232 int Ber::scanf(
const QString &format, ... )
236 va_start ( args, format );
240 while ( i < format.
length() ) {
249 int *v = va_arg( args,
int * );
250 ret = ber_scanf( d->mBer, fmt, v );
257 int *Bc = va_arg( args,
int * );
259 ret = ber_scanf( d->mBer, fmt, &c, Bc );
270 ret = ber_scanf( d->mBer, fmt, &bv );
273 ber_memfree( bv.bv_val );
281 ret = ber_scanf( d->mBer, fmt, &bv );
293 ret = ber_scanf( d->mBer, fmt, &bv );
303 ret = ber_scanf( d->mBer, fmt, &c );
315 ber_len_t l =
sizeof( buf );
316 ret = ber_scanf( d->mBer, fmt, &buf, &l );
325 unsigned int *t = va_arg( args,
unsigned int * );
326 ret = ber_scanf( d->mBer, fmt, t );
334 ret = ber_scanf( d->mBer, fmt, &c );
335 if ( ret != -1 && c ) {
342 ber_memfree( (
char *) c2 );
349 struct berval **bv, **bv2;
350 ret = ber_scanf( d->mBer, fmt, &bv );
351 if ( ret != -1 && bv ) {
367 ret = ber_scanf( d->mBer, fmt );
370 kWarning() <<
"Invalid BER format parameter: '" << fmt <<
"'";
374 kDebug() <<
"ber_scanf format:" << fmt <<
"ret:" << ret;
384 unsigned int Ber::peekTag(
int &size )
388 ret = ber_peek_tag( d->mBer, &len );
393 unsigned int Ber::skipTag(
int &size )
397 ret = ber_skip_tag( d->mBer, &len );
404 : d( new BerPrivate )
406 kError() <<
"LDAP support not compiled";
410 : d( new BerPrivate )
412 kError() <<
"LDAP support not compiled";
421 : d( new BerPrivate )
423 kError() <<
"LDAP support not compiled";
426 Ber &Ber::operator=(
const Ber &that )
428 if (
this == &that ) {
431 kError() <<
"LDAP support not compiled";
437 kError() <<
"LDAP support not compiled";
444 kError() <<
"LDAP support not compiled";
448 int Ber::scanf(
const QString &format, ... )
451 kError() <<
"LDAP support not compiled";
455 unsigned int Ber::peekTag(
int &size )
458 kError() <<
"LDAP support not compiled";
462 unsigned int Ber::skipTag(
int &size )
465 kError() <<
"LDAP support not compiled";
const T & at(int i) const
Ber()
Constructs a Ber object.
This class allows encoding and decoding Qt structures using Basic Encoding Rules. ...
virtual ~Ber()
Destroys the Ber object.
int count(const T &value) const
void append(const T &value)
QByteArray flatten() const
Returns the Ber object as a flat QByteArray.
QByteArray toLatin1() const
int printf(const QString &format,...)
Appends the data with the specified format to the Ber object.