/src/mozilla-central/toolkit/components/reputationservice/ApplicationReputationTelemetryUtils.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | #include "ApplicationReputationTelemetryUtils.h" |
6 | | #include "mozilla/Assertions.h" |
7 | | |
8 | | using ServerLabel = |
9 | | mozilla::Telemetry::LABELS_APPLICATION_REPUTATION_SERVER_2; |
10 | | |
11 | | struct NSErrorTelemetryResult |
12 | | { |
13 | | nsresult mValue; |
14 | | ServerLabel mLabel; |
15 | | }; |
16 | | |
17 | | static const NSErrorTelemetryResult sResult[] = { |
18 | | { |
19 | | NS_ERROR_ALREADY_CONNECTED, |
20 | | ServerLabel::ErrAlreadyConnected, |
21 | | }, |
22 | | { |
23 | | NS_ERROR_NOT_CONNECTED, |
24 | | ServerLabel::ErrNotConnected, |
25 | | }, |
26 | | { |
27 | | NS_ERROR_CONNECTION_REFUSED, |
28 | | ServerLabel::ErrConnectionRefused, |
29 | | }, |
30 | | { |
31 | | NS_ERROR_NET_TIMEOUT, |
32 | | ServerLabel::ErrNetTimeout, |
33 | | }, |
34 | | { |
35 | | NS_ERROR_OFFLINE, |
36 | | ServerLabel::ErrOffline, |
37 | | }, |
38 | | { |
39 | | NS_ERROR_PORT_ACCESS_NOT_ALLOWED, |
40 | | ServerLabel::ErrPortAccess, |
41 | | }, |
42 | | { |
43 | | NS_ERROR_NET_RESET, |
44 | | ServerLabel::ErrNetReset, |
45 | | }, |
46 | | { |
47 | | NS_ERROR_NET_INTERRUPT, |
48 | | ServerLabel::ErrNetInterrupt, |
49 | | }, |
50 | | { |
51 | | NS_ERROR_PROXY_CONNECTION_REFUSED, |
52 | | ServerLabel::ErrProxyConnection, |
53 | | }, |
54 | | { |
55 | | NS_ERROR_NET_PARTIAL_TRANSFER, |
56 | | ServerLabel::ErrNetPartial, |
57 | | }, |
58 | | { |
59 | | NS_ERROR_NET_INADEQUATE_SECURITY, |
60 | | ServerLabel::ErrNetInadequate, |
61 | | }, |
62 | | { |
63 | | NS_ERROR_UNKNOWN_HOST, |
64 | | ServerLabel::ErrUnknownHost, |
65 | | }, |
66 | | { |
67 | | NS_ERROR_DNS_LOOKUP_QUEUE_FULL, |
68 | | ServerLabel::ErrDNSLookupQueue, |
69 | | }, |
70 | | { |
71 | | NS_ERROR_UNKNOWN_PROXY_HOST, |
72 | | ServerLabel::ErrUnknownProxyHost, |
73 | | }, |
74 | | }; |
75 | | |
76 | | mozilla::Telemetry::LABELS_APPLICATION_REPUTATION_SERVER_2 |
77 | | NSErrorToLabel(nsresult rv) |
78 | 0 | { |
79 | 0 | MOZ_ASSERT(rv != NS_OK); |
80 | 0 |
|
81 | 0 | for (const auto& p : sResult) { |
82 | 0 | if (p.mValue == rv) { |
83 | 0 | return p.mLabel; |
84 | 0 | } |
85 | 0 | } |
86 | 0 | return ServerLabel::ErrOthers; |
87 | 0 | } |
88 | | |
89 | | mozilla::Telemetry::LABELS_APPLICATION_REPUTATION_SERVER_2 |
90 | | HTTPStatusToLabel(uint32_t status) |
91 | 0 | { |
92 | 0 | MOZ_ASSERT(status != 200); |
93 | 0 |
|
94 | 0 | ServerLabel label; |
95 | 0 | switch (status) { |
96 | 0 | case 100: |
97 | 0 | case 101: |
98 | 0 | // Unexpected 1xx return code |
99 | 0 | label = ServerLabel::HTTP1xx; |
100 | 0 | break; |
101 | 0 | case 201: |
102 | 0 | case 202: |
103 | 0 | case 203: |
104 | 0 | case 205: |
105 | 0 | case 206: |
106 | 0 | // Unexpected 2xx return code |
107 | 0 | label = ServerLabel::HTTP2xx; |
108 | 0 | break; |
109 | 0 | case 204: |
110 | 0 | // No Content |
111 | 0 | label = ServerLabel::HTTP204; |
112 | 0 | break; |
113 | 0 | case 300: |
114 | 0 | case 301: |
115 | 0 | case 302: |
116 | 0 | case 303: |
117 | 0 | case 304: |
118 | 0 | case 305: |
119 | 0 | case 307: |
120 | 0 | case 308: |
121 | 0 | // Unexpected 3xx return code |
122 | 0 | label = ServerLabel::HTTP3xx; |
123 | 0 | break; |
124 | 0 | case 400: |
125 | 0 | // Bad Request - The HTTP request was not correctly formed. |
126 | 0 | // The client did not provide all required CGI parameters. |
127 | 0 | label = ServerLabel::HTTP400; |
128 | 0 | break; |
129 | 0 | case 401: |
130 | 0 | case 402: |
131 | 0 | case 405: |
132 | 0 | case 406: |
133 | 0 | case 407: |
134 | 0 | case 409: |
135 | 0 | case 410: |
136 | 0 | case 411: |
137 | 0 | case 412: |
138 | 0 | case 414: |
139 | 0 | case 415: |
140 | 0 | case 416: |
141 | 0 | case 417: |
142 | 0 | case 421: |
143 | 0 | case 426: |
144 | 0 | case 428: |
145 | 0 | case 429: |
146 | 0 | case 431: |
147 | 0 | case 451: |
148 | 0 | // Unexpected 4xx return code |
149 | 0 | label = ServerLabel::HTTP4xx; |
150 | 0 | break; |
151 | 0 | case 403: |
152 | 0 | // Forbidden - The client id is invalid. |
153 | 0 | label = ServerLabel::HTTP403; |
154 | 0 | break; |
155 | 0 | case 404: |
156 | 0 | // Not Found |
157 | 0 | label = ServerLabel::HTTP404; |
158 | 0 | break; |
159 | 0 | case 408: |
160 | 0 | // Request Timeout |
161 | 0 | label = ServerLabel::HTTP408; |
162 | 0 | break; |
163 | 0 | case 413: |
164 | 0 | // Request Entity Too Large |
165 | 0 | label = ServerLabel::HTTP413; |
166 | 0 | break; |
167 | 0 | case 500: |
168 | 0 | case 501: |
169 | 0 | case 510: |
170 | 0 | // Unexpected 5xx return code |
171 | 0 | label = ServerLabel::HTTP5xx; |
172 | 0 | break; |
173 | 0 | case 502: |
174 | 0 | case 504: |
175 | 0 | case 511: |
176 | 0 | // Local network errors, we'll ignore these. |
177 | 0 | label = ServerLabel::HTTP502_504_511; |
178 | 0 | break; |
179 | 0 | case 503: |
180 | 0 | // Service Unavailable - The server cannot handle the request. |
181 | 0 | // Clients MUST follow the backoff behavior specified in the |
182 | 0 | // Request Frequency section. |
183 | 0 | label = ServerLabel::HTTP503; |
184 | 0 | break; |
185 | 0 | case 505: |
186 | 0 | // HTTP Version Not Supported - The server CANNOT handle the requested |
187 | 0 | // protocol major version. |
188 | 0 | label = ServerLabel::HTTP505; |
189 | 0 | break; |
190 | 0 | default: |
191 | 0 | label = ServerLabel::HTTPOthers; |
192 | 0 | }; |
193 | 0 | return label; |
194 | 0 | } |