Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "update_engine/omaha_request_params.h" |
| 6 | |
| 7 | #include <errno.h> |
| 8 | #include <fcntl.h> |
| 9 | #include <sys/utsname.h> |
| 10 | |
| 11 | #include <map> |
| 12 | #include <string> |
| 13 | |
| 14 | #include "base/string_util.h" |
| 15 | #include "update_engine/simple_key_value_store.h" |
| 16 | #include "update_engine/utils.h" |
| 17 | |
| 18 | using std::map; |
| 19 | using std::string; |
| 20 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 21 | namespace chromeos_update_engine { |
| 22 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 23 | const char* const OmahaRequestParams::kAppId( |
| 24 | "{87efface-864d-49a5-9bb3-4b050a7c227a}"); |
| 25 | const char* const OmahaRequestParams::kOsPlatform("Chrome OS"); |
| 26 | const char* const OmahaRequestParams::kOsVersion("Indy"); |
| 27 | const char* const OmahaRequestParams::kUpdateUrl( |
| 28 | "https://tools.google.com/service/update2"); |
| 29 | |
| 30 | bool OmahaRequestDeviceParams::Init(const std::string& in_app_version, |
| 31 | const std::string& in_update_url) { |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 32 | os_platform = OmahaRequestParams::kOsPlatform; |
| 33 | os_version = OmahaRequestParams::kOsVersion; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 34 | app_version = in_app_version.empty() ? |
| 35 | GetLsbValue("CHROMEOS_RELEASE_VERSION", "") : in_app_version; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 36 | os_sp = app_version + "_" + GetMachineType(); |
| 37 | os_board = GetLsbValue("CHROMEOS_RELEASE_BOARD", ""); |
| 38 | app_id = OmahaRequestParams::kAppId; |
| 39 | app_lang = "en-US"; |
| 40 | app_track = GetLsbValue("CHROMEOS_RELEASE_TRACK", ""); |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 41 | struct stat stbuf; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 42 | |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 43 | // Deltas are only okay if the /.nodelta file does not exist. |
| 44 | // If we don't know (i.e. stat() returns some unexpected error), |
| 45 | // then err on the side of caution and say deltas are not okay |
| 46 | delta_okay = (stat((root_ + "/.nodelta").c_str(), &stbuf) < 0) && |
| 47 | (errno == ENOENT); |
| 48 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 49 | update_url = in_update_url.empty() ? |
| 50 | GetLsbValue("CHROMEOS_AUSERVER", OmahaRequestParams::kUpdateUrl) : |
| 51 | in_update_url; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 52 | return true; |
| 53 | } |
| 54 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 55 | string OmahaRequestDeviceParams::GetLsbValue( |
| 56 | const string& key, const string& default_value) const { |
| 57 | string files[] = {string(utils::kStatefulPartition) + "/etc/lsb-release", |
| 58 | "/etc/lsb-release"}; |
| 59 | for (unsigned int i = 0; i < arraysize(files); ++i) { |
| 60 | // TODO(adlr): make sure files checked are owned as root (and all |
| 61 | // their parents are recursively, too). |
| 62 | string file_data; |
| 63 | if (!utils::ReadFileToString(root_ + files[i], &file_data)) |
| 64 | continue; |
| 65 | |
| 66 | map<string, string> data = simple_key_value_store::ParseString(file_data); |
| 67 | if (utils::MapContainsKey(data, key)) |
| 68 | return data[key]; |
| 69 | } |
| 70 | // not found |
| 71 | return default_value; |
| 72 | } |
| 73 | |
| 74 | string OmahaRequestDeviceParams::GetMachineType() const { |
| 75 | struct utsname buf; |
| 76 | string ret; |
| 77 | if (uname(&buf) == 0) |
| 78 | ret = buf.machine; |
| 79 | return ret; |
| 80 | } |
| 81 | |
| 82 | } // namespace chromeos_update_engine |