VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c@ 106058

Last change on this file since 106058 was 105670, checked in by vboxsync, 8 months ago

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette