lr: support client-side usage

This commit is contained in:
Michael Scire 2020-02-28 03:17:24 -08:00
parent 45e51da0b2
commit b8f77dad97
31 changed files with 1109 additions and 327 deletions

View File

@ -17,12 +17,4 @@
#pragma once #pragma once
#include <vapours.hpp> #include <vapours.hpp>
#include <stratosphere/lr/lr_types.hpp> #include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_location_redirector.hpp> #include <stratosphere/lr/lr_service.hpp>
#include <stratosphere/lr/lr_registered_data.hpp>
#include <stratosphere/lr/lr_i_location_resolver.hpp>
#include <stratosphere/lr/lr_i_location_resolver_interface.hpp>
#include <stratosphere/lr/lr_content_location_resolver.hpp>
#include <stratosphere/lr/lr_redirect_only_location_resolver.hpp>
#include <stratosphere/lr/lr_registered_location_resolver.hpp>
#include <stratosphere/lr/lr_i_location_resolver_manager.hpp>
#include <stratosphere/lr/lr_location_resolver_manager_impl.hpp>

View File

@ -16,42 +16,60 @@
#pragma once #pragma once
#include <stratosphere/lr/lr_types.hpp> #include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_registered_data.hpp> #include <stratosphere/lr/lr_i_add_on_content_location_resolver.hpp>
namespace ams::lr { namespace ams::lr {
class AddOnContentLocationResolverInterface : public sf::IServiceObject { class AddOnContentLocationResolver {
protected: NON_COPYABLE(AddOnContentLocationResolver);
enum class CommandId {
ResolveAddOnContentPath = 0,
RegisterAddOnContentStorageDeprecated = 1,
RegisterAddOnContentStorage = 1,
UnregisterAllAddOnContentPath = 2,
RefreshApplicationAddOnContent = 3,
UnregisterApplicationAddOnContent = 4,
};
private: private:
/* Storage for RegisteredData entries by program id. */ std::shared_ptr<IAddOnContentLocationResolver> interface;
RegisteredStorages<ncm::ProgramId, 0x800> registered_storages;
public: public:
AddOnContentLocationResolverInterface() : registered_storages(hos::GetVersion() < hos::Version_900 ? 0x800 : 0x2) { /* ... */ } AddOnContentLocationResolver() { /* ... */ }
explicit AddOnContentLocationResolver(std::shared_ptr<IAddOnContentLocationResolver> intf) : interface(std::move(intf)) { /* ... */ }
/* Actual commands. */ AddOnContentLocationResolver(AddOnContentLocationResolver &&rhs) {
virtual Result ResolveAddOnContentPath(sf::Out<Path> out, ncm::ProgramId id); this->interface = std::move(rhs.interface);
virtual Result RegisterAddOnContentStorageDeprecated(ncm::StorageId storage_id, ncm::ProgramId id); }
virtual Result RegisterAddOnContentStorage(ncm::StorageId storage_id, ncm::ProgramId id, ncm::ProgramId application_id);
virtual Result UnregisterAllAddOnContentPath(); AddOnContentLocationResolver &operator=(AddOnContentLocationResolver &&rhs) {
virtual Result RefreshApplicationAddOnContent(const sf::InArray<ncm::ProgramId> &ids); AddOnContentLocationResolver(std::move(rhs)).Swap(*this);
virtual Result UnregisterApplicationAddOnContent(ncm::ProgramId id); return *this;
}
void Swap(AddOnContentLocationResolver &rhs) {
std::swap(this->interface, rhs.interface);
}
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { /* Actual commands. */
MAKE_SERVICE_COMMAND_META(ResolveAddOnContentPath, hos::Version_200), Result ResolveAddOnContentPath(Path *out, ncm::ProgramId id) {
MAKE_SERVICE_COMMAND_META(RegisterAddOnContentStorageDeprecated, hos::Version_200, hos::Version_810), AMS_ASSERT(this->interface);
MAKE_SERVICE_COMMAND_META(RegisterAddOnContentStorage, hos::Version_900), return this->interface->ResolveAddOnContentPath(out, id);
MAKE_SERVICE_COMMAND_META(UnregisterAllAddOnContentPath, hos::Version_200), }
MAKE_SERVICE_COMMAND_META(RefreshApplicationAddOnContent, hos::Version_900),
MAKE_SERVICE_COMMAND_META(UnregisterApplicationAddOnContent, hos::Version_900), Result RegisterAddOnContentStorage(ncm::StorageId storage_id, ncm::ProgramId id, ncm::ProgramId application_id) {
}; AMS_ASSERT(this->interface);
if (hos::GetVersion() >= hos::Version_900) {
return this->interface->RegisterAddOnContentStorage(storage_id, id, application_id);
} else {
return this->interface->RegisterAddOnContentStorageDeprecated(storage_id, id);
}
}
Result UnregisterAllAddOnContentPath() {
AMS_ASSERT(this->interface);
return this->interface->UnregisterAllAddOnContentPath();
}
Result RefreshApplicationAddOnContent(const ncm::ProgramId *ids, size_t num_ids) {
AMS_ASSERT(this->interface);
return this->interface->RefreshApplicationAddOnContent(sf::InArray<ncm::ProgramId>(ids, num_ids));
}
Result UnregisterApplicationAddOnContent(ncm::ProgramId id) {
AMS_ASSERT(this->interface);
return this->interface->UnregisterApplicationAddOnContent(id);
}
}; };
} }

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere/lr/lr_types.hpp>
namespace ams::lr {
class IAddOnContentLocationResolver : public sf::IServiceObject {
protected:
enum class CommandId {
ResolveAddOnContentPath = 0,
RegisterAddOnContentStorageDeprecated = 1,
RegisterAddOnContentStorage = 1,
UnregisterAllAddOnContentPath = 2,
RefreshApplicationAddOnContent = 3,
UnregisterApplicationAddOnContent = 4,
};
public:
/* Actual commands. */
virtual Result ResolveAddOnContentPath(sf::Out<Path> out, ncm::ProgramId id) = 0;
virtual Result RegisterAddOnContentStorageDeprecated(ncm::StorageId storage_id, ncm::ProgramId id) = 0;
virtual Result RegisterAddOnContentStorage(ncm::StorageId storage_id, ncm::ProgramId id, ncm::ProgramId application_id) = 0;
virtual Result UnregisterAllAddOnContentPath() = 0;
virtual Result RefreshApplicationAddOnContent(const sf::InArray<ncm::ProgramId> &ids) = 0;
virtual Result UnregisterApplicationAddOnContent(ncm::ProgramId id) = 0;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(ResolveAddOnContentPath, hos::Version_200),
MAKE_SERVICE_COMMAND_META(RegisterAddOnContentStorageDeprecated, hos::Version_200, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RegisterAddOnContentStorage, hos::Version_900),
MAKE_SERVICE_COMMAND_META(UnregisterAllAddOnContentPath, hos::Version_200),
MAKE_SERVICE_COMMAND_META(RefreshApplicationAddOnContent, hos::Version_900),
MAKE_SERVICE_COMMAND_META(UnregisterApplicationAddOnContent, hos::Version_900),
};
};
}

View File

