Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2019 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_request_builder_xml.h" |
| 18 | |
| 19 | #include <inttypes.h> |
| 20 | |
| 21 | #include <string> |
| 22 | |
Jae Hoon Kim | 6ada591 | 2019-06-14 10:11:34 -0700 | [diff] [blame] | 23 | #include <base/guid.h> |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 24 | #include <base/logging.h> |
| 25 | #include <base/strings/string_number_conversions.h> |
| 26 | #include <base/strings/string_util.h> |
| 27 | #include <base/strings/stringprintf.h> |
| 28 | #include <base/time/time.h> |
| 29 | |
| 30 | #include "update_engine/common/constants.h" |
| 31 | #include "update_engine/common/prefs_interface.h" |
| 32 | #include "update_engine/common/utils.h" |
| 33 | #include "update_engine/omaha_request_params.h" |
| 34 | |
| 35 | using std::string; |
| 36 | |
| 37 | namespace chromeos_update_engine { |
| 38 | |
| 39 | const int kNeverPinged = -1; |
| 40 | |
| 41 | bool XmlEncode(const string& input, string* output) { |
| 42 | if (std::find_if(input.begin(), input.end(), [](const char c) { |
| 43 | return c & 0x80; |
| 44 | }) != input.end()) { |
| 45 | LOG(WARNING) << "Invalid ASCII-7 string passed to the XML encoder:"; |
| 46 | utils::HexDumpString(input); |
| 47 | return false; |
| 48 | } |
| 49 | output->clear(); |
| 50 | // We need at least input.size() space in the output, but the code below will |
| 51 | // handle it if we need more. |
| 52 | output->reserve(input.size()); |
| 53 | for (char c : input) { |
| 54 | switch (c) { |
| 55 | case '\"': |
| 56 | output->append("""); |
| 57 | break; |
| 58 | case '\'': |
| 59 | output->append("'"); |
| 60 | break; |
| 61 | case '&': |
| 62 | output->append("&"); |
| 63 | break; |
| 64 | case '<': |
| 65 | output->append("<"); |
| 66 | break; |
| 67 | case '>': |
| 68 | output->append(">"); |
| 69 | break; |
| 70 | default: |
| 71 | output->push_back(c); |
| 72 | } |
| 73 | } |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | string XmlEncodeWithDefault(const string& input, const string& default_value) { |
| 78 | string output; |
| 79 | if (XmlEncode(input, &output)) |
| 80 | return output; |
| 81 | return default_value; |
| 82 | } |
| 83 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 84 | string OmahaRequestBuilderXml::GetPing() const { |
| 85 | // Returns an XML ping element attribute assignment with attribute |
| 86 | // |name| and value |ping_days| if |ping_days| has a value that needs |
| 87 | // to be sent, or an empty string otherwise. |
| 88 | auto GetPingAttribute = [](const char* name, int ping_days) -> string { |
| 89 | if (ping_days > 0 || ping_days == kNeverPinged) |
| 90 | return base::StringPrintf(" %s=\"%d\"", name, ping_days); |
| 91 | return ""; |
| 92 | }; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 93 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 94 | string ping_active = GetPingAttribute("a", ping_active_days_); |
| 95 | string ping_roll_call = GetPingAttribute("r", ping_roll_call_days_); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 96 | if (!ping_active.empty() || !ping_roll_call.empty()) { |
| 97 | return base::StringPrintf(" <ping active=\"1\"%s%s></ping>\n", |
| 98 | ping_active.c_str(), |
| 99 | ping_roll_call.c_str()); |
| 100 | } |
| 101 | return ""; |
| 102 | } |
| 103 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 104 | string OmahaRequestBuilderXml::GetAppBody(bool skip_updatecheck) const { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 105 | string app_body; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 106 | if (event_ == nullptr) { |
| 107 | if (include_ping_) |
| 108 | app_body = GetPing(); |
| 109 | if (!ping_only_) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 110 | if (!skip_updatecheck) { |
| 111 | app_body += " <updatecheck"; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 112 | if (!params_->target_version_prefix().empty()) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 113 | app_body += base::StringPrintf( |
| 114 | " targetversionprefix=\"%s\"", |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 115 | XmlEncodeWithDefault(params_->target_version_prefix()).c_str()); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 116 | // Rollback requires target_version_prefix set. |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 117 | if (params_->rollback_allowed()) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 118 | app_body += " rollback_allowed=\"true\""; |
| 119 | } |
| 120 | } |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 121 | app_body += "></updatecheck>\n"; |
| 122 | } |
| 123 | |
| 124 | // If this is the first update check after a reboot following a previous |
| 125 | // update, generate an event containing the previous version number. If |
| 126 | // the previous version preference file doesn't exist the event is still |
| 127 | // generated with a previous version of 0.0.0.0 -- this is relevant for |
| 128 | // older clients or new installs. The previous version event is not sent |
| 129 | // for ping-only requests because they come before the client has |
| 130 | // rebooted. The previous version event is also not sent if it was already |
| 131 | // sent for this new version with a previous updatecheck. |
| 132 | string prev_version; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 133 | if (!prefs_->GetString(kPrefsPreviousVersion, &prev_version)) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 134 | prev_version = "0.0.0.0"; |
| 135 | } |
| 136 | // We only store a non-empty previous version value after a successful |
| 137 | // update in the previous boot. After reporting it back to the server, |
| 138 | // we clear the previous version value so it doesn't get reported again. |
| 139 | if (!prev_version.empty()) { |
| 140 | app_body += base::StringPrintf( |
| 141 | " <event eventtype=\"%d\" eventresult=\"%d\" " |
| 142 | "previousversion=\"%s\"></event>\n", |
| 143 | OmahaEvent::kTypeRebootedAfterUpdate, |
| 144 | OmahaEvent::kResultSuccess, |
| 145 | XmlEncodeWithDefault(prev_version, "0.0.0.0").c_str()); |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 146 | LOG_IF(WARNING, !prefs_->SetString(kPrefsPreviousVersion, "")) |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 147 | << "Unable to reset the previous version."; |
| 148 | } |
| 149 | } |
| 150 | } else { |
| 151 | // The error code is an optional attribute so append it only if the result |
| 152 | // is not success. |
| 153 | string error_code; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 154 | if (event_->result != OmahaEvent::kResultSuccess) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 155 | error_code = base::StringPrintf(" errorcode=\"%d\"", |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 156 | static_cast<int>(event_->error_code)); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 157 | } |
| 158 | app_body = base::StringPrintf( |
| 159 | " <event eventtype=\"%d\" eventresult=\"%d\"%s></event>\n", |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 160 | event_->type, |
| 161 | event_->result, |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 162 | error_code.c_str()); |
| 163 | } |
| 164 | |
| 165 | return app_body; |
| 166 | } |
| 167 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 168 | string OmahaRequestBuilderXml::GetCohortArg(const string arg_name, |
Askar Aitzhan | 18fff84 | 2019-06-21 23:24:37 +0200 | [diff] [blame] | 169 | const string prefs_key, |
| 170 | const string override_value) const { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 171 | string cohort_value; |
Askar Aitzhan | 18fff84 | 2019-06-21 23:24:37 +0200 | [diff] [blame] | 172 | if (!override_value.empty()) { |
| 173 | // |override_value| take precedence over pref value. |
| 174 | cohort_value = override_value; |
| 175 | } else { |
| 176 | // There's nothing wrong with not having a given cohort setting, so we check |
| 177 | // existence first to avoid the warning log message. |
| 178 | if (!prefs_->Exists(prefs_key)) |
| 179 | return ""; |
| 180 | if (!prefs_->GetString(prefs_key, &cohort_value) || cohort_value.empty()) |
| 181 | return ""; |
| 182 | } |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 183 | // This is a sanity check to avoid sending a huge XML file back to Ohama due |
| 184 | // to a compromised stateful partition making the update check fail in low |
| 185 | // network environments envent after a reboot. |
| 186 | if (cohort_value.size() > 1024) { |
| 187 | LOG(WARNING) << "The omaha cohort setting " << arg_name |
| 188 | << " has a too big value, which must be an error or an " |
| 189 | "attacker trying to inhibit updates."; |
| 190 | return ""; |
| 191 | } |
| 192 | |
| 193 | string escaped_xml_value; |
| 194 | if (!XmlEncode(cohort_value, &escaped_xml_value)) { |
| 195 | LOG(WARNING) << "The omaha cohort setting " << arg_name |
| 196 | << " is ASCII-7 invalid, ignoring it."; |
| 197 | return ""; |
| 198 | } |
| 199 | |
| 200 | return base::StringPrintf( |
| 201 | "%s=\"%s\" ", arg_name.c_str(), escaped_xml_value.c_str()); |
| 202 | } |
| 203 | |
| 204 | bool IsValidComponentID(const string& id) { |
| 205 | for (char c : id) { |
| 206 | if (!isalnum(c) && c != '-' && c != '_' && c != '.') |
| 207 | return false; |
| 208 | } |
| 209 | return true; |
| 210 | } |
| 211 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 212 | string OmahaRequestBuilderXml::GetApp(const OmahaAppData& app_data) const { |
| 213 | string app_body = GetAppBody(app_data.skip_update); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 214 | string app_versions; |
| 215 | |
| 216 | // If we are downgrading to a more stable channel and we are allowed to do |
| 217 | // powerwash, then pass 0.0.0.0 as the version. This is needed to get the |
| 218 | // highest-versioned payload on the destination channel. |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 219 | if (params_->ShouldPowerwash()) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 220 | LOG(INFO) << "Passing OS version as 0.0.0.0 as we are set to powerwash " |
| 221 | << "on downgrading to the version in the more stable channel"; |
| 222 | app_versions = "version=\"0.0.0.0\" from_version=\"" + |
| 223 | XmlEncodeWithDefault(app_data.version, "0.0.0.0") + "\" "; |
| 224 | } else { |
| 225 | app_versions = "version=\"" + |
| 226 | XmlEncodeWithDefault(app_data.version, "0.0.0.0") + "\" "; |
| 227 | } |
| 228 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 229 | string download_channel = params_->download_channel(); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 230 | string app_channels = |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 231 | "track=\"" + XmlEncodeWithDefault(download_channel) + "\" "; |
| 232 | if (params_->current_channel() != download_channel) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 233 | app_channels += "from_track=\"" + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 234 | XmlEncodeWithDefault(params_->current_channel()) + "\" "; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 237 | string delta_okay_str = params_->delta_okay() ? "true" : "false"; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 238 | |
| 239 | // If install_date_days is not set (e.g. its value is -1 ), don't |
| 240 | // include the attribute. |
| 241 | string install_date_in_days_str = ""; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 242 | if (install_date_in_days_ >= 0) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 243 | install_date_in_days_str = |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 244 | base::StringPrintf("installdate=\"%d\" ", install_date_in_days_); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | string app_cohort_args; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 248 | app_cohort_args += GetCohortArg("cohort", kPrefsOmahaCohort); |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 249 | app_cohort_args += GetCohortArg("cohortname", kPrefsOmahaCohortName); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 250 | |
Askar Aitzhan | 18fff84 | 2019-06-21 23:24:37 +0200 | [diff] [blame] | 251 | // Policy provided value overrides pref. |
| 252 | string autoupdate_token = params_->autoupdate_token(); |
| 253 | app_cohort_args += GetCohortArg("cohorthint", |
| 254 | kPrefsOmahaCohortHint, |
| 255 | autoupdate_token /* override_value */); |
| 256 | |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 257 | string fingerprint_arg; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 258 | if (!params_->os_build_fingerprint().empty()) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 259 | fingerprint_arg = "fingerprint=\"" + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 260 | XmlEncodeWithDefault(params_->os_build_fingerprint()) + |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 261 | "\" "; |
| 262 | } |
| 263 | |
| 264 | string buildtype_arg; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 265 | if (!params_->os_build_type().empty()) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 266 | buildtype_arg = "os_build_type=\"" + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 267 | XmlEncodeWithDefault(params_->os_build_type()) + "\" "; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | string product_components_args; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 271 | if (!params_->ShouldPowerwash() && !app_data.product_components.empty()) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 272 | brillo::KeyValueStore store; |
| 273 | if (store.LoadFromString(app_data.product_components)) { |
| 274 | for (const string& key : store.GetKeys()) { |
| 275 | if (!IsValidComponentID(key)) { |
| 276 | LOG(ERROR) << "Invalid component id: " << key; |
| 277 | continue; |
| 278 | } |
| 279 | string version; |
| 280 | if (!store.GetString(key, &version)) { |
| 281 | LOG(ERROR) << "Failed to get version for " << key |
| 282 | << " in product_components."; |
| 283 | continue; |
| 284 | } |
| 285 | product_components_args += |
| 286 | base::StringPrintf("_%s.version=\"%s\" ", |
| 287 | key.c_str(), |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 288 | XmlEncodeWithDefault(version).c_str()); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 289 | } |
| 290 | } else { |
| 291 | LOG(ERROR) << "Failed to parse product_components:\n" |
| 292 | << app_data.product_components; |
| 293 | } |
| 294 | } |
| 295 | |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 296 | string requisition_arg; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 297 | if (!params_->device_requisition().empty()) { |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 298 | requisition_arg = "requisition=\"" + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 299 | XmlEncodeWithDefault(params_->device_requisition()) + |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 300 | "\" "; |
| 301 | } |
| 302 | |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 303 | // clang-format off |
| 304 | string app_xml = " <app " |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 305 | "appid=\"" + XmlEncodeWithDefault(app_data.id) + "\" " + |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 306 | app_cohort_args + |
| 307 | app_versions + |
| 308 | app_channels + |
| 309 | product_components_args + |
| 310 | fingerprint_arg + |
| 311 | buildtype_arg + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 312 | "board=\"" + XmlEncodeWithDefault(params_->os_board()) + "\" " + |
| 313 | "hardware_class=\"" + XmlEncodeWithDefault(params_->hwid()) + "\" " + |
Jae Hoon Kim | 37d1537 | 2020-01-08 18:11:26 -0800 | [diff] [blame^] | 314 | "delta_okay=\"" + delta_okay_str + "\" " + |
| 315 | install_date_in_days_str + |
| 316 | |
| 317 | // DLC excluded for installs and updates. |
| 318 | (app_data.is_dlc ? "" : |
| 319 | "lang=\"" + XmlEncodeWithDefault(params_->app_lang(), "en-US") + "\" " + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 320 | "fw_version=\"" + XmlEncodeWithDefault(params_->fw_version()) + "\" " + |
| 321 | "ec_version=\"" + XmlEncodeWithDefault(params_->ec_version()) + "\" " + |
Jae Hoon Kim | 37d1537 | 2020-01-08 18:11:26 -0800 | [diff] [blame^] | 322 | requisition_arg) + |
| 323 | |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 324 | ">\n" + |
| 325 | app_body + |
| 326 | " </app>\n"; |
| 327 | // clang-format on |
| 328 | return app_xml; |
| 329 | } |
| 330 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 331 | string OmahaRequestBuilderXml::GetOs() const { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 332 | string os_xml = |
| 333 | " <os " |
| 334 | "version=\"" + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 335 | XmlEncodeWithDefault(params_->os_version()) + "\" " + "platform=\"" + |
| 336 | XmlEncodeWithDefault(params_->os_platform()) + "\" " + "sp=\"" + |
| 337 | XmlEncodeWithDefault(params_->os_sp()) + |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 338 | "\">" |
| 339 | "</os>\n"; |
| 340 | return os_xml; |
| 341 | } |
| 342 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 343 | string OmahaRequestBuilderXml::GetRequest() const { |
| 344 | string os_xml = GetOs(); |
| 345 | string app_xml = GetApps(); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 346 | |
| 347 | string request_xml = base::StringPrintf( |
| 348 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 349 | "<request requestid=\"%s\" sessionid=\"%s\"" |
Jae Hoon Kim | 6ada591 | 2019-06-14 10:11:34 -0700 | [diff] [blame] | 350 | " protocol=\"3.0\" updater=\"%s\" updaterversion=\"%s\"" |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 351 | " installsource=\"%s\" ismachine=\"1\">\n%s%s</request>\n", |
Jae Hoon Kim | 6ada591 | 2019-06-14 10:11:34 -0700 | [diff] [blame] | 352 | base::GenerateGUID().c_str() /* requestid */, |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 353 | session_id_.c_str(), |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 354 | constants::kOmahaUpdaterID, |
| 355 | kOmahaUpdaterVersion, |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 356 | params_->interactive() ? "ondemandupdate" : "scheduler", |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 357 | os_xml.c_str(), |
| 358 | app_xml.c_str()); |
| 359 | |
| 360 | return request_xml; |
| 361 | } |
| 362 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 363 | string OmahaRequestBuilderXml::GetApps() const { |
| 364 | string app_xml = ""; |
| 365 | OmahaAppData product_app = { |
| 366 | .id = params_->GetAppId(), |
| 367 | .version = params_->app_version(), |
| 368 | .product_components = params_->product_components(), |
| 369 | // Skips updatecheck for platform app in case of an install operation. |
Jae Hoon Kim | 37d1537 | 2020-01-08 18:11:26 -0800 | [diff] [blame^] | 370 | .skip_update = params_->is_install(), |
| 371 | .is_dlc = false}; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 372 | app_xml += GetApp(product_app); |
| 373 | if (!params_->system_app_id().empty()) { |
| 374 | OmahaAppData system_app = {.id = params_->system_app_id(), |
| 375 | .version = params_->system_version(), |
Jae Hoon Kim | 37d1537 | 2020-01-08 18:11:26 -0800 | [diff] [blame^] | 376 | .skip_update = false, |
| 377 | .is_dlc = false}; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 378 | app_xml += GetApp(system_app); |
| 379 | } |
| 380 | // Create APP ID according to |dlc_module_id| (sticking the current AppID to |
| 381 | // the DLC module ID with an underscode). |
| 382 | for (const auto& dlc_module_id : params_->dlc_module_ids()) { |
| 383 | OmahaAppData dlc_module_app = { |
| 384 | .id = params_->GetAppId() + "_" + dlc_module_id, |
| 385 | .version = params_->app_version(), |
Jae Hoon Kim | 37d1537 | 2020-01-08 18:11:26 -0800 | [diff] [blame^] | 386 | .skip_update = false, |
| 387 | .is_dlc = true}; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 388 | app_xml += GetApp(dlc_module_app); |
| 389 | } |
| 390 | return app_xml; |
| 391 | } |
| 392 | |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 393 | } // namespace chromeos_update_engine |