blob: 61bb4e1ed10090617d93683d2362d34e0d2e9b81 [file] [log] [blame]
[email protected]de0fdca22014-08-19 05:26:091// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]2cddef42013-11-22 08:23:222// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
sorin7cff6e52017-05-17 16:37:235#ifndef COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_
6#define COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_
[email protected]2cddef42013-11-22 08:23:227
wafflesf43eb2fd32016-08-23 19:15:298#include <map>
9#include <memory>
[email protected]2cddef42013-11-22 08:23:2210#include <string>
11#include <vector>
sorin5cb1f5492014-09-23 04:07:4412
13#include "base/macros.h"
[email protected]2cddef42013-11-22 08:23:2214#include "url/gurl.h"
15
sorin52ac0882015-01-24 01:15:0016namespace update_client {
[email protected]2cddef42013-11-22 08:23:2217
sorin39852802017-05-01 22:46:2818// The protocol versions so far are:
19// * Version 3.1: it changes how the run actions are serialized.
20// * Version 3.0: it is the version implemented by the desktop updaters.
21constexpr char kProtocolVersion[] = "3.1";
22
[email protected]2cddef42013-11-22 08:23:2223// Parses responses for the update protocol version 3.
mostynbdf175a82016-02-08 23:27:2024// (https://github.com/google/omaha/blob/wiki/ServerProtocolV3.md)
[email protected]2cddef42013-11-22 08:23:2225//
[email protected]6268d3a2013-11-27 01:28:0926// An update response looks like this:
[email protected]2cddef42013-11-22 08:23:2227//
28// <?xml version="1.0" encoding="UTF-8"?>
29// <response protocol="3.0" server="prod">
30// <daystart elapsed_seconds="56508"/>
31// <app appid="{430FD4D0-B729-4F61-AA34-91526481799D}" status="ok">
32// <updatecheck status="noupdate"/>
33// <ping status="ok"/>
34// </app>
35// <app appid="{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}" status="ok">
36// <updatecheck status="ok">
37// <urls>
38// <url codebase="http://host/edgedl/chrome/install/782.112/"
39// <url codebasediff="http://fallback/chrome/diff/782.112/"/>
40// </urls>
41// <manifest version="13.0.782.112" prodversionmin="2.0.143.0">
42// <packages>
43// <package name="component.crx"
44// namediff="diff_1.2.3.4.crx"
45// fp="1.123"
46// hash_sha256="9830b4245c4..." size="23963192"
47// hashdiff_sha256="cfb6caf3d0..." sizediff="101"/>
48// </packages>
49// </manifest>
50// </updatecheck>
51// <ping status="ok"/>
52// </app>
53// </response>
54//
55// The <daystart> tag contains a "elapsed_seconds" attribute which refers to
56// the server's notion of how many seconds it has been since midnight.
57//
58// The "appid" attribute of the <app> tag refers to the unique id of the
59// extension. The "codebase" attribute of the <updatecheck> tag is the url to
60// fetch the updated crx file, and the "prodversionmin" attribute refers to
61// the minimum version of the chrome browser that the update applies to.
62//
63// The diff data members correspond to the differential update package, if
64// a differential update is specified in the response.
sorin7cff6e52017-05-17 16:37:2365class ProtocolParser {
[email protected]2cddef42013-11-22 08:23:2266 public:
[email protected]6268d3a2013-11-27 01:28:0967 // The result of parsing one <app> tag in an xml update check response.
[email protected]2cddef42013-11-22 08:23:2268 struct Result {
69 struct Manifest {
70 struct Package {
71 Package();
vmpstrb6449d512016-02-25 23:55:4072 Package(const Package& other);
[email protected]2cddef42013-11-22 08:23:2273 ~Package();
74
75 std::string fingerprint;
76
77 // Attributes for the full update.
78 std::string name;
79 std::string hash_sha256;
sorin519656c2017-04-28 22:39:3480 int size = 0;
[email protected]2cddef42013-11-22 08:23:2281
82 // Attributes for the differential update.
83 std::string namediff;
84 std::string hashdiff_sha256;
sorin519656c2017-04-28 22:39:3485 int sizediff = 0;
[email protected]2cddef42013-11-22 08:23:2286 };
87
88 Manifest();
vmpstrb6449d512016-02-25 23:55:4089 Manifest(const Manifest& other);
[email protected]2cddef42013-11-22 08:23:2290 ~Manifest();
91
92 std::string version;
93 std::string browser_min_version;
94 std::vector<Package> packages;
95 };
96
97 Result();
vmpstrb6449d512016-02-25 23:55:4098 Result(const Result& other);
[email protected]2cddef42013-11-22 08:23:2299 ~Result();
100
101 std::string extension_id;
102
sorin9ef301c2017-02-16 20:29:17103 // The updatecheck response status.
104 std::string status;
105
[email protected]2cddef42013-11-22 08:23:22106 // The list of fallback urls, for full and diff updates respectively.
[email protected]da37c1d2013-12-19 01:04:38107 // These urls are base urls; they don't include the filename.
[email protected]2cddef42013-11-22 08:23:22108 std::vector<GURL> crx_urls;
109 std::vector<GURL> crx_diffurls;
110
111 Manifest manifest;
wafflesf43eb2fd32016-08-23 19:15:29112
113 // The server has instructed the client to set its [key] to [value] for each
114 // key-value pair in this string.
115 std::map<std::string, std::string> cohort_attrs;
116
117 // The following are the only allowed keys in |cohort_attrs|.
118 static const char kCohort[];
119 static const char kCohortHint[];
120 static const char kCohortName[];
sorin519656c2017-04-28 22:39:34121
122 // Contains the run action returned by the server as part of an update
123 // check response.
124 std::string action_run;
[email protected]2cddef42013-11-22 08:23:22125 };
126
127 static const int kNoDaystart = -1;
128 struct Results {
129 Results();
vmpstrb6449d512016-02-25 23:55:40130 Results(const Results& other);
[email protected]2cddef42013-11-22 08:23:22131 ~Results();
132
133 // This will be >= 0, or kNoDaystart if the <daystart> tag was not present.
sorin519656c2017-04-28 22:39:34134 int daystart_elapsed_seconds = kNoDaystart;
135
wafflesd2d9a332016-04-09 01:59:57136 // This will be >= 0, or kNoDaystart if the <daystart> tag was not present.
sorin519656c2017-04-28 22:39:34137 int daystart_elapsed_days = kNoDaystart;
[email protected]2cddef42013-11-22 08:23:22138 std::vector<Result> list;
139 };
140
sorin7cff6e52017-05-17 16:37:23141 ProtocolParser();
142 ~ProtocolParser();
[email protected]2cddef42013-11-22 08:23:22143
[email protected]6268d3a2013-11-27 01:28:09144 // Parses an update response xml string into Result data. Returns a bool
[email protected]2cddef42013-11-22 08:23:22145 // indicating success or failure. On success, the results are available by
sorin9ef301c2017-02-16 20:29:17146 // calling results(). In case of success, only results corresponding to
147 // the update check status |ok| or |noupdate| are included.
148 // The details for any failures are available by calling errors().
[email protected]2cddef42013-11-22 08:23:22149 bool Parse(const std::string& manifest_xml);
150
151 const Results& results() const { return results_; }
152 const std::string& errors() const { return errors_; }
153
154 private:
155 Results results_;
156 std::string errors_;
157
158 // Adds parse error details to |errors_| string.
159 void ParseError(const char* details, ...);
160
sorin7cff6e52017-05-17 16:37:23161 DISALLOW_COPY_AND_ASSIGN(ProtocolParser);
[email protected]2cddef42013-11-22 08:23:22162};
163
sorin52ac0882015-01-24 01:15:00164} // namespace update_client
[email protected]2cddef42013-11-22 08:23:22165
sorin7cff6e52017-05-17 16:37:23166#endif // COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_