• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 DEVICE_AUTH_EXT
17 #define DEVICE_AUTH_EXT
18 
19 #include "device_auth.h"
20 #include "cJSON.h"
21 
22 /** The Type of account auth plugin. */
23 #define EXT_PLUGIN_ACCT_AUTH 1000
24 /** The Type of account lifecycle plugin. */
25 #define EXT_PLUGIN_ACCT_LIFECYCLE 1001
26 
27 /**
28  * @brief This structure describes the ext plugin context.
29  */
30 typedef struct ExtPluginCtx {
31     /** The context of ext, the user can inject the method into the plugin. */
32     void *instance;
33 } ExtPluginCtx;
34 
35 /**
36  * @brief This structure describes the base ext plugin.
37  */
38 typedef struct ExtPlugin {
39     /** The tyep of plugin, the caller can convert the plugin to object based on the type. */
40     int32_t pluginType;
41     /** The init function. */
42     int32_t (*init)(struct ExtPlugin *extPlugin, const cJSON *params, const struct ExtPluginCtx *context);
43     /** The destroy function. */
44     void (*destroy)(struct ExtPlugin *extPlugin);
45 } ExtPlugin;
46 
47 /**
48  * @brief This structure describes the ext list.
49  */
50 typedef struct ExtPluginNode {
51     /** The element of list, denote the plugin. */
52     ExtPlugin *plugin;
53     /** The next node of list. */
54     struct ExtPluginNode *next;
55 } ExtPluginNode, *ExtPluginList;
56 
57 /**
58  * @brief This structure describes the ext plugin.
59  */
60 typedef struct ExtPart {
61     /** The instance of plugin. */
62     void *instance;
63 } ExtPart;
64 
65 /**
66  * @brief This structure describes task function.
67  */
68 typedef struct ExtWorkerTask {
69     /** The function of task, this can execute time-consuming function. */
70     void (*execute)(struct ExtWorkerTask *task);
71 
72     /** The deinit of task, this can destroy the task. */
73     void (*destroy)(struct ExtWorkerTask *task);
74 } ExtWorkerTask;
75 
76 /**
77  * @brief This structure describes account auth plugin.
78  */
79 typedef struct {
80     /** The base object contains init func and destroy func. */
81     ExtPlugin base;
82     /** Call it when account cred needs to update, query, delete or add. */
83     int32_t (*excuteCredMgrCmd)(int32_t osAccount, int32_t cmdId, const cJSON *in, cJSON *out);
84     /** This function is used to initiate authentication between devices.. */
85     int32_t (*createSession)(int32_t *sessionId, const cJSON *in, cJSON *out);
86     /** This function is used to process authentication dat. */
87     int32_t (*processSession)(int32_t *sessionId, const cJSON *in, cJSON *out, int32_t *status);
88     /** This function is used to destroy authentication dat. */
89     int32_t (*destroySession)(int32_t sessionId);
90 } AccountAuthExtPlug;
91 
92 /**
93  * @brief This structure describes the account auth plugin context.
94  */
95 typedef struct {
96     /** The base context. */
97     ExtPluginCtx base;
98     /** The function will return storage path. */
99     const char *(*getStoragePath)(void);
100 } AccountAuthExtPlugCtx;
101 
102 /**
103  * @brief This structure describes the account lifecycle plugin.
104  */
105 typedef struct {
106     /** The base account lifecycle plugin. */
107     ExtPlugin base;
108 } AccountLifecyleExtPlug;
109 
110 /**
111  * @brief This structure describes the account lifecycle plugin context.
112  */
113 typedef struct {
114     /** The base account lifecycle context. */
115     ExtPluginCtx base;
116     /** This interface is used to create a trusted group. */
117     int32_t (*createGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams);
118     /** This interface is used to delete a trusted group. */
119     int32_t (*deleteGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *disbandParams);
120     /** This interface is used to obtain the group information of groups that meet the query parameters. */
121     int32_t (*getGroupInfo)(int32_t osAccountId, const char *appId, const char *queryParams,
122         char **returnGroupVec, uint32_t *groupNum);
123     /** This interface is used to obtain the registration information of the local device. */
124     int32_t (*getRegisterInfo)(const char *reqJsonStr, char **returnRegisterInfo);
125     /** This interface is used to register business callbacks. */
126     int32_t (*regCallback)(const char *appId, const DeviceAuthCallback *callback);
127     /** This interface is used to unregister business callbacks. */
128     int32_t (*unRegCallback)(const char *appId);
129     /** This interface is used to execute business function. */
130     int32_t (*executeWorkerTask)(struct ExtWorkerTask *task);
131     /** This interface is used to notify the account async task is started. */
132     void (*notifyAsyncTaskStart)(void);
133     /** This interface is used to notify the account async task is stopped. */
134     void (*notifyAsyncTaskStop)(void);
135     /** This interface is used to import credential data. */
136     int32_t (*addCredential)(int32_t osAccountId, const char *requestParams, char **returnData);
137     /** This interface is used to export credential data. */
138     int32_t (*exportCredential)(int32_t osAccountId, const char *credId, char **returnData);
139     /** This interface is used to delete credential data. */
140     int32_t (*deleteCredential)(int32_t osAccountId, const char *credId);
141     /** This interface is used to update cred info. */
142     int32_t (*updateCredInfo)(int32_t osAccountId, const char *credId, const char *requestParams);
143     /** This interface is used to query credential data by cred id. */
144     int32_t (*queryCredInfoByCredId)(int32_t osAccountId, int32_t uid, const char *credId, char **returnData);
145     /** This interface is used to query credential data by cred param. */
146     int32_t (*queryCredentialByParams)(int32_t osAccountId, const char *requestParams, char **returnData);
147     /** This interface is used to destroy the information returned by the internal allocated memory. */
148     void (*destroyInfo)(char **returnInfo);
149 } AccountLifecyleExtPlugCtx;
150 
151 #ifdef __cplusplus
152 extern "C" {
153 #endif
154 
155 /**
156  * @brief Initialize ext part.
157  *
158  * This API is used to initialize ext part.
159  *
160  * @param params The plugin needs params.
161  * @param extPart The interface of ext part.
162  * @return When the service initialization is successful, it returns HC_SUCCESS.
163  * Otherwise, it returns other values.
164  */
165 int32_t InitExtPart(const cJSON *params, ExtPart *extPart);
166 
167 /**
168  * @brief Get plugin list.
169  *
170  * This API is used to get all plugins.
171  *
172  * @param extPart The interface of ext part.
173  * @return The list of plugin.
174  */
175 ExtPluginList GetExtPlugins(ExtPart *extPart);
176 
177 /**
178  * @brief Destroy ext part.
179  *
180  * This API is used to destroy ext part.
181  *
182  * @param extPart The interface of ext part.
183  */
184 void DestroyExtPart(ExtPart *extPart);
185 
186 #ifdef __cplusplus
187 }
188 #endif
189 
190 #endif
191