Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 1 | // |
| 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 Kim | 893cae4 | 2019-08-16 17:13:49 -0700 | [diff] [blame] | 20 | #include <base/strings/string_number_conversions.h> |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 21 | |
| 22 | namespace chromeos_update_engine { |
| 23 | |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 24 | const char kEolStatusSupported[] = "supported"; |
| 25 | const char kEolStatusSecurityOnly[] = "security-only"; |
| 26 | const char kEolStatusEol[] = "eol"; |
| 27 | |
Jae Hoon Kim | 893cae4 | 2019-08-16 17:13:49 -0700 | [diff] [blame] | 28 | const MilestonesToEol kMilestonesToEolNone = -1; |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 29 | |
| 30 | const 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 | |
| 44 | EolStatus 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 Kim | 893cae4 | 2019-08-16 17:13:49 -0700 | [diff] [blame] | 51 | LOG(WARNING) << "Invalid EOL attribute: " << eol_status; |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 52 | return EolStatus::kSupported; |
| 53 | } |
| 54 | |
Jae Hoon Kim | 893cae4 | 2019-08-16 17:13:49 -0700 | [diff] [blame] | 55 | std::string MilestonesToEolToString(MilestonesToEol milestones_to_eol) { |
| 56 | return base::IntToString(milestones_to_eol); |
| 57 | } |
| 58 | |
| 59 | MilestonesToEol 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 Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 70 | } // namespace chromeos_update_engine |