Bug 1402151, part 7 - Add a time zone argument to ParseFTPList. r=michal draft
authorAndrew McCreight <continuation@gmail.com>
Mon, 25 Sep 2017 11:45:27 -0700
changeset 680197 a9149aa36295316231d9e2987cf45deca9cf962e
parent 680196 f67e375c9dbfb247aa9e538cb299a503d6298535
child 680198 6a39a32f1cc64b10466a12044d97680ec07ecabb
push id84417
push userbmo:continuation@gmail.com
push dateFri, 13 Oct 2017 16:41:48 +0000
reviewersmichal
bugs1402151
milestone58.0a1
Bug 1402151, part 7 - Add a time zone argument to ParseFTPList. r=michal In a few places, the FTP parser needs to know the time zone and daylight savings time correction, encapsulated in PRTimeParamFn. Before this patch, it would use the time zone of the current machine, which would obviously make automated testing difficult. This patch allows a caller to pass in a PRTimeParamFn, which will allow the gtest to use GMT instead of whatever the local time is. MozReview-Commit-ID: 81R3Zbndr43
netwerk/streamconv/converters/ParseFTPList.cpp
netwerk/streamconv/converters/ParseFTPList.h
--- a/netwerk/streamconv/converters/ParseFTPList.cpp
+++ b/netwerk/streamconv/converters/ParseFTPList.cpp
@@ -35,17 +35,17 @@ FixupYear(PRExplodedTime* aTime)
   if (aTime->tm_year < 80) {
     aTime->tm_year += 2000;
   } else if (aTime->tm_year < 100) {
     aTime->tm_year += 1900;
   }
 }
 
 int ParseFTPList(const char *line, struct list_state *state,
-                 struct list_result *result )
+                 struct list_result *result, PRTimeParamFn timeParam)
 {
   unsigned int carry_buf_len; /* copy of state->carry_buf_len */
   unsigned int pos;
   const char *p;
 
   if (!line || !state || !result)
     return 0;
 
@@ -145,17 +145,17 @@ int ParseFTPList(const char *line, struc
               while (pos < linelen && isdigit(line[pos]))
                 pos++;
               if (pos < linelen && line[pos] == ',')
               {
                 PRTime t;
                 PRTime seconds;
                 PR_sscanf(p+1, "%llu", &seconds);
                 t = seconds * PR_USEC_PER_SEC;
-                PR_ExplodeTime(t, PR_LocalTimeParameters, &(result->fe_time) );
+                PR_ExplodeTime(t, timeParam, &(result->fe_time) );
               }
             }
           }
           else if (*p == 's')
           {
             if (isdigit(line[pos]))
             {
               while (pos < linelen && isdigit(line[pos]))
@@ -1134,17 +1134,17 @@ int ParseFTPList(const char *line, struc
           result->fe_time.tm_hour = pos;
           result->fe_time.tm_min  = atoi(p+3);
           if (p[5] == ':')
             result->fe_time.tm_sec = atoi(p+6);
 
           if (!state->now_time)
           {
             state->now_time = PR_Now();
-            PR_ExplodeTime((state->now_time), PR_LocalTimeParameters, &(state->now_tm) );
+            PR_ExplodeTime((state->now_time), timeParam, &(state->now_tm) );
           }
 
           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--;
 
         } /* time/year */
@@ -1612,17 +1612,17 @@ int ParseFTPList(const char *line, struc
               {
                 if (p[1] == ':')
                   p--;
                 result->fe_time.tm_hour = pos;
                 result->fe_time.tm_min = atoi(p+3);
                 if (!state->now_time)
                 {
                   state->now_time = PR_Now();
-                  PR_ExplodeTime((state->now_time), PR_LocalTimeParameters, &(state->now_tm) );
+                  PR_ExplodeTime((state->now_time), timeParam, &(state->now_tm) );
                 }
                 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--;
               } /* got year or time */
             } /* got month/mday */
           } /* may have year or time */
--- a/netwerk/streamconv/converters/ParseFTPList.h
+++ b/netwerk/streamconv/converters/ParseFTPList.h
@@ -94,11 +94,12 @@ struct list_result
   char              fe_size[40];  /* size of file in bytes (<= (2^128 - 1)) */
   PRExplodedTime    fe_time;      /* last-modified time */
   int32_t           fe_cinfs;     /* file system is definitely case insensitive */
                                   /* (converting all-upcase names may be desirable) */
 };
 
 int ParseFTPList(const char *line,
                  struct list_state *state,
-                 struct list_result *result );
+                 struct list_result *result,
+                 PRTimeParamFn timeParam = PR_LocalTimeParameters);
 
 #endif /* !ParseRTPList_h___ */