@ -16,11 +16,12 @@
#pragma once #pragma once
#include <stratosphere/lr/lr_types.hpp> #include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_location_redirector.hpp>
namespace ams::lr { namespace ams::lr {
class ILocationResolver : public sf::IServiceObject { class ILocationResolver : public sf::IServiceObject {
NON_COPYABLE(ILocationResolver);
NON_MOVEABLE(ILocationResolver);
protected: protected:
enum class CommandId { enum class CommandId {
ResolveProgramPath = 0, ResolveProgramPath = 0,
@ -50,30 +51,8 @@ namespace ams::lr {
RedirectApplicationProgramPathForDebug = 18, RedirectApplicationProgramPathForDebug = 18,
EraseProgramRedirectionForDebug = 19, EraseProgramRedirectionForDebug = 19,
}; };
protected: public:
/* Location redirectors. */ ILocationResolver() { /* ... */ }
LocationRedirector program_redirector;
LocationRedirector debug_program_redirector;
LocationRedirector app_control_redirector;
LocationRedirector html_docs_redirector;
LocationRedirector legal_info_redirector;
protected:
/* Helper functions. */
void ClearRedirections(u32 flags = RedirectionFlags_None) {
this->program_redirector.ClearRedirections(flags);
this->debug_program_redirector.ClearRedirections(flags);
this->app_control_redirector.ClearRedirections(flags);
this->html_docs_redirector.ClearRedirections(flags);
this->legal_info_redirector.ClearRedirections(flags);
}
void ClearRedirections(const ncm::ProgramId* excluding_ids, size_t num_ids) {
this->program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
this->debug_program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
this->app_control_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
this->html_docs_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
this->legal_info_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
}
public: public:
/* Actual commands. */ /* Actual commands. */
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) = 0; virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) = 0;
@ -102,6 +81,35 @@ namespace ams::lr {
virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) = 0; virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) = 0;
virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0; virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0;
virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) = 0; virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) = 0;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(ResolveProgramPath),
MAKE_SERVICE_COMMAND_META(RedirectProgramPath),
MAKE_SERVICE_COMMAND_META(ResolveApplicationControlPath),
MAKE_SERVICE_COMMAND_META(ResolveApplicationHtmlDocumentPath),
MAKE_SERVICE_COMMAND_META(ResolveDataPath),
MAKE_SERVICE_COMMAND_META(RedirectApplicationControlPathDeprecated, hos::Version_100, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectApplicationControlPath, hos::Version_900),
MAKE_SERVICE_COMMAND_META(RedirectApplicationHtmlDocumentPathDeprecated, hos::Version_100, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectApplicationHtmlDocumentPath, hos::Version_900),
MAKE_SERVICE_COMMAND_META(ResolveApplicationLegalInformationPath),
MAKE_SERVICE_COMMAND_META(RedirectApplicationLegalInformationPathDeprecated, hos::Version_100, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectApplicationLegalInformationPath, hos::Version_900),
MAKE_SERVICE_COMMAND_META(Refresh),
MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathDeprecated, hos::Version_500, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPath, hos::Version_900),
MAKE_SERVICE_COMMAND_META(ClearApplicationRedirectionDeprecated, hos::Version_500, hos::Version_810),
MAKE_SERVICE_COMMAND_META(ClearApplicationRedirection, hos::Version_900),
MAKE_SERVICE_COMMAND_META(EraseProgramRedirection, hos::Version_500),
MAKE_SERVICE_COMMAND_META(EraseApplicationControlRedirection, hos::Version_500),
MAKE_SERVICE_COMMAND_META(EraseApplicationHtmlDocumentRedirection, hos::Version_500),
MAKE_SERVICE_COMMAND_META(EraseApplicationLegalInformationRedirection, hos::Version_500),
MAKE_SERVICE_COMMAND_META(ResolveProgramPathForDebug, hos::Version_700),
MAKE_SERVICE_COMMAND_META(RedirectProgramPathForDebug, hos::Version_700),
MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathForDebugDeprecated, hos::Version_700, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathForDebug, hos::Version_900),
MAKE_SERVICE_COMMAND_META(EraseProgramRedirectionForDebug, hos::Version_700),
};
}; };
} }

View File

@ -1,83 +0,0 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_i_location_resolver.hpp>
namespace ams::lr {
class ILocationResolverInterface : public ILocationResolver {
public:
/* Actual commands. */
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) = 0;
virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id) = 0;
virtual Result ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) = 0;
virtual Result ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) = 0;
virtual Result ResolveDataPath(sf::Out<Path> out, ncm::ProgramId id) = 0;
virtual Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) = 0;
virtual Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0;
virtual Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) = 0;
virtual Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0;
virtual Result ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) = 0;
virtual Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) = 0;
virtual Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0;
virtual Result Refresh() = 0;
virtual Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) = 0;
virtual Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0;
virtual Result ClearApplicationRedirectionDeprecated() = 0;
virtual Result ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids) = 0;
virtual Result EraseProgramRedirection(ncm::ProgramId id) = 0;
virtual Result EraseApplicationControlRedirection(ncm::ProgramId id) = 0;
virtual Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) = 0;
virtual Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id) = 0;
virtual Result ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) = 0;
virtual Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) = 0;
virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) = 0;
virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0;
virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) = 0;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(ResolveProgramPath),
MAKE_SERVICE_COMMAND_META(RedirectProgramPath),
MAKE_SERVICE_COMMAND_META(ResolveApplicationControlPath),
MAKE_SERVICE_COMMAND_META(ResolveApplicationHtmlDocumentPath),
MAKE_SERVICE_COMMAND_META(ResolveDataPath),
MAKE_SERVICE_COMMAND_META(RedirectApplicationControlPathDeprecated, hos::Version_100, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectApplicationControlPath, hos::Version_900),
MAKE_SERVICE_COMMAND_META(RedirectApplicationHtmlDocumentPathDeprecated, hos::Version_100, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectApplicationHtmlDocumentPath, hos::Version_900),
MAKE_SERVICE_COMMAND_META(ResolveApplicationLegalInformationPath),
MAKE_SERVICE_COMMAND_META(RedirectApplicationLegalInformationPathDeprecated, hos::Version_100, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectApplicationLegalInformationPath, hos::Version_900),
MAKE_SERVICE_COMMAND_META(Refresh),
MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathDeprecated, hos::Version_500, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPath, hos::Version_900),
MAKE_SERVICE_COMMAND_META(ClearApplicationRedirectionDeprecated, hos::Version_500, hos::Version_810),
MAKE_SERVICE_COMMAND_META(ClearApplicationRedirection, hos::Version_900),
MAKE_SERVICE_COMMAND_META(EraseProgramRedirection, hos::Version_500),
MAKE_SERVICE_COMMAND_META(EraseApplicationControlRedirection, hos::Version_500),
MAKE_SERVICE_COMMAND_META(EraseApplicationHtmlDocumentRedirection, hos::Version_500),
MAKE_SERVICE_COMMAND_META(EraseApplicationLegalInformationRedirection, hos::Version_500),
MAKE_SERVICE_COMMAND_META(ResolveProgramPathForDebug, hos::Version_700),
MAKE_SERVICE_COMMAND_META(RedirectProgramPathForDebug, hos::Version_700),
MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathForDebugDeprecated, hos::Version_700, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathForDebug, hos::Version_900),
MAKE_SERVICE_COMMAND_META(EraseProgramRedirectionForDebug, hos::Version_700),
};
};
}

View File

@ -16,9 +16,9 @@
#pragma once #pragma once
#include <stratosphere/lr/lr_types.hpp> #include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_i_location_resolver_interface.hpp> #include <stratosphere/lr/lr_i_location_resolver.hpp>
#include <stratosphere/lr/lr_add_on_content_location_resolver.hpp> #include <stratosphere/lr/lr_i_add_on_content_location_resolver.hpp>
#include <stratosphere/lr/lr_registered_location_resolver.hpp> #include <stratosphere/lr/lr_i_registered_location_resolver.hpp>
namespace ams::lr { namespace ams::lr {
@ -32,10 +32,10 @@ namespace ams::lr {
}; };
public: public:
/* Actual commands. */ /* Actual commands. */
virtual Result OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolverInterface>> out, ncm::StorageId storage_id) = 0; virtual Result OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolver>> out, ncm::StorageId storage_id) = 0;
virtual Result OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<RegisteredLocationResolverInterface>> out) = 0; virtual Result OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<IRegisteredLocationResolver>> out) = 0;
virtual Result RefreshLocationResolver(ncm::StorageId storage_id) = 0; virtual Result RefreshLocationResolver(ncm::StorageId storage_id) = 0;
virtual Result OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<AddOnContentLocationResolverInterface>> out) = 0; virtual Result OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<IAddOnContentLocationResolver>> out) = 0;
}; };
} }

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere/lr/lr_types.hpp>
namespace ams::lr {
class IRegisteredLocationResolver : public sf::IServiceObject {
protected:
enum class CommandId {
ResolveProgramPath = 0,
RegisterProgramPathDeprecated = 1,
RegisterProgramPath = 1,
UnregisterProgramPath = 2,
RedirectProgramPathDeprecated = 3,
RedirectProgramPath = 3,
ResolveHtmlDocumentPath = 4,
RegisterHtmlDocumentPathDeprecated = 5,
RegisterHtmlDocumentPath = 5,
UnregisterHtmlDocumentPath = 6,
RedirectHtmlDocumentPathDeprecated = 7,
RedirectHtmlDocumentPath = 7,
Refresh = 8,
RefreshExcluding = 9,
};
public:
/* Actual commands. */
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) = 0;
virtual Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) = 0;
virtual Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0;
virtual Result UnregisterProgramPath(ncm::ProgramId id) = 0;
virtual Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) = 0;
virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0;
virtual Result ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) = 0;
virtual Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) = 0;
virtual Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0;
virtual Result UnregisterHtmlDocumentPath(ncm::ProgramId id) = 0;
virtual Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) = 0;
virtual Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0;
virtual Result Refresh() = 0;
virtual Result RefreshExcluding(const sf::InArray<ncm::ProgramId> &ids) = 0;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(ResolveProgramPath),
MAKE_SERVICE_COMMAND_META(RegisterProgramPathDeprecated, hos::Version_100, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RegisterProgramPath, hos::Version_900),
MAKE_SERVICE_COMMAND_META(UnregisterProgramPath),
MAKE_SERVICE_COMMAND_META(RedirectProgramPathDeprecated, hos::Version_100, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectProgramPath, hos::Version_900),
MAKE_SERVICE_COMMAND_META(ResolveHtmlDocumentPath, hos::Version_200),
MAKE_SERVICE_COMMAND_META(RegisterHtmlDocumentPathDeprecated, hos::Version_200, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RegisterHtmlDocumentPath, hos::Version_900),
MAKE_SERVICE_COMMAND_META(UnregisterHtmlDocumentPath, hos::Version_200),
MAKE_SERVICE_COMMAND_META(RedirectHtmlDocumentPathDeprecated, hos::Version_200, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectHtmlDocumentPathDeprecated, hos::Version_900),
MAKE_SERVICE_COMMAND_META(Refresh, hos::Version_700),
MAKE_SERVICE_COMMAND_META(RefreshExcluding, hos::Version_900),
};
};
}

