Skip to content

Commit

Permalink
Merge pull request #452 from airdcpp-web/develop
Browse files Browse the repository at this point in the history
2.12.0
  • Loading branch information
maksis authored May 22, 2023
2 parents cad3510 + bda4ef6 commit 970c99d
Show file tree
Hide file tree
Showing 461 changed files with 1,535 additions and 1,059 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required (VERSION 3.12)
project (airdcpp-webclient)
cmake_minimum_required (VERSION 3.0.2)

if (APPLE)
set (PROJECT_NAME_GLOBAL AirDC++ Web Client)
Expand All @@ -10,8 +10,8 @@ endif (APPLE)
set (PROJECT_NAME "AirDC++ Web Client")
set (TAG_APPLICATION "AirDC++w")
set (APPLICATION_ID "airdcpp-web")
set (VERSION "2.11.4") # NOTE: the minor version must match the lastest UI version
set (SOVERSION "2.11.4" )
set (VERSION "2.12.0") # NOTE: the minor version must match the lastest UI version
set (SOVERSION "2.12.0" )

set (GNUCXX_MINIMUM_VERSION "7.0")

Expand Down Expand Up @@ -209,8 +209,8 @@ endif()
add_definitions (-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_REENTRANT
-D_DATADIR="${CLIENT_DATA_DIR}" -DLOCALE_DIR="${LOCALE_DIR}" -DBUILDING_AIRDCPP)

