TianoCore EDK2 master
Loading...
Searching...
No Matches
RedfishLib.c
Go to the documentation of this file.
1
13#include "RedfishMisc.h"
14
28REDFISH_SERVICE
29EFIAPI
31 IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo
32 )
33{
34 REDFISH_SERVICE RedfishService;
36 CHAR8 *UserId;
37 CHAR8 *Password;
38 EFI_STATUS Status;
39
40 RedfishService = NULL;
41 UserId = NULL;
42 Password = NULL;
43
44 //
45 // Check Input Parameters.
46 //
47 if (RedfishConfigServiceInfo == NULL) {
48 return NULL;
49 }
50
51 //
52 // Get Authentication Configuration.
53 //
54 Status = RedfishGetAuthInfo (&AuthMethod, &UserId, &Password);
55 if (EFI_ERROR (Status)) {
56 goto ON_EXIT;
57 }
58
59 //
60 // Create a redfish service node based on Redfish network host interface.
61 //
62 RedfishService = RedfishCreateLibredfishService (
63 RedfishConfigServiceInfo,
64 AuthMethod,
65 UserId,
66 Password
67 );
68
69ON_EXIT:
70 if (UserId != NULL) {
71 FreePool (UserId);
72 }
73
74 if (Password != NULL) {
75 FreePool (Password);
76 }
77
78 return RedfishService;
79}
80
87VOID
88EFIAPI
90 IN REDFISH_SERVICE RedfishService
91 )
92{
93 if (RedfishService == NULL) {
94 return;
95 }
96
97 cleanupServiceEnumerator (RedfishService);
98}
99
115REDFISH_PAYLOAD
116EFIAPI
118 IN EDKII_JSON_VALUE Value,
119 IN REDFISH_SERVICE RedfishService
120 )
121{
122 EDKII_JSON_VALUE CopyValue;
123
124 CopyValue = JsonValueClone (Value);
125 return createRedfishPayload (CopyValue, RedfishService);
126}
127
134VOID
135EFIAPI
137 IN REDFISH_PAYLOAD Payload
138 )
139{
140 if (Payload == NULL) {
141 return;
142 }
143
144 cleanupPayload ((redfishPayload *)Payload);
145}
146
158EDKII_JSON_VALUE
159EFIAPI
161 IN REDFISH_PAYLOAD Payload
162 )
163{
164 if (Payload == NULL) {
165 return NULL;
166 }
167
168 return ((redfishPayload *)Payload)->json;
169}
170
182REDFISH_SERVICE
183EFIAPI
185 IN REDFISH_PAYLOAD Payload
186 )
187{
188 if (Payload == NULL) {
189 return NULL;
190 }
191
192 return ((redfishPayload *)Payload)->service;
193}
194
214CHAR8 *
215EFIAPI
217 IN CONST CHAR8 *RedPath,
218 IN BOOLEAN FromSmbios,
219 IN CHAR8 *IdString OPTIONAL
220 )
221{
222 UINTN BufSize;
223 CHAR8 *RetRedPath;
224 EFI_GUID SystemUuid;
225 EFI_STATUS Status;
226
227 if (RedPath == NULL) {
228 return NULL;
229 }
230
231 //
232 // Find system UUID from SMBIOS table.
233 //
234 if (FromSmbios) {
235 Status = NetLibGetSystemGuid (&SystemUuid);
236 if (EFI_ERROR (Status)) {
237 return NULL;
238 }
239
240 // AsciiStrLen ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") = 36
241 BufSize = AsciiStrSize (RedPath) + AsciiStrLen ("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
242 } else {
243 BufSize = AsciiStrSize (RedPath) + AsciiStrLen (IdString);
244 }
245
246 RetRedPath = AllocateZeroPool (BufSize);
247 if (RetRedPath == NULL) {
248 return NULL;
249 }
250
251 if (FromSmbios) {
252 AsciiSPrint (RetRedPath, BufSize, RedPath, &SystemUuid);
253 } else {
254 AsciiSPrint (RetRedPath, BufSize, RedPath, IdString);
255 }
256
257 return RetRedPath;
258}
259
284EFIAPI
286 IN REDFISH_SERVICE RedfishService,
287 IN CONST CHAR8 *RedPath,
288 OUT REDFISH_RESPONSE *RedResponse
289 )
290{
291 if ((RedfishService == NULL) || (RedPath == NULL) || (RedResponse == NULL)) {
292 return EFI_INVALID_PARAMETER;
293 }
294
295 ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
296
297 RedResponse->Payload = (REDFISH_PAYLOAD)getPayloadByPath (RedfishService, RedPath, &(RedResponse->StatusCode));
298
299 //
300 // 1. If the returned Payload is NULL, indicates any error happen.
301 // 2. If the returned StatusCode is NULL, indicates any error happen.
302 //
303 if ((RedResponse->Payload == NULL) || (RedResponse->StatusCode == NULL)) {
304 return EFI_DEVICE_ERROR;
305 }
306
307 //
308 // 3. If the returned StatusCode is not 2XX, indicates any error happen.
309 // NOTE: If there is any error message returned from server, it will be returned in
310 // Payload within RedResponse.
311 //
312 if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
313 (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
314 {
315 return EFI_DEVICE_ERROR;
316 }
317
318 return EFI_SUCCESS;
319}
320
344EFIAPI
346 IN REDFISH_SERVICE RedfishService,
347 IN CONST CHAR8 *Uri,
348 OUT REDFISH_RESPONSE *RedResponse
349 )
350{
351 EDKII_JSON_VALUE JsonValue;
352
353 if ((RedfishService == NULL) || (Uri == NULL) || (RedResponse == NULL)) {
354 return EFI_INVALID_PARAMETER;
355 }
356
357 ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
358
359 JsonValue = getUriFromServiceEx (RedfishService, Uri, &RedResponse->Headers, &RedResponse->HeaderCount, &RedResponse->StatusCode);
360 RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);
361
362 //
363 // 1. If the returned Payload is NULL, indicates any error happen.
364 // 2. If the returned StatusCode is NULL, indicates any error happen.
365 //
366 if ((RedResponse->Payload == NULL) || (RedResponse->StatusCode == NULL)) {
367 return EFI_DEVICE_ERROR;
368 }
369
370 //
371 // 3. If the returned StatusCode is not 2XX, indicates any error happen.
372 // NOTE: If there is any error message returned from server, it will be returned in
373 // Payload within RedResponse.
374 //
375 if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
376 (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
377 {
378 return EFI_DEVICE_ERROR;
379 }
380
381 return EFI_SUCCESS;
382}
383
411EFIAPI
413 IN REDFISH_PAYLOAD Payload,
414 IN CONST CHAR8 *RedPath,
415 OUT REDFISH_RESPONSE *RedResponse
416 )
417{
418 if ((Payload == NULL) || (RedPath == NULL) || (RedResponse == NULL)) {
419 return EFI_INVALID_PARAMETER;
420 }
421
422 ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
423
424 RedResponse->Payload = (REDFISH_PAYLOAD)getPayloadForPathString (Payload, RedPath, &(RedResponse->StatusCode));
425
426 //
427 // 1. If the returned Payload is NULL, indicates any error happen.
428 //
429 if (RedResponse->Payload == NULL) {
430 return EFI_DEVICE_ERROR;
431 }
432
433 //
434 // 2. If StatusCode is not NULL and the returned value of StatusCode is not 2XX, indicates any
435 // error happen.
436 // NOTE: If there is any error message returned from server, it will be returned in
437 // Payload within RedResponse.
438 //
439 if ((RedResponse->StatusCode != NULL) && \
440 ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
441 (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT)
442 ))
443 {
444 return EFI_DEVICE_ERROR;
445 }
446
447 return EFI_SUCCESS;
448}
449
481EFIAPI
483 IN REDFISH_SERVICE RedfishService,
484 IN CONST CHAR8 *Uri,
485 IN CONST CHAR8 *Content,
486 OUT REDFISH_RESPONSE *RedResponse
487 )
488{
489 EFI_STATUS Status;
490 EDKII_JSON_VALUE JsonValue;
491
492 Status = EFI_SUCCESS;
493 JsonValue = NULL;
494
495 if ((RedfishService == NULL) || (Uri == NULL) || (Content == NULL) || (RedResponse == NULL)) {
496 return EFI_INVALID_PARAMETER;
497 }
498
499 ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
500
501 JsonValue = (EDKII_JSON_VALUE)patchUriFromServiceEx (
502 RedfishService,
503 Uri,
504 Content,
505 &(RedResponse->Headers),
506 &(RedResponse->HeaderCount),
507 &(RedResponse->StatusCode)
508 );
509
510 //
511 // 1. If the returned StatusCode is NULL, indicates any error happen.
512 //
513 if (RedResponse->StatusCode == NULL) {
514 Status = EFI_DEVICE_ERROR;
515 goto ON_EXIT;
516 }
517
518 //
519 // 2. If the returned StatusCode is not NULL and the value is not 2XX, indicates any error happen.
520 // NOTE: If there is any error message returned from server, it will be returned in
521 // Payload within RedResponse.
522 //
523 if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
524 (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
525 {
526 Status = EFI_DEVICE_ERROR;
527 }
528
529ON_EXIT:
530 if (JsonValue != NULL) {
531 RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);
532 if (RedResponse->Payload == NULL) {
533 //
534 // Ignore the error when create RedfishPayload, just free the JsonValue since it's not what
535 // we care about if the returned StatusCode is 2XX.
536 //
537 JsonValueFree (JsonValue);
538 }
539 }
540
541 return Status;
542}
543
573EFIAPI
575 IN REDFISH_PAYLOAD Target,
576 IN REDFISH_PAYLOAD Payload,
577 OUT REDFISH_RESPONSE *RedResponse
578 )
579{
580 if ((Target == NULL) || (Payload == NULL) || (RedResponse == NULL)) {
581 return EFI_INVALID_PARAMETER;
582 }
583
584 ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
585
586 RedResponse->Payload = (REDFISH_PAYLOAD)patchPayload (
587 Target,
588 Payload,
589 &(RedResponse->StatusCode)
590 );
591
592 //
593 // 1. If the returned StatusCode is NULL, indicates any error happen.
594 //
595 if (RedResponse->StatusCode == NULL) {
596 return EFI_DEVICE_ERROR;
597 }
598
599 //
600 // 2. If the returned StatusCode is not NULL and the value is not 2XX, indicates any error happen.
601 // NOTE: If there is any error message returned from server, it will be returned in
602 // Payload within RedResponse.
603 //
604 if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
605 (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
606 {
607 return EFI_DEVICE_ERROR;
608 }
609
610 return EFI_SUCCESS;
611}
612
644EFIAPI
646 IN REDFISH_SERVICE RedfishService,
647 IN CONST CHAR8 *Uri,
648 IN CONST CHAR8 *Content,
649 IN UINTN ContentSize OPTIONAL,
650 IN CONST CHAR8 *ContentType OPTIONAL,
651 OUT REDFISH_RESPONSE *RedResponse
652 )
653{
654 EFI_STATUS Status;
655 EDKII_JSON_VALUE JsonValue;
656
657 Status = EFI_SUCCESS;
658 JsonValue = NULL;
659
660 if ((RedfishService == NULL) || (Uri == NULL) || (Content == NULL) || (RedResponse == NULL)) {
661 return EFI_INVALID_PARAMETER;
662 }
663
664 ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
665
666 JsonValue = (EDKII_JSON_VALUE)postUriFromServiceEx (
667 RedfishService,
668 Uri,
669 Content,
670 ContentSize,
671 ContentType,
672 &(RedResponse->Headers),
673 &(RedResponse->HeaderCount),
674 &(RedResponse->StatusCode)
675 );
676
677 //
678 // 1. If the returned StatusCode is NULL, indicates any error happen.
679 //
680 if (RedResponse->StatusCode == NULL) {
681 Status = EFI_DEVICE_ERROR;
682 goto ON_EXIT;
683 }
684
685 //
686 // 2. If the returned StatusCode is not NULL and the value is not 2XX, indicates any error happen.
687 // NOTE: If there is any error message returned from server, it will be returned in
688 // Payload within RedResponse.
689 //
690 if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
691 (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
692 {
693 Status = EFI_DEVICE_ERROR;
694 }
695
696ON_EXIT:
697 if (JsonValue != NULL) {
698 RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);
699 if (RedResponse->Payload == NULL) {
700 //
701 // Ignore the error when create RedfishPayload, just free the JsonValue since it's not what
702 // we care about if the returned StatusCode is 2XX.
703 //
704 JsonValueFree (JsonValue);
705 }
706 }
707
708 return Status;
709}
710
739EFIAPI
741 IN REDFISH_PAYLOAD Target,
742 IN REDFISH_PAYLOAD Payload,
743 OUT REDFISH_RESPONSE *RedResponse
744 )
745{
746 if ((Target == NULL) || (Payload == NULL) || (RedResponse == NULL)) {
747 return EFI_INVALID_PARAMETER;
748 }
749
750 ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
751
752 RedResponse->Payload = (REDFISH_PAYLOAD)postPayload (
753 Target,
754 Payload,
755 &(RedResponse->StatusCode)
756 );
757
758 //
759 // 1. If the returned StatusCode is NULL, indicates any error happen.
760 //
761 if (RedResponse->StatusCode == NULL) {
762 return EFI_DEVICE_ERROR;
763 }
764
765 //
766 // 2. If the returned StatusCode is not NULL and the value is not 2XX, indicates any error happen.
767 // NOTE: If there is any error message returned from server, it will be returned in
768 // Payload within RedResponse.
769 //
770 if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
771 (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
772 {
773 return EFI_DEVICE_ERROR;
774 }
775
776 return EFI_SUCCESS;
777}
778
807EFIAPI
809 IN REDFISH_SERVICE RedfishService,
810 IN CONST CHAR8 *Uri,
811 OUT REDFISH_RESPONSE *RedResponse
812 )
813{
814 EFI_STATUS Status;
815 EDKII_JSON_VALUE JsonValue;
816
817 Status = EFI_SUCCESS;
818 JsonValue = NULL;
819
820 if ((RedfishService == NULL) || (Uri == NULL) || (RedResponse == NULL)) {
821 return EFI_INVALID_PARAMETER;
822 }
823
824 ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
825
826 JsonValue = (EDKII_JSON_VALUE)deleteUriFromService (
827 RedfishService,
828 Uri,
829 &(RedResponse->StatusCode)
830 );
831
832 //
833 // 1. If the returned StatusCode is NULL, indicates any error happen.
834 //
835 if (RedResponse->StatusCode == NULL) {
836 Status = EFI_DEVICE_ERROR;
837 goto ON_EXIT;
838 }
839
840 //
841 // 2. If the returned StatusCode is not NULL and the value is not 2XX, indicates any error happen.
842 // NOTE: If there is any error message returned from server, it will be returned in
843 // Payload within RedResponse.
844 //
845 if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
846 (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
847 {
848 Status = EFI_DEVICE_ERROR;
849 }
850
851ON_EXIT:
852 if (JsonValue != NULL) {
853 RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);
854 if (RedResponse->Payload == NULL) {
855 //
856 // Ignore the error when create RedfishPayload, just free the JsonValue since it's not what
857 // we care about if the returned StatusCode is 2XX.
858 //
859 JsonValueFree (JsonValue);
860 }
861 }
862
863 return Status;
864}
865
895EFIAPI
897 IN REDFISH_SERVICE RedfishService,
898 IN CONST CHAR8 *Uri,
899 IN CONST CHAR8 *Content,
900 OUT REDFISH_RESPONSE *RedResponse
901 )
902{
903 EFI_STATUS Status;
904 EDKII_JSON_VALUE JsonValue;
905
906 Status = EFI_SUCCESS;
907 JsonValue = NULL;
908
909 if ((RedfishService == NULL) || (Content == NULL) || (Uri == NULL) || (RedResponse == NULL)) {
910 return EFI_INVALID_PARAMETER;
911 }
912
913 ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
914
915 JsonValue = (EDKII_JSON_VALUE)deleteUriFromServiceEx (
916 RedfishService,
917 Uri,
918 Content,
919 &(RedResponse->StatusCode)
920 );
921
922 //
923 // 1. If the returned StatusCode is NULL, indicates any error happen.
924 //
925 if (RedResponse->StatusCode == NULL) {
926 Status = EFI_DEVICE_ERROR;
927 goto ON_EXIT;
928 }
929
930 //
931 // 2. If the returned StatusCode is not NULL and the value is not 2XX, indicates any error happen.
932 // NOTE: If there is any error message returned from server, it will be returned in
933 // Payload within RedResponse.
934 //
935 if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
936 (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
937 {
938 Status = EFI_DEVICE_ERROR;
939 }
940
941ON_EXIT:
942 if (JsonValue != NULL) {
943 RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);
944 if (RedResponse->Payload == NULL) {
945 //
946 // Ignore the error when create RedfishPayload, just free the JsonValue since it's not what
947 // we care about if the returned StatusCode is 2XX.
948 //
949 JsonValueFree (JsonValue);
950 }
951 }
952
953 return Status;
954}
955
962VOID
964 IN CHAR8 *String
965 )
966{
967 CHAR8 *NextFraction;
968 UINTN StringFractionSize;
970 UINTN Count;
971 CHAR8 BackupChar;
972
973 StringFractionSize = 200;
974 if (String == NULL) {
975 return;
976 }
977
978 DEBUG ((DEBUG_MANAGEABILITY, "JSON text:\n"));
979 NextFraction = String;
980 StrLen = AsciiStrLen (String);
981 if (StrLen == 0) {
982 return;
983 }
984
985 for (Count = 0; Count < (StrLen / StringFractionSize); Count++) {
986 BackupChar = *(NextFraction + StringFractionSize);
987 *(NextFraction + StringFractionSize) = 0;
988 DEBUG ((DEBUG_MANAGEABILITY, "%a", NextFraction));
989 *(NextFraction + StringFractionSize) = BackupChar;
990 NextFraction += StringFractionSize;
991 }
992
993 if ((StrLen % StringFractionSize) != 0) {
994 DEBUG ((DEBUG_MANAGEABILITY, "%a\n\n", NextFraction));
995 }
996}
997
1004VOID
1006 IN EDKII_JSON_VALUE JsonValue
1007 )
1008{
1009 CHAR8 *String;
1010
1011 String = JsonDumpString (JsonValue, 0);
1012 if (String == NULL) {
1013 return;
1014 }
1015
1017 FreePool (String);
1018}
1019
1026VOID
1028 IN REDFISH_PAYLOAD Payload
1029 )
1030{
1031 EDKII_JSON_VALUE JsonValue;
1032 CHAR8 *String;
1033
1034 JsonValue = NULL;
1035 String = NULL;
1036
1037 if (Payload == NULL) {
1038 return;
1039 }
1040
1041 JsonValue = RedfishJsonInPayload (Payload);
1042 if (JsonValue == NULL) {
1043 return;
1044 }
1045
1046 String = JsonDumpString (JsonValue, 0);
1047 if (String == NULL) {
1048 return;
1049 }
1050
1052 FreePool (String);
1053}
1054
1064VOID
1066 IN EFI_HTTP_STATUS_CODE *StatusCode,
1067 IN UINTN HeaderCount,
1068 IN EFI_HTTP_HEADER *Headers,
1069 IN REDFISH_PAYLOAD Payload
1070 )
1071{
1072 if (StatusCode != NULL) {
1073 FreePool (StatusCode);
1074 StatusCode = NULL;
1075 }
1076
1077 if ((HeaderCount != 0) && (Headers != NULL)) {
1078 HttpFreeHeaderFields (Headers, HeaderCount);
1079 Headers = NULL;
1080 }
1081
1082 if (Payload != NULL) {
1083 RedfishCleanupPayload (Payload);
1084 Payload = NULL;
1085 }
1086}
1087
1099BOOLEAN
1101 IN REDFISH_PAYLOAD Payload,
1102 IN CONST CHAR8 *OdataTypeName,
1103 IN REDFISH_ODATA_TYPE_MAPPING *OdataTypeMappingList,
1104 IN UINTN OdataTypeMappingListSize
1105 )
1106{
1107 UINTN Index;
1108 EDKII_JSON_VALUE OdataType;
1109 EDKII_JSON_VALUE JsonValue;
1110
1111 if ((Payload == NULL) || (OdataTypeName == NULL)) {
1112 return FALSE;
1113 }
1114
1115 JsonValue = RedfishJsonInPayload (Payload);
1116 if (!JsonValueIsObject (JsonValue)) {
1117 return FALSE;
1118 }
1119
1120 OdataType = JsonObjectGetValue (JsonValueGetObject (JsonValue), "@odata.type");
1121 if (!JsonValueIsString (OdataType) || (JsonValueGetAsciiString (OdataType) == NULL)) {
1122 return FALSE;
1123 }
1124
1125 for (Index = 0; Index < OdataTypeMappingListSize; Index++) {
1126 if ((AsciiStrCmp (OdataTypeMappingList[Index].OdataTypeName, OdataTypeName) == 0) &&
1127 (AsciiStrCmp (OdataTypeMappingList[Index].OdataType, JsonValueGetAsciiString (OdataType)) == 0))
1128 {
1129 return TRUE;
1130 }
1131 }
1132
1133 DEBUG ((DEBUG_MANAGEABILITY, "%a: This Odata type is not in the list.\n", __func__));
1134 return FALSE;
1135}
1136
1145BOOLEAN
1147 IN REDFISH_PAYLOAD Payload
1148 )
1149{
1150 return isPayloadCollection (Payload);
1151}
1152
1164 IN REDFISH_PAYLOAD Payload,
1165 IN UINTN *CollectionSize
1166 )
1167{
1168 if ((Payload == NULL) || (CollectionSize == NULL)) {
1169 return EFI_INVALID_PARAMETER;
1170 }
1171
1172 if (!RedfishIsPayloadCollection (Payload)) {
1173 return EFI_INVALID_PARAMETER;
1174 }
1175
1176 *CollectionSize = (UINTN)getCollectionSize (Payload);
1177 return EFI_SUCCESS;
1178}
1179
1189REDFISH_PAYLOAD
1191 IN REDFISH_PAYLOAD Payload,
1192 IN UINTN Index
1193 )
1194{
1195 REDFISH_RESPONSE RedfishResponse;
1196 REDFISH_PAYLOAD PayloadReturn;
1197
1198 PayloadReturn = (VOID *)getPayloadByIndex (Payload, Index, &RedfishResponse.StatusCode);
1199 if ((PayloadReturn == NULL) ||
1200 ((*(RedfishResponse.StatusCode) < HTTP_STATUS_200_OK) && (*(RedfishResponse.StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT)))
1201 {
1202 return NULL;
1203 }
1204
1205 return PayloadReturn;
1206}
1207
1219 IN REDFISH_SERVICE RedfishService,
1220 IN CHAR8 *Redpath,
1221 IN REDFISH_RESPONSE *Response OPTIONAL
1222 )
1223{
1224 EFI_STATUS Status;
1225 REDFISH_RESPONSE TempResponse;
1226
1227 if (Redpath == NULL) {
1228 return EFI_INVALID_PARAMETER;
1229 }
1230
1231 Status = RedfishGetByService (RedfishService, Redpath, &TempResponse);
1232 if (EFI_ERROR (Status)) {
1233 return Status;
1234 }
1235
1236 if (Response == NULL) {
1238 TempResponse.StatusCode,
1239 TempResponse.HeaderCount,
1240 TempResponse.Headers,
1241 TempResponse.Payload
1242 );
1243 } else {
1244 CopyMem ((VOID *)Response, (VOID *)&TempResponse, sizeof (REDFISH_RESPONSE));
1245 }
1246
1247 return EFI_SUCCESS;
1248}
1249
1283EFIAPI
1285 IN REDFISH_SERVICE RedfishService,
1286 IN CONST CHAR8 *Uri,
1287 IN CONST CHAR8 *Content,
1288 IN UINTN ContentSize OPTIONAL,
1289 IN CONST CHAR8 *ContentType OPTIONAL,
1290 OUT REDFISH_RESPONSE *RedResponse
1291 )
1292{
1293 EFI_STATUS Status;
1294 EDKII_JSON_VALUE JsonValue;
1295
1296 Status = EFI_SUCCESS;
1297 JsonValue = NULL;
1298
1299 if ((RedfishService == NULL) || (Uri == NULL) || (Content == NULL) || (RedResponse == NULL)) {
1300 return EFI_INVALID_PARAMETER;
1301 }
1302
1303 ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
1304
1305 JsonValue = (EDKII_JSON_VALUE)putUriFromServiceEx (
1306 RedfishService,
1307 Uri,
1308 Content,
1309 ContentSize,
1310 ContentType,
1311 &(RedResponse->Headers),
1312 &(RedResponse->HeaderCount),
1313 &(RedResponse->StatusCode)
1314 );
1315
1316 //
1317 // 1. If the returned StatusCode is NULL, indicates any error happen.
1318 //
1319 if (RedResponse->StatusCode == NULL) {
1320 Status = EFI_DEVICE_ERROR;
1321 goto ON_EXIT;
1322 }
1323
1324 //
1325 // 2. If the returned StatusCode is not NULL and the value is not 2XX, indicates any error happen.
1326 // NOTE: If there is any error message returned from server, it will be returned in
1327 // Payload within RedResponse.
1328 //
1329 if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
1330 (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
1331 {
1332 Status = EFI_DEVICE_ERROR;
1333 }
1334
1335ON_EXIT:
1336 if (JsonValue != NULL) {
1337 RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);
1338 if (RedResponse->Payload == NULL) {
1339 //
1340 // Ignore the error when create RedfishPayload, just free the JsonValue since it's not what
1341 // we care about if the returned StatusCode is 2XX.
1342 //
1343 JsonValueFree (JsonValue);
1344 }
1345 }
1346
1347 return Status;
1348}
UINT64 UINTN
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
Definition: String.c:716
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
Definition: String.c:681
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EDKII_REDFISH_AUTH_METHOD
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID EFIAPI HttpFreeHeaderFields(IN EFI_HTTP_HEADER *HeaderFields, IN UINTN FieldCount)
Definition: DxeHttpLib.c:1730
BOOLEAN EFIAPI JsonValueIsString(IN EDKII_JSON_VALUE Json)
Definition: JsonLib.c:350
VOID EFIAPI JsonValueFree(IN EDKII_JSON_VALUE Json)
Definition: JsonLib.c:269
CHAR8 *EFIAPI JsonDumpString(IN EDKII_JSON_VALUE JsonValue, IN UINTN Flags)
Definition: JsonLib.c:960
EDKII_JSON_OBJECT EFIAPI JsonValueGetObject(IN EDKII_JSON_VALUE Json)
Definition: JsonLib.c:508
EDKII_JSON_VALUE EFIAPI JsonValueClone(IN EDKII_JSON_VALUE Json)
Definition: JsonLib.c:295
CONST CHAR8 *EFIAPI JsonValueGetAsciiString(IN EDKII_JSON_VALUE Json)
Definition: JsonLib.c:531
EDKII_JSON_VALUE EFIAPI JsonObjectGetValue(IN CONST EDKII_JSON_OBJECT JsonObj, IN CONST CHAR8 *Key)
Definition: JsonLib.c:772
BOOLEAN EFIAPI JsonValueIsObject(IN EDKII_JSON_VALUE Json)
Definition: JsonLib.c:331
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:813
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_HTTP_STATUS_CODE
Definition: Http.h:59
EFI_STATUS EFIAPI NetLibGetSystemGuid(OUT EFI_GUID *SystemGuid)
Definition: DxeNetLib.c:3325
REDFISH_SERVICE EFIAPI RedfishServiceInPayload(IN REDFISH_PAYLOAD Payload)
Definition: RedfishLib.c:184
EFI_STATUS EFIAPI RedfishGetByUri(IN REDFISH_SERVICE RedfishService, IN CONST CHAR8 *Uri, OUT REDFISH_RESPONSE *RedResponse)
Definition: RedfishLib.c:345
VOID EFIAPI RedfishCleanupPayload(IN REDFISH_PAYLOAD Payload)
Definition: RedfishLib.c:136
EFI_STATUS EFIAPI RedfishDeleteByUri(IN REDFISH_SERVICE RedfishService, IN CONST CHAR8 *Uri, OUT REDFISH_RESPONSE *RedResponse)
Definition: RedfishLib.c:808
EFI_STATUS EFIAPI RedfishGetByPayload(IN REDFISH_PAYLOAD Payload, IN CONST CHAR8 *RedPath, OUT REDFISH_RESPONSE *RedResponse)
Definition: RedfishLib.c:412
VOID EFIAPI RedfishCleanupService(IN REDFISH_SERVICE RedfishService)
Definition: RedfishLib.c:89
EFI_STATUS EFIAPI RedfishPostToPayload(IN REDFISH_PAYLOAD Target, IN REDFISH_PAYLOAD Payload, OUT REDFISH_RESPONSE *RedResponse)
Definition: RedfishLib.c:740
VOID RedfishFreeResponse(IN EFI_HTTP_STATUS_CODE *StatusCode, IN UINTN HeaderCount, IN EFI_HTTP_HEADER *Headers, IN REDFISH_PAYLOAD Payload)
Definition: RedfishLib.c:1065
EFI_STATUS EFIAPI RedfishPatchToUri(IN REDFISH_SERVICE RedfishService, IN CONST CHAR8 *Uri, IN CONST CHAR8 *Content, OUT REDFISH_RESPONSE *RedResponse)
Definition: RedfishLib.c:482
BOOLEAN RedfishIsPayloadCollection(IN REDFISH_PAYLOAD Payload)
Definition: RedfishLib.c:1146
EFI_STATUS EFIAPI RedfishDeleteByUriEx(IN REDFISH_SERVICE RedfishService, IN CONST CHAR8 *Uri, IN CONST CHAR8 *Content, OUT REDFISH_RESPONSE *RedResponse)
Definition: RedfishLib.c:896
VOID RedfishDumpPayload(IN REDFISH_PAYLOAD Payload)
Definition: RedfishLib.c:1027
CHAR8 *EFIAPI RedfishBuildPathWithSystemUuid(IN CONST CHAR8 *RedPath, IN BOOLEAN FromSmbios, IN CHAR8 *IdString OPTIONAL)
Definition: RedfishLib.c:216
VOID RedfishDumpJson(IN EDKII_JSON_VALUE JsonValue)
Definition: RedfishLib.c:1005
EDKII_JSON_VALUE EFIAPI RedfishJsonInPayload(IN REDFISH_PAYLOAD Payload)
Definition: RedfishLib.c:160
EFI_STATUS RedfishGetCollectionSize(IN REDFISH_PAYLOAD Payload, IN UINTN *CollectionSize)
Definition: RedfishLib.c:1163
REDFISH_SERVICE EFIAPI RedfishCreateService(IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo)
Definition: RedfishLib.c:30
EFI_STATUS RedfishCheckIfRedpathExist(IN REDFISH_SERVICE RedfishService, IN CHAR8 *Redpath, IN REDFISH_RESPONSE *Response OPTIONAL)
Definition: RedfishLib.c:1218
REDFISH_PAYLOAD RedfishGetPayloadByIndex(IN REDFISH_PAYLOAD Payload, IN UINTN Index)
Definition: RedfishLib.c:1190
EFI_STATUS EFIAPI RedfishPutToUri(IN REDFISH_SERVICE RedfishService, IN CONST CHAR8 *Uri, IN CONST CHAR8 *Content, IN UINTN ContentSize OPTIONAL, IN CONST CHAR8 *ContentType OPTIONAL, OUT REDFISH_RESPONSE *RedResponse)
Definition: RedfishLib.c:1284
EFI_STATUS EFIAPI RedfishPostToUri(IN REDFISH_SERVICE RedfishService, IN CONST CHAR8 *Uri, IN CONST CHAR8 *Content, IN UINTN ContentSize OPTIONAL, IN CONST CHAR8 *ContentType OPTIONAL, OUT REDFISH_RESPONSE *RedResponse)
Definition: RedfishLib.c:645
EFI_STATUS EFIAPI RedfishGetByService(IN REDFISH_SERVICE RedfishService, IN CONST CHAR8 *RedPath, OUT REDFISH_RESPONSE *RedResponse)
Definition: RedfishLib.c:285
VOID RedfishDumpJsonStringFractions(IN CHAR8 *String)
Definition: RedfishLib.c:963
REDFISH_PAYLOAD EFIAPI RedfishCreatePayload(IN EDKII_JSON_VALUE Value, IN REDFISH_SERVICE RedfishService)
Definition: RedfishLib.c:117
EFI_STATUS EFIAPI RedfishPatchToPayload(IN REDFISH_PAYLOAD Target, IN REDFISH_PAYLOAD Payload, OUT REDFISH_RESPONSE *RedResponse)
Definition: RedfishLib.c:574
BOOLEAN RedfishIsValidOdataType(IN REDFISH_PAYLOAD Payload, IN CONST CHAR8 *OdataTypeName, IN REDFISH_ODATA_TYPE_MAPPING *OdataTypeMappingList, IN UINTN OdataTypeMappingListSize)
Definition: RedfishLib.c:1100
EFI_STATUS RedfishGetAuthInfo(OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod, OUT CHAR8 **UserId, OUT CHAR8 **Password)
Definition: RedfishMisc.c:136
REDFISH_SERVICE RedfishCreateLibredfishService(IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo, IN EDKII_REDFISH_AUTH_METHOD AuthMethod, IN CHAR8 *UserId, IN CHAR8 *Password)
Definition: RedfishMisc.c:71
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213