Commit 3ab587e3 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

GIT_SILENT: coding style

parent f0f85026
......@@ -149,7 +149,7 @@ void KLdapTest::testLdapUrl()
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"));
"dc=kde,dc=org?cn,mail?sub?(objectClass=*)?x-dir=base"));
url.parseQuery();
QCOMPARE(url.userName(), QStringLiteral("cn=manager,dc=kde,dc=org"));
......
......@@ -42,7 +42,7 @@ using namespace KIO;
using namespace KLDAP;
extern "C" {
int Q_DECL_EXPORT kdemain(int argc, char **argv);
int Q_DECL_EXPORT kdemain(int argc, char **argv);
}
/**
......@@ -71,8 +71,7 @@ int kdemain(int argc, char **argv)
/**
* Initialize the ldap slave
*/
LDAPProtocol::LDAPProtocol(const QByteArray &protocol, const QByteArray &pool,
const QByteArray &app)
LDAPProtocol::LDAPProtocol(const QByteArray &protocol, const QByteArray &pool, const QByteArray &app)
: SlaveBase(protocol, pool, app)
{
mConnected = false;
......@@ -87,7 +86,6 @@ LDAPProtocol::~LDAPProtocol()
void LDAPProtocol::LDAPErr(int err)
{
QString extramsg;
if (mConnected) {
if (err == KLDAP_SUCCESS) {
......@@ -101,8 +99,8 @@ void LDAPProtocol::LDAPErr(int err)
return;
}
qDebug() << "error code: " << err << " msg: " << LdapConnection::errorString(err) <<
extramsg << "'" << endl;
qDebug() << "error code: " << err << " msg: " << LdapConnection::errorString(err)
<<extramsg << "'" << endl;
QString msg;
msg = mServer.url().toDisplayString();
if (!extramsg.isEmpty()) {
......@@ -181,8 +179,7 @@ void LDAPProtocol::LDAPErr(int err)
}
}
void LDAPProtocol::controlsFromMetaData(LdapControls &serverctrls,
LdapControls &clientctrls)
void LDAPProtocol::controlsFromMetaData(LdapControls &serverctrls, LdapControls &clientctrls)
{
QString oid;
bool critical;
......@@ -191,9 +188,9 @@ void LDAPProtocol::controlsFromMetaData(LdapControls &serverctrls,
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()) << endl;
qCDebug(KLDAP_LOG) << "server ctrl #" << i << " value: " << val
<<" oid: " << oid << " critical: " << critical << " value: "
<<QString::fromUtf8(value.constData(), value.size()) << endl;
LdapControl ctrl(oid, val, critical);
serverctrls.append(ctrl);
i++;
......@@ -202,18 +199,16 @@ void LDAPProtocol::controlsFromMetaData(LdapControls &serverctrls,
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()) << endl;
qCDebug(KLDAP_LOG) << "client ctrl #" << i << " value: " << val
<<" oid: " << oid << " critical: " << critical << " value: "
<<QString::fromUtf8(value.constData(), value.size()) << endl;
LdapControl ctrl(oid, val, critical);
clientctrls.append(ctrl);
i++;
}
}
void LDAPProtocol::LDAPEntry2UDSEntry(const LdapDN &dn, UDSEntry &entry,
const LdapUrl &usrc, bool dir)
void LDAPProtocol::LDAPEntry2UDSEntry(const LdapDN &dn, UDSEntry &entry, const LdapUrl &usrc, bool dir)
{
int pos;
entry.clear();
......@@ -253,20 +248,19 @@ 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();
......@@ -277,13 +271,12 @@ void LDAPProtocol::changeCheck(const LdapUrl &url)
}
}
void LDAPProtocol::setHost(const QString &host, quint16 port,
const QString &user, const QString &password)
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();
}
......@@ -305,8 +298,8 @@ void LDAPProtocol::setHost(const QString &host, quint16 port,
mServer.setUser(user);
mServer.setPassword(password);
qCDebug(KLDAP_LOG) << "setHost: " << host << " port: " << port << " user: " <<
user << " pass: [protected]" << endl;
qCDebug(KLDAP_LOG) << "setHost: " << host << " port: " << port << " user: "
<<user << " pass: [protected]" << endl;
}
void LDAPProtocol::openConnection()
......@@ -329,8 +322,8 @@ 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();
......@@ -347,11 +340,10 @@ void LDAPProtocol::openConnection()
connected();
return;
}
if (retval == KLDAP_INVALID_CREDENTIALS ||
retval == KLDAP_INSUFFICIENT_ACCESS ||
retval == KLDAP_INAPPROPRIATE_AUTH ||
retval == KLDAP_UNWILLING_TO_PERFORM) {
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) {
mServer.setUser(info.username);
......@@ -362,9 +354,9 @@ void LDAPProtocol::openConnection()
mConn.setServer(mServer);
cached = false;
} else {
bool ok = firstauth ?
openPasswordDialog(info) :
openPasswordDialog(info, i18n("Invalid authorization information."));
bool ok = firstauth
? openPasswordDialog(info)
: openPasswordDialog(info, i18n("Invalid authorization information."));
if (!ok) {
error(ERR_USER_CANCELED, i18n("LDAP connection canceled."));
closeConnection();
......@@ -379,7 +371,6 @@ void LDAPProtocol::openConnection()
firstauth = false;
mConn.setServer(mServer);
}
} else {
LDAPErr(retval);
closeConnection();
......@@ -444,7 +435,6 @@ void LDAPProtocol::get(const QUrl &_url)
}
qCDebug(KLDAP_LOG) << " ldap_result: " << ret;
if (ret == LdapOperation::RES_SEARCH_RESULT) {
if (mServer.pageSize()) {
QByteArray cookie;
int estsize = -1;
......@@ -613,7 +603,6 @@ void LDAPProtocol::put(const QUrl &_url, int, KIO::JobFlags flags)
ldif.endLdif();
}
do {
ret = ldif.nextItem();
qCDebug(KLDAP_LOG) << "nextitem: " << ret;
......@@ -633,10 +622,10 @@ 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() << endl;
qCDebug(KLDAP_LOG) << "kio_ldap_modrdn olddn:" << ldif.dn().toString()
<<" newRdn: " << ldif.newRdn()
<<" newSuperior: " << ldif.newSuperior()
<<" deloldrdn: " << ldif.delOldRdn() << endl;
ldaperr = mOp.rename_s(ldif.dn(), ldif.newRdn(),
ldif.newSuperior(), ldif.delOldRdn());
break;
......@@ -667,7 +656,8 @@ 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()) {
......@@ -701,7 +691,8 @@ 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);
......
......@@ -38,8 +38,7 @@ public:
LDAPProtocol(const QByteArray &protocol, const QByteArray &pool, const QByteArray &app);
~LDAPProtocol() override;
void setHost(const QString &host, quint16 port,
const QString &user, const QString &pass) override;
void setHost(const QString &host, quint16 port, const QString &user, const QString &pass) override;
void openConnection() override;
void closeConnection() override;
......@@ -57,10 +56,8 @@ private:
KLDAP::LdapServer mServer;
bool mConnected;
void controlsFromMetaData(KLDAP::LdapControls &serverctrls,
KLDAP::LdapControls &clientctrls);
void LDAPEntry2UDSEntry(const KLDAP::LdapDN &dn, KIO::UDSEntry &entry,
const KLDAP::LdapUrl &usrc, bool dir = false);
void controlsFromMetaData(KLDAP::LdapControls &serverctrls, KLDAP::LdapControls &clientctrls);
void LDAPEntry2UDSEntry(const KLDAP::LdapDN &dn, KIO::UDSEntry &entry, const KLDAP::LdapUrl &usrc, bool dir = false);
int asyncSearch(KLDAP::LdapUrl &usrc, const QByteArray &cookie = "");
void LDAPErr(int err = KLDAP_SUCCESS);
......
......@@ -77,7 +77,7 @@ Ber::Ber(const QByteArray &value)
: d(new BerPrivate)
{
struct berval bv;
bv.bv_val = (char *) value.data();
bv.bv_val = (char *)value.data();
bv.bv_len = value.size();
d->mBer = ber_init(&bv);
Q_ASSERT(d->mBer);
......@@ -138,45 +138,52 @@ 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': {
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();
bv.bv_val = (char *)O->data();
bv.bv_len = O->size();
ret = ber_printf(d->mBer, fmt, &bv);
break;
break;
}
break;
case 's': {
case 's':
{
QByteArray *s = va_arg(args, QByteArray *);
ret = ber_printf(d->mBer, fmt, s->data());
break;
break;
}
break;
case 't': {
case 't':
{
unsigned int t = va_arg(args, unsigned int);
ret = ber_printf(d->mBer, fmt, t);
break;
break;
}
break;
case 'v': {
case 'v':
{
QList<QByteArray> *v = va_arg(args, QList<QByteArray> *);
QVarLengthArray<const char *> l(v->count() + 1);
int j;
......@@ -187,13 +194,14 @@ 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());
int j;
for (j = 0; j < V->count(); j++) {
bvs[j].bv_val = (char *) V->at(j).data();
bvs[j].bv_val = (char *)V->at(j).data();
bvs[j].bv_len = V->at(j).size();
bv[j] = &bvs[j];
}
......@@ -236,12 +244,14 @@ 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': {
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 *);
......@@ -253,7 +263,8 @@ 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);
......@@ -263,7 +274,8 @@ 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);
......@@ -272,9 +284,10 @@ int Ber::scanf(QString format, ...)
ber_bvfree(bv);
}
break;
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,7 +296,8 @@ 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);
......@@ -294,7 +308,8 @@ 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);
......@@ -305,13 +320,15 @@ 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;
}
break;
case 'v': {
case 'v':
{
QList<QByteArray> *v = va_arg(args, QList<QByteArray> *);
char **c, **c2;
ret = ber_scanf(d->mBer, fmt, &c);
......@@ -322,11 +339,12 @@ int Ber::scanf(QString format, ...)
ber_memfree(*c);
c++;
}
ber_memfree((char *) c2);
ber_memfree((char *)c2);
}
break;
}
case 'V': {
case 'V':
{
QList<QByteArray> *v = va_arg(args, QList<QByteArray> *);
struct berval **bv, **bv2;
ret = ber_scanf(d->mBer, fmt, &bv);
......@@ -357,7 +375,6 @@ int Ber::scanf(QString format, ...)
if (ret == -1) {
break;
}
}
va_end(args);
return ret;
......@@ -380,6 +397,7 @@ unsigned int Ber::skipTag(int &size)
size = len;
return ret;
}
#else
Ber::Ber()
......
......@@ -27,9 +27,7 @@
// clazy:excludeall=copyable-polymorphic
namespace KLDAP
{
namespace KLDAP {
/**
* This class allows encoding and decoding Qt structures using Basic
* Encoding Rules.
......@@ -126,6 +124,5 @@ private:
class BerPrivate;
BerPrivate *const d;
};
}
#endif
......@@ -27,28 +27,23 @@
using namespace KLDAP;
LdapAttributeProxyModel::LdapAttributeProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
LdapAttributeProxyModel::~LdapAttributeProxyModel()
{
}
QVariant LdapAttributeProxyModel::data(const QModelIndex &index,
int role) const
QVariant LdapAttributeProxyModel::data(const QModelIndex &index, int role) const
{
// Included just in case we decide to do any special presentation of the data
// at some other point throughout the 4.x series.
return sourceModel()->data(mapToSource(index), role);
}
bool LdapAttributeProxyModel::setData(const QModelIndex &index,
const QVariant &value,
int role)
bool LdapAttributeProxyModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
Q_UNUSED(index);
Q_UNUSED(value);
......@@ -56,19 +51,16 @@ bool LdapAttributeProxyModel::setData(const QModelIndex &index,
return false;
}
bool LdapAttributeProxyModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const
bool LdapAttributeProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
LdapModelNode::NodeType nodeType =
static_cast<LdapModelNode::NodeType>(
sourceModel()->data(idx, LdapModel::NodeTypeRole).toUInt());
LdapModelNode::NodeType nodeType
= static_cast<LdapModelNode::NodeType>(
sourceModel()->data(idx, LdapModel::NodeTypeRole).toUInt());
return nodeType == LdapModelNode::Attr;
}
QVariant LdapAttributeProxyModel::headerData(int section,
Qt::Orientation orientation,
int role) const
QVariant LdapAttributeProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
if (section == 0) {
......@@ -81,7 +73,7 @@ QVariant LdapAttributeProxyModel::headerData(int section,
return QVariant();
}
int LdapAttributeProxyModel::columnCount(const QModelIndex &/*parent*/) const
int LdapAttributeProxyModel::columnCount(const QModelIndex & /*parent*/) const
{
return 2;
}
......@@ -110,8 +102,7 @@ QModelIndex LdapAttributeProxyModel::mapToSource(const QModelIndex &proxyIndex)
return QSortFilterProxyModel::mapToSource(proxyIndex);
}
bool LdapAttributeProxyModel::insertRows(int row, int count,
const QModelIndex &parent)
bool LdapAttributeProxyModel::insertRows(int row, int count, const QModelIndex &parent)
{
Q_UNUSED(row);
Q_UNUSED(count);
......@@ -119,8 +110,7 @@ bool LdapAttributeProxyModel::insertRows(int row, int count,
return false;
}
bool LdapAttributeProxyModel::removeRows(int row, int count,
const QModelIndex &parent)
bool LdapAttributeProxyModel::removeRows(int row, int count, const QModelIndex &parent)
{
Q_UNUSED(row);
Q_UNUSED(count);
......@@ -145,8 +135,7 @@ QMimeData *LdapAttributeProxyModel::mimeData(const QModelIndexList &indexes) con
return nullptr;
}
bool LdapAttributeProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent)
bool LdapAttributeProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
/** \todo Implement drag and drop for LdapModel */
Q_UNUSED(data);
......@@ -156,4 +145,3 @@ bool LdapAttributeProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction
Q_UNUSED(parent);
return false;
}
......@@ -25,9 +25,7 @@
#include "kldap_export.h"
namespace KLDAP
{
namespace KLDAP {
class KLDAP_EXPORT LdapAttributeProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
......@@ -40,9 +38,7 @@ public:
* Reimplemented from QAbstractItemModel::setData(). This is a placeholder for when
* LdapAttributeProxyModel beomes writeable and always returns false.
*/
Q_REQUIRED_RESULT bool setData(const QModelIndex &index,
const QVariant &value,
int role = Qt::EditRole) override;
Q_REQUIRED_RESULT bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
Q_REQUIRED_RESULT bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
Q_REQUIRED_RESULT QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
Q_REQUIRED_RESULT int columnCount(const QModelIndex &parent) const override;
......@@ -56,14 +52,12 @@ public:
* Reimplemented from QAbstractItemModel::insertRows(). This is a placeholder for when