Commit 9418ca07 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

run git clang-format

parent 57e0730f
......@@ -11,7 +11,6 @@ QTEST_MAIN(LdapClientSearchConfigReadConfigJobTest)
LdapClientSearchConfigReadConfigJobTest::LdapClientSearchConfigReadConfigJobTest(QObject *parent)
: QObject(parent)
{
}
void LdapClientSearchConfigReadConfigJobTest::shouldHaveDefaultValues()
......
......@@ -8,18 +8,18 @@
#include "testkldap.h"
#include "ldif.h"
#include "ldapdn.h"
#include "ldapurl.h"
#include "ldapserver.h"
#include "ber.h"
#include "ldapconnection.h"
#include "ldapdn.h"
#include "ldapoperation.h"
#include "ldapsearch.h"
#include "ber.h"
#include "ldapserver.h"
#include "ldapurl.h"
#include "ldif.h"
#include <QDebug>
#include <QTest>
#include <QFile>
#include <QTest>
QTEST_MAIN(KLdapTest)
KLdapTest::KLdapTest(QObject *parent)
......@@ -80,12 +80,12 @@ void KLdapTest::testBer()
ber6.printf(QStringLiteral("{V}"), &alist2);
ber7.printf(QStringLiteral("oi{v}O"), &aoctetString1, ainteger, &alist2, &aoctetString2);
//test integer:
// test integer:
bber = ber1;
bber.scanf(QStringLiteral("i"), &binteger);
QCOMPARE(ainteger, binteger);
//test octet strings:
// test octet strings:
bber = ber2;
bber.scanf(QStringLiteral("o"), &boctetString1);
QCOMPARE(aoctetString1, boctetString1);
......@@ -96,7 +96,7 @@ void KLdapTest::testBer()
bber.scanf(QStringLiteral("o"), &boctetString3);
QCOMPARE(aoctetString3, boctetString3);
//test sequence of octet strings:
// test sequence of octet strings:
bber = ber5;
bber.scanf(QStringLiteral("v"), &blist1);
QCOMPARE(alist1, blist1);
......@@ -105,7 +105,7 @@ void KLdapTest::testBer()
bber.scanf(QStringLiteral("v"), &blist2);
QCOMPARE(alist2, blist2);
//complex tests
// complex tests
boctetString1 = boctetString2 = boctetString3 = QByteArray();
binteger = 0;
blist1.clear();
......@@ -130,8 +130,9 @@ void KLdapTest::testLdapUrl()
LdapUrl url;
bool critical;
url.setUrl(QStringLiteral("ldap://cn=manager,dc=kde,dc=org:password@localhost:3999/"
"dc=kde,dc=org?cn,mail?sub?(objectClass=*)?x-dir=base"));
url.setUrl(
QStringLiteral("ldap://cn=manager,dc=kde,dc=org:password@localhost:3999/"
"dc=kde,dc=org?cn,mail?sub?(objectClass=*)?x-dir=base"));
url.parseQuery();
QCOMPARE(url.userName(), QStringLiteral("cn=manager,dc=kde,dc=org"));
......@@ -141,23 +142,25 @@ void KLdapTest::testLdapUrl()
QCOMPARE(url.attributes().at(0), QStringLiteral("cn"));
QCOMPARE(url.attributes().at(1), QStringLiteral("mail"));
QCOMPARE(url.filter(), QStringLiteral("(objectClass=*)"));
QCOMPARE(url.extension(QStringLiteral("x-dir"), critical),
QStringLiteral("base"));
QCOMPARE(url.extension(QStringLiteral("x-dir"), critical), QStringLiteral("base"));
QCOMPARE(url.query(), QStringLiteral("?cn,mail?sub??x-dir=base"));
// For some reason the code removes the filter if it's (objectClass=*)...
QCOMPARE(url.toString(), QStringLiteral("ldap://cn=manager,dc=kde,dc=org:password@localhost:3999/"
"dc=kde,dc=org??cn,mail?sub??x-dir=base"));
QCOMPARE(url.toString(),
QStringLiteral("ldap://cn=manager,dc=kde,dc=org:password@localhost:3999/"
"dc=kde,dc=org??cn,mail?sub??x-dir=base"));
// Now set a different filter
url.setFilter(QStringLiteral("(objectclass=person)"));
QCOMPARE(url.toDisplayString(), QStringLiteral("ldap://cn=manager,dc=kde,dc=org@localhost:3999/"
"dc=kde,dc=org??cn,mail?sub?%28objectclass%3Dperson%29?x-dir=base"));
QCOMPARE(url.toDisplayString(),
QStringLiteral("ldap://cn=manager,dc=kde,dc=org@localhost:3999/"
"dc=kde,dc=org??cn,mail?sub?%28objectclass%3Dperson%29?x-dir=base"));
QCOMPARE(url.filter(), QStringLiteral("(objectclass=person)"));
// And now a filter with non-ascii letters
url.setFilter(QStringLiteral("(givenName=Valérie *)"));
QCOMPARE(url.toDisplayString(), QString::fromUtf8("ldap://cn=manager,dc=kde,dc=org@localhost:3999/"
"dc=kde,dc=org??cn,mail?sub?%28givenName%3DValérie %2A%29?x-dir=base"));
QCOMPARE(url.toDisplayString(),
QString::fromUtf8("ldap://cn=manager,dc=kde,dc=org@localhost:3999/"
"dc=kde,dc=org??cn,mail?sub?%28givenName%3DValérie %2A%29?x-dir=base"));
QCOMPARE(url.filter(), QStringLiteral("(givenName=Valérie *)"));
// Test roundtrip via QUrl, as happens when sending it to kio_ldap
......@@ -199,10 +202,8 @@ void KLdapTest::testLdapSearch()
LdapUrl url;
url.setUrl(m_url);
url.parseQuery();
connect(m_search, &LdapSearch::result,
this, &KLdapTest::searchResult);
connect(m_search, &LdapSearch::data,
this, &KLdapTest::searchData);
connect(m_search, &LdapSearch::result, this, &KLdapTest::searchResult);
connect(m_search, &LdapSearch::data, this, &KLdapTest::searchData);
const bool success = m_search->search(url);
QCoreApplication::processEvents();
......@@ -225,9 +226,9 @@ void KLdapTest::searchResult(KLDAP::LdapSearch *search)
void KLdapTest::searchData(KLDAP::LdapSearch *search, const KLDAP::LdapObject &obj)
{
Q_UNUSED(search)
//qDebug();
//qDebug() << "Object:";
//qDebug() << obj.toString();
// qDebug();
// qDebug() << "Object:";
// qDebug() << obj.toString();
m_objects.append(obj);
}
......@@ -312,7 +313,7 @@ QCOMPARE( c3.oid(), QStringLiteral("1.2.3.4.5.6") );
QCOMPARE( c3.value(), QByteArray("abcdefg") );
QCOMPARE( c3.critical(), true );
*/
//test Ber functions
// test Ber functions
/*
QByteArray left1("bertest"), right1;
int left2 = 0, right2;
......
......@@ -21,7 +21,7 @@ public:
~KLdapTest() = default;
private Q_SLOTS:
//void testKLdap();
// void testKLdap();
void initTestCase();
void cleanupTestCase();
......
......@@ -7,10 +7,10 @@
#ifndef _KIOSLAVE_COMMON_H
#define _KIOSLAVE_COMMON_H
#include <stdio.h>
#include <QFile>
#include <QDir>
#include <QCoreApplication>
#include <QDir>
#include <QFile>
#include <stdio.h>
extern "C" {
#include <sasl/sasl.h>
......@@ -18,7 +18,7 @@ extern "C" {
inline bool initSASL()
{
#ifdef Q_OS_WIN //krazy:exclude=cpp
#ifdef Q_OS_WIN // krazy:exclude=cpp
for (const auto &path : QCoreApplication::libraryPaths()) {
QDir dir(path);
if (dir.exists(QStringLiteral("sasl2"))) {
......
......@@ -10,9 +10,9 @@
#include <kldap/ldif.h>
#include <QDebug>
#include <KLocalizedString>
#include <QCoreApplication>
#include <QDebug>
#ifdef Q_OS_WIN
#include <Winsock2.h>
......@@ -34,7 +34,7 @@ int Q_DECL_EXPORT kdemain(int argc, char **argv);
*/
int kdemain(int argc, char **argv)
{
QCoreApplication app(argc, argv); // needed for QSocketNotifier
QCoreApplication app(argc, argv); // needed for QSocketNotifier
app.setApplicationName(QStringLiteral("kio_ldap"));
qCDebug(KLDAP_LOG) << "Starting kio_ldap instance";
......@@ -83,8 +83,7 @@ void LDAPProtocol::LDAPErr(int err)
return;
}
qDebug() << "error code: " << err << " msg: " << LdapConnection::errorString(err)
<<extramsg << "'";
qDebug() << "error code: " << err << " msg: " << LdapConnection::errorString(err) << extramsg << "'";
QString msg;
msg = mServer.url().toDisplayString();
if (!extramsg.isEmpty()) {
......@@ -158,8 +157,7 @@ void LDAPProtocol::LDAPErr(int err)
default:
error(ERR_SLAVE_DEFINED,
i18n("LDAP server returned the error: %1 %2\nThe LDAP URL was: %3",
LdapConnection::errorString(err), extramsg, mServer.url().toDisplayString()));
i18n("LDAP server returned the error: %1 %2\nThe LDAP URL was: %3", LdapConnection::errorString(err), extramsg, mServer.url().toDisplayString()));
}
}
......@@ -172,9 +170,8 @@ void LDAPProtocol::controlsFromMetaData(LdapControls &serverctrls, LdapControls
while (hasMetaData(QStringLiteral("SERVER_CTRL%1").arg(i))) {
QByteArray val = metaData(QStringLiteral("SERVER_CTRL%1").arg(i)).toUtf8();
Ldif::splitControl(val, oid, critical, value);
qCDebug(KLDAP_LOG) << "server ctrl #" << i << " value: " << val
<<" oid: " << oid << " critical: " << critical << " value: "
<<QString::fromUtf8(value.constData(), value.size());
qCDebug(KLDAP_LOG) << "server ctrl #" << i << " value: " << val << " oid: " << oid << " critical: " << critical
<< " value: " << QString::fromUtf8(value.constData(), value.size());
LdapControl ctrl(oid, val, critical);
serverctrls.append(ctrl);
i++;
......@@ -183,9 +180,8 @@ void LDAPProtocol::controlsFromMetaData(LdapControls &serverctrls, LdapControls
while (hasMetaData(QStringLiteral("CLIENT_CTRL%1").arg(i))) {
QByteArray val = metaData(QStringLiteral("CLIENT_CTRL%1").arg(i)).toUtf8();
Ldif::splitControl(val, oid, critical, value);
qCDebug(KLDAP_LOG) << "client ctrl #" << i << " value: " << val
<<" oid: " << oid << " critical: " << critical << " value: "
<<QString::fromUtf8(value.constData(), value.size());
qCDebug(KLDAP_LOG) << "client ctrl #" << i << " value: " << val << " oid: " << oid << " critical: " << critical
<< " value: " << QString::fromUtf8(value.constData(), value.size());
LdapControl ctrl(oid, val, critical);
clientctrls.append(ctrl);
i++;
......@@ -232,19 +228,10 @@ void LDAPProtocol::changeCheck(const LdapUrl &url)
server.setUrl(url);
if (mConnected) {
if (server.host() != mServer.host()
|| server.port() != mServer.port()
|| server.baseDn() != mServer.baseDn()
|| server.user() != mServer.user()
|| server.bindDn() != mServer.bindDn()
|| server.realm() != mServer.realm()
|| server.password() != mServer.password()
|| server.timeLimit() != mServer.timeLimit()
|| server.sizeLimit() != mServer.sizeLimit()
|| server.version() != mServer.version()
|| server.security() != mServer.security()
|| server.auth() != mServer.auth()
|| server.mech() != mServer.mech()) {
if (server.host() != mServer.host() || server.port() != mServer.port() || server.baseDn() != mServer.baseDn() || server.user() != mServer.user()
|| server.bindDn() != mServer.bindDn() || server.realm() != mServer.realm() || server.password() != mServer.password()
|| server.timeLimit() != mServer.timeLimit() || server.sizeLimit() != mServer.sizeLimit() || server.version() != mServer.version()
|| server.security() != mServer.security() || server.auth() != mServer.auth() || server.mech() != mServer.mech()) {
closeConnection();
mServer = server;
openConnection();
......@@ -257,10 +244,7 @@ void LDAPProtocol::changeCheck(const LdapUrl &url)
void LDAPProtocol::setHost(const QString &host, quint16 port, const QString &user, const QString &password)
{
if (mServer.host() != host
|| mServer.port() != port
|| mServer.user() != user
|| mServer.password() != password) {
if (mServer.host() != host || mServer.port() != port || mServer.user() != user || mServer.password() != password) {
closeConnection();
}
......@@ -282,8 +266,7 @@ void LDAPProtocol::setHost(const QString &host, quint16 port, const QString &use
mServer.setUser(user);
mServer.setPassword(password);
qCDebug(KLDAP_LOG) << "setHost: " << host << " port: " << port << " user: "
<<user << " pass: [protected]";
qCDebug(KLDAP_LOG) << "setHost: " << host << " port: " << port << " user: " << user << " pass: [protected]";
}
void LDAPProtocol::openConnection()
......@@ -306,8 +289,7 @@ void LDAPProtocol::openConnection()
info.url.setPort(mServer.port());
info.url.setUserName(mServer.user());
info.caption = i18n("LDAP Login");
info.comment = QString::fromLatin1(mProtocol) + QLatin1String("://") + mServer.host() + QLatin1Char(':')
+QString::number(mServer.port());
info.comment = QString::fromLatin1(mProtocol) + QLatin1String("://") + mServer.host() + QLatin1Char(':') + QString::number(mServer.port());
info.commentLabel = i18n("site:");
info.username = mServer.auth() == LdapServer::SASL ? mServer.user() : mServer.bindDn();
info.password = mServer.password();
......@@ -324,9 +306,7 @@ void LDAPProtocol::openConnection()
connected();
return;
}
if (retval == KLDAP_INVALID_CREDENTIALS
|| retval == KLDAP_INSUFFICIENT_ACCESS
|| retval == KLDAP_INAPPROPRIATE_AUTH
if (retval == KLDAP_INVALID_CREDENTIALS || retval == KLDAP_INSUFFICIENT_ACCESS || retval == KLDAP_INAPPROPRIATE_AUTH
|| retval == KLDAP_UNWILLING_TO_PERFORM) {
if (firstauth && cached) {
if (mServer.auth() == LdapServer::SASL) {
......@@ -338,11 +318,9 @@ void LDAPProtocol::openConnection()
mConn.setServer(mServer);
cached = false;
} else {
const int errorCode = firstauth
? openPasswordDialogV2(info)
: openPasswordDialogV2(info, i18n("Invalid authorization information."));
const int errorCode = firstauth ? openPasswordDialogV2(info) : openPasswordDialogV2(info, i18n("Invalid authorization information."));
if (!errorCode) {
if (info.keepPassword) { // user asked password be save/remembered
if (info.keepPassword) { // user asked password be save/remembered
cacheAuthentication(info);
}
} else {
......@@ -416,7 +394,7 @@ void LDAPProtocol::get(const QUrl &_url)
// tell the mimetype
mimeType(QStringLiteral("text/plain"));
// collect the result
//QByteArray result;
// QByteArray result;
filesize_t processed_size = 0;
while (true) {
......@@ -587,7 +565,7 @@ void LDAPProtocol::put(const QUrl &_url, int, KIO::JobFlags flags)
ldif.setLdif(buffer);
}
if (result < 0) {
//error
// error
return;
}
if (result == 0) {
......@@ -614,12 +592,9 @@ void LDAPProtocol::put(const QUrl &_url, int, KIO::JobFlags flags)
ldaperr = mOp.del_s(ldif.dn());
break;
case Ldif::Entry_Modrdn:
qCDebug(KLDAP_LOG) << "kio_ldap_modrdn olddn:" << ldif.dn().toString()
<<" newRdn: " << ldif.newRdn()
<<" newSuperior: " << ldif.newSuperior()
<<" deloldrdn: " << ldif.delOldRdn();
ldaperr = mOp.rename_s(ldif.dn(), ldif.newRdn(),
ldif.newSuperior(), ldif.delOldRdn());
qCDebug(KLDAP_LOG) << "kio_ldap_modrdn olddn:" << ldif.dn().toString() << " newRdn: " << ldif.newRdn()
<< " newSuperior: " << ldif.newSuperior() << " deloldrdn: " << ldif.delOldRdn();
ldaperr = mOp.rename_s(ldif.dn(), ldif.newRdn(), ldif.newSuperior(), ldif.delOldRdn());
break;
case Ldif::Entry_Mod:
qCDebug(KLDAP_LOG) << "kio_ldap_mod";
......@@ -648,8 +623,7 @@ void LDAPProtocol::put(const QUrl &_url, int, KIO::JobFlags flags)
break;
case Ldif::Item:
switch (ldif.entryType()) {
case Ldif::Entry_Mod:
{
case Ldif::Entry_Mod: {
LdapOperation::ModOp op;
op.type = LdapOperation::Mod_None;
switch (ldif.modType()) {
......@@ -683,8 +657,7 @@ void LDAPProtocol::put(const QUrl &_url, int, KIO::JobFlags flags)
return;
}
break;
case Ldif::Control:
{
case Ldif::Control: {
LdapControl control;
control.setControl(ldif.oid(), ldif.value(), ldif.isCritical());
serverctrls.append(control);
......@@ -692,8 +665,7 @@ void LDAPProtocol::put(const QUrl &_url, int, KIO::JobFlags flags)
break;
}
case Ldif::Err:
error(ERR_SLAVE_DEFINED,
i18n("Invalid Ldif file in line %1.", ldif.lineNumber()));
error(ERR_SLAVE_DEFINED, i18n("Invalid Ldif file in line %1.", ldif.lineNumber()));
return;
}
} while (ret != Ldif::MoreData);
......@@ -761,7 +733,7 @@ void LDAPProtocol::listDir(const QUrl &_url)
LDAPEntry2UDSEntry(mOp.object().dn(), uds, usrc);
listEntry(uds);
// processedSize( total );
// processedSize( total );
qCDebug(KLDAP_LOG) << " total: " << total << " " << usrc.toDisplayString();
// publish the sub-directories (if dirmode==sub)
......@@ -791,7 +763,7 @@ void LDAPProtocol::listDir(const QUrl &_url)
}
}
// totalSize( total );
// totalSize( total );
uds.clear();
// we are done
......
......@@ -7,15 +7,15 @@
#ifndef __LDAP_H__
#define __LDAP_H__
#include <kio/slavebase.h>
#include <kio/authinfo.h>
#include <kio/slavebase.h>
#include <kldap/ldapdefs.h>
#include <kldap/ldapurl.h>
#include <kldap/ldapcontrol.h>
#include <kldap/ldapconnection.h>
#include <kldap/ldapcontrol.h>
#include <kldap/ldapdefs.h>
#include <kldap/ldapdn.h>
#include <kldap/ldapoperation.h>
#include <kldap/ldapurl.h>
class LDAPProtocol : public KIO::SlaveBase
{
......@@ -35,7 +35,6 @@ public:
void put(const QUrl &url, int permissions, KIO::JobFlags flags) override;
private:
KLDAP::LdapConnection mConn;
KLDAP::LdapOperation mOp;
KLDAP::LdapServer mServer;
......
......@@ -17,7 +17,7 @@
#ifdef LDAP_FOUND
#ifdef Q_OS_SOLARIS //krazy:exclude=cpp
#ifdef Q_OS_SOLARIS // krazy:exclude=cpp
#define BC31 1
#endif
......@@ -33,11 +33,11 @@
#endif
#ifndef HAVE_BER_MEMFREE
# ifndef HAVE_WINLDAP_H
# define ber_memfree(x) ldap_memfree(x)
# else
# define ber_memfree(x) win_ldap_memfree(x)
# endif
#ifndef HAVE_WINLDAP_H
#define ber_memfree(x) ldap_memfree(x)
#else
#define ber_memfree(x) win_ldap_memfree(x)
#endif
#endif
#endif
......@@ -125,28 +125,24 @@ int Ber::printf(QString format, ...)
switch (fmt[0]) {
case 'b':
case 'e':
case 'i':
{
case 'i': {
ber_int_t v = va_arg(args, int);
ret = ber_printf(d->mBer, fmt, v);
break;
}
case 'B':
{
//FIXME: QBitArray vould be logical, but how to access the bits?
case 'B': {
// FIXME: QBitArray vould be logical, but how to access the bits?
QByteArray *B = va_arg(args, QByteArray *);
int Bc = va_arg(args, int);
ret = ber_printf(d->mBer, fmt, B->data(), Bc);
break;
}
case 'o':
{
case 'o': {
QByteArray *o = va_arg(args, QByteArray *);
ret = ber_printf(d->mBer, fmt, o->data(), o->size());
break;
}
case 'O':
{
case 'O': {
QByteArray *O = va_arg(args, QByteArray *);
struct berval bv;
bv.bv_val = (char *)O->data();
......@@ -155,22 +151,19 @@ int Ber::printf(QString format, ...)
break;
break;
}
case 's':
{
case 's': {
QByteArray *s = va_arg(args, QByteArray *);
ret = ber_printf(d->mBer, fmt, s->data());
break;
break;
}
case 't':
{
case 't': {
unsigned int t = va_arg(args, unsigned int);
ret = ber_printf(d->mBer, fmt, t);
break;
break;
}
case 'v':
{
case 'v': {
QList<QByteArray> *v = va_arg(args, QList<QByteArray> *);
QVarLengthArray<const char *> l(v->count() + 1);
int j;
......@@ -181,8 +174,7 @@ int Ber::printf(QString format, ...)
ret = ber_printf(d->mBer, fmt, l.data());
break;
}
case 'V':
{
case 'V': {
QList<QByteArray> *V = va_arg(args, QList<QByteArray> *);
QVarLengthArray<struct berval *> bv(V->count() + 1);
QVarLengthArray<struct berval> bvs(V->count());
......@@ -231,15 +223,13 @@ int Ber::scanf(QString format, ...)
case 'l':
case 'b':
case 'e':
case 'i':
{
case 'i': {
int *v = va_arg(args, int *);
ret = ber_scanf(d->mBer, fmt, v);
break;
}
case 'B':
{
//FIXME: QBitArray vould be logical, but how to access the bits?
case 'B': {
// FIXME: QBitArray vould be logical, but how to access the bits?
QByteArray *B = va_arg(args, QByteArray *);
int *Bc = va_arg(args, int *);
char *c;
......@@ -250,8 +240,7 @@ int Ber::scanf(QString format, ...)
}
break;
}
case 'o':
{
case 'o': {
QByteArray *o = va_arg(args, QByteArray *);
struct berval bv;
ret = ber_scanf(d->mBer, fmt, &bv);
......@@ -261,8 +250,7 @@ int Ber::scanf(QString format, ...)
}
break;
}
case 'O':
{
case 'O': {
QByteArray *O = va_arg(args, QByteArray *);
struct berval *bv;
ret = ber_scanf(d->mBer, fmt, &bv);
......@@ -273,8 +261,7 @@ int Ber::scanf(QString format, ...)
break;
break;
}
case 'm':
{ //the same as 'O', just *bv should not be freed.
case 'm': { // the same as 'O', just *bv should not be freed.
QByteArray *m = va_arg(args, QByteArray *);
struct berval *bv;
ret = ber_scanf(d->mBer, fmt, &bv);
......@@ -283,8 +270,7 @@ int Ber::scanf(QString format, ...)
}
break;
}
case 'a':
{
case 'a': {
QByteArray *a = va_arg(args, QByteArray *);
char *c;
ret = ber_scanf(d->mBer, fmt, &c);
......@@ -295,8 +281,7 @@ int Ber::scanf(QString format, ...)
break;
}
case 's':
{
case 's': {
QByteArray *s = va_arg(args, QByteArray *);
char buf[255];
ber_len_t l = sizeof(buf);
......@@ -307,15 +292,13 @@ int Ber::scanf(QString format, ...)
break;
}
case 't':
case 'T':
{
case 'T': {
unsigned int *t = va_arg(args, unsigned int *);
ret = ber_scanf(d->mBer, fmt, t);
break;
break;
}
case 'v':
{
case 'v': {
QList<QByteArray> *v = va_arg(args, QList<QByteArray> *);
char **c, **c2;
ret = ber_scanf(d->mBer, fmt, &c);
......@@ -330,8 +313,7 @@ int Ber::scanf(QString format, ...)
}
break;
}
case 'V':
{
case 'V': {
QList<QByteArray> *v = va_arg(args, QList<QByteArray> *);
struct berval **bv, **bv2;