• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 GROUP_OPERATION_COMMON_H
17 #define GROUP_OPERATION_COMMON_H
18 
19 #include "common_defs.h"
20 #include "string_util.h"
21 #include "data_manager.h"
22 #include "json_utils.h"
23 #include "data_manager.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 bool IsAccountRelatedGroup(int groupType);
30 int32_t GenerateReturnGroupInfo(const TrustedGroupEntry *groupEntry, CJson *returnJson);
31 int32_t GenerateReturnDevInfo(const TrustedDeviceEntry *deviceEntry, CJson *returnJson);
32 
33 bool IsUserTypeValid(int userType);
34 bool IsExpireTimeValid(int expireTime);
35 bool IsGroupVisibilityValid(int groupVisibility);
36 
37 int32_t ProcessKeyPair(int action, const CJson *jsonParams, const char *groupId);
38 int32_t GetHashMessage(const Uint8Buff *first, const Uint8Buff *second, uint8_t **hashMessage, uint32_t *messageSize);
39 
40 int32_t AssertUserIdExist(const CJson *jsonParams);
41 int32_t AssertGroupTypeMatch(int32_t inputType, int32_t targetType);
42 int32_t AssertSameGroupNotExist(int32_t osAccountId, const char *groupId);
43 int32_t AssertPeerDeviceNotSelf(const char *peerUdid);
44 int32_t CheckGroupExist(int32_t osAccountId, const char *groupId);
45 int32_t CheckGroupNumLimit(int32_t osAccountId, int32_t groupType, const char *appId);
46 int32_t CheckDeviceNumLimit(int32_t osAccountId, const char *groupId, const char *peerUdid);
47 int32_t CheckUserTypeIfExist(const CJson *jsonParams);
48 int32_t CheckGroupVisibilityIfExist(const CJson *jsonParams);
49 int32_t CheckExpireTimeIfExist(const CJson *jsonParams);
50 int32_t CheckPermForGroup(int32_t osAccountId, int actionType, const char *callerPkgName, const char *groupId);
51 
52 int32_t AddGroupNameToParams(const char *groupName, TrustedGroupEntry *groupParams);
53 int32_t AddGroupIdToParams(const char *groupId, TrustedGroupEntry *groupParams);
54 int32_t AddGroupOwnerToParams(const char *owner, TrustedGroupEntry *groupParams);
55 int32_t AddGroupTypeToParams(int groupType, TrustedGroupEntry *groupParams);
56 int32_t AddGroupVisibilityOrDefault(const CJson *jsonParams, TrustedGroupEntry *groupParams);
57 int32_t AddExpireTimeOrDefault(const CJson *jsonParams, TrustedGroupEntry *groupParams);
58 int32_t AddUserIdToGroupParams(const CJson *jsonParams, TrustedGroupEntry *groupParams);
59 int32_t AddSharedUserIdToGroupParams(const CJson *jsonParams, TrustedGroupEntry *groupParams);
60 
61 int32_t AddSelfUdidToParams(TrustedDeviceEntry *devParams);
62 int32_t AddUdidToParams(const CJson *jsonParams, TrustedDeviceEntry *devParams);
63 int32_t AddAuthIdToParams(const CJson *jsonParams, TrustedDeviceEntry *devParams);
64 int32_t AddAuthIdToParamsOrDefault(const CJson *jsonParams, TrustedDeviceEntry *devParams);
65 int32_t AddUserTypeToParamsOrDefault(const CJson *jsonParams, TrustedDeviceEntry *devParams);
66 int32_t AddSourceToParams(RelationShipSource source, TrustedDeviceEntry *devParams);
67 int32_t AddCredTypeToParams(const CJson *jsonParams, TrustedDeviceEntry *devParams);
68 int32_t AddServiceTypeToParams(const char *groupId, TrustedDeviceEntry *devParams);
69 int32_t AddGroupIdToDevParams(const char *groupId, TrustedDeviceEntry *devParams);
70 int32_t AddUserIdToDevParams(const CJson *jsonParams, TrustedDeviceEntry *devParams);
71 
72 int32_t AddGroupToDatabaseByJson(int32_t osAccountId, int32_t (*generateGroupParams)(const CJson*,
73     const char *, TrustedGroupEntry*), const CJson *jsonParams, const char *groupId);
74 int32_t AddDeviceToDatabaseByJson(int32_t osAccountId, int32_t (*generateDevParams)(const CJson*, const char*,
75     TrustedDeviceEntry*), const CJson *jsonParams, const char *groupId);
76 int32_t DelGroupFromDb(int32_t osAccountId, const char *groupId);
77 
78 int32_t ConvertGroupIdToJsonStr(const char *groupId, char **returnJsonStr);
79 int32_t GenerateBindSuccessData(const char *peerAuthId, const char *peerUdid, const char *groupId,
80     char **returnDataStr);
81 int32_t GenerateUnbindSuccessData(const char *peerAuthId, const char *groupId, char **returnDataStr);
82 
83 int32_t GetCurDeviceNumByGroupId(int32_t osAccountId, const char *groupId);
84 int32_t GetGroupTypeFromDb(int32_t osAccountId, const char *groupId, int32_t *returnGroupType);
85 int32_t GetUserIdFromJson(const CJson *jsonParams, char **userId);
86 int32_t GetSharedUserIdFromJson(const CJson *jsonParams, char **sharedUserId);
87 int32_t GetGroupIdFromJson(const CJson *jsonParams, const char **groupId);
88 int32_t GetAppIdFromJson(const CJson *jsonParams, const char **appId);
89 
90 int32_t GetHashResult(const uint8_t *info, uint32_t infoLen, char *hash, uint32_t hashLen);
91 
92 bool IsLocalDevice(const char *udid);
93 bool IsGroupExistByGroupId(int32_t osAccountId, const char *groupId);
94 bool IsGroupOwner(int32_t osAccountId, const char *groupId, const char *appId);
95 bool IsTrustedDeviceInGroup(int32_t osAccountId, const char *groupId, const char *deviceId, bool isUdid);
96 int32_t CheckGroupAccessible(int32_t osAccountId, const char *groupId, const char *appId);
97 int32_t CheckGroupEditAllowed(int32_t osAccountId, const char *groupId, const char *appId);
98 int32_t GetGroupInfo(int32_t osAccountId, const QueryGroupParams *params, GroupEntryVec *returnGroupEntryVec);
99 int32_t GetJoinedGroups(int32_t osAccountId, int groupType, GroupEntryVec *returnGroupEntryVec);
100 int32_t GetRelatedGroups(int32_t osAccountId, const char *peerDeviceId, bool isUdid,
101     GroupEntryVec *returnGroupEntryVec);
102 int32_t GetTrustedDevInfoById(int32_t osAccountId, const char *deviceId, bool isUdid, const char *groupId,
103     TrustedDeviceEntry *returnDeviceEntry);
104 int32_t GetTrustedDevices(int32_t osAccountId, const char *groupId, DeviceEntryVec *returnDeviceEntryVec);
105 
106 TrustedGroupEntry *GetGroupEntryById(int32_t osAccountId, const char *groupId);
107 TrustedDeviceEntry *GetTrustedDeviceEntryById(int32_t osAccountId, const char *deviceId, bool isUdid,
108     const char *groupId);
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 #endif
114