]>
Commit | Line | Data |
---|---|---|
5692db78 AC |
1 | /** @file\r |
2 | \r | |
3 | The implementation of EFI REST Resource JSON to C structure convertor\r | |
4 | Protocol.\r | |
5 | \r | |
6 | (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r | |
7 | \r | |
8 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
9 | \r | |
10 | **/\r | |
11 | \r | |
12 | #include <Uefi.h>\r | |
13 | #include <Protocol/RestJsonStructure.h>\r | |
14 | #include "RestJsonStructureInternal.h"\r | |
15 | \r | |
16 | LIST_ENTRY mRestJsonStructureList;\r | |
17 | EFI_HANDLE mProtocolHandle;\r | |
18 | \r | |
19 | /**\r | |
20 | This function registers Restful resource interpreter for the\r | |
21 | specific schema.\r | |
22 | \r | |
23 | @param[in] This This is the EFI_REST_JSON_STRUCTURE_PROTOCOL instance.\r | |
24 | @param[in] JsonStructureSupported The type and version of REST JSON resource which this converter\r | |
25 | supports.\r | |
26 | @param[in] ToStructure The function to convert REST JSON resource to structure.\r | |
27 | @param[in] ToJson The function to convert REST JSON structure to JSON in text format.\r | |
28 | @param[in] DestroyStructure Destroy REST JSON structure returned in ToStructure() function.\r | |
29 | \r | |
30 | @retval EFI_SUCCESS Register successfully.\r | |
31 | @retval Others Fail to register.\r | |
32 | \r | |
33 | **/\r | |
34 | EFI_STATUS\r | |
35 | EFIAPI\r | |
36 | RestJsonStructureRegister (\r | |
37 | IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,\r | |
38 | IN EFI_REST_JSON_STRUCTURE_SUPPORTED *JsonStructureSupported,\r | |
39 | IN EFI_REST_JSON_STRUCTURE_TO_STRUCTURE ToStructure,\r | |
40 | IN EFI_REST_JSON_STRUCTURE_TO_JSON ToJson,\r | |
41 | IN EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure\r | |
42 | )\r | |
43 | {\r | |
44 | UINTN NumberOfNS;\r | |
45 | UINTN Index;\r | |
46 | LIST_ENTRY *ThisList;\r | |
47 | REST_JSON_STRUCTURE_INSTANCE *Instance;\r | |
48 | EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *CloneSupportedInterpId;\r | |
49 | EFI_REST_JSON_STRUCTURE_SUPPORTED *ThisSupportedInterp;\r | |
50 | \r | |
51 | if (This == NULL ||\r | |
52 | ToStructure == NULL ||\r | |
53 | ToJson == NULL ||\r | |
54 | DestroyStructure == NULL ||\r | |
55 | JsonStructureSupported == NULL\r | |
56 | ) {\r | |
57 | return EFI_INVALID_PARAMETER;\r | |
58 | }\r | |
59 | \r | |
60 | //\r | |
61 | // Check how many name space interpreter can interpret.\r | |
62 | //\r | |
63 | ThisList = &JsonStructureSupported->NextSupportedRsrcInterp;\r | |
64 | NumberOfNS = 1;\r | |
65 | while (TRUE) {\r | |
66 | if (ThisList->ForwardLink == &JsonStructureSupported->NextSupportedRsrcInterp) {\r | |
67 | break;\r | |
68 | } else {\r | |
69 | ThisList = ThisList->ForwardLink;\r | |
70 | NumberOfNS ++;\r | |
71 | }\r | |
72 | };\r | |
73 | \r | |
74 | Instance =\r | |
75 | (REST_JSON_STRUCTURE_INSTANCE *)AllocateZeroPool (sizeof (REST_JSON_STRUCTURE_INSTANCE) + NumberOfNS * sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER));\r | |
76 | if (Instance == NULL) {\r | |
77 | return EFI_OUT_OF_RESOURCES;\r | |
78 | }\r | |
79 | InitializeListHead (&Instance->NextRestJsonStructureInstance);\r | |
80 | Instance->NumberOfNameSpaceToConvert = NumberOfNS;\r | |
81 | Instance->SupportedRsrcIndentifier = (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *)((REST_JSON_STRUCTURE_INSTANCE *)Instance + 1);\r | |
82 | //\r | |
83 | // Copy supported resource identifer interpreter.\r | |
84 | //\r | |
85 | CloneSupportedInterpId = Instance->SupportedRsrcIndentifier;\r | |
86 | ThisSupportedInterp = JsonStructureSupported;\r | |
87 | for (Index = 0; Index < NumberOfNS; Index ++) {\r | |
88 | CopyMem ((VOID *)CloneSupportedInterpId, (VOID *)&ThisSupportedInterp->RestResourceInterp, sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER));\r | |
89 | ThisSupportedInterp = (EFI_REST_JSON_STRUCTURE_SUPPORTED *)ThisSupportedInterp->NextSupportedRsrcInterp.ForwardLink;\r | |
90 | CloneSupportedInterpId ++;\r | |
91 | }\r | |
92 | Instance->JsonToStructure = ToStructure;\r | |
93 | Instance->StructureToJson = ToJson;\r | |
94 | Instance->DestroyStructure = DestroyStructure;\r | |
95 | InsertTailList (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);\r | |
96 | return EFI_SUCCESS;\r | |
97 | }\r | |
98 | \r | |
99 | /**\r | |
100 | This function check if this interpreter instance support the given namesapce.\r | |
101 | \r | |
102 | @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL instance.\r | |
103 | @param[in] InterpreterInstance REST_JSON_STRUCTURE_INSTANCE\r | |
104 | @param[in] RsrcTypeIdentifier Resource type identifier.\r | |
105 | @param[in] ResourceRaw Given Restful resource.\r | |
106 | @param[out] RestJSonHeader Property interpreted from given ResourceRaw.\r | |
107 | \r | |
108 | @retval EFI_SUCCESS\r | |
109 | @retval Others.\r | |
110 | \r | |
111 | **/\r | |
112 | EFI_STATUS\r | |
113 | InterpreterInstanceToStruct (\r | |
114 | IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,\r | |
115 | IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance,\r | |
116 | IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier OPTIONAL,\r | |
117 | IN CHAR8 *ResourceRaw,\r | |
118 | OUT EFI_REST_JSON_STRUCTURE_HEADER **RestJSonHeader\r | |
119 | )\r | |
120 | {\r | |
121 | UINTN Index;\r | |
122 | EFI_STATUS Status;\r | |
123 | EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;\r | |
124 | \r | |
125 | if (This == NULL ||\r | |
126 | InterpreterInstance == NULL ||\r | |
127 | ResourceRaw == NULL ||\r | |
128 | RestJSonHeader == NULL\r | |
129 | ) {\r | |
130 | return EFI_INVALID_PARAMETER;\r | |
131 | }\r | |
132 | \r | |
133 | Status = EFI_UNSUPPORTED;\r | |
134 | if (RsrcTypeIdentifier == NULL) {\r | |
135 | //\r | |
136 | // No resource type identifier, send to intepreter anyway.\r | |
137 | // Interpreter may recognize this resource.\r | |
138 | //\r | |
139 | Status = InterpreterInstance->JsonToStructure (\r | |
140 | This,\r | |
141 | NULL,\r | |
142 | ResourceRaw,\r | |
143 | RestJSonHeader\r | |
144 | );\r | |
145 | } else {\r | |
146 | //\r | |
147 | // Check if the namesapce and version is supported by this interpreter.\r | |
148 | //\r | |
149 | ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;\r | |
150 | for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index ++){\r | |
151 | if (AsciiStrCmp (\r | |
152 | RsrcTypeIdentifier->NameSpace.ResourceTypeName,\r | |
153 | ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) == 0){\r | |
154 | if ((RsrcTypeIdentifier->NameSpace.MajorVersion == NULL) &&\r | |
155 | (RsrcTypeIdentifier->NameSpace.MinorVersion == NULL) &&\r | |
156 | (RsrcTypeIdentifier->NameSpace.ErrataVersion == NULL)\r | |
157 | ) {\r | |
158 | //\r | |
159 | // Don't check version of this resource type identifier.\r | |
160 | //\r | |
161 | Status = InterpreterInstance->JsonToStructure (\r | |
162 | This,\r | |
163 | RsrcTypeIdentifier,\r | |
164 | ResourceRaw,\r | |
165 | RestJSonHeader\r | |
166 | );\r | |
167 | break;\r | |
168 | } else {\r | |
169 | //\r | |
170 | // Check version.\r | |
171 | //\r | |
172 | if ((AsciiStrCmp (\r | |
173 | RsrcTypeIdentifier->NameSpace.MajorVersion,\r | |
174 | ThisSupportedRsrcTypeId->NameSpace.MajorVersion) == 0) &&\r | |
175 | (AsciiStrCmp (\r | |
176 | RsrcTypeIdentifier->NameSpace.MinorVersion,\r | |
177 | ThisSupportedRsrcTypeId->NameSpace.MinorVersion) == 0) &&\r | |
178 | (AsciiStrCmp (\r | |
179 | RsrcTypeIdentifier->NameSpace.ErrataVersion,\r | |
180 | ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) == 0)) {\r | |
181 | Status = InterpreterInstance->JsonToStructure (\r | |
182 | This,\r | |
183 | RsrcTypeIdentifier,\r | |
184 | ResourceRaw,\r | |
185 | RestJSonHeader\r | |
186 | );\r | |
187 | break;\r | |
188 | }\r | |
189 | }\r | |
190 | }\r | |
191 | ThisSupportedRsrcTypeId ++;\r | |
192 | }\r | |
193 | }\r | |
194 | return Status;\r | |
195 | }\r | |
196 | /**\r | |
197 | This function converts JSON C structure to JSON property.\r | |
198 | \r | |
199 | @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL instance.\r | |
200 | @param[in] InterpreterInstance REST_JSON_STRUCTURE_INSTANCE\r | |
201 | @param[in] RestJSonHeader Resource type identifier.\r | |
202 | @param[out] ResourceRaw Output in JSON text format.\r | |
203 | \r | |
204 | @retval EFI_SUCCESS\r | |
205 | @retval Others.\r | |
206 | \r | |
207 | **/\r | |
208 | EFI_STATUS\r | |
209 | InterpreterEfiStructToInstance (\r | |
210 | IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,\r | |
211 | IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance,\r | |
212 | IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader,\r | |
213 | OUT CHAR8 **ResourceRaw\r | |
214 | )\r | |
215 | {\r | |
216 | UINTN Index;\r | |
217 | EFI_STATUS Status;\r | |
218 | EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;\r | |
219 | EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier;\r | |
220 | \r | |
221 | if (This == NULL ||\r | |
222 | InterpreterInstance == NULL ||\r | |
223 | RestJSonHeader == NULL ||\r | |
224 | ResourceRaw == NULL\r | |
225 | ) {\r | |
226 | return EFI_INVALID_PARAMETER;\r | |
227 | }\r | |
228 | RsrcTypeIdentifier = &RestJSonHeader->JsonRsrcIdentifier;\r | |
229 | if (RsrcTypeIdentifier == NULL ||\r | |
230 | RsrcTypeIdentifier->NameSpace.ResourceTypeName == NULL ||\r | |
231 | RsrcTypeIdentifier->NameSpace.MajorVersion == NULL ||\r | |
232 | RsrcTypeIdentifier->NameSpace.MinorVersion == NULL ||\r | |
233 | RsrcTypeIdentifier->NameSpace.ErrataVersion == NULL\r | |
234 | ) {\r | |
235 | return EFI_INVALID_PARAMETER;\r | |
236 | }\r | |
237 | \r | |
238 | //\r | |
239 | // Check if the namesapce and version is supported by this interpreter.\r | |
240 | //\r | |
241 | Status = EFI_UNSUPPORTED;\r | |
242 | ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;\r | |
243 | for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index ++){\r | |
244 | if (AsciiStrCmp (\r | |
245 | RsrcTypeIdentifier->NameSpace.ResourceTypeName,\r | |
246 | ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) == 0){\r | |
247 | //\r | |
248 | // Check version.\r | |
249 | //\r | |
250 | if ((AsciiStrCmp (\r | |
251 | RsrcTypeIdentifier->NameSpace.MajorVersion,\r | |
252 | ThisSupportedRsrcTypeId->NameSpace.MajorVersion) == 0) &&\r | |
253 | (AsciiStrCmp (\r | |
254 | RsrcTypeIdentifier->NameSpace.MinorVersion,\r | |
255 | ThisSupportedRsrcTypeId->NameSpace.MinorVersion) == 0) &&\r | |
256 | (AsciiStrCmp (\r | |
257 | RsrcTypeIdentifier->NameSpace.ErrataVersion,\r | |
258 | ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) == 0)) {\r | |
259 | Status = InterpreterInstance->StructureToJson (\r | |
260 | This,\r | |
261 | RestJSonHeader,\r | |
262 | ResourceRaw\r | |
263 | );\r | |
264 | break;\r | |
265 | }\r | |
266 | }\r | |
267 | ThisSupportedRsrcTypeId ++;\r | |
268 | }\r | |
269 | return Status;\r | |
270 | }\r | |
271 | \r | |
272 | /**\r | |
273 | This function destory REST property structure.\r | |
274 | \r | |
275 | @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL instance.\r | |
276 | @param[in] InterpreterInstance REST_JSON_STRUCTURE_INSTANCE\r | |
277 | @param[in] RestJSonHeader Property interpreted from given ResourceRaw.\r | |
278 | \r | |
279 | @retval EFI_SUCCESS\r | |
280 | @retval Others.\r | |
281 | \r | |
282 | **/\r | |
283 | EFI_STATUS\r | |
284 | InterpreterInstanceDestoryJsonStruct (\r | |
285 | IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,\r | |
286 | IN REST_JSON_STRUCTURE_INSTANCE *InterpreterInstance,\r | |
287 | IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader\r | |
288 | )\r | |
289 | {\r | |
290 | UINTN Index;\r | |
291 | EFI_STATUS Status;\r | |
292 | EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;\r | |
293 | \r | |
294 | if (This == NULL ||\r | |
295 | InterpreterInstance == NULL ||\r | |
296 | RestJSonHeader == NULL\r | |
297 | ) {\r | |
298 | return EFI_INVALID_PARAMETER;\r | |
299 | }\r | |
300 | \r | |
301 | Status = EFI_UNSUPPORTED;\r | |
302 | //\r | |
303 | // Check if the namesapce and version is supported by this interpreter.\r | |
304 | //\r | |
305 | ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;\r | |
306 | for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index ++){\r | |
307 | if (AsciiStrCmp (\r | |
308 | RestJSonHeader->JsonRsrcIdentifier.NameSpace.ResourceTypeName,\r | |
309 | ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) == 0) {\r | |
310 | if ((RestJSonHeader->JsonRsrcIdentifier.NameSpace.MajorVersion == NULL) &&\r | |
311 | (RestJSonHeader->JsonRsrcIdentifier.NameSpace.MinorVersion == NULL) &&\r | |
312 | (RestJSonHeader->JsonRsrcIdentifier.NameSpace.ErrataVersion == NULL)\r | |
313 | ) {\r | |
314 | //\r | |
315 | // Don't check version of this resource type identifier.\r | |
316 | //\r | |
317 | Status = InterpreterInstance->DestroyStructure (\r | |
318 | This,\r | |
319 | RestJSonHeader\r | |
320 | );\r | |
321 | break;\r | |
322 | } else {\r | |
323 | //\r | |
324 | // Check version.\r | |
325 | //\r | |
326 | if ((AsciiStrCmp (\r | |
327 | RestJSonHeader->JsonRsrcIdentifier.NameSpace.MajorVersion,\r | |
328 | ThisSupportedRsrcTypeId->NameSpace.MajorVersion) == 0) &&\r | |
329 | (AsciiStrCmp (\r | |
330 | RestJSonHeader->JsonRsrcIdentifier.NameSpace.MinorVersion,\r | |
331 | ThisSupportedRsrcTypeId->NameSpace.MinorVersion) == 0) &&\r | |
332 | (AsciiStrCmp (\r | |
333 | RestJSonHeader->JsonRsrcIdentifier.NameSpace.ErrataVersion,\r | |
334 | ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) == 0)) {\r | |
335 | Status = InterpreterInstance->DestroyStructure (\r | |
336 | This,\r | |
337 | RestJSonHeader\r | |
338 | );\r | |
339 | break;\r | |
340 | }\r | |
341 | }\r | |
342 | }\r | |
343 | ThisSupportedRsrcTypeId ++;\r | |
344 | }\r | |
345 | return Status;\r | |
346 | }\r | |
347 | \r | |
348 | /**\r | |
349 | This function translates the given JSON text to JSON C Structure.\r | |
350 | \r | |
351 | @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL instance.\r | |
352 | @param[in] RsrcTypeIdentifier Resource type identifier.\r | |
353 | @param[in] ResourceJsonText Given Restful resource.\r | |
354 | @param[out] JsonStructure Property interpreted from given ResourceRaw.\r | |
355 | \r | |
356 | @retval EFI_SUCCESS\r | |
357 | @retval Others.\r | |
358 | \r | |
359 | **/\r | |
360 | EFI_STATUS\r | |
361 | EFIAPI\r | |
362 | RestJsonStructureToStruct (\r | |
363 | IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,\r | |
364 | IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier OPTIONAL,\r | |
365 | IN CHAR8 *ResourceJsonText,\r | |
366 | OUT EFI_REST_JSON_STRUCTURE_HEADER **JsonStructure\r | |
367 | )\r | |
368 | {\r | |
369 | EFI_STATUS Status;\r | |
370 | REST_JSON_STRUCTURE_INSTANCE *Instance;\r | |
371 | \r | |
372 | if (This == NULL ||\r | |
373 | ResourceJsonText == NULL ||\r | |
374 | JsonStructure == NULL\r | |
375 | ) {\r | |
376 | return EFI_INVALID_PARAMETER;\r | |
377 | }\r | |
378 | \r | |
379 | if (IsListEmpty (&mRestJsonStructureList)) {\r | |
380 | return EFI_UNSUPPORTED;\r | |
381 | }\r | |
382 | Status = EFI_SUCCESS;\r | |
383 | Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);\r | |
384 | while (TRUE) {\r | |
385 | Status = InterpreterInstanceToStruct (\r | |
386 | This,\r | |
387 | Instance,\r | |
388 | RsrcTypeIdentifier,\r | |
389 | ResourceJsonText,\r | |
390 | JsonStructure\r | |
391 | );\r | |
392 | if (!EFI_ERROR (Status)) {\r | |
393 | break;\r | |
394 | }\r | |
395 | if (IsNodeAtEnd(&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {\r | |
396 | Status = EFI_UNSUPPORTED;\r | |
397 | break;\r | |
398 | }\r | |
399 | Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);\r | |
400 | };\r | |
401 | return Status;\r | |
402 | }\r | |
403 | \r | |
404 | /**\r | |
405 | This function destory REST property EFI structure which returned in\r | |
406 | JsonToStructure().\r | |
407 | \r | |
408 | @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL instance.\r | |
409 | @param[in] RestJSonHeader Property to destory.\r | |
410 | \r | |
411 | @retval EFI_SUCCESS\r | |
412 | @retval Others\r | |
413 | \r | |
414 | **/\r | |
415 | EFI_STATUS\r | |
416 | EFIAPI\r | |
417 | RestJsonStructureDestroyStruct (\r | |
418 | IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,\r | |
419 | IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader\r | |
420 | )\r | |
421 | {\r | |
422 | EFI_STATUS Status;\r | |
423 | REST_JSON_STRUCTURE_INSTANCE *Instance;\r | |
424 | \r | |
425 | if (This == NULL || RestJSonHeader == NULL) {\r | |
426 | return EFI_INVALID_PARAMETER;\r | |
427 | }\r | |
428 | \r | |
429 | if (IsListEmpty (&mRestJsonStructureList)) {\r | |
430 | return EFI_UNSUPPORTED;\r | |
431 | }\r | |
432 | Status = EFI_SUCCESS;\r | |
433 | Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);\r | |
434 | while (TRUE) {\r | |
435 | Status = InterpreterInstanceDestoryJsonStruct (\r | |
436 | This,\r | |
437 | Instance,\r | |
438 | RestJSonHeader\r | |
439 | );\r | |
440 | if (!EFI_ERROR (Status)) {\r | |
441 | break;\r | |
442 | }\r | |
443 | if (IsNodeAtEnd(&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {\r | |
444 | Status = EFI_UNSUPPORTED;\r | |
445 | break;\r | |
446 | }\r | |
447 | Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);\r | |
448 | };\r | |
449 | return Status;\r | |
450 | }\r | |
451 | \r | |
452 | /**\r | |
453 | This function translates the given JSON C Structure to JSON text.\r | |
454 | \r | |
455 | @param[in] This EFI_REST_JSON_STRUCTURE_PROTOCOL instance.\r | |
456 | @param[in] RestJSonHeader Given Restful resource.\r | |
457 | @param[out] ResourceRaw Resource in RESTfuls service oriented.\r | |
458 | \r | |
459 | @retval EFI_SUCCESS\r | |
460 | @retval Others Fail to remove the entry\r | |
461 | \r | |
462 | **/\r | |
463 | EFI_STATUS\r | |
464 | EFIAPI\r | |
465 | RestJsonStructureToJson (\r | |
466 | IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,\r | |
467 | IN EFI_REST_JSON_STRUCTURE_HEADER *RestJSonHeader,\r | |
468 | OUT CHAR8 **ResourceRaw\r | |
469 | )\r | |
470 | {\r | |
471 | EFI_STATUS Status;\r | |
472 | REST_JSON_STRUCTURE_INSTANCE *Instance;\r | |
473 | \r | |
474 | if (This == NULL || RestJSonHeader == NULL || ResourceRaw == NULL) {\r | |
475 | return EFI_INVALID_PARAMETER;\r | |
476 | }\r | |
477 | \r | |
478 | if (IsListEmpty (&mRestJsonStructureList)) {\r | |
479 | return EFI_UNSUPPORTED;\r | |
480 | }\r | |
481 | Status = EFI_SUCCESS;\r | |
482 | Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);\r | |
483 | while (TRUE) {\r | |
484 | Status = InterpreterEfiStructToInstance (\r | |
485 | This,\r | |
486 | Instance,\r | |
487 | RestJSonHeader,\r | |
488 | ResourceRaw\r | |
489 | );\r | |
490 | if (!EFI_ERROR (Status)) {\r | |
491 | break;\r | |
492 | }\r | |
493 | if (IsNodeAtEnd(&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {\r | |
494 | Status = EFI_UNSUPPORTED;\r | |
495 | break;\r | |
496 | }\r | |
497 | Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);\r | |
498 | };\r | |
499 | return Status;\r | |
500 | }\r | |
501 | \r | |
502 | EFI_REST_JSON_STRUCTURE_PROTOCOL mRestJsonStructureProtocol = {\r | |
503 | RestJsonStructureRegister,\r | |
504 | RestJsonStructureToStruct,\r | |
505 | RestJsonStructureToJson,\r | |
506 | RestJsonStructureDestroyStruct\r | |
507 | };\r | |
508 | \r | |
509 | /**\r | |
510 | This is the declaration of an EFI image entry point.\r | |
511 | \r | |
512 | @param ImageHandle The firmware allocated handle for the UEFI image.\r | |
513 | @param SystemTable A pointer to the EFI System Table.\r | |
514 | \r | |
515 | @retval EFI_SUCCESS The operation completed successfully.\r | |
516 | @retval Others An unexpected error occurred.\r | |
517 | **/\r | |
518 | EFI_STATUS\r | |
519 | EFIAPI\r | |
520 | RestJsonStructureEntryPoint (\r | |
521 | IN EFI_HANDLE ImageHandle,\r | |
522 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
523 | )\r | |
524 | {\r | |
525 | EFI_STATUS Status;\r | |
526 | \r | |
527 | InitializeListHead (&mRestJsonStructureList);\r | |
528 | //\r | |
529 | // Install the Restful Resource Interpreter Protocol.\r | |
530 | //\r | |
531 | mProtocolHandle = NULL;\r | |
532 | Status = gBS->InstallProtocolInterface (\r | |
533 | &mProtocolHandle,\r | |
534 | &gEfiRestJsonStructureProtocolGuid,\r | |
535 | EFI_NATIVE_INTERFACE,\r | |
536 | (VOID *)&mRestJsonStructureProtocol\r | |
537 | );\r | |
538 | return Status;\r | |
539 | }\r | |
540 | \r | |
541 | /**\r | |
542 | This is the unload handle for Redfish discover module.\r | |
543 | \r | |
544 | Disconnect the driver specified by ImageHandle from all the devices in the handle database.\r | |
545 | Uninstall all the protocols installed in the driver entry point.\r | |
546 | \r | |
547 | @param[in] ImageHandle The drivers' driver image.\r | |
548 | \r | |
549 | @retval EFI_SUCCESS The image is unloaded.\r | |
550 | @retval Others Failed to unload the image.\r | |
551 | \r | |
552 | **/\r | |
553 | EFI_STATUS\r | |
554 | EFIAPI\r | |
555 | RestJsonStructureUnload (\r | |
556 | IN EFI_HANDLE ImageHandle\r | |
557 | )\r | |
558 | {\r | |
559 | EFI_STATUS Status;\r | |
560 | REST_JSON_STRUCTURE_INSTANCE *Instance;\r | |
561 | REST_JSON_STRUCTURE_INSTANCE *NextInstance;\r | |
562 | \r | |
563 | Status = gBS->UninstallProtocolInterface (\r | |
564 | mProtocolHandle,\r | |
565 | &gEfiRestJsonStructureProtocolGuid,\r | |
566 | (VOID *)&mRestJsonStructureProtocol\r | |
567 | );\r | |
568 | \r | |
569 | if (IsListEmpty (&mRestJsonStructureList)) {\r | |
570 | return Status;\r | |
571 | }\r | |
572 | //\r | |
573 | // Free memory of REST_JSON_STRUCTURE_INSTANCE instance.\r | |
574 | //\r | |
575 | Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);\r | |
576 | do {\r | |
577 | NextInstance = NULL;\r | |
578 | if (!IsNodeAtEnd(&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {\r | |
579 | NextInstance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);\r | |
580 | }\r | |
581 | FreePool ((VOID *)Instance);\r | |
582 | Instance = NextInstance;\r | |
583 | } while (Instance != NULL);\r | |
584 | \r | |
585 | return Status;\r | |
586 | }\r |