Get the latest ParseFTPList code from Mozilla, and apply only the absolutely

required changes.

This way future merging would be much easier.

TEST=none
BUG=none

Review URL: http://codereview.chromium.org/201034

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25878 0039d316-1c4b-4281-b951-d872f2087c98
parent 7f113f39
This source diff could not be displayed because it is too large. You can view the blob instead.
// Version: MPL 1.1/GPL 2.0/LGPL 2.1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// /* ***** BEGIN LICENSE BLOCK *****
// The contents of this file are subject to the Mozilla Public License Version * Version: MPL 1.1/GPL 2.0/LGPL 2.1
// 1.1 (the "License"); you may not use this file except in compliance with *
// the License. You may obtain a copy of the License at * The contents of this file are subject to the Mozilla Public License Version
// http://www.mozilla.org/MPL/ * 1.1 (the "License"); you may not use this file except in compliance with
// Software distributed under the License is distributed on an "AS IS" basis, * the License. You may obtain a copy of the License at
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * http://www.mozilla.org/MPL/
// for the specific language governing rights and limitations under the *
// License. * Software distributed under the License is distributed on an "AS IS" basis,
// * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// The Original Code is mozilla.org Code. * for the specific language governing rights and limitations under the
// * License.
// The Initial Developer of the Original Code is *
// Cyrus Patel <cyp@fb14.uni-mainz.de>. * The Original Code is mozilla.org Code.
// Portions created by the Initial Developer are Copyright (C) 2002 *
// the Initial Developer. All Rights Reserved. * The Initial Developer of the Original Code is
// * Cyrus Patel <cyp@fb14.uni-mainz.de>.
// Contributor(s): * Portions created by the Initial Developer are Copyright (C) 2002
// Doug Turner <dougt@netscape.com> * the Initial Developer. All Rights Reserved.
// *
// Alternatively, the contents of this file may be used under the terms of * Contributor(s):
// either the GNU General Public License Version 2 or later (the "GPL"), or * Doug Turner <dougt@netscape.com>
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), *
// in which case the provisions of the GPL or the LGPL are applicable instead * Alternatively, the contents of this file may be used under the terms of
// of those above. If you wish to allow use of your version of this file only * either the GNU General Public License Version 2 or later (the "GPL"), or
// under the terms of either the GPL or the LGPL, and not to allow others to * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
// use your version of this file under the terms of the MPL, indicate your * in which case the provisions of the GPL or the LGPL are applicable instead
// decision by deleting the provisions above and replace them with the notice * of those above. If you wish to allow use of your version of this file only
// and other provisions required by the GPL or the LGPL. If you do not delete * under the terms of either the GPL or the LGPL, and not to allow others to
// the provisions above, a recipient may use your version of this file under * use your version of this file under the terms of the MPL, indicate your
// the terms of any one of the MPL, the GPL or the LGPL. * decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Derived from: #ifndef NET_THIRD_PARTY_PARSEFTP_PARSEFTPLIST_H_
// mozilla/netwerk/streamconv/converters/ParseFTPList.h revision 1.3 #define NET_THIRD_PARTY_PARSEFTP_PARSEFTPLIST_H_
#include "base/time.h"
#ifndef NET_THIRD_PARTY_PARSEFTP_FTP_DIRECTORY_PARSER_H_ /* ParseFTPList() parses lines from an FTP LIST command.
#define NET_THIRD_PARTY_PARSEFTP_FTP_DIRECTORY_PARSER_H_ **
** Written July 2002 by Cyrus Patel <cyp@fb14.uni-mainz.de>
** with acknowledgements to squid, lynx, wget and ftpmirror.
**
** Arguments:
** 'line': line of FTP data connection output. The line is assumed
** to end at the first '\0' or '\n' or '\r\n'.
** 'state': a structure used internally to track state between
** lines. Needs to be bzero()'d at LIST begin.
** 'result': where ParseFTPList will store the results of the parse
** if 'line' is not a comment and is not junk.
**
** Returns one of the following:
** 'd' - LIST line is a directory entry ('result' is valid)
** 'f' - LIST line is a file's entry ('result' is valid)
** 'l' - LIST line is a symlink's entry ('result' is valid)
** '?' - LIST line is junk. (cwd, non-file/dir/link, etc)
** '"' - its not a LIST line (its a "comment")
**
** It may be advisable to let the end-user see "comments" (particularly when
** the listing results in ONLY such lines) because such a listing may be:
** - an unknown LIST format (NLST or "custom" format for example)
** - an error msg (EPERM,ENOENT,ENFILE,EMFILE,ENOTDIR,ENOTBLK,EEXDEV etc).
** - an empty directory and the 'comment' is a "total 0" line or similar.
** (warning: a "total 0" can also mean the total size is unknown).
**
** ParseFTPList() supports all known FTP LISTing formats:
** - '/bin/ls -l' and all variants (including Hellsoft FTP for NetWare);
** - EPLF (Easily Parsable List Format);
** - Windows NT's default "DOS-dirstyle";
** - OS/2 basic server format LIST format;
** - VMS (MultiNet, UCX, and CMU) LIST format (including multi-line format);
** - IBM VM/CMS, VM/ESA LIST format (two known variants);
** - SuperTCP FTP Server for Win16 LIST format;
** - NetManage Chameleon (NEWT) for Win16 LIST format;
** - '/bin/dls' (two known variants, plus multi-line) LIST format;
** If there are others, then I'd like to hear about them (send me a sample).
**
** NLSTings are not supported explicitely because they cannot be machine
** parsed consistently: NLSTings do not have unique characteristics - even
** the assumption that there won't be whitespace on the line does not hold
** because some nlistings have more than one filename per line and/or
** may have filenames that have spaces in them. Moreover, distinguishing
** between an error message and an NLST line would require ParseList() to
** recognize all the possible strerror() messages in the world.
*/
#include "base/time.h"
namespace net { /* #undef anything you don't want to support */
#define SUPPORT_LSL /* /bin/ls -l and dozens of variations therof */
#define SUPPORT_DLS /* /bin/dls format (very, Very, VERY rare) */
#define SUPPORT_EPLF /* Extraordinarily Pathetic List Format */
#define SUPPORT_DOS /* WinNT server in 'site dirstyle' dos */
#define SUPPORT_VMS /* VMS (all: MultiNet, UCX, CMU-IP) */
#define SUPPORT_CMS /* IBM VM/CMS,VM/ESA (z/VM and LISTING forms) */
#define SUPPORT_OS2 /* IBM TCP/IP for OS/2 - FTP Server */
#define SUPPORT_W16 /* win16 hosts: SuperTCP or NetManage Chameleon */
struct ListState { namespace net {
void* magic; // to determine if previously
// initialized.
int now_tm_valid; // now_tm contains a valid time?
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.
unsigned int carry_buf_len; // length of name in carry_buf.
unsigned int numlines; // number of lines seen.
};
enum LineType { struct list_state
FTP_TYPE_DIRECTORY, // LIST line is a directory entry ('result' is valid). {
FTP_TYPE_FILE, // LIST line is a file's entry ('result' is valid). void *magic; /* to determine if previously initialized */
FTP_TYPE_SYMLINK, // LIST line is a symlink's entry ('result' is valid). bool now_tm_valid; /* true if now_tm is valid */
FTP_TYPE_JUNK, // LIST line is junk. (cwd, non-file/dir/link, etc). base::Time::Exploded now_tm; /* needed for year determination */
FTP_TYPE_COMMENT // Its not a LIST line (its a "comment"). int lstyle; /* LISTing style */
int parsed_one; /* returned anything yet? */
char carry_buf[84]; /* for VMS multiline */
unsigned int carry_buf_len; /* length of name in carry_buf */
unsigned int numlines; /* number of lines seen */
}; };
struct ListResult { struct list_result
LineType fe_type; {
const char* fe_fname; // pointer to filename int fe_type; /* 'd'(dir) or 'l'(link) or 'f'(file) */
unsigned int fe_fnlen; // length of filename const char * fe_fname; /* pointer to filename */
const char* fe_lname; // pointer to symlink name unsigned int fe_fnlen; /* length of filename */
unsigned int fe_lnlen; // length of symlink name const char * fe_lname; /* pointer to symlink name */
char fe_size[40]; // size of file in bytes unsigned int fe_lnlen; /* length of symlink name */
// (<= (2^128 - 1)) char fe_size[40]; /* size of file in bytes (<= (2^128 - 1)) */
base::Time::Exploded fe_time; // last-modified time base::Time::Exploded fe_time; /* last-modified time */
int fe_cinfs; // file system is definitely int fe_cinfs; /* file system is definitely case insensitive */
// case insensitive /* (converting all-upcase names may be desirable) */
}; };
// ParseFTPLine() parses line from an FTP LIST command. int ParseFTPList(const char *line,
// struct list_state *state,
// Written July 2002 by Cyrus Patel <cyp@fb14.uni-mainz.de> struct list_result *result );
// with acknowledgements to squid, lynx, wget and ftpmirror.
//
// Arguments:
// 'line': line of FTP data connection output. The line is assumed
// to end at the first '\0' or '\n' or '\r\n'.
// 'state': a structure used internally to track state between
// lines. Needs to be bzero()'d at LIST begin.
// 'result': where ParseFTPList will store the results of the parse
// if 'line' is not a comment and is not junk.
//
// Returns one of the following:
// 'd' - LIST line is a directory entry ('result' is valid)
// 'f' - LIST line is a file's entry ('result' is valid)
// 'l' - LIST line is a symlink's entry ('result' is valid)
// '?' - LIST line is junk. (cwd, non-file/dir/link, etc)
// '"' - its not a LIST line (its a "comment")
//
// It may be advisable to let the end-user see "comments" (particularly when
// the listing results in ONLY such lines) because such a listing may be:
// - an unknown LIST format (NLST or "custom" format for example)
// - an error msg (EPERM,ENOENT,ENFILE,EMFILE,ENOTDIR,ENOTBLK,EEXDEV etc).
// - an empty directory and the 'comment' is a "total 0" line or similar.
// (warning: a "total 0" can also mean the total size is unknown).
//
// ParseFTPList() supports all known FTP LISTing formats:
// - '/bin/ls -l' and all variants (including Hellsoft FTP for NetWare);
// - EPLF (Easily Parsable List Format);
// - Windows NT's default "DOS-dirstyle";
// - OS/2 basic server format LIST format;
// - VMS (MultiNet, UCX, and CMU) LIST format (including multi-line format);
// - IBM VM/CMS, VM/ESA LIST format (two known variants);
// - SuperTCP FTP Server for Win16 LIST format;
// - NetManage Chameleon (NEWT) for Win16 LIST format;
// - '/bin/dls' (two known variants, plus multi-line) LIST format;
// If there are others, then I'd like to hear about them (send me a sample).
//
// NLSTings are not supported explicitely because they cannot be machine
// parsed consistently: NLSTings do not have unique characteristics - even
// the assumption that there won't be whitespace on the line does not hold
// because some nlistings have more than one filename per line and/or
// may have filenames that have spaces in them. Moreover, distinguishing
// between an error message and an NLST line would require ParseList() to
// recognize all the possible strerror() messages in the world.
LineType ParseFTPLine(const char *line,
struct ListState *state,
struct ListResult *result);
} // namespace net } // namespace net
#endif // NET_THIRD_PARTY_PARSEFTP_FTP_DIRECTORY_PARSER_H_ #endif // NET_THIRD_PARTY_PARSEFTP_PARSEFTPLIST_H_
...@@ -3,6 +3,7 @@ This directory contains Mozilla FTP LIST response parsing routines. ...@@ -3,6 +3,7 @@ This directory contains Mozilla FTP LIST response parsing routines.
The original code location was mozilla/netwerk/streamconv/converters/ParseFTPList.{cpp,h} The original code location was mozilla/netwerk/streamconv/converters/ParseFTPList.{cpp,h}
List of changes made to original code: List of changes made to original code:
- style adjustment for Chromium
- wrapped the routines in net namespace - wrapped the routines in net namespace
- changed PRExplodedTime to base::Time::Exploded - eliminated dependency on NSPR
All the changes are in chromium.patch.
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_
...@@ -245,27 +245,36 @@ int URLRequestNewFtpJob::ProcessFtpDir(net::IOBuffer *buf, ...@@ -245,27 +245,36 @@ int URLRequestNewFtpJob::ProcessFtpDir(net::IOBuffer *buf,
int64 file_size; int64 file_size;
std::istringstream iss(std::string(buf->data(), bytes_read)); std::istringstream iss(std::string(buf->data(), bytes_read));
struct net::ListState state; struct net::list_state state;
memset(&state, 0, sizeof(state)); memset(&state, 0, sizeof(state));
while (getline(iss, line)) { while (getline(iss, line)) {
struct net::ListResult result; struct net::list_result result;
std::replace(line.begin(), line.end(), '\r', '\0'); std::replace(line.begin(), line.end(), '\r', '\0');
net::LineType line_type = ParseFTPLine(line.c_str(), &state, &result); int line_type = net::ParseFTPList(line.c_str(), &state, &result);
// The original code assumed months are in range 0-11 (PRExplodedTime),
// but our Time class expects a 1-12 range. Adjust it here, because
// the third-party parsing code uses bit-shifting on the month,
// and it'd be too easy to break that logic.
result.fe_time.month++;
DCHECK_LE(1, result.fe_time.month);
DCHECK_GE(12, result.fe_time.month);
switch (line_type) { switch (line_type) {
case net::FTP_TYPE_DIRECTORY: case 'd': // Directory entry.
file_entry.append(net::GetDirectoryListingEntry( file_entry.append(net::GetDirectoryListingEntry(
RawByteSequenceToFilename(result.fe_fname, encoding_), RawByteSequenceToFilename(result.fe_fname, encoding_),
result.fe_fname, true, 0, result.fe_fname, true, 0,
base::Time::FromLocalExploded(result.fe_time))); base::Time::FromLocalExploded(result.fe_time)));
break; break;
case net::FTP_TYPE_FILE: case 'f': // File entry.
if (StringToInt64(result.fe_size, &file_size)) if (StringToInt64(result.fe_size, &file_size))
file_entry.append(net::GetDirectoryListingEntry( file_entry.append(net::GetDirectoryListingEntry(
RawByteSequenceToFilename(result.fe_fname, encoding_), RawByteSequenceToFilename(result.fe_fname, encoding_),
result.fe_fname, false, file_size, result.fe_fname, false, file_size,
base::Time::FromLocalExploded(result.fe_time))); base::Time::FromLocalExploded(result.fe_time)));
break; break;
case net::FTP_TYPE_SYMLINK: { case 'l': { // Symlink entry.
std::string filename(result.fe_fname, result.fe_fnlen); std::string filename(result.fe_fname, result.fe_fnlen);
// Parsers for styles 'U' and 'W' handle " -> " themselves. // Parsers for styles 'U' and 'W' handle " -> " themselves.
...@@ -283,10 +292,11 @@ int URLRequestNewFtpJob::ProcessFtpDir(net::IOBuffer *buf, ...@@ -283,10 +292,11 @@ int URLRequestNewFtpJob::ProcessFtpDir(net::IOBuffer *buf,
} }
} }
break; break;
case net::FTP_TYPE_JUNK: case '?': // Junk entry.
case net::FTP_TYPE_COMMENT: case '"': // Comment entry.
break; break;
default: default:
NOTREACHED();
break; break;
} }
} }
...@@ -301,7 +311,8 @@ int URLRequestNewFtpJob::ProcessFtpDir(net::IOBuffer *buf, ...@@ -301,7 +311,8 @@ int URLRequestNewFtpJob::ProcessFtpDir(net::IOBuffer *buf,
return bytes_to_copy; return bytes_to_copy;
} }
void URLRequestNewFtpJob::LogFtpServerType(const net::ListState& list_state) { void URLRequestNewFtpJob::LogFtpServerType(
const struct net::list_state& list_state) {
// We can't recognize server type based on empty directory listings. Don't log // We can't recognize server type based on empty directory listings. Don't log
// that as unknown, it's misleading. // that as unknown, it's misleading.
if (!list_state.parsed_one) if (!list_state.parsed_one)
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
class URLRequestContext; class URLRequestContext;
namespace net { namespace net {
struct ListState; struct list_state;
} }
// A URLRequestJob subclass that is built on top of FtpTransaction. It // A URLRequestJob subclass that is built on top of FtpTransaction. It
...@@ -56,7 +56,7 @@ class URLRequestNewFtpJob : public URLRequestJob { ...@@ -56,7 +56,7 @@ class URLRequestNewFtpJob : public URLRequestJob {
int ProcessFtpDir(net::IOBuffer *buf, int buf_size, int bytes_read); int ProcessFtpDir(net::IOBuffer *buf, int buf_size, int bytes_read);
void LogFtpServerType(const net::ListState& list_state); void LogFtpServerType(const struct net::list_state& list_state);
net::FtpRequestInfo request_info_; net::FtpRequestInfo request_info_;
scoped_ptr<net::FtpTransaction> transaction_; scoped_ptr<net::FtpTransaction> transaction_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment