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 IsDataProxyURI(const std::string &uri); 43 static void FormatUri(std::string &uri); 44 static UriConfig GetUriConfig(const std::string &uri); 45 static std::string Anonymous(const std::string &uri); 46 static std::map<std::string, std::string> GetQueryParams(const std::string& uri); 47 static std::pair<bool, uint32_t> Strtoul(const std::string &str); 48 static constexpr const char *DATA_SHARE_SCHEMA = "datashare:///";; 49 static constexpr const char DATA_PROXY_SCHEMA[] = "datashareproxy://"; 50 static constexpr const char *PARAM_URI_SEPARATOR = ":///"; 51 static constexpr const char *SCHEME_SEPARATOR = "://"; 52 static constexpr const char *URI_SEPARATOR = "/"; 53 static constexpr int DATA_PROXY_SCHEMA_LEN = sizeof(DATA_PROXY_SCHEMA) - 1; 54 static constexpr uint32_t PARAM_URI_SEPARATOR_LEN = 4; 55 56 private: 57 enum PATH_PARAM : int32_t { 58 BUNDLE_NAME = 0, 59 MODULE_NAME, 60 STORE_NAME, 61 TABLE_NAME, 62 PARAM_SIZE 63 }; 64 static constexpr int32_t END_LENGTH = 10; 65 static constexpr const char *DEFAULT_ANONYMOUS = "******"; 66 }; 67 } // namespace OHOS::DataShare 68 #endif // DATASHARESERVICE_URI_UTILS_H 69