2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-09-09 23:33:16 +04:00
|
|
|
|
|
|
|
#include "nsFTPDirListingConv.h"
|
2000-06-03 13:46:12 +04:00
|
|
|
#include "nsMemory.h"
|
1999-09-09 23:33:16 +04:00
|
|
|
#include "plstr.h"
|
1999-09-10 18:36:56 +04:00
|
|
|
#include "prlog.h"
|
1999-09-09 23:33:16 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-09-10 18:36:56 +04:00
|
|
|
#include "nsEscape.h"
|
2006-01-02 05:57:15 +03:00
|
|
|
#include "nsStringStream.h"
|
1999-11-23 18:13:29 +03:00
|
|
|
#include "nsIStreamListener.h"
|
1999-11-23 23:55:27 +03:00
|
|
|
#include "nsCRT.h"
|
2005-07-08 23:40:44 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2013-09-23 07:34:09 +04:00
|
|
|
#include "nsIChannel.h"
|
2013-09-23 07:35:05 +04:00
|
|
|
#include "nsIURI.h"
|
2001-03-25 01:57:35 +03:00
|
|
|
|
2002-08-29 07:13:18 +04:00
|
|
|
#include "ParseFTPList.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
1999-09-09 23:33:16 +04:00
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
#if defined(PR_LOGGING)
|
1999-09-10 18:36:56 +04:00
|
|
|
//
|
|
|
|
// Log module for FTP dir listing stream converter logging...
|
|
|
|
//
|
|
|
|
// To enable logging (see prlog.h for full details):
|
|
|
|
//
|
2000-10-29 02:17:53 +04:00
|
|
|
// set NSPR_LOG_MODULES=nsFTPDirListConv:5
|
1999-09-10 18:36:56 +04:00
|
|
|
// set NSPR_LOG_FILE=nspr.log
|
|
|
|
//
|
|
|
|
// this enables PR_LOG_DEBUG level information and places all output in
|
|
|
|
// the file nspr.log
|
|
|
|
//
|
2012-07-30 18:20:58 +04:00
|
|
|
PRLogModuleInfo* gFTPDirListConvLog = nullptr;
|
1999-09-10 18:36:56 +04:00
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
#endif /* PR_LOGGING */
|
1999-09-10 18:36:56 +04:00
|
|
|
|
1999-09-09 23:33:16 +04:00
|
|
|
// nsISupports implementation
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsFTPDirListingConv,
|
|
|
|
nsIStreamConverter,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver)
|
1999-09-09 23:33:16 +04:00
|
|
|
|
2001-08-01 06:04:53 +04:00
|
|
|
|
|
|
|
// nsIStreamConverter implementation
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFTPDirListingConv::Convert(nsIInputStream *aFromStream,
|
2004-06-29 20:45:07 +04:00
|
|
|
const char *aFromType,
|
|
|
|
const char *aToType,
|
2001-08-01 06:04:53 +04:00
|
|
|
nsISupports *aCtxt, nsIInputStream **_retval) {
|
2002-08-29 07:13:18 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-09-09 23:33:16 +04:00
|
|
|
}
|
|
|
|
|
1999-11-23 18:13:29 +03:00
|
|
|
|
1999-09-09 23:33:16 +04:00
|
|
|
// Stream converter service calls this to initialize the actual stream converter (us).
|
|
|
|
NS_IMETHODIMP
|
2004-06-29 20:45:07 +04:00
|
|
|
nsFTPDirListingConv::AsyncConvertData(const char *aFromType, const char *aToType,
|
1999-10-26 13:16:24 +04:00
|
|
|
nsIStreamListener *aListener, nsISupports *aCtxt) {
|
1999-09-09 23:33:16 +04:00
|
|
|
NS_ASSERTION(aListener && aFromType && aToType, "null pointer passed into FTP dir listing converter");
|
|
|
|
|
|
|
|
// hook up our final listener. this guy gets the various On*() calls we want to throw
|
|
|
|
// at him.
|
|
|
|
mFinalListener = aListener;
|
|
|
|
NS_ADDREF(mFinalListener);
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
PR_LOG(gFTPDirListConvLog, PR_LOG_DEBUG,
|
2002-08-29 07:13:18 +04:00
|
|
|
("nsFTPDirListingConv::AsyncConvertData() converting FROM raw, TO application/http-index-format\n"));
|
1999-09-10 18:36:56 +04:00
|
|
|
|
1999-09-09 23:33:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsIStreamListener implementation
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsFTPDirListingConv::OnDataAvailable(nsIRequest* request, nsISupports *ctxt,
|
2012-09-06 06:41:02 +04:00
|
|
|
nsIInputStream *inStr, uint64_t sourceOffset, uint32_t count) {
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_ASSERTION(request, "FTP dir listing stream converter needs a request");
|
|
|
|
|
1999-09-09 23:33:16 +04:00
|
|
|
nsresult rv;
|
2001-02-21 23:38:08 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request, &rv);
|
2005-07-08 23:40:44 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-02-21 23:38:08 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t read, streamLen;
|
1999-09-09 23:33:16 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t streamLen64;
|
2012-08-11 06:44:11 +04:00
|
|
|
rv = inStr->Available(&streamLen64);
|
2005-07-08 23:40:44 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-01-15 16:22:03 +04:00
|
|
|
streamLen = (uint32_t)std::min(streamLen64, uint64_t(UINT32_MAX - 1));
|
2005-07-08 23:40:44 +04:00
|
|
|
|
|
|
|
nsAutoArrayPtr<char> buffer(new char[streamLen + 1]);
|
|
|
|
NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
|
1999-09-09 23:33:16 +04:00
|
|
|
|
|
|
|
rv = inStr->Read(buffer, streamLen, &read);
|
2005-07-08 23:40:44 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-09-09 23:33:16 +04:00
|
|
|
|
|
|
|
// the dir listings are ascii text, null terminate this sucker.
|
|
|
|
buffer[streamLen] = '\0';
|
|
|
|
|
2012-09-06 06:41:02 +04:00
|
|
|
PR_LOG(gFTPDirListConvLog, PR_LOG_DEBUG, ("nsFTPDirListingConv::OnData(request = %x, ctxt = %x, inStr = %x, sourceOffset = %llu, count = %u)\n", request, ctxt, inStr, sourceOffset, count));
|
1999-09-10 18:36:56 +04:00
|
|
|
|
1999-09-09 23:33:16 +04:00
|
|
|
if (!mBuffer.IsEmpty()) {
|
|
|
|
// we have data left over from a previous OnDataAvailable() call.
|
|
|
|
// combine the buffers so we don't lose any data.
|
|
|
|
mBuffer.Append(buffer);
|
2005-07-08 23:40:44 +04:00
|
|
|
|
|
|
|
buffer = new char[mBuffer.Length()+1];
|
|
|
|
NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
strncpy(buffer, mBuffer.get(), mBuffer.Length()+1);
|
1999-09-09 23:33:16 +04:00
|
|
|
mBuffer.Truncate();
|
|
|
|
}
|
|
|
|
|
2002-08-29 07:13:18 +04:00
|
|
|
#ifndef DEBUG_dougt
|
2005-08-04 01:40:11 +04:00
|
|
|
PR_LOG(gFTPDirListConvLog, PR_LOG_DEBUG, ("::OnData() received the following %d bytes...\n\n%s\n\n", streamLen, buffer.get()) );
|
2000-10-29 02:17:53 +04:00
|
|
|
#else
|
|
|
|
printf("::OnData() received the following %d bytes...\n\n%s\n\n", streamLen, buffer);
|
2002-08-29 07:13:18 +04:00
|
|
|
#endif // DEBUG_dougt
|
2000-10-29 02:17:53 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString indexFormat;
|
1999-09-09 23:33:16 +04:00
|
|
|
if (!mSentHeading) {
|
1999-11-23 18:13:29 +03:00
|
|
|
// build up the 300: line
|
2001-12-06 03:09:00 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(uri));
|
2005-07-08 23:40:44 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-09-10 18:36:56 +04:00
|
|
|
|
2001-12-06 03:09:00 +03:00
|
|
|
rv = GetHeaders(indexFormat, uri);
|
2005-07-08 23:40:44 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-09-09 23:33:16 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mSentHeading = true;
|
1999-11-23 18:13:29 +03:00
|
|
|
}
|
1999-09-10 18:36:56 +04:00
|
|
|
|
1999-11-23 18:13:29 +03:00
|
|
|
char *line = buffer;
|
|
|
|
line = DigestBufferLines(line, indexFormat);
|
1999-09-09 23:33:16 +04:00
|
|
|
|
2002-08-29 07:13:18 +04:00
|
|
|
#ifndef DEBUG_dougt
|
2000-10-29 02:17:53 +04:00
|
|
|
PR_LOG(gFTPDirListConvLog, PR_LOG_DEBUG, ("::OnData() sending the following %d bytes...\n\n%s\n\n",
|
2001-03-02 12:26:57 +03:00
|
|
|
indexFormat.Length(), indexFormat.get()) );
|
2000-10-29 02:17:53 +04:00
|
|
|
#else
|
2001-09-29 12:28:41 +04:00
|
|
|
char *unescData = ToNewCString(indexFormat);
|
2005-07-08 23:40:44 +04:00
|
|
|
NS_ENSURE_TRUE(unescData, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
1999-09-18 00:13:33 +04:00
|
|
|
nsUnescape(unescData);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("::OnData() sending the following %d bytes...\n\n%s\n\n", indexFormat.Length(), unescData);
|
2015-03-27 03:01:12 +03:00
|
|
|
free(unescData);
|
2002-08-29 07:13:18 +04:00
|
|
|
#endif // DEBUG_dougt
|
1999-09-09 23:33:16 +04:00
|
|
|
|
|
|
|
// if there's any data left over, buffer it.
|
|
|
|
if (line && *line) {
|
|
|
|
mBuffer.Append(line);
|
2000-10-29 02:17:53 +04:00
|
|
|
PR_LOG(gFTPDirListConvLog, PR_LOG_DEBUG, ("::OnData() buffering the following %d bytes...\n\n%s\n\n",
|
2013-05-08 07:40:12 +04:00
|
|
|
strlen(line), line) );
|
1999-09-09 23:33:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// send the converted data out.
|
1999-10-01 18:10:02 +04:00
|
|
|
nsCOMPtr<nsIInputStream> inputData;
|
1999-09-09 23:33:16 +04:00
|
|
|
|
2002-01-28 01:02:00 +03:00
|
|
|
rv = NS_NewCStringInputStream(getter_AddRefs(inputData), indexFormat);
|
2005-07-08 23:40:44 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-09-09 23:33:16 +04:00
|
|
|
|
2006-03-03 19:27:35 +03:00
|
|
|
rv = mFinalListener->OnDataAvailable(request, ctxt, inputData, 0, indexFormat.Length());
|
1999-09-09 23:33:16 +04:00
|
|
|
|
2005-07-08 23:40:44 +04:00
|
|
|
return rv;
|
1999-09-09 23:33:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
// nsIRequestObserver implementation
|
1999-09-09 23:33:16 +04:00
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsFTPDirListingConv::OnStartRequest(nsIRequest* request, nsISupports *ctxt) {
|
1999-09-09 23:33:16 +04:00
|
|
|
// we don't care about start. move along... but start masqeurading
|
|
|
|
// as the http-index channel now.
|
2006-03-03 19:27:35 +03:00
|
|
|
return mFinalListener->OnStartRequest(request, ctxt);
|
1999-09-09 23:33:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsFTPDirListingConv::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
|
2001-04-10 10:01:08 +04:00
|
|
|
nsresult aStatus) {
|
1999-09-09 23:33:16 +04:00
|
|
|
// we don't care about stop. move along...
|
2001-02-21 23:38:08 +03:00
|
|
|
|
2006-03-03 19:27:35 +03:00
|
|
|
return mFinalListener->OnStopRequest(request, ctxt, aStatus);
|
1999-09-09 23:33:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsFTPDirListingConv methods
|
|
|
|
nsFTPDirListingConv::nsFTPDirListingConv() {
|
2012-07-30 18:20:58 +04:00
|
|
|
mFinalListener = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mSentHeading = false;
|
1999-09-09 23:33:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFTPDirListingConv::~nsFTPDirListingConv() {
|
|
|
|
NS_IF_RELEASE(mFinalListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFTPDirListingConv::Init() {
|
2000-10-29 02:17:53 +04:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
//
|
|
|
|
// Initialize the global PRLogModule for FTP Protocol logging
|
|
|
|
// if necessary...
|
|
|
|
//
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr == gFTPDirListConvLog) {
|
2000-10-29 02:17:53 +04:00
|
|
|
gFTPDirListConvLog = PR_NewLogModule("nsFTPDirListingConv");
|
|
|
|
}
|
|
|
|
#endif /* PR_LOGGING */
|
|
|
|
|
1999-09-09 23:33:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-06 03:09:00 +03:00
|
|
|
nsresult
|
2002-03-24 00:35:01 +03:00
|
|
|
nsFTPDirListingConv::GetHeaders(nsACString& headers,
|
2001-12-06 03:09:00 +03:00
|
|
|
nsIURI* uri)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// build up 300 line
|
2004-12-04 13:19:29 +03:00
|
|
|
headers.AppendLiteral("300: ");
|
2001-12-06 03:09:00 +03:00
|
|
|
|
|
|
|
// Bug 111117 - don't print the password
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString pw;
|
|
|
|
nsAutoCString spec;
|
2002-03-06 10:48:55 +03:00
|
|
|
uri->GetPassword(pw);
|
2001-12-06 03:09:00 +03:00
|
|
|
if (!pw.IsEmpty()) {
|
2004-01-30 01:04:45 +03:00
|
|
|
rv = uri->SetPassword(EmptyCString());
|
2001-12-06 03:09:00 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = uri->GetAsciiSpec(spec);
|
2001-12-06 03:09:00 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
headers.Append(spec);
|
|
|
|
rv = uri->SetPassword(pw);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
} else {
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = uri->GetAsciiSpec(spec);
|
2001-12-06 03:09:00 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
headers.Append(spec);
|
|
|
|
}
|
|
|
|
headers.Append(char(nsCRT::LF));
|
|
|
|
// END 300:
|
|
|
|
|
|
|
|
// build up the column heading; 200:
|
2004-12-04 13:19:29 +03:00
|
|
|
headers.AppendLiteral("200: filename content-length last-modified file-type\n");
|
2001-12-06 03:09:00 +03:00
|
|
|
// END 200:
|
|
|
|
return rv;
|
|
|
|
}
|
1999-09-09 23:33:16 +04:00
|
|
|
|
1999-11-23 18:13:29 +03:00
|
|
|
char *
|
2001-12-06 03:09:00 +03:00
|
|
|
nsFTPDirListingConv::DigestBufferLines(char *aBuffer, nsCString &aString) {
|
1999-11-23 18:13:29 +03:00
|
|
|
char *line = aBuffer;
|
|
|
|
char *eol;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool cr = false;
|
1999-11-23 18:13:29 +03:00
|
|
|
|
2009-09-04 22:27:07 +04:00
|
|
|
list_state state;
|
|
|
|
|
1999-11-23 18:13:29 +03:00
|
|
|
// while we have new lines, parse 'em into application/http-index-format.
|
2001-04-18 09:59:43 +04:00
|
|
|
while ( line && (eol = PL_strchr(line, nsCRT::LF)) ) {
|
1999-11-23 18:13:29 +03:00
|
|
|
// yank any carriage returns too.
|
2001-04-18 09:59:43 +04:00
|
|
|
if (eol > line && *(eol-1) == nsCRT::CR) {
|
1999-11-23 18:13:29 +03:00
|
|
|
eol--;
|
|
|
|
*eol = '\0';
|
2011-10-17 18:59:28 +04:00
|
|
|
cr = true;
|
1999-11-23 18:13:29 +03:00
|
|
|
} else {
|
|
|
|
*eol = '\0';
|
2011-10-17 18:59:28 +04:00
|
|
|
cr = false;
|
1999-11-23 18:13:29 +03:00
|
|
|
}
|
|
|
|
|
2002-08-29 07:13:18 +04:00
|
|
|
list_result result;
|
1999-11-23 18:13:29 +03:00
|
|
|
|
2002-08-29 07:13:18 +04:00
|
|
|
int type = ParseFTPList(line, &state, &result );
|
1999-11-23 18:13:29 +03:00
|
|
|
|
2002-08-29 07:13:18 +04:00
|
|
|
// if it is other than a directory, file, or link -OR- if it is a
|
|
|
|
// directory named . or .., skip over this line.
|
|
|
|
if ((type != 'd' && type != 'f' && type != 'l') ||
|
|
|
|
(result.fe_type == 'd' && result.fe_fname[0] == '.' &&
|
|
|
|
(result.fe_fnlen == 1 || (result.fe_fnlen == 2 && result.fe_fname[1] == '.'))) )
|
1999-11-23 18:13:29 +03:00
|
|
|
{
|
2002-08-29 07:13:18 +04:00
|
|
|
if (cr)
|
|
|
|
line = eol+2;
|
2001-09-20 18:16:14 +04:00
|
|
|
else
|
2002-08-29 07:13:18 +04:00
|
|
|
line = eol+1;
|
|
|
|
|
|
|
|
continue;
|
1999-11-23 18:13:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// blast the index entry into the indexFormat buffer as a 201: line.
|
2004-12-04 13:19:29 +03:00
|
|
|
aString.AppendLiteral("201: ");
|
1999-11-23 18:13:29 +03:00
|
|
|
// FILENAME
|
2002-08-29 07:13:18 +04:00
|
|
|
|
2008-10-01 09:28:39 +04:00
|
|
|
// parsers for styles 'U' and 'W' handle sequence " -> " themself
|
|
|
|
if (state.lstyle != 'U' && state.lstyle != 'W') {
|
|
|
|
const char* offset = strstr(result.fe_fname, " -> ");
|
|
|
|
if (offset) {
|
|
|
|
result.fe_fnlen = offset - result.fe_fname;
|
|
|
|
}
|
2002-09-05 09:01:12 +04:00
|
|
|
}
|
1999-11-23 18:13:29 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString buf;
|
2004-12-04 13:19:29 +03:00
|
|
|
aString.Append('\"');
|
|
|
|
aString.Append(NS_EscapeURL(Substring(result.fe_fname,
|
2003-02-27 13:55:01 +03:00
|
|
|
result.fe_fname+result.fe_fnlen),
|
2004-12-04 13:19:29 +03:00
|
|
|
esc_Minimal|esc_OnlyASCII|esc_Forced,buf));
|
|
|
|
aString.AppendLiteral("\" ");
|
2003-02-27 13:55:01 +03:00
|
|
|
|
1999-11-23 18:13:29 +03:00
|
|
|
// CONTENT LENGTH
|
2002-08-29 07:13:18 +04:00
|
|
|
|
2002-09-05 09:01:12 +04:00
|
|
|
if (type != 'd')
|
2002-08-29 07:13:18 +04:00
|
|
|
{
|
2004-01-08 02:43:12 +03:00
|
|
|
for (int i = 0; i < int(sizeof(result.fe_size)); ++i)
|
2002-08-29 07:13:18 +04:00
|
|
|
{
|
|
|
|
if (result.fe_size[i] != '\0')
|
|
|
|
aString.Append((const char*)&result.fe_size[i], 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
aString.Append(' ');
|
1999-11-23 18:13:29 +03:00
|
|
|
}
|
2002-08-29 07:13:18 +04:00
|
|
|
else
|
2004-12-04 13:19:29 +03:00
|
|
|
aString.AppendLiteral("0 ");
|
2002-08-29 07:13:18 +04:00
|
|
|
|
1999-11-23 18:13:29 +03:00
|
|
|
|
|
|
|
// MODIFIED DATE
|
2000-10-25 01:53:12 +04:00
|
|
|
char buffer[256] = "";
|
2001-10-03 04:43:30 +04:00
|
|
|
// Note: The below is the RFC822/1123 format, as required by
|
|
|
|
// the application/http-index-format specs
|
|
|
|
// viewers of such a format can then reformat this into the
|
|
|
|
// current locale (or anything else they choose)
|
2002-08-29 07:13:18 +04:00
|
|
|
PR_FormatTimeUSEnglish(buffer, sizeof(buffer),
|
|
|
|
"%a, %d %b %Y %H:%M:%S", &result.fe_time );
|
2002-01-08 05:56:20 +03:00
|
|
|
|
2000-10-25 01:53:12 +04:00
|
|
|
char *escapedDate = nsEscape(buffer, url_Path);
|
1999-11-23 18:13:29 +03:00
|
|
|
aString.Append(escapedDate);
|
2015-03-27 03:01:12 +03:00
|
|
|
free(escapedDate);
|
1999-11-23 18:13:29 +03:00
|
|
|
aString.Append(' ');
|
|
|
|
|
|
|
|
// ENTRY TYPE
|
2002-08-29 07:13:18 +04:00
|
|
|
if (type == 'd')
|
2004-12-04 13:19:29 +03:00
|
|
|
aString.AppendLiteral("DIRECTORY");
|
2002-08-29 07:13:18 +04:00
|
|
|
else if (type == 'l')
|
2004-12-04 13:19:29 +03:00
|
|
|
aString.AppendLiteral("SYMBOLIC-LINK");
|
2002-08-29 07:13:18 +04:00
|
|
|
else
|
2004-12-04 13:19:29 +03:00
|
|
|
aString.AppendLiteral("FILE");
|
2002-08-29 07:13:18 +04:00
|
|
|
|
1999-11-23 18:13:29 +03:00
|
|
|
aString.Append(' ');
|
|
|
|
|
2001-04-18 09:59:43 +04:00
|
|
|
aString.Append(char(nsCRT::LF)); // complete this line
|
1999-11-23 18:13:29 +03:00
|
|
|
// END 201:
|
|
|
|
|
|
|
|
if (cr)
|
|
|
|
line = eol+2;
|
|
|
|
else
|
|
|
|
line = eol+1;
|
|
|
|
} // end while(eol)
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
1999-10-14 17:36:33 +04:00
|
|
|
nsresult
|
|
|
|
NS_NewFTPDirListingConv(nsFTPDirListingConv** aFTPDirListingConv)
|
1999-09-09 23:33:16 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aFTPDirListingConv != nullptr, "null ptr");
|
1999-10-14 17:36:33 +04:00
|
|
|
if (! aFTPDirListingConv)
|
1999-09-09 23:33:16 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-10-14 17:36:33 +04:00
|
|
|
*aFTPDirListingConv = new nsFTPDirListingConv();
|
|
|
|
if (! *aFTPDirListingConv)
|
1999-09-09 23:33:16 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
1999-10-14 17:36:33 +04:00
|
|
|
NS_ADDREF(*aFTPDirListingConv);
|
|
|
|
return (*aFTPDirListingConv)->Init();
|
1999-09-09 23:33:16 +04:00
|
|
|
}
|