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