| OLD | NEW |
| 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> |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 return false; | 251 return false; |
| 252 } | 252 } |
| 253 | 253 |
| 254 return true; | 254 return true; |
| 255 } | 255 } |
| 256 | 256 |
| 257 // Parses the <updatecheck> tag. | 257 // Parses the <updatecheck> tag. |
| 258 bool ParseUpdateCheckTag(xmlNode* updatecheck, | 258 bool ParseUpdateCheckTag(xmlNode* updatecheck, |
| 259 UpdateResponse::Result* result, | 259 UpdateResponse::Result* result, |
| 260 std::string* error) { | 260 std::string* error) { |
| 261 if (GetAttribute(updatecheck, "status") == "noupdate") { | 261 // Read the |status| attribute. |
| 262 return true; | 262 result->status = GetAttribute(updatecheck, "status"); |
| 263 } | 263 if (result->status.empty()) { |
| 264 | 264 *error = "Missing status on updatecheck node"; |
| 265 // Get the <urls> tag. | |
| 266 std::vector<xmlNode*> urls = GetChildren(updatecheck, "urls"); | |
| 267 if (urls.empty()) { | |
| 268 *error = "Missing urls on updatecheck."; | |
| 269 return false; | 265 return false; |
| 270 } | 266 } |
| 271 | 267 |
| 272 if (!ParseUrlsTag(urls[0], result, error)) { | 268 if (result->status == "noupdate") |
| 273 return false; | 269 return true; |
| 270 |
| 271 if (result->status == "ok") { |
| 272 std::vector<xmlNode*> urls = GetChildren(updatecheck, "urls"); |
| 273 if (urls.empty()) { |
| 274 *error = "Missing urls on updatecheck."; |
| 275 return false; |
| 276 } |
| 277 |
| 278 if (!ParseUrlsTag(urls[0], result, error)) { |
| 279 return false; |
| 280 } |
| 281 |
| 282 std::vector<xmlNode*> manifests = GetChildren(updatecheck, "manifest"); |
| 283 if (manifests.empty()) { |
| 284 *error = "Missing manifest on updatecheck."; |
| 285 return false; |
| 286 } |
| 287 |
| 288 return ParseManifestTag(manifests[0], result, error); |
| 274 } | 289 } |
| 275 | 290 |
| 276 std::vector<xmlNode*> manifests = GetChildren(updatecheck, "manifest"); | 291 // Return the |updatecheck| element status as a parsing error. |
| 277 if (manifests.empty()) { | 292 *error = result->status; |
| 278 *error = "Missing manifest on updatecheck."; | 293 return false; |
| 279 return false; | |
| 280 } | |
| 281 | |
| 282 return ParseManifestTag(manifests[0], result, error); | |
| 283 } | 294 } |
| 284 | 295 |
| 285 // Parses a single <app> tag. | 296 // Parses a single <app> tag. |
| 286 bool ParseAppTag(xmlNode* app, | 297 bool ParseAppTag(xmlNode* app, |
| 287 UpdateResponse::Result* result, | 298 UpdateResponse::Result* result, |
| 288 std::string* error) { | 299 std::string* error) { |
| 289 // Read cohort information. | 300 // Read cohort information. |
| 290 auto cohort = GetAttributePtr(app, "cohort"); | 301 auto cohort = GetAttributePtr(app, "cohort"); |
| 291 static const char* attrs[] = {UpdateResponse::Result::kCohort, | 302 static const char* attrs[] = {UpdateResponse::Result::kCohort, |
| 292 UpdateResponse::Result::kCohortHint, | 303 UpdateResponse::Result::kCohortHint, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 313 | 324 |
| 314 return ParseUpdateCheckTag(updates[0], result, error); | 325 return ParseUpdateCheckTag(updates[0], result, error); |
| 315 } | 326 } |
| 316 | 327 |
| 317 bool UpdateResponse::Parse(const std::string& response_xml) { | 328 bool UpdateResponse::Parse(const std::string& response_xml) { |
| 318 results_.daystart_elapsed_seconds = kNoDaystart; | 329 results_.daystart_elapsed_seconds = kNoDaystart; |
| 319 results_.daystart_elapsed_days = kNoDaystart; | 330 results_.daystart_elapsed_days = kNoDaystart; |
| 320 results_.list.clear(); | 331 results_.list.clear(); |
| 321 errors_.clear(); | 332 errors_.clear(); |
| 322 | 333 |
| 323 if (response_xml.length() < 1) { | 334 if (response_xml.empty()) { |
| 324 ParseError("Empty xml"); | 335 ParseError("Empty xml"); |
| 325 return false; | 336 return false; |
| 326 } | 337 } |
| 327 | 338 |
| 328 std::string xml_errors; | 339 std::string xml_errors; |
| 329 ScopedXmlErrorFunc error_func(&xml_errors, &XmlErrorFunc); | 340 ScopedXmlErrorFunc error_func(&xml_errors, &XmlErrorFunc); |
| 330 | 341 |
| 331 // Start up the xml parser with the manifest_xml contents. | 342 // Start up the xml parser with the manifest_xml contents. |
| 332 ScopedXmlDocument document( | 343 ScopedXmlDocument document( |
| 333 xmlParseDoc(reinterpret_cast<const xmlChar*>(response_xml.c_str()))); | 344 xmlParseDoc(reinterpret_cast<const xmlChar*>(response_xml.c_str()))); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 results_.list.push_back(result); | 392 results_.list.push_back(result); |
| 382 } else { | 393 } else { |
| 383 ParseError("%s", error.c_str()); | 394 ParseError("%s", error.c_str()); |
| 384 } | 395 } |
| 385 } | 396 } |
| 386 | 397 |
| 387 return true; | 398 return true; |
| 388 } | 399 } |
| 389 | 400 |
| 390 } // namespace update_client | 401 } // namespace update_client |
| OLD | NEW |