Browse Source

The agent should really be an agent

master
David Lanzendörfer 6 months ago
parent
commit
56ecc89dc0
6 changed files with 120 additions and 68 deletions
  1. +2
    -2
      akonadi_pep_agent/CMakeLists.txt
  2. +42
    -30
      akonadi_pep_agent/pepagent.cpp
  3. +3
    -3
      akonadi_pep_agent/pepagent.desktop
  4. +32
    -27
      akonadi_pep_agent/pepagent.h
  5. +29
    -5
      akonadi_pep_agent/syncthread.cpp
  6. +12
    -1
      akonadi_pep_agent/syncthread.h

+ 2
- 2
akonadi_pep_agent/CMakeLists.txt View File

@ -56,10 +56,10 @@ target_link_libraries(akonadi_pep_agent
set_property(TARGET akonadi_pep_agent PROPERTY CXX_STANDARD 17)
configure_file(pepagent.service.in ${CMAKE_CURRENT_BINARY_DIR}/pepagent.service)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pepagent.service
DESTINATION ${KDE_INSTALL_DBUSSERVICEDIR})
install( TARGETS akonadi_pep_agent ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} )
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/pepagent.service DESTINATION ${KDE_INSTALL_DBUSSERVICEDIR})
install( FILES pepagent.desktop DESTINATION "${KDE_INSTALL_DATAROOTDIR}/akonadi/agents" )
install( FILES akonadi_pep_agent.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFY5RCDIR} )
install( FILES "pep-mimeinfo.xml" DESTINATION "${KDE_INSTALL_DATAROOTDIR}/mime/packages" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT "pep")

+ 42
- 30
akonadi_pep_agent/pepagent.cpp View File

