mirror of
https://gitee.com/openharmony/distributeddatamgr_datamgr_service
synced 2024-11-27 00:51:12 +00:00
movefunction
Signed-off-by: Cuiziyuan <cuiziyuan1@h-partners.com>
This commit is contained in:
parent
9fe646fc3d
commit
e50e1164d5
@ -62,6 +62,21 @@ bool URIUtils::GetBundleNameFromProxyURI(const std::string &uri, std::string &bu
|
||||
return true;
|
||||
}
|
||||
|
||||
bool URIUtils::GetAppIndexFromProxyURI(const std::string &uri, int32_t &appIndex)
|
||||
{
|
||||
auto queryParams = URIUtils::GetQueryParams(uri);
|
||||
if (!queryParams[APP_INDEX].empty()) {
|
||||
auto [success, data] = URIUtils::Strtoul(queryParams[APP_INDEX]);
|
||||
if (!success) {
|
||||
appIndex = -1;
|
||||
ZLOGE("appIndex is invalid! appIndex: %{public}s", queryParams[APP_INDEX].c_str());
|
||||
return false;
|
||||
}
|
||||
appIndex = data;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void URIUtils::FormatUri(std::string &uri)
|
||||
{
|
||||
auto pos = uri.find_last_of('?');
|
||||
|
@ -39,6 +39,7 @@ class URIUtils {
|
||||
public:
|
||||
static bool GetInfoFromURI(const std::string &uri, UriInfo &uriInfo);
|
||||
static bool GetBundleNameFromProxyURI(const std::string &uri, std::string &bundleName);
|
||||
static bool GetAppIndexFromProxyURI(const std::string &uri, int32_t &appIndex);
|
||||
static bool IsDataProxyURI(const std::string &uri);
|
||||
static void FormatUri(std::string &uri);
|
||||
static UriConfig GetUriConfig(const std::string &uri);
|
||||
@ -50,6 +51,7 @@ public:
|
||||
static constexpr const char *PARAM_URI_SEPARATOR = ":///";
|
||||
static constexpr const char *SCHEME_SEPARATOR = "://";
|
||||
static constexpr const char *URI_SEPARATOR = "/";
|
||||
static constexpr const char APP_INDEX[] = "appIndex"; // for Application Clone
|
||||
static constexpr int DATA_PROXY_SCHEMA_LEN = sizeof(DATA_PROXY_SCHEMA) - 1;
|
||||
static constexpr uint32_t PARAM_URI_SEPARATOR_LEN = 4;
|
||||
|
||||
|
@ -33,7 +33,7 @@ DataProviderConfig::DataProviderConfig(const std::string &uri, uint32_t callerTo
|
||||
{
|
||||
providerInfo_.uri = uri;
|
||||
providerInfo_.currentUserId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(callerTokenId);
|
||||
LoadConfigCommonStrategy::GetAppIndexFromProxyURI(providerInfo_.uri, providerInfo_.appIndex);
|
||||
URIUtils::GetAppIndexFromProxyURI(providerInfo_.uri, providerInfo_.appIndex);
|
||||
if (providerInfo_.currentUserId == 0) {
|
||||
LoadConfigCommonStrategy::GetInfoFromProxyURI(providerInfo_.uri, providerInfo_.currentUserId,
|
||||
callerTokenId, providerInfo_.bundleName);
|
||||
|
@ -42,7 +42,7 @@
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "log_print.h"
|
||||
#include "strategies/general/load_config_common_strategy.h"
|
||||
#include "common/uri_utils.h"
|
||||
#include "metadata/auto_launch_meta_data.h"
|
||||
#include "metadata/meta_data_manager.h"
|
||||
#include "matching_skills.h"
|
||||
@ -845,7 +845,7 @@ int32_t DataShareServiceImpl::GetSilentProxyStatus(const std::string &uri, bool
|
||||
}
|
||||
std::string calledBundleName = uriInfo.bundleName;
|
||||
int32_t appIndex = 0;
|
||||
if (!LoadConfigCommonStrategy::GetAppIndexFromProxyURI(uri, appIndex)) {
|
||||
if (!URIUtils::GetAppIndexFromProxyURI(uri, appIndex)) {
|
||||
return E_APPINDEX_INVALID;
|
||||
}
|
||||
uint32_t calledTokenId = Security::AccessToken::AccessTokenKit::GetHapTokenID(
|
||||
|
@ -26,14 +26,13 @@ namespace OHOS::DataShare {
|
||||
constexpr const char USER_PARAM[] = "user";
|
||||
constexpr const char TOKEN_ID_PARAM[] = "srcToken";
|
||||
constexpr const char DST_BUNDLE_NAME_PARAM[] = "dstBundleName";
|
||||
constexpr const char APP_INDEX[] = "appIndex"; // for Application Clone
|
||||
bool LoadConfigCommonStrategy::operator()(std::shared_ptr<Context> context)
|
||||
{
|
||||
if (context->callerTokenId == 0) {
|
||||
context->callerTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
}
|
||||
context->currentUserId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(context->callerTokenId);
|
||||
if (!GetAppIndexFromProxyURI(context->uri, context->appIndex)) {
|
||||
if (!URIUtils::GetAppIndexFromProxyURI(context->uri, context->appIndex)) {
|
||||
return false;
|
||||
}
|
||||
// sa, userId is in uri, caller token id is from first caller tokenId
|
||||
@ -77,19 +76,4 @@ bool LoadConfigCommonStrategy::GetInfoFromProxyURI(
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoadConfigCommonStrategy::GetAppIndexFromProxyURI(const std::string &uri, int32_t &appIndex)
|
||||
{
|
||||
auto queryParams = URIUtils::GetQueryParams(uri);
|
||||
if (!queryParams[APP_INDEX].empty()) {
|
||||
auto [success, data] = URIUtils::Strtoul(queryParams[APP_INDEX]);
|
||||
if (!success) {
|
||||
appIndex = -1;
|
||||
ZLOGE("appIndex is invalid! appIndex: %{public}s", queryParams[APP_INDEX].c_str());
|
||||
return false;
|
||||
}
|
||||
appIndex = data;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace OHOS::DataShare
|
@ -23,7 +23,6 @@ public:
|
||||
bool operator()(std::shared_ptr<Context> context) override;
|
||||
static bool GetInfoFromProxyURI(
|
||||
const std::string &uri, int32_t &user, uint32_t &callerTokenId, std::string &calledBundleName);
|
||||
static bool GetAppIndexFromProxyURI(const std::string &uri, int32_t &appIndex);
|
||||
};
|
||||
} // namespace OHOS::DataShare
|
||||
#endif // DATASHARESERVICE_LOAD_CONFIG_COMMON_STRAGETY_H
|
||||
|
Loading…
Reference in New Issue
Block a user