summaryrefslogtreecommitdiff
path: root/chromium/components/update_client/protocol_parser.cc
blob: 457a2cbdcfc2093ec18cc5093a19d5ccb62b7127 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/update_client/protocol_parser.h"

#include <string>

#include "base/strings/stringprintf.h"

namespace update_client {

const char ProtocolParser::Result::kCohort[] = "cohort";
const char ProtocolParser::Result::kCohortHint[] = "cohorthint";
const char ProtocolParser::Result::kCohortName[] = "cohortname";

ProtocolParser::ProtocolParser() = default;
ProtocolParser::~ProtocolParser() = default;

ProtocolParser::Results::Results() = default;
ProtocolParser::Results::Results(const Results& other) = default;
ProtocolParser::Results::~Results() = default;

ProtocolParser::Result::Result() = default;
ProtocolParser::Result::Result(const Result& other) = default;
ProtocolParser::Result::~Result() = default;

ProtocolParser::Result::Manifest::Manifest() = default;
ProtocolParser::Result::Manifest::Manifest(const Manifest& other) = default;
ProtocolParser::Result::Manifest::~Manifest() = default;

ProtocolParser::Result::Manifest::Package::Package() = default;
ProtocolParser::Result::Manifest::Package::Package(const Package& other) =
    default;
ProtocolParser::Result::Manifest::Package::~Package() = default;

ProtocolParser::Result::Data::Data() = default;
ProtocolParser::Result::Data::Data(const Data& other) = default;
ProtocolParser::Result::Data& ProtocolParser::Result::Data::operator=(
    const Data&) = default;
ProtocolParser::Result::Data::Data(const std::string& status,
                                   const std::string& name,
                                   const std::string& install_data_index,
                                   const std::string& text)
    : status(status),
      name(name),
      install_data_index(install_data_index),
      text(text) {}
ProtocolParser::Result::Data::~Data() = default;

void ProtocolParser::ParseError(const char* details, ...) {
  va_list args;
  va_start(args, details);

  if (!errors_.empty()) {
    errors_ += "\r\n";
  }

  base::StringAppendV(&errors_, details, args);
  va_end(args);
}

bool ProtocolParser::Parse(const std::string& response) {
  results_.daystart_elapsed_seconds = kNoDaystart;
  results_.daystart_elapsed_days = kNoDaystart;
  results_.list.clear();
  errors_.clear();

  return DoParse(response, &results_);
}

}  // namespace update_client