mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-16 20:17:07 +03:00
bug fix
This commit is contained in:
147
.clang-tidy
Normal file
147
.clang-tidy
Normal file
@@ -0,0 +1,147 @@
|
||||
# Generated from CLion Inspection settings
|
||||
---
|
||||
Checks: '-*,
|
||||
bugprone-argument-comment,
|
||||
bugprone-assert-side-effect,
|
||||
bugprone-bad-signal-to-kill-thread,
|
||||
bugprone-branch-clone,
|
||||
bugprone-copy-constructor-init,
|
||||
bugprone-dangling-handle,
|
||||
bugprone-dynamic-static-initializers,
|
||||
bugprone-fold-init-type,
|
||||
bugprone-forward-declaration-namespace,
|
||||
bugprone-forwarding-reference-overload,
|
||||
bugprone-inaccurate-erase,
|
||||
bugprone-incorrect-roundings,
|
||||
bugprone-integer-division,
|
||||
bugprone-lambda-function-name,
|
||||
bugprone-macro-parentheses,
|
||||
bugprone-macro-repeated-side-effects,
|
||||
bugprone-misplaced-operator-in-strlen-in-alloc,
|
||||
bugprone-misplaced-pointer-arithmetic-in-alloc,
|
||||
bugprone-misplaced-widening-cast,
|
||||
bugprone-move-forwarding-reference,
|
||||
bugprone-multiple-statement-macro,
|
||||
bugprone-no-escape,
|
||||
bugprone-not-null-terminated-result,
|
||||
bugprone-parent-virtual-call,
|
||||
bugprone-posix-return,
|
||||
bugprone-reserved-identifier,
|
||||
bugprone-sizeof-container,
|
||||
bugprone-sizeof-expression,
|
||||
bugprone-spuriously-wake-up-functions,
|
||||
bugprone-string-constructor,
|
||||
bugprone-string-integer-assignment,
|
||||
bugprone-string-literal-with-embedded-nul,
|
||||
bugprone-suspicious-enum-usage,
|
||||
bugprone-suspicious-include,
|
||||
bugprone-suspicious-memory-comparison,
|
||||
bugprone-suspicious-memset-usage,
|
||||
bugprone-suspicious-missing-comma,
|
||||
bugprone-suspicious-semicolon,
|
||||
bugprone-suspicious-string-compare,
|
||||
bugprone-swapped-arguments,
|
||||
bugprone-terminating-continue,
|
||||
bugprone-throw-keyword-missing,
|
||||
bugprone-too-small-loop-variable,
|
||||
bugprone-undefined-memory-manipulation,
|
||||
bugprone-undelegated-constructor,
|
||||
bugprone-unhandled-self-assignment,
|
||||
bugprone-unused-raii,
|
||||
bugprone-unused-return-value,
|
||||
bugprone-use-after-move,
|
||||
bugprone-virtual-near-miss,
|
||||
cert-dcl21-cpp,
|
||||
cert-dcl58-cpp,
|
||||
cert-err34-c,
|
||||
cert-err52-cpp,
|
||||
cert-err60-cpp,
|
||||
cert-flp30-c,
|
||||
cert-msc50-cpp,
|
||||
cert-msc51-cpp,
|
||||
cert-str34-c,
|
||||
cppcoreguidelines-interfaces-global-init,
|
||||
cppcoreguidelines-narrowing-conversions,
|
||||
cppcoreguidelines-pro-type-member-init,
|
||||
cppcoreguidelines-pro-type-static-cast-downcast,
|
||||
cppcoreguidelines-slicing,
|
||||
google-default-arguments,
|
||||
google-explicit-constructor,
|
||||
google-runtime-operator,
|
||||
hicpp-exception-baseclass,
|
||||
hicpp-multiway-paths-covered,
|
||||
misc-misplaced-const,
|
||||
misc-new-delete-overloads,
|
||||
misc-no-recursion,
|
||||
misc-non-copyable-objects,
|
||||
misc-throw-by-value-catch-by-reference,
|
||||
misc-unconventional-assign-operator,
|
||||
misc-uniqueptr-reset-release,
|
||||
modernize-avoid-bind,
|
||||
modernize-concat-nested-namespaces,
|
||||
modernize-deprecated-headers,
|
||||
modernize-deprecated-ios-base-aliases,
|
||||
modernize-loop-convert,
|
||||
modernize-make-shared,
|
||||
modernize-make-unique,
|
||||
modernize-pass-by-value,
|
||||
modernize-raw-string-literal,
|
||||
modernize-redundant-void-arg,
|
||||
modernize-replace-auto-ptr,
|
||||
modernize-replace-disallow-copy-and-assign-macro,
|
||||
modernize-replace-random-shuffle,
|
||||
modernize-return-braced-init-list,
|
||||
modernize-shrink-to-fit,
|
||||
modernize-unary-static-assert,
|
||||
modernize-use-auto,
|
||||
modernize-use-bool-literals,
|
||||
modernize-use-emplace,
|
||||
modernize-use-equals-default,
|
||||
modernize-use-equals-delete,
|
||||
modernize-use-nodiscard,
|
||||
modernize-use-noexcept,
|
||||
modernize-use-nullptr,
|
||||
modernize-use-override,
|
||||
modernize-use-transparent-functors,
|
||||
modernize-use-uncaught-exceptions,
|
||||
mpi-buffer-deref,
|
||||
mpi-type-mismatch,
|
||||
openmp-use-default-none,
|
||||
performance-faster-string-find,
|
||||
performance-for-range-copy,
|
||||
performance-implicit-conversion-in-loop,
|
||||
performance-inefficient-algorithm,
|
||||
performance-inefficient-string-concatenation,
|
||||
performance-inefficient-vector-operation,
|
||||
performance-move-const-arg,
|
||||
performance-move-constructor-init,
|
||||
performance-no-automatic-move,
|
||||
performance-noexcept-move-constructor,
|
||||
performance-trivially-destructible,
|
||||
performance-type-promotion-in-math-fn,
|
||||
performance-unnecessary-copy-initialization,
|
||||
performance-unnecessary-value-param,
|
||||
portability-simd-intrinsics,
|
||||
readability-avoid-const-params-in-decls,
|
||||
readability-const-return-type,
|
||||
readability-container-size-empty,
|
||||
readability-convert-member-functions-to-static,
|
||||
readability-delete-null-pointer,
|
||||
readability-deleted-default,
|
||||
readability-inconsistent-declaration-parameter-name,
|
||||
readability-make-member-function-const,
|
||||
readability-misleading-indentation,
|
||||
readability-misplaced-array-index,
|
||||
readability-non-const-parameter,
|
||||
readability-redundant-control-flow,
|
||||
readability-redundant-declaration,
|
||||
readability-redundant-function-ptr-dereference,
|
||||
readability-redundant-smartptr-get,
|
||||
readability-redundant-string-cstr,
|
||||
readability-redundant-string-init,
|
||||
readability-simplify-subscript-expr,
|
||||
readability-static-accessed-through-instance,
|
||||
readability-static-definition-in-anonymous-namespace,
|
||||
readability-string-compare,
|
||||
readability-uniqueptr-delete-release,
|
||||
readability-use-anyofallof'
|
||||
@@ -7,51 +7,34 @@
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
|
||||
#define QV_MODULE_NAME "NetworkCore"
|
||||
|
||||
#include "qv2ray/wrapper.hpp"
|
||||
|
||||
namespace Qv2ray::common::network {
|
||||
void NetworkRequestHelper::setHeader(QNetworkRequest &request, const QByteArray &key, const QByteArray &value) {
|
||||
DEBUG("Adding HTTP request header: " + key + ":" + value);
|
||||
request.setRawHeader(key, value);
|
||||
}
|
||||
|
||||
void
|
||||
NetworkRequestHelper::setAccessManagerAttributes(QNetworkRequest &request, QNetworkAccessManager &accessManager) {
|
||||
|
||||
// Use proxy
|
||||
if (NekoRay::dataStore->sub_use_proxy) {
|
||||
QNetworkProxy p{QNetworkProxy::Socks5Proxy, "127.0.0.1",
|
||||
static_cast<quint16>(NekoRay::dataStore->inbound_socks_port)};
|
||||
accessManager.setProxy(p);
|
||||
if (NekoRay::dataStore->started_id < 0) {
|
||||
showLog(QObject::tr("Request with proxy but no profile started."));
|
||||
}
|
||||
}
|
||||
|
||||
if (accessManager.proxy().type() == QNetworkProxy::Socks5Proxy) {
|
||||
DEBUG("Adding HostNameLookupCapability to proxy.");
|
||||
accessManager.proxy().setCapabilities(
|
||||
accessManager.proxy().capabilities() | QNetworkProxy::HostNameLookupCapability);
|
||||
}
|
||||
|
||||
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
// request.setAttribute(QNetworkRequest::Http2AllowedAttribute, true);
|
||||
#else
|
||||
// request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true);
|
||||
#endif
|
||||
|
||||
request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader, NekoRay::dataStore->user_agent);
|
||||
}
|
||||
|
||||
HTTPResponse NetworkRequestHelper::HttpGet(const QUrl &url) {
|
||||
NekoHTTPResponse NetworkRequestHelper::HttpGet(const QUrl &url) {
|
||||
QNetworkRequest request;
|
||||
QNetworkAccessManager accessManager;
|
||||
request.setUrl(url);
|
||||
setAccessManagerAttributes(request, accessManager);
|
||||
// Set proxy
|
||||
if (NekoRay::dataStore->sub_use_proxy) {
|
||||
QNetworkProxy p;
|
||||
// Note: sing-box mixed socks5 protocol error
|
||||
p.setType(IS_NEKO_BOX ? QNetworkProxy::HttpProxy : QNetworkProxy::Socks5Proxy);
|
||||
p.setHostName("127.0.0.1");
|
||||
p.setPort(NekoRay::dataStore->inbound_socks_port);
|
||||
accessManager.setProxy(p);
|
||||
if (NekoRay::dataStore->started_id < 0) {
|
||||
return NekoHTTPResponse{QObject::tr("Request with proxy but no profile started.")};
|
||||
}
|
||||
}
|
||||
if (accessManager.proxy().type() == QNetworkProxy::Socks5Proxy) {
|
||||
DEBUG("Adding HostNameLookupCapability to proxy.");
|
||||
auto cap = accessManager.proxy().capabilities();
|
||||
accessManager.proxy().setCapabilities(cap | QNetworkProxy::HostNameLookupCapability);
|
||||
}
|
||||
// Set attribute
|
||||
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||
request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader, NekoRay::dataStore->user_agent);
|
||||
auto _reply = accessManager.get(request);
|
||||
//
|
||||
{
|
||||
@@ -60,38 +43,12 @@ namespace Qv2ray::common::network {
|
||||
loop.exec();
|
||||
}
|
||||
//
|
||||
return HTTPResponse{_reply->error() == QNetworkReply::NetworkError::NoError ? "" : _reply->errorString(),
|
||||
_reply->readAll(), _reply->rawHeaderPairs()};
|
||||
}
|
||||
|
||||
void NetworkRequestHelper::AsyncHttpGet(const QString &url, std::function<void(const QByteArray &)> funcPtr) {
|
||||
QNetworkRequest request;
|
||||
request.setUrl(url);
|
||||
auto accessManagerPtr = new QNetworkAccessManager();
|
||||
setAccessManagerAttributes(request, *accessManagerPtr);
|
||||
auto reply = accessManagerPtr->get(request);
|
||||
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
bool h2Used = reply->attribute(QNetworkRequest::Http2WasUsedAttribute).toBool();
|
||||
#else
|
||||
bool h2Used = reply->attribute(QNetworkRequest::HTTP2WasUsedAttribute).toBool();
|
||||
#endif
|
||||
if (h2Used)
|
||||
DEBUG("HTTP/2 was used.");
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError)
|
||||
LOG("Network error: " +
|
||||
QString(QMetaEnum::fromType<QNetworkReply::NetworkError>().key(reply->error())));
|
||||
|
||||
funcPtr(reply->readAll());
|
||||
accessManagerPtr->deleteLater();
|
||||
}
|
||||
});
|
||||
return NekoHTTPResponse{_reply->error() == QNetworkReply::NetworkError::NoError ? "" : _reply->errorString(),
|
||||
_reply->readAll(), _reply->rawHeaderPairs()};
|
||||
}
|
||||
|
||||
QString NetworkRequestHelper::GetHeader(const QList<QPair<QByteArray, QByteArray>> &header, const QString &name) {
|
||||
for (auto p: header) {
|
||||
for (const auto &p: header) {
|
||||
if (QString(p.first).toLower() == name.toLower()) return p.second;
|
||||
}
|
||||
return "";
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <functional>
|
||||
|
||||
namespace Qv2ray::common::network {
|
||||
struct HTTPResponse {
|
||||
struct NekoHTTPResponse {
|
||||
QString error;
|
||||
QByteArray data;
|
||||
QList<QPair<QByteArray, QByteArray>> header;
|
||||
@@ -18,19 +18,12 @@ namespace Qv2ray::common::network {
|
||||
|
||||
explicit NetworkRequestHelper(QObject *parent) : QObject(parent) {};
|
||||
|
||||
~NetworkRequestHelper() {};
|
||||
~NetworkRequestHelper() override = default;;
|
||||
|
||||
public:
|
||||
static void AsyncHttpGet(const QString &url, std::function<void(const QByteArray &)> funcPtr);
|
||||
static NekoHTTPResponse HttpGet(const QUrl &url);
|
||||
|
||||
static HTTPResponse HttpGet(const QUrl &url);
|
||||
|
||||
static QString GetHeader(const QList<QPair<QByteArray, QByteArray>>& header, const QString& name);
|
||||
|
||||
private:
|
||||
static void setAccessManagerAttributes(QNetworkRequest &request, QNetworkAccessManager &accessManager);
|
||||
|
||||
static void setHeader(QNetworkRequest &request, const QByteArray &key, const QByteArray &value);
|
||||
static QString GetHeader(const QList<QPair<QByteArray, QByteArray>> &header, const QString &name);
|
||||
};
|
||||
} // namespace Qv2ray::common::network
|
||||
|
||||
|
||||
@@ -268,12 +268,14 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
ui->menuActive_Server->removeAction(old);
|
||||
old->deleteLater();
|
||||
}
|
||||
int active_server_item_count = 0;
|
||||
for (const auto &pf: NekoRay::profileManager->CurrentGroup()->ProfilesWithOrder()) {
|
||||
auto a = new QAction(pf->bean->DisplayTypeAndName());
|
||||
a->setProperty("id", pf->id);
|
||||
a->setCheckable(true);
|
||||
if (NekoRay::dataStore->started_id == pf->id) a->setChecked(true);
|
||||
ui->menuActive_Server->addAction(a);
|
||||
if (++active_server_item_count == 50) break;
|
||||
}
|
||||
// active routing
|
||||
for (const auto &old: ui->menuActive_Routing->actions()) {
|
||||
@@ -996,7 +998,7 @@ void MainWindow::on_menu_copy_links_triggered() {
|
||||
if (ui->masterLogBrowser->hasFocus()) {
|
||||
ui->masterLogBrowser->copy();
|
||||
return;
|
||||
};
|
||||
}
|
||||
auto ents = get_now_selected();
|
||||
QStringList links;
|
||||
for (const auto &ent: ents) {
|
||||
@@ -1134,6 +1136,10 @@ void MainWindow::on_menu_clear_test_result_triggered() {
|
||||
}
|
||||
|
||||
void MainWindow::on_menu_select_all_triggered() {
|
||||
if (ui->masterLogBrowser->hasFocus()) {
|
||||
ui->masterLogBrowser->selectAll();
|
||||
return;
|
||||
}
|
||||
ui->proxyListTable->selectAll();
|
||||
}
|
||||
|
||||
@@ -1144,10 +1150,16 @@ void MainWindow::on_menu_delete_repeat_triggered() {
|
||||
NekoRay::ProfileFilter::Uniq(NekoRay::profileManager->CurrentGroup()->Profiles(), out, true, false);
|
||||
NekoRay::ProfileFilter::OnlyInSrc_ByPointer(NekoRay::profileManager->CurrentGroup()->Profiles(), out, out_del);
|
||||
|
||||
int remove_display_count = 0;
|
||||
QString remove_display;
|
||||
for (const auto &ent: out_del) {
|
||||
remove_display += ent->bean->DisplayTypeAndName() + "\n";
|
||||
if (++remove_display_count == 20) {
|
||||
remove_display += "...";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (out_del.length() > 0 &&
|
||||
QMessageBox::question(this,
|
||||
tr("Confirmation"),
|
||||
|
||||
Reference in New Issue
Block a user