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 */ 30typedef 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 */ 38typedef 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 */ 50typedef 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 */ 60typedef struct ExtPart { 61 /** The instance of plugin. */ 62 void *instance; 63} ExtPart; 64 65/** 66 * @brief This structure describes task function. 67 */ 68typedef 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 */ 79typedef 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 */ 95typedef 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 */ 105typedef 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 */ 113typedef 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} AccountLifecyleExtPlugCtx; 132 133#ifdef __cplusplus 134extern "C" { 135#endif 136 137/** 138 * @brief Initialize ext part. 139 * 140 * This API is used to initialize ext part. 141 * 142 * @param params The plugin needs params. 143 * @param extPart The interface of ext part. 144 * @return When the service initialization is successful, it returns HC_SUCCESS. 145 * Otherwise, it returns other values. 146 */ 147int32_t InitExtPart(const cJSON *params, ExtPart *extPart); 148 149/** 150 * @brief Get plugin list. 151 * 152 * This API is used to get all plugins. 153 * 154 * @param extPart The interface of ext part. 155 * @return The list of plugin. 156 */ 157ExtPluginList GetExtPlugins(ExtPart *extPart); 158 159/** 160 * @brief Destroy ext part. 161 * 162 * This API is used to destroy ext part. 163 * 164 * @param extPart The interface of ext part. 165 */ 166void DestroyExtPart(ExtPart *extPart); 167 168#ifdef __cplusplus 169} 170#endif 171 172#endif 173