| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // A library to manage RLZ information for access-points shared | 5 // A library to manage RLZ information for access-points shared |
| 6 // across different client applications. | 6 // across different client applications. |
| 7 | 7 |
| 8 #include "rlz/lib/rlz_lib.h" | 8 #include "rlz/lib/rlz_lib.h" |
| 9 | 9 |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 int calculated_crc; | 415 int calculated_crc; |
| 416 int checksum_index = response_string.find(checksum_param); | 416 int checksum_index = response_string.find(checksum_param); |
| 417 if (checksum_index >= 0) { | 417 if (checksum_index >= 0) { |
| 418 // Calculate checksum of message preceeding checksum line. | 418 // Calculate checksum of message preceeding checksum line. |
| 419 // (+ 1 to include the \n) | 419 // (+ 1 to include the \n) |
| 420 std::string message(response_string.substr(0, checksum_index + 1)); | 420 std::string message(response_string.substr(0, checksum_index + 1)); |
| 421 if (!Crc32(message.c_str(), &calculated_crc)) | 421 if (!Crc32(message.c_str(), &calculated_crc)) |
| 422 return false; | 422 return false; |
| 423 } else { | 423 } else { |
| 424 checksum_param = "crc32: "; // Empty response case. | 424 checksum_param = "crc32: "; // Empty response case. |
| 425 if (!StartsWithASCII(response_string, checksum_param, true)) | 425 if (!base::StartsWithASCII(response_string, checksum_param, true)) |
| 426 return false; | 426 return false; |
| 427 | 427 |
| 428 checksum_index = 0; | 428 checksum_index = 0; |
| 429 if (!Crc32("", &calculated_crc)) | 429 if (!Crc32("", &calculated_crc)) |
| 430 return false; | 430 return false; |
| 431 } | 431 } |
| 432 | 432 |
| 433 // Find the checksum value on the response. | 433 // Find the checksum value on the response. |
| 434 int checksum_end = response_string.find("\n", checksum_index + 1); | 434 int checksum_end = response_string.find("\n", checksum_index + 1); |
| 435 if (checksum_end < 0) | 435 if (checksum_end < 0) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 int line_end = line_end_index; | 527 int line_end = line_end_index; |
| 528 if (line_end < 0) | 528 if (line_end < 0) |
| 529 line_end = response_length; | 529 line_end = response_length; |
| 530 | 530 |
| 531 if (line_end <= line_begin) | 531 if (line_end <= line_begin) |
| 532 continue; // Empty line. | 532 continue; // Empty line. |
| 533 | 533 |
| 534 std::string response_line; | 534 std::string response_line; |
| 535 response_line = response_string.substr(line_begin, line_end - line_begin); | 535 response_line = response_string.substr(line_begin, line_end - line_begin); |
| 536 | 536 |
| 537 if (StartsWithASCII(response_line, kRlzCgiVariable, true)) { // An RLZ. | 537 if (base::StartsWithASCII(response_line, kRlzCgiVariable, |
| 538 true)) { // An RLZ. |
| 538 int separator_index = -1; | 539 int separator_index = -1; |
| 539 if ((separator_index = response_line.find(": ")) < 0) | 540 if ((separator_index = response_line.find(": ")) < 0) |
| 540 continue; // Not a valid key-value pair. | 541 continue; // Not a valid key-value pair. |
| 541 | 542 |
| 542 // Get the access point. | 543 // Get the access point. |
| 543 std::string point_name = | 544 std::string point_name = |
| 544 response_line.substr(3, separator_index - rlz_cgi_length); | 545 response_line.substr(3, separator_index - rlz_cgi_length); |
| 545 AccessPoint point = NO_ACCESS_POINT; | 546 AccessPoint point = NO_ACCESS_POINT; |
| 546 if (!GetAccessPointFromName(point_name.c_str(), &point) || | 547 if (!GetAccessPointFromName(point_name.c_str(), &point) || |
| 547 point == NO_ACCESS_POINT) | 548 point == NO_ACCESS_POINT) |
| 548 continue; // Not a valid access point. | 549 continue; // Not a valid access point. |
| 549 | 550 |
| 550 // Get the new RLZ. | 551 // Get the new RLZ. |
| 551 std::string rlz_value(response_line.substr(separator_index + 2)); | 552 std::string rlz_value(response_line.substr(separator_index + 2)); |
| 552 base::TrimWhitespaceASCII(rlz_value, base::TRIM_LEADING, &rlz_value); | 553 base::TrimWhitespaceASCII(rlz_value, base::TRIM_LEADING, &rlz_value); |
| 553 | 554 |
| 554 size_t rlz_length = rlz_value.find_first_of("\r\n "); | 555 size_t rlz_length = rlz_value.find_first_of("\r\n "); |
| 555 if (rlz_length == std::string::npos) | 556 if (rlz_length == std::string::npos) |
| 556 rlz_length = rlz_value.size(); | 557 rlz_length = rlz_value.size(); |
| 557 | 558 |
| 558 if (rlz_length > kMaxRlzLength) | 559 if (rlz_length > kMaxRlzLength) |
| 559 continue; // Too long. | 560 continue; // Too long. |
| 560 | 561 |
| 561 if (IsAccessPointSupported(point)) | 562 if (IsAccessPointSupported(point)) |
| 562 SetAccessPointRlz(point, rlz_value.substr(0, rlz_length).c_str()); | 563 SetAccessPointRlz(point, rlz_value.substr(0, rlz_length).c_str()); |
| 563 } else if (StartsWithASCII(response_line, events_variable, true)) { | 564 } else if (base::StartsWithASCII(response_line, events_variable, true)) { |
| 564 // Clear events which server parsed. | 565 // Clear events which server parsed. |
| 565 std::vector<ReturnedEvent> event_array; | 566 std::vector<ReturnedEvent> event_array; |
| 566 GetEventsFromResponseString(response_line, events_variable, &event_array); | 567 GetEventsFromResponseString(response_line, events_variable, &event_array); |
| 567 for (size_t i = 0; i < event_array.size(); ++i) { | 568 for (size_t i = 0; i < event_array.size(); ++i) { |
| 568 ClearProductEvent(product, event_array[i].access_point, | 569 ClearProductEvent(product, event_array[i].access_point, |
| 569 event_array[i].event_type); | 570 event_array[i].event_type); |
| 570 } | 571 } |
| 571 } else if (StartsWithASCII(response_line, stateful_events_variable, true)) { | 572 } else if (base::StartsWithASCII(response_line, stateful_events_variable, |
| 573 true)) { |
| 572 // Record any stateful events the server send over. | 574 // Record any stateful events the server send over. |
| 573 std::vector<ReturnedEvent> event_array; | 575 std::vector<ReturnedEvent> event_array; |
| 574 GetEventsFromResponseString(response_line, stateful_events_variable, | 576 GetEventsFromResponseString(response_line, stateful_events_variable, |
| 575 &event_array); | 577 &event_array); |
| 576 for (size_t i = 0; i < event_array.size(); ++i) { | 578 for (size_t i = 0; i < event_array.size(); ++i) { |
| 577 RecordStatefulEvent(product, event_array[i].access_point, | 579 RecordStatefulEvent(product, event_array[i].access_point, |
| 578 event_array[i].event_type); | 580 event_array[i].event_type); |
| 579 } | 581 } |
| 580 } | 582 } |
| 581 } while (line_end_index >= 0); | 583 } while (line_end_index >= 0); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 if (cgi_string.size() >= cgi_size) | 644 if (cgi_string.size() >= cgi_size) |
| 643 return false; | 645 return false; |
| 644 | 646 |
| 645 strncpy(cgi, cgi_string.c_str(), cgi_size); | 647 strncpy(cgi, cgi_string.c_str(), cgi_size); |
| 646 cgi[cgi_size - 1] = 0; | 648 cgi[cgi_size - 1] = 0; |
| 647 | 649 |
| 648 return true; | 650 return true; |
| 649 } | 651 } |
| 650 | 652 |
| 651 } // namespace rlz_lib | 653 } // namespace rlz_lib |
| OLD | NEW |