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 #include "net/ftp/ftp_directory_listing_parser_vms.h" | 5 #include "net/ftp/ftp_directory_listing_parser_vms.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 if (base::EqualsASCII(filename_parts[1], "DIR")) { | 48 if (base::EqualsASCII(filename_parts[1], "DIR")) { |
49 *parsed_filename = base::ToLowerASCII(filename_parts[0]); | 49 *parsed_filename = base::ToLowerASCII(filename_parts[0]); |
50 *type = FtpDirectoryListingEntry::DIRECTORY; | 50 *type = FtpDirectoryListingEntry::DIRECTORY; |
51 } else { | 51 } else { |
52 *parsed_filename = base::ToLowerASCII(listing_parts[0]); | 52 *parsed_filename = base::ToLowerASCII(listing_parts[0]); |
53 *type = FtpDirectoryListingEntry::FILE; | 53 *type = FtpDirectoryListingEntry::FILE; |
54 } | 54 } |
55 return true; | 55 return true; |
56 } | 56 } |
57 | 57 |
58 bool ParseVmsFilesize(const base::string16& input, int64* size) { | 58 bool ParseVmsFilesize(const base::string16& input, int64_t* size) { |
59 if (base::ContainsOnlyChars(input, base::ASCIIToUTF16("*"))) { | 59 if (base::ContainsOnlyChars(input, base::ASCIIToUTF16("*"))) { |
60 // Response consisting of asterisks means unknown size. | 60 // Response consisting of asterisks means unknown size. |
61 *size = -1; | 61 *size = -1; |
62 return true; | 62 return true; |
63 } | 63 } |
64 | 64 |
65 // VMS's directory listing gives us file size in blocks. We assume that | 65 // VMS's directory listing gives us file size in blocks. We assume that |
66 // the block size is 512 bytes. It doesn't give accurate file size, but is the | 66 // the block size is 512 bytes. It doesn't give accurate file size, but is the |
67 // best information we have. | 67 // best information we have. |
68 const int kBlockSize = 512; | 68 const int kBlockSize = 512; |
69 | 69 |
70 if (base::StringToInt64(input, size)) { | 70 if (base::StringToInt64(input, size)) { |
71 if (*size < 0) | 71 if (*size < 0) |
72 return false; | 72 return false; |
73 *size *= kBlockSize; | 73 *size *= kBlockSize; |
74 return true; | 74 return true; |
75 } | 75 } |
76 | 76 |
77 std::vector<base::StringPiece16> parts = | 77 std::vector<base::StringPiece16> parts = |
78 base::SplitStringPiece(input, base::ASCIIToUTF16("/"), | 78 base::SplitStringPiece(input, base::ASCIIToUTF16("/"), |
79 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 79 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
80 if (parts.size() != 2) | 80 if (parts.size() != 2) |
81 return false; | 81 return false; |
82 | 82 |
83 int64 blocks_used, blocks_allocated; | 83 int64_t blocks_used, blocks_allocated; |
84 if (!base::StringToInt64(parts[0], &blocks_used)) | 84 if (!base::StringToInt64(parts[0], &blocks_used)) |
85 return false; | 85 return false; |
86 if (!base::StringToInt64(parts[1], &blocks_allocated)) | 86 if (!base::StringToInt64(parts[1], &blocks_allocated)) |
87 return false; | 87 return false; |
88 if (blocks_used > blocks_allocated) | 88 if (blocks_used > blocks_allocated) |
89 return false; | 89 return false; |
90 if (blocks_used < 0 || blocks_allocated < 0) | 90 if (blocks_used < 0 || blocks_allocated < 0) |
91 return false; | 91 return false; |
92 | 92 |
93 *size = blocks_used * kBlockSize; | 93 *size = blocks_used * kBlockSize; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 entries->push_back(entry); | 295 entries->push_back(entry); |
296 } | 296 } |
297 | 297 |
298 // The only place where we return true is after receiving the "Total" line, | 298 // The only place where we return true is after receiving the "Total" line, |
299 // that should be present in every VMS listing. Alternatively, if the listing | 299 // that should be present in every VMS listing. Alternatively, if the listing |
300 // contains error messages, it's OK not to have the "Total" line. | 300 // contains error messages, it's OK not to have the "Total" line. |
301 return seen_error; | 301 return seen_error; |
302 } | 302 } |
303 | 303 |
304 } // namespace net | 304 } // namespace net |
OLD | NEW |