unmangle merge

This commit is contained in:
Seth Alves 2018-03-20 11:17:56 -07:00
commit 585a523823
6 changed files with 38 additions and 36 deletions

View file

@ -4,7 +4,7 @@ cmake_policy(SET CMP0046 OLD)
include(ExternalProject) include(ExternalProject)
set(QUAZIP_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -DCMAKE_PREFIX_PATH=${QT_CMAKE_PREFIX_PATH} -DCMAKE_INSTALL_NAME_DIR:PATH=<INSTALL_DIR>/lib -DZLIB_ROOT=${ZLIB_ROOT} -DCMAKE_POSITION_INDEPENDENT_CODE=ON) set(QUAZIP_CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -DCMAKE_PREFIX_PATH=${QT_CMAKE_PREFIX_PATH} -DCMAKE_INSTALL_NAME_DIR:PATH=<INSTALL_DIR>/lib -DZLIB_ROOT=${ZLIB_ROOT} -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
if (APPLE) if (APPLE)
else () else ()

View file

@ -20,6 +20,7 @@
#include <QJsonArray> #include <QJsonArray>
#include <QProcess> #include <QProcess>
#include <QSharedMemory> #include <QSharedMemory>
#include <QRegularExpression>
#include <QStandardPaths> #include <QStandardPaths>
#include <QTimer> #include <QTimer>
#include <QUrlQuery> #include <QUrlQuery>
@ -727,7 +728,7 @@ void DomainServer::setupNodeListAndAssignments() {
packetReceiver.registerListener(PacketType::OctreeDataPersist, this, "processOctreeDataPersistMessage"); packetReceiver.registerListener(PacketType::OctreeDataPersist, this, "processOctreeDataPersistMessage");
packetReceiver.registerListener(PacketType::OctreeFileReplacement, this, "handleOctreeFileReplacementRequest"); packetReceiver.registerListener(PacketType::OctreeFileReplacement, this, "handleOctreeFileReplacementRequest");
packetReceiver.registerListener(PacketType::OctreeFileReplacementFromUrl, this, "handleOctreeFileReplacementFromURLRequest"); packetReceiver.registerListener(PacketType::DomainContentReplacementFromUrl, this, "handleDomainContentReplacementFromURLRequest");
// set a custom packetVersionMatch as the verify packet operator for the udt::Socket // set a custom packetVersionMatch as the verify packet operator for the udt::Socket
nodeList->setPacketFilterOperator(&DomainServer::isPacketVerified); nodeList->setPacketFilterOperator(&DomainServer::isPacketVerified);
@ -736,7 +737,6 @@ void DomainServer::setupNodeListAndAssignments() {
auto assetClient = DependencyManager::set<AssetClient>(); auto assetClient = DependencyManager::set<AssetClient>();
assetClient->moveToThread(&_assetClientThread); assetClient->moveToThread(&_assetClientThread);
_assetClientThread.start(); _assetClientThread.start();
// add whatever static assignments that have been parsed to the queue // add whatever static assignments that have been parsed to the queue
addStaticAssignmentsToQueue(); addStaticAssignmentsToQueue();
} }
@ -2136,7 +2136,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
} else if (url.path().startsWith(URI_API_BACKUPS_ID)) { } else if (url.path().startsWith(URI_API_BACKUPS_ID)) {
auto id = url.path().mid(QString(URI_API_BACKUPS_ID).length()); auto id = url.path().mid(QString(URI_API_BACKUPS_ID).length());
auto deferred = makePromise("consolidateBackup"); auto deferred = makePromise("consolidateBackup");
deferred->then([connectionPtr, JSON_MIME_TYPE](QString error, QVariantMap result) { deferred->then([connectionPtr, JSON_MIME_TYPE, id](QString error, QVariantMap result) {
if (!connectionPtr) { if (!connectionPtr) {
return; return;
} }
@ -2147,7 +2147,14 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
auto path = result["backupFilePath"].toString(); auto path = result["backupFilePath"].toString();
auto file { std::unique_ptr<QFile>(new QFile(path)) }; auto file { std::unique_ptr<QFile>(new QFile(path)) };
if (file->open(QIODevice::ReadOnly)) { if (file->open(QIODevice::ReadOnly)) {
connectionPtr->respond(HTTPConnection::StatusCode200, std::move(file)); constexpr const char* CONTENT_TYPE_ZIP = "application/zip";
auto downloadedFilename = id;
downloadedFilename.replace(QRegularExpression(".zip$"), ".content.zip");
auto contentDisposition = "attachment; filename=\"" + downloadedFilename + "\"";
connectionPtr->respond(HTTPConnection::StatusCode200, std::move(file), CONTENT_TYPE_ZIP, {
{ "Content-Disposition", contentDisposition.toUtf8() }
});
} else { } else {
qCritical(domain_server) << "Unable to load consolidated backup at:" << path << result; qCritical(domain_server) << "Unable to load consolidated backup at:" << path << result;
connectionPtr->respond(HTTPConnection::StatusCode500, "Error opening backup"); connectionPtr->respond(HTTPConnection::StatusCode500, "Error opening backup");
@ -3429,13 +3436,10 @@ void DomainServer::handleOctreeFileReplacement(QByteArray octreeFile) {
} }
} }
void DomainServer::handleOctreeFileReplacementFromURLRequest(QSharedPointer<ReceivedMessage> message) { void DomainServer::handleDomainContentReplacementFromURLRequest(QSharedPointer<ReceivedMessage> message) {
qInfo() << "Received request to replace content from a url"; qInfo() << "Received request to replace content from a url";
auto node = DependencyManager::get<LimitedNodeList>()->findNodeWithAddr(message->getSenderSockAddr()); auto node = DependencyManager::get<LimitedNodeList>()->findNodeWithAddr(message->getSenderSockAddr());
if (node) { if (node && node->getCanReplaceContent()) {
qDebug() << "Found node: " << node->getCanReplaceContent();
}
if (node->getCanReplaceContent()) {
// Convert message data into our URL // Convert message data into our URL
QString url(message->getMessage()); QString url(message->getMessage());
QUrl modelsURL = QUrl(url, QUrl::StrictMode); QUrl modelsURL = QUrl(url, QUrl::StrictMode);
@ -3448,7 +3452,12 @@ void DomainServer::handleOctreeFileReplacementFromURLRequest(QSharedPointer<Rece
connect(reply, &QNetworkReply::finished, [this, reply, modelsURL]() { connect(reply, &QNetworkReply::finished, [this, reply, modelsURL]() {
QNetworkReply::NetworkError networkError = reply->error(); QNetworkReply::NetworkError networkError = reply->error();
if (networkError == QNetworkReply::NoError) { if (networkError == QNetworkReply::NoError) {
handleOctreeFileReplacement(reply->readAll()); if (modelsURL.fileName().endsWith(".json.gz")) {
handleOctreeFileReplacement(reply->readAll());
} else if (modelsURL.fileName().endsWith(".zip")) {
auto deferred = makePromise("recoverFromUploadedBackup");
_contentManager->recoverFromUploadedBackup(deferred, reply->readAll());
}
} else { } else {
qDebug() << "Error downloading JSON from specified file: " << modelsURL; qDebug() << "Error downloading JSON from specified file: " << modelsURL;
} }
@ -3456,9 +3465,6 @@ void DomainServer::handleOctreeFileReplacementFromURLRequest(QSharedPointer<Rece
} }
} }
void DomainServer::handleOctreeFileReplacementRequest(QSharedPointer<ReceivedMessage> message) { void DomainServer::handleOctreeFileReplacementRequest(QSharedPointer<ReceivedMessage> message) {
auto node = DependencyManager::get<NodeList>()->nodeWithUUID(message->getSourceID()); auto node = DependencyManager::get<NodeList>()->nodeWithUUID(message->getSourceID());
if (node->getCanReplaceContent()) { if (node->getCanReplaceContent()) {

View file

@ -91,7 +91,7 @@ private slots:
void processICEServerHeartbeatDenialPacket(QSharedPointer<ReceivedMessage> message); void processICEServerHeartbeatDenialPacket(QSharedPointer<ReceivedMessage> message);
void processICEServerHeartbeatACK(QSharedPointer<ReceivedMessage> message); void processICEServerHeartbeatACK(QSharedPointer<ReceivedMessage> message);
void handleOctreeFileReplacementFromURLRequest(QSharedPointer<ReceivedMessage> message); void handleDomainContentReplacementFromURLRequest(QSharedPointer<ReceivedMessage> message);
void handleOctreeFileReplacementRequest(QSharedPointer<ReceivedMessage> message); void handleOctreeFileReplacementRequest(QSharedPointer<ReceivedMessage> message);
void handleOctreeFileReplacement(QByteArray octreeFile); void handleOctreeFileReplacement(QByteArray octreeFile);

View file

@ -351,6 +351,7 @@ static const QString OBJ_EXTENSION = ".obj";
static const QString AVA_JSON_EXTENSION = ".ava.json"; static const QString AVA_JSON_EXTENSION = ".ava.json";
static const QString WEB_VIEW_TAG = "noDownload=true"; static const QString WEB_VIEW_TAG = "noDownload=true";
static const QString ZIP_EXTENSION = ".zip"; static const QString ZIP_EXTENSION = ".zip";
static const QString CONTENT_ZIP_EXTENSION = ".content.zip";
static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f; static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f;
@ -376,7 +377,7 @@ static const QString DESKTOP_DISPLAY_PLUGIN_NAME = "Desktop";
static const QString SYSTEM_TABLET = "com.highfidelity.interface.tablet.system"; static const QString SYSTEM_TABLET = "com.highfidelity.interface.tablet.system";
const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensions { const std::vector<std::pair<QString, Application::AcceptURLMethod>> Application::_acceptedExtensions {
{ SVO_EXTENSION, &Application::importSVOFromURL }, { SVO_EXTENSION, &Application::importSVOFromURL },
{ SVO_JSON_EXTENSION, &Application::importSVOFromURL }, { SVO_JSON_EXTENSION, &Application::importSVOFromURL },
{ AVA_JSON_EXTENSION, &Application::askToWearAvatarAttachmentUrl }, { AVA_JSON_EXTENSION, &Application::askToWearAvatarAttachmentUrl },
@ -384,6 +385,7 @@ const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensi
{ JS_EXTENSION, &Application::askToLoadScript }, { JS_EXTENSION, &Application::askToLoadScript },
{ FST_EXTENSION, &Application::askToSetAvatarUrl }, { FST_EXTENSION, &Application::askToSetAvatarUrl },
{ JSON_GZ_EXTENSION, &Application::askToReplaceDomainContent }, { JSON_GZ_EXTENSION, &Application::askToReplaceDomainContent },
{ CONTENT_ZIP_EXTENSION, &Application::askToReplaceDomainContent },
{ ZIP_EXTENSION, &Application::importFromZIP }, { ZIP_EXTENSION, &Application::importFromZIP },
{ JPG_EXTENSION, &Application::importImage }, { JPG_EXTENSION, &Application::importImage },
{ PNG_EXTENSION, &Application::importImage } { PNG_EXTENSION, &Application::importImage }
@ -6276,11 +6278,9 @@ bool Application::canAcceptURL(const QString& urlString) const {
} else if (urlString.startsWith(URL_SCHEME_HIFI)) { } else if (urlString.startsWith(URL_SCHEME_HIFI)) {
return true; return true;
} }
QHashIterator<QString, AcceptURLMethod> i(_acceptedExtensions);
QString lowerPath = url.path().toLower(); QString lowerPath = url.path().toLower();
while (i.hasNext()) { for (auto& pair : _acceptedExtensions) {
i.next(); if (lowerPath.endsWith(pair.first, Qt::CaseInsensitive)) {
if (lowerPath.endsWith(i.key(), Qt::CaseInsensitive)) {
return true; return true;
} }
} }
@ -6296,12 +6296,10 @@ bool Application::acceptURL(const QString& urlString, bool defaultUpload) {
return true; return true;
} }
QHashIterator<QString, AcceptURLMethod> i(_acceptedExtensions);
QString lowerPath = url.path().toLower(); QString lowerPath = url.path().toLower();
while (i.hasNext()) { for (auto& pair : _acceptedExtensions) {
i.next(); if (lowerPath.endsWith(pair.first, Qt::CaseInsensitive)) {
if (lowerPath.endsWith(i.key(), Qt::CaseInsensitive)) { AcceptURLMethod method = pair.second;
AcceptURLMethod method = i.value();
return (this->*method)(urlString); return (this->*method)(urlString);
} }
} }
@ -6488,13 +6486,11 @@ void Application::replaceDomainContent(const QString& url) {
QByteArray urlData(url.toUtf8()); QByteArray urlData(url.toUtf8());
auto limitedNodeList = DependencyManager::get<NodeList>(); auto limitedNodeList = DependencyManager::get<NodeList>();
const auto& domainHandler = limitedNodeList->getDomainHandler(); const auto& domainHandler = limitedNodeList->getDomainHandler();
limitedNodeList->eachMatchingNode([](const SharedNodePointer& node) {
return node->getType() == NodeType::EntityServer && node->getActiveSocket(); auto octreeFilePacket = NLPacket::create(PacketType::DomainContentReplacementFromUrl, urlData.size(), true);
}, [&urlData, limitedNodeList, &domainHandler](const SharedNodePointer& octreeNode) { octreeFilePacket->write(urlData);
auto octreeFilePacket = NLPacket::create(PacketType::OctreeFileReplacementFromUrl, urlData.size(), true); limitedNodeList->sendPacket(std::move(octreeFilePacket), domainHandler.getSockAddr());
octreeFilePacket->write(urlData);
limitedNodeList->sendPacket(std::move(octreeFilePacket), domainHandler.getSockAddr());
});
auto addressManager = DependencyManager::get<AddressManager>(); auto addressManager = DependencyManager::get<AddressManager>();
addressManager->handleLookupString(DOMAIN_SPAWNING_POINT); addressManager->handleLookupString(DOMAIN_SPAWNING_POINT);
QString newHomeAddress = addressManager->getHost() + DOMAIN_SPAWNING_POINT; QString newHomeAddress = addressManager->getHost() + DOMAIN_SPAWNING_POINT;

View file

@ -608,7 +608,7 @@ private:
GLCanvas* _glWidget{ nullptr }; GLCanvas* _glWidget{ nullptr };
typedef bool (Application::* AcceptURLMethod)(const QString &); typedef bool (Application::* AcceptURLMethod)(const QString &);
static const QHash<QString, AcceptURLMethod> _acceptedExtensions; static const std::vector<std::pair<QString, Application::AcceptURLMethod>> _acceptedExtensions;
glm::uvec2 _renderResolution; glm::uvec2 _renderResolution;

View file

@ -121,7 +121,7 @@ public:
ReplicatedAvatarIdentity, ReplicatedAvatarIdentity,
ReplicatedKillAvatar, ReplicatedKillAvatar,
ReplicatedBulkAvatarData, ReplicatedBulkAvatarData,
OctreeFileReplacementFromUrl, DomainContentReplacementFromUrl,
ChallengeOwnership, ChallengeOwnership,
EntityScriptCallMethod, EntityScriptCallMethod,
ChallengeOwnershipRequest, ChallengeOwnershipRequest,
@ -171,7 +171,7 @@ public:
<< PacketTypeEnum::Value::DomainServerPathResponse << PacketTypeEnum::Value::DomainServerAddedNode << PacketTypeEnum::Value::DomainServerPathResponse << PacketTypeEnum::Value::DomainServerAddedNode
<< PacketTypeEnum::Value::DomainServerConnectionToken << PacketTypeEnum::Value::DomainSettingsRequest << PacketTypeEnum::Value::DomainServerConnectionToken << PacketTypeEnum::Value::DomainSettingsRequest
<< PacketTypeEnum::Value::OctreeDataFileRequest << PacketTypeEnum::Value::OctreeDataFileReply << PacketTypeEnum::Value::OctreeDataFileRequest << PacketTypeEnum::Value::OctreeDataFileReply
<< PacketTypeEnum::Value::OctreeDataPersist << PacketTypeEnum::Value::OctreeFileReplacementFromUrl << PacketTypeEnum::Value::OctreeDataPersist << PacketTypeEnum::Value::DomainContentReplacementFromUrl
<< PacketTypeEnum::Value::DomainSettings << PacketTypeEnum::Value::ICEServerPeerInformation << PacketTypeEnum::Value::DomainSettings << PacketTypeEnum::Value::ICEServerPeerInformation
<< PacketTypeEnum::Value::ICEServerQuery << PacketTypeEnum::Value::ICEServerHeartbeat << PacketTypeEnum::Value::ICEServerQuery << PacketTypeEnum::Value::ICEServerHeartbeat
<< PacketTypeEnum::Value::ICEServerHeartbeatACK << PacketTypeEnum::Value::ICEPing << PacketTypeEnum::Value::ICEServerHeartbeatACK << PacketTypeEnum::Value::ICEPing