[email protected] | de0fdca2 | 2014-08-19 05:26:09 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
sorin | 7cff6e5 | 2017-05-17 16:37:23 | [diff] [blame^] | 5 | #ifndef COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_ |
6 | #define COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_ | ||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 7 | |
waffles | f43eb2fd3 | 2016-08-23 19:15:29 | [diff] [blame] | 8 | #include <map> |
9 | #include <memory> | ||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 10 | #include <string> |
11 | #include <vector> | ||||
sorin | 5cb1f549 | 2014-09-23 04:07:44 | [diff] [blame] | 12 | |
13 | #include "base/macros.h" | ||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 14 | #include "url/gurl.h" |
15 | |||||
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 16 | namespace update_client { |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 17 | |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 18 | // 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. | ||||
21 | constexpr char kProtocolVersion[] = "3.1"; | ||||
22 | |||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 23 | // Parses responses for the update protocol version 3. |
mostynb | df175a8 | 2016-02-08 23:27:20 | [diff] [blame] | 24 | // (https://github.com/google/omaha/blob/wiki/ServerProtocolV3.md) |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 25 | // |
[email protected] | 6268d3a | 2013-11-27 01:28:09 | [diff] [blame] | 26 | // An update response looks like this: |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 27 | // |
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. | ||||
sorin | 7cff6e5 | 2017-05-17 16:37:23 | [diff] [blame^] | 65 | class ProtocolParser { |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 66 | public: |
[email protected] | 6268d3a | 2013-11-27 01:28:09 | [diff] [blame] | 67 | // The result of parsing one <app> tag in an xml update check response. |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 68 | struct Result { |
69 | struct Manifest { | ||||
70 | struct Package { | ||||
71 | Package(); | ||||
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 72 | Package(const Package& other); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 73 | ~Package(); |
74 | |||||
75 | std::string fingerprint; | ||||
76 | |||||
77 | // Attributes for the full update. | ||||
78 | std::string name; | ||||
79 | std::string hash_sha256; | ||||
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 80 | int size = 0; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 81 | |
82 | // Attributes for the differential update. | ||||
83 | std::string namediff; | ||||
84 | std::string hashdiff_sha256; | ||||
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 85 | int sizediff = 0; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 86 | }; |
87 | |||||
88 | Manifest(); | ||||
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 89 | Manifest(const Manifest& other); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 90 | ~Manifest(); |
91 | |||||
92 | std::string version; | ||||
93 | std::string browser_min_version; | ||||
94 | std::vector<Package> packages; | ||||
95 | }; | ||||
96 | |||||
97 | Result(); | ||||
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 98 | Result(const Result& other); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 99 | ~Result(); |
100 | |||||
101 | std::string extension_id; | ||||
102 | |||||
sorin | 9ef301c | 2017-02-16 20:29:17 | [diff] [blame] | 103 | // The updatecheck response status. |
104 | std::string status; | ||||
105 | |||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 106 | // The list of fallback urls, for full and diff updates respectively. |
[email protected] | da37c1d | 2013-12-19 01:04:38 | [diff] [blame] | 107 | // These urls are base urls; they don't include the filename. |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 108 | std::vector<GURL> crx_urls; |
109 | std::vector<GURL> crx_diffurls; | ||||
110 | |||||
111 | Manifest manifest; | ||||
waffles | f43eb2fd3 | 2016-08-23 19:15:29 | [diff] [blame] | 112 | |
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[]; | ||||
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 121 | |
122 | // Contains the run action returned by the server as part of an update | ||||
123 | // check response. | ||||
124 | std::string action_run; | ||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 125 | }; |
126 | |||||
127 | static const int kNoDaystart = -1; | ||||
128 | struct Results { | ||||
129 | Results(); | ||||
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 130 | Results(const Results& other); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 131 | ~Results(); |
132 | |||||
133 | // This will be >= 0, or kNoDaystart if the <daystart> tag was not present. | ||||
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 134 | int daystart_elapsed_seconds = kNoDaystart; |
135 | |||||
waffles | d2d9a33 | 2016-04-09 01:59:57 | [diff] [blame] | 136 | // This will be >= 0, or kNoDaystart if the <daystart> tag was not present. |
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 137 | int daystart_elapsed_days = kNoDaystart; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 138 | std::vector<Result> list; |
139 | }; | ||||
140 | |||||
sorin | 7cff6e5 | 2017-05-17 16:37:23 | [diff] [blame^] | 141 | ProtocolParser(); |
142 | ~ProtocolParser(); | ||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 143 | |
[email protected] | 6268d3a | 2013-11-27 01:28:09 | [diff] [blame] | 144 | // Parses an update response xml string into Result data. Returns a bool |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 145 | // indicating success or failure. On success, the results are available by |
sorin | 9ef301c | 2017-02-16 20:29:17 | [diff] [blame] | 146 | // 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] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 149 | 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 | |||||
sorin | 7cff6e5 | 2017-05-17 16:37:23 | [diff] [blame^] | 161 | DISALLOW_COPY_AND_ASSIGN(ProtocolParser); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 162 | }; |
163 | |||||
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 164 | } // namespace update_client |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 165 | |
sorin | 7cff6e5 | 2017-05-17 16:37:23 | [diff] [blame^] | 166 | #endif // COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_ |