View File

@ -0,0 +1,175 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_i_location_resolver.hpp>
namespace ams::lr {
class LocationResolver {
NON_COPYABLE(LocationResolver);
private:
std::shared_ptr<ILocationResolver> interface;
public:
LocationResolver() { /* ... */ }
explicit LocationResolver(std::shared_ptr<ILocationResolver> intf) : interface(std::move(intf)) { /* ... */ }
LocationResolver(LocationResolver &&rhs) {
this->interface = std::move(rhs.interface);
}
LocationResolver &operator=(LocationResolver &&rhs) {
LocationResolver(std::move(rhs)).Swap(*this);
return *this;
}
void Swap(LocationResolver &rhs) {
std::swap(this->interface, rhs.interface);
}
public:
Result ResolveProgramPath(Path *out, ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
return this->interface->ResolveProgramPath(out, id);
}
void RedirectProgramPath(const Path &path, ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
R_ABORT_UNLESS(this->interface->RedirectProgramPath(path, id));
}
Result ResolveApplicationControlPath(Path *out, ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
return this->interface->ResolveApplicationControlPath(out, id);
}
Result ResolveApplicationHtmlDocumentPath(Path *out, ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
return this->interface->ResolveApplicationHtmlDocumentPath(out, id);
}
Result ResolveDataPath(Path *out, ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
return this->interface->ResolveDataPath(out, id);
}
void RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
AMS_ASSERT(this->interface != nullptr);
if (hos::GetVersion() >= hos::Version_900) {
R_ABORT_UNLESS(this->interface->RedirectApplicationControlPath(path, id, owner_id));
} else {
R_ABORT_UNLESS(this->interface->RedirectApplicationControlPathDeprecated(path, id));
}
}
void RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
AMS_ASSERT(this->interface != nullptr);
if (hos::GetVersion() >= hos::Version_900) {
R_ABORT_UNLESS(this->interface->RedirectApplicationHtmlDocumentPath(path, id, owner_id));
} else {
R_ABORT_UNLESS(this->interface->RedirectApplicationHtmlDocumentPathDeprecated(path, id));
}
}
Result ResolveApplicationLegalInformationPath(Path *out, ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
return this->interface->ResolveApplicationLegalInformationPath(out, id);
}
void RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
AMS_ASSERT(this->interface != nullptr);
if (hos::GetVersion() >= hos::Version_900) {
R_ABORT_UNLESS(this->interface->RedirectApplicationLegalInformationPath(path, id, owner_id));
} else {
R_ABORT_UNLESS(this->interface->RedirectApplicationLegalInformationPathDeprecated(path, id));
}
}
Result Refresh() {
AMS_ASSERT(this->interface != nullptr);
return this->interface->Refresh();
}
void RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
AMS_ASSERT(this->interface != nullptr);
if (hos::GetVersion() >= hos::Version_900) {
R_ABORT_UNLESS(this->interface->RedirectApplicationProgramPath(path, id, owner_id));
} else {
R_ABORT_UNLESS(this->interface->RedirectApplicationProgramPathDeprecated(path, id));
}
}
Result ClearApplicationRedirection() {
AMS_ASSERT(this->interface != nullptr);
AMS_ASSERT(hos::GetVersion() < hos::Version_900);
return this->ClearApplicationRedirection(nullptr, 0);
}
Result ClearApplicationRedirection(const ncm::ProgramId *excluding_ids, size_t num_ids) {
AMS_ASSERT(this->interface != nullptr);
if (hos::GetVersion() >= hos::Version_900) {
return this->interface->ClearApplicationRedirection(sf::InArray<ncm::ProgramId>(excluding_ids, num_ids));
} else {
return this->interface->ClearApplicationRedirectionDeprecated();
}
}
Result EraseProgramRedirection(ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
return this->interface->EraseProgramRedirection(id);
}
Result EraseApplicationControlRedirection(ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
return this->interface->EraseApplicationControlRedirection(id);
}
Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
return this->interface->EraseApplicationHtmlDocumentRedirection(id);
}
Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
return this->interface->EraseApplicationLegalInformationRedirection(id);
}
Result ResolveProgramPathForDebug(Path *out, ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
return this->interface->ResolveProgramPathForDebug(out, id);
}
void RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
R_ABORT_UNLESS(this->interface->RedirectProgramPathForDebug(path, id));
}
void RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
AMS_ASSERT(this->interface != nullptr);
if (hos::GetVersion() >= hos::Version_900) {
R_ABORT_UNLESS(this->interface->RedirectApplicationProgramPathForDebug(path, id, owner_id));
} else {
R_ABORT_UNLESS(this->interface->RedirectApplicationProgramPathForDebugDeprecated(path, id));
}
}
Result EraseProgramRedirectionForDebug(ncm::ProgramId id) {
AMS_ASSERT(this->interface != nullptr);
return this->interface->EraseProgramRedirectionForDebug(id);
}
};
}

View File

@ -24,17 +24,17 @@ namespace ams::lr {
class LocationResolverManagerImpl final : public ILocationResolverManager { class LocationResolverManagerImpl final : public ILocationResolverManager {
private: private:
/* Resolver storage. */ /* Resolver storage. */
ncm::BoundedMap<ncm::StorageId, std::shared_ptr<ILocationResolverInterface>, 5> location_resolvers; ncm::BoundedMap<ncm::StorageId, std::shared_ptr<ILocationResolver>, 5> location_resolvers;
std::shared_ptr<RegisteredLocationResolverInterface> registered_location_resolver = nullptr; std::shared_ptr<IRegisteredLocationResolver> registered_location_resolver = nullptr;
std::shared_ptr<AddOnContentLocationResolverInterface> add_on_content_location_resolver = nullptr; std::shared_ptr<IAddOnContentLocationResolver> add_on_content_location_resolver = nullptr;
os::Mutex mutex; os::Mutex mutex;
public: public:
/* Actual commands. */ /* Actual commands. */
virtual Result OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolverInterface>> out, ncm::StorageId storage_id) override; virtual Result OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolver>> out, ncm::StorageId storage_id) override;
virtual Result OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<RegisteredLocationResolverInterface>> out) override; virtual Result OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<IRegisteredLocationResolver>> out) override;
virtual Result RefreshLocationResolver(ncm::StorageId storage_id) override; virtual Result RefreshLocationResolver(ncm::StorageId storage_id) override;
virtual Result OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<AddOnContentLocationResolverInterface>> out) override; virtual Result OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<IAddOnContentLocationResolver>> out) override;
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(OpenLocationResolver), MAKE_SERVICE_COMMAND_META(OpenLocationResolver),

View File

