blob: cea874428be072884680971bd9101efc6335982a [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#include "components/update_client/protocol_parser.h"
[email protected]2cddef42013-11-22 08:23:226#include "base/strings/stringprintf.h"
Sorin Jianu039032b2018-10-12 21:48:137#include "components/update_client/protocol_parser_xml.h"
[email protected]2cddef42013-11-22 08:23:228
sorin52ac0882015-01-24 01:15:009namespace update_client {
[email protected]2cddef42013-11-22 08:23:2210
sorin7cff6e52017-05-17 16:37:2311const char ProtocolParser::Result::kCohort[] = "cohort";
12const char ProtocolParser::Result::kCohortHint[] = "cohorthint";
13const char ProtocolParser::Result::kCohortName[] = "cohortname";
[email protected]2cddef42013-11-22 08:23:2214
sorin7cff6e52017-05-17 16:37:2315ProtocolParser::ProtocolParser() = default;
16ProtocolParser::~ProtocolParser() = default;
[email protected]2cddef42013-11-22 08:23:2217
sorin7cff6e52017-05-17 16:37:2318ProtocolParser::Results::Results() = default;
19ProtocolParser::Results::Results(const Results& other) = default;
20ProtocolParser::Results::~Results() = default;
[email protected]2cddef42013-11-22 08:23:2221
sorin7cff6e52017-05-17 16:37:2322ProtocolParser::Result::Result() = default;
23ProtocolParser::Result::Result(const Result& other) = default;
24ProtocolParser::Result::~Result() = default;
[email protected]2cddef42013-11-22 08:23:2225
sorin7cff6e52017-05-17 16:37:2326ProtocolParser::Result::Manifest::Manifest() = default;
27ProtocolParser::Result::Manifest::Manifest(const Manifest& other) = default;
28ProtocolParser::Result::Manifest::~Manifest() = default;
[email protected]2cddef42013-11-22 08:23:2229
sorin7cff6e52017-05-17 16:37:2330ProtocolParser::Result::Manifest::Package::Package() = default;
31ProtocolParser::Result::Manifest::Package::Package(const Package& other) =
vmpstrb6449d512016-02-25 23:55:4032 default;
sorin7cff6e52017-05-17 16:37:2333ProtocolParser::Result::Manifest::Package::~Package() = default;
[email protected]2cddef42013-11-22 08:23:2234
sorin7cff6e52017-05-17 16:37:2335void ProtocolParser::ParseError(const char* details, ...) {
[email protected]2cddef42013-11-22 08:23:2236 va_list args;
37 va_start(args, details);
38
39 if (!errors_.empty()) {
40 errors_ += "\r\n";
41 }
42
43 base::StringAppendV(&errors_, details, args);
44 va_end(args);
45}
46
Sorin Jianu039032b2018-10-12 21:48:1347bool ProtocolParser::Parse(const std::string& response) {
[email protected]2cddef42013-11-22 08:23:2248 results_.daystart_elapsed_seconds = kNoDaystart;
wafflesd2d9a332016-04-09 01:59:5749 results_.daystart_elapsed_days = kNoDaystart;
[email protected]2cddef42013-11-22 08:23:2250 results_.list.clear();
51 errors_.clear();
52
Sorin Jianu039032b2018-10-12 21:48:1353 return DoParse(response, &results_);
54}
[email protected]2cddef42013-11-22 08:23:2255
Sorin Jianu039032b2018-10-12 21:48:1356std::unique_ptr<ProtocolParser> ProtocolParser::Create() {
57 return std::make_unique<ProtocolParserXml>();
[email protected]2cddef42013-11-22 08:23:2258}
59
sorin52ac0882015-01-24 01:15:0060} // namespace update_client