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 DATA_MANAGER_H 17 #define DATA_MANAGER_H 18 19 #include <stdbool.h> 20 #include "hc_string.h" 21 #include "hc_string_vector.h" 22 #include "hc_tlv_parser.h" 23 #include "hc_vector.h" 24 25 #define MAX_STRING_LEN 256 26 #define MAX_EXPIRE_TIME 90 27 #define HC_TRUST_DEV_ENTRY_MAX_NUM 101 28 #define HC_TRUST_GROUP_ENTRY_MAX_NUM 100 29 30 typedef struct { 31 HcString name; /* group name */ 32 HcString id; /* group id */ 33 int32_t type; /* including identical account group(1), peer to peer group(256), across account group(1282) */ 34 int32_t visibility; /* visibility of the group */ 35 int32_t expireTime; /* the time of group expired, unit day, user config */ 36 HcString userId; /* the user account id */ 37 HcString sharedUserId; /* the shared user account id */ 38 StringVector managers; /* group manager vector, group manager can add and delete members, index 0 is the owner */ 39 StringVector friends; /* group friend vector, group friend can query group information */ 40 } TrustedGroupEntry; 41 DECLARE_HC_VECTOR(GroupEntryVec, TrustedGroupEntry*) 42 43 typedef struct { 44 TrustedGroupEntry *groupEntry; 45 HcString groupId; 46 HcString udid; /* unique device id */ 47 HcString authId; /* id by service defined for authentication */ 48 HcString userId; /* the user account id */ 49 HcString serviceType; /* compatible with previous versions, the value is the same as groupId */ 50 HcParcel ext; /* for caching extern data, user data */ 51 uint8_t credential; /* 1 - asymmetrical, 2 - symmetrical */ 52 uint8_t devType; /* 0 - accessory, 1 - controller, 2 - proxy */ 53 uint8_t source; /* the tursted relationship source. 0: self-created, 1: imported from the cloud */ 54 uint64_t lastTm; /* accessed time of the device of the auth information, absolute time */ 55 } TrustedDeviceEntry; 56 DECLARE_HC_VECTOR(DeviceEntryVec, TrustedDeviceEntry*) 57 58 typedef struct { 59 const char *groupId; 60 const char *groupName; 61 const char *ownerName; 62 const char *userId; 63 const char *sharedUserId; 64 int32_t groupType; 65 int32_t groupVisibility; 66 } QueryGroupParams; 67 68 typedef struct { 69 const char *groupId; 70 const char *udid; 71 const char *authId; 72 const char *userId; 73 } QueryDeviceParams; 74 75 #ifdef __cplusplus 76 extern "C" { 77 #endif 78 79 int32_t InitDatabase(void); 80 void DestroyDatabase(void); 81 82 int32_t AddGroup(int32_t osAccountId, const TrustedGroupEntry *groupEntry); 83 int32_t DelGroup(int32_t osAccountId, const QueryGroupParams *params); 84 int32_t AddTrustedDevice(int32_t osAccountId, const TrustedDeviceEntry *deviceEntry); 85 int32_t DelTrustedDevice(int32_t osAccountId, const QueryDeviceParams *params); 86 int32_t QueryGroups(int32_t osAccountId, const QueryGroupParams *params, GroupEntryVec *vec); 87 int32_t QueryDevices(int32_t osAccountId, const QueryDeviceParams *params, DeviceEntryVec *vec); 88 int32_t SaveOsAccountDb(int32_t osAccountId); 89 bool GenerateGroupEntryFromEntry(const TrustedGroupEntry *entry, TrustedGroupEntry *returnEntry); 90 bool GenerateDeviceEntryFromEntry(const TrustedDeviceEntry *entry, TrustedDeviceEntry *returnEntry); 91 92 TrustedGroupEntry *DeepCopyGroupEntry(const TrustedGroupEntry *entry); 93 TrustedDeviceEntry *DeepCopyDeviceEntry(const TrustedDeviceEntry *entry); 94 95 QueryGroupParams InitQueryGroupParams(void); 96 QueryDeviceParams InitQueryDeviceParams(void); 97 98 TrustedGroupEntry *CreateGroupEntry(void); 99 TrustedDeviceEntry *CreateDeviceEntry(void); 100 void DestroyGroupEntry(TrustedGroupEntry *groupEntry); 101 void DestroyDeviceEntry(TrustedDeviceEntry *deviceEntry); 102 GroupEntryVec CreateGroupEntryVec(void); 103 DeviceEntryVec CreateDeviceEntryVec(void); 104 void ClearGroupEntryVec(GroupEntryVec *vec); 105 void ClearDeviceEntryVec(DeviceEntryVec *vec); 106 107 #ifdef __cplusplus 108 } 109 #endif 110 #endif 111