• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef DATASHARESERVICE_URI_UTILS_H
17 #define DATASHARESERVICE_URI_UTILS_H
18 
19 #include <map>
20 #include <vector>
21 #include <string>
22 namespace OHOS::DataShare {
23 struct UriInfo {
24     std::string bundleName;
25     std::string moduleName;
26     std::string storeName;
27     std::string tableName;
28 };
29 
30 struct UriConfig {
31     std::string authority;
32     std::string path;
33     std::vector<std::string> pathSegments;
34     std::string formatUri;
35     std::string scheme;
36 };
37 
38 class URIUtils {
39 public:
40     static bool GetInfoFromURI(const std::string &uri, UriInfo &uriInfo);
41     static bool GetBundleNameFromProxyURI(const std::string &uri, std::string &bundleName);
42     static bool GetAppIndexFromProxyURI(const std::string &uri, int32_t &appIndex);
43     static std::pair<bool, int32_t> GetUserFromProxyURI(const std::string &uri);
44     static bool IsDataProxyURI(const std::string &uri);
45     static void FormatUri(std::string &uri);
46     static std::string FormatConstUri(const std::string &uri);
47     static UriConfig GetUriConfig(const std::string &uri);
48     static std::string Anonymous(const std::string &uri);
49     static std::map<std::string, std::string> GetQueryParams(const std::string& uri);
50     static std::pair<bool, uint32_t> Strtoul(const std::string &str);
51     static constexpr const char *DATA_SHARE_SCHEMA = "datashare:///";;
52     static constexpr const char DATA_PROXY_SCHEMA[] = "datashareproxy://";
53     static constexpr const char *PARAM_URI_SEPARATOR = ":///";
54     static constexpr const char *SCHEME_SEPARATOR = "://";
55     static constexpr const char *URI_SEPARATOR = "/";
56     static constexpr const char *APP_INDEX = "appIndex";  // for Application Clone
57     static constexpr const char USER_PARAM[] = "user";
58     static constexpr int DATA_PROXY_SCHEMA_LEN = sizeof(DATA_PROXY_SCHEMA) - 1;
59     static constexpr uint32_t PARAM_URI_SEPARATOR_LEN = 4;
60 
61 private:
62     enum PATH_PARAM : int32_t {
63         BUNDLE_NAME = 0,
64         MODULE_NAME,
65         STORE_NAME,
66         TABLE_NAME,
67         PARAM_SIZE
68     };
69     static constexpr int32_t END_LENGTH = 10;
70     static constexpr const char *DEFAULT_ANONYMOUS = "******";
71 };
72 } // namespace OHOS::DataShare
73 #endif // DATASHARESERVICE_URI_UTILS_H
74