summaryrefslogtreecommitdiffstats
path: root/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c
blob: 404866fb31969c51b7431bcfc0dc11a3bade1cf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
/** @file

  The implementation of EFI REST Resource JSON to C structure convertor
  Protocol.

  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>

  SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <Uefi.h>
#include <Protocol/RestJsonStructure.h>
#include "RestJsonStructureInternal.h"

LIST_ENTRY  mRestJsonStructureList;
EFI_HANDLE  mProtocolHandle;

/**
  This function registers Restful resource interpreter for the
  specific schema.

  @param[in]    This                     This is the EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
  @param[in]    JsonStructureSupported   The type and version of REST JSON resource which this converter
                                         supports.
  @param[in]    ToStructure              The function to convert REST JSON resource to structure.
  @param[in]    ToJson                   The function to convert REST JSON structure to JSON in text format.
  @param[in]    DestroyStructure         Destroy REST JSON structure returned in ToStructure()  function.

  @retval EFI_SUCCESS             Register successfully.
  @retval Others                  Fail to register.

**/
EFI_STATUS
EFIAPI
RestJsonStructureRegister (
  IN EFI_REST_JSON_STRUCTURE_PROTOCOL           *This,
  IN EFI_REST_JSON_STRUCTURE_SUPPORTED          *JsonStructureSupported,
  IN EFI_REST_JSON_STRUCTURE_TO_STRUCTURE       ToStructure,
  IN EFI_REST_JSON_STRUCTURE_TO_JSON            ToJson,
  IN EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE  DestroyStructure
  )
{
  UINTN                                   NumberOfNS;
  UINTN                                   Index;
  LIST_ENTRY                              *ThisList;
  REST_JSON_STRUCTURE_INSTANCE            *Instance;
  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER  *CloneSupportedInterpId;
  EFI_REST_JSON_STRUCTURE_SUPPORTED       *ThisSupportedInterp;

  if ((This == NULL) ||
      (ToStructure == NULL) ||
      (ToJson == NULL) ||
      (DestroyStructure == NULL) ||
      (JsonStructureSupported == NULL)
      )
  {
    return EFI_INVALID_PARAMETER;
  }

  //
  // Check how many name space interpreter can interpret.
  //
  ThisList   = &JsonStructureSupported->NextSupportedRsrcInterp;
  NumberOfNS = 1;
  while (TRUE) {
    if (ThisList->ForwardLink == &JsonStructureSupported->NextSupportedRsrcInterp) {
      break;
    } else {
      ThisList = ThisList->ForwardLink;
      NumberOfNS++;
    }
  }

  Instance =
    (REST_JSON_STRUCTURE_INSTANCE *)AllocateZeroPool (sizeof (REST_JSON_STRUCTURE_INSTANCE) + NumberOfNS * sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER));
  if (Instance == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  InitializeListHead (&Instance->NextRestJsonStructureInstance);
  Instance->NumberOfNameSpaceToConvert = NumberOfNS;
  Instance->SupportedRsrcIndentifier   = (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *)((REST_JSON_STRUCTURE_INSTANCE *)Instance + 1);
  //
  // Copy supported resource identifer interpreter.
  //
  CloneSupportedInterpId = Instance->SupportedRsrcIndentifier;
  ThisSupportedInterp    = JsonStructureSupported;
  for (Index = 0; Index < NumberOfNS; Index++) {
    CopyMem ((VOID *)CloneSupportedInterpId, (VOID *)&ThisSupportedInterp->RestResourceInterp, sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER));
    ThisSupportedInterp = (EFI_REST_JSON_STRUCTURE_SUPPORTED *)ThisSupportedInterp->NextSupportedRsrcInterp.ForwardLink;
    CloneSupportedInterpId++;
  }

  Instance->JsonToStructure  = ToStructure;
  Instance->StructureToJson  = ToJson;
  Instance->DestroyStructure = DestroyStructure;
  InsertTailList (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
  return EFI_SUCCESS;
}

