OLD | NEW |
---|---|
(Empty) | |
1 diff --git a/net/third_party/parseftp/ParseFTPList.cpp b/net/third_party/parseft p/ParseFTPList.cpp | |
2 index b9ffbdc..be099e1 100644 | |
3 --- a/net/third_party/parseftp/ParseFTPList.cpp | |
4 +++ b/net/third_party/parseftp/ParseFTPList.cpp | |
5 @@ -36,15 +36,18 @@ | |
6 * | |
7 * ***** END LICENSE BLOCK ***** */ | |
8 | |
9 -#include <stdlib.h> | |
10 -#include <string.h> | |
11 +#include "net/third_party/parseftp/ParseFTPList.h" | |
12 + | |
13 #include <ctype.h> | |
14 -#include "plstr.h" | |
15 | |
16 -#include "ParseFTPList.h" | |
17 +#include "base/string_util.h" | |
18 + | |
19 +using base::Time; | |
20 | |
21 /* ==================================================================== */ | |
22 | |
23 +namespace net { | |
24 + | |
25 int ParseFTPList(const char *line, struct list_state *state, | |
26 struct list_result *result ) | |
27 { | |
28 @@ -156,11 +159,9 @@ int ParseFTPList(const char *line, struct list_state *state , | |
29 pos++; | |
30 if (pos < linelen && line[pos] == ',') | |
31 { | |
32 - PRTime t; | |
33 - PRTime seconds; | |
34 - PR_sscanf(p+1, "%llu", &seconds); | |
35 - LL_MUL(t, seconds, PR_USEC_PER_SEC); | |
36 - PR_ExplodeTime(t, PR_LocalTimeParameters, &(result->fe_time) ); | |
37 + uint64 seconds = StringToInt64(p+1); | |
38 + Time t = Time::FromTimeT(seconds); | |
39 + t.LocalExplode(&(result->fe_time)); | |
wtc
2009/09/10 18:55:32
We need to subtract 1 from result->fe_time.month a
| |
40 } | |
41 } | |
42 } | |
43 @@ -508,12 +509,9 @@ int ParseFTPList(const char *line, struct list_state *state , | |
44 * So its rounded up to the next block, so what, its better | |
45 * than not showing the size at all. | |
46 */ | |
47 - PRUint64 fsz, factor; | |
48 - LL_UI2L(fsz, strtoul(tokens[1], (char **)0, 10)); | |
49 - LL_UI2L(factor, 512); | |
50 - LL_MUL(fsz, fsz, factor); | |
51 - PR_snprintf(result->fe_size, sizeof(result->fe_size), | |
52 - "%lld", fsz); | |
53 + long long size = strtoul(tokens[1], NULL, 10) * 512; | |
54 + base::snprintf(result->fe_size, sizeof(result->fe_size), "%lld", | |
55 + size); | |
56 } | |
57 | |
58 } /* if (result->fe_type != 'd') */ | |
59 @@ -535,17 +533,17 @@ int ParseFTPList(const char *line, struct list_state *stat e, | |
60 } | |
61 if (month_num >= 12) | |
62 month_num = 0; | |
63 - result->fe_time.tm_month = month_num; | |
64 - result->fe_time.tm_mday = atoi(tokens[2]); | |
65 - result->fe_time.tm_year = atoi(p+4); // NSPR wants year as XXXX | |
66 + result->fe_time.month = month_num; | |
67 + result->fe_time.day_of_month = atoi(tokens[2]); | |
68 + result->fe_time.year = atoi(p+4); | |
69 | |
70 p = tokens[3] + 2; | |
71 if (*p == ':') | |
72 p++; | |
73 if (p[2] == ':') | |
74 - result->fe_time.tm_sec = atoi(p+3); | |
75 - result->fe_time.tm_hour = atoi(tokens[3]); | |
76 - result->fe_time.tm_min = atoi(p); | |
77 + result->fe_time.second = atoi(p+3); | |
78 + result->fe_time.hour = atoi(tokens[3]); | |
79 + result->fe_time.minute = atoi(p); | |
80 | |
81 return result->fe_type; | |
82 | |
83 @@ -678,25 +676,25 @@ int ParseFTPList(const char *line, struct list_state *stat e, | |
84 p = tokens[tokmarker+4]; | |
85 if (toklen[tokmarker+4] == 10) /* newstyle: YYYY-MM-DD format */ | |
86 { | |
87 - result->fe_time.tm_year = atoi(p+0) - 1900; | |
88 - result->fe_time.tm_month = atoi(p+5) - 1; | |
89 - result->fe_time.tm_mday = atoi(p+8); | |
90 + result->fe_time.year = atoi(p+0) - 1900; | |
91 + result->fe_time.month = atoi(p+5) - 1; | |
92 + result->fe_time.day_of_month = atoi(p+8); | |
93 } | |
94 else /* oldstyle: [M]M/DD/YY format */ | |
95 { | |
96 pos = toklen[tokmarker+4]; | |
97 - result->fe_time.tm_month = atoi(p) - 1; | |
98 - result->fe_time.tm_mday = atoi((p+pos)-5); | |
99 - result->fe_time.tm_year = atoi((p+pos)-2); | |
100 - if (result->fe_time.tm_year < 70) | |
101 - result->fe_time.tm_year += 100; | |
102 + result->fe_time.month = atoi(p) - 1; | |
103 + result->fe_time.day_of_month = atoi((p+pos)-5); | |
104 + result->fe_time.year = atoi((p+pos)-2); | |
105 + if (result->fe_time.year < 70) | |
106 + result->fe_time.year += 100; | |
107 } | |
108 | |
109 p = tokens[tokmarker+5]; | |
110 pos = toklen[tokmarker+5]; | |
111 - result->fe_time.tm_hour = atoi(p); | |
112 - result->fe_time.tm_min = atoi((p+pos)-5); | |
113 - result->fe_time.tm_sec = atoi((p+pos)-2); | |
114 + result->fe_time.hour = atoi(p); | |
115 + result->fe_time.minute = atoi((p+pos)-5); | |
116 + result->fe_time.second = atoi((p+pos)-2); | |
117 | |
118 result->fe_cinfs = 1; | |
119 result->fe_fname = tokens[0]; | |
120 @@ -839,25 +837,25 @@ int ParseFTPList(const char *line, struct list_state *stat e, | |
121 } | |
122 } | |
123 | |
124 - result->fe_time.tm_month = atoi(tokens[0]+0); | |
125 - if (result->fe_time.tm_month != 0) | |
126 + result->fe_time.month = atoi(tokens[0]+0); | |
127 + if (result->fe_time.month != 0) | |
128 { | |
129 - result->fe_time.tm_month--; | |
130 - result->fe_time.tm_mday = atoi(tokens[0]+3); | |
131 - result->fe_time.tm_year = atoi(tokens[0]+6); | |
132 + result->fe_time.month--; | |
133 + result->fe_time.day_of_month = atoi(tokens[0]+3); | |
134 + result->fe_time.year = atoi(tokens[0]+6); | |
135 /* if year has only two digits then assume that | |
136 00-79 is 2000-2079 | |
137 80-99 is 1980-1999 */ | |
138 - if (result->fe_time.tm_year < 80) | |
139 - result->fe_time.tm_year += 2000; | |
140 - else if (result->fe_time.tm_year < 100) | |
141 - result->fe_time.tm_year += 1900; | |
142 + if (result->fe_time.year < 80) | |
143 + result->fe_time.year += 2000; | |
144 + else if (result->fe_time.year < 100) | |
145 + result->fe_time.year += 1900; | |
146 } | |
147 | |
148 - result->fe_time.tm_hour = atoi(tokens[1]+0); | |
149 - result->fe_time.tm_min = atoi(tokens[1]+3); | |
150 - if ((tokens[1][5]) == 'P' && result->fe_time.tm_hour < 12) | |
151 - result->fe_time.tm_hour += 12; | |
152 + result->fe_time.hour = atoi(tokens[1]+0); | |
153 + result->fe_time.minute = atoi(tokens[1]+3); | |
154 + if ((tokens[1][5]) == 'P' && result->fe_time.hour < 12) | |
155 + result->fe_time.hour += 12; | |
156 | |
157 /* the caller should do this (if dropping "." and ".." is desired) | |
158 if (result->fe_type == 'd' && result->fe_fname[0] == '.' && | |
159 @@ -955,13 +953,13 @@ int ParseFTPList(const char *line, struct list_state *stat e, | |
160 result->fe_size[pos] = '\0'; | |
161 } | |
162 | |
163 - result->fe_time.tm_month = atoi(&p[35-18]) - 1; | |
164 - result->fe_time.tm_mday = atoi(&p[38-18]); | |
165 - result->fe_time.tm_year = atoi(&p[41-18]); | |
166 - if (result->fe_time.tm_year < 80) | |
167 - result->fe_time.tm_year += 100; | |
168 - result->fe_time.tm_hour = atoi(&p[46-18]); | |
169 - result->fe_time.tm_min = atoi(&p[49-18]); | |
170 + result->fe_time.month = atoi(&p[35-18]) - 1; | |
171 + result->fe_time.day_of_month = atoi(&p[38-18]); | |
172 + result->fe_time.year = atoi(&p[41-18]); | |
173 + if (result->fe_time.year < 80) | |
174 + result->fe_time.year += 100; | |
175 + result->fe_time.hour = atoi(&p[46-18]); | |
176 + result->fe_time.minute = atoi(&p[49-18]); | |
177 | |
178 /* the caller should do this (if dropping "." and ".." is desired) | |
179 if (result->fe_type == 'd' && result->fe_fname[0] == '.' && | |
180 @@ -1006,7 +1004,7 @@ int ParseFTPList(const char *line, struct list_state *stat e, | |
181 * "drwxr-xr-x 2 0 0 512 May 28 22:17 etc" | |
182 */ | |
183 | |
184 - PRBool is_old_Hellsoft = PR_FALSE; | |
185 + bool is_old_Hellsoft = false; | |
186 | |
187 if (numtoks >= 6) | |
188 { | |
189 @@ -1034,7 +1032,7 @@ int ParseFTPList(const char *line, struct list_state *stat e, | |
190 /* rest is FMA[S] or AFM[S] */ | |
191 lstyle = 'U'; /* very likely one of the NetWare servers */ | |
192 if (toklen[0] == 10) | |
193 - is_old_Hellsoft = PR_TRUE; | |
194 + is_old_Hellsoft = true; | |
195 } | |
196 } | |
197 } | |
198 @@ -1150,10 +1148,10 @@ int ParseFTPList(const char *line, struct list_state *st ate, | |
199 result->fe_size[pos] = '\0'; | |
200 } | |
201 | |
202 - result->fe_time.tm_month = month_num; | |
203 - result->fe_time.tm_mday = atoi(tokens[tokmarker+2]); | |
204 - if (result->fe_time.tm_mday == 0) | |
205 - result->fe_time.tm_mday++; | |
206 + result->fe_time.month = month_num; | |
207 + result->fe_time.day_of_month = atoi(tokens[tokmarker+2]); | |
208 + if (result->fe_time.day_of_month == 0) | |
209 + result->fe_time.day_of_month++; | |
210 | |
211 p = tokens[tokmarker+3]; | |
212 pos = (unsigned int)atoi(p); | |
213 @@ -1161,25 +1159,26 @@ int ParseFTPList(const char *line, struct list_state *st ate, | |
214 p--; | |
215 if (p[2] != ':') /* year */ | |
216 { | |
217 - result->fe_time.tm_year = pos; | |
218 + result->fe_time.year = pos; | |
219 } | |
220 else | |
221 { | |
222 - result->fe_time.tm_hour = pos; | |
223 - result->fe_time.tm_min = atoi(p+3); | |
224 + result->fe_time.hour = pos; | |
225 + result->fe_time.minute = atoi(p+3); | |
226 if (p[5] == ':') | |
227 - result->fe_time.tm_sec = atoi(p+6); | |
228 + result->fe_time.second = atoi(p+6); | |
229 | |
230 - if (!state->now_time) | |
231 + if (!state->now_tm_valid) | |
232 { | |
233 - state->now_time = PR_Now(); | |
234 - PR_ExplodeTime((state->now_time), PR_LocalTimeParameters, &(state-> now_tm) ); | |
235 + Time t = Time::Now(); | |
236 + t.LocalExplode(&(state->now_tm)); | |
wtc
2009/09/10 18:55:32
We need to subtract 1 from state->now_tm.month aft
| |
237 + state->now_tm_valid = true; | |
238 } | |
239 | |
240 - result->fe_time.tm_year = state->now_tm.tm_year; | |
241 - if ( (( state->now_tm.tm_month << 5) + state->now_tm.tm_mday) < | |
242 - ((result->fe_time.tm_month << 5) + result->fe_time.tm_mday) ) | |
243 - result->fe_time.tm_year--; | |
244 + result->fe_time.year = state->now_tm.year; | |
245 + if ( (( state->now_tm.month << 5) + state->now_tm.day_of_month) < | |
246 + ((result->fe_time.month << 5) + result->fe_time.day_of_month) ) | |
247 + result->fe_time.year--; | |
248 | |
249 } /* time/year */ | |
250 | |
251 @@ -1197,10 +1196,10 @@ int ParseFTPList(const char *line, struct list_state *st ate, | |
252 { | |
253 /* First try to use result->fe_size to find " -> " sequence. | |
254 This can give proper result for cases like "aaa -> bbb -> ccc". */ | |
255 - PRUint32 fe_size = atoi(result->fe_size); | |
256 + unsigned int fe_size = atoi(result->fe_size); | |
257 | |
258 if (result->fe_fnlen > (fe_size + 4) && | |
259 - PL_strncmp(result->fe_fname + result->fe_fnlen - fe_size - 4 , " -> ", 4) == 0) | |
260 + strncmp(result->fe_fname + result->fe_fnlen - fe_size - 4 , " -> ", 4) == 0) | |
261 { | |
262 result->fe_lname = result->fe_fname + (result->fe_fnlen - fe_size); | |
263 result->fe_lnlen = (&(line[linelen])) - (result->fe_lname); | |
264 @@ -1216,7 +1215,7 @@ int ParseFTPList(const char *line, struct list_state *stat e, | |
265 p = result->fe_fname + (result->fe_fnlen - 5); | |
266 for (pos = (result->fe_fnlen - 5); pos > 0; pos--) | |
267 { | |
268 - if (PL_strncmp(p, " -> ", 4) == 0) | |
269 + if (strncmp(p, " -> ", 4) == 0) | |
270 { | |
271 result->fe_lname = p + 4; | |
272 result->fe_lnlen = (&(line[linelen])) | |
273 @@ -1371,9 +1370,9 @@ int ParseFTPList(const char *line, struct list_state *stat e, | |
274 tbuf[1] == month_names[pos+1] && | |
275 tbuf[2] == month_names[pos+2]) | |
276 { | |
277 - result->fe_time.tm_month = pos/3; | |
278 - result->fe_time.tm_mday = atoi(tokens[3]); | |
279 - result->fe_time.tm_year = atoi(tokens[4]) - 1900; | |
280 + result->fe_time.month = pos/3; | |
281 + result->fe_time.day_of_month = atoi(tokens[3]); | |
282 + result->fe_time.year = atoi(tokens[4]) - 1900; | |
283 break; | |
284 } | |
285 } | |
286 @@ -1381,17 +1380,17 @@ int ParseFTPList(const char *line, struct list_state *st ate, | |
287 } | |
288 else | |
289 { | |
290 - result->fe_time.tm_month = atoi(p+0)-1; | |
291 - result->fe_time.tm_mday = atoi(p+3); | |
292 - result->fe_time.tm_year = atoi(p+6); | |
293 - if (result->fe_time.tm_year < 80) /* SuperTCP */ | |
294 - result->fe_time.tm_year += 100; | |
295 + result->fe_time.month = atoi(p+0)-1; | |
296 + result->fe_time.day_of_month = atoi(p+3); | |
297 + result->fe_time.year = atoi(p+6); | |
298 + if (result->fe_time.year < 80) /* SuperTCP */ | |
299 + result->fe_time.year += 100; | |
300 | |
301 pos = 3; /* SuperTCP toknum of date field */ | |
302 } | |
303 | |
304 - result->fe_time.tm_hour = atoi(tokens[pos]); | |
305 - result->fe_time.tm_min = atoi(&(tokens[pos][toklen[pos]-2])); | |
306 + result->fe_time.hour = atoi(tokens[pos]); | |
307 + result->fe_time.minute = atoi(&(tokens[pos][toklen[pos]-2])); | |
308 | |
309 /* the caller should do this (if dropping "." and ".." is desired) | |
310 if (result->fe_type == 'd' && result->fe_fname[0] == '.' && | |
311 @@ -1607,7 +1606,7 @@ int ParseFTPList(const char *line, struct list_state *stat e, | |
312 pos = atoi(tokens[pos]); | |
313 if (pos > 0 && pos <= 31) | |
314 { | |
315 - result->fe_time.tm_mday = pos; | |
316 + result->fe_time.day_of_month = pos; | |
317 month_num = 1; | |
318 for (pos = 0; pos < (12*3); pos+=3) | |
319 { | |
320 @@ -1618,34 +1617,35 @@ int ParseFTPList(const char *line, struct list_state *st ate, | |
321 month_num++; | |
322 } | |
323 if (month_num > 12) | |
324 - result->fe_time.tm_mday = 0; | |
325 + result->fe_time.day_of_month = 0; | |
326 else | |
327 - result->fe_time.tm_month = month_num - 1; | |
328 + result->fe_time.month = month_num - 1; | |
329 } | |
330 } | |
331 - if (result->fe_time.tm_mday) | |
332 + if (result->fe_time.day_of_month) | |
333 { | |
334 tokmarker += 3; /* skip mday/mon/yrtime (to find " -> ") */ | |
335 p = tokens[tokmarker]; | |
336 | |
337 pos = atoi(p); | |
338 if (pos > 24) | |
339 - result->fe_time.tm_year = pos-1900; | |
340 + result->fe_time.year = pos-1900; | |
341 else | |
342 { | |
343 if (p[1] == ':') | |
344 p--; | |
345 - result->fe_time.tm_hour = pos; | |
346 - result->fe_time.tm_min = atoi(p+3); | |
347 - if (!state->now_time) | |
348 + result->fe_time.hour = pos; | |
349 + result->fe_time.minute = atoi(p+3); | |
350 + if (!state->now_tm_valid) | |
351 { | |
352 - state->now_time = PR_Now(); | |
353 - PR_ExplodeTime((state->now_time), PR_LocalTimeParameters, &(s tate->now_tm) ); | |
354 + Time t = Time::Now(); | |
355 + t.LocalExplode(&(state->now_tm)); | |
wtc
2009/09/10 18:55:32
We need to subtract 1 from state->now_tm.month aft
| |
356 + state->now_tm_valid = true; | |
357 } | |
358 - result->fe_time.tm_year = state->now_tm.tm_year; | |
359 - if ( (( state->now_tm.tm_month << 4) + state->now_tm.tm_mday) < | |
360 - ((result->fe_time.tm_month << 4) + result->fe_time.tm_mday ) ) | |
361 - result->fe_time.tm_year--; | |
362 + result->fe_time.year = state->now_tm.year; | |
363 + if ( (( state->now_tm.month << 4) + state->now_tm.day_of_month ) < | |
364 + ((result->fe_time.month << 4) + result->fe_time.day_of_mon th) ) | |
365 + result->fe_time.year--; | |
366 } /* got year or time */ | |
367 } /* got month/mday */ | |
368 } /* may have year or time */ | |
369 @@ -1893,3 +1893,5 @@ int main(int argc, char *argv[]) | |
370 return 0; | |
371 } | |
372 #endif | |
373 + | |
374 +} // namespace net | |
375 diff --git a/net/third_party/parseftp/ParseFTPList.h b/net/third_party/parseftp/ ParseFTPList.h | |
376 index 30ef8a3..b11abdc 100644 | |
377 --- a/net/third_party/parseftp/ParseFTPList.h | |
378 +++ b/net/third_party/parseftp/ParseFTPList.h | |
379 @@ -35,7 +35,11 @@ | |
380 * the terms of any one of the MPL, the GPL or the LGPL. | |
381 * | |
382 * ***** END LICENSE BLOCK ***** */ | |
383 -#include "nspr.h" | |
384 + | |
385 +#ifndef NET_THIRD_PARTY_PARSEFTP_PARSEFTPLIST_H_ | |
386 +#define NET_THIRD_PARTY_PARSEFTP_PARSEFTPLIST_H_ | |
387 + | |
388 +#include "base/time.h" | |
389 | |
390 /* ParseFTPList() parses lines from an FTP LIST command. | |
391 ** | |
392 @@ -96,28 +100,30 @@ | |
393 #define SUPPORT_OS2 /* IBM TCP/IP for OS/2 - FTP Server */ | |
394 #define SUPPORT_W16 /* win16 hosts: SuperTCP or NetManage Chameleon */ | |
395 | |
396 +namespace net { | |
wtc
2009/09/10 18:55:32
Let's add a comment here about the 'month' field
o
| |
397 + | |
398 struct list_state | |
399 { | |
400 void *magic; /* to determine if previously initialized */ | |
401 - PRTime now_time; /* needed for year determination */ | |
402 - PRExplodedTime now_tm; /* needed for year determination */ | |
403 - PRInt32 lstyle; /* LISTing style */ | |
404 - PRInt32 parsed_one; /* returned anything yet? */ | |
405 + bool now_tm_valid; /* true if now_tm is valid */ | |
406 + base::Time::Exploded now_tm; /* needed for year determination */ | |
407 + int lstyle; /* LISTing style */ | |
408 + int parsed_one; /* returned anything yet? */ | |
409 char carry_buf[84]; /* for VMS multiline */ | |
410 - PRUint32 carry_buf_len; /* length of name in carry_buf */ | |
411 - PRUint32 numlines; /* number of lines seen */ | |
412 + unsigned int carry_buf_len; /* length of name in carry_buf */ | |
413 + unsigned int numlines; /* number of lines seen */ | |
414 }; | |
415 | |
416 struct list_result | |
417 { | |
418 - PRInt32 fe_type; /* 'd'(dir) or 'l'(link) or 'f'(file) */ | |
419 + int fe_type; /* 'd'(dir) or 'l'(link) or 'f'(file) */ | |
420 const char * fe_fname; /* pointer to filename */ | |
421 - PRUint32 fe_fnlen; /* length of filename */ | |
422 + unsigned int fe_fnlen; /* length of filename */ | |
423 const char * fe_lname; /* pointer to symlink name */ | |
424 - PRUint32 fe_lnlen; /* length of symlink name */ | |
425 + unsigned int fe_lnlen; /* length of symlink name */ | |
426 char fe_size[40]; /* size of file in bytes (<= (2^128 - 1)) */ | |
427 - PRExplodedTime fe_time; /* last-modified time */ | |
428 - PRInt32 fe_cinfs; /* file system is definitely case insensitive */ | |
429 + base::Time::Exploded fe_time; /* last-modified time */ | |
430 + int fe_cinfs; /* file system is definitely case insensitive */ | |
431 /* (converting all-upcase names may be desira ble) */ | |
432 }; | |
433 | |
434 @@ -125,3 +131,6 @@ int ParseFTPList(const char *line, | |
435 struct list_state *state, | |
436 struct list_result *result ); | |
437 | |
438 +} // namespace net | |
439 + | |
440 +#endif // NET_THIRD_PARTY_PARSEFTP_PARSEFTPLIST_H_ | |
OLD | NEW |