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 } AccountAuthExtPlug; 89 90 /** 91 * @brief This structure describes the account auth plugin context. 92 */ 93 typedef struct { 94 /** The base context. */ 95 ExtPluginCtx base; 96 /** The function will return storage path. */ 97 const char *(*getStoragePath)(void); 98 } AccountAuthExtPlugCtx; 99 100 /** 101 * @brief This structure describes the account lifecycle plugin. 102 */ 103 typedef struct { 104 /** The base account lifecycle plugin. */ 105 ExtPlugin base; 106 } AccountLifecyleExtPlug; 107 108 /** 109 * @brief This structure describes the account lifecycle plugin context. 110 */ 111 typedef struct { 112 /** The base account lifecycle context. */ 113 ExtPluginCtx base; 114 /** This interface is used to create a trusted group. */ 115 int32_t (*createGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams); 116 /** This interface is used to delete a trusted group. */ 117 int32_t (*deleteGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *disbandParams); 118 /** This interface is used to obtain the group information of groups that meet the query parameters. */ 119 int32_t (*getGroupInfo)(int32_t osAccountId, const char *appId, const char *queryParams, 120 char **returnGroupVec, uint32_t *groupNum); 121 /** This interface is used to obtain the registration information of the local device. */ 122 int32_t (*getRegisterInfo)(const char *reqJsonStr, char **returnRegisterInfo); 123 /** This interface is used to register business callbacks. */ 124 int32_t (*regCallback)(const char *appId, const DeviceAuthCallback *callback); 125 /** This interface is used to unregister business callbacks. */ 126 int32_t (*unRegCallback)(const char *appId); 127 /** This interface is used to execute business function. */ 128 int32_t (*executeWorkerTask)(struct ExtWorkerTask *task); 129 } AccountLifecyleExtPlugCtx; 130 131 #ifdef __cplusplus 132 extern "C" { 133 #endif 134 135 /** 136 * @brief Initialize ext part. 137 * 138 * This API is used to initialize ext part. 139 * 140 * @param params The plugin needs params. 141 * @param extPart The interface of ext part. 142 * @return When the service initialization is successful, it returns HC_SUCCESS. 143 * Otherwise, it returns other values. 144 */ 145 int32_t InitExtPart(const cJSON *params, ExtPart *extPart); 146 147 /** 148 * @brief Get plugin list. 149 * 150 * This API is used to get all plugins. 151 * 152 * @param extPart The interface of ext part. 153 * @return The list of plugin. 154 */ 155 ExtPluginList GetExtPlugins(ExtPart *extPart); 156 157 /** 158 * @brief Destroy ext part. 159 * 160 * This API is used to destroy ext part. 161 * 162 * @param extPart The interface of ext part. 163 */ 164 void DestroyExtPart(ExtPart *extPart); 165 166 #ifdef __cplusplus 167 } 168 #endif 169 170 #endif 171