// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_ #define COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_ #include #include #include #include #include "base/macros.h" #include "url/gurl.h" namespace update_client { // The protocol versions so far are: // * Version 3.1: it changes how the run actions are serialized. // * Version 3.0: it is the version implemented by the desktop updaters. constexpr char kProtocolVersion[] = "3.1"; // Parses responses for the update protocol version 3. // (https://github.com/google/omaha/blob/wiki/ServerProtocolV3.md) // // An update response looks like this: // // // // // // // // // // // // // // // // // // // // // // // // The tag contains a "elapsed_seconds" attribute which refers to // the server's notion of how many seconds it has been since midnight. // // The "appid" attribute of the tag refers to the unique id of the // extension. The "codebase" attribute of the tag is the url to // fetch the updated crx file, and the "prodversionmin" attribute refers to // the minimum version of the chrome browser that the update applies to. // // The diff data members correspond to the differential update package, if // a differential update is specified in the response. class ProtocolParser { public: // The result of parsing one tag in an xml update check response. struct Result { struct Manifest { struct Package { Package(); Package(const Package& other); ~Package(); std::string fingerprint; // Attributes for the full update. std::string name; std::string hash_sha256; int size = 0; // Attributes for the differential update. std::string namediff; std::string hashdiff_sha256; int sizediff = 0; }; Manifest(); Manifest(const Manifest& other); ~Manifest(); std::string version; std::string browser_min_version; std::vector packages; }; Result(); Result(const Result& other); ~Result(); std::string extension_id; // The updatecheck response status. std::string status; // The list of fallback urls, for full and diff updates respectively. // These urls are base urls; they don't include the filename. std::vector crx_urls; std::vector crx_diffurls; Manifest manifest; // The server has instructed the client to set its [key] to [value] for each // key-value pair in this string. std::map cohort_attrs; // The following are the only allowed keys in |cohort_attrs|. static const char kCohort[]; static const char kCohortHint[]; static const char kCohortName[]; // Contains the run action returned by the server as part of an update // check response. std::string action_run; }; static const int kNoDaystart = -1; struct Results { Results(); Results(const Results& other); ~Results(); // This will be >= 0, or kNoDaystart if the tag was not present. int daystart_elapsed_seconds = kNoDaystart; // This will be >= 0, or kNoDaystart if the tag was not present. int daystart_elapsed_days = kNoDaystart; std::vector list; }; ProtocolParser(); ~ProtocolParser(); // Parses an update response xml string into Result data. Returns a bool // indicating success or failure. On success, the results are available by // calling results(). In case of success, only results corresponding to // the update check status |ok| or |noupdate| are included. // The details for any failures are available by calling errors(). bool Parse(const std::string& manifest_xml); const Results& results() const { return results_; } const std::string& errors() const { return errors_; } private: Results results_; std::string errors_; // Adds parse error details to |errors_| string. void ParseError(const char* details, ...); DISALLOW_COPY_AND_ASSIGN(ProtocolParser); }; } // namespace update_client #endif // COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_