@ -11,33 +11,29 @@
using namespace Akonadi;
PEP_STATUS pEpAgent::messageToSend(::message* msg)
/*PEP_STATUS pEpAgent::messageToSend(::message* msg)
{
qDebug() << "pEp wants to send a message";
return PEP_STATUS_OK;
}
}*/
pEpAgent::pEpAgent(const QString &id)
: ResourceBase(id)
: AgentBase(id)
{
Q_D(pEpAgent);
PEP_STATUS status;
QDBusConnection dbus = QDBusConnection::sessionBus();
const QString service = Akonadi::ServerManager::self()->agentServiceName(Akonadi::ServerManager::Agent, QStringLiteral("pEpAgent"));
/* -------------- Starting the pEp Engine ------------------- */
status = ::init(&m_session, NULL, NULL, NULL);
/* --------------------- Done ------------------------------- */
/* ------------- Extending DBus functions ------------------- */
m_pEpadaptor = new PepAdaptor(this);
m_pEpAdaptor = new PepAdaptor(this);
dbus.registerObject(QStringLiteral("/security/pep"), QStringLiteral("security.pep"), this);
dbus.registerService(service);
/* --------------------- Done ------------------------------- */
// pEp management
m_syncThread = new pEpSyncThread(this);
m_syncThread->start();
// This here is just bureaucracy:
auto *collectionMonitor = new Akonadi::Monitor(this);
@ -262,40 +258,44 @@ void pEpAgent::configure(WId windowId)
qDebug() << __FUNCTION__ << "Test";
}
void pEpAgent::retrieveCollections()
void pEpAgent::sendItem(const Akonadi::Item &item)
{
qDebug() << "pEp send";
}
void pEpAgent::itemSent(const Akonadi::Item &item, Akonadi::TransportResourceBase::TransportResult result, const QString &message)
{
// TODO: Put information here, like person table content and so:
Akonadi::Collection::List collections;
Akonadi::Collection topLevel;
topLevel.setName(identifier());
topLevel.setRemoteId(identifier());
topLevel.setParentCollection(Akonadi::Collection::root());
topLevel.setContentMimeTypes({Akonadi::Collection::mimeType()});
topLevel.setRights(Akonadi::Collection::ReadOnly);
auto topLevelDisplayAttr = topLevel.attribute<Akonadi::EntityDisplayAttribute>(Akonadi::Collection::AddIfMissing);
topLevelDisplayAttr->setDisplayName(i18n("p≡p Engine"));
topLevelDisplayAttr->setActiveIconName(QStringLiteral("akonadi-pep"));
collections.push_back(topLevel);
collectionsRetrieved(std::move(collections));
}
int pEpAgent::encrypt_message(const QString &src, const QStringList &extra, QString &dst, int &enc_format, int &flags)
{
return 0;
}
int pEpAgent::decrypt_message(const QString &src, QString &dst, QStringList &keylist, int &flags)
{
qDebug() << "pEpAgent: Decrypting";
char *ms = src.toLatin1().data();
::message *m = NULL;
bool might_be_pep = true;
char *ms;
::message *m = new_message(PEP_dir_incoming);
::message *md = new_message(PEP_dir_incoming);
stringlist_t *kl = new_stringlist("");
PEP_decrypt_flags_t fl = 0;
bool might_be_pep = true;
::mime_decode_message( ms, src.toLatin1().size(), &m, &might_be_pep );
::decrypt_message(m_session, m, &md, &kl, &fl);
qDebug() << "pEpAgent: Decrypting src: " << src;
::mime_decode_message(src.toLatin1().data(), src.toLatin1().size(), &m, &might_be_pep);
::decrypt_message_2(pEp::Adapter::session(), m, &md, &kl, &fl);
if(md) {
::mime_encode_message(md, true, &ms, true);
}
qDebug() << "pEpAgent: Decrypted: " << ms;
flags = fl;
dst = QLatin1String(ms);
qDebug() << "pEpAgent: Decrypting dst: " << dst;
keylist.clear();
while(kl) {
keylist << QLatin1String(kl->value);
@ -305,6 +305,18 @@ int pEpAgent::decrypt_message(const QString &src, QString &dst, QStringList &key
return 0;
}
AKONADI_RESOURCE_MAIN(pEpAgent)
int pEpAgent::decrypt_and_verify(const QString &ctext,
int csize,
const QString &dsigtext,
int dsize,
QString &ptext,
int &psize,
QStringList &keylist,
QString &filename)
{
return 0;
}
AKONADI_AGENT_MAIN(pEpAgent)
#include "moc_pepagent.cpp"

+ 3
- 3
akonadi_pep_agent/pepagent.desktop View File

@ -1,10 +1,10 @@
[Desktop Entry]
Name=p≡p engine agent
Comment=Akonadi adapter to the p≡p engine
Type=AkonadiResource
Type=AkonadiAgent
Exec=akonadi_pep_agent
Icon=akonadi-pep
X-Akonadi-MimeTypes=message/rfc822
X-Akonadi-Capabilities=Resource,Unique,Autostart
X-Akonadi-MimeTypes=message/rfc822,text/pep,application/pep.sync,application/pep.sign
X-Akonadi-Capabilities=Agent,Unique,Autostart
X-Akonadi-Identifier=akonadi_pep_agent

+ 32
- 27
akonadi_pep_agent/pepagent.h View File

@ -1,31 +1,31 @@
#ifndef PEP_RESOURCE_H
#define PEP_RESOURCE_H
#include <ResourceBase>
#include <Akonadi/AgentInstance>
#include <Akonadi/AgentManager>
#include <Akonadi/AttributeFactory>
#include <Akonadi/ChangeRecorder>
#include <Akonadi/CollectionFetchJob>
#include <Akonadi/CollectionFetchScope>
#include <Akonadi/EntityDisplayAttribute>
#include <Akonadi/ItemFetchJob>
#include <Akonadi/ItemFetchScope>
#include <Akonadi/Monitor>
#include <Akonadi/PartFetcher>
#include <Akonadi/ResourceBase>
#include <Akonadi/ServerManager>
#include <Akonadi/Session>
#include <Akonadi/TransportResourceBase>
#include <KMime/Message>
#include <KJob>
#include <AkonadiCore/AgentInstance>
#include <Akonadi/KMime/Pop3ResourceAttribute>
#include <AkonadiCore/ServerManager>
#include <AkonadiCore/CollectionFetchJob>
#include <AkonadiCore/CollectionFetchScope>
#include <AkonadiCore/AgentManager>
#include <AkonadiCore/AttributeFactory>
#include <AkonadiCore/Monitor>
#include <AkonadiCore/Session>
#include <AkonadiCore/ItemFetchScope>
#include <AkonadiCore/ChangeRecorder>
#include <AkonadiAgentBase/ResourceBase>
#include <AkonadiCore/EntityDisplayAttribute>
#include <AkonadiCore/ItemFetchJob>
#include <AkonadiCore/PartFetcher>
#include <Akonadi/KMime/MessageParts>
#include <MailCommon/MailKernel>
#include <MailCommon/SearchRule>
#include <KI18n/KLocalizedString>
#include <KJob>
#include <GrantleeTheme/GrantleeKi18nLocalizer>
@ -44,9 +44,7 @@
class PepAdaptor;
class pEpAgent :
public Akonadi::ResourceBase,
public Akonadi::AgentBase::ObserverV3
class pEpAgent : public Akonadi::AgentBase, public Akonadi::AgentBase::ObserverV3
{
Q_OBJECT
@ -59,9 +57,8 @@ public:
~pEpAgent() = default;
protected Q_SLOTS:
void retrieveCollections() override;
void retrieveItems(const Akonadi::Collection &col) override {};
void sendItem(const Akonadi::Item &item);
void itemSent(const Akonadi::Item &item, Akonadi::TransportResourceBase::TransportResult result, const QString &message = QString());
protected:
void itemsReceiviedForFiltering(const Akonadi::Item::List &items);
@ -78,8 +75,19 @@ private Q_SLOTS:
void slotInstanceRemoved(const Akonadi::AgentInstance &instance);
void slotItemChanged(const Akonadi::Item &item);
// void messageToSend(::message* msg);
public Q_SLOTS: // pEp methods
int decrypt_message(const QString &src, QString &dst, QStringList &keylist, int &flags);
int decrypt_and_verify(const QString &ctext,
int csize,
const QString &dsigtext,
int dsize,
QString &ptext,
int &psize,
QStringList &keylist,
QString &filename);
int encrypt_message(const QString &src, const QStringList &extra, QString &dst, int &enc_format, int &flags);
private:
Q_DECLARE_PRIVATE(pEpAgent)
@ -100,12 +108,9 @@ private:
bool isFilterableCollection(const Akonadi::Collection &collection) const;
QTimer *mProgressTimer;
PepAdaptor *m_pEpadaptor;
QDBusInterface *m_pEpEngine;
PepAdaptor *m_pEpAdaptor;
int mProgressCounter;
PEP_SESSION m_session;
static PEP_STATUS messageToSend(::message* msg);
inject_sync_event_t inject_sync_event = nullptr;
};


+ 29
- 5
akonadi_pep_agent/syncthread.cpp View File

@ -1,24 +1,47 @@
#include "syncthread.h"
/*notifyHandshake_t notifyHandshake()
#include <kde_pep_common/pephelpers.h>
#include <QDebug>
pEpSyncThread *pEpSyncThread::hackinstance = nullptr;
void pEpSyncThread::slotMessageToSend(message *msg)
{
return 1;
}
retrieve_next_sync_event_t retrieve_next_sync_event()
void pEpSyncThread::slotNotifyHandshake(_pEp_identity *, _pEp_identity *, _sync_handshake_signal)
{
return 1;
}*/
}
PEP_STATUS pEpSyncThread::messageToSend(message *msg)
{
if (pEpSyncThread::hackinstance) {
pEpSyncThread::hackinstance->slotMessageToSend(msg);
}
return PEP_STATUS_OK;
}
PEP_STATUS pEpSyncThread::notifyHandshake(_pEp_identity *id1, _pEp_identity *id2, _sync_handshake_signal sig)
{
if (pEpSyncThread::hackinstance) {
pEpSyncThread::hackinstance->slotNotifyHandshake(id1, id2, sig);
}
return PEP_STATUS_OK;
}
pEpSyncThread::pEpSyncThread(QObject *parent)
: QThread(parent)
{
hackinstance = this;
pEp::Adapter::session.initialize(pEp::Adapter::SyncModes::Sync, true, messageToSend, notifyHandshake);
// pEp::Adapter::session.initialize();
}
pEpSyncThread::~pEpSyncThread()
{
mutex.lock();
pEp::Adapter::session.release();
mutex.unlock();
wait();
}
@ -26,5 +49,6 @@ pEpSyncThread::~pEpSyncThread()
void pEpSyncThread::run()
{
mutex.lock();
pEp::Adapter::start_sync();
mutex.unlock();
}

+ 12
- 1
akonadi_pep_agent/syncthread.h View File

@ -4,6 +4,8 @@
#include <QThread>
#include <QMutex>
#include <pEp/Adapter.hh>
class pEpSyncThread : public QThread
{
Q_OBJECT
@ -12,12 +14,21 @@ public:
pEpSyncThread(QObject *parent = nullptr);
~pEpSyncThread();
public Q_SLOTS:
void slotMessageToSend(message *msg);
void slotNotifyHandshake(_pEp_identity *, _pEp_identity *, _sync_handshake_signal);
Q_SIGNALS:
void signalMessageToSend(message *msg);
protected:
void run() override;
private:
QMutex mutex;
static pEpSyncThread *hackinstance;
static PEP_STATUS messageToSend(message *msg);
static PEP_STATUS notifyHandshake(_pEp_identity *, _pEp_identity *, _sync_handshake_signal);
};
#endif

Loading…
Cancel
Save