/**
  This function check if this interpreter instance support the given namesapce.

  @param[in]    This                EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
  @param[in]    InterpreterInstance REST_JSON_STRUCTURE_INSTANCE
  @param[in]    RsrcTypeIdentifier  Resource type identifier.
  @param[in]    ResourceRaw         Given Restful resource.
  @param[out]   RestJSonHeader      Property interpreted from given ResourceRaw.

  @retval EFI_SUCCESS
  @retval Others.

**/
EFI_STATUS
InterpreterInstanceToStruct (
  IN EFI_REST_JSON_STRUCTURE_PROTOCOL        *This,
  IN REST_JSON_STRUCTURE_INSTANCE            *InterpreterInstance,
  IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER  *RsrcTypeIdentifier OPTIONAL,
  IN CHAR8                                   *ResourceRaw,
  OUT EFI_REST_JSON_STRUCTURE_HEADER         **RestJSonHeader
  )
{
  UINTN                                   Index;
  EFI_STATUS                              Status;
  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER  *ThisSupportedRsrcTypeId;

  if ((This == NULL) ||
      (InterpreterInstance == NULL) ||
      (ResourceRaw == NULL) ||
      (RestJSonHeader == NULL)
      )
  {
    return EFI_INVALID_PARAMETER;
  }

  Status = EFI_UNSUPPORTED;
  if (RsrcTypeIdentifier == NULL) {
    //
    // No resource type identifier, send to intepreter anyway.
    // Interpreter may recognize this resource.
    //
    Status = InterpreterInstance->JsonToStructure (
                                    This,
                                    NULL,
                                    ResourceRaw,
                                    RestJSonHeader
                                    );
  } else {
    //
    // Check if the namesapce and version is supported by this interpreter.
    //
    ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;
    for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index++) {
      if (AsciiStrCmp (
            RsrcTypeIdentifier->NameSpace.ResourceTypeName,
            ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName
            ) == 0)
      {
        if ((RsrcTypeIdentifier->NameSpace.MajorVersion == NULL) &&
            (RsrcTypeIdentifier->NameSpace.MinorVersion == NULL) &&
            (RsrcTypeIdentifier->NameSpace.ErrataVersion == NULL)
            )
        {
          //
          // Don't check version of this resource type identifier.
          //
          Status = InterpreterInstance->JsonToStructure (
                                          This,
                                          RsrcTypeIdentifier,
                                          ResourceRaw,
                                          RestJSonHeader
                                          );
          break;
        } else {
          //
          // Check version.
          //
          if ((AsciiStrCmp (
                 RsrcTypeIdentifier->NameSpace.MajorVersion,
                 ThisSupportedRsrcTypeId->NameSpace.MajorVersion
                 ) == 0) &&
              (AsciiStrCmp (
                 RsrcTypeIdentifier->NameSpace.MinorVersion,
                 ThisSupportedRsrcTypeId->NameSpace.MinorVersion
                 ) == 0) &&
              (AsciiStrCmp (
                 RsrcTypeIdentifier->NameSpace.ErrataVersion,
                 ThisSupportedRsrcTypeId->NameSpace.ErrataVersion
                 ) == 0))
          {
            Status = InterpreterInstance->JsonToStructure (
                                            This,
                                            RsrcTypeIdentifier,
                                            ResourceRaw,
                                            RestJSonHeader
                                            );
            break;
          }
        }
      }

      ThisSupportedRsrcTypeId++;
    }
  }

  return Status;
}

