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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 return false; | 114 return false; |
115 | 115 |
116 // We expect four parts of the file protection listing: for System, Owner, | 116 // We expect four parts of the file protection listing: for System, Owner, |
117 // Group, and World. | 117 // Group, and World. |
118 std::vector<base::string16> parts; | 118 std::vector<base::string16> parts; |
119 base::SplitString(input.substr(1, input.length() - 2), ',', &parts); | 119 base::SplitString(input.substr(1, input.length() - 2), ',', &parts); |
120 if (parts.size() != 4) | 120 if (parts.size() != 4) |
121 return false; | 121 return false; |
122 | 122 |
123 return LooksLikeVmsFileProtectionListingPart(parts[0]) && | 123 return LooksLikeVmsFileProtectionListingPart(parts[0]) && |
124 LooksLikeVmsFileProtectionListingPart(parts[1]) && | 124 LooksLikeVmsFileProtectionListingPart(parts[1]) && |
125 LooksLikeVmsFileProtectionListingPart(parts[2]) && | 125 LooksLikeVmsFileProtectionListingPart(parts[2]) && |
126 LooksLikeVmsFileProtectionListingPart(parts[3]); | 126 LooksLikeVmsFileProtectionListingPart(parts[3]); |
127 } | 127 } |
128 | 128 |
129 bool LooksLikeVmsUserIdentificationCode(const base::string16& input) { | 129 bool LooksLikeVmsUserIdentificationCode(const base::string16& input) { |
130 if (input.length() < 2) | 130 if (input.length() < 2) |
131 return false; | 131 return false; |
132 return input[0] == '[' && input[input.length() - 1] == ']'; | 132 return input[0] == '[' && input[input.length() - 1] == ']'; |
133 } | 133 } |
134 | 134 |
135 bool LooksLikeVMSError(const base::string16& text) { | 135 bool LooksLikeVMSError(const base::string16& text) { |
136 static const char* kPermissionDeniedMessages[] = { | 136 static const char* kPermissionDeniedMessages[] = { |
137 "%RMS-E-FNF", // File not found. | 137 "%RMS-E-FNF", // File not found. |
138 "%RMS-E-PRV", // Access denied. | 138 "%RMS-E-PRV", // Access denied. |
139 "%SYSTEM-F-NOPRIV", | 139 "%SYSTEM-F-NOPRIV", "privilege", |
140 "privilege", | |
141 }; | 140 }; |
142 | 141 |
143 for (size_t i = 0; i < arraysize(kPermissionDeniedMessages); i++) { | 142 for (size_t i = 0; i < arraysize(kPermissionDeniedMessages); i++) { |
144 if (text.find(base::ASCIIToUTF16(kPermissionDeniedMessages[i])) != | 143 if (text.find(base::ASCIIToUTF16(kPermissionDeniedMessages[i])) != |
145 base::string16::npos) | 144 base::string16::npos) |
146 return true; | 145 return true; |
147 } | 146 } |
148 | 147 |
149 return false; | 148 return false; |
150 } | 149 } |
151 | 150 |
152 bool VmsDateListingToTime(const std::vector<base::string16>& columns, | 151 bool VmsDateListingToTime(const std::vector<base::string16>& columns, |
153 base::Time* time) { | 152 base::Time* time) { |
154 DCHECK_EQ(4U, columns.size()); | 153 DCHECK_EQ(4U, columns.size()); |
155 | 154 |
156 base::Time::Exploded time_exploded = { 0 }; | 155 base::Time::Exploded time_exploded = {0}; |
157 | 156 |
158 // Date should be in format DD-MMM-YYYY. | 157 // Date should be in format DD-MMM-YYYY. |
159 std::vector<base::string16> date_parts; | 158 std::vector<base::string16> date_parts; |
160 base::SplitString(columns[2], '-', &date_parts); | 159 base::SplitString(columns[2], '-', &date_parts); |
161 if (date_parts.size() != 3) | 160 if (date_parts.size() != 3) |
162 return false; | 161 return false; |
163 if (!base::StringToInt(date_parts[0], &time_exploded.day_of_month)) | 162 if (!base::StringToInt(date_parts[0], &time_exploded.day_of_month)) |
164 return false; | 163 return false; |
165 if (!FtpUtil::AbbreviatedMonthToNumber(date_parts[1], | 164 if (!FtpUtil::AbbreviatedMonthToNumber(date_parts[1], &time_exploded.month)) |
166 &time_exploded.month)) | |
167 return false; | 165 return false; |
168 if (!base::StringToInt(date_parts[2], &time_exploded.year)) | 166 if (!base::StringToInt(date_parts[2], &time_exploded.year)) |
169 return false; | 167 return false; |
170 | 168 |
171 // Time can be in format HH:MM, HH:MM:SS, or HH:MM:SS.mm. Try to recognize the | 169 // Time can be in format HH:MM, HH:MM:SS, or HH:MM:SS.mm. Try to recognize the |
172 // last type first. Do not parse the seconds, they will be ignored anyway. | 170 // last type first. Do not parse the seconds, they will be ignored anyway. |
173 base::string16 time_column(columns[3]); | 171 base::string16 time_column(columns[3]); |
174 if (time_column.length() == 11 && time_column[8] == '.') | 172 if (time_column.length() == 11 && time_column[8] == '.') |
175 time_column = time_column.substr(0, 8); | 173 time_column = time_column.substr(0, 8); |
176 if (time_column.length() == 8 && time_column[5] == ':') | 174 if (time_column.length() == 8 && time_column[5] == ':') |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 entries->push_back(entry); | 282 entries->push_back(entry); |
285 } | 283 } |
286 | 284 |
287 // The only place where we return true is after receiving the "Total" line, | 285 // The only place where we return true is after receiving the "Total" line, |
288 // that should be present in every VMS listing. Alternatively, if the listing | 286 // that should be present in every VMS listing. Alternatively, if the listing |
289 // contains error messages, it's OK not to have the "Total" line. | 287 // contains error messages, it's OK not to have the "Total" line. |
290 return seen_error; | 288 return seen_error; |
291 } | 289 } |
292 | 290 |
293 } // namespace net | 291 } // namespace net |
OLD | NEW |