117fd14ceSopenharmony_ci/*
217fd14ceSopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
317fd14ceSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
417fd14ceSopenharmony_ci * you may not use this file except in compliance with the License.
517fd14ceSopenharmony_ci * You may obtain a copy of the License at
617fd14ceSopenharmony_ci *
717fd14ceSopenharmony_ci *    http://www.apache.org/licenses/LICENSE-2.0
817fd14ceSopenharmony_ci *
917fd14ceSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1017fd14ceSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1117fd14ceSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1217fd14ceSopenharmony_ci * See the License for the specific language governing permissions and
1317fd14ceSopenharmony_ci * limitations under the License.
1417fd14ceSopenharmony_ci */
1517fd14ceSopenharmony_ci
1617fd14ceSopenharmony_ci#ifndef DEVICE_AUTH_EXT
1717fd14ceSopenharmony_ci#define DEVICE_AUTH_EXT
1817fd14ceSopenharmony_ci
1917fd14ceSopenharmony_ci#include "device_auth.h"
2017fd14ceSopenharmony_ci#include "cJSON.h"
2117fd14ceSopenharmony_ci
2217fd14ceSopenharmony_ci/** The Type of account auth plugin. */
2317fd14ceSopenharmony_ci#define EXT_PLUGIN_ACCT_AUTH 1000
2417fd14ceSopenharmony_ci/** The Type of account lifecycle plugin. */
2517fd14ceSopenharmony_ci#define EXT_PLUGIN_ACCT_LIFECYCLE 1001
2617fd14ceSopenharmony_ci
2717fd14ceSopenharmony_ci/**
2817fd14ceSopenharmony_ci * @brief This structure describes the ext plugin context.
2917fd14ceSopenharmony_ci */
3017fd14ceSopenharmony_citypedef struct ExtPluginCtx {
3117fd14ceSopenharmony_ci    /** The context of ext, the user can inject the method into the plugin. */
3217fd14ceSopenharmony_ci    void *instance;
3317fd14ceSopenharmony_ci} ExtPluginCtx;
3417fd14ceSopenharmony_ci
3517fd14ceSopenharmony_ci/**
3617fd14ceSopenharmony_ci * @brief This structure describes the base ext plugin.
3717fd14ceSopenharmony_ci */
3817fd14ceSopenharmony_citypedef struct ExtPlugin {
3917fd14ceSopenharmony_ci    /** The tyep of plugin, the caller can convert the plugin to object based on the type. */
4017fd14ceSopenharmony_ci    int32_t pluginType;
4117fd14ceSopenharmony_ci    /** The init function. */
4217fd14ceSopenharmony_ci    int32_t (*init)(struct ExtPlugin *extPlugin, const cJSON *params, const struct ExtPluginCtx *context);
4317fd14ceSopenharmony_ci    /** The destroy function. */
4417fd14ceSopenharmony_ci    void (*destroy)(struct ExtPlugin *extPlugin);
4517fd14ceSopenharmony_ci} ExtPlugin;
4617fd14ceSopenharmony_ci
4717fd14ceSopenharmony_ci/**
4817fd14ceSopenharmony_ci * @brief This structure describes the ext list.
4917fd14ceSopenharmony_ci */
5017fd14ceSopenharmony_citypedef struct ExtPluginNode {
5117fd14ceSopenharmony_ci    /** The element of list, denote the plugin. */
5217fd14ceSopenharmony_ci    ExtPlugin *plugin;
5317fd14ceSopenharmony_ci    /** The next node of list. */
5417fd14ceSopenharmony_ci    struct ExtPluginNode *next;
5517fd14ceSopenharmony_ci} ExtPluginNode, *ExtPluginList;
5617fd14ceSopenharmony_ci
5717fd14ceSopenharmony_ci/**
5817fd14ceSopenharmony_ci * @brief This structure describes the ext plugin.
5917fd14ceSopenharmony_ci */
6017fd14ceSopenharmony_citypedef struct ExtPart {
6117fd14ceSopenharmony_ci    /** The instance of plugin. */
6217fd14ceSopenharmony_ci    void *instance;
6317fd14ceSopenharmony_ci} ExtPart;
6417fd14ceSopenharmony_ci
6517fd14ceSopenharmony_ci/**
6617fd14ceSopenharmony_ci * @brief This structure describes task function.
6717fd14ceSopenharmony_ci */
6817fd14ceSopenharmony_citypedef struct ExtWorkerTask {
6917fd14ceSopenharmony_ci    /** The function of task, this can execute time-consuming function. */
7017fd14ceSopenharmony_ci    void (*execute)(struct ExtWorkerTask *task);
7117fd14ceSopenharmony_ci
7217fd14ceSopenharmony_ci    /** The deinit of task, this can destroy the task. */
7317fd14ceSopenharmony_ci    void (*destroy)(struct ExtWorkerTask *task);
7417fd14ceSopenharmony_ci} ExtWorkerTask;
7517fd14ceSopenharmony_ci
7617fd14ceSopenharmony_ci/**
7717fd14ceSopenharmony_ci * @brief This structure describes account auth plugin.
7817fd14ceSopenharmony_ci */
7917fd14ceSopenharmony_citypedef struct {
8017fd14ceSopenharmony_ci    /** The base object contains init func and destroy func. */
8117fd14ceSopenharmony_ci    ExtPlugin base;
8217fd14ceSopenharmony_ci    /** Call it when account cred needs to update, query, delete or add. */
8317fd14ceSopenharmony_ci    int32_t (*excuteCredMgrCmd)(int32_t osAccount, int32_t cmdId, const cJSON *in, cJSON *out);
8417fd14ceSopenharmony_ci    /** This function is used to initiate authentication between devices.. */
8517fd14ceSopenharmony_ci    int32_t (*createSession)(int32_t *sessionId, const cJSON *in, cJSON *out);
8617fd14ceSopenharmony_ci    /** This function is used to process authentication dat. */
8717fd14ceSopenharmony_ci    int32_t (*processSession)(int32_t *sessionId, const cJSON *in, cJSON *out, int32_t *status);
8817fd14ceSopenharmony_ci    /** This function is used to destroy authentication dat. */
8917fd14ceSopenharmony_ci    int32_t (*destroySession)(int32_t sessionId);
9017fd14ceSopenharmony_ci} AccountAuthExtPlug;
9117fd14ceSopenharmony_ci
9217fd14ceSopenharmony_ci/**
9317fd14ceSopenharmony_ci * @brief This structure describes the account auth plugin context.
9417fd14ceSopenharmony_ci */
9517fd14ceSopenharmony_citypedef struct {
9617fd14ceSopenharmony_ci    /** The base context. */
9717fd14ceSopenharmony_ci    ExtPluginCtx base;
9817fd14ceSopenharmony_ci    /** The function will return storage path. */
9917fd14ceSopenharmony_ci    const char *(*getStoragePath)(void);
10017fd14ceSopenharmony_ci} AccountAuthExtPlugCtx;
10117fd14ceSopenharmony_ci
10217fd14ceSopenharmony_ci/**
10317fd14ceSopenharmony_ci * @brief This structure describes the account lifecycle plugin.
10417fd14ceSopenharmony_ci */
10517fd14ceSopenharmony_citypedef struct {
10617fd14ceSopenharmony_ci    /** The base account lifecycle plugin. */
10717fd14ceSopenharmony_ci    ExtPlugin base;
10817fd14ceSopenharmony_ci} AccountLifecyleExtPlug;
10917fd14ceSopenharmony_ci
11017fd14ceSopenharmony_ci/**
11117fd14ceSopenharmony_ci * @brief This structure describes the account lifecycle plugin context.
11217fd14ceSopenharmony_ci */
11317fd14ceSopenharmony_citypedef struct {
11417fd14ceSopenharmony_ci    /** The base account lifecycle context. */
11517fd14ceSopenharmony_ci    ExtPluginCtx base;
11617fd14ceSopenharmony_ci    /** This interface is used to create a trusted group. */
11717fd14ceSopenharmony_ci    int32_t (*createGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams);
11817fd14ceSopenharmony_ci    /** This interface is used to delete a trusted group. */
11917fd14ceSopenharmony_ci    int32_t (*deleteGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *disbandParams);
12017fd14ceSopenharmony_ci    /** This interface is used to obtain the group information of groups that meet the query parameters. */
12117fd14ceSopenharmony_ci    int32_t (*getGroupInfo)(int32_t osAccountId, const char *appId, const char *queryParams,
12217fd14ceSopenharmony_ci        char **returnGroupVec, uint32_t *groupNum);
12317fd14ceSopenharmony_ci    /** This interface is used to obtain the registration information of the local device. */
12417fd14ceSopenharmony_ci    int32_t (*getRegisterInfo)(const char *reqJsonStr, char **returnRegisterInfo);
12517fd14ceSopenharmony_ci    /** This interface is used to register business callbacks. */
12617fd14ceSopenharmony_ci    int32_t (*regCallback)(const char *appId, const DeviceAuthCallback *callback);
12717fd14ceSopenharmony_ci    /** This interface is used to unregister business callbacks. */
12817fd14ceSopenharmony_ci    int32_t (*unRegCallback)(const char *appId);
12917fd14ceSopenharmony_ci    /** This interface is used to execute business function. */
13017fd14ceSopenharmony_ci    int32_t (*executeWorkerTask)(struct ExtWorkerTask *task);
13117fd14ceSopenharmony_ci} AccountLifecyleExtPlugCtx;
13217fd14ceSopenharmony_ci
13317fd14ceSopenharmony_ci#ifdef __cplusplus
13417fd14ceSopenharmony_ciextern "C" {
13517fd14ceSopenharmony_ci#endif
13617fd14ceSopenharmony_ci
13717fd14ceSopenharmony_ci/**
13817fd14ceSopenharmony_ci * @brief Initialize ext part.
13917fd14ceSopenharmony_ci *
14017fd14ceSopenharmony_ci * This API is used to initialize ext part.
14117fd14ceSopenharmony_ci *
14217fd14ceSopenharmony_ci * @param params The plugin needs params.
14317fd14ceSopenharmony_ci * @param extPart The interface of ext part.
14417fd14ceSopenharmony_ci * @return When the service initialization is successful, it returns HC_SUCCESS.
14517fd14ceSopenharmony_ci * Otherwise, it returns other values.
14617fd14ceSopenharmony_ci */
14717fd14ceSopenharmony_ciint32_t InitExtPart(const cJSON *params, ExtPart *extPart);
14817fd14ceSopenharmony_ci
14917fd14ceSopenharmony_ci/**
15017fd14ceSopenharmony_ci * @brief Get plugin list.
15117fd14ceSopenharmony_ci *
15217fd14ceSopenharmony_ci * This API is used to get all plugins.
15317fd14ceSopenharmony_ci *
15417fd14ceSopenharmony_ci * @param extPart The interface of ext part.
15517fd14ceSopenharmony_ci * @return The list of plugin.
15617fd14ceSopenharmony_ci */
15717fd14ceSopenharmony_ciExtPluginList GetExtPlugins(ExtPart *extPart);
15817fd14ceSopenharmony_ci
15917fd14ceSopenharmony_ci/**
16017fd14ceSopenharmony_ci * @brief Destroy ext part.
16117fd14ceSopenharmony_ci *
16217fd14ceSopenharmony_ci * This API is used to destroy ext part.
16317fd14ceSopenharmony_ci *
16417fd14ceSopenharmony_ci * @param extPart The interface of ext part.
16517fd14ceSopenharmony_ci */
16617fd14ceSopenharmony_civoid DestroyExtPart(ExtPart *extPart);
16717fd14ceSopenharmony_ci
16817fd14ceSopenharmony_ci#ifdef __cplusplus
16917fd14ceSopenharmony_ci}
17017fd14ceSopenharmony_ci#endif
17117fd14ceSopenharmony_ci
17217fd14ceSopenharmony_ci#endif
173