VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.c

Last change on this file 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: 17.4 KB
Line 
1/** @file
2 Redfish HTTP cache library helps Redfish application to get Redfish resource
3 from BMC with cache mechanism enabled.
4
5 Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
13#include <Library/RedfishHttpLib.h>
14#include <Library/UefiBootServicesTableLib.h>
15#include <Library/UefiLib.h>
16
17EDKII_REDFISH_HTTP_PROTOCOL *mRedfishHttpProtocol = NULL;
18
19/**
20 This function create Redfish service. It's caller's responsibility to free returned
21 Redfish service by calling FreeService ().
22
23 @param[in] RedfishConfigServiceInfo Redfish config service information.
24
25 @retval REDFISH_SERVICE Redfish service is created.
26 @retval NULL Errors occur.
27
28**/
29REDFISH_SERVICE
30RedfishCreateService (
31 IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo
32 )
33{
34 if (mRedfishHttpProtocol == NULL) {
35 return NULL;
36 }
37
38 return mRedfishHttpProtocol->CreateService (
39 mRedfishHttpProtocol,
40 RedfishConfigServiceInfo
41 );
42}
43
44/**
45 This function free resources in Redfish service. RedfishService is no longer available
46 after this function returns successfully.
47
48 @param[in] RedfishService Pointer to Redfish service to be released.
49
50 @retval EFI_SUCCESS Resource is released successfully.
51 @retval Others Errors occur.
52
53**/
54EFI_STATUS
55RedfishCleanupService (
56 IN REDFISH_SERVICE RedfishService
57 )
58{
59 if (mRedfishHttpProtocol == NULL) {
60 return EFI_NOT_READY;
61 }
62
63 return mRedfishHttpProtocol->FreeService (
64 mRedfishHttpProtocol,
65 RedfishService
66 );
67}
68
69/**
70 This function returns JSON value in given RedfishPayload. Returned JSON value
71 is a reference to the JSON value in RedfishPayload. Any modification to returned
72 JSON value will change JSON value in RedfishPayload.
73
74 @param[in] RedfishPayload Pointer to Redfish payload.
75
76 @retval EDKII_JSON_VALUE JSON value is returned.
77 @retval NULL Errors occur.
78
79**/
80EDKII_JSON_VALUE
81RedfishJsonInPayload (
82 IN REDFISH_PAYLOAD RedfishPayload
83 )
84{
85 if (mRedfishHttpProtocol == NULL) {
86 return NULL;
87 }
88
89 return mRedfishHttpProtocol->JsonInPayload (
90 mRedfishHttpProtocol,
91 RedfishPayload
92 );
93}
94
95/**
96 This function free resources in Request. Request is no longer available
97 after this function returns successfully.
98
99 @param[in] Request HTTP request to be released.
100
101 @retval EFI_SUCCESS Resource is released successfully.
102 @retval Others Errors occur.
103
104**/
105EFI_STATUS
106RedfishHttpFreeRequest (
107 IN REDFISH_REQUEST *Request
108 )
109{
110 if (mRedfishHttpProtocol == NULL) {
111 return EFI_NOT_READY;
112 }
113
114 return mRedfishHttpProtocol->FreeRequest (
115 mRedfishHttpProtocol,
116 Request
117 );
118}
119
120/**
121 This function free resources in Response. Response is no longer available
122 after this function returns successfully.
123
124 @param[in] Response HTTP response to be released.
125
126 @retval EFI_SUCCESS Resource is released successfully.
127 @retval Others Errors occur.
128
129**/
130EFI_STATUS
131RedfishHttpFreeResponse (
132 IN REDFISH_RESPONSE *Response
133 )
134{
135 if (mRedfishHttpProtocol == NULL) {
136 return EFI_NOT_READY;
137 }
138
139 return mRedfishHttpProtocol->FreeResponse (
140 mRedfishHttpProtocol,
141 Response
142 );
143}
144
145/**
146 This function expire the cached response of given URI.
147
148 @param[in] Uri Target response of URI.
149
150 @retval EFI_SUCCESS Target response is expired successfully.
151 @retval Others Errors occur.
152
153**/
154EFI_STATUS
155RedfishHttpExpireResponse (
156 IN EFI_STRING Uri
157 )
158{
159 if (mRedfishHttpProtocol == NULL) {
160 return EFI_NOT_READY;
161 }
162
163 return mRedfishHttpProtocol->ExpireResponse (
164 mRedfishHttpProtocol,
165 Uri
166 );
167}
168
169/**
170 Get redfish resource from given resource URI with cache mechanism
171 supported. It's caller's responsibility to Response by calling
172 RedfishHttpFreeResponse ().
173
174 @param[in] Service Redfish service instance to perform HTTP GET.
175 @param[in] Uri Target resource URI.
176 @param[in] Request Additional request context. This is optional.
177 @param[out] Response HTTP response from redfish service.
178 @param[in] UseCache If it is TRUE, this function will search for
179 cache first. If it is FALSE, this function
180 will query Redfish URI directly.
181
182 @retval EFI_SUCCESS Resource is returned successfully.
183 @retval Others Errors occur.
184
185**/
186EFI_STATUS
187RedfishHttpGetResource (
188 IN REDFISH_SERVICE Service,
189 IN EFI_STRING Uri,
190 IN REDFISH_REQUEST *Request OPTIONAL,
191 OUT REDFISH_RESPONSE *Response,
192 IN BOOLEAN UseCache
193 )
194{
195 if (mRedfishHttpProtocol == NULL) {
196 return EFI_NOT_READY;
197 }
198
199 return mRedfishHttpProtocol->GetResource (
200 mRedfishHttpProtocol,
201 Service,
202 Uri,
203 Request,
204 Response,
205 UseCache
206 );
207}
208
209/**
210 Perform HTTP PATCH to send redfish resource to given resource URI.
211 It's caller's responsibility to free Response by calling RedfishHttpFreeResponse ().
212
213 @param[in] Service Redfish service instance to perform HTTP PATCH.
214 @param[in] Uri Target resource URI.
215 @param[in] Content Data to patch.
216 @param[out] Response HTTP response from redfish service.
217
218 @retval EFI_SUCCESS Resource is returned successfully.
219 @retval Others Errors occur.
220
221**/
222EFI_STATUS
223RedfishHttpPatchResource (
224 IN REDFISH_SERVICE Service,
225 IN EFI_STRING Uri,
226 IN CHAR8 *Content,
227 OUT REDFISH_RESPONSE *Response
228 )
229{
230 if (mRedfishHttpProtocol == NULL) {
231 return EFI_NOT_READY;
232 }
233
234 return mRedfishHttpProtocol->PatchResource (
235 mRedfishHttpProtocol,
236 Service,
237 Uri,
238 Content,
239 0,
240 NULL,
241 Response
242 );
243}
244
245/**
246 Perform HTTP PATCH to send redfish resource to given resource URI.
247 It's caller's responsibility to free Response by calling RedfishHttpFreeResponse ().
248
249 @param[in] Service Redfish service instance to perform HTTP PATCH.
250 @param[in] Uri Target resource URI.
251 @param[in] Content Data to patch.
252 @param[in] ContentSize Size of the Content to be send to Redfish service.
253 This is optional. When ContentSize is 0, ContentSize
254 is the size of Content.
255 @param[in] ContentType Type of the Content to be send to Redfish service.
256 This is optional.
257 @param[out] Response HTTP response from redfish service.
258
259 @retval EFI_SUCCESS Resource is returned successfully.
260 @retval Others Errors occur.
261
262**/
263EFI_STATUS
264RedfishHttpPatchResourceEx (
265 IN REDFISH_SERVICE Service,
266 IN EFI_STRING Uri,
267 IN CHAR8 *Content,
268 IN UINTN ContentSize OPTIONAL,
269 IN CHAR8 *ContentType OPTIONAL,
270 OUT REDFISH_RESPONSE *Response
271 )
272{
273 if (mRedfishHttpProtocol == NULL) {
274 return EFI_NOT_READY;
275 }
276
277 return mRedfishHttpProtocol->PatchResource (
278 mRedfishHttpProtocol,
279 Service,
280 Uri,
281 Content,
282 ContentSize,
283 ContentType,
284 Response
285 );
286}
287
288/**
289 Perform HTTP PUT to send redfish resource to given resource URI.
290 It's caller's responsibility to free Response by calling RedfishHttpFreeResponse ().
291
292 @param[in] Service Redfish service instance to perform HTTP PUT.
293 @param[in] Uri Target resource URI.
294 @param[in] Content Data to put.
295 @param[out] Response HTTP response from redfish service.
296
297 @retval EFI_SUCCESS Resource is returned successfully.
298 @retval Others Errors occur.
299
300**/
301EFI_STATUS
302RedfishHttpPutResource (
303 IN REDFISH_SERVICE Service,
304 IN EFI_STRING Uri,
305 IN CHAR8 *Content,
306 OUT REDFISH_RESPONSE *Response
307 )
308{
309 if (mRedfishHttpProtocol == NULL) {
310 return EFI_NOT_READY;
311 }
312
313 return mRedfishHttpProtocol->PutResource (
314 mRedfishHttpProtocol,
315 Service,
316 Uri,
317 Content,
318 0,
319 NULL,
320 Response
321 );
322}
323
324/**
325 Perform HTTP PUT to send redfish resource to given resource URI.
326 It's caller's responsibility to free Response by calling RedfishHttpFreeResponse ().
327
328 @param[in] Service Redfish service instance to perform HTTP PUT.
329 @param[in] Uri Target resource URI.
330 @param[in] Content Data to put.
331 @param[in] ContentSize Size of the Content to be send to Redfish service.
332 This is optional. When ContentSize is 0, ContentSize
333 is the size of Content.
334 @param[in] ContentType Type of the Content to be send to Redfish service.
335 This is optional.
336 @param[out] Response HTTP response from redfish service.
337
338 @retval EFI_SUCCESS Resource is returned successfully.
339 @retval Others Errors occur.
340
341**/
342EFI_STATUS
343RedfishHttpPutResourceEx (
344 IN REDFISH_SERVICE Service,
345 IN EFI_STRING Uri,
346 IN CHAR8 *Content,
347 IN UINTN ContentSize OPTIONAL,
348 IN CHAR8 *ContentType OPTIONAL,
349 OUT REDFISH_RESPONSE *Response
350 )
351{
352 if (mRedfishHttpProtocol == NULL) {
353 return EFI_NOT_READY;
354 }
355
356 return mRedfishHttpProtocol->PutResource (
357 mRedfishHttpProtocol,
358 Service,
359 Uri,
360 Content,
361 ContentSize,
362 ContentType,
363 Response
364 );
365}
366
367/**
368 Perform HTTP POST to send redfish resource to given resource URI.
369 It's caller's responsibility to free Response by calling RedfishHttpFreeResponse ().
370
371 @param[in] Service Redfish service instance to perform HTTP POST.
372 @param[in] Uri Target resource URI.
373 @param[in] Content Data to post.
374 @param[out] Response HTTP response from redfish service.
375
376 @retval EFI_SUCCESS Resource is returned successfully.
377 @retval Others Errors occur.
378
379**/
380EFI_STATUS
381RedfishHttpPostResource (
382 IN REDFISH_SERVICE Service,
383 IN EFI_STRING Uri,
384 IN CHAR8 *Content,
385 OUT REDFISH_RESPONSE *Response
386 )
387{
388 if (mRedfishHttpProtocol == NULL) {
389 return EFI_NOT_READY;
390 }
391
392 return mRedfishHttpProtocol->PostResource (
393 mRedfishHttpProtocol,
394 Service,
395 Uri,
396 Content,
397 0,
398 NULL,
399 Response
400 );
401}
402
403/**
404 Perform HTTP POST to send redfish resource to given resource URI.
405 It's caller's responsibility to free Response by calling RedfishHttpFreeResponse ().
406
407 @param[in] Service Redfish service instance to perform HTTP POST.
408 @param[in] Uri Target resource URI.
409 @param[in] Content Data to post.
410 @param[in] ContentSize Size of the Content to be send to Redfish service.
411 This is optional. When ContentSize is 0, ContentSize
412 is the size of Content.
413 @param[in] ContentType Type of the Content to be send to Redfish service.
414 This is optional.
415 @param[out] Response HTTP response from redfish service.
416
417 @retval EFI_SUCCESS Resource is returned successfully.
418 @retval Others Errors occur.
419
420**/
421EFI_STATUS
422RedfishHttpPostResourceEx (
423 IN REDFISH_SERVICE Service,
424 IN EFI_STRING Uri,
425 IN CHAR8 *Content,
426 IN UINTN ContentSize OPTIONAL,
427 IN CHAR8 *ContentType OPTIONAL,
428 OUT REDFISH_RESPONSE *Response
429 )
430{
431 if (mRedfishHttpProtocol == NULL) {
432 return EFI_NOT_READY;
433 }
434
435 return mRedfishHttpProtocol->PostResource (
436 mRedfishHttpProtocol,
437 Service,
438 Uri,
439 Content,
440 ContentSize,
441 ContentType,
442 Response
443 );
444}
445
446/**
447 Perform HTTP DELETE to delete redfish resource on given resource URI.
448 It's caller's responsibility to free Response by calling RedfishHttpFreeResponse ().
449
450 @param[in] Service Redfish service instance to perform HTTP DELETE.
451 @param[in] Uri Target resource URI.
452 @param[out] Response HTTP response from redfish service.
453
454 @retval EFI_SUCCESS Resource is returned successfully.
455 @retval Others Errors occur.
456
457**/
458EFI_STATUS
459RedfishHttpDeleteResource (
460 IN REDFISH_SERVICE Service,
461 IN EFI_STRING Uri,
462 OUT REDFISH_RESPONSE *Response
463 )
464{
465 if (mRedfishHttpProtocol == NULL) {
466 return EFI_NOT_READY;
467 }
468
469 return mRedfishHttpProtocol->DeleteResource (
470 mRedfishHttpProtocol,
471 Service,
472 Uri,
473 NULL,
474 0,
475 NULL,
476 Response
477 );
478}
479
480/**
481 Perform HTTP DELETE to delete redfish resource on given resource URI.
482 It's caller's responsibility to free Response by calling RedfishHttpFreeResponse ().
483
484 @param[in] Service Redfish service instance to perform HTTP DELETE.
485 @param[in] Uri Target resource URI.
486 @param[in] Content JSON represented properties to be deleted. This is
487 optional.
488 @param[in] ContentSize Size of the Content to be send to Redfish service.
489 This is optional. When ContentSize is 0, ContentSize
490 is the size of Content if Content is not NULL.
491 @param[in] ContentType Type of the Content to be send to Redfish service.
492 This is optional.
493 @param[out] Response HTTP response from redfish service.
494
495 @retval EFI_SUCCESS Resource is returned successfully.
496 @retval Others Errors occur.
497
498**/
499EFI_STATUS
500RedfishHttpDeleteResourceEx (
501 IN REDFISH_SERVICE Service,
502 IN EFI_STRING Uri,
503 IN CHAR8 *Content OPTIONAL,
504 IN UINTN ContentSize OPTIONAL,
505 IN CHAR8 *ContentType OPTIONAL,
506 OUT REDFISH_RESPONSE *Response
507 )
508{
509 if (mRedfishHttpProtocol == NULL) {
510 return EFI_NOT_READY;
511 }
512
513 return mRedfishHttpProtocol->DeleteResource (
514 mRedfishHttpProtocol,
515 Service,
516 Uri,
517 Content,
518 ContentSize,
519 ContentType,
520 Response
521 );
522}
523
524/**
525 Callback function when gEdkIIRedfishHttpProtocolGuid is installed.
526
527 @param[in] Event Event whose notification function is being invoked.
528 @param[in] Context Pointer to the notification function's context.
529**/
530VOID
531EFIAPI
532RedfishHttpProtocolIsReady (
533 IN EFI_EVENT Event,
534 IN VOID *Context
535 )
536{
537 EFI_STATUS Status;
538
539 if (mRedfishHttpProtocol != NULL) {
540 gBS->CloseEvent (Event);
541 return;
542 }
543
544 Status = gBS->LocateProtocol (
545 &gEdkIIRedfishHttpProtocolGuid,
546 NULL,
547 (VOID **)&mRedfishHttpProtocol
548 );
549 if (EFI_ERROR (Status)) {
550 return;
551 }
552
553 gBS->CloseEvent (Event);
554}
555
556/**
557
558 Initial HTTP library instance.
559
560 @param[in] ImageHandle The image handle.
561 @param[in] SystemTable The system table.
562
563 @retval EFI_SUCCESS Initial library successfully.
564 @retval Other Return error status.
565
566**/
567EFI_STATUS
568EFIAPI
569RedfishHttpConstructor (
570 IN EFI_HANDLE ImageHandle,
571 IN EFI_SYSTEM_TABLE *SystemTable
572 )
573{
574 VOID *Registration;
575
576 EfiCreateProtocolNotifyEvent (
577 &gEdkIIRedfishHttpProtocolGuid,
578 TPL_CALLBACK,
579 RedfishHttpProtocolIsReady,
580 NULL,
581 &Registration
582 );
583
584 return EFI_SUCCESS;
585}
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