diff --git a/airdcpp-webapi/api/HubInfo.cpp b/airdcpp-webapi/api/HubInfo.cpp index 090df818..40276e9a 100644 --- a/airdcpp-webapi/api/HubInfo.cpp +++ b/airdcpp-webapi/api/HubInfo.cpp @@ -159,7 +159,7 @@ namespace webserver { return { { "id", id }, - { "encryption", aClient->getEncryptionInfo() }, + { "encryption", Serializer::serializeEncryption(aClient->getEncryptionInfo(), aClient->isTrusted()) }, }; } diff --git a/airdcpp-webapi/api/PrivateChatInfo.cpp b/airdcpp-webapi/api/PrivateChatInfo.cpp index 74dba068..5d931f20 100644 --- a/airdcpp-webapi/api/PrivateChatInfo.cpp +++ b/airdcpp-webapi/api/PrivateChatInfo.cpp @@ -82,11 +82,16 @@ namespace webserver { } json PrivateChatInfo::serializeCCPMState(const PrivateChatPtr& aChat) noexcept { + json encryption; + if (aChat->getUc()) { + encryption = Serializer::serializeEncryption(aChat->getUc()->getEncryptionInfo(), aChat->getUc()->isTrusted()); + } + return{ { "id", formatCCPMState(aChat->getCCPMState()) }, { "str", PrivateChat::ccpmStateToString(aChat->getCCPMState()) }, { "supported", aChat->getSupportsCCPM() }, - { "encryption", aChat->getUc() ? aChat->getUc()->getEncryptionInfo() : Util::emptyString }, + { "encryption", encryption }, }; } diff --git a/airdcpp-webapi/api/TransferApi.h b/airdcpp-webapi/api/TransferApi.h index c18799bc..ae233b3d 100644 --- a/airdcpp-webapi/api/TransferApi.h +++ b/airdcpp-webapi/api/TransferApi.h @@ -59,7 +59,7 @@ namespace webserver { { PROP_SECONDS_LEFT, "seconds_left", TYPE_TIME, SERIALIZE_NUMERIC, SORT_NUMERIC }, { PROP_IP, "ip", TYPE_TEXT, SERIALIZE_CUSTOM, SORT_TEXT }, { PROP_FLAGS, "flags", TYPE_LIST_TEXT, SERIALIZE_CUSTOM, SORT_CUSTOM }, - { PROP_ENCRYPTION, "encryption", TYPE_TEXT, SERIALIZE_TEXT, SORT_TEXT }, + { PROP_ENCRYPTION, "encryption", TYPE_TEXT, SERIALIZE_CUSTOM, SORT_TEXT }, }; enum Properties { diff --git a/airdcpp-webapi/api/TransferUtils.cpp b/airdcpp-webapi/api/TransferUtils.cpp index 4ff7b636..9cd1e0d8 100644 --- a/airdcpp-webapi/api/TransferUtils.cpp +++ b/airdcpp-webapi/api/TransferUtils.cpp @@ -76,16 +76,21 @@ namespace webserver { json TransferUtils::serializeProperty(const TransferInfoPtr& aItem, int aPropertyName) noexcept { switch (aPropertyName) { - case TransferApi::PROP_IP: return Serializer::serializeIp(aItem->getIp()); - case TransferApi::PROP_USER: return Serializer::serializeHintedUser(aItem->getHintedUser()); - case TransferApi::PROP_STATUS: - { - return { - { "id", aItem->getStateKey() }, - { "str", aItem->getStatusString() }, - }; - } - case TransferApi::PROP_FLAGS: return aItem->getFlags(); + case TransferApi::PROP_IP: return Serializer::serializeIp(aItem->getIp()); + case TransferApi::PROP_USER: return Serializer::serializeHintedUser(aItem->getHintedUser()); + case TransferApi::PROP_STATUS: + { + return { + { "id", aItem->getStateKey() }, + { "str", aItem->getStatusString() }, + }; + } + case TransferApi::PROP_FLAGS: return aItem->getFlags(); + case TransferApi::PROP_ENCRYPTION: + { + auto trusted = aItem->getFlags().find("S") != aItem->getFlags().end(); + return Serializer::serializeEncryption(aItem->getEncryption(), trusted); + } } dcassert(0); diff --git a/airdcpp-webapi/api/common/Serializer.cpp b/airdcpp-webapi/api/common/Serializer.cpp index 0dac643f..89f38129 100644 --- a/airdcpp-webapi/api/common/Serializer.cpp +++ b/airdcpp-webapi/api/common/Serializer.cpp @@ -89,9 +89,9 @@ namespace webserver { } auto cm = aUser->getIdentity().getConnectMode(); - if (cm == Identity::MODE_NOCONNECT_PASSIVE || cm == Identity::MODE_NOCONNECT_IP || cm == Identity::MODE_UNDEFINED) { + if (!aUser->getUser()->isNMDC() && (cm == Identity::MODE_NOCONNECT_PASSIVE || cm == Identity::MODE_NOCONNECT_IP || cm == Identity::MODE_UNDEFINED)) { flags_.insert("noconnect"); - } if (!aUser->getIdentity().isTcpActive(aUser->getClient())) { + } else if (!aUser->getIdentity().isTcpActive(aUser->getClient())) { flags_.insert("passive"); } } @@ -147,6 +147,17 @@ namespace webserver { }; } + json Serializer::serializeEncryption(const string& aInfo, bool aIsTrusted) noexcept { + if (aInfo.empty()) { + return nullptr; + } + + return { + { "str", aInfo }, + { "trusted", aIsTrusted }, + }; + } + json Serializer::serializeChatMessage(const ChatMessagePtr& aMessage) noexcept { json ret = { { "id", aMessage->getId()}, diff --git a/airdcpp-webapi/api/common/Serializer.h b/airdcpp-webapi/api/common/Serializer.h index d65fdd86..76f73fb4 100644 --- a/airdcpp-webapi/api/common/Serializer.h +++ b/airdcpp-webapi/api/common/Serializer.h @@ -56,6 +56,7 @@ namespace webserver { static json serializeIp(const string& aIP, const string& aCountryCode) noexcept; static json serializeShareProfileSimple(ProfileToken aProfile) noexcept; + static json serializeEncryption(const string& aInfo, bool aIsTrusted) noexcept; static string getDownloadStateId(TrackableDownloadItem::State aState) noexcept; //static string getDownloadStateStr(TrackableDownloadItem& aItem) noexcept;