Skip to content

Commit

Permalink
Add a config option to choose default find path of SIP003 plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
OceanS2000 committed Jul 22, 2021
1 parent b8a497e commit 2f5acbd
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*.user
build/
/cmake-build-debug
/cmake-build-*
/.idea
/compile_commands.json

23 changes: 13 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ add_library(${PROJECT_NAME} MODULE
ui/SSOutboundEditor.cpp
ui/SSOutboundEditor.hpp
ui/SSOutboundEditor.ui
ui/SSSettingsWidget.ui
ui/SSSettingsWidget.cpp
ui/SSSettingsWidget.hpp
ui/GUIInterface.hpp
resx.qrc
${QVPLUGIN_INTERFACE_HEADERS}
Expand All @@ -64,15 +67,15 @@ target_link_libraries(${PROJECT_NAME}
install(TARGETS ${PROJECT_NAME} DESTINATION share/qv2ray/plugins)
if(BUILD_TESTING)
add_executable(testparsess test/TestParseSS.cpp test/catch.hpp
common/CommonHelpers.cpp
common/CommonHelpers.hpp
core/Serializer.cpp
core/Serializer.hpp
${QVPLUGIN_INTERFACE_HEADERS})
target_link_libraries(testparsess
${QV_QT_LIBNAME}::Core
${QV_QT_LIBNAME}::Gui
${QV_QT_LIBNAME}::Widgets
${QV_QT_LIBNAME}::Network)
common/CommonHelpers.cpp
common/CommonHelpers.hpp
core/Serializer.cpp
core/Serializer.hpp
${QVPLUGIN_INTERFACE_HEADERS})
target_link_libraries(testparsess
${QV_QT_LIBNAME}::Core
${QV_QT_LIBNAME}::Gui
${QV_QT_LIBNAME}::Widgets
${QV_QT_LIBNAME}::Network)
add_test(NAME testparsess COMMAND $<TARGET_FILE:testparsess>)
endif()
3 changes: 2 additions & 1 deletion SSPlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "SSPlugin.hpp"

#include "core/Serializer.hpp"
#include "core/kernel/SSInstance.hpp"
#include "ui/GUIInterface.hpp"

#include <QDateTime>
Expand All @@ -14,6 +15,6 @@ bool QvSSPlugin::InitializePlugin(const QString &, const QJsonObject &_settings)
eventHandler = std::make_shared<SSPluginEventHandler>();
outboundHandler = std::make_shared<SSSerializer>();
guiInterface = new ShadowsocksPluginGUIInterface();
kernelInterface = std::make_shared<SSKernelInterface>();
kernelInterface = std::make_shared<SSKernelInterface>(this);
return true;
}
4 changes: 1 addition & 3 deletions SSPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
#include "QvPluginInterface.hpp"
#include "core/EventHandler.hpp"
#include "core/Serializer.hpp"
#include "core/kernel/SSInstance.hpp"

#include <QObject>
#include <QtPlugin>

