2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-09-09 23:33:16 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 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
|
|
|
|
* http://www.mozilla.org/NPL/
|
1999-09-09 23:33:16 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-09-09 23:33:16 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2002-03-27 08:43:49 +03:00
|
|
|
* Contributor(s): Bradley Baetz <bbaetz@student.usyd.edu.au>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* 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
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* 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 NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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 "nsIAtom.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIGenericFactory.h"
|
1999-11-23 18:13:29 +03:00
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
1999-09-09 23:33:16 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-09-10 18:36:56 +04:00
|
|
|
#include "nsEscape.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1999-09-09 23:33:16 +04:00
|
|
|
#include "nsIStringStream.h"
|
|
|
|
#include "nsILocaleService.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsDateTimeFormatCID.h"
|
1999-11-23 18:13:29 +03:00
|
|
|
#include "nsIStreamListener.h"
|
1999-11-23 23:55:27 +03:00
|
|
|
#include "nsCRT.h"
|
2001-03-25 01:57:35 +03:00
|
|
|
#include "nsMimeTypes.h"
|
|
|
|
|
2002-08-29 07:13:18 +04:00
|
|
|
#include "ParseFTPList.h"
|
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
|
|
|
|
//
|
2000-10-29 02:17:53 +04:00
|
|
|
PRLogModuleInfo* gFTPDirListConvLog = nsnull;
|
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
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS3(nsFTPDirListingConv,
|
|
|
|
nsIStreamConverter,
|
|
|
|
nsIStreamListener,
|
2001-04-10 10:01:08 +04:00
|
|
|
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,
|
|
|
|
const PRUnichar *aFromType,
|
|
|
|
const PRUnichar *aToType,
|
|
|
|
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
|
|
|
|
nsFTPDirListingConv::AsyncConvertData(const PRUnichar *aFromType, const PRUnichar *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");
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// hook up our final listener. this guy gets the various On*() calls we want to throw
|
|
|
|
// at him.
|
|
|
|
mFinalListener = aListener;
|
|
|
|
NS_ADDREF(mFinalListener);
|
|
|
|
|
|
|
|
// we need our own channel that represents the content-type of the
|
|
|
|
// converted data.
|
|
|
|
NS_ASSERTION(aCtxt, "FTP dir listing needs a context (the uri)");
|
|
|
|
nsIURI *uri;
|
|
|
|
rv = aCtxt->QueryInterface(NS_GET_IID(nsIURI), (void**)&uri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
// XXX this seems really wrong!!
|
2000-03-29 07:58:50 +04:00
|
|
|
rv = NS_NewInputStreamChannel(&mPartChannel,
|
|
|
|
uri,
|
|
|
|
nsnull,
|
2002-03-21 01:50:33 +03:00
|
|
|
NS_LITERAL_CSTRING(APPLICATION_HTTP_INDEX_FORMAT),
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_LITERAL_CSTRING(""));
|
1999-09-09 23:33:16 +04:00
|
|
|
NS_RELEASE(uri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
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,
|
1999-09-09 23:33:16 +04:00
|
|
|
nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 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);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-09-09 23:33:16 +04:00
|
|
|
PRUint32 read, streamLen;
|
|
|
|
|
1999-09-10 18:36:56 +04:00
|
|
|
rv = inStr->Available(&streamLen);
|
1999-09-09 23:33:16 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-06-03 13:46:12 +04:00
|
|
|
char *buffer = (char*)nsMemory::Alloc(streamLen + 1);
|
1999-09-09 23:33:16 +04:00
|
|
|
rv = inStr->Read(buffer, streamLen, &read);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// the dir listings are ascii text, null terminate this sucker.
|
|
|
|
buffer[streamLen] = '\0';
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
PR_LOG(gFTPDirListConvLog, PR_LOG_DEBUG, ("nsFTPDirListingConv::OnData(request = %x, ctxt = %x, inStr = %x, sourceOffset = %d, count = %d)\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);
|
2000-06-03 13:46:12 +04:00
|
|
|
nsMemory::Free(buffer);
|
2001-09-29 12:28:41 +04:00
|
|
|
buffer = ToNewCString(mBuffer);
|
1999-09-09 23:33:16 +04:00
|
|
|
mBuffer.Truncate();
|
|
|
|
}
|
|
|
|
|
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() received the following %d bytes...\n\n%s\n\n", streamLen, buffer) );
|
|
|
|
#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
|
|
|
|
2001-12-06 03:09:00 +03:00
|
|
|
nsCString 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));
|
1999-11-23 18:13:29 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-10 18:36:56 +04:00
|
|
|
|
2001-12-06 03:09:00 +03:00
|
|
|
rv = GetHeaders(indexFormat, uri);
|
1999-11-23 18:13:29 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-09 23:33:16 +04:00
|
|
|
|
1999-11-23 18:13:29 +03:00
|
|
|
mSentHeading = PR_TRUE;
|
|
|
|
}
|
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);
|
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);
|
2000-06-03 13:46:12 +04:00
|
|
|
nsMemory::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",
|
1999-09-10 18:36:56 +04:00
|
|
|
PL_strlen(line), line) );
|
1999-09-09 23:33:16 +04:00
|
|
|
}
|
|
|
|
|
2000-06-03 13:46:12 +04:00
|
|
|
nsMemory::Free(buffer);
|
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);
|
1999-09-09 23:33:16 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mFinalListener->OnDataAvailable(mPartChannel, ctxt, inputData, 0, indexFormat.Length());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
return mFinalListener->OnStartRequest(mPartChannel, ctxt);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
|
2000-01-20 03:51:18 +03:00
|
|
|
nsCOMPtr<nsILoadGroup> loadgroup;
|
2001-02-21 23:38:08 +03:00
|
|
|
rv = channel->GetLoadGroup(getter_AddRefs(loadgroup));
|
2000-01-20 03:51:18 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (loadgroup)
|
2001-04-10 10:01:08 +04:00
|
|
|
(void)loadgroup->RemoveRequest(mPartChannel, nsnull, aStatus);
|
2000-01-20 03:51:18 +03:00
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
return mFinalListener->OnStopRequest(mPartChannel, ctxt, aStatus);
|
1999-09-09 23:33:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsFTPDirListingConv methods
|
|
|
|
nsFTPDirListingConv::nsFTPDirListingConv() {
|
|
|
|
mFinalListener = nsnull;
|
|
|
|
mPartChannel = nsnull;
|
|
|
|
mSentHeading = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFTPDirListingConv::~nsFTPDirListingConv() {
|
|
|
|
NS_IF_RELEASE(mFinalListener);
|
|
|
|
NS_IF_RELEASE(mPartChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
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...
|
|
|
|
//
|
|
|
|
if (nsnull == gFTPDirListConvLog) {
|
|
|
|
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
|
|
|
|
headers.Append("300: ");
|
|
|
|
|
|
|
|
// Bug 111117 - don't print the password
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString pw;
|
|
|
|
nsCAutoString spec;
|
|
|
|
uri->GetPassword(pw);
|
2001-12-06 03:09:00 +03:00
|
|
|
if (!pw.IsEmpty()) {
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = uri->SetPassword(NS_LITERAL_CSTRING(""));
|
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:
|
|
|
|
headers.Append("200: filename content-length last-modified file-type\n");
|
|
|
|
// 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;
|
|
|
|
PRBool cr = PR_FALSE;
|
|
|
|
|
|
|
|
// 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';
|
|
|
|
cr = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
*eol = '\0';
|
|
|
|
cr = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-08-29 07:13:18 +04:00
|
|
|
list_state state;
|
|
|
|
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.
|
|
|
|
aString.Append("201: ");
|
|
|
|
// FILENAME
|
2002-08-29 07:13:18 +04:00
|
|
|
|
|
|
|
|
2002-09-05 09:01:12 +04:00
|
|
|
const char* offset = strstr(result.fe_fname, " -> ");
|
|
|
|
if (offset) {
|
|
|
|
result.fe_fnlen = offset - result.fe_fname;
|
|
|
|
}
|
|
|
|
aString.Append(NS_LITERAL_CSTRING("\"") +
|
|
|
|
Substring(result.fe_fname, result.fe_fname+result.fe_fnlen) +
|
|
|
|
NS_LITERAL_CSTRING("\" "));
|
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
|
|
|
{
|
|
|
|
for (int i = 0; i < sizeof(result.fe_size); i++)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
aString.Append("0 ");
|
|
|
|
|
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);
|
2002-02-23 03:41:52 +03:00
|
|
|
nsMemory::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')
|
1999-11-23 18:13:29 +03:00
|
|
|
aString.Append("DIRECTORY");
|
2002-08-29 07:13:18 +04:00
|
|
|
else if (type == 'l')
|
2000-02-08 04:20:46 +03:00
|
|
|
aString.Append("SYMBOLIC-LINK");
|
2002-08-29 07:13:18 +04:00
|
|
|
else
|
1999-11-23 18:13:29 +03:00
|
|
|
aString.Append("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
|
|
|
{
|
1999-10-14 17:36:33 +04:00
|
|
|
NS_PRECONDITION(aFTPDirListingConv != nsnull, "null ptr");
|
|
|
|
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
|
|
|
}
|
2001-02-21 23:38:08 +03:00
|
|
|
|