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 (!base::StartsWithASCII(response_string, checksum_param, true)) | 425 if (!base::StartsWith(response_string, checksum_param, |
| 426 base::CompareCase::SENSITIVE)) |
426 return false; | 427 return false; |
427 | 428 |
428 checksum_index = 0; | 429 checksum_index = 0; |
429 if (!Crc32("", &calculated_crc)) | 430 if (!Crc32("", &calculated_crc)) |
430 return false; | 431 return false; |
431 } | 432 } |
432 | 433 |
433 // Find the checksum value on the response. | 434 // Find the checksum value on the response. |
434 int checksum_end = response_string.find("\n", checksum_index + 1); | 435 int checksum_end = response_string.find("\n", checksum_index + 1); |
435 if (checksum_end < 0) | 436 if (checksum_end < 0) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 int line_end = line_end_index; | 528 int line_end = line_end_index; |
528 if (line_end < 0) | 529 if (line_end < 0) |
529 line_end = response_length; | 530 line_end = response_length; |
530 | 531 |
531 if (line_end <= line_begin) | 532 if (line_end <= line_begin) |
532 continue; // Empty line. | 533 continue; // Empty line. |
533 | 534 |
534 std::string response_line; | 535 std::string response_line; |
535 response_line = response_string.substr(line_begin, line_end - line_begin); | 536 response_line = response_string.substr(line_begin, line_end - line_begin); |
536 | 537 |
537 if (base::StartsWithASCII(response_line, kRlzCgiVariable, | 538 if (base::StartsWith(response_line, kRlzCgiVariable, |
538 true)) { // An RLZ. | 539 base::CompareCase::SENSITIVE)) { // An RLZ. |
539 int separator_index = -1; | 540 int separator_index = -1; |
540 if ((separator_index = response_line.find(": ")) < 0) | 541 if ((separator_index = response_line.find(": ")) < 0) |
541 continue; // Not a valid key-value pair. | 542 continue; // Not a valid key-value pair. |
542 | 543 |
543 // Get the access point. | 544 // Get the access point. |
544 std::string point_name = | 545 std::string point_name = |
545 response_line.substr(3, separator_index - rlz_cgi_length); | 546 response_line.substr(3, separator_index - rlz_cgi_length); |
546 AccessPoint point = NO_ACCESS_POINT; | 547 AccessPoint point = NO_ACCESS_POINT; |
547 if (!GetAccessPointFromName(point_name.c_str(), &point) || | 548 if (!GetAccessPointFromName(point_name.c_str(), &point) || |
548 point == NO_ACCESS_POINT) | 549 point == NO_ACCESS_POINT) |
549 continue; // Not a valid access point. | 550 continue; // Not a valid access point. |
550 | 551 |
551 // Get the new RLZ. | 552 // Get the new RLZ. |
552 std::string rlz_value(response_line.substr(separator_index + 2)); | 553 std::string rlz_value(response_line.substr(separator_index + 2)); |
553 base::TrimWhitespaceASCII(rlz_value, base::TRIM_LEADING, &rlz_value); | 554 base::TrimWhitespaceASCII(rlz_value, base::TRIM_LEADING, &rlz_value); |
554 | 555 |
555 size_t rlz_length = rlz_value.find_first_of("\r\n "); | 556 size_t rlz_length = rlz_value.find_first_of("\r\n "); |
556 if (rlz_length == std::string::npos) | 557 if (rlz_length == std::string::npos) |
557 rlz_length = rlz_value.size(); | 558 rlz_length = rlz_value.size(); |
558 | 559 |
559 if (rlz_length > kMaxRlzLength) | 560 if (rlz_length > kMaxRlzLength) |
560 continue; // Too long. | 561 continue; // Too long. |
561 | 562 |
562 if (IsAccessPointSupported(point)) | 563 if (IsAccessPointSupported(point)) |
563 SetAccessPointRlz(point, rlz_value.substr(0, rlz_length).c_str()); | 564 SetAccessPointRlz(point, rlz_value.substr(0, rlz_length).c_str()); |
564 } else if (base::StartsWithASCII(response_line, events_variable, true)) { | 565 } else if (base::StartsWith(response_line, events_variable, |
| 566 base::CompareCase::SENSITIVE)) { |
565 // Clear events which server parsed. | 567 // Clear events which server parsed. |
566 std::vector<ReturnedEvent> event_array; | 568 std::vector<ReturnedEvent> event_array; |
567 GetEventsFromResponseString(response_line, events_variable, &event_array); | 569 GetEventsFromResponseString(response_line, events_variable, &event_array); |
568 for (size_t i = 0; i < event_array.size(); ++i) { | 570 for (size_t i = 0; i < event_array.size(); ++i) { |
569 ClearProductEvent(product, event_array[i].access_point, | 571 ClearProductEvent(product, event_array[i].access_point, |
570 event_array[i].event_type); | 572 event_array[i].event_type); |
571 } | 573 } |
572 } else if (base::StartsWithASCII(response_line, stateful_events_variable, | 574 } else if (base::StartsWith(response_line, stateful_events_variable, |
573 true)) { | 575 base::CompareCase::SENSITIVE)) { |
574 // Record any stateful events the server send over. | 576 // Record any stateful events the server send over. |
575 std::vector<ReturnedEvent> event_array; | 577 std::vector<ReturnedEvent> event_array; |
576 GetEventsFromResponseString(response_line, stateful_events_variable, | 578 GetEventsFromResponseString(response_line, stateful_events_variable, |
577 &event_array); | 579 &event_array); |
578 for (size_t i = 0; i < event_array.size(); ++i) { | 580 for (size_t i = 0; i < event_array.size(); ++i) { |
579 RecordStatefulEvent(product, event_array[i].access_point, | 581 RecordStatefulEvent(product, event_array[i].access_point, |
580 event_array[i].event_type); | 582 event_array[i].event_type); |
581 } | 583 } |
582 } | 584 } |
583 } while (line_end_index >= 0); | 585 } while (line_end_index >= 0); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 if (cgi_string.size() >= cgi_size) | 646 if (cgi_string.size() >= cgi_size) |
645 return false; | 647 return false; |
646 | 648 |
647 strncpy(cgi, cgi_string.c_str(), cgi_size); | 649 strncpy(cgi, cgi_string.c_str(), cgi_size); |
648 cgi[cgi_size - 1] = 0; | 650 cgi[cgi_size - 1] = 0; |
649 | 651 |
650 return true; | 652 return true; |
651 } | 653 } |
652 | 654 |
653 } // namespace rlz_lib | 655 } // namespace rlz_lib |
OLD | NEW |