• 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 #include "group_manager.h"
17 
18 #include "bind_peer.h"
19 #include "common_defs.h"
20 #include "data_manager.h"
21 #include "group_operation.h"
22 #include "key_agree.h"
23 
CreateGroupImpl(int32_t osAccountId,int64_t requestId,const char * appId,const char * createParams)24 int32_t CreateGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams)
25 {
26     return IsGroupSupport() ? GetGroupImplInstance()->createGroup(osAccountId, requestId, appId, createParams)
27                             : HC_ERR_NOT_SUPPORT;
28 }
29 
DeleteGroupImpl(int32_t osAccountId,int64_t requestId,const char * appId,const char * disbandParams)30 int32_t DeleteGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *disbandParams)
31 {
32     return IsGroupSupport() ? GetGroupImplInstance()->deleteGroup(osAccountId, requestId, appId, disbandParams)
33                             : HC_ERR_NOT_SUPPORT;
34 }
35 
AddMemberToGroupImpl(int32_t osAccountId,int64_t requestId,const char * appId,const char * addParams)36 int32_t AddMemberToGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams)
37 {
38     return IsGroupSupport() ? GetGroupImplInstance()->addMember(osAccountId, requestId, appId, addParams)
39                             : HC_ERR_NOT_SUPPORT;
40 }
41 
DeleteMemberFromGroupImpl(int32_t osAccountId,int64_t requestId,const char * appId,const char * deleteParams)42 int32_t DeleteMemberFromGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *deleteParams)
43 {
44     return IsGroupSupport() ? GetGroupImplInstance()->deleteMember(osAccountId, requestId, appId, deleteParams)
45                             : HC_ERR_NOT_SUPPORT;
46 }
47 
ProcessBindDataImpl(int64_t requestId,const uint8_t * data,uint32_t dataLen)48 int32_t ProcessBindDataImpl(int64_t requestId, const uint8_t *data, uint32_t dataLen)
49 {
50     return IsGroupSupport() ? GetGroupImplInstance()->processBindData(requestId, data, dataLen) : HC_ERR_NOT_SUPPORT;
51 }
52 
ConfirmRequestImpl(int32_t osAccountId,int64_t requestId,const char * appId,const char * confirmParams)53 int32_t ConfirmRequestImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *confirmParams)
54 {
55     return IsGroupSupport() ? GetGroupImplInstance()->confirmRequest(osAccountId, requestId, appId,
56         confirmParams) : HC_ERR_NOT_SUPPORT;
57 }
58 
GenerateAccountGroupIdImpl(int32_t groupType,const char * userIdHash,const char * sharedUserIdHash,char ** returnGroupId)59 int32_t GenerateAccountGroupIdImpl(int32_t groupType, const char *userIdHash, const char *sharedUserIdHash,
60     char **returnGroupId)
61 {
62     return IsGroupSupport() ? GetGroupImplInstance()->generateAccountGroupId(groupType, userIdHash, sharedUserIdHash,
63         returnGroupId) : HC_ERR_NOT_SUPPORT;
64 }
65 
SyncAcrossAccountGroupImpl(const char * appId,const char * userIdHash,const char * deviceId,const CJson * sharedUserIdHashList)66 int32_t SyncAcrossAccountGroupImpl(const char *appId, const char *userIdHash, const char *deviceId,
67     const CJson *sharedUserIdHashList)
68 {
69     return IsGroupSupport() ? GetGroupImplInstance()->syncAcrossAccountGroup(appId, userIdHash, deviceId,
70         sharedUserIdHashList) : HC_ERR_NOT_SUPPORT;
71 }
72 
AddGroupManagerImpl(int32_t osAccountId,const char * appId,const char * groupId,const char * managerAppId)73 int32_t AddGroupManagerImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *managerAppId)
74 {
75     return IsGroupSupport() ? GetGroupImplInstance()->addGroupRole(osAccountId, true, appId, groupId,
76         managerAppId) : HC_ERR_NOT_SUPPORT;
77 }
78 
AddGroupFriendImpl(int32_t osAccountId,const char * appId,const char * groupId,const char * friendAppId)79 int32_t AddGroupFriendImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *friendAppId)
80 {
81     return IsGroupSupport() ? GetGroupImplInstance()->addGroupRole(osAccountId, false, appId, groupId,
82         friendAppId) : HC_ERR_NOT_SUPPORT;
83 }
84 
DeleteGroupManagerImpl(int32_t osAccountId,const char * appId,const char * groupId,const char * managerAppId)85 int32_t DeleteGroupManagerImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *managerAppId)
86 {
87     return IsGroupSupport() ? GetGroupImplInstance()->deleteGroupRole(osAccountId, true, appId, groupId,
88         managerAppId) : HC_ERR_NOT_SUPPORT;
89 }
90 
DeleteGroupFriendImpl(int32_t osAccountId,const char * appId,const char * groupId,const char * friendAppId)91 int32_t DeleteGroupFriendImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *friendAppId)
92 {
93     return IsGroupSupport() ? GetGroupImplInstance()->deleteGroupRole(osAccountId, false, appId, groupId,
94         friendAppId) : HC_ERR_NOT_SUPPORT;
95 }
96 
GetGroupManagersImpl(int32_t osAccuntId,const char * appId,const char * groupId,char ** returnManagers,uint32_t * returnSize)97 int32_t GetGroupManagersImpl(int32_t osAccuntId, const char *appId, const char *groupId,
98     char **returnManagers, uint32_t *returnSize)
99 {
100     return IsGroupSupport() ? GetGroupImplInstance()->getGroupRoles(osAccuntId, true, appId, groupId,
101         returnManagers, returnSize) : HC_ERR_NOT_SUPPORT;
102 }
103 
GetGroupFriendsImpl(int32_t osAccuntId,const char * appId,const char * groupId,char ** returnFriends,uint32_t * returnSize)104 int32_t GetGroupFriendsImpl(int32_t osAccuntId, const char *appId, const char *groupId,
105     char **returnFriends, uint32_t *returnSize)
106 {
107     return IsGroupSupport() ? GetGroupImplInstance()->getGroupRoles(osAccuntId, false, appId, groupId,
108         returnFriends, returnSize) : HC_ERR_NOT_SUPPORT;
109 }
110 
RegListenerImpl(const char * appId,const DataChangeListener * listener)111 int32_t RegListenerImpl(const char *appId, const DataChangeListener *listener)
112 {
113     return IsGroupSupport() ? GetGroupImplInstance()->regListener(appId, listener) : HC_ERR_NOT_SUPPORT;
114 }
115 
UnRegListenerImpl(const char * appId)116 int32_t UnRegListenerImpl(const char *appId)
117 {
118     return IsGroupSupport() ? GetGroupImplInstance()->unRegListener(appId) : HC_ERR_NOT_SUPPORT;
119 }
120 
CheckAccessToGroupImpl(int32_t osAccountId,const char * appId,const char * groupId)121 int32_t CheckAccessToGroupImpl(int32_t osAccountId, const char *appId, const char *groupId)
122 {
123     return IsGroupSupport() ? GetGroupImplInstance()->checkAccessToGroup(osAccountId, appId, groupId)
124                             : HC_ERR_NOT_SUPPORT;
125 }
126 
GetGroupInfoByIdImpl(int32_t osAccountId,const char * appId,const char * groupId,char ** returnGroupInfo)127 int32_t GetGroupInfoByIdImpl(int32_t osAccountId, const char *appId, const char *groupId, char **returnGroupInfo)
128 {
129     return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleGroupInfoById(osAccountId, appId, groupId,
130         returnGroupInfo) : HC_ERR_NOT_SUPPORT;
131 }
132 
GetGroupInfoImpl(int32_t osAccountId,const char * appId,const char * queryParams,char ** returnGroupVec,uint32_t * groupNum)133 int32_t GetGroupInfoImpl(int32_t osAccountId, const char *appId, const char *queryParams,
134     char **returnGroupVec, uint32_t *groupNum)
135 {
136     return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleGroupInfo(osAccountId, appId, queryParams,
137         returnGroupVec, groupNum) : HC_ERR_NOT_SUPPORT;
138 }
139 
GetJoinedGroupsImpl(int32_t osAccountId,const char * appId,int groupType,char ** returnGroupVec,uint32_t * groupNum)140 int32_t GetJoinedGroupsImpl(int32_t osAccountId, const char *appId, int groupType,
141     char **returnGroupVec, uint32_t *groupNum)
142 {
143     return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleJoinedGroups(osAccountId, appId, groupType,
144         returnGroupVec, groupNum) : HC_ERR_NOT_SUPPORT;
145 }
146 
GetRelatedGroupsImpl(int32_t osAccountId,const char * appId,const char * peerDeviceId,char ** returnGroupVec,uint32_t * groupNum)147 int32_t GetRelatedGroupsImpl(int32_t osAccountId, const char *appId, const char *peerDeviceId,
148     char **returnGroupVec, uint32_t *groupNum)
149 {
150     return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleRelatedGroups(osAccountId, appId, peerDeviceId,
151         false, returnGroupVec, groupNum) : HC_ERR_NOT_SUPPORT;
152 }
153 
GetDeviceInfoByIdImpl(int32_t osAccountId,const char * appId,const char * deviceId,const char * groupId,char ** returnDeviceInfo)154 int32_t GetDeviceInfoByIdImpl(int32_t osAccountId, const char *appId, const char *deviceId, const char *groupId,
155     char **returnDeviceInfo)
156 {
157     return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleDeviceInfoById(osAccountId, appId, deviceId,
158         false, groupId, returnDeviceInfo) : HC_ERR_NOT_SUPPORT;
159 }
160 
GetTrustedDevicesImpl(int32_t osAccountId,const char * appId,const char * groupId,char ** returnDevInfoVec,uint32_t * deviceNum)161 int32_t GetTrustedDevicesImpl(int32_t osAccountId, const char *appId, const char *groupId,
162     char **returnDevInfoVec, uint32_t *deviceNum)
163 {
164     return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleTrustedDevices(osAccountId, appId, groupId,
165         returnDevInfoVec, deviceNum) : HC_ERR_NOT_SUPPORT;
166 }
167 
IsDeviceInGroupImpl(int32_t osAccountId,const char * appId,const char * groupId,const char * deviceId)168 bool IsDeviceInGroupImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *deviceId)
169 {
170     return IsGroupSupport() ? GetGroupImplInstance()->isDeviceInAccessibleGroup(osAccountId, appId, groupId,
171         deviceId, false) : false;
172 }
173 
GetPkInfoListImpl(int32_t osAccountId,const char * appId,const char * queryParams,char ** returnInfoList,uint32_t * returnInfoNum)174 int32_t GetPkInfoListImpl(int32_t osAccountId, const char *appId, const char *queryParams,
175     char **returnInfoList, uint32_t *returnInfoNum)
176 {
177     return IsGroupSupport() ? GetGroupImplInstance()->getPkInfoList(osAccountId, appId, queryParams,
178         returnInfoList, returnInfoNum) : HC_ERR_NOT_SUPPORT;
179 }
180 
DestroyInfoImpl(char ** returnInfo)181 void DestroyInfoImpl(char **returnInfo)
182 {
183     if (IsGroupSupport()) {
184         GetGroupImplInstance()->destroyInfo(returnInfo);
185     }
186 }
187 
BindPeerImpl(int64_t requestId,const char * appId,const char * bindParams)188 int32_t BindPeerImpl(int64_t requestId, const char *appId, const char *bindParams)
189 {
190     return RequestBindPeer(requestId, appId, bindParams);
191 }
192 
UnbindPeerImpl(int64_t requestId,const char * appId,const char * unbindParams)193 int32_t UnbindPeerImpl(int64_t requestId, const char *appId, const char *unbindParams)
194 {
195     return RequestUnbindPeer(requestId, appId, unbindParams);
196 }
197 
ProcessLiteDataImpl(int64_t requestId,const char * appId,const uint8_t * data,uint32_t dataLen)198 int32_t ProcessLiteDataImpl(int64_t requestId, const char *appId, const uint8_t *data, uint32_t dataLen)
199 {
200     return RequestProcessLiteData(requestId, appId, data, dataLen);
201 }
202 
AuthKeyAgreeImpl(int64_t requestId,const char * appId,const char * agreeParams)203 int32_t AuthKeyAgreeImpl(int64_t requestId, const char *appId, const char *agreeParams)
204 {
205     return RequestAuthKeyAgree(requestId, appId, agreeParams);
206 }
207 
ProcessKeyAgreeDataImpl(int64_t requestId,const char * appId,const uint8_t * data,uint32_t dataLen)208 int32_t ProcessKeyAgreeDataImpl(int64_t requestId, const char *appId, const uint8_t *data, uint32_t dataLen)
209 {
210     return RequestProcessKeyAgreeData(requestId, appId, data, dataLen);
211 }
212 
InitGroupManager(void)213 int32_t InitGroupManager(void)
214 {
215     if (InitDatabase() != HC_SUCCESS) {
216         return HC_ERR_SERVICE_NEED_RESTART;
217     }
218     return IsGroupSupport() ? InitGroupRelatedModule() : HC_SUCCESS;
219 }
220 
DestroyGroupManager(void)221 void DestroyGroupManager(void)
222 {
223     if (IsGroupSupport()) {
224         DestroyGroupRelatedModule();
225     }
226     DestroyDatabase();
227 }