@ -16,77 +16,98 @@
#pragma once #pragma once
#include <stratosphere/lr/lr_types.hpp> #include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_location_redirector.hpp> #include <stratosphere/lr/lr_i_registered_location_resolver.hpp>
#include <stratosphere/lr/lr_registered_data.hpp>
namespace ams::lr { namespace ams::lr {
class RegisteredLocationResolverInterface final : public sf::IServiceObject { class RegisteredLocationResolver {
NON_COPYABLE(RegisteredLocationResolver);
private: private:
static constexpr size_t MaxRegisteredLocations = 0x20; std::shared_ptr<IRegisteredLocationResolver> interface;
protected:
enum class CommandId {
ResolveProgramPath = 0,
RegisterProgramPathDeprecated = 1,
RegisterProgramPath = 1,
UnregisterProgramPath = 2,
RedirectProgramPathDeprecated = 3,
RedirectProgramPath = 3,
ResolveHtmlDocumentPath = 4,
RegisterHtmlDocumentPathDeprecated = 5,
RegisterHtmlDocumentPath = 5,
UnregisterHtmlDocumentPath = 6,
RedirectHtmlDocumentPathDeprecated = 7,
RedirectHtmlDocumentPath = 7,
Refresh = 8,
RefreshExcluding = 9,
};
private:
/* Redirection and registered location storage. */
LocationRedirector program_redirector;
RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations> registered_program_locations;
LocationRedirector html_docs_redirector;
RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations> registered_html_docs_locations;
private:
/* Helper functions. */
void ClearRedirections(u32 flags = RedirectionFlags_None);
Result RefreshImpl(const ncm::ProgramId* excluding_ids, size_t num_ids);
public: public:
RegisteredLocationResolverInterface() : registered_program_locations(hos::GetVersion() < hos::Version_900 ? 0x10 : MaxRegisteredLocations), registered_html_docs_locations(hos::GetVersion() < hos::Version_900 ? 0x10 : MaxRegisteredLocations) { /* ... */ } RegisteredLocationResolver() { /* ... */ }
~RegisteredLocationResolverInterface(); explicit RegisteredLocationResolver(std::shared_ptr<IRegisteredLocationResolver> intf) : interface(std::move(intf)) { /* ... */ }
/* Actual commands. */ RegisteredLocationResolver(RegisteredLocationResolver &&rhs) {
Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id); this->interface = std::move(rhs.interface);
Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id); }
Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id);
Result UnregisterProgramPath(ncm::ProgramId id); RegisteredLocationResolver &operator=(RegisteredLocationResolver &&rhs) {
Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id); RegisteredLocationResolver(std::move(rhs)).Swap(*this);
Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); return *this;
Result ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id); }
Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id);
Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); void Swap(RegisteredLocationResolver &rhs) {
Result UnregisterHtmlDocumentPath(ncm::ProgramId id); std::swap(this->interface, rhs.interface);
Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id); }
Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id);
Result Refresh();
Result RefreshExcluding(const sf::InArray<ncm::ProgramId> &ids);
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { /* Actual commands. */
MAKE_SERVICE_COMMAND_META(ResolveProgramPath), Result ResolveProgramPath(Path *out, ncm::ProgramId id) {
MAKE_SERVICE_COMMAND_META(RegisterProgramPathDeprecated, hos::Version_100, hos::Version_810), AMS_ASSERT(this->interface);
MAKE_SERVICE_COMMAND_META(RegisterProgramPath, hos::Version_900), return this->interface->ResolveProgramPath(out, id);
MAKE_SERVICE_COMMAND_META(UnregisterProgramPath), }
MAKE_SERVICE_COMMAND_META(RedirectProgramPathDeprecated, hos::Version_100, hos::Version_810),
MAKE_SERVICE_COMMAND_META(RedirectProgramPath, hos::Version_900), Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
MAKE_SERVICE_COMMAND_META(ResolveHtmlDocumentPath, hos::Version_200), AMS_ASSERT(this->interface);
MAKE_SERVICE_COMMAND_META(RegisterHtmlDocumentPathDeprecated, hos::Version_200, hos::Version_810), if (hos::GetVersion() >= hos::Version_900) {
MAKE_SERVICE_COMMAND_META(RegisterHtmlDocumentPath, hos::Version_900), return this->interface->RegisterProgramPath(path, id, owner_id);
MAKE_SERVICE_COMMAND_META(UnregisterHtmlDocumentPath, hos::Version_200), } else {
MAKE_SERVICE_COMMAND_META(RedirectHtmlDocumentPathDeprecated, hos::Version_200, hos::Version_810), return this->interface->RegisterProgramPathDeprecated(path, id);
MAKE_SERVICE_COMMAND_META(RedirectHtmlDocumentPathDeprecated, hos::Version_900), }
MAKE_SERVICE_COMMAND_META(Refresh, hos::Version_700), }
MAKE_SERVICE_COMMAND_META(RefreshExcluding, hos::Version_900),
}; Result UnregisterProgramPath(ncm::ProgramId id) {
AMS_ASSERT(this->interface);
return this->interface->UnregisterProgramPath(id);
}
void RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
AMS_ASSERT(this->interface);
if (hos::GetVersion() >= hos::Version_900) {
R_ABORT_UNLESS(this->interface->RedirectProgramPath(path, id, owner_id));
} else {
R_ABORT_UNLESS(this->interface->RedirectProgramPathDeprecated(path, id));
}
}
Result ResolveHtmlDocumentPath(Path *out, ncm::ProgramId id) {
AMS_ASSERT(this->interface);
return this->interface->ResolveHtmlDocumentPath(out, id);
}
Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
AMS_ASSERT(this->interface);
if (hos::GetVersion() >= hos::Version_900) {
return this->interface->RegisterHtmlDocumentPath(path, id, owner_id);
} else {
return this->interface->RegisterHtmlDocumentPathDeprecated(path, id);
}
}
Result UnregisterHtmlDocumentPath(ncm::ProgramId id) {
AMS_ASSERT(this->interface);
return this->interface->UnregisterHtmlDocumentPath(id);
}
void RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
AMS_ASSERT(this->interface);
if (hos::GetVersion() >= hos::Version_900) {
R_ABORT_UNLESS(this->interface->RedirectHtmlDocumentPath(path, id, owner_id));
} else {
R_ABORT_UNLESS(this->interface->RedirectHtmlDocumentPathDeprecated(path, id));
}
}
Result Refresh() {
AMS_ASSERT(this->interface);
return this->interface->Refresh();
}
Result RefreshExcluding(const ncm::ProgramId *excluding_ids, size_t num_ids) {
AMS_ASSERT(this->interface);
return this->interface->RefreshExcluding(sf::InArray<ncm::ProgramId>(excluding_ids, num_ids));
}
}; };
} }

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_location_resolver.hpp>
#include <stratosphere/lr/lr_add_on_content_location_resolver.hpp>
#include <stratosphere/lr/lr_registered_location_resolver.hpp>
namespace ams::lr {
/* Management. */
void Initialize();
void Finalize();
/* Service API. */
Result OpenLocationResolver(LocationResolver *out, ncm::StorageId storage_id);
Result OpenRegisteredLocationResolver(RegisteredLocationResolver *out);
Result OpenAddOnContentLocationResolver(AddOnContentLocationResolver *out);
Result RefreshLocationResolver(ncm::StorageId storage_id);
}

View File

@ -17,3 +17,5 @@
#pragma once #pragma once
#include "ncm/ncm_types.hpp" #include "ncm/ncm_types.hpp"
#include "ncm/ncm_i_content_meta_database.hpp"
#include "ncm/ncm_i_content_storage.hpp"

View File

