9#include "kldap_config.h"
11#include "ldap_core_debug.h"
14#include <QVarLengthArray>
28#include "w32-ldap-help.h"
37#define ber_memfree(x) ldap_memfree(x)
39#define ber_memfree(x) win_ldap_memfree(x)
45using namespace KLDAPCore;
47class Q_DECL_HIDDEN
Ber::BerPrivate
51 BerElement *mBer =
nullptr;
59 d->mBer = ber_alloc_t(LBER_USE_DER);
67 bv.bv_val = (
char *)value.
data();
68 bv.bv_len = value.
size();
69 d->mBer = ber_init(&bv);
82 if (ber_flatten(that.d->mBer, &bv) == 0) {
83 d->mBer = ber_init(bv);
88Ber &Ber::operator=(
const Ber &that)
95 if (ber_flatten(that.d->mBer, &bv) == 0) {
96 d->mBer = ber_init(bv);
106 if (ber_flatten(d->mBer, &bv) == 0) {
117 va_start(args, format);
122 while (i < format.
length()) {
129 ber_int_t v = va_arg(args,
int);
130 ret = ber_printf(d->mBer, fmt, v);
136 int Bc = va_arg(args,
int);
137 ret = ber_printf(d->mBer, fmt, B->
data(), Bc);
142 ret = ber_printf(d->mBer, fmt, o->
data(), o->
size());
148 bv.bv_val = (
char *)O->
data();
149 bv.bv_len = O->
size();
150 ret = ber_printf(d->mBer, fmt, &bv);
155 ret = ber_printf(d->mBer, fmt, s->
data());
160 unsigned int t = va_arg(args,
unsigned int);
161 ret = ber_printf(d->mBer, fmt, t);
168 for (j = 0; j < v->
count(); j++) {
169 l[j] = v->
at(j).data();
172 ret = ber_printf(d->mBer, fmt, l.data());
180 for (j = 0; j < V->
count(); j++) {
181 bvs[j].bv_val = (
char *)V->
at(j).data();
182 bvs[j].bv_len = V->
at(j).size();
185 bv[V->
count()] =
nullptr;
186 ret = ber_printf(d->mBer, fmt, bv.data());
194 ret = ber_printf(d->mBer, fmt);
197 qCWarning(LDAP_CORE_LOG) <<
"Invalid BER format parameter: '" << fmt <<
"'";
200 qCDebug(LDAP_CORE_LOG) <<
"ber_printf format:" << fmt <<
"ret:" << ret;
209int Ber::scanf(
QString format, ...)
213 va_start(args, format);
218 while (i < format.
length()) {
226 int *v = va_arg(args,
int *);
227 ret = ber_scanf(d->mBer, fmt, v);
233 int *Bc = va_arg(args,
int *);
235 ret = ber_scanf(d->mBer, fmt, &c, Bc);
245 ret = ber_scanf(d->mBer, fmt, &bv);
248 ber_memfree(bv.bv_val);
255 ret = ber_scanf(d->mBer, fmt, &bv);
265 ret = ber_scanf(d->mBer, fmt, &bv);
274 ret = ber_scanf(d->mBer, fmt, &c);
285 ber_len_t l =
sizeof(buf);
286 ret = ber_scanf(d->mBer, fmt, &buf, &l);
294 unsigned int *t = va_arg(args,
unsigned int *);
295 ret = ber_scanf(d->mBer, fmt, t);
302 ret = ber_scanf(d->mBer, fmt, &c);
303 if (ret != -1 && c) {
310 ber_memfree((
char *)c2);
318 ret = ber_scanf(d->mBer, fmt, &bv);
319 if (ret != -1 && bv) {
335 ret = ber_scanf(d->mBer, fmt);
338 qCWarning(LDAP_CORE_LOG) <<
"Invalid BER format parameter: '" << fmt <<
"'";
342 qCDebug(LDAP_CORE_LOG) <<
"ber_scanf format:" << fmt <<
"ret:" << ret;
351unsigned int Ber::peekTag(
int &size)
355 ret = ber_peek_tag(d->mBer, &len);
360unsigned int Ber::skipTag(
int &size)
364 ret = ber_skip_tag(d->mBer, &len);
374 qCritical() <<
"LDAP support not compiled";
380 qCritical() <<
"LDAP support not compiled";
390 qCritical() <<
"LDAP support not compiled";
393Ber &Ber::operator=(
const Ber &that)
398 qCritical() <<
"LDAP support not compiled";
404 qCritical() <<
"LDAP support not compiled";
411 qCritical() <<
"LDAP support not compiled";
415int Ber::scanf(
QString format, ...)
418 qCritical() <<
"LDAP support not compiled";
422unsigned int Ber::peekTag(
int &size)
425 qCritical() <<
"LDAP support not compiled";
429unsigned int Ber::skipTag(
int &size)
432 qCritical() <<
"LDAP support not compiled";
This class allows encoding and decoding Qt structures using Basic Encoding Rules.
QByteArray flatten() const
Returns the Ber object as a flat QByteArray.
int printf(QString format,...)
Appends the data with the specified format to the Ber object.
Ber()
Constructs a Ber object.
~Ber()
Destroys the Ber object.
qsizetype size() const const
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
qsizetype count() const const
qsizetype length() const const
QByteArray toLatin1() const const