Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/chrome/RegistryMessageUtils.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef mozilla_RegistryMessageUtils_h
7
#define mozilla_RegistryMessageUtils_h
8
9
#include "ipc/IPCMessageUtils.h"
10
#include "nsString.h"
11
12
struct SerializedURI
13
{
14
  nsCString spec;
15
16
  bool operator ==(const SerializedURI& rhs) const
17
0
  {
18
0
      return spec.Equals(rhs.spec);
19
0
  }
20
};
21
22
struct ChromePackage
23
{
24
  nsCString package;
25
  SerializedURI contentBaseURI;
26
  SerializedURI localeBaseURI;
27
  SerializedURI skinBaseURI;
28
  uint32_t flags;
29
30
  bool operator ==(const ChromePackage& rhs) const
31
0
  {
32
0
    return package.Equals(rhs.package) &&
33
0
           contentBaseURI == rhs.contentBaseURI &&
34
0
           localeBaseURI == rhs.localeBaseURI &&
35
0
           skinBaseURI == rhs.skinBaseURI &&
36
0
           flags == rhs.flags;
37
0
  }
38
};
39
40
struct SubstitutionMapping
41
{
42
  nsCString scheme;
43
  nsCString path;
44
  SerializedURI resolvedURI;
45
  uint32_t flags;
46
47
  bool operator ==(const SubstitutionMapping& rhs) const
48
0
  {
49
0
    return scheme.Equals(rhs.scheme) &&
50
0
           path.Equals(rhs.path) &&
51
0
           resolvedURI == rhs.resolvedURI &&
52
0
           flags == rhs.flags;
53
0
  }
54
};
55
56
struct OverrideMapping
57
{
58
  SerializedURI originalURI;
59
  SerializedURI overrideURI;
60
61
  bool operator==(const OverrideMapping& rhs) const
62
0
  {
63
0
      return originalURI == rhs.originalURI &&
64
0
             overrideURI == rhs.overrideURI;
65
0
  }
66
};
67
68
namespace IPC {
69
70
template<>
71
struct ParamTraits<SerializedURI>
72
{
73
  typedef SerializedURI paramType;
74
75
  static void Write(Message* aMsg, const paramType& aParam)
76
0
  {
77
0
    WriteParam(aMsg, aParam.spec);
78
0
  }
79
80
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
81
0
  {
82
0
    nsCString spec;
83
0
    if (ReadParam(aMsg, aIter, &spec)) {
84
0
      aResult->spec = spec;
85
0
      return true;
86
0
    }
87
0
    return false;
88
0
  }
89
};
90
91
template <>
92
struct ParamTraits<ChromePackage>
93
{
94
  typedef ChromePackage paramType;
95
96
  static void Write(Message* aMsg, const paramType& aParam)
97
0
  {
98
0
    WriteParam(aMsg, aParam.package);
99
0
    WriteParam(aMsg, aParam.contentBaseURI);
100
0
    WriteParam(aMsg, aParam.localeBaseURI);
101
0
    WriteParam(aMsg, aParam.skinBaseURI);
102
0
    WriteParam(aMsg, aParam.flags);
103
0
  }
104
105
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
106
0
  {
107
0
    nsCString package;
108
0
    SerializedURI contentBaseURI, localeBaseURI, skinBaseURI;
109
0
    uint32_t flags;
110
0
111
0
    if (ReadParam(aMsg, aIter, &package) &&
112
0
        ReadParam(aMsg, aIter, &contentBaseURI) &&
113
0
        ReadParam(aMsg, aIter, &localeBaseURI) &&
114
0
        ReadParam(aMsg, aIter, &skinBaseURI) &&
115
0
        ReadParam(aMsg, aIter, &flags)) {
116
0
      aResult->package = package;
117
0
      aResult->contentBaseURI = contentBaseURI;
118
0
      aResult->localeBaseURI = localeBaseURI;
119
0
      aResult->skinBaseURI = skinBaseURI;
120
0
      aResult->flags = flags;
121
0
      return true;
122
0
    }
123
0
    return false;
124
0
  }
125
126
  static void Log(const paramType& aParam, std::wstring* aLog)
127
0
  {
128
0
    aLog->append(StringPrintf(L"[%s, %s, %s, %s, %u]", aParam.package.get(),
129
0
                             aParam.contentBaseURI.spec.get(),
130
0
                             aParam.localeBaseURI.spec.get(),
131
0
                             aParam.skinBaseURI.spec.get(), aParam.flags));
132
0
  }
133
};
134
135
template <>
136
struct ParamTraits<SubstitutionMapping>
137
{
138
  typedef SubstitutionMapping paramType;
139
140
  static void Write(Message* aMsg, const paramType& aParam)
141
0
  {
142
0
    WriteParam(aMsg, aParam.scheme);
143
0
    WriteParam(aMsg, aParam.path);
144
0
    WriteParam(aMsg, aParam.resolvedURI);
145
0
    WriteParam(aMsg, aParam.flags);
146
0
  }
147
148
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
149
0
  {
150
0
    nsCString scheme, path;
151
0
    SerializedURI resolvedURI;
152
0
    uint32_t flags;
153
0
154
0
    if (ReadParam(aMsg, aIter, &scheme) &&
155
0
        ReadParam(aMsg, aIter, &path) &&
156
0
        ReadParam(aMsg, aIter, &resolvedURI) &&
157
0
        ReadParam(aMsg, aIter, &flags)) {
158
0
      aResult->scheme = scheme;
159
0
      aResult->path = path;
160
0
      aResult->resolvedURI = resolvedURI;
161
0
      aResult->flags = flags;
162
0
      return true;
163
0
    }
164
0
    return false;
165
0
  }
166
167
  static void Log(const paramType& aParam, std::wstring* aLog)
168
0
  {
169
0
    aLog->append(StringPrintf(L"[%s://%s, %s, %u]",
170
0
                             aParam.scheme.get(),
171
0
                             aParam.path.get(),
172
0
                             aParam.resolvedURI.spec.get()));
173
0
  }
174
};
175
176
template <>
177
struct ParamTraits<OverrideMapping>
178
{
179
  typedef OverrideMapping paramType;
180
181
  static void Write(Message* aMsg, const paramType& aParam)
182
0
  {
183
0
    WriteParam(aMsg, aParam.originalURI);
184
0
    WriteParam(aMsg, aParam.overrideURI);
185
0
  }
186
187
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
188
0
  {
189
0
    SerializedURI originalURI;
190
0
    SerializedURI overrideURI;
191
0
192
0
    if (ReadParam(aMsg, aIter, &originalURI) &&
193
0
        ReadParam(aMsg, aIter, &overrideURI)) {
194
0
      aResult->originalURI = originalURI;
195
0
      aResult->overrideURI = overrideURI;
196
0
      return true;
197
0
    }
198
0
    return false;
199
0
  }
200
201
  static void Log(const paramType& aParam, std::wstring* aLog)
202
0
  {
203
0
    aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.originalURI.spec.get(),
204
0
                             aParam.overrideURI.spec.get()));
205
0
  }
206
};
207
208
} // namespace IPC
209
210
#endif // RegistryMessageUtils_h