blob: dffa5d3abeef254e3892b84e6af226804353a1bb [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 Kim893cae42019-08-16 17:13:49 -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 Kim893cae42019-08-16 17:13:49 -070028const MilestonesToEol kMilestonesToEolNone = -1;
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 Kim893cae42019-08-16 17:13:49 -070051 LOG(WARNING) << "Invalid EOL attribute: " << eol_status;
Alex Deymob3fa53b2016-04-18 19:57:58 -070052 return EolStatus::kSupported;
53}
54
Jae Hoon Kim893cae42019-08-16 17:13:49 -070055std::string MilestonesToEolToString(MilestonesToEol milestones_to_eol) {
56 return base::IntToString(milestones_to_eol);
57}
58
59MilestonesToEol StringToMilestonesToEol(const std::string& milestones_to_eol) {
60 MilestonesToEol milestone = kMilestonesToEolNone;
61 if (!base::StringToInt(milestones_to_eol, &milestone)) {
62 LOG(WARNING) << "Invalid milestones to EOL attribute: "
63 << milestones_to_eol;
64 return kMilestonesToEolNone;
65 }
66
67 return milestone;
68}
69
Alex Deymob3fa53b2016-04-18 19:57:58 -070070} // namespace chromeos_update_engine