• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 OHOS_DM_ANONYMOUS_H
17 #define OHOS_DM_ANONYMOUS_H
18 
19 #include <map>
20 #include <string>
21 
22 #include "dm_device_info.h"
23 #include "json_object.h"
24 
25 namespace OHOS {
26 namespace DistributedHardware {
27 extern const char* PRINT_LIST_SPLIT;
28 extern const int32_t LIST_SPLIT_LEN;
29 
30 std::string GetAnonyString(const std::string &value);
31 std::string GetAnonyStringList(const std::vector<std::string> &values);
32 std::string GetAnonyInt32(const int32_t value);
33 std::string GetAnonyInt32List(const std::vector<int32_t> &values);
34 bool IsNumberString(const std::string &inputString);
35 bool IsString(const JsonItemObject &jsonObj, const std::string &key);
36 bool IsInt32(const JsonItemObject &jsonObj, const std::string &key);
37 bool IsUint32(const JsonItemObject &jsonObj, const std::string &key);
38 bool IsInt64(const JsonItemObject &jsonObj, const std::string &key);
39 bool IsArray(const JsonItemObject &jsonObj, const std::string &key);
40 bool IsBool(const JsonItemObject &jsonObj, const std::string &key);
41 std::string ConvertMapToJsonString(const std::map<std::string, std::string> &paramMap);
42 void ParseMapFromJsonString(const std::string &jsonStr, std::map<std::string, std::string> &paramMap);
43 bool IsInvalidPeerTargetId(const PeerTargetId &targetId);
44 std::string ConvertCharArray2String(const char *srcData, uint32_t srcLen);
45 int32_t StringToInt(const std::string &str, int32_t base);
46 int64_t StringToInt64(const std::string &str, int32_t base);
47 void VersionSplitToInt(const std::string &str, const char split, std::vector<int32_t> &numVec);
48 bool CompareVecNum(const std::vector<int32_t> &srcVecNum, const std::vector<int32_t> &sinkVecNum);
49 bool CompareVersion(const std::string &remoteVersion, const std::string &oldVersion);
50 std::string ComposeStr(const std::string &pkgName, uint16_t subscribeId);
51 std::string GetCallerPkgName(const std::string &pkgName);
52 uint16_t GetSubscribeId(const std::string &pkgName);
53 template <class T>
GetAnonyInteger(const T value)54 std::string GetAnonyInteger(const T value)
55 {
56     std::string tempString = std::to_string(value);
57     size_t length = tempString.length();
58     if (length == 0x01) {
59         tempString[0] = '*';
60         return tempString;
61     }
62     for (size_t i = 1; i < length - 1; i++) {
63         tempString[i] = '*';
64     }
65     return tempString;
66 }
67 
68 template <class T>
GetAnonyIntegerList(const std::vector<T> & values)69 std::string GetAnonyIntegerList(const std::vector<T> &values)
70 {
71     std::string temp = "[ ";
72     bool flag = false;
73     for (auto const &v : values) {
74         temp += GetAnonyInteger(v) + PRINT_LIST_SPLIT;
75         flag = true;
76     }
77     if (flag) {
78         temp.erase(temp.length() - LIST_SPLIT_LEN);
79     }
80     temp += " ]";
81     return temp;
82 }
83 
84 template <class T>
GetIntegerList(const std::vector<T> & values)85 std::string GetIntegerList(const std::vector<T> &values)
86 {
87     std::string temp = "[ ";
88     bool flag = false;
89     for (auto const &v : values) {
90         temp += std::to_string(v) + PRINT_LIST_SPLIT;
91         flag = true;
92     }
93     if (flag) {
94         temp.erase(temp.length() - LIST_SPLIT_LEN);
95     }
96     temp += " ]";
97     return temp;
98 }
99 
100 bool IsIdLengthValid(const std::string &inputID);
101 bool IsMessageLengthValid(const std::string &inputMessage);
102 bool IsValueExist(const std::multimap<std::string, int32_t> unorderedmap, const std::string &udid, int32_t userId);
103 bool IsDmCommonNotifyEventValid(DmCommonNotifyEvent dmCommonNotifyEvent);
104 std::string SafetyDump(const JsonItemObject &jsonObj);
105 std::string GetSubStr(const std::string &rawStr, const std::string &separator, int32_t index);
106 bool IsJsonValIntegerString(const JsonItemObject &jsonObj, const std::string &key);
107 } // namespace DistributedHardware
108 } // namespace OHOS
109 #endif // OHOS_DM_ANONYMOUS_H
110