• 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 #include "device_auth_ext.h"
17 #include "device_auth_defines.h"
18 #include "hc_log.h"
19 #include "hc_types.h"
20 #include "json_utils.h"
21 
22 static ExtPluginList g_list = NULL;
23 
InitPlugin(struct ExtPlugin * extPlugin,const cJSON * params,const struct ExtPluginCtx * context)24 int32_t InitPlugin(struct ExtPlugin *extPlugin, const cJSON *params, const struct ExtPluginCtx *context)
25 {
26     (void)extPlugin;
27     (void)params;
28     (void)context;
29     return HC_SUCCESS;
30 }
31 
DestroyPlugin(struct ExtPlugin * extPlugin)32 void DestroyPlugin(struct ExtPlugin *extPlugin)
33 {
34     (void)extPlugin;
35     LOGI("DestroyPlugin");
36 }
37 
CreateNode(int32_t plugType)38 ExtPluginNode *CreateNode(int32_t plugType)
39 {
40     LOGI("CreateNode");
41     ExtPluginNode *node = (ExtPluginNode *)HcMalloc(sizeof(ExtPluginNode), 0);
42     if (node == NULL) {
43         LOGE("Failed to malloc plugin node!");
44         return NULL;
45     }
46     node->plugin = (ExtPlugin *)HcMalloc(sizeof(ExtPlugin), 0);
47     if (node->plugin == NULL) {
48         LOGE("Failed to malloc plugin!");
49         HcFree(node);
50         return NULL;
51     }
52     node->plugin->pluginType = plugType;
53     node->plugin->init = InitPlugin;
54     node->plugin->destroy = DestroyPlugin;
55     node->next = NULL;
56     return node;
57 }
58 
AddPlugin(ExtPluginList * list,ExtPluginNode * node)59 void AddPlugin(ExtPluginList *list, ExtPluginNode *node)
60 {
61     if (*list == NULL) {
62         *list = node;
63     } else {
64         ExtPluginNode *p = *list;
65         while (p->next != NULL) {
66             p = p->next;
67         }
68         p->next = node;
69     }
70 }
71 
DestroyList(ExtPluginList list)72 void DestroyList(ExtPluginList list)
73 {
74     while (list != NULL) {
75         ExtPluginNode *node = list;
76         list = list->next;
77         HcFree(node->plugin);
78         node->plugin = NULL;
79         HcFree(node);
80         node = NULL;
81     }
82 }
83 
InitExtPart(const cJSON * params,ExtPart * extPart)84 int32_t InitExtPart(const cJSON *params, ExtPart *extPart)
85 {
86     LOGI("InitExtPart.");
87     (void)params;
88     if (extPart == NULL) {
89         return HC_ERR_INVALID_PARAMS;
90     }
91     extPart->instance = (ExtPart *)HcMalloc(sizeof(ExtPart), 0);
92     if (extPart->instance == NULL) {
93         return HC_ERR_ALLOC_MEMORY;
94     }
95     return HC_SUCCESS;
96 }
97 
GetExtPlugins(ExtPart * extPart)98 ExtPluginList GetExtPlugins(ExtPart *extPart)
99 {
100     LOGI("GetExtPlugins.");
101     (void)extPart;
102     AddPlugin(&g_list, CreateNode(EXT_PLUGIN_ACCT_AUTH));
103     return g_list;
104 }
105 
DestroyExtPart(ExtPart * extPart)106 void DestroyExtPart(ExtPart *extPart)
107 {
108     LOGI("DestroyExtPart.");
109     if (extPart != NULL) {
110         HcFree(extPart->instance);
111         extPart->instance = NULL;
112     }
113     DestroyList(g_list);
114 }