/**
  This function converts JSON C structure to JSON property.

  @param[in]    This                 EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
  @param[in]    InterpreterInstance  REST_JSON_STRUCTURE_INSTANCE
  @param[in]    RestJSonHeader       Resource type identifier.
  @param[out]   ResourceRaw          Output in JSON text format.

  @retval EFI_SUCCESS
  @retval Others.

**/
EFI_STATUS
InterpreterEfiStructToInstance (
  IN EFI_REST_JSON_STRUCTURE_PROTOCOL  *This,
  IN REST_JSON_STRUCTURE_INSTANCE      *InterpreterInstance,
  IN EFI_REST_JSON_STRUCTURE_HEADER    *RestJSonHeader,
  OUT CHAR8                            **ResourceRaw
  )
{
  UINTN                                   Index;
  EFI_STATUS                              Status;
  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER  *ThisSupportedRsrcTypeId;
  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER  *RsrcTypeIdentifier;

  if ((This == NULL) ||
      (InterpreterInstance == NULL) ||
      (RestJSonHeader == NULL) ||
      (ResourceRaw == NULL)
      )
  {
    return EFI_INVALID_PARAMETER;
  }

  RsrcTypeIdentifier = &RestJSonHeader->JsonRsrcIdentifier;
  if ((RsrcTypeIdentifier == NULL) ||
      (RsrcTypeIdentifier->NameSpace.ResourceTypeName == NULL) ||
      (RsrcTypeIdentifier->NameSpace.MajorVersion == NULL) ||
      (RsrcTypeIdentifier->NameSpace.MinorVersion == NULL) ||
      (RsrcTypeIdentifier->NameSpace.ErrataVersion == NULL)
      )
  {
    return EFI_INVALID_PARAMETER;
  }

  //
  // Check if the namesapce and version is supported by this interpreter.
  //
  Status                  = EFI_UNSUPPORTED;
  ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;
  for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index++) {
    if (AsciiStrCmp (
          RsrcTypeIdentifier->NameSpace.ResourceTypeName,
          ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName
          ) == 0)
    {
      //
      // Check version.
      //
      if ((AsciiStrCmp (
             RsrcTypeIdentifier->NameSpace.MajorVersion,
             ThisSupportedRsrcTypeId->NameSpace.MajorVersion
             ) == 0) &&
          (AsciiStrCmp (
             RsrcTypeIdentifier->NameSpace.MinorVersion,
             ThisSupportedRsrcTypeId->NameSpace.MinorVersion
             ) == 0) &&
          (AsciiStrCmp (
             RsrcTypeIdentifier->NameSpace.ErrataVersion,
             ThisSupportedRsrcTypeId->NameSpace.ErrataVersion
             ) == 0))
      {
        Status = InterpreterInstance->StructureToJson (
                                        This,
                                        RestJSonHeader,
                                        ResourceRaw
                                        );
        break;
      }
    }

    ThisSupportedRsrcTypeId++;
  }

  return Status;
}

/**
  This function destory REST property structure.

  @param[in]    This                 EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
  @param[in]    InterpreterInstance  REST_JSON_STRUCTURE_INSTANCE
  @param[in]    RestJSonHeader       Property interpreted from given ResourceRaw.

  @retval EFI_SUCCESS
  @retval Others.

**/
EFI_STATUS
InterpreterInstanceDestoryJsonStruct (
  IN EFI_REST_JSON_STRUCTURE_PROTOCOL  *This,
  IN REST_JSON_STRUCTURE_INSTANCE      *InterpreterInstance,
  IN EFI_REST_JSON_STRUCTURE_HEADER    *RestJSonHeader
  )
{
  UINTN                                   Index;
  EFI_STATUS                              Status;
  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER  *ThisSupportedRsrcTypeId;

  if ((This == NULL) ||
      (InterpreterInstance == NULL) ||
      (RestJSonHeader == NULL)
      )
  {
    return EFI_INVALID_PARAMETER;
  }

  Status = EFI_UNSUPPORTED;
  //
  // Check if the namesapce and version is supported by this interpreter.
  //
  ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;
  for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index++) {
    if (AsciiStrCmp (
          RestJSonHeader->JsonRsrcIdentifier.NameSpace.ResourceTypeName,
          ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName
          ) == 0)
    {
      if ((RestJSonHeader->JsonRsrcIdentifier.NameSpace.MajorVersion == NULL) &&
          (RestJSonHeader->JsonRsrcIdentifier.NameSpace.MinorVersion == NULL) &&
          (RestJSonHeader->JsonRsrcIdentifier.NameSpace.ErrataVersion == NULL)
          )
      {
        //
        // Don't check version of this resource type identifier.
        //
        Status = InterpreterInstance->DestroyStructure (
                                        This,
                                        RestJSonHeader
                                        );
        break;
      } else {
        //
        // Check version.
        //
        if ((AsciiStrCmp (
               RestJSonHeader->JsonRsrcIdentifier.NameSpace.MajorVersion,
               ThisSupportedRsrcTypeId->NameSpace.MajorVersion
               ) == 0) &&
            (AsciiStrCmp (
               RestJSonHeader->JsonRsrcIdentifier.NameSpace.MinorVersion,
               ThisSupportedRsrcTypeId->NameSpace.MinorVersion
               ) == 0) &&
            (AsciiStrCmp (
               RestJSonHeader->JsonRsrcIdentifier.NameSpace.ErrataVersion,
               ThisSupportedRsrcTypeId->NameSpace.ErrataVersion
               ) == 0))
        {
          Status = InterpreterInstance->DestroyStructure (
                                          This,
                                          RestJSonHeader
                                          );
          break;
        }
      }
    }

    ThisSupportedRsrcTypeId++;
  }

  return Status;
}

