]> git.proxmox.com Git - mirror_edk2.git/blob - RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h
RedfishPkg/RefishCrtLib: Public RefishCrtLib
[mirror_edk2.git] / RedfishPkg / PrivateLibrary / RedfishLib / edk2libredfish / include / redfishService.h
1 /** @file
2 This file is cloned from DMTF libredfish library tag v1.0.0 and maintained
3 by EDKII.
4
5 //----------------------------------------------------------------------------
6 // Copyright Notice:
7 // Copyright 2017 Distributed Management Task Force, Inc. All rights reserved.
8 // License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libredfish/LICENSE.md
9 //----------------------------------------------------------------------------
10
11 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
12 (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
13
14 SPDX-License-Identifier: BSD-2-Clause-Patent
15
16 **/
17
18 #ifndef LIBREDFISH_REDFISH_SERVICE_H_
19 #define LIBREDFISH_REDFISH_SERVICE_H_
20
21 #include <IndustryStandard/Http11.h>
22
23 #include <Library/BaseLib.h>
24 #include <Library/BaseMemoryLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/HttpLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/NetLib.h>
29 #include <Library/RedfishContentCodingLib.h>
30 #include <Library/UefiRuntimeServicesTableLib.h>
31 #include <Library/UefiBootServicesTableLib.h>
32
33 #include <Include/Library/RedfishCrtLib.h>
34
35 #include <Protocol/EdkIIRedfishConfigHandler.h>
36 #include <Protocol/RestEx.h>
37
38 #include <jansson.h>
39
40 typedef struct {
41 char* host;
42 json_t* versions;
43 unsigned int flags;
44 char* sessionToken;
45 char* basicAuthStr;
46 //
47 // point to the <HOST> part in above "host" field, which will be put into
48 // the "Host" header of HTTP request message.
49 //
50 char* HostHeaderValue;
51 EFI_REST_EX_PROTOCOL *RestEx;
52 } redfishService;
53
54 typedef struct {
55 json_t* json;
56 redfishService* service;
57 } redfishPayload;
58
59 #define REDFISH_AUTH_BASIC 0
60 #define REDFISH_AUTH_BEARER_TOKEN 1
61 #define REDFISH_AUTH_SESSION 2
62
63 #define REDFISH_HTTP_RESPONSE_TIMEOUT 5000 /// 5 seconds in uints of millisecond.
64
65 ///
66 /// Library class public defines
67 ///
68 #define HTTP_FLAG L"http://"
69 #define HTTPS_FLAG L"https://"
70
71 ///
72 /// The redfish first URL should be "/redfish/v1/", while we use "/redfish/v1" here without "/"
73 /// in the end is to avoid the 301 Perment redirect response from Redfish profile simulator.
74 ///
75 #define REDFISH_FIRST_URL L"/redfish/v1"
76
77 typedef struct {
78 unsigned int authType;
79 union {
80 struct {
81 char* username;
82 char* password;
83 } userPass;
84 struct {
85 char* token;
86 } authToken;
87 } authCodes;
88 } enumeratorAuthentication;
89
90 //Values for flags
91 #define REDFISH_FLAG_SERVICE_NO_VERSION_DOC 0x00000001 //The Redfish Service lacks the version document (in violation of the Redfish spec)
92 redfishService* createServiceEnumerator(REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo, const char* rootUri, enumeratorAuthentication* auth, unsigned int flags);
93 json_t* getUriFromService(redfishService* service, const char* uri, EFI_HTTP_STATUS_CODE** StatusCode);
94 json_t* patchUriFromService(redfishService* service, const char* uri, const char* content, EFI_HTTP_STATUS_CODE** StatusCode);
95 json_t* postUriFromService(redfishService* service, const char* uri, const char* content, size_t contentLength, const char* contentType, EFI_HTTP_STATUS_CODE** StatusCode);
96 json_t* deleteUriFromService(redfishService* service, const char* uri, EFI_HTTP_STATUS_CODE** StatusCode);
97 redfishPayload* getRedfishServiceRoot(redfishService* service, const char* version, EFI_HTTP_STATUS_CODE** StatusCode);
98 redfishPayload* getPayloadByPath(redfishService* service, const char* path, EFI_HTTP_STATUS_CODE** StatusCode);
99 void cleanupServiceEnumerator(redfishService* service);
100
101 #endif