omaha_request_params.cc revision fbb40098314ab45efa60667ad7ccae354c4f18da
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/file_util.h" 15#include "base/string_util.h" 16#include "update_engine/simple_key_value_store.h" 17#include "update_engine/utils.h" 18 19using std::map; 20using std::string; 21 22namespace chromeos_update_engine { 23 24const char* const OmahaRequestParams::kAppId( 25 "{87efface-864d-49a5-9bb3-4b050a7c227a}"); 26const char* const OmahaRequestParams::kOsPlatform("Chrome OS"); 27const char* const OmahaRequestParams::kOsVersion("Indy"); 28const char* const OmahaRequestParams::kUpdateUrl( 29 "https://tools.google.com/service/update2"); 30 31static const char kHWIDPath[] = "/sys/devices/platform/chromeos_acpi/HWID"; 32 33bool OmahaRequestDeviceParams::Init(const std::string& in_app_version, 34 const std::string& in_update_url) { 35 os_platform = OmahaRequestParams::kOsPlatform; 36 os_version = OmahaRequestParams::kOsVersion; 37 app_version = in_app_version.empty() ? 38 GetLsbValue("CHROMEOS_RELEASE_VERSION", "") : in_app_version; 39 os_sp = app_version + "_" + GetMachineType(); 40 os_board = GetLsbValue("CHROMEOS_RELEASE_BOARD", ""); 41 app_id = OmahaRequestParams::kAppId; 42 app_lang = "en-US"; 43 app_track = GetLsbValue("CHROMEOS_RELEASE_TRACK", ""); 44 hardware_class = GetHardwareClass(); 45 struct stat stbuf; 46 47 // Deltas are only okay if the /.nodelta file does not exist. 48 // If we don't know (i.e. stat() returns some unexpected error), 49 // then err on the side of caution and say deltas are not okay 50 delta_okay = (stat((root_ + "/.nodelta").c_str(), &stbuf) < 0) && 51 (errno == ENOENT); 52 53 update_url = in_update_url.empty() ? 54 GetLsbValue("CHROMEOS_AUSERVER", OmahaRequestParams::kUpdateUrl) : 55 in_update_url; 56 return true; 57} 58 59string OmahaRequestDeviceParams::GetLsbValue( 60 const string& key, const string& default_value) const { 61 string files[] = {string(utils::kStatefulPartition) + "/etc/lsb-release", 62 "/etc/lsb-release"}; 63 for (unsigned int i = 0; i < arraysize(files); ++i) { 64 // TODO(adlr): make sure files checked are owned as root (and all 65 // their parents are recursively, too). 66 string file_data; 67 if (!utils::ReadFileToString(root_ + files[i], &file_data)) 68 continue; 69 70 map<string, string> data = simple_key_value_store::ParseString(file_data); 71 if (utils::MapContainsKey(data, key)) 72 return data[key]; 73 } 74 // not found 75 return default_value; 76} 77 78string OmahaRequestDeviceParams::GetMachineType() const { 79 struct utsname buf; 80 string ret; 81 if (uname(&buf) == 0) 82 ret = buf.machine; 83 return ret; 84} 85 86string OmahaRequestDeviceParams::GetHardwareClass() const { 87 string hwid; 88 if (!file_util::ReadFileToString(FilePath(root_ + kHWIDPath), &hwid)) { 89 LOG(ERROR) << "Unable to determine the system hardware qualification ID."; 90 return ""; 91 } 92 TrimWhitespaceASCII(hwid, TRIM_ALL, &hwid); 93 return hwid; 94} 95 96} // namespace chromeos_update_engine 97