/**
  This function translates the given JSON text to JSON C Structure.

  @param[in]    This                EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
  @param[in]    RsrcTypeIdentifier  Resource type identifier.
  @param[in]    ResourceJsonText    Given Restful resource.
  @param[out]   JsonStructure       Property interpreted from given ResourceRaw.

  @retval EFI_SUCCESS
  @retval Others.

**/
EFI_STATUS
EFIAPI
RestJsonStructureToStruct (
  IN EFI_REST_JSON_STRUCTURE_PROTOCOL        *This,
  IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER  *RsrcTypeIdentifier OPTIONAL,
  IN CHAR8                                   *ResourceJsonText,
  OUT EFI_REST_JSON_STRUCTURE_HEADER         **JsonStructure
  )
{
  EFI_STATUS                    Status;
  REST_JSON_STRUCTURE_INSTANCE  *Instance;

  if ((This == NULL) ||
      (ResourceJsonText == NULL) ||
      (JsonStructure == NULL)
      )
  {
    return EFI_INVALID_PARAMETER;
  }

  if (IsListEmpty (&mRestJsonStructureList)) {
    return EFI_UNSUPPORTED;
  }

  Status   = EFI_SUCCESS;
  Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
  while (TRUE) {
    Status = InterpreterInstanceToStruct (
               This,
               Instance,
               RsrcTypeIdentifier,
               ResourceJsonText,
               JsonStructure
               );
    if (!EFI_ERROR (Status)) {
      break;
    }

    if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
      Status = EFI_UNSUPPORTED;
      break;
    }

    Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
  }

  return Status;
}

/**
  This function destory REST property EFI structure which returned in
  JsonToStructure().

  @param[in]    This            EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
  @param[in]    RestJSonHeader  Property to destory.

  @retval EFI_SUCCESS
  @retval Others

**/
EFI_STATUS
EFIAPI
RestJsonStructureDestroyStruct (
  IN EFI_REST_JSON_STRUCTURE_PROTOCOL  *This,
  IN EFI_REST_JSON_STRUCTURE_HEADER    *RestJSonHeader
  )
{
  EFI_STATUS                    Status;
  REST_JSON_STRUCTURE_INSTANCE  *Instance;

  if ((This == NULL) || (RestJSonHeader == NULL)) {
    return EFI_INVALID_PARAMETER;
  }

  if (IsListEmpty (&mRestJsonStructureList)) {
    return EFI_UNSUPPORTED;
  }

  Status   = EFI_SUCCESS;
  Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
  while (TRUE) {
    Status = InterpreterInstanceDestoryJsonStruct (
               This,
               Instance,
               RestJSonHeader
               );
    if (!EFI_ERROR (Status)) {
      break;
    }

    if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
      Status = EFI_UNSUPPORTED;
      break;
    }

    Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
  }

  return Status;
}

