#pragma once #include #include #include #include namespace Configs { enum OSType { Unknown = 0, Linux = 1, Windows = 2, Darwin = 3, }; class ExtraCoreData { public: QString path; QString args; QString config; QString configDir; bool noLog; }; class DNSDeps { public: bool needDirectDnsRules = false; QJsonArray directDomains; QJsonArray directRuleSets; QJsonArray directSuffixes; QJsonArray directKeywords; QJsonArray directRegexes; }; class HijackDeps { public: QJsonArray hijackDomains; QJsonArray hijackDomainSuffix; QJsonArray hijackDomainRegex; QJsonArray hijackGeoAssets; }; class TunDeps { public: QJsonArray directIPSets; QJsonArray directIPCIDRs; }; class RoutingDeps { public: int defaultOutboundID; QList neededOutbounds; QStringList neededRuleSets; std::map outboundMap; }; class BuildPrerequisities { public: std::shared_ptr dnsDeps = std::make_shared(); std::shared_ptr hijackDeps = std::make_shared(); std::shared_ptr tunDeps = std::make_shared(); std::shared_ptr routingDeps = std::make_shared(); }; class BuildConfigResult { public: QString error; QJsonObject coreConfig; std::shared_ptr extraCoreData = std::make_shared(); QList> outboundStats; }; class BuildSingBoxConfigContext { public: bool forTest = false; bool forExport = false; bool tunEnabled = false; bool isResolvedUsed = false; std::shared_ptr ent = std::make_shared(nullptr, nullptr, nullptr); std::shared_ptr buildPrerequisities = std::make_shared(); OSType os; QString error; QStringList warnings; QJsonArray outbounds; QJsonArray endpoints; std::shared_ptr buildConfigResult = std::make_shared(); }; inline QString get_jsdelivr_link(QString link) { if(dataStore->routing->ruleset_mirror == Mirrors::GITHUB) return link; if(auto url = QUrl(link); url.isValid() && url.host() == "raw.githubusercontent.com") { QStringList list = url.path().split('/'); QString result; switch(dataStore->routing->ruleset_mirror) { case Mirrors::GCORE: result = "https://gcore.jsdelivr.net/gh"; break; case Mirrors::QUANTIL: result = "https://quantil.jsdelivr.net/gh"; break; case Mirrors::FASTLY: result = "https://fastly.jsdelivr.net/gh"; break; case Mirrors::CDN: result = "https://cdn.jsdelivr.net/gh"; break; default: result = "https://testingcf.jsdelivr.net/gh"; } int index = 0; foreach(QString item, list) { if(!item.isEmpty()) { if(index == 2) result += "@" + item; else result += "/" + item; index++; } } return result; } return link; } void CalculatePrerequisities(std::shared_ptr &ctx); void buildLogSections(std::shared_ptr &ctx); void buildDNSSection(std::shared_ptr &ctx, bool useDnsObj = true); void buildNTPSection(std::shared_ptr &ctx); void buildCertificateSection(std::shared_ptr &ctx); void buildInboundSection(std::shared_ptr &ctx); void buildOutboundsSection(std::shared_ptr &ctx); void buildRouteSection(std::shared_ptr &ctx); void buildExperimentalSection(std::shared_ptr &ctx); std::shared_ptr BuildSingBoxConfig(const std::shared_ptr &ent); class BuildTestConfigResult { public: QString error; QMap fullConfigs; QMap tag2entID; QJsonObject coreConfig; QStringList outboundTags; }; bool IsValid(const std::shared_ptr &ent); std::shared_ptr BuildTestConfig(const QList > &profiles); }