Commit d9a74779 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Move ldap class from libkdepim here

parent 2277b0ff
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.14.40")
set(PIM_VERSION "5.14.41")
project(KLdap VERSION ${PIM_VERSION})
......@@ -21,12 +21,17 @@ include(ECMSetupVersion)
include(FeatureSummary)
include(ECMQtDeclareLoggingCategory)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(KLDAP_LIB_VERSION ${PIM_VERSION})
find_package(KF5KIO ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5I18n ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5DocTools ${KF5_MIN_VERSION} CONFIG)
find_package(KF5Wallet ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5KIO ${KF5_MIN_VERSION} CONFIG REQUIRED)
# tell what is missing without doctools
set_package_properties(KF5DocTools PROPERTIES DESCRIPTION "Provides tools to generate documentation in various format from DocBook files"
......@@ -94,6 +99,7 @@ add_subdirectory(src)
add_subdirectory(kioslave)
if(BUILD_TESTING)
add_subdirectory(autotests)
add_subdirectory(tests)
endif()
ecm_qt_install_logging_categories(
......
......@@ -30,25 +30,46 @@ configure_file(kldap_config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/kldap_config.h)
########### next target ###############
set(kldap_LIB_SRCS
ber.cpp
ldif.cpp
ldapurl.cpp
ldapserver.cpp
ldapobject.cpp
ldapconnection.cpp
ldapoperation.cpp
ldapcontrol.cpp
ldapsearch.cpp
ldapconfigwidget.cpp
ldapdn.cpp
set(kldap_LIB_core_SRCS
core/ber.cpp
core/ldif.cpp
core/ldapurl.cpp
core/ldapserver.cpp
core/ldapobject.cpp
core/ldapconnection.cpp
core/ldapoperation.cpp
core/ldapcontrol.cpp
core/ldapsearch.cpp
core/ldapdn.cpp
)
set(kldap_LIB_widgets_SRCS
widgets/ldapconfigwidget.cpp
widgets/addhostdialog.cpp
widgets/ldapclient.cpp
widgets/ldapclientsearch.cpp
widgets/ldapclientsearchconfig.cpp
widgets/ldapconfigurewidget.cpp
#widgets/ldapsearchdialog.cpp
)
set(kldap_LIB_SRCS
${kldap_LIB_core_SRCS}
${kldap_LIB_widgets_SRCS}
)
ecm_qt_declare_logging_category(kldap_LIB_SRCS HEADER ldap_debug.h IDENTIFIER LDAP_LOG CATEGORY_NAME org.kde.pim.ldap
DESCRIPTION "kldaplib (kldap)"
OLD_CATEGORY_NAMES log_ldap
EXPORT KLDAP
)
ecm_qt_declare_logging_category(kldap_LIB_SRCS HEADER ldapclient_debug.h IDENTIFIER LDAPCLIENT_LOG CATEGORY_NAME org.kde.pim.ldapclient
DESCRIPTION "ldapclient (libkdepim)"
OLD_CATEGORY_NAMES log_ldapclient
EXPORT KLDAP
)
add_library(KF5Ldap ${kldap_LIB_SRCS})
......@@ -62,11 +83,15 @@ PRIVATE
Qt5::Widgets
KF5::I18n
KF5::WidgetsAddons
KF5::ConfigCore
KF5::Wallet
KF5::CoreAddons
KF5::KIOWidgets
${kldap_EXTRA_LIBS}
)
target_include_directories(KF5Ldap INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF5}/KLDAP>")
target_include_directories(KF5Ldap PUBLIC "$<BUILD_INTERFACE:${KLdap_SOURCE_DIR}/src;${KLdap_BINARY_DIR}/src>")
target_include_directories(KF5Ldap PUBLIC "$<BUILD_INTERFACE:${KLdap_SOURCE_DIR}/src/core;${KLdap_BINARY_DIR}/src/core>")
set_target_properties(KF5Ldap PROPERTIES
VERSION ${KLDAP_VERSION_STRING}
......@@ -78,10 +103,9 @@ install(TARGETS KF5Ldap EXPORT KF5LdapTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS
########### install files ###############
ecm_generate_headers(KLdap_CamelCase_HEADERS
ecm_generate_headers(KLdapCore_CamelCase_HEADERS
HEADER_NAMES
Ber
LdapConfigWidget
LdapConnection
LdapControl
LdapDN
......@@ -92,19 +116,36 @@ ecm_generate_headers(KLdap_CamelCase_HEADERS
LdapDefs
LdapUrl
Ldif
RELATIVE core
PREFIX KLDAP
REQUIRED_HEADERS KLdapCore_HEADERS
)
ecm_generate_headers(KLdapWidgets_CamelCase_HEADERS
HEADER_NAMES
LdapConfigWidget
LdapClientSearchConfig
LdapClientSearch
AddHostDialog
LdapSearchDialog
LdapClient
LdapConfigureWidget
RELATIVE widgets
PREFIX KLDAP
REQUIRED_HEADERS KLdap_HEADERS
REQUIRED_HEADERS KLdapWidgets_HEADERS
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/kldap_export.h
${KLdap_HEADERS}
${KLdapCore_HEADERS}
${KLdapWidgets_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KLDAP/kldap
COMPONENT Devel
)
install(FILES
${KLdap_CamelCase_HEADERS}
${KLdapCore_CamelCase_HEADERS}
${KLdapWidgets_CamelCase_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KLDAP/KLDAP/
COMPONENT Devel
)
......
#! /bin/sh
$XGETTEXT *.cpp -o $podir/libkldap5.pot
$XGETTEXT core/*.cpp widgets/*.cpp -o $podir/libkldap5.pot
/*
This file is part of libkldap.
Copyright (c) 2002-2010 Tobias Koenig <tokoe@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "addhostdialog.h"
#include <QHBoxLayout>
#include <KSharedConfig>
#include <KAcceleratorManager>
#include <kldap/ldapserver.h>
#include <kldap/ldapconfigwidget.h>
#include <KLocalizedString>
#include <QDialogButtonBox>
#include <KConfigGroup>
#include <QPushButton>
#include <QVBoxLayout>
using namespace KLDAP;
class KLDAP::AddHostDialogPrivate
{
public:
AddHostDialogPrivate(AddHostDialog *qq)
: q(qq)
{
}
~AddHostDialogPrivate()
{
writeConfig();
}
void readConfig();
void writeConfig();
KLDAP::LdapConfigWidget *mCfg = nullptr;
KLDAP::LdapServer *mServer = nullptr;
QPushButton *mOkButton = nullptr;
AddHostDialog *q = nullptr;
};
void AddHostDialogPrivate::readConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), "AddHostDialog");
const QSize size = group.readEntry("Size", QSize(600, 400));
if (size.isValid()) {
q->resize(size);
}
}
void AddHostDialogPrivate::writeConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), "AddHostDialog");
group.writeEntry("Size", q->size());
group.sync();
}
AddHostDialog::AddHostDialog(KLDAP::LdapServer *server, QWidget *parent)
: QDialog(parent)
, d(new KLDAP::AddHostDialogPrivate(this))
{
setWindowTitle(i18nc("@title:window", "Add Host"));
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
d->mOkButton = buttonBox->button(QDialogButtonBox::Ok);
d->mOkButton->setDefault(true);
d->mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::rejected, this, &AddHostDialog::reject);
setModal(true);
d->mServer = server;
QWidget *page = new QWidget(this);
mainLayout->addWidget(page);
mainLayout->addWidget(buttonBox);
QHBoxLayout *layout = new QHBoxLayout(page);
layout->setContentsMargins(0, 0, 0, 0);
d->mCfg = new KLDAP::LdapConfigWidget(
KLDAP::LdapConfigWidget::W_USER
|KLDAP::LdapConfigWidget::W_PASS
|KLDAP::LdapConfigWidget::W_BINDDN
|KLDAP::LdapConfigWidget::W_REALM
|KLDAP::LdapConfigWidget::W_HOST
|KLDAP::LdapConfigWidget::W_PORT
|KLDAP::LdapConfigWidget::W_VER
|KLDAP::LdapConfigWidget::W_TIMELIMIT
|KLDAP::LdapConfigWidget::W_SIZELIMIT
|KLDAP::LdapConfigWidget::W_PAGESIZE
|KLDAP::LdapConfigWidget::W_DN
|KLDAP::LdapConfigWidget::W_FILTER
|KLDAP::LdapConfigWidget::W_SECBOX
|KLDAP::LdapConfigWidget::W_AUTHBOX,
page);
layout->addWidget(d->mCfg);
d->mCfg->setHost(d->mServer->host());
d->mCfg->setPort(d->mServer->port());
d->mCfg->setDn(d->mServer->baseDn());
d->mCfg->setUser(d->mServer->user());
d->mCfg->setBindDn(d->mServer->bindDn());
d->mCfg->setPassword(d->mServer->password());
d->mCfg->setTimeLimit(d->mServer->timeLimit());
d->mCfg->setSizeLimit(d->mServer->sizeLimit());
d->mCfg->setPageSize(d->mServer->pageSize());
d->mCfg->setVersion(d->mServer->version());
d->mCfg->setFilter(d->mServer->filter());
switch (d->mServer->security()) {
case KLDAP::LdapServer::TLS:
d->mCfg->setSecurity(KLDAP::LdapConfigWidget::TLS);
break;
case KLDAP::LdapServer::SSL:
d->mCfg->setSecurity(KLDAP::LdapConfigWidget::SSL);
break;
default:
d->mCfg->setSecurity(KLDAP::LdapConfigWidget::None);
}
switch (d->mServer->auth()) {
case KLDAP::LdapServer::Simple:
d->mCfg->setAuth(KLDAP::LdapConfigWidget::Simple);
break;
case KLDAP::LdapServer::SASL:
d->mCfg->setAuth(KLDAP::LdapConfigWidget::SASL);
break;
default:
d->mCfg->setAuth(KLDAP::LdapConfigWidget::Anonymous);
}
d->mCfg->setMech(d->mServer->mech());
KAcceleratorManager::manage(this);
connect(d->mCfg, &KLDAP::LdapConfigWidget::hostNameChanged, this, &AddHostDialog::slotHostEditChanged);
connect(d->mOkButton, &QPushButton::clicked, this, &AddHostDialog::slotOk);
d->mOkButton->setEnabled(!d->mServer->host().isEmpty());
d->readConfig();
}
AddHostDialog::~AddHostDialog()
{
delete d;
}
void AddHostDialog::slotHostEditChanged(const QString &text)
{
d->mOkButton->setEnabled(!text.isEmpty());
}
void AddHostDialog::slotOk()
{
d->mServer->setHost(d->mCfg->host());
d->mServer->setPort(d->mCfg->port());
d->mServer->setBaseDn(d->mCfg->dn());
d->mServer->setUser(d->mCfg->user());
d->mServer->setBindDn(d->mCfg->bindDn());
d->mServer->setPassword(d->mCfg->password());
d->mServer->setTimeLimit(d->mCfg->timeLimit());
d->mServer->setSizeLimit(d->mCfg->sizeLimit());
d->mServer->setPageSize(d->mCfg->pageSize());
d->mServer->setVersion(d->mCfg->version());
d->mServer->setFilter(d->mCfg->filter());
switch (d->mCfg->security()) {
case KLDAP::LdapConfigWidget::TLS:
d->mServer->setSecurity(KLDAP::LdapServer::TLS);
break;
case KLDAP::LdapConfigWidget::SSL:
d->mServer->setSecurity(KLDAP::LdapServer::SSL);
break;
default:
d->mServer->setSecurity(KLDAP::LdapServer::None);
}
switch (d->mCfg->auth()) {
case KLDAP::LdapConfigWidget::Simple:
d->mServer->setAuth(KLDAP::LdapServer::Simple);
break;
case KLDAP::LdapConfigWidget::SASL:
d->mServer->setAuth(KLDAP::LdapServer::SASL);
break;
default:
d->mServer->setAuth(KLDAP::LdapServer::Anonymous);
}
d->mServer->setMech(d->mCfg->mech());
QDialog::accept();
}
#include "moc_addhostdialog.cpp"
/*
This file is part of libkldap.
Copyright (c) 2002-2010 Tobias Koenig <tokoe@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef ADDHOSTDIALOG_H
#define ADDHOSTDIALOG_H
#include "kldap_export.h"
#include <QDialog>
namespace KLDAP {
class LdapServer;
class AddHostDialogPrivate;
/**
* @brief The AddHostDialog class
* @author Laurent Montel <montel@kde.org>
*/
class KLDAP_EXPORT AddHostDialog : public QDialog
{
Q_OBJECT
public:
explicit AddHostDialog(KLDAP::LdapServer *server, QWidget *parent = nullptr);
~AddHostDialog();
Q_SIGNALS:
void changed(bool);
private Q_SLOTS:
void slotHostEditChanged(const QString &);
void slotOk();
private:
AddHostDialogPrivate *const d;
};
}
#endif // ADDHOSTDIALOG_H
/* kldapclient.cpp - LDAP access
* Copyright (C) 2002 Klarälvdalens Datakonsult AB
*
* Author: Steffen Hansen <hansen@kde.org>
*
* Ported to KABC by Daniel Molkentin <molkentin@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "ldapclient.h"
#include "ldapclient_debug.h"
#include <kldap/ldapobject.h>
#include <kldap/ldapserver.h>
#include <kldap/ldapurl.h>
#include <kldap/ldif.h>
#include <kio/job.h>
#include <QPointer>
using namespace KLDAP;
class Q_DECL_HIDDEN LdapClient::Private
{
public:
Private(LdapClient *qq)
: q(qq)
{
}
~Private()
{
q->cancelQuery();
}
void startParseLDIF();
void parseLDIF(const QByteArray &data);
void endParseLDIF();
void finishCurrentObject();
void slotData(KIO::Job *, const QByteArray &data);
void slotInfoMessage(KJob *, const QString &info, const QString &);
void slotDone();
LdapClient *q = nullptr;
KLDAP::LdapServer mServer;
QString mScope;
QStringList mAttrs;
QPointer<KJob> mJob = nullptr;
bool mActive = false;
KLDAP::LdapObject mCurrentObject;
KLDAP::Ldif mLdif;
int mClientNumber = 0;
int mCompletionWeight = 0;
};
LdapClient::LdapClient(int clientNumber, QObject *parent)
: QObject(parent)
, d(new Private(this))
{
d->mClientNumber = clientNumber;
d->mCompletionWeight = 50 - d->mClientNumber;
}
LdapClient::~LdapClient()
{
delete d;
}
bool LdapClient::isActive() const
{
return d->mActive;
}
void LdapClient::setServer(const KLDAP::LdapServer &server)
{
d->mServer = server;
}
const KLDAP::LdapServer LdapClient::server() const
{
return d->mServer;
}
void LdapClient::setAttributes(const QStringList &attrs)
{
d->mAttrs = attrs;
d->mAttrs << QStringLiteral("objectClass"); // via objectClass we detect distribution lists
}
QStringList LdapClient::attributes() const
{
return d->mAttrs;
}
void LdapClient::setScope(const QString &scope)
{
d->mScope = scope;
}
void LdapClient::startQuery(const QString &filter)
{
cancelQuery();
KLDAP::LdapUrl url;
url = d->mServer.url();
url.setAttributes(d->mAttrs);
url.setScope(d->mScope == QLatin1String("one") ? KLDAP::LdapUrl::One : KLDAP::LdapUrl::Sub);
const QString userFilter = url.filter();
QString finalFilter = filter;
// combine the filter set by the user in the config dialog (url.filter()) and the filter from this query
if (!userFilter.isEmpty()) {
finalFilter = QLatin1String("&(") + finalFilter + QLatin1String(")(") + userFilter + QLatin1Char(')');
}
url.setFilter(QLatin1Char('(') + finalFilter + QLatin1Char(')'));
qCDebug(LDAPCLIENT_LOG) << "LdapClient: Doing query:" << url.toDisplayString();
d->startParseLDIF();
d->mActive = true;
KIO::TransferJob *transfertJob = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo);
d->mJob = transfertJob;
connect(transfertJob, &KIO::TransferJob::data, this, [this](KIO::Job *job, const QByteArray &data) {
d->slotData(job, data);
});
connect(d->mJob.data(), &KIO::TransferJob::infoMessage, this,
[this](KJob *job, const QString &str, const QString &val) {
d->slotInfoMessage(job, str, val);
});
connect(d->mJob.data(), &KIO::TransferJob::result,
this, [this]() {