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