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
--- 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___ */