File: protocol_parser.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (137 lines) | stat: -rw-r--r-- 3,857 bytes parent folder | download | duplicates (3)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// 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.

#ifndef COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_
#define COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_

#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <vector>

#include "base/version.h"
#include "url/gurl.h"

namespace update_client {

class ProtocolParser {
 public:
  // The result of parsing one |app| entity in an update check response.
  struct Data {
    Data();
    Data(const std::string& install_data_index, const std::string& text);
    Data(const Data& other);
    Data& operator=(const Data&);
    ~Data();

    // The `install_data_index` specified by the update check.
    std::string install_data_index;

    // The server data corresponding to the `name`/`install_data_index pair`.
    std::string text;
  };

  struct Operation {
    Operation();
    Operation(const Operation& other);
    Operation& operator=(const Operation&);
    ~Operation();
    std::string type;
    std::string sha256_in;
    std::string sha256_out;
    std::string sha256_previous;
    std::string path;
    std::string arguments;
    int64_t size = 0;
    std::vector<GURL> urls;
  };

  struct Pipeline {
    Pipeline();
    Pipeline(const Pipeline& other);
    Pipeline& operator=(const Pipeline&);
    ~Pipeline();
    std::string pipeline_id;
    std::vector<Operation> operations;
  };

  struct App {
    App();
    App(const App& other);
    App& operator=(const App&);
    ~App();

    std::string app_id;

    // status indicates the outcome of the check. It can be filled from either
    // the app or updatecheck node.
    std::string status;

    // App-specific additions in the updatecheck response, including the
    // mandatory '_' prefix (which prevents collision with formal protocol
    // elements).
    std::map<std::string, std::string> custom_attributes;

    // The server has instructed the client to set its [key] to [value] for each
    // key-value pair in this string.
    std::optional<std::string> cohort;
    std::optional<std::string> cohort_name;
    std::optional<std::string> cohort_hint;

    // Contains the data responses corresponding to the data elements specified
    // in the update request.
    std::vector<Data> data;

    // When an update is available, these fields will be filled.
    base::Version nextversion;
    std::vector<Pipeline> pipelines;
  };

  static constexpr int kNoDaystart = -1;
  struct Results {
    Results();
    Results(const Results& other);
    Results& operator=(const Results&);
    ~Results();

    // This will be >= 0, or kNoDaystart if the <daystart> tag was not present.
    int daystart_elapsed_days = kNoDaystart;

    std::vector<App> apps;
  };

  static std::unique_ptr<ProtocolParser> Create();

  ProtocolParser(const ProtocolParser&) = delete;
  ProtocolParser& operator=(const ProtocolParser&) = delete;

  virtual ~ProtocolParser();

  // Parses an update response 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& response);

  const Results& results() const { return results_; }
  const std::string& errors() const { return errors_; }

 protected:
  ProtocolParser();

  // Appends parse error details to |errors_| string.
  void ParseError(const char* details, ...);

 private:
  virtual bool DoParse(const std::string& response, Results* results) = 0;

  Results results_;
  std::string errors_;
};

}  // namespace update_client

#endif  // COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_