• 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 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 userIdHash; /* hash result of the user account id */
37     StringVector sharedUserIdHashVec; /* vector of hash results for 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 serviceType; /* compatible with previous versions, the value is the same as groupId */
49     HcParcel ext; /* for caching extern data, user data */
50     uint8_t credential; /* 1 - asymmetrical, 2 - symmetrical */
51     uint8_t devType; /* 0 - accessory, 1 - controller, 2 - proxy */
52     HcString userIdHash; /* hash result of the user account id */
53     uint64_t lastTm; /* accessed time of the device of the auth information, absolute time */
54 } TrustedDeviceEntry;
55 DECLARE_HC_VECTOR(DeviceEntryVec, TrustedDeviceEntry*)
56 
57 typedef struct {
58     const char *groupId;
59     const char *groupName;
60     const char *ownerName;
61     int32_t groupType;
62     int32_t groupVisibility;
63 } QueryGroupParams;
64 
65 typedef struct {
66     const char *groupId;
67     const char *udid;
68     const char *authId;
69 } QueryDeviceParams;
70 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
75 int32_t InitDatabase(void);
76 void DestroyDatabase(void);
77 
78 int32_t AddGroup(int32_t osAccountId, const TrustedGroupEntry *groupEntry);
79 int32_t DelGroup(int32_t osAccountId, const QueryGroupParams *params);
80 int32_t AddTrustedDevice(int32_t osAccountId, const TrustedDeviceEntry *deviceEntry);
81 int32_t DelTrustedDevice(int32_t osAccountId, const QueryDeviceParams *params);
82 int32_t QueryGroups(int32_t osAccountId, const QueryGroupParams *params, GroupEntryVec *vec);
83 int32_t QueryDevices(int32_t osAccountId, const QueryDeviceParams *params, DeviceEntryVec *vec);
84 int32_t SaveOsAccountDb(int32_t osAccountId);
85 bool GenerateGroupEntryFromEntry(const TrustedGroupEntry *entry, TrustedGroupEntry *returnEntry);
86 bool GenerateDeviceEntryFromEntry(const TrustedDeviceEntry *entry, TrustedDeviceEntry *returnEntry);
87 
88 TrustedGroupEntry *DeepCopyGroupEntry(const TrustedGroupEntry *entry);
89 TrustedDeviceEntry *DeepCopyDeviceEntry(const TrustedDeviceEntry *entry);
90 
91 QueryGroupParams InitQueryGroupParams(void);
92 QueryDeviceParams InitQueryDeviceParams(void);
93 
94 TrustedGroupEntry *CreateGroupEntry(void);
95 TrustedDeviceEntry *CreateDeviceEntry(void);
96 void DestroyGroupEntry(TrustedGroupEntry *groupEntry);
97 void DestroyDeviceEntry(TrustedDeviceEntry *groupEntry);
98 GroupEntryVec CreateGroupEntryVec(void);
99 DeviceEntryVec CreateDeviceEntryVec(void);
100 void ClearGroupEntryVec(GroupEntryVec *vec);
101 void ClearDeviceEntryVec(DeviceEntryVec *vec);
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 #endif
107