Parse and add manifest version to the Omaha Response object.

This CL adds the version of the update we're updating to to the Omaha
response object and removes the use of DisplayVersion. DisplayVersion is
from the Omaha Protocol v1, and v2 and has never been used or relied
upon in the update engine.

Protocol is described here:
https://code.google.com/p/omaha/wiki/ServerProtocol

Manifest version should always describe the version of the application we are
updating to as is described by the manifest.

BUG=chromium:252527
TEST=Unittests + devserver image_to_live test.

Change-Id: I9afaa8af3c21813f19d88abf437f35b024d31985
Reviewed-on: https://gerrit.chromium.org/gerrit/59498
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Chris Sosa <sosa@chromium.org>
diff --git a/omaha_request_action.cc b/omaha_request_action.cc
index 15d3188..6a6f87a 100644
--- a/omaha_request_action.cc
+++ b/omaha_request_action.cc
@@ -34,7 +34,7 @@
 // List of custom pair tags that we interpret in the Omaha Response:
 static const char* kTagDeadline = "deadline";
 static const char* kTagDisablePayloadBackoff = "DisablePayloadBackoff";
-static const char* kTagDisplayVersion = "DisplayVersion";
+static const char* kTagVersion = "version";
 // Deprecated: "IsDelta"
 static const char* kTagIsDeltaPayload = "IsDeltaPayload";
 static const char* kTagMaxFailureCountPerUrl = "MaxFailureCountPerUrl";
@@ -614,22 +614,48 @@
 bool OmahaRequestAction::ParseParams(xmlDoc* doc,
                                      OmahaResponse* output_object,
                                      ScopedActionCompleter* completer) {
-  // Get the action node where parameters are present.
+  // XPath location for response elements we care about.
+  static const char* kManifestNodeXPath("/response/app/updatecheck/manifest");\
   static const char* kActionNodeXPath(
-      "/response/app/updatecheck/manifest/actions/action");
+        "/response/app/updatecheck/manifest/actions/action");
 
+  // Get the manifest node where version is present.
   scoped_ptr_malloc<xmlXPathObject, ScopedPtrXmlXPathObjectFree>
-      xpath_nodeset(GetNodeSet(doc, ConstXMLStr(kActionNodeXPath)));
-  if (!xpath_nodeset.get()) {
+      xpath_manifest_nodeset(GetNodeSet(doc, ConstXMLStr(kManifestNodeXPath)));
+  if (!xpath_manifest_nodeset.get()) {
     completer->set_code(kErrorCodeOmahaResponseInvalid);
     return false;
   }
 
-  xmlNodeSet* nodeset = xpath_nodeset->nodesetval;
-  CHECK(nodeset) << "XPath missing " << kActionNodeXPath;
+  // Grab the only matching node there should be from the xpath.
+  xmlNodeSet* nodeset = xpath_manifest_nodeset->nodesetval;
+  CHECK(nodeset) << "XPath missing " << kManifestNodeXPath;
+  CHECK_GE(nodeset->nodeNr, 1);
+  xmlNode* manifest_node = nodeset->nodeTab[0];
 
-  // We only care about the action that has event "postinall", because this is
+  // Set the version.
+  output_object->version = XmlGetProperty(manifest_node, kTagVersion);
+  if (output_object->version.empty()) {
+    LOG(ERROR) << "Omaha Response has manifest version";
+    completer->set_code(kErrorCodeOmahaResponseInvalid);
+    return false;
+  }
+
+  LOG(INFO) << "Received omaha response to update to version "
+            << output_object->version;
+
+  // Grab the action nodes.
+  scoped_ptr_malloc<xmlXPathObject, ScopedPtrXmlXPathObjectFree>
+      xpath_action_nodeset(GetNodeSet(doc, ConstXMLStr(kActionNodeXPath)));
+  if (!xpath_action_nodeset.get()) {
+    completer->set_code(kErrorCodeOmahaResponseInvalid);
+    return false;
+  }
+
+  // We only care about the action that has event "postinstall", because this is
   // where Omaha puts all the generic name/value pairs in the rule.
+  nodeset = xpath_action_nodeset->nodesetval;
+  CHECK(nodeset) << "XPath missing " << kActionNodeXPath;
   LOG(INFO) << "Found " << nodeset->nodeNr
             << " action(s). Processing the postinstall action.";
 
@@ -658,8 +684,6 @@
   }
 
   // Get the optional properties one by one.
-  output_object->display_version =
-      XmlGetProperty(pie_action_node, kTagDisplayVersion);
   output_object->more_info_url = XmlGetProperty(pie_action_node, kTagMoreInfo);
   output_object->metadata_size =
       ParseInt(XmlGetProperty(pie_action_node, kTagMetadataSize));