| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "update_engine/omaha_request_action.h" | 5 #include "update_engine/omaha_request_action.h" |
| 6 | 6 |
| 7 #include <inttypes.h> | 7 #include <inttypes.h> |
| 8 | 8 |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 322 |
| 323 // Events are best effort transactions -- assume they always succeed. | 323 // Events are best effort transactions -- assume they always succeed. |
| 324 if (IsEvent()) { | 324 if (IsEvent()) { |
| 325 CHECK(!HasOutputPipe()) << "No output pipe allowed for event requests."; | 325 CHECK(!HasOutputPipe()) << "No output pipe allowed for event requests."; |
| 326 completer.set_code(kActionCodeSuccess); | 326 completer.set_code(kActionCodeSuccess); |
| 327 return; | 327 return; |
| 328 } | 328 } |
| 329 | 329 |
| 330 if (!successful) { | 330 if (!successful) { |
| 331 LOG(ERROR) << "Omaha request network transfer failed."; | 331 LOG(ERROR) << "Omaha request network transfer failed."; |
| 332 int code = GetHTTPResponseCode(); |
| 333 // Makes sure we send sane error values. |
| 334 if (code < 0 || code >= 1000) { |
| 335 code = 999; |
| 336 } |
| 337 completer.set_code(static_cast<ActionExitCode>( |
| 338 kActionCodeOmahaRequestHTTPResponseBase + code)); |
| 332 return; | 339 return; |
| 333 } | 340 } |
| 334 if (!HasOutputPipe()) { | 341 if (!HasOutputPipe()) { |
| 335 // Just set success to whether or not the http transfer succeeded, | 342 // Just set success to whether or not the http transfer succeeded, |
| 336 // which must be true at this point in the code. | 343 // which must be true at this point in the code. |
| 337 completer.set_code(kActionCodeSuccess); | 344 completer.set_code(kActionCodeSuccess); |
| 338 return; | 345 return; |
| 339 } | 346 } |
| 340 | 347 |
| 341 // parse our response and fill the fields in the output object | 348 // parse our response and fill the fields in the output object |
| 342 scoped_ptr_malloc<xmlDoc, ScopedPtrXmlDocFree> doc( | 349 scoped_ptr_malloc<xmlDoc, ScopedPtrXmlDocFree> doc( |
| 343 xmlParseMemory(&response_buffer_[0], response_buffer_.size())); | 350 xmlParseMemory(&response_buffer_[0], response_buffer_.size())); |
| 344 if (!doc.get()) { | 351 if (!doc.get()) { |
| 345 LOG(ERROR) << "Omaha response not valid XML"; | 352 LOG(ERROR) << "Omaha response not valid XML"; |
| 353 completer.set_code(response_buffer_.empty() ? |
| 354 kActionCodeOmahaRequestEmptyResponseError : |
| 355 kActionCodeOmahaRequestXMLParseError); |
| 346 return; | 356 return; |
| 347 } | 357 } |
| 348 | 358 |
| 349 // If a ping was sent, update the last ping day preferences based on | 359 // If a ping was sent, update the last ping day preferences based on |
| 350 // the server daystart response. | 360 // the server daystart response. |
| 351 if (ShouldPing(ping_active_days_) || | 361 if (ShouldPing(ping_active_days_) || |
| 352 ShouldPing(ping_roll_call_days_) || | 362 ShouldPing(ping_roll_call_days_) || |
| 353 ping_active_days_ == kPingTimeJump || | 363 ping_active_days_ == kPingTimeJump || |
| 354 ping_roll_call_days_ == kPingTimeJump) { | 364 ping_roll_call_days_ == kPingTimeJump) { |
| 355 LOG_IF(ERROR, !UpdateLastPingDays(doc.get(), prefs_)) | 365 LOG_IF(ERROR, !UpdateLastPingDays(doc.get(), prefs_)) |
| 356 << "Failed to update the last ping day preferences!"; | 366 << "Failed to update the last ping day preferences!"; |
| 357 } | 367 } |
| 358 | 368 |
| 359 static const char* kNamespace("x"); | 369 static const char* kNamespace("x"); |
| 360 static const char* kUpdatecheckNodeXpath("/x:gupdate/x:app/x:updatecheck"); | 370 static const char* kUpdatecheckNodeXpath("/x:gupdate/x:app/x:updatecheck"); |
| 361 static const char* kNsUrl("http://www.google.com/update2/response"); | 371 static const char* kNsUrl("http://www.google.com/update2/response"); |
| 362 | 372 |
| 363 scoped_ptr_malloc<xmlXPathObject, ScopedPtrXmlXPathObjectFree> | 373 scoped_ptr_malloc<xmlXPathObject, ScopedPtrXmlXPathObjectFree> |
| 364 xpath_nodeset(GetNodeSet(doc.get(), | 374 xpath_nodeset(GetNodeSet(doc.get(), |
| 365 ConstXMLStr(kUpdatecheckNodeXpath), | 375 ConstXMLStr(kUpdatecheckNodeXpath), |
| 366 ConstXMLStr(kNamespace), | 376 ConstXMLStr(kNamespace), |
| 367 ConstXMLStr(kNsUrl))); | 377 ConstXMLStr(kNsUrl))); |
| 368 if (!xpath_nodeset.get()) { | 378 if (!xpath_nodeset.get()) { |
| 379 completer.set_code(kActionCodeOmahaRequestNoUpdateCheckNode); |
| 369 return; | 380 return; |
| 370 } | 381 } |
| 371 xmlNodeSet* nodeset = xpath_nodeset->nodesetval; | 382 xmlNodeSet* nodeset = xpath_nodeset->nodesetval; |
| 372 CHECK(nodeset) << "XPath missing NodeSet"; | 383 CHECK(nodeset) << "XPath missing NodeSet"; |
| 373 CHECK_GE(nodeset->nodeNr, 1); | 384 CHECK_GE(nodeset->nodeNr, 1); |
| 374 | 385 |
| 375 xmlNode* updatecheck_node = nodeset->nodeTab[0]; | 386 xmlNode* updatecheck_node = nodeset->nodeTab[0]; |
| 376 // get status | 387 // get status |
| 377 if (!xmlHasProp(updatecheck_node, ConstXMLStr("status"))) { | 388 if (!xmlHasProp(updatecheck_node, ConstXMLStr("status"))) { |
| 378 LOG(ERROR) << "Response missing status"; | 389 LOG(ERROR) << "Response missing status"; |
| 390 completer.set_code(kActionCodeOmahaRequestNoUpdateCheckStatus); |
| 379 return; | 391 return; |
| 380 } | 392 } |
| 381 | 393 |
| 382 OmahaResponse output_object; | 394 OmahaResponse output_object; |
| 383 base::StringToInt(XmlGetProperty(updatecheck_node, "PollInterval"), | 395 base::StringToInt(XmlGetProperty(updatecheck_node, "PollInterval"), |
| 384 &output_object.poll_interval); | 396 &output_object.poll_interval); |
| 385 const string status(XmlGetProperty(updatecheck_node, "status")); | 397 const string status(XmlGetProperty(updatecheck_node, "status")); |
| 386 if (status == "noupdate") { | 398 if (status == "noupdate") { |
| 387 LOG(INFO) << "No update."; | 399 LOG(INFO) << "No update."; |
| 388 output_object.update_exists = false; | 400 output_object.update_exists = false; |
| 389 SetOutputObject(output_object); | 401 SetOutputObject(output_object); |
| 390 completer.set_code(kActionCodeSuccess); | 402 completer.set_code(kActionCodeSuccess); |
| 391 return; | 403 return; |
| 392 } | 404 } |
| 393 | 405 |
| 394 if (status != "ok") { | 406 if (status != "ok") { |
| 395 LOG(ERROR) << "Unknown status: " << status; | 407 LOG(ERROR) << "Unknown status: " << status; |
| 408 completer.set_code(kActionCodeOmahaRequestBadUpdateCheckStatus); |
| 396 return; | 409 return; |
| 397 } | 410 } |
| 398 | 411 |
| 399 // In best-effort fashion, fetch the rest of the expected attributes | 412 // In best-effort fashion, fetch the rest of the expected attributes |
| 400 // from the updatecheck node, then return the object | 413 // from the updatecheck node, then return the object |
| 401 output_object.update_exists = true; | 414 output_object.update_exists = true; |
| 402 completer.set_code(kActionCodeSuccess); | 415 completer.set_code(kActionCodeSuccess); |
| 403 | 416 |
| 404 output_object.display_version = | 417 output_object.display_version = |
| 405 XmlGetProperty(updatecheck_node, "DisplayVersion"); | 418 XmlGetProperty(updatecheck_node, "DisplayVersion"); |
| 406 output_object.codebase = XmlGetProperty(updatecheck_node, "codebase"); | 419 output_object.codebase = XmlGetProperty(updatecheck_node, "codebase"); |
| 407 output_object.more_info_url = XmlGetProperty(updatecheck_node, "MoreInfo"); | 420 output_object.more_info_url = XmlGetProperty(updatecheck_node, "MoreInfo"); |
| 408 output_object.hash = XmlGetProperty(updatecheck_node, "sha256"); | 421 output_object.hash = XmlGetProperty(updatecheck_node, "sha256"); |
| 409 output_object.size = ParseInt(XmlGetProperty(updatecheck_node, "size")); | 422 output_object.size = ParseInt(XmlGetProperty(updatecheck_node, "size")); |
| 410 output_object.needs_admin = | 423 output_object.needs_admin = |
| 411 XmlGetProperty(updatecheck_node, "needsadmin") == "true"; | 424 XmlGetProperty(updatecheck_node, "needsadmin") == "true"; |
| 412 output_object.prompt = XmlGetProperty(updatecheck_node, "Prompt") == "true"; | 425 output_object.prompt = XmlGetProperty(updatecheck_node, "Prompt") == "true"; |
| 413 output_object.is_delta = | 426 output_object.is_delta = |
| 414 XmlGetProperty(updatecheck_node, "IsDelta") == "true"; | 427 XmlGetProperty(updatecheck_node, "IsDelta") == "true"; |
| 415 output_object.deadline = XmlGetProperty(updatecheck_node, "deadline"); | 428 output_object.deadline = XmlGetProperty(updatecheck_node, "deadline"); |
| 416 SetOutputObject(output_object); | 429 SetOutputObject(output_object); |
| 417 } | 430 } |
| 418 | 431 |
| 419 }; // namespace chromeos_update_engine | 432 }; // namespace chromeos_update_engine |
| OLD | NEW |