Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(818)

Side by Side Diff: components/update_client/update_response.cc

Issue 2856573003: Fix the broken XML parser due to version mismatch. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/update_client/update_response.h" 5 #include "components/update_client/update_response.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/version.h" 17 #include "base/version.h"
18 #include "libxml/tree.h" 18 #include "libxml/tree.h"
19 #include "third_party/libxml/chromium/libxml_utils.h" 19 #include "third_party/libxml/chromium/libxml_utils.h"
20 20
21 namespace update_client { 21 namespace update_client {
22 22
23 static const char* kExpectedResponseProtocol = "3.0";
24 const char UpdateResponse::Result::kCohort[] = "cohort"; 23 const char UpdateResponse::Result::kCohort[] = "cohort";
25 const char UpdateResponse::Result::kCohortHint[] = "cohorthint"; 24 const char UpdateResponse::Result::kCohortHint[] = "cohorthint";
26 const char UpdateResponse::Result::kCohortName[] = "cohortname"; 25 const char UpdateResponse::Result::kCohortName[] = "cohortname";
27 26
28 UpdateResponse::UpdateResponse() = default; 27 UpdateResponse::UpdateResponse() = default;
29 UpdateResponse::~UpdateResponse() = default; 28 UpdateResponse::~UpdateResponse() = default;
30 29
31 UpdateResponse::Results::Results() = default; 30 UpdateResponse::Results::Results() = default;
32 UpdateResponse::Results::Results(const Results& other) = default; 31 UpdateResponse::Results::Results(const Results& other) = default;
33 UpdateResponse::Results::~Results() = default; 32 UpdateResponse::Results::~Results() = default;
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 ParseError("Missing root node"); 359 ParseError("Missing root node");
361 return false; 360 return false;
362 } 361 }
363 362
364 if (!TagNameEquals(root, "response")) { 363 if (!TagNameEquals(root, "response")) {
365 ParseError("Missing response tag"); 364 ParseError("Missing response tag");
366 return false; 365 return false;
367 } 366 }
368 367
369 // Check for the response "protocol" attribute. 368 // Check for the response "protocol" attribute.
370 if (GetAttribute(root, "protocol") != kExpectedResponseProtocol) { 369 const auto protocol = GetAttribute(root, "protocol");
370 if (protocol != kProtocolVersion) {
371 ParseError( 371 ParseError(
372 "Missing/incorrect protocol on response tag " 372 "Missing/incorrect protocol on response tag "
373 "(expected '%s')", 373 "(expected '%s', found '%s')",
374 kExpectedResponseProtocol); 374 kProtocolVersion, protocol.c_str());
375 return false; 375 return false;
376 } 376 }
377 377
378 // Parse the first <daystart> if it is present. 378 // Parse the first <daystart> if it is present.
379 std::vector<xmlNode*> daystarts = GetChildren(root, "daystart"); 379 std::vector<xmlNode*> daystarts = GetChildren(root, "daystart");
380 if (!daystarts.empty()) { 380 if (!daystarts.empty()) {
381 xmlNode* first = daystarts[0]; 381 xmlNode* first = daystarts[0];
382 std::string elapsed_seconds = GetAttribute(first, "elapsed_seconds"); 382 std::string elapsed_seconds = GetAttribute(first, "elapsed_seconds");
383 int parsed_elapsed = kNoDaystart; 383 int parsed_elapsed = kNoDaystart;
384 if (base::StringToInt(elapsed_seconds, &parsed_elapsed)) { 384 if (base::StringToInt(elapsed_seconds, &parsed_elapsed)) {
(...skipping 15 matching lines...) Expand all
400 results_.list.push_back(result); 400 results_.list.push_back(result);
401 } else { 401 } else {
402 ParseError("%s", error.c_str()); 402 ParseError("%s", error.c_str());
403 } 403 }
404 } 404 }
405 405
406 return true; 406 return true;
407 } 407 }
408 408
409 } // namespace update_client 409 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/update_response.h ('k') | components/update_client/update_response_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698