/**
  This function translates the given JSON C Structure to JSON text.

  @param[in]    This            EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
  @param[in]    RestJSonHeader  Given Restful resource.
  @param[out]   ResourceRaw     Resource in RESTfuls service oriented.

  @retval EFI_SUCCESS
  @retval Others             Fail to remove the entry

**/
EFI_STATUS
EFIAPI
RestJsonStructureToJson (
  IN EFI_REST_JSON_STRUCTURE_PROTOCOL  *This,
  IN EFI_REST_JSON_STRUCTURE_HEADER    *RestJSonHeader,
  OUT CHAR8                            **ResourceRaw
  )
{
  EFI_STATUS                    Status;
  REST_JSON_STRUCTURE_INSTANCE  *Instance;

  if ((This == NULL) || (RestJSonHeader == NULL) || (ResourceRaw == NULL)) {
    return EFI_INVALID_PARAMETER;
  }

  if (IsListEmpty (&mRestJsonStructureList)) {
    return EFI_UNSUPPORTED;
  }

  Status   = EFI_SUCCESS;
  Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
  while (TRUE) {
    Status = InterpreterEfiStructToInstance (
               This,
               Instance,
               RestJSonHeader,
               ResourceRaw
               );
    if (!EFI_ERROR (Status)) {
      break;
    }

    if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
      Status = EFI_UNSUPPORTED;
      break;
    }

    Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
  }

  return Status;
}

EFI_REST_JSON_STRUCTURE_PROTOCOL  mRestJsonStructureProtocol = {
  RestJsonStructureRegister,
  RestJsonStructureToStruct,
  RestJsonStructureToJson,
  RestJsonStructureDestroyStruct
};

/**
  This is the declaration of an EFI image entry point.

  @param  ImageHandle           The firmware allocated handle for the UEFI image.
  @param  SystemTable           A pointer to the EFI System Table.

  @retval EFI_SUCCESS           The operation completed successfully.
  @retval Others                An unexpected error occurred.
**/
EFI_STATUS
EFIAPI
RestJsonStructureEntryPoint (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS  Status;

  InitializeListHead (&mRestJsonStructureList);
  //
  // Install the Restful Resource Interpreter Protocol.
  //
  mProtocolHandle = NULL;
  Status          = gBS->InstallProtocolInterface (
                           &mProtocolHandle,
                           &gEfiRestJsonStructureProtocolGuid,
                           EFI_NATIVE_INTERFACE,
                           (VOID *)&mRestJsonStructureProtocol
                           );
  return Status;
}

/**
  This is the unload handle for Redfish discover module.

  Disconnect the driver specified by ImageHandle from all the devices in the handle database.
  Uninstall all the protocols installed in the driver entry point.

  @param[in] ImageHandle           The drivers' driver image.

  @retval    EFI_SUCCESS           The image is unloaded.
  @retval    Others                Failed to unload the image.

**/
EFI_STATUS
EFIAPI
RestJsonStructureUnload (
  IN EFI_HANDLE  ImageHandle
  )
{
  EFI_STATUS                    Status;
  REST_JSON_STRUCTURE_INSTANCE  *Instance;
  REST_JSON_STRUCTURE_INSTANCE  *NextInstance;

  Status = gBS->UninstallProtocolInterface (
                  mProtocolHandle,
                  &gEfiRestJsonStructureProtocolGuid,
                  (VOID *)&mRestJsonStructureProtocol
                  );

  if (IsListEmpty (&mRestJsonStructureList)) {
    return Status;
  }

  //
  // Free memory of REST_JSON_STRUCTURE_INSTANCE instance.
  //
  Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
  do {
    NextInstance = NULL;
    if (!IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
      NextInstance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
    }

    FreePool ((VOID *)Instance);
    Instance = NextInstance;
  } while (Instance != NULL);

  return Status;
}