class QLabel;
using namespace Qv2rayPlugin;
class QvSSPlugin
: public QObject
, Qv2rayInterface
: public QObject, public Qv2rayInterface
{
Q_INTERFACES(Qv2rayPlugin::Qv2rayInterface)
Q_PLUGIN_METADATA(IID Qv2rayInterface_IID)
Expand Down
15 changes: 12 additions & 3 deletions common/CommonHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ struct ShadowSocksServerObject
QString remarks; // Unused
QString group; // Unused
int port;
ShadowSocksServerObject()
{

ShadowSocksServerObject() {
method = "chacha20-ietf-poly1305";
address = "0.0.0.0";
port = 0;
}
JSONSTRUCT_REGISTER(ShadowSocksServerObject, F(address, method, password, plugin, plugin_options, key, remarks, group, port))

JSONSTRUCT_REGISTER(ShadowSocksServerObject,
F(address, method, password, plugin, plugin_options, key, remarks, group, port))
};

struct SSPluginSettingObject {
QString default_plugin_prefix;

JSONSTRUCT_REGISTER(SSPluginSettingObject, F(default_plugin_prefix))
};

QString SafeBase64Decode(QString string);

QString SafeBase64Encode(const QString &string, bool trim = true);
18 changes: 12 additions & 6 deletions core/kernel/SSInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
#include "SSInstance.hpp"
#include "common/CommonHelpers.hpp"

#include <QDir>
#include <QJsonArray>
#include <QJsonObject>
#include <memory>

SSKernelInstance::SSKernelInstance(QObject *) : PluginKernel()
{
}

void SSKernelInstance::SetConnectionSettings(const QMap<KernelOptionFlags, QVariant> &options, const QJsonObject &settings)
{
this->listen_address = options[KERNEL_LISTEN_ADDRESS].toString();
Expand All @@ -35,17 +32,26 @@ bool SSKernelInstance::StartKernel()
auto method = outbound.method.toStdString();
auto password = outbound.password.toStdString();
auto key = outbound.key.toStdString();
auto plugin = outbound.plugin.toStdString();
auto plugin = outbound.plugin;
auto plugin_opts = outbound.plugin_options.toStdString();
auto plugin_default_prefix = parent->GetSettngs().value("default_plugin_prefix").toString();
std::string plugin_final_path;
auto mode = static_cast<SSThread::SSR_WORK_MODE>(enable_udp);

if (plugin[0] != '/') {
plugin_final_path = QDir(plugin_default_prefix).filePath(plugin).toStdString();
} else {
plugin_final_path = plugin.toStdString();
}

ssrThread = std::make_unique<SSThread>(socks_local_port, //
remotePort, //
60000, 1500, mode, //
listen_address.toStdString(), //
remote_host, //
method, //
password, //
plugin, //
plugin_final_path, //
plugin_opts, key);
ssrThread->connect(ssrThread.get(), &SSThread::onSSRThreadLog, this, &SSKernelInstance::OnKernelLogAvailable);
ssrThread->connect(ssrThread.get(), &SSThread::OnDataReady, this, &SSKernelInstance::OnKernelStatsAvailable);
Expand Down
24 changes: 15 additions & 9 deletions core/kernel/SSInstance.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "3rdparty/shadowsocks-uvw/src/SSThread.hpp"
#include "QvPluginProcessor.hpp"
#include "SSPlugin.hpp"
#include "common/CommonHelpers.hpp"
#include "utils/HttpProxy.hpp"

Expand All @@ -9,7 +10,7 @@ using namespace Qv2rayPlugin;
class SSKernelInstance : public PluginKernel
{
public:
explicit SSKernelInstance(QObject *parent = nullptr);
explicit SSKernelInstance(QvSSPlugin *_parent) : parent(_parent) {}
bool StartKernel() override;
bool StopKernel() override;
void SetConnectionSettings(const QMap<KernelOptionFlags, QVariant> &options, const QJsonObject &settings) override;
Expand All @@ -26,16 +27,21 @@ class SSKernelInstance : public PluginKernel
ShadowSocksServerObject outbound;
std::unique_ptr<Qv2rayPlugin::Utils::HttpProxy> httpProxy;
std::unique_ptr<SSThread> ssrThread;
QvSSPlugin *parent;
};

class SSKernelInterface : public PluginKernelInterface
{
std::unique_ptr<PluginKernel> CreateKernel() const
{
return std::make_unique<SSKernelInstance>();
class SSKernelInterface : public PluginKernelInterface {
public:
explicit SSKernelInterface(QvSSPlugin *_parent) : parent(_parent) {}

std::unique_ptr<PluginKernel> CreateKernel() const final {
return std::make_unique<SSKernelInstance>(parent);
}
QList<QString> GetKernelProtocols() const
{
return { "shadowsocks-sip003" };

QList<QString> GetKernelProtocols() const final {
return {"shadowsocks-sip003"};
}

private:
QvSSPlugin *parent;
};
5 changes: 3 additions & 2 deletions ui/GUIInterface.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "QvGUIPluginInterface.hpp"
#include "SSOutboundEditor.hpp"
#include "SSSettingsWidget.hpp"

using namespace Qv2rayPlugin;

Expand All @@ -11,11 +12,11 @@ class ShadowsocksPluginGUIInterface : public Qv2rayPlugin::PluginGUIInterface
}
QList<PluginGuiComponentType> GetComponents() const
{
return { GUI_COMPONENT_OUTBOUND_EDITOR };
return {GUI_COMPONENT_OUTBOUND_EDITOR, GUI_COMPONENT_SETTINGS};
}
std::unique_ptr<QvPluginSettingsWidget> createSettingsWidgets() const
{
return {};
return std::make_unique<SSSettingsWidget>();
}
QList<typed_plugin_editor> createInboundEditors() const
{
Expand Down
25 changes: 25 additions & 0 deletions ui/SSSettingsWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "SSSettingsWidget.hpp"
#include <QFileDialog>

void SSSettingsWidget::SetSettings(const QJsonObject &content) {
setting.loadJson(content);

pfxPathEdit->setText(setting.default_plugin_prefix);
}

QJsonObject SSSettingsWidget::GetSettings() {
return setting.toJson();
}

void SSSettingsWidget::on_pfxPathPushButton_clicked() {
auto filename = QFileDialog::getExistingDirectory(this, tr("Default Plugin Path"), {});

if (!filename.isEmpty()) {
setting.default_plugin_prefix = filename;
pfxPathEdit->setText(filename);
}
}

void SSSettingsWidget::on_pfxPathEdit_textEdited(const QString &arg1) {
setting.default_plugin_prefix = arg1;
}
31 changes: 31 additions & 0 deletions ui/SSSettingsWidget.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef SSSETTINGSWIDGET_HPP
#define SSSETTINGSWIDGET_HPP

#include "QvGUIPluginInterface.hpp"
#include "common/CommonHelpers.hpp"
#include "ui_SSSettingsWidget.h"

class SSSettingsWidget
: public Qv2rayPlugin::QvPluginSettingsWidget, private Ui::SSSettingsWidget {
Q_OBJECT

public:
explicit SSSettingsWidget(QWidget *parent = nullptr) : QvPluginSettingsWidget(parent) {
setupUi(this);
}

void SetSettings(const QJsonObject &content) override;

QJsonObject GetSettings() override;

private slots:

void on_pfxPathPushButton_clicked();

void on_pfxPathEdit_textEdited(const QString &arg1);

private:
SSPluginSettingObject setting;
};

#endif // SSSETTINGSWIDGET_HPP
48 changes: 48 additions & 0 deletions ui/SSSettingsWidget.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SSSettingsWidget</class>
<widget class="QWidget" name="SSSettingsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>361</width>
<height>82</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Default Prefix for Plugins</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="pfxPathEdit"/>
</item>
<item>
<widget class="QPushButton" name="pfxPathPushButton">
<property name="text">
<string>选择Plugin默认路径</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit 2f5acbd

Please sign in to comment.