blob: f9ec85ac02c1d58512b585621135ab47ff4b3e6e [file] [log] [blame]
Alex Deymob3fa53b2016-04-18 19:57:58 -07001//
2// Copyright (C) 2016 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#include "update_engine/omaha_utils.h"
18
19#include <base/logging.h>
Jae Hoon Kim051627a2019-09-03 12:56:32 -070020#include <base/strings/string_number_conversions.h>
Alex Deymob3fa53b2016-04-18 19:57:58 -070021
22namespace chromeos_update_engine {
23
Alex Deymob3fa53b2016-04-18 19:57:58 -070024const char kEolStatusSupported[] = "supported";
25const char kEolStatusSecurityOnly[] = "security-only";
26const char kEolStatusEol[] = "eol";
27
Jae Hoon Kim051627a2019-09-03 12:56:32 -070028const EolDate kEolDateInvalid = -9999;
Alex Deymob3fa53b2016-04-18 19:57:58 -070029
30const char* EolStatusToString(EolStatus eol_status) {
31 switch (eol_status) {
32 case EolStatus::kSupported:
33 return kEolStatusSupported;
34 case EolStatus::kSecurityOnly:
35 return kEolStatusSecurityOnly;
36 case EolStatus::kEol:
37 return kEolStatusEol;
38 }
39 // Only reached if an invalid number is casted to |EolStatus|.
40 LOG(WARNING) << "Invalid EolStatus value: " << static_cast<int>(eol_status);
41 return kEolStatusSupported;
42}
43
44EolStatus StringToEolStatus(const std::string& eol_status) {
45 if (eol_status == kEolStatusSupported || eol_status.empty())
46 return EolStatus::kSupported;
47 if (eol_status == kEolStatusSecurityOnly)
48 return EolStatus::kSecurityOnly;
49 if (eol_status == kEolStatusEol)
50 return EolStatus::kEol;
Jae Hoon Kima1f4a7d2019-09-03 18:12:33 +000051 LOG(WARNING) << "Invalid end-of-life attribute: " << eol_status;
Alex Deymob3fa53b2016-04-18 19:57:58 -070052 return EolStatus::kSupported;
53}
54
Jae Hoon Kim051627a2019-09-03 12:56:32 -070055std::string EolDateToString(EolDate eol_date) {
56#if BASE_VER < 576279
57 return base::Int64ToString(eol_date);
58#else
59 return base::NumberToString(eol_date);
60#endif
61}
62
63EolDate StringToEolDate(const std::string& eol_date) {
64 EolDate date = kEolDateInvalid;
65 if (!base::StringToInt64(eol_date, &date)) {
Jae Hoon Kim8368ee02019-10-16 15:37:39 -070066 // TODO(b/142823480): Once Omaha is passing _eol_date attribute, this log
67 // may be turned back on.
68 // LOG(WARNING) << "Invalid EOL date attribute: " << eol_date;
Jae Hoon Kim051627a2019-09-03 12:56:32 -070069 return kEolDateInvalid;
70 }
71 return date;
72}
73
Alex Deymob3fa53b2016-04-18 19:57:58 -070074} // namespace chromeos_update_engine