JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 1 | #pragma once |
2 | #include "logging.hpp" | ||||
3 | |||||
Ed Tanous | 601c71a | 2021-09-08 16:40:12 -0700 | [diff] [blame] | 4 | #include <boost/beast/http/fields.hpp> |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 5 | #include <boost/container/flat_map.hpp> |
Ed Tanous | a716aa7 | 2023-08-01 11:35:53 -0700 | [diff] [blame] | 6 | #include <boost/url/parse.hpp> |
Ed Tanous | 4a7fbef | 2024-04-06 16:03:49 -0700 | [diff] [blame] | 7 | #include <boost/url/url.hpp> |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 8 | #include <nlohmann/json.hpp> |
9 | |||||
Myung Bae | 5064a25 | 2024-10-04 09:34:25 -0700 | [diff] [blame] | 10 | #include <limits> |
Myung Bae | 56ba386 | 2024-10-10 17:09:37 -0700 | [diff] [blame] | 11 | #include <memory> |
12 | #include <string> | ||||
13 | #include <vector> | ||||
14 | |||||
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 15 | namespace persistent_data |
16 | { | ||||
17 | |||||
18 | struct UserSubscription | ||||
19 | { | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 20 | // Represents a Redfish EventDestination instance |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 21 | std::string id; |
Ed Tanous | a716aa7 | 2023-08-01 11:35:53 -0700 | [diff] [blame] | 22 | boost::urls::url destinationUrl; |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 23 | std::string protocol; |
Ed Tanous | 19bb362 | 2024-07-05 10:07:40 -0500 | [diff] [blame] | 24 | bool verifyCertificate = true; |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 25 | std::string retryPolicy; |
Myung Bae | 5064a25 | 2024-10-04 09:34:25 -0700 | [diff] [blame] | 26 | bool sendHeartbeat = false; |
27 | // This value of hbIntervalMinutes is just a reasonable default value and | ||||
28 | // most clients will update it if sendHeartbeat is turned on | ||||
29 | uint64_t hbIntervalMinutes = 10; | ||||
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 30 | std::string customText; |
31 | std::string eventFormatType; | ||||
32 | std::string subscriptionType; | ||||
33 | std::vector<std::string> registryMsgIds; | ||||
34 | std::vector<std::string> registryPrefixes; | ||||
35 | std::vector<std::string> resourceTypes; | ||||
Ed Tanous | 601c71a | 2021-09-08 16:40:12 -0700 | [diff] [blame] | 36 | boost::beast::http::fields httpHeaders; |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 37 | std::vector<std::string> metricReportDefinitions; |
Ed Tanous | a14c911 | 2024-09-04 10:46:47 -0700 | [diff] [blame] | 38 | std::vector<std::string> originResources; |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 39 | |
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 40 | static std::optional<UserSubscription> fromJson( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 41 | const nlohmann::json::object_t& j, const bool loadFromOldConfig = false) |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 42 | { |
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 43 | UserSubscription subvalue; |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 44 | for (const auto& element : j) |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 45 | { |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 46 | if (element.first == "Id") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 47 | { |
48 | const std::string* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 49 | element.second.get_ptr<const std::string*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 50 | if (value == nullptr) |
51 | { | ||||
52 | continue; | ||||
53 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 54 | subvalue.id = *value; |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 55 | } |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 56 | else if (element.first == "Destination") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 57 | { |
58 | const std::string* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 59 | element.second.get_ptr<const std::string*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 60 | if (value == nullptr) |
61 | { | ||||
62 | continue; | ||||
63 | } | ||||
Ed Tanous | 6fd2955 | 2023-10-04 09:40:14 -0700 | [diff] [blame] | 64 | boost::system::result<boost::urls::url> url = |
Ed Tanous | a716aa7 | 2023-08-01 11:35:53 -0700 | [diff] [blame] | 65 | boost::urls::parse_absolute_uri(*value); |
66 | if (!url) | ||||
67 | { | ||||
68 | continue; | ||||
69 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 70 | subvalue.destinationUrl = std::move(*url); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 71 | } |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 72 | else if (element.first == "Protocol") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 73 | { |
74 | const std::string* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 75 | element.second.get_ptr<const std::string*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 76 | if (value == nullptr) |
77 | { | ||||
78 | continue; | ||||
79 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 80 | subvalue.protocol = *value; |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 81 | } |
Ed Tanous | 19bb362 | 2024-07-05 10:07:40 -0500 | [diff] [blame] | 82 | else if (element.first == "VerifyCertificate") |
83 | { | ||||
84 | const bool* value = element.second.get_ptr<const bool*>(); | ||||
85 | if (value == nullptr) | ||||
86 | { | ||||
87 | continue; | ||||
88 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 89 | subvalue.verifyCertificate = *value; |
Ed Tanous | 19bb362 | 2024-07-05 10:07:40 -0500 | [diff] [blame] | 90 | } |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 91 | else if (element.first == "DeliveryRetryPolicy") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 92 | { |
93 | const std::string* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 94 | element.second.get_ptr<const std::string*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 95 | if (value == nullptr) |
96 | { | ||||
97 | continue; | ||||
98 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 99 | subvalue.retryPolicy = *value; |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 100 | } |
Myung Bae | 5064a25 | 2024-10-04 09:34:25 -0700 | [diff] [blame] | 101 | else if (element.first == "SendHeartbeat") |
102 | { | ||||
103 | const bool* value = element.second.get_ptr<const bool*>(); | ||||
104 | if (value == nullptr) | ||||
105 | { | ||||
106 | continue; | ||||
107 | } | ||||
108 | subvalue.sendHeartbeat = *value; | ||||
109 | } | ||||
110 | else if (element.first == "HeartbeatIntervalMinutes") | ||||
111 | { | ||||
112 | const uint64_t* value = | ||||
113 | element.second.get_ptr<const uint64_t*>(); | ||||
114 | if (value == nullptr || *value < 1 || *value > 65535) | ||||
115 | { | ||||
116 | continue; | ||||
117 | } | ||||
118 | subvalue.hbIntervalMinutes = *value; | ||||
119 | } | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 120 | else if (element.first == "Context") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 121 | { |
122 | const std::string* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 123 | element.second.get_ptr<const std::string*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 124 | if (value == nullptr) |
125 | { | ||||
126 | continue; | ||||
127 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 128 | subvalue.customText = *value; |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 129 | } |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 130 | else if (element.first == "EventFormatType") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 131 | { |
132 | const std::string* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 133 | element.second.get_ptr<const std::string*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 134 | if (value == nullptr) |
135 | { | ||||
136 | continue; | ||||
137 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 138 | subvalue.eventFormatType = *value; |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 139 | } |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 140 | else if (element.first == "SubscriptionType") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 141 | { |
142 | const std::string* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 143 | element.second.get_ptr<const std::string*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 144 | if (value == nullptr) |
145 | { | ||||
146 | continue; | ||||
147 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 148 | subvalue.subscriptionType = *value; |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 149 | } |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 150 | else if (element.first == "MessageIds") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 151 | { |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 152 | const nlohmann::json::array_t* obj = |
153 | element.second.get_ptr<const nlohmann::json::array_t*>(); | ||||
154 | if (obj == nullptr) | ||||
155 | { | ||||
156 | continue; | ||||
157 | } | ||||
158 | for (const auto& val : *obj) | ||||
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 159 | { |
160 | const std::string* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 161 | val.get_ptr<const std::string*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 162 | if (value == nullptr) |
163 | { | ||||
164 | continue; | ||||
165 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 166 | subvalue.registryMsgIds.emplace_back(*value); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 167 | } |
168 | } | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 169 | else if (element.first == "RegistryPrefixes") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 170 | { |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 171 | const nlohmann::json::array_t* obj = |
172 | element.second.get_ptr<const nlohmann::json::array_t*>(); | ||||
173 | if (obj == nullptr) | ||||
174 | { | ||||
175 | continue; | ||||
176 | } | ||||
177 | for (const auto& val : *obj) | ||||
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 178 | { |
179 | const std::string* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 180 | val.get_ptr<const std::string*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 181 | if (value == nullptr) |
182 | { | ||||
183 | continue; | ||||
184 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 185 | subvalue.registryPrefixes.emplace_back(*value); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 186 | } |
187 | } | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 188 | else if (element.first == "ResourceTypes") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 189 | { |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 190 | const nlohmann::json::array_t* obj = |
191 | element.second.get_ptr<const nlohmann::json::array_t*>(); | ||||
192 | if (obj == nullptr) | ||||
193 | { | ||||
194 | continue; | ||||
195 | } | ||||
196 | for (const auto& val : *obj) | ||||
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 197 | { |
198 | const std::string* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 199 | val.get_ptr<const std::string*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 200 | if (value == nullptr) |
201 | { | ||||
202 | continue; | ||||
203 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 204 | subvalue.resourceTypes.emplace_back(*value); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 205 | } |
206 | } | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 207 | else if (element.first == "HttpHeaders") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 208 | { |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 209 | const nlohmann::json::object_t* obj = |
210 | element.second.get_ptr<const nlohmann::json::object_t*>(); | ||||
211 | if (obj == nullptr) | ||||
212 | { | ||||
213 | continue; | ||||
214 | } | ||||
215 | for (const auto& val : *obj) | ||||
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 216 | { |
Ed Tanous | 601c71a | 2021-09-08 16:40:12 -0700 | [diff] [blame] | 217 | const std::string* value = |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 218 | val.second.get_ptr<const std::string*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 219 | if (value == nullptr) |
220 | { | ||||
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 221 | BMCWEB_LOG_ERROR("Failed to parse value for key{}", |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 222 | val.first); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 223 | continue; |
224 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 225 | subvalue.httpHeaders.set(val.first, *value); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 226 | } |
227 | } | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 228 | else if (element.first == "MetricReportDefinitions") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 229 | { |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 230 | const nlohmann::json::array_t* obj = |
231 | element.second.get_ptr<const nlohmann::json::array_t*>(); | ||||
232 | if (obj == nullptr) | ||||
233 | { | ||||
234 | continue; | ||||
235 | } | ||||
236 | for (const auto& val : *obj) | ||||
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 237 | { |
238 | const std::string* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 239 | val.get_ptr<const std::string*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 240 | if (value == nullptr) |
241 | { | ||||
242 | continue; | ||||
243 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 244 | subvalue.metricReportDefinitions.emplace_back(*value); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 245 | } |
246 | } | ||||
Ed Tanous | a14c911 | 2024-09-04 10:46:47 -0700 | [diff] [blame] | 247 | else if (element.first == "OriginResources") |
248 | { | ||||
249 | const nlohmann::json::array_t* obj = | ||||
250 | element.second.get_ptr<const nlohmann::json::array_t*>(); | ||||
251 | if (obj == nullptr) | ||||
252 | { | ||||
253 | continue; | ||||
254 | } | ||||
255 | for (const auto& val : *obj) | ||||
256 | { | ||||
257 | const std::string* value = | ||||
258 | val.get_ptr<const std::string*>(); | ||||
259 | if (value == nullptr) | ||||
260 | { | ||||
261 | continue; | ||||
262 | } | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 263 | subvalue.originResources.emplace_back(*value); |
Ed Tanous | a14c911 | 2024-09-04 10:46:47 -0700 | [diff] [blame] | 264 | } |
265 | } | ||||
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 266 | else |
267 | { | ||||
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 268 | BMCWEB_LOG_ERROR( |
269 | "Got unexpected property reading persistent file: {}", | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 270 | element.first); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 271 | continue; |
272 | } | ||||
273 | } | ||||
274 | |||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 275 | if ((subvalue.id.empty() && !loadFromOldConfig) || |
276 | subvalue.destinationUrl.empty() || subvalue.protocol.empty() || | ||||
277 | subvalue.retryPolicy.empty() || subvalue.eventFormatType.empty() || | ||||
278 | subvalue.subscriptionType.empty()) | ||||
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 279 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 280 | BMCWEB_LOG_ERROR("Subscription missing required field " |
281 | "information, refusing to restore"); | ||||
Ed Tanous | 4b712a2 | 2023-08-02 12:56:52 -0700 | [diff] [blame] | 282 | return std::nullopt; |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 283 | } |
284 | |||||
285 | return subvalue; | ||||
286 | } | ||||
287 | }; | ||||
288 | |||||
289 | struct EventServiceConfig | ||||
290 | { | ||||
291 | bool enabled = true; | ||||
292 | uint32_t retryAttempts = 3; | ||||
293 | uint32_t retryTimeoutInterval = 30; | ||||
294 | |||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 295 | void fromJson(const nlohmann::json::object_t& j) |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 296 | { |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 297 | for (const auto& element : j) |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 298 | { |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 299 | if (element.first == "ServiceEnabled") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 300 | { |
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 301 | const bool* value = element.second.get_ptr<const bool*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 302 | if (value == nullptr) |
303 | { | ||||
304 | continue; | ||||
305 | } | ||||
306 | enabled = *value; | ||||
307 | } | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 308 | else if (element.first == "DeliveryRetryAttempts") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 309 | { |
310 | const uint64_t* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 311 | element.second.get_ptr<const uint64_t*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 312 | if ((value == nullptr) || |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 313 | (*value > std::numeric_limits<uint32_t>::max())) |
314 | { | ||||
315 | continue; | ||||
316 | } | ||||
317 | retryAttempts = static_cast<uint32_t>(*value); | ||||
318 | } | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 319 | else if (element.first == "DeliveryRetryIntervalSeconds") |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 320 | { |
321 | const uint64_t* value = | ||||
Ed Tanous | 0bdda66 | 2023-08-03 17:27:34 -0700 | [diff] [blame] | 322 | element.second.get_ptr<const uint64_t*>(); |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 323 | if ((value == nullptr) || |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 324 | (*value > std::numeric_limits<uint32_t>::max())) |
325 | { | ||||
326 | continue; | ||||
327 | } | ||||
328 | retryTimeoutInterval = static_cast<uint32_t>(*value); | ||||
329 | } | ||||
330 | } | ||||
331 | } | ||||
332 | }; | ||||
333 | |||||
334 | class EventServiceStore | ||||
335 | { | ||||
336 | public: | ||||
Myung Bae | 5fe4ef3 | 2024-10-19 09:56:02 -0400 | [diff] [blame] | 337 | boost::container::flat_map<std::string, std::shared_ptr<UserSubscription>> |
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 338 | subscriptionsConfigMap; |
339 | EventServiceConfig eventServiceConfig; | ||||
340 | |||||
341 | static EventServiceStore& getInstance() | ||||
342 | { | ||||
343 | static EventServiceStore eventServiceStore; | ||||
344 | return eventServiceStore; | ||||
345 | } | ||||
346 | |||||
347 | EventServiceConfig& getEventServiceConfig() | ||||
348 | { | ||||
349 | return eventServiceConfig; | ||||
350 | } | ||||
JunLin Chen | 28afb49 | 2021-02-24 17:13:29 +0800 | [diff] [blame] | 351 | }; |
352 | |||||
353 | } // namespace persistent_data |