@ -16,7 +16,8 @@
#pragma once #pragma once
#include <stratosphere/ncm/ncm_types.hpp> #include <stratosphere/ncm/ncm_types.hpp>
#include <stratosphere/kvdb/kvdb_memory_key_value_store.hpp> #include <stratosphere/sf.hpp>
#include <stratosphere/kvdb.hpp>
namespace ams::ncm { namespace ams::ncm {

View File

@ -16,6 +16,8 @@
#pragma once #pragma once
#include <stratosphere/ncm/ncm_types.hpp> #include <stratosphere/ncm/ncm_types.hpp>
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/sf.hpp>
namespace ams::ncm { namespace ams::ncm {

View File

@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "lr_add_on_content_location_resolver_impl.hpp"
/* TODO: Properly integrate NCM api into libstratosphere to avoid linker hack. */ /* TODO: Properly integrate NCM api into libstratosphere to avoid linker hack. */
namespace ams::ncm::impl { namespace ams::ncm::impl {
@ -25,7 +26,7 @@ namespace ams::ncm::impl {
namespace ams::lr { namespace ams::lr {
Result AddOnContentLocationResolverInterface::ResolveAddOnContentPath(sf::Out<Path> out, ncm::ProgramId id) { Result AddOnContentLocationResolverImpl::ResolveAddOnContentPath(sf::Out<Path> out, ncm::ProgramId id) {
/* Find a storage that contains the given program id. */ /* Find a storage that contains the given program id. */
ncm::StorageId storage_id = ncm::StorageId::None; ncm::StorageId storage_id = ncm::StorageId::None;
R_UNLESS(this->registered_storages.Find(&storage_id, id), lr::ResultAddOnContentNotFound()); R_UNLESS(this->registered_storages.Find(&storage_id, id), lr::ResultAddOnContentNotFound());
@ -48,24 +49,24 @@ namespace ams::lr {
return ResultSuccess(); return ResultSuccess();
} }
Result AddOnContentLocationResolverInterface::RegisterAddOnContentStorageDeprecated(ncm::StorageId storage_id, ncm::ProgramId id) { Result AddOnContentLocationResolverImpl::RegisterAddOnContentStorageDeprecated(ncm::StorageId storage_id, ncm::ProgramId id) {
/* Register storage for the given program id. 2.0.0-8.1.0 did not require an owner application id. */ /* Register storage for the given program id. 2.0.0-8.1.0 did not require an owner application id. */
R_UNLESS(this->registered_storages.Register(id, storage_id, ncm::ProgramId::Invalid), lr::ResultTooManyRegisteredPaths()); R_UNLESS(this->registered_storages.Register(id, storage_id, ncm::ProgramId::Invalid), lr::ResultTooManyRegisteredPaths());
return ResultSuccess(); return ResultSuccess();
} }
Result AddOnContentLocationResolverInterface::RegisterAddOnContentStorage(ncm::StorageId storage_id, ncm::ProgramId id, ncm::ProgramId application_id) { Result AddOnContentLocationResolverImpl::RegisterAddOnContentStorage(ncm::StorageId storage_id, ncm::ProgramId id, ncm::ProgramId application_id) {
/* Register storage for the given program id and owner application. */ /* Register storage for the given program id and owner application. */
R_UNLESS(this->registered_storages.Register(id, storage_id, application_id), lr::ResultTooManyRegisteredPaths()); R_UNLESS(this->registered_storages.Register(id, storage_id, application_id), lr::ResultTooManyRegisteredPaths());
return ResultSuccess(); return ResultSuccess();
} }
Result AddOnContentLocationResolverInterface::UnregisterAllAddOnContentPath() { Result AddOnContentLocationResolverImpl::UnregisterAllAddOnContentPath() {
this->registered_storages.Clear(); this->registered_storages.Clear();
return ResultSuccess(); return ResultSuccess();
} }
Result AddOnContentLocationResolverInterface::RefreshApplicationAddOnContent(const sf::InArray<ncm::ProgramId> &ids) { Result AddOnContentLocationResolverImpl::RefreshApplicationAddOnContent(const sf::InArray<ncm::ProgramId> &ids) {
if (ids.GetSize() == 0) { if (ids.GetSize() == 0) {
/* Clear all registered storages. */ /* Clear all registered storages. */
this->registered_storages.Clear(); this->registered_storages.Clear();
@ -77,7 +78,7 @@ namespace ams::lr {
return ResultSuccess(); return ResultSuccess();
} }
Result AddOnContentLocationResolverInterface::UnregisterApplicationAddOnContent(ncm::ProgramId id) { Result AddOnContentLocationResolverImpl::UnregisterApplicationAddOnContent(ncm::ProgramId id) {
/* Remove entries belonging to the provided application. */ /* Remove entries belonging to the provided application. */
this->registered_storages.UnregisterOwnerProgram(id); this->registered_storages.UnregisterOwnerProgram(id);
return ResultSuccess(); return ResultSuccess();

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
#include "lr_location_redirector.hpp"
#include "lr_registered_data.hpp"
namespace ams::lr {
class AddOnContentLocationResolverImpl : public IAddOnContentLocationResolver {
private:
/* Storage for RegisteredData entries by program id. */
RegisteredStorages<ncm::ProgramId, 0x800> registered_storages;
public:
AddOnContentLocationResolverImpl() : registered_storages(hos::GetVersion() < hos::Version_900 ? 0x800 : 0x2) { /* ... */ }
/* Actual commands. */
virtual Result ResolveAddOnContentPath(sf::Out<Path> out, ncm::ProgramId id) override;
virtual Result RegisterAddOnContentStorageDeprecated(ncm::StorageId storage_id, ncm::ProgramId id) override;
virtual Result RegisterAddOnContentStorage(ncm::StorageId storage_id, ncm::ProgramId id, ncm::ProgramId application_id) override;
virtual Result UnregisterAllAddOnContentPath() override;
virtual Result RefreshApplicationAddOnContent(const sf::InArray<ncm::ProgramId> &ids) override;
virtual Result UnregisterApplicationAddOnContent(ncm::ProgramId id) override;
};
}

View File

@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "lr_content_location_resolver_impl.hpp"
/* TODO: Properly integrate NCM api into libstratosphere to avoid linker hack. */ /* TODO: Properly integrate NCM api into libstratosphere to avoid linker hack. */
namespace ams::ncm::impl { namespace ams::ncm::impl {
@ -25,16 +26,16 @@ namespace ams::ncm::impl {
namespace ams::lr { namespace ams::lr {
ContentLocationResolverInterface::~ContentLocationResolverInterface() { ContentLocationResolverImpl::~ContentLocationResolverImpl() {
this->ClearRedirections(); this->ClearRedirections();
} }
/* Helper function. */ /* Helper function. */
void ContentLocationResolverInterface::GetContentStoragePath(Path* out, ncm::ContentId content_id) { void ContentLocationResolverImpl::GetContentStoragePath(Path* out, ncm::ContentId content_id) {
R_ABORT_UNLESS(this->content_storage->GetPath(out, content_id)); R_ABORT_UNLESS(this->content_storage->GetPath(out, content_id));
} }
Result ContentLocationResolverInterface::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) { Result ContentLocationResolverImpl::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) {
/* Use a redirection if present. */ /* Use a redirection if present. */
R_UNLESS(!this->program_redirector.FindRedirection(out.GetPointer(), id), ResultSuccess()); R_UNLESS(!this->program_redirector.FindRedirection(out.GetPointer(), id), ResultSuccess());
@ -50,22 +51,22 @@ namespace ams::lr {
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::RedirectProgramPath(const Path &path, ncm::ProgramId id) { Result ContentLocationResolverImpl::RedirectProgramPath(const Path &path, ncm::ProgramId id) {
this->program_redirector.SetRedirection(id, path); this->program_redirector.SetRedirection(id, path);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) { Result ContentLocationResolverImpl::ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) {
R_UNLESS(this->app_control_redirector.FindRedirection(out.GetPointer(), id), lr::ResultControlNotFound()); R_UNLESS(this->app_control_redirector.FindRedirection(out.GetPointer(), id), lr::ResultControlNotFound());
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) { Result ContentLocationResolverImpl::ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) {
R_UNLESS(this->html_docs_redirector.FindRedirection(out.GetPointer(), id), lr::ResultHtmlDocumentNotFound()); R_UNLESS(this->html_docs_redirector.FindRedirection(out.GetPointer(), id), lr::ResultHtmlDocumentNotFound());
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::ResolveDataPath(sf::Out<Path> out, ncm::ProgramId id) { Result ContentLocationResolverImpl::ResolveDataPath(sf::Out<Path> out, ncm::ProgramId id) {
/* Find the latest data content for the program id. */ /* Find the latest data content for the program id. */
ncm::ContentId data_content_id; ncm::ContentId data_content_id;
R_TRY(this->content_meta_database->GetLatestData(&data_content_id, id)); R_TRY(this->content_meta_database->GetLatestData(&data_content_id, id));
@ -76,42 +77,42 @@ namespace ams::lr {
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) { Result ContentLocationResolverImpl::RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) {
this->app_control_redirector.SetRedirection(id, path, RedirectionFlags_Application); this->app_control_redirector.SetRedirection(id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result ContentLocationResolverImpl::RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
this->app_control_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); this->app_control_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { Result ContentLocationResolverImpl::RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) {
this->html_docs_redirector.SetRedirection(id, path, RedirectionFlags_Application); this->html_docs_redirector.SetRedirection(id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result ContentLocationResolverImpl::RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
this->html_docs_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); this->html_docs_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) { Result ContentLocationResolverImpl::ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) {
R_UNLESS(this->legal_info_redirector.FindRedirection(out.GetPointer(), id), lr::ResultLegalInformationNotFound()); R_UNLESS(this->legal_info_redirector.FindRedirection(out.GetPointer(), id), lr::ResultLegalInformationNotFound());
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) { Result ContentLocationResolverImpl::RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) {
this->legal_info_redirector.SetRedirection(id, path, RedirectionFlags_Application); this->legal_info_redirector.SetRedirection(id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result ContentLocationResolverImpl::RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
this->legal_info_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); this->legal_info_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::Refresh() { Result ContentLocationResolverImpl::Refresh() {
/* Obtain Content Meta Database and Content Storage objects for this resolver's storage. */ /* Obtain Content Meta Database and Content Storage objects for this resolver's storage. */
std::shared_ptr<ncm::IContentMetaDatabase> content_meta_database; std::shared_ptr<ncm::IContentMetaDatabase> content_meta_database;
std::shared_ptr<ncm::IContentStorage> content_storage; std::shared_ptr<ncm::IContentStorage> content_storage;
@ -128,47 +129,47 @@ namespace ams::lr {
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) { Result ContentLocationResolverImpl::RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) {
this->program_redirector.SetRedirection(id, path, RedirectionFlags_Application); this->program_redirector.SetRedirection(id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result ContentLocationResolverImpl::RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
this->program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); this->program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::ClearApplicationRedirectionDeprecated() { Result ContentLocationResolverImpl::ClearApplicationRedirectionDeprecated() {
this->ClearRedirections(RedirectionFlags_Application); this->ClearRedirections(RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids) { Result ContentLocationResolverImpl::ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids) {
this->ClearRedirectionsExcludingOwners(excluding_ids.GetPointer(), excluding_ids.GetSize()); this->ClearRedirections(excluding_ids.GetPointer(), excluding_ids.GetSize());
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::EraseProgramRedirection(ncm::ProgramId id) { Result ContentLocationResolverImpl::EraseProgramRedirection(ncm::ProgramId id) {
this->program_redirector.EraseRedirection(id); this->program_redirector.EraseRedirection(id);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::EraseApplicationControlRedirection(ncm::ProgramId id) { Result ContentLocationResolverImpl::EraseApplicationControlRedirection(ncm::ProgramId id) {
this->app_control_redirector.EraseRedirection(id); this->app_control_redirector.EraseRedirection(id);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) { Result ContentLocationResolverImpl::EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) {
this->html_docs_redirector.EraseRedirection(id); this->html_docs_redirector.EraseRedirection(id);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::EraseApplicationLegalInformationRedirection(ncm::ProgramId id) { Result ContentLocationResolverImpl::EraseApplicationLegalInformationRedirection(ncm::ProgramId id) {
this->legal_info_redirector.EraseRedirection(id); this->legal_info_redirector.EraseRedirection(id);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) { Result ContentLocationResolverImpl::ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) {
/* Use a redirection if present. */ /* Use a redirection if present. */
R_UNLESS(!this->debug_program_redirector.FindRedirection(out.GetPointer(), id), ResultSuccess()); R_UNLESS(!this->debug_program_redirector.FindRedirection(out.GetPointer(), id), ResultSuccess());
@ -180,22 +181,22 @@ namespace ams::lr {
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) { Result ContentLocationResolverImpl::RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) {
this->debug_program_redirector.SetRedirection(id, path); this->debug_program_redirector.SetRedirection(id, path);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) { Result ContentLocationResolverImpl::RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) {
this->debug_program_redirector.SetRedirection(id, path, RedirectionFlags_Application); this->debug_program_redirector.SetRedirection(id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result ContentLocationResolverImpl::RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
this->debug_program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); this->debug_program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentLocationResolverInterface::EraseProgramRedirectionForDebug(ncm::ProgramId id) { Result ContentLocationResolverImpl::EraseProgramRedirectionForDebug(ncm::ProgramId id) {
this->debug_program_redirector.EraseRedirection(id); this->debug_program_redirector.EraseRedirection(id);
return ResultSuccess(); return ResultSuccess();
} }

View File

@ -15,14 +15,11 @@
*/ */
#pragma once #pragma once
#include <stratosphere/lr/lr_types.hpp> #include "lr_location_resolver_impl_base.hpp"
#include <stratosphere/lr/lr_i_location_resolver_interface.hpp>
#include <stratosphere/ncm/ncm_i_content_meta_database.hpp>
#include <stratosphere/ncm/ncm_i_content_storage.hpp>
namespace ams::lr { namespace ams::lr {
class ContentLocationResolverInterface : public ILocationResolverInterface { class ContentLocationResolverImpl : public LocationResolverImplBase {
private: private:
ncm::StorageId storage_id; ncm::StorageId storage_id;
@ -30,9 +27,9 @@ namespace ams::lr {
std::shared_ptr<ncm::IContentMetaDatabase> content_meta_database; std::shared_ptr<ncm::IContentMetaDatabase> content_meta_database;
std::shared_ptr<ncm::IContentStorage> content_storage; std::shared_ptr<ncm::IContentStorage> content_storage;
public: public:
ContentLocationResolverInterface(ncm::StorageId storage_id) : storage_id(storage_id) { /* ... */ } ContentLocationResolverImpl(ncm::StorageId storage_id) : storage_id(storage_id) { /* ... */ }
~ContentLocationResolverInterface(); ~ContentLocationResolverImpl();
private: private:
/* Helper functions. */ /* Helper functions. */
void GetContentStoragePath(Path* out, ncm::ContentId content_id); void GetContentStoragePath(Path* out, ncm::ContentId content_id);

View File

@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "lr_location_redirector.hpp"
namespace ams::lr { namespace ams::lr {
@ -68,7 +69,7 @@ namespace ams::lr {
void LocationRedirector::SetRedirection(ncm::ProgramId program_id, ncm::ProgramId owner_id, const Path &path, u32 flags) { void LocationRedirector::SetRedirection(ncm::ProgramId program_id, ncm::ProgramId owner_id, const Path &path, u32 flags) {
/* Remove any existing redirections for this program id. */ /* Remove any existing redirections for this program id. */
this->EraseRedirection(program_id); this->EraseRedirection(program_id);
/* Insert a new redirection into the list. */ /* Insert a new redirection into the list. */
this->redirection_list.push_back(*(new Redirection(program_id, owner_id, path, flags))); this->redirection_list.push_back(*(new Redirection(program_id, owner_id, path, flags)));
} }
@ -83,7 +84,7 @@ namespace ams::lr {
} }
} }
void LocationRedirector::EraseRedirection(ncm::ProgramId program_id) void LocationRedirector::EraseRedirection(ncm::ProgramId program_id)
{ {
/* Remove any redirections with a matching program id. */ /* Remove any redirections with a matching program id. */
for (auto &redirection : this->redirection_list) { for (auto &redirection : this->redirection_list) {

View File

@ -15,7 +15,7 @@
*/ */
#pragma once #pragma once
#include <stratosphere/lr/lr_types.hpp> #include <stratosphere.hpp>
namespace ams::lr { namespace ams::lr {

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
#include "lr_location_redirector.hpp"
namespace ams::lr {
class LocationResolverImplBase : public ILocationResolver {
NON_COPYABLE(LocationResolverImplBase);
NON_MOVEABLE(LocationResolverImplBase);
protected:
/* Location redirectors. */
LocationRedirector program_redirector;
LocationRedirector debug_program_redirector;
LocationRedirector app_control_redirector;
LocationRedirector html_docs_redirector;
LocationRedirector legal_info_redirector;
protected:
LocationResolverImplBase() : program_redirector(), debug_program_redirector(), app_control_redirector(), html_docs_redirector(), legal_info_redirector() { /* ... */ }
protected:
/* Helper functions. */
void ClearRedirections(u32 flags = RedirectionFlags_None) {
this->program_redirector.ClearRedirections(flags);
this->debug_program_redirector.ClearRedirections(flags);
this->app_control_redirector.ClearRedirections(flags);
this->html_docs_redirector.ClearRedirections(flags);
this->legal_info_redirector.ClearRedirections(flags);
}
void ClearRedirections(const ncm::ProgramId* excluding_ids, size_t num_ids) {
this->program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
this->debug_program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
this->app_control_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
this->html_docs_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
this->legal_info_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
}
};
}

View File

@ -14,10 +14,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/lr/lr_location_resolver_manager_impl.hpp>
#include "lr_content_location_resolver_impl.hpp"
#include "lr_redirect_only_location_resolver_impl.hpp"
#include "lr_add_on_content_location_resolver_impl.hpp"
#include "lr_registered_location_resolver_impl.hpp"
namespace ams::lr { namespace ams::lr {
Result LocationResolverManagerImpl::OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolverInterface>> out, ncm::StorageId storage_id) { Result LocationResolverManagerImpl::OpenLocationResolver(sf::Out<std::shared_ptr<ILocationResolver>> out, ncm::StorageId storage_id) {
std::scoped_lock lk(this->mutex); std::scoped_lock lk(this->mutex);
/* Find an existing resolver. */ /* Find an existing resolver. */
auto resolver = this->location_resolvers.Find(storage_id); auto resolver = this->location_resolvers.Find(storage_id);
@ -25,9 +30,9 @@ namespace ams::lr {
/* No existing resolver is present, create one. */ /* No existing resolver is present, create one. */
if (!resolver) { if (!resolver) {
if (storage_id == ncm::StorageId::Host) { if (storage_id == ncm::StorageId::Host) {
this->location_resolvers[storage_id] = std::make_shared<RedirectOnlyLocationResolverInterface>(); this->location_resolvers[storage_id] = std::make_shared<RedirectOnlyLocationResolverImpl>();
} else { } else {
auto content_resolver = std::make_shared<ContentLocationResolverInterface>(storage_id); auto content_resolver = std::make_shared<ContentLocationResolverImpl>(storage_id);
R_TRY(content_resolver->Refresh()); R_TRY(content_resolver->Refresh());
this->location_resolvers[storage_id] = std::move(content_resolver); this->location_resolvers[storage_id] = std::move(content_resolver);
} }
@ -37,21 +42,21 @@ namespace ams::lr {
} }
/* Copy the output interface. */ /* Copy the output interface. */
std::shared_ptr<ILocationResolverInterface> new_intf = *resolver; std::shared_ptr<ILocationResolver> new_intf = *resolver;
out.SetValue(std::move(new_intf)); out.SetValue(std::move(new_intf));
return ResultSuccess(); return ResultSuccess();
} }
Result LocationResolverManagerImpl::OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<RegisteredLocationResolverInterface>> out) { Result LocationResolverManagerImpl::OpenRegisteredLocationResolver(sf::Out<std::shared_ptr<IRegisteredLocationResolver>> out) {
std::scoped_lock lk(this->mutex); std::scoped_lock lk(this->mutex);
/* No existing resolver is present, create one. */ /* No existing resolver is present, create one. */
if (!this->registered_location_resolver) { if (!this->registered_location_resolver) {
this->registered_location_resolver = std::make_shared<RegisteredLocationResolverInterface>(); this->registered_location_resolver = std::make_shared<RegisteredLocationResolverImpl>();
} }
/* Copy the output interface. */ /* Copy the output interface. */
std::shared_ptr<RegisteredLocationResolverInterface> new_intf = this->registered_location_resolver; std::shared_ptr<IRegisteredLocationResolver> new_intf = this->registered_location_resolver;
out.SetValue(std::move(new_intf)); out.SetValue(std::move(new_intf));
return ResultSuccess(); return ResultSuccess();
} }
@ -71,16 +76,16 @@ namespace ams::lr {
return ResultSuccess(); return ResultSuccess();
} }
Result LocationResolverManagerImpl::OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<AddOnContentLocationResolverInterface>> out) { Result LocationResolverManagerImpl::OpenAddOnContentLocationResolver(sf::Out<std::shared_ptr<IAddOnContentLocationResolver>> out) {
std::scoped_lock lk(this->mutex); std::scoped_lock lk(this->mutex);
/* No existing resolver is present, create one. */ /* No existing resolver is present, create one. */
if (!this->add_on_content_location_resolver) { if (!this->add_on_content_location_resolver) {
this->add_on_content_location_resolver = std::make_shared<AddOnContentLocationResolverInterface>(); this->add_on_content_location_resolver = std::make_shared<AddOnContentLocationResolverImpl>();
} }
/* Copy the output interface. */ /* Copy the output interface. */
std::shared_ptr<AddOnContentLocationResolverInterface> new_intf = this->add_on_content_location_resolver; std::shared_ptr<IAddOnContentLocationResolver> new_intf = this->add_on_content_location_resolver;
out.SetValue(std::move(new_intf)); out.SetValue(std::move(new_intf));
return ResultSuccess(); return ResultSuccess();
} }

View File

@ -14,119 +14,120 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "lr_redirect_only_location_resolver_impl.hpp"
namespace ams::lr { namespace ams::lr {
RedirectOnlyLocationResolverInterface::~RedirectOnlyLocationResolverInterface() { RedirectOnlyLocationResolverImpl::~RedirectOnlyLocationResolverImpl() {
/* Ensure entries are deallocated */ /* Ensure entries are deallocated */
this->ClearRedirections(); this->ClearRedirections();
} }
Result RedirectOnlyLocationResolverInterface::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) {
R_UNLESS(this->program_redirector.FindRedirection(out.GetPointer(), id), lr::ResultProgramNotFound()); R_UNLESS(this->program_redirector.FindRedirection(out.GetPointer(), id), lr::ResultProgramNotFound());
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::RedirectProgramPath(const Path &path, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::RedirectProgramPath(const Path &path, ncm::ProgramId id) {
this->program_redirector.SetRedirection(id, path); this->program_redirector.SetRedirection(id, path);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) {
R_UNLESS(this->app_control_redirector.FindRedirection(out.GetPointer(), id), lr::ResultControlNotFound()); R_UNLESS(this->app_control_redirector.FindRedirection(out.GetPointer(), id), lr::ResultControlNotFound());
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) {
R_UNLESS(this->html_docs_redirector.FindRedirection(out.GetPointer(), id), lr::ResultHtmlDocumentNotFound()); R_UNLESS(this->html_docs_redirector.FindRedirection(out.GetPointer(), id), lr::ResultHtmlDocumentNotFound());
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::ResolveDataPath(sf::Out<Path> out, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::ResolveDataPath(sf::Out<Path> out, ncm::ProgramId id) {
return ResultDataNotFound(); return ResultDataNotFound();
} }
Result RedirectOnlyLocationResolverInterface::RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) {
this->app_control_redirector.SetRedirection(id, path, RedirectionFlags_Application); this->app_control_redirector.SetRedirection(id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result RedirectOnlyLocationResolverImpl::RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
this->app_control_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); this->app_control_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) {
this->html_docs_redirector.SetRedirection(id, path, RedirectionFlags_Application); this->html_docs_redirector.SetRedirection(id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result RedirectOnlyLocationResolverImpl::RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
this->html_docs_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); this->html_docs_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) {
R_UNLESS(this->legal_info_redirector.FindRedirection(out.GetPointer(), id), lr::ResultLegalInformationNotFound()); R_UNLESS(this->legal_info_redirector.FindRedirection(out.GetPointer(), id), lr::ResultLegalInformationNotFound());
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) {
this->legal_info_redirector.SetRedirection(id, path, RedirectionFlags_Application); this->legal_info_redirector.SetRedirection(id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result RedirectOnlyLocationResolverImpl::RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
this->legal_info_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); this->legal_info_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::Refresh() { Result RedirectOnlyLocationResolverImpl::Refresh() {
this->ClearRedirections(); this->ClearRedirections();
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) {
this->program_redirector.SetRedirection(id, path, RedirectionFlags_Application); this->program_redirector.SetRedirection(id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result RedirectOnlyLocationResolverImpl::RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
this->program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); this->program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::ClearApplicationRedirectionDeprecated() { Result RedirectOnlyLocationResolverImpl::ClearApplicationRedirectionDeprecated() {
this->ClearRedirections(RedirectionFlags_Application); this->ClearRedirections(RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids) { Result RedirectOnlyLocationResolverImpl::ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids) {
this->ClearRedirectionsExcludingOwners(excluding_ids.GetPointer(), excluding_ids.GetSize()); this->ClearRedirections(excluding_ids.GetPointer(), excluding_ids.GetSize());
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::EraseProgramRedirection(ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::EraseProgramRedirection(ncm::ProgramId id) {
this->program_redirector.EraseRedirection(id); this->program_redirector.EraseRedirection(id);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::EraseApplicationControlRedirection(ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::EraseApplicationControlRedirection(ncm::ProgramId id) {
this->app_control_redirector.EraseRedirection(id); this->app_control_redirector.EraseRedirection(id);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) {
this->html_docs_redirector.EraseRedirection(id); this->html_docs_redirector.EraseRedirection(id);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::EraseApplicationLegalInformationRedirection(ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::EraseApplicationLegalInformationRedirection(ncm::ProgramId id) {
this->legal_info_redirector.EraseRedirection(id); this->legal_info_redirector.EraseRedirection(id);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) {
/* Use a redirection if present. */ /* Use a redirection if present. */
R_UNLESS(!this->debug_program_redirector.FindRedirection(out.GetPointer(), id), ResultSuccess()); R_UNLESS(!this->debug_program_redirector.FindRedirection(out.GetPointer(), id), ResultSuccess());
@ -138,22 +139,22 @@ namespace ams::lr {
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) {
this->debug_program_redirector.SetRedirection(id, path); this->debug_program_redirector.SetRedirection(id, path);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) {
this->debug_program_redirector.SetRedirection(id, path, RedirectionFlags_Application); this->debug_program_redirector.SetRedirection(id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result RedirectOnlyLocationResolverImpl::RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
this->debug_program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); this->debug_program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application);
return ResultSuccess(); return ResultSuccess();
} }
Result RedirectOnlyLocationResolverInterface::EraseProgramRedirectionForDebug(ncm::ProgramId id) { Result RedirectOnlyLocationResolverImpl::EraseProgramRedirectionForDebug(ncm::ProgramId id) {
this->debug_program_redirector.EraseRedirection(id); this->debug_program_redirector.EraseRedirection(id);
return ResultSuccess(); return ResultSuccess();
} }

View File

@ -15,14 +15,13 @@
*/ */
#pragma once #pragma once
#include <stratosphere/lr/lr_types.hpp> #include "lr_location_resolver_impl_base.hpp"
#include <stratosphere/lr/lr_i_location_resolver_interface.hpp>
namespace ams::lr { namespace ams::lr {
class RedirectOnlyLocationResolverInterface : public ILocationResolverInterface { class RedirectOnlyLocationResolverImpl : public LocationResolverImplBase {
public: public:
~RedirectOnlyLocationResolverInterface(); ~RedirectOnlyLocationResolverImpl();
public: public:
/* Actual commands. */ /* Actual commands. */
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) override; virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) override;

View File

@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "lr_registered_location_resolver_impl.hpp"
namespace ams::lr { namespace ams::lr {
@ -45,18 +46,18 @@ namespace ams::lr {
} }
RegisteredLocationResolverInterface::~RegisteredLocationResolverInterface() { RegisteredLocationResolverImpl::~RegisteredLocationResolverImpl() {
/* Ensure entries are deallocated */ /* Ensure entries are deallocated */
this->ClearRedirections(); this->ClearRedirections();
} }
/* Helper function. */ /* Helper function. */
void RegisteredLocationResolverInterface::ClearRedirections(u32 flags) { void RegisteredLocationResolverImpl::ClearRedirections(u32 flags) {
this->html_docs_redirector.ClearRedirections(flags); this->html_docs_redirector.ClearRedirections(flags);
this->program_redirector.ClearRedirections(flags); this->program_redirector.ClearRedirections(flags);
} }
Result RegisteredLocationResolverInterface::RefreshImpl(const ncm::ProgramId* excluding_ids, size_t num_ids) { Result RegisteredLocationResolverImpl::RefreshImpl(const ncm::ProgramId* excluding_ids, size_t num_ids) {
/* On < 9.0.0, exclusion lists were not supported yet, so simply clear and return. */ /* On < 9.0.0, exclusion lists were not supported yet, so simply clear and return. */
if (hos::GetVersion() < hos::Version_900) { if (hos::GetVersion() < hos::Version_900) {
this->ClearRedirections(); this->ClearRedirections();
@ -78,71 +79,71 @@ namespace ams::lr {
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) { Result RegisteredLocationResolverImpl::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) {
R_UNLESS(ResolvePath(out.GetPointer(), this->program_redirector, this->registered_program_locations, id), lr::ResultProgramNotFound()); R_UNLESS(ResolvePath(out.GetPointer(), this->program_redirector, this->registered_program_locations, id), lr::ResultProgramNotFound());
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) { Result RegisteredLocationResolverImpl::RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) {
RegisterPath(this->registered_program_locations, id, path, ncm::ProgramId::Invalid); RegisterPath(this->registered_program_locations, id, path, ncm::ProgramId::Invalid);
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result RegisteredLocationResolverImpl::RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
RegisterPath(this->registered_program_locations, id, path, owner_id); RegisterPath(this->registered_program_locations, id, path, owner_id);
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::UnregisterProgramPath(ncm::ProgramId id) { Result RegisteredLocationResolverImpl::UnregisterProgramPath(ncm::ProgramId id) {
this->registered_program_locations.Unregister(id); this->registered_program_locations.Unregister(id);
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) { Result RegisteredLocationResolverImpl::RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) {
this->program_redirector.SetRedirection(id, path); this->program_redirector.SetRedirection(id, path);
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result RegisteredLocationResolverImpl::RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
this->program_redirector.SetRedirection(id, owner_id, path); this->program_redirector.SetRedirection(id, owner_id, path);
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) { Result RegisteredLocationResolverImpl::ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) {
R_UNLESS(ResolvePath(out.GetPointer(), this->html_docs_redirector, this->registered_html_docs_locations, id), lr::ResultHtmlDocumentNotFound()); R_UNLESS(ResolvePath(out.GetPointer(), this->html_docs_redirector, this->registered_html_docs_locations, id), lr::ResultHtmlDocumentNotFound());
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { Result RegisteredLocationResolverImpl::RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) {
RegisterPath(this->registered_html_docs_locations, id, path, ncm::ProgramId::Invalid); RegisterPath(this->registered_html_docs_locations, id, path, ncm::ProgramId::Invalid);
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result RegisteredLocationResolverImpl::RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
RegisterPath(this->registered_html_docs_locations, id, path, owner_id); RegisterPath(this->registered_html_docs_locations, id, path, owner_id);
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::UnregisterHtmlDocumentPath(ncm::ProgramId id) { Result RegisteredLocationResolverImpl::UnregisterHtmlDocumentPath(ncm::ProgramId id) {
this->registered_html_docs_locations.Unregister(id); this->registered_html_docs_locations.Unregister(id);
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { Result RegisteredLocationResolverImpl::RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) {
this->html_docs_redirector.SetRedirection(id, path); this->html_docs_redirector.SetRedirection(id, path);
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { Result RegisteredLocationResolverImpl::RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) {
this->html_docs_redirector.SetRedirection(id, owner_id, path); this->html_docs_redirector.SetRedirection(id, owner_id, path);
return ResultSuccess(); return ResultSuccess();
} }
Result RegisteredLocationResolverInterface::Refresh() { Result RegisteredLocationResolverImpl::Refresh() {
return this->RefreshImpl(nullptr, 0); return this->RefreshImpl(nullptr, 0);
} }
Result RegisteredLocationResolverInterface::RefreshExcluding(const sf::InArray<ncm::ProgramId> &ids) { Result RegisteredLocationResolverImpl::RefreshExcluding(const sf::InArray<ncm::ProgramId> &ids) {
return this->RefreshImpl(ids.GetPointer(), ids.GetSize()); return this->RefreshImpl(ids.GetPointer(), ids.GetSize());
} }

View File

@ -0,0 +1,68 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
#include "lr_location_redirector.hpp"
#include "lr_registered_data.hpp"
namespace ams::lr {
class RegisteredLocationResolverImpl : public IRegisteredLocationResolver {
private:
static constexpr size_t MaxRegisteredLocationsDeprecated = 0x10;
static constexpr size_t MaxRegisteredLocations = 0x20;
static_assert(MaxRegisteredLocations >= MaxRegisteredLocationsDeprecated);
private:
static ALWAYS_INLINE size_t GetMaxRegisteredLocations() {
if (hos::GetVersion() >= hos::Version_900) {
return MaxRegisteredLocations;
} else {
return MaxRegisteredLocationsDeprecated;
}
}
private:
/* Redirection and registered location storage. */
LocationRedirector program_redirector;
RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations> registered_program_locations;
LocationRedirector html_docs_redirector;
RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations> registered_html_docs_locations;
private:
/* Helper functions. */
void ClearRedirections(u32 flags = RedirectionFlags_None);
Result RefreshImpl(const ncm::ProgramId* excluding_ids, size_t num_ids);
public:
RegisteredLocationResolverImpl() : registered_program_locations(GetMaxRegisteredLocations()), registered_html_docs_locations(GetMaxRegisteredLocations()) { /* ... */ }
~RegisteredLocationResolverImpl();
public:
/* Actual commands. */
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) override;
virtual Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) override;
virtual Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
virtual Result UnregisterProgramPath(ncm::ProgramId id) override;
virtual Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) override;
virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
virtual Result ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) override;
virtual Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override;
virtual Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
virtual Result UnregisterHtmlDocumentPath(ncm::ProgramId id) override;
virtual Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override;
virtual Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override;
virtual Result Refresh() override;
virtual Result RefreshExcluding(const sf::InArray<ncm::ProgramId> &ids) override;
};
}

View File

@ -0,0 +1,148 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
namespace ams::lr {
class RemoteLocationResolverImpl : public ILocationResolver {
private:
::LrLocationResolver srv;
public:
RemoteLocationResolverImpl(::LrLocationResolver &l) : srv(l) { /* ... */ }
~RemoteLocationResolverImpl() { ::serviceClose(&srv.s); }
public:
/* Actual commands. */
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) override {
return lrLrResolveProgramPath(std::addressof(this->srv), static_cast<u64>(id), out->str);
}
virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id) override {
return lrLrRedirectProgramPath(std::addressof(this->srv), static_cast<u64>(id), path.str);
}
virtual Result ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) override {
return lrLrResolveApplicationControlPath(std::addressof(this->srv), static_cast<u64>(id), out->str);
}
virtual Result ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) override {
return lrLrResolveApplicationHtmlDocumentPath(std::addressof(this->srv), static_cast<u64>(id), out->str);
}
virtual Result ResolveDataPath(sf::Out<Path> out, ncm::ProgramId id) override {
return lrLrResolveDataPath(std::addressof(this->srv), static_cast<u64>(id), out->str);
}
virtual Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) override {
return lrLrRedirectApplicationControlPath(std::addressof(this->srv), static_cast<u64>(id), 0, path.str);
}
virtual Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
return lrLrRedirectApplicationControlPath(std::addressof(this->srv), static_cast<u64>(id), static_cast<u64>(owner_id), path.str);
}
virtual Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override {
return lrLrRedirectApplicationHtmlDocumentPath(std::addressof(this->srv), static_cast<u64>(id), 0, path.str);
}
virtual Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
return lrLrRedirectApplicationHtmlDocumentPath(std::addressof(this->srv), static_cast<u64>(id), static_cast<u64>(owner_id), path.str);
}
virtual Result ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) override {
return lrLrResolveApplicationLegalInformationPath(std::addressof(this->srv), static_cast<u64>(id), out->str);
}
virtual Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) override {
return lrLrRedirectApplicationLegalInformationPath(std::addressof(this->srv), static_cast<u64>(id), 0, path.str);
}
virtual Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
return lrLrRedirectApplicationLegalInformationPath(std::addressof(this->srv), static_cast<u64>(id), static_cast<u64>(owner_id), path.str);
}
virtual Result Refresh() override {
return lrLrRefresh(std::addressof(this->srv));
}
virtual Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result ClearApplicationRedirectionDeprecated() override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result EraseProgramRedirection(ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result EraseApplicationControlRedirection(ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
};
}

View File

@ -0,0 +1,101 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
namespace ams::lr {
class RemoteRegisteredLocationResolverImpl : public IRegisteredLocationResolver {
private:
::LrRegisteredLocationResolver srv;
public:
RemoteRegisteredLocationResolverImpl(::LrRegisteredLocationResolver &l) : srv(l) { /* ... */ }
~RemoteRegisteredLocationResolverImpl() { ::serviceClose(&srv.s); }
public:
/* Actual commands. */
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) override {
return lrRegLrResolveProgramPath(std::addressof(this->srv), static_cast<u64>(id), out->str);
}
virtual Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result UnregisterProgramPath(ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result UnregisterHtmlDocumentPath(ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result Refresh() override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result RefreshExcluding(const sf::InArray<ncm::ProgramId> &ids) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
};
}

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "lr_remote_location_resolver_impl.hpp"
#include "lr_remote_registered_location_resolver_impl.hpp"
namespace ams::lr {
namespace {
bool g_initialized;
}
void Initialize() {
AMS_ASSERT(!g_initialized);
R_ABORT_UNLESS(lrInitialize());
g_initialized = true;
}
void Finalize() {
AMS_ASSERT(g_initialized);
lrExit();
g_initialized = false;
}
Result OpenLocationResolver(LocationResolver *out, ncm::StorageId storage_id) {
LrLocationResolver lr;
R_TRY(lrOpenLocationResolver(static_cast<NcmStorageId>(storage_id), std::addressof(lr)));
*out = LocationResolver(std::make_shared<RemoteLocationResolverImpl>(lr));
return ResultSuccess();
}
Result OpenRegisteredLocationResolver(RegisteredLocationResolver *out) {
LrRegisteredLocationResolver lr;
R_TRY(lrOpenRegisteredLocationResolver(std::addressof(lr)));
*out = RegisteredLocationResolver(std::make_shared<RemoteRegisteredLocationResolverImpl>(lr));
return ResultSuccess();
}
Result OpenAddOnContentLocationResolver(AddOnContentLocationResolver *out) {
/* TODO: libnx binding */
AMS_ABORT();
}
Result RefreshLocationResolver(ncm::StorageId storage_id) {
/* TODO: libnx binding */
AMS_ABORT();
}
}

View File

@ -15,6 +15,7 @@
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/lr/lr_location_resolver_manager_impl.hpp>
#include "impl/ncm_content_manager.hpp" #include "impl/ncm_content_manager.hpp"
#include "ncm_content_manager_service.hpp" #include "ncm_content_manager_service.hpp"