if (CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pipe -Wformat -Werror=format-security")
if (CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pipe")
if (USE_GOLD)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-linker-plugin")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-linker-plugin")
Expand Down
2 changes: 2 additions & 0 deletions airdcpp-core/airdcpp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
<ClCompile Include="airdcpp\AdcHub.cpp" />
<ClCompile Include="airdcpp\DirectSearch.cpp" />
<ClCompile Include="airdcpp\ErrorCollector.cpp" />
<ClCompile Include="airdcpp\FloodCounter.cpp" />
<ClCompile Include="airdcpp\GroupedSearchResult.cpp" />
<ClCompile Include="airdcpp\Hasher.cpp" />
<ClCompile Include="airdcpp\HashStore.cpp" />
Expand Down Expand Up @@ -340,6 +341,7 @@
<ClInclude Include="airdcpp\AdcCommand.h" />
<ClInclude Include="airdcpp\AdcHub.h" />
<ClInclude Include="airdcpp\AddressInfo.h" />
<ClInclude Include="airdcpp\FloodCounter.h" />
<ClInclude Include="airdcpp\HashStore.h" />
<ClInclude Include="airdcpp\modules\ADLSearch.h" />
<ClInclude Include="airdcpp\QueueAddInfo.h" />
Expand Down
6 changes: 6 additions & 0 deletions airdcpp-core/airdcpp.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@
<ClCompile Include="airdcpp\modules\ADLSearch.cpp">
<Filter>Source Files\modules</Filter>
</ClCompile>
<ClCompile Include="airdcpp\FloodCounter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="airdcpp\AdcCommand.h">
Expand Down Expand Up @@ -964,6 +967,9 @@
<ClInclude Include="airdcpp\modules\ADLSearch.h">
<Filter>Header Files\modules</Filter>
</ClInclude>
<ClInclude Include="airdcpp\FloodCounter.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="airdcpp\StringDefs.h">
Expand Down
54 changes: 38 additions & 16 deletions airdcpp-core/airdcpp/ActionHook.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001-2022 Jacek Sieka, arnetheduck on gmail point com
* Copyright (C) 2001-2023 Jacek Sieka, arnetheduck on gmail point com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -107,6 +107,8 @@ namespace dcpp {
const void* ignoredOwner;
};

typedef std::vector<ActionHookSubscriber> ActionHookSubscriberList;

// Helper class to be passed to hook handlers for creating result entities
template<typename DataT>
class ActionHookDataGetter {
Expand Down Expand Up @@ -147,8 +149,8 @@ namespace dcpp {

ActionHookHandler(ActionHookSubscriber&& aSubscriber, const HookCallback& aCallback) noexcept: dataGetter(ActionHookDataGetter<DataT>(std::move(aSubscriber))), callback(aCallback) { }

const string& getId() const noexcept {
return dataGetter.getSubscriber().getId();
const ActionHookSubscriber& getSubscriber() const noexcept {
return dataGetter.getSubscriber();
}
protected:
friend class ActionHook;
Expand All @@ -162,11 +164,11 @@ namespace dcpp {
using CallbackFunc = std::function<ActionHookResult<DataT>(ArgT&... aArgs, const ActionHookResultGetter<DataT>& aResultGetter)>;
bool addSubscriber(ActionHookSubscriber&& aSubscriber, CallbackFunc aCallback) noexcept {
Lock l(cs);
if (findById(aSubscriber.getId()) != subscribers.end()) {
if (findById(aSubscriber.getId()) != handlers.end()) {
return false;
}

subscribers.push_back(ActionHookHandler(std::move(aSubscriber), aCallback));
handlers.push_back(ActionHookHandler(std::move(aSubscriber), aCallback));
return true;
}

Expand All @@ -183,11 +185,11 @@ namespace dcpp {
bool removeSubscriber(const string& aId) noexcept {
Lock l(cs);
auto i = findById(aId);
if (i == subscribers.end()) {
if (i == handlers.end()) {
return false;
}

subscribers.erase(i);
handlers.erase(i);
return true;
}

Expand Down Expand Up @@ -237,7 +239,18 @@ namespace dcpp {

bool hasSubscribers() const noexcept {
Lock l(cs);
return !subscribers.empty();
return !handlers.empty();
}

ActionHookSubscriberList getSubscribers() const noexcept {
Lock l(cs);

ActionHookSubscriberList ret;
for (const auto& s: handlers) {
ret.push_back(s.getSubscriber());
}

return ret;
}

static DataT normalizeListItems(const ActionHookDataList<DataT>& aResult) noexcept {
Expand All @@ -250,16 +263,25 @@ namespace dcpp {

return ret;
}

static vector<DataT> normalizeData(const ActionHookDataList<DataT>& aResult) noexcept {
vector<DataT> ret;
for (const auto& i : aResult) {
ret.push_back(i->data);
}

return ret;
}
private:
typedef std::vector<ActionHookHandler> SubscriberList;
typedef std::vector<ActionHookHandler> ActionHookHandlerList;

typename SubscriberList::iterator findById(const string& aId) noexcept {
return find_if(subscribers.begin(), subscribers.end(), [&aId](const ActionHookHandler& aSubscriber) {
return aSubscriber.getId() == aId;
typename ActionHookHandlerList::iterator findById(const string& aId) noexcept {
return find_if(handlers.begin(), handlers.end(), [&aId](const ActionHookHandler& aHandler) {
return aHandler.getSubscriber().getId() == aId;
});
}

SubscriberList subscribers;
ActionHookHandlerList handlers;
mutable CriticalSection cs;

ActionHookDataList<DataT> runHooksDataImpl(const void* aOwner, const std::function<void(const ActionHookRejectionPtr&)> aRejectHandler, ArgT&... aItem) const {
Expand All @@ -286,12 +308,12 @@ namespace dcpp {
return ret;
}

SubscriberList getHookHandlers(const void* aOwner) const noexcept {
SubscriberList ret;
ActionHookHandlerList getHookHandlers(const void* aOwner) const noexcept {
ActionHookHandlerList ret;

{
Lock l(cs);
for (const auto& s: subscribers) {
for (const auto& s: handlers) {
if (!s.dataGetter.getSubscriber().getIgnoredOwner() || s.dataGetter.getSubscriber().getIgnoredOwner() != aOwner) {
ret.push_back(s);
}
Expand Down
2 changes: 1 addition & 1 deletion airdcpp-core/airdcpp/ActivityManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011-2022 AirDC++ Project
* Copyright (C) 2011-2023 AirDC++ Project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion airdcpp-core/airdcpp/ActivityManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011-2022 AirDC++ Project
* Copyright (C) 2011-2023 AirDC++ Project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion airdcpp-core/airdcpp/AdcCommand.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001-2022 Jacek Sieka, arnetheduck on gmail point com
* Copyright (C) 2001-2023 Jacek Sieka, arnetheduck on gmail point com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion airdcpp-core/airdcpp/AdcCommand.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001-2022 Jacek Sieka, arnetheduck on gmail point com
* Copyright (C) 2001-2023 Jacek Sieka, arnetheduck on gmail point com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
57 changes: 40 additions & 17 deletions airdcpp-core/airdcpp/AdcHub.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001-2022 Jacek Sieka, arnetheduck on gmail point com
* Copyright (C) 2001-2023 Jacek Sieka, arnetheduck on gmail point com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -198,7 +198,7 @@ void AdcHub::handle(AdcCommand::INF, AdcCommand& c) noexcept {

auto message = u->getIdentity().getNick() + " (" + u->getIdentity().getSIDString() +
") has same CID {" + cid + "} as " + nick + " (" + AdcCommand::fromSID(c.getFrom()) + "), ignoring.";
statusMessage(message, LogMessage::SEV_INFO, Util::emptyString, ClientListener::FLAG_IS_SPAM);
statusMessage(message, LogMessage::SEV_VERBOSE);
return;
}
} else {
Expand Down Expand Up @@ -404,7 +404,7 @@ void AdcHub::handle(AdcCommand::QUI, AdcCommand& c) noexcept {
tmp = victim->getIdentity().getNick() + " was kicked: " + tmp;
}

statusMessage(tmp, LogMessage::SEV_INFO, Util::emptyString, ClientListener::FLAG_IS_SPAM);
statusMessage(tmp, LogMessage::SEV_VERBOSE);
}

putUser(s, c.getParam("DI", 1, tmp));
Expand Down Expand Up @@ -442,9 +442,7 @@ void AdcHub::handle(AdcCommand::QUI, AdcCommand& c) noexcept {
}

void AdcHub::handle(AdcCommand::CTM, AdcCommand& c) noexcept {
OnlineUser* u = findUser(c.getFrom());
if(!u || u->getUser() == ClientManager::getInstance()->getMe())
return;
auto ou = findUser(c.getFrom());
if(c.getParameters().size() < 3)
return;

Expand All @@ -454,10 +452,10 @@ void AdcHub::handle(AdcCommand::CTM, AdcCommand& c) noexcept {
const string& token = c.getParam(2);

bool allowSecure = false;
if (!checkProtocol(*u, allowSecure, protocol, token))
if (!validateConnectUser(ou, allowSecure, protocol, token, remotePort))
return;

ConnectionManager::getInstance()->adcConnect(*u, remotePort, token, allowSecure);
ConnectionManager::getInstance()->adcConnect(*ou, remotePort, token, allowSecure);
}

void AdcHub::handle(AdcCommand::ZON, AdcCommand& c) noexcept {
Expand Down Expand Up @@ -665,12 +663,20 @@ void AdcHub::handle(AdcCommand::STA, AdcCommand& c) noexcept {
}

void AdcHub::handle(AdcCommand::SCH, AdcCommand& c) noexcept {
OnlineUser* ou = findUser(c.getFrom());
if(!ou) {
auto ou = findUser(c.getFrom());
if (!ou) {
dcdebug("Invalid user in AdcHub::onSCH\n");
return;
}

{
auto remotePort = ou->getIdentity().getUdpPort();
auto target = !remotePort.empty() ? ou->getIdentity().getUdpIp() + ":" + remotePort : ou->getIdentity().getNick();
if (!checkIncomingSearch(target, ou)) {
return;
}
}

ASSERT_DIRECT_TO_ME(c)

// Filter own searches
Expand Down Expand Up @@ -803,16 +809,16 @@ void AdcHub::handle(AdcCommand::GET, AdcCommand& c) noexcept {

void AdcHub::handle(AdcCommand::NAT, AdcCommand& c) noexcept {
ASSERT_DIRECT_TO_ME(c)
OnlineUser* u = findUser(c.getFrom());
if(!u || u->getUser() == ClientManager::getInstance()->getMe() || c.getParameters().size() < 3)
auto u = findUser(c.getFrom());
if (c.getParameters().size() < 3)
return;

const string& protocol = c.getParam(0);
const string& remotePort = c.getParam(1);
const string& token = c.getParam(2);

bool allowSecure = false;
if (!checkProtocol(*u, allowSecure, protocol, token))
if (!validateConnectUser(u, allowSecure, protocol, token, remotePort))
return;

// Trigger connection attempt sequence locally ...
Expand All @@ -829,16 +835,16 @@ void AdcHub::handle(AdcCommand::RNT, AdcCommand& c) noexcept {
ASSERT_DIRECT_TO_ME(c)
// Sent request for NAT traversal cooperation, which
// was acknowledged (with requisite local port information).
OnlineUser* u = findUser(c.getFrom());
if(!u || u->getUser() == ClientManager::getInstance()->getMe() || c.getParameters().size() < 3)
auto u = findUser(c.getFrom());
if(c.getParameters().size() < 3)
return;

const string& protocol = c.getParam(0);
const string& remotePort = c.getParam(1);
const string& token = c.getParam(2);

bool allowSecure = false;
if (!checkProtocol(*u, allowSecure, protocol, token))
if (!validateConnectUser(u, allowSecure, protocol, token, remotePort))
return;

// Trigger connection attempt sequence locally
Expand Down Expand Up @@ -968,6 +974,23 @@ int AdcHub::connect(const OnlineUser& user, const string& token, string& lastErr
return conn;
}


bool AdcHub::validateConnectUser(const OnlineUser* aUser, bool& secure_, const string& aRemoteProtocol, const string& aToken, const string& aRemotePort) noexcept {
if (!aUser || aUser->getUser() == ClientManager::getInstance()->getMe())
return false;

if (!checkProtocol(*aUser, secure_, aRemoteProtocol, aToken)) {
return false;
}

auto target = aUser->getIdentity().getTcpConnectIp() + ":" + aRemotePort;
if (!checkIncomingCTM(target, aUser)) {
return false;
}

return true;
}

bool AdcHub::checkProtocol(const OnlineUser& aUser, bool& secure_, const string& aRemoteProtocol, const string& aToken) noexcept {
string failedProtocol;
AdcCommand::Error errCode = AdcCommand::SUCCESS;
Expand Down Expand Up @@ -1219,7 +1242,7 @@ void AdcHub::constructSearch(AdcCommand& c, const SearchPtr& aSearch, bool isDir
c.addParam("LE", Util::toString(aSearch->size));
}

auto searchTokens = move(SearchQuery::parseSearchString(aSearch->query));
auto searchTokens = std::move(SearchQuery::parseSearchString(aSearch->query));
for(const auto& t: searchTokens)
c.addParam("AN", t);

Expand Down
3 changes: 2 additions & 1 deletion airdcpp-core/airdcpp/AdcHub.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001-2022 Jacek Sieka, arnetheduck on gmail point com
* Copyright (C) 2001-2023 Jacek Sieka, arnetheduck on gmail point com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -101,6 +101,7 @@ class AdcHub : public Client, public CommandHandler<AdcHub> {
AdcCommand::Error allowConnect(const OnlineUser& aUser, bool aSecure, string& failedProtocol_, bool checkBase) const noexcept;
/* Does the same thing but also sends the error to the remote user */
bool checkProtocol(const OnlineUser& aUser, bool& secure_, const string& aRemoteProtocol, const string& aToken) noexcept;
bool validateConnectUser(const OnlineUser* aUser, bool& secure_, const string& aRemoteProtocol, const string& aToken, const string& aRemotePort) noexcept;

bool oldPassword = false;
unique_ptr<Socket> udp;
Expand Down
2 changes: 1 addition & 1 deletion airdcpp-core/airdcpp/AddressInfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001-2022 Jacek Sieka, arnetheduck on gmail point com
* Copyright (C) 2001-2023 Jacek Sieka, arnetheduck on gmail point com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
4 changes: 2 additions & 2 deletions airdcpp-core/airdcpp/AirUtil.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011-2022 AirDC++ Project
* Copyright (C) 2011-2023 AirDC++ Project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -62,7 +62,7 @@ boost::regex AirUtil::crcReg;
boost::regex AirUtil::lineBreakRegex;
boost::regex AirUtil::urlReg;

AirUtil::TimeCounter::TimeCounter(string aMsg) : start(GET_TICK()), msg(move(aMsg)) {
AirUtil::TimeCounter::TimeCounter(string aMsg) : start(GET_TICK()), msg(std::move(aMsg)) {

}

Expand Down
Loading

0 comments on commit 970c99d

Please sign in to comment.