plugin wip

This commit is contained in:
Tim Blume 2021-01-09 11:17:50 +01:00
parent 44709f0498
commit 4d020014c0
7 changed files with 80 additions and 15 deletions

View file

@ -30,6 +30,7 @@ add_executable(bigsnitch
networkthread.cpp
session.cpp
httpflow.cpp
pluginhandler.cpp
proxyhandler.cpp
historymodel.cpp
editandresend.cpp
@ -41,6 +42,7 @@ add_executable(bigsnitch
session.h
includes.h
proxyhandler.h
pluginhandler.h
historymodel.h
editandresend.h
settings.h

View file

@ -1,6 +1,6 @@
#pragma once
#include "include/api.h"
#include "api.h"
#include <QObject>
namespace http {
@ -11,8 +11,8 @@ namespace http {
/*!
Interface for implementing proxies
*/
class ProxyInterface {
class ProxyInterface : public QObject {
Q_OBJECT
public:
virtual ~ProxyInterface() = default;
//! called in a custom thread, may block.
@ -23,9 +23,9 @@ public:
virtual void disconnect() = 0;
// options/settings
signals:
void finished();
void error(QString err);
void message(http::Flow flow);
virtual void finished();
virtual void error(QString err);
virtual void message(http::Flow flow);
};
}

28
pluginhandler.cpp Normal file
View file

@ -0,0 +1,28 @@
#include "pluginhandler.h"
/*
const auto staticInstances = QPluginLoader::staticInstances();
for (QObject *plugin : staticInstances)
populateMenus(plugin);
*/
bool PluginHandler::load(QString path)
{
QPluginLoader loader(path);
QObject *plugin = loader.instance();
if (plugin) {
proxyhandler.loadPlugin(plugin);
loaded_plugins += path;
return true;
}
return false;
}
void PluginHandler::loadPlugins(QDir path)
{
const auto entryList = path.entryList(QDir::Files);
for (const QString &fileName : entryList) {
load(path.absoluteFilePath(fileName));
}
}

18
pluginhandler.h Normal file
View file

@ -0,0 +1,18 @@
#pragma once
#include <include/api.h>
#include <include/proxyinterface.h>
#include <QObject>
#include <QDir>
#include <QPluginLoader>
#include <proxyhandler.h>
class PluginHandler
{
private:
QStringList loaded_plugins;
ProxyHandler proxyhandler;
public:
bool load(QString path);
void loadPlugins(QDir path);
};

View file

@ -1,6 +1,15 @@
#pragma once
#include "api.h"
#include "proxyinterface.h"
#include <QObject>
class mitmproxyPlugin : public QObject,
public http::ProxyInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "bigsnitch.api.HTTPProxyInterface/100" FILE "mitmproxy.json")
Q_INTERFACES(http::ProxyInterface)
public:
};

View file

@ -1,11 +1,14 @@
#include "proxyhandler.h"
bool PluginHandler::load(std::string path)
{
}
void PluginHandler::loadPlugins(std::string path)
bool http::ProxyHandler::loadPlugin(QObject *proxy)
{
auto inst = qobject_cast<ProxyInterface*>(proxy);
if(!inst) {
return false;
}
return true;
}

View file

@ -2,10 +2,15 @@
#include <include/api.h>
#include <include/proxyinterface.h>
#include <QObject>
class PluginHandler
namespace http {
class ProxyHandler
{
private:
public:
bool load(std::string path);
void loadPlugins(std::string path);
bool loadPlugin(QObject *proxy);
};
}