Skip to content

Commit

Permalink
Merge commit '3d6e7428134cfcade2a68b65d7f52b4ce7998ed2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
maksis committed Jan 31, 2016
2 parents 379fd4f + 3d6e742 commit b67fffe
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion airdcpp-webapi/api/HubInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ namespace webserver {

return {
{ "id", id },
{ "encryption", aClient->getEncryptionInfo() },
{ "encryption", Serializer::serializeEncryption(aClient->getEncryptionInfo(), aClient->isTrusted()) },
};
}

Expand Down
7 changes: 6 additions & 1 deletion airdcpp-webapi/api/PrivateChatInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
};
}

Expand Down
2 changes: 1 addition & 1 deletion airdcpp-webapi/api/TransferApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 15 additions & 10 deletions airdcpp-webapi/api/TransferUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 13 additions & 2 deletions airdcpp-webapi/api/common/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -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()},
Expand Down
1 change: 1 addition & 0 deletions airdcpp-webapi/api/common/Serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b67fffe

Please sign in to comment.