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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 normalized_rlz[index] = 0; | 97 normalized_rlz[index] = 0; |
98 } | 98 } |
99 | 99 |
100 void GetEventsFromResponseString( | 100 void GetEventsFromResponseString( |
101 const std::string& response_line, | 101 const std::string& response_line, |
102 const std::string& field_header, | 102 const std::string& field_header, |
103 std::vector<ReturnedEvent>* event_array) { | 103 std::vector<ReturnedEvent>* event_array) { |
104 // Get the string of events. | 104 // Get the string of events. |
105 std::string events = response_line.substr(field_header.size()); | 105 std::string events = response_line.substr(field_header.size()); |
106 TrimWhitespaceASCII(events, TRIM_LEADING, &events); | 106 base::TrimWhitespaceASCII(events, base::TRIM_LEADING, &events); |
107 | 107 |
108 int events_length = events.find_first_of("\r\n "); | 108 int events_length = events.find_first_of("\r\n "); |
109 if (events_length < 0) | 109 if (events_length < 0) |
110 events_length = events.size(); | 110 events_length = events.size(); |
111 events = events.substr(0, events_length); | 111 events = events.substr(0, events_length); |
112 | 112 |
113 // Break this up into individual events | 113 // Break this up into individual events |
114 int event_end_index = -1; | 114 int event_end_index = -1; |
115 do { | 115 do { |
116 int event_begin = event_end_index + 1; | 116 int event_begin = event_end_index + 1; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) |
436 checksum_end = response_string.size(); | 436 checksum_end = response_string.size(); |
437 | 437 |
438 int checksum_begin = checksum_index + checksum_param.size(); | 438 int checksum_begin = checksum_index + checksum_param.size(); |
439 std::string checksum = response_string.substr(checksum_begin, | 439 std::string checksum = response_string.substr(checksum_begin, |
440 checksum_end - checksum_begin + 1); | 440 checksum_end - checksum_begin + 1); |
441 TrimWhitespaceASCII(checksum, TRIM_ALL, &checksum); | 441 base::TrimWhitespaceASCII(checksum, base::TRIM_ALL, &checksum); |
442 | 442 |
443 if (checksum_idx) | 443 if (checksum_idx) |
444 *checksum_idx = checksum_index; | 444 *checksum_idx = checksum_index; |
445 | 445 |
446 return calculated_crc == HexStringToInteger(checksum.c_str()); | 446 return calculated_crc == HexStringToInteger(checksum.c_str()); |
447 } | 447 } |
448 | 448 |
449 // Complex helpers built on top of other functions. | 449 // Complex helpers built on top of other functions. |
450 | 450 |
451 bool ParseFinancialPingResponse(Product product, const char* response) { | 451 bool ParseFinancialPingResponse(Product product, const char* response) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 // Get the access point. | 542 // Get the access point. |
543 std::string point_name = | 543 std::string point_name = |
544 response_line.substr(3, separator_index - rlz_cgi_length); | 544 response_line.substr(3, separator_index - rlz_cgi_length); |
545 AccessPoint point = NO_ACCESS_POINT; | 545 AccessPoint point = NO_ACCESS_POINT; |
546 if (!GetAccessPointFromName(point_name.c_str(), &point) || | 546 if (!GetAccessPointFromName(point_name.c_str(), &point) || |
547 point == NO_ACCESS_POINT) | 547 point == NO_ACCESS_POINT) |
548 continue; // Not a valid access point. | 548 continue; // Not a valid access point. |
549 | 549 |
550 // Get the new RLZ. | 550 // Get the new RLZ. |
551 std::string rlz_value(response_line.substr(separator_index + 2)); | 551 std::string rlz_value(response_line.substr(separator_index + 2)); |
552 TrimWhitespaceASCII(rlz_value, TRIM_LEADING, &rlz_value); | 552 base::TrimWhitespaceASCII(rlz_value, base::TRIM_LEADING, &rlz_value); |
553 | 553 |
554 size_t rlz_length = rlz_value.find_first_of("\r\n "); | 554 size_t rlz_length = rlz_value.find_first_of("\r\n "); |
555 if (rlz_length == std::string::npos) | 555 if (rlz_length == std::string::npos) |
556 rlz_length = rlz_value.size(); | 556 rlz_length = rlz_value.size(); |
557 | 557 |
558 if (rlz_length > kMaxRlzLength) | 558 if (rlz_length > kMaxRlzLength) |
559 continue; // Too long. | 559 continue; // Too long. |
560 | 560 |
561 if (IsAccessPointSupported(point)) | 561 if (IsAccessPointSupported(point)) |
562 SetAccessPointRlz(point, rlz_value.substr(0, rlz_length).c_str()); | 562 SetAccessPointRlz(point, rlz_value.substr(0, rlz_length).c_str()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 if (cgi_string.size() >= cgi_size) | 642 if (cgi_string.size() >= cgi_size) |
643 return false; | 643 return false; |
644 | 644 |
645 strncpy(cgi, cgi_string.c_str(), cgi_size); | 645 strncpy(cgi, cgi_string.c_str(), cgi_size); |
646 cgi[cgi_size - 1] = 0; | 646 cgi[cgi_size - 1] = 0; |
647 | 647 |
648 return true; | 648 return true; |
649 } | 649 } |
650 | 650 |
651 } // namespace rlz_lib | 651 } // namespace rlz_lib |
OLD | NEW |