TianoCore EDK2 master
Loading...
Searching...
No Matches
RedfishDebugLib.c
Go to the documentation of this file.
1
11#include <Uefi.h>
12#include <RedfishCommon.h>
13#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
18#include <Library/UefiLib.h>
19
20#define REDFISH_JSON_STRING_LENGTH 200
21#define REDFISH_JSON_OUTPUT_FORMAT (EDKII_JSON_COMPACT | EDKII_JSON_INDENT(2))
22#define REDFISH_PRINT_BUFFER_BYTES_PER_ROW 16
23
33BOOLEAN
35 IN UINT64 RedfishDebugCategory
36 )
37{
38 UINT64 DebugCategory;
39
40 DebugCategory = FixedPcdGet64 (PcdRedfishDebugCategory);
41 return ((DebugCategory & RedfishDebugCategory) != 0);
42}
43
55 IN UINTN ErrorLevel,
56 IN EDKII_REDFISH_VALUE *RedfishValue
57 )
58{
59 UINTN Index;
60
61 if (RedfishValue == NULL) {
62 return EFI_INVALID_PARAMETER;
63 }
64
65 DEBUG ((ErrorLevel, "Type: 0x%x\n", RedfishValue->Type));
66 DEBUG ((ErrorLevel, "ArrayCount: 0x%x\n", RedfishValue->ArrayCount));
67
68 switch (RedfishValue->Type) {
69 case RedfishValueTypeInteger:
70 DEBUG ((ErrorLevel, "Value: 0x%x\n", RedfishValue->Value.Integer));
71 break;
72 case RedfishValueTypeBoolean:
73 DEBUG ((ErrorLevel, "Value: %a\n", (RedfishValue->Value.Boolean ? "true" : "false")));
74 break;
75 case RedfishValueTypeString:
76 DEBUG ((ErrorLevel, "Value: %a\n", RedfishValue->Value.Buffer));
77 break;
78 case RedfishValueTypeStringArray:
79 for (Index = 0; Index < RedfishValue->ArrayCount; Index++) {
80 DEBUG ((ErrorLevel, "Value[%d]: %a\n", Index, RedfishValue->Value.StringArray[Index]));
81 }
82
83 break;
84 case RedfishValueTypeIntegerArray:
85 for (Index = 0; Index < RedfishValue->ArrayCount; Index++) {
86 DEBUG ((ErrorLevel, "Value[%d]: 0x%x\n", Index, RedfishValue->Value.IntegerArray[Index]));
87 }
88
89 break;
90 case RedfishValueTypeBooleanArray:
91 for (Index = 0; Index < RedfishValue->ArrayCount; Index++) {
92 DEBUG ((ErrorLevel, "Value[%d]: %a\n", Index, (RedfishValue->Value.BooleanArray[Index] ? "true" : "false")));
93 }
94
95 break;
96 case RedfishValueTypeUnknown:
97 case RedfishValueTypeMax:
98 default:
99 break;
100 }
101
102 return EFI_SUCCESS;
103}
104
118 IN UINTN ErrorLevel,
119 IN EDKII_JSON_VALUE JsonValue
120 )
121{
122 CHAR8 *String;
123 CHAR8 *Runner;
124 CHAR8 Buffer[REDFISH_JSON_STRING_LENGTH + 1];
126 UINTN Count;
127 UINTN Index;
128
129 if (JsonValue == NULL) {
130 return EFI_INVALID_PARAMETER;
131 }
132
133 String = JsonDumpString (JsonValue, REDFISH_JSON_OUTPUT_FORMAT);
134 if (String == NULL) {
135 return EFI_UNSUPPORTED;
136 }
137
138 StrLen = AsciiStrLen (String);
139 if (StrLen == 0) {
140 return EFI_UNSUPPORTED;
141 }
142
143 Count = StrLen / REDFISH_JSON_STRING_LENGTH;
144 Runner = String;
145 for (Index = 0; Index < Count; Index++) {
146 AsciiStrnCpyS (Buffer, (REDFISH_JSON_STRING_LENGTH + 1), Runner, REDFISH_JSON_STRING_LENGTH);
147 Buffer[REDFISH_JSON_STRING_LENGTH] = '\0';
148 DEBUG ((ErrorLevel, "%a", Buffer));
149 Runner += REDFISH_JSON_STRING_LENGTH;
150 }
151
152 Count = StrLen % REDFISH_JSON_STRING_LENGTH;
153 if (Count > 0) {
154 DEBUG ((ErrorLevel, "%a", Runner));
155 }
156
157 DEBUG ((ErrorLevel, "\n"));
158
159 FreePool (String);
160 return EFI_SUCCESS;
161}
162
177 IN UINTN ErrorLevel,
178 IN REDFISH_PAYLOAD Payload
179 )
180{
181 EDKII_JSON_VALUE JsonValue;
182
183 if (Payload == NULL) {
184 return EFI_INVALID_PARAMETER;
185 }
186
187 JsonValue = RedfishJsonInPayload (Payload);
188 if (JsonValue != NULL) {
189 DEBUG ((ErrorLevel, "Payload:\n"));
190 DumpJsonValue (ErrorLevel, JsonValue);
191 }
192
193 return EFI_SUCCESS;
194}
195
208 IN UINTN ErrorLevel,
209 IN EFI_HTTP_STATUS_CODE HttpStatusCode
210 )
211{
212 switch (HttpStatusCode) {
213 case HTTP_STATUS_100_CONTINUE:
214 DEBUG ((ErrorLevel, "Status code: 100 CONTINUE\n"));
215 break;
216 case HTTP_STATUS_200_OK:
217 DEBUG ((ErrorLevel, "Status code: 200 OK\n"));
218 break;
219 case HTTP_STATUS_201_CREATED:
220 DEBUG ((ErrorLevel, "Status code: 201 CREATED\n"));
221 break;
222 case HTTP_STATUS_202_ACCEPTED:
223 DEBUG ((ErrorLevel, "Status code: 202 ACCEPTED\n"));
224 break;
225 case HTTP_STATUS_304_NOT_MODIFIED:
226 DEBUG ((ErrorLevel, "Status code: 304 NOT MODIFIED\n"));
227 break;
228 case HTTP_STATUS_400_BAD_REQUEST:
229 DEBUG ((ErrorLevel, "Status code: 400 BAD REQUEST\n"));
230 break;
231 case HTTP_STATUS_401_UNAUTHORIZED:
232 DEBUG ((ErrorLevel, "Status code: 401 UNAUTHORIZED\n"));
233 break;
234 case HTTP_STATUS_403_FORBIDDEN:
235 DEBUG ((ErrorLevel, "Status code: 403 FORBIDDEN\n"));
236 break;
237 case HTTP_STATUS_404_NOT_FOUND:
238 DEBUG ((ErrorLevel, "Status code: 404 NOT FOUND\n"));
239 break;
240 case HTTP_STATUS_405_METHOD_NOT_ALLOWED:
241 DEBUG ((ErrorLevel, "Status code: 405 METHOD NOT ALLOWED\n"));
242 break;
243 case HTTP_STATUS_500_INTERNAL_SERVER_ERROR:
244 DEBUG ((ErrorLevel, "Status code: 500 INTERNAL SERVER ERROR\n"));
245 break;
246 default:
247 DEBUG ((ErrorLevel, "Status code: 0x%x\n", HttpStatusCode));
248 break;
249 }
250
251 return EFI_SUCCESS;
252}
253
269 IN CONST CHAR8 *Message,
270 IN UINTN ErrorLevel,
271 IN REDFISH_RESPONSE *Response
272 )
273{
274 UINTN Index;
275
276 if (Response == NULL) {
277 return EFI_INVALID_PARAMETER;
278 }
279
280 if (!IS_EMPTY_STRING (Message)) {
281 DEBUG ((ErrorLevel, "%a\n", Message));
282 }
283
284 //
285 // status code
286 //
287 if (Response->StatusCode != NULL) {
288 DumpHttpStatusCode (ErrorLevel, *(Response->StatusCode));
289 }
290
291 //
292 // header
293 //
294 if (Response->HeaderCount > 0) {
295 DEBUG ((ErrorLevel, "Header: %d\n", Response->HeaderCount));
296 for (Index = 0; Index < Response->HeaderCount; Index++) {
297 DEBUG ((ErrorLevel, " %a: %a\n", Response->Headers[Index].FieldName, Response->Headers[Index].FieldValue));
298 }
299 }
300
301 //
302 // Body
303 //
304 if (Response->Payload != NULL) {
305 DumpRedfishPayload (ErrorLevel, Response->Payload);
306 }
307
308 return EFI_SUCCESS;
309}
310
324 IN UINTN ErrorLevel,
325 IN EFI_IPv4_ADDRESS *Ipv4Address
326 )
327{
328 if (Ipv4Address == NULL) {
329 return EFI_INVALID_PARAMETER;
330 }
331
332 DEBUG ((ErrorLevel, "%d.%d.%d.%d\n", Ipv4Address->Addr[0], Ipv4Address->Addr[1], Ipv4Address->Addr[2], Ipv4Address->Addr[3]));
333
334 return EFI_SUCCESS;
335}
336
350 IN UINTN ErrorLevel,
351 IN UINT8 *Buffer,
352 IN UINTN BufferSize
353 )
354{
355 UINTN Index;
356
357 if (Buffer == NULL) {
358 return EFI_INVALID_PARAMETER;
359 }
360
361 DEBUG ((ErrorLevel, "Address: 0x%p size: %d\n", Buffer, BufferSize));
362 for (Index = 0; Index < BufferSize; Index++) {
363 if (Index % REDFISH_PRINT_BUFFER_BYTES_PER_ROW == 0) {
364 DEBUG ((ErrorLevel, "\n%04X: ", Index));
365 }
366
367 DEBUG ((ErrorLevel, "%02X ", Buffer[Index]));
368 }
369
370 DEBUG ((ErrorLevel, "\n"));
371
372 return EFI_SUCCESS;
373}
UINT64 UINTN
RETURN_STATUS EFIAPI AsciiStrnCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source, IN UINTN Length)
Definition: SafeString.c:1875
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID EFIAPI FreePool(IN VOID *Buffer)
CHAR8 *EFIAPI JsonDumpString(IN EDKII_JSON_VALUE JsonValue, IN UINTN Flags)
Definition: JsonLib.c:960
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_HTTP_STATUS_CODE
Definition: Http.h:59
#define FixedPcdGet64(TokenName)
Definition: PcdLib.h:106
EFI_STATUS DumpRedfishValue(IN UINTN ErrorLevel, IN EDKII_REDFISH_VALUE *RedfishValue)
EFI_STATUS DumpJsonValue(IN UINTN ErrorLevel, IN EDKII_JSON_VALUE JsonValue)
EFI_STATUS DumpHttpStatusCode(IN UINTN ErrorLevel, IN EFI_HTTP_STATUS_CODE HttpStatusCode)
EFI_STATUS DumpBuffer(IN UINTN ErrorLevel, IN UINT8 *Buffer, IN UINTN BufferSize)
EFI_STATUS DumpRedfishPayload(IN UINTN ErrorLevel, IN REDFISH_PAYLOAD Payload)
BOOLEAN DebugRedfishComponentEnabled(IN UINT64 RedfishDebugCategory)
EFI_STATUS DumpRedfishResponse(IN CONST CHAR8 *Message, IN UINTN ErrorLevel, IN REDFISH_RESPONSE *Response)
EFI_STATUS DumpIpv4Address(IN UINTN ErrorLevel, IN EFI_IPv4_ADDRESS *Ipv4Address)
EDKII_JSON_VALUE RedfishJsonInPayload(IN REDFISH_PAYLOAD RedfishPayload)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112