2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2005-08-21 14:13:52 +00:00
|
|
|
/* vim:set sw=4 sts=4 et cin: */
|
2001-09-28 20:14:13 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 22:01:16 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-09-13 20:20:21 +00:00
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
1999-09-13 20:20:21 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00: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-13 20:20:21 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* Contributor(s):
|
|
|
|
* Bradley Baetz <bbaetz@cs.mcgill.ca>
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 22:01:16 +00:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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
|
2004-04-18 22:01:16 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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
|
2004-04-18 22:01:16 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-09-13 20:20:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2000-02-08 01:16:09 +00:00
|
|
|
The converts a filesystem directory into an "HTTP index" stream per
|
|
|
|
Lou Montulli's original spec:
|
|
|
|
|
2004-05-10 23:21:35 +00:00
|
|
|
http://www.mozilla.org/projects/netlib/dirindexformat.html
|
1999-09-13 20:20:21 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsDirectoryIndexStream.h"
|
2000-02-08 01:16:09 +00:00
|
|
|
#include "nsXPIDLString.h"
|
1999-09-13 20:20:21 +00:00
|
|
|
#include "prio.h"
|
2000-02-08 01:16:09 +00:00
|
|
|
#include "prlog.h"
|
2000-02-27 16:19:59 +00:00
|
|
|
#include "prlong.h"
|
2000-02-08 01:16:09 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static PRLogModuleInfo* gLog;
|
|
|
|
#endif
|
1999-09-13 20:20:21 +00:00
|
|
|
|
2001-10-03 00:43:30 +00:00
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsICollation.h"
|
|
|
|
#include "nsILocale.h"
|
|
|
|
#include "nsILocaleService.h"
|
|
|
|
#include "nsCollationCID.h"
|
|
|
|
#include "nsIPlatformCharset.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2002-09-13 19:32:45 +00:00
|
|
|
#include "nsURLHelper.h"
|
2002-01-08 01:31:25 +00:00
|
|
|
#include "nsNetUtil.h"
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "nsCRT.h"
|
2001-10-03 00:43:30 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
|
|
|
|
|
|
|
|
// NOTE: This runs on the _file transport_ thread.
|
|
|
|
// The problem is that now that we're actually doing something with the data,
|
|
|
|
// we want to do stuff like i18n sorting. However, none of the collation stuff
|
|
|
|
// is threadsafe, and stuff like GetUnicodeLeafName spews warnings on a debug
|
|
|
|
// build, because the singletons were initialised on the UI thread.
|
|
|
|
// So THIS CODE IS ASCII ONLY!!!!!!!! This is no worse than the current
|
|
|
|
// behaviour, though. See bug 99382.
|
|
|
|
// When this is fixed, #define THREADSAFE_I18N to get this code working
|
|
|
|
|
|
|
|
//#define THREADSAFE_I18N
|
|
|
|
|
1999-09-13 20:20:21 +00:00
|
|
|
nsDirectoryIndexStream::nsDirectoryIndexStream()
|
2001-10-03 00:43:30 +00:00
|
|
|
: mOffset(0), mPos(0)
|
1999-09-13 20:20:21 +00:00
|
|
|
{
|
2000-02-08 01:16:09 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (! gLog)
|
|
|
|
gLog = PR_NewLogModule("nsDirectoryIndexStream");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PR_LOG(gLog, PR_LOG_DEBUG,
|
|
|
|
("nsDirectoryIndexStream[%p]: created", this));
|
1999-09-13 20:20:21 +00:00
|
|
|
}
|
|
|
|
|
2001-10-03 00:43:30 +00:00
|
|
|
static int PR_CALLBACK compare(const void* aElement1,
|
|
|
|
const void* aElement2,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
nsIFile* a = (nsIFile*)aElement1;
|
|
|
|
nsIFile* b = (nsIFile*)aElement2;
|
|
|
|
|
|
|
|
// Not that this #ifdef makes much of a difference... We need it
|
|
|
|
// to work out which version of GetLeafName to use, though
|
|
|
|
#ifdef THREADSAFE_I18N
|
|
|
|
// don't check for errors, because we can't report them anyway
|
|
|
|
nsXPIDLString name1, name2;
|
|
|
|
a->GetUnicodeLeafName(getter_Copies(name1));
|
|
|
|
b->GetUnicodeLeafName(getter_Copies(name2));
|
|
|
|
|
|
|
|
// Note - we should be the collation to do sorting. Why don't we?
|
|
|
|
// Because that is _slow_. Using TestProtocols to list file:///dev/
|
|
|
|
// goes from 3 seconds to 22. (This may be why nsXULSortService is
|
|
|
|
// so slow as well).
|
2002-03-29 02:46:01 +00:00
|
|
|
// Does this have bad effects? Probably, but since nsXULTree appears
|
2001-10-03 00:43:30 +00:00
|
|
|
// to use the raw RDF literal value as the sort key (which ammounts to an
|
|
|
|
// strcmp), it won't be any worse, I think.
|
|
|
|
// This could be made faster, by creating the keys once,
|
|
|
|
// but CompareString could still be smarter - see bug 99383 - bbaetz
|
|
|
|
// NB - 99393 has been WONTFIXed. So if the I18N code is ever made
|
|
|
|
// threadsafe so that this matters, we'd have to pass through a
|
|
|
|
// struct { nsIFile*, PRUint8* } with the pre-calculated key.
|
|
|
|
return Compare(name1, name2);
|
|
|
|
|
|
|
|
/*PRInt32 res;
|
|
|
|
// CompareString takes an nsString...
|
|
|
|
nsString str1(name1);
|
|
|
|
nsString str2(name2);
|
|
|
|
|
|
|
|
nsICollation* coll = (nsICollation*)aData;
|
2004-08-24 22:50:33 +00:00
|
|
|
coll->CompareString(nsICollation::kCollationStrengthDefault, str1, str2, &res);
|
2001-10-03 00:43:30 +00:00
|
|
|
return res;*/
|
|
|
|
#else
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString name1, name2;
|
|
|
|
a->GetNativeLeafName(name1);
|
|
|
|
b->GetNativeLeafName(name2);
|
2001-10-03 00:43:30 +00:00
|
|
|
|
|
|
|
return Compare(name1, name2);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-09-13 20:20:21 +00:00
|
|
|
nsresult
|
2000-01-24 21:28:28 +00:00
|
|
|
nsDirectoryIndexStream::Init(nsIFile* aDir)
|
1999-09-13 20:20:21 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
nsresult rv;
|
|
|
|
PRBool isDir;
|
|
|
|
rv = aDir->IsDirectory(&isDir);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
NS_PRECONDITION(isDir, "not a directory");
|
|
|
|
if (!isDir)
|
1999-09-13 20:20:21 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
2000-02-08 01:16:09 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString path;
|
|
|
|
aDir->GetNativePath(path);
|
2000-02-08 01:16:09 +00:00
|
|
|
PR_LOG(gLog, PR_LOG_DEBUG,
|
|
|
|
("nsDirectoryIndexStream[%p]: initialized on %s",
|
2002-04-27 05:33:09 +00:00
|
|
|
this, path.get()));
|
2000-02-08 01:16:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-10-03 00:43:30 +00:00
|
|
|
#ifdef THREADSAFE_I18N
|
|
|
|
if (!mTextToSubURI) {
|
|
|
|
mTextToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
#endif
|
1999-09-13 20:20:21 +00:00
|
|
|
|
|
|
|
// Sigh. We have to allocate on the heap because there are no
|
|
|
|
// assignment operators defined.
|
2001-10-03 00:43:30 +00:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> iter;
|
2003-11-05 12:39:05 +00:00
|
|
|
rv = aDir->GetDirectoryEntries(getter_AddRefs(iter));
|
2001-10-03 00:43:30 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Now lets sort, because clients expect it that way
|
|
|
|
// XXX - should we do so here, or when the first item is requested?
|
|
|
|
// XXX - use insertion sort instead?
|
|
|
|
|
|
|
|
PRBool more;
|
|
|
|
nsCOMPtr<nsISupports> elem;
|
|
|
|
while (NS_SUCCEEDED(iter->HasMoreElements(&more)) && more) {
|
|
|
|
rv = iter->GetNext(getter_AddRefs(elem));
|
2002-01-15 00:51:11 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIFile> file = do_QueryInterface(elem);
|
|
|
|
if (file) {
|
|
|
|
nsIFile* f = file;
|
|
|
|
NS_ADDREF(f);
|
|
|
|
mArray.AppendElement(f);
|
|
|
|
}
|
2001-10-03 00:43:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef THREADSAFE_I18N
|
|
|
|
nsCOMPtr<nsILocaleService> ls = do_GetService(NS_LOCALESERVICE_CONTRACTID,
|
|
|
|
&rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocale> locale;
|
|
|
|
rv = ls->GetApplicationLocale(getter_AddRefs(locale));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICollationFactory> cf = do_CreateInstance(kCollationFactoryCID,
|
|
|
|
&rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICollation> coll;
|
|
|
|
rv = cf->CreateCollation(locale, getter_AddRefs(coll));
|
2000-01-24 21:28:28 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-13 20:20:21 +00:00
|
|
|
|
2001-10-03 00:43:30 +00:00
|
|
|
mArray.Sort(compare, coll);
|
|
|
|
#else
|
|
|
|
mArray.Sort(compare, nsnull);
|
|
|
|
#endif
|
|
|
|
|
2004-12-04 10:19:29 +00:00
|
|
|
mBuf.AppendLiteral("300: ");
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString url;
|
2003-11-05 12:39:05 +00:00
|
|
|
rv = net_GetURLSpecFromFile(aDir, url);
|
2001-10-03 00:43:30 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
mBuf.Append(url);
|
|
|
|
mBuf.Append('\n');
|
|
|
|
|
2004-12-04 10:19:29 +00:00
|
|
|
mBuf.AppendLiteral("200: filename content-length last-modified file-type\n");
|
2001-10-03 00:43:30 +00:00
|
|
|
|
|
|
|
if (mFSCharset.IsEmpty()) {
|
|
|
|
// OK, set up the charset
|
|
|
|
#ifdef THREADSAFE_I18N
|
|
|
|
nsCOMPtr<nsIPlatformCharset> pc = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsString tmp;
|
|
|
|
rv = pc->GetCharset(kPlatformCharsetSel_FileName, tmp);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2005-06-24 19:44:50 +00:00
|
|
|
LossyCopyUTF16toASCII(tmp, mFSCharset);
|
2001-10-03 00:43:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
2002-02-20 02:14:17 +00:00
|
|
|
|
|
|
|
if (!mFSCharset.IsEmpty()) {
|
2004-12-04 10:19:29 +00:00
|
|
|
mBuf.AppendLiteral("301: ");
|
2002-02-20 02:14:17 +00:00
|
|
|
mBuf.Append(mFSCharset);
|
|
|
|
mBuf.Append('\n');
|
|
|
|
}
|
2001-10-03 00:43:30 +00:00
|
|
|
|
1999-09-13 20:20:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDirectoryIndexStream::~nsDirectoryIndexStream()
|
|
|
|
{
|
2001-10-03 00:43:30 +00:00
|
|
|
PRInt32 i;
|
|
|
|
for (i=0; i<mArray.Count(); ++i) {
|
|
|
|
nsIFile* elem = (nsIFile*)mArray.ElementAt(i);
|
|
|
|
NS_RELEASE(elem);
|
|
|
|
}
|
|
|
|
|
2000-02-08 01:16:09 +00:00
|
|
|
PR_LOG(gLog, PR_LOG_DEBUG,
|
|
|
|
("nsDirectoryIndexStream[%p]: destroyed", this));
|
1999-09-13 20:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-01-24 21:28:28 +00:00
|
|
|
nsDirectoryIndexStream::Create(nsIFile* aDir, nsIInputStream** aResult)
|
1999-09-13 20:20:21 +00:00
|
|
|
{
|
|
|
|
nsDirectoryIndexStream* result = new nsDirectoryIndexStream();
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
rv = result->Init(aDir);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete result;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = result;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-03 00:43:30 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsDirectoryIndexStream, nsIInputStream)
|
1999-09-13 20:20:21 +00:00
|
|
|
|
2001-10-03 00:43:30 +00:00
|
|
|
// The below routines are proxied to the UI thread!
|
1999-09-13 20:20:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDirectoryIndexStream::Close()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDirectoryIndexStream::Available(PRUint32* aLength)
|
|
|
|
{
|
2005-08-21 14:13:52 +00:00
|
|
|
// If there's data in our buffer, use that
|
|
|
|
if (mOffset < (PRInt32)mBuf.Length()) {
|
|
|
|
*aLength = mBuf.Length() - mOffset;
|
1999-09-13 20:20:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-08-21 14:13:52 +00:00
|
|
|
|
|
|
|
// Returning one byte is not ideal, but good enough
|
|
|
|
*aLength = (mPos < mArray.Count()) ? 1 : 0;
|
|
|
|
return NS_OK;
|
1999-09-13 20:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDirectoryIndexStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aReadCount)
|
|
|
|
{
|
|
|
|
PRUint32 nread = 0;
|
|
|
|
|
|
|
|
// If anything is enqueued (or left-over) in mBuf, then feed it to
|
|
|
|
// the reader first.
|
2000-07-25 05:45:56 +00:00
|
|
|
while (mOffset < (PRInt32)mBuf.Length() && aCount != 0) {
|
1999-09-13 20:20:21 +00:00
|
|
|
*(aBuf++) = char(mBuf.CharAt(mOffset++));
|
|
|
|
--aCount;
|
|
|
|
++nread;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Room left?
|
|
|
|
if (aCount > 0) {
|
|
|
|
mOffset = 0;
|
|
|
|
mBuf.Truncate();
|
|
|
|
|
|
|
|
// Okay, now we'll suck stuff off of our iterator into the mBuf...
|
2000-01-24 21:28:28 +00:00
|
|
|
while (PRUint32(mBuf.Length()) < aCount) {
|
2001-10-03 00:43:30 +00:00
|
|
|
PRBool more = mPos < mArray.Count();
|
2000-01-24 21:28:28 +00:00
|
|
|
if (!more) break;
|
|
|
|
|
2001-10-03 00:43:30 +00:00
|
|
|
nsCOMPtr<nsIFile> current = (nsIFile*)mArray.ElementAt(mPos);
|
|
|
|
++mPos;
|
2000-01-24 21:28:28 +00:00
|
|
|
|
2000-02-08 01:16:09 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString path;
|
|
|
|
current->GetNativePath(path);
|
2000-02-08 01:16:09 +00:00
|
|
|
PR_LOG(gLog, PR_LOG_DEBUG,
|
|
|
|
("nsDirectoryIndexStream[%p]: iterated %s",
|
2002-04-27 05:33:09 +00:00
|
|
|
this, path.get()));
|
2000-02-08 01:16:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-02-27 16:19:59 +00:00
|
|
|
// rjc: don't return hidden files/directories!
|
2001-10-03 00:43:30 +00:00
|
|
|
// bbaetz: why not?
|
|
|
|
nsresult rv;
|
|
|
|
#ifndef XP_UNIX
|
2002-01-15 00:51:11 +00:00
|
|
|
PRBool hidden = PR_FALSE;
|
|
|
|
current->IsHidden(&hidden);
|
2000-02-27 16:19:59 +00:00
|
|
|
if (hidden) {
|
|
|
|
PR_LOG(gLog, PR_LOG_DEBUG,
|
|
|
|
("nsDirectoryIndexStream[%p]: skipping hidden file/directory",
|
|
|
|
this));
|
|
|
|
continue;
|
|
|
|
}
|
2001-10-03 00:43:30 +00:00
|
|
|
#endif
|
|
|
|
|
2002-01-15 00:51:11 +00:00
|
|
|
PRInt64 fileSize = LL_Zero();
|
|
|
|
current->GetFileSize( &fileSize );
|
2003-07-09 02:28:07 +00:00
|
|
|
|
2002-01-15 00:51:11 +00:00
|
|
|
PRInt64 tmpTime = LL_Zero();
|
|
|
|
PRInt64 fileInfoModifyTime = LL_Zero();
|
|
|
|
current->GetLastModifiedTime( &tmpTime );
|
2001-10-03 00:43:30 +00:00
|
|
|
// Why does nsIFile give this back in milliseconds?
|
|
|
|
LL_MUL(fileInfoModifyTime, tmpTime, PR_USEC_PER_MSEC);
|
2002-01-15 00:51:11 +00:00
|
|
|
|
2004-12-04 10:19:29 +00:00
|
|
|
mBuf.AppendLiteral("201: ");
|
1999-09-13 20:20:21 +00:00
|
|
|
|
2001-10-03 00:43:30 +00:00
|
|
|
// The "filename" field
|
|
|
|
{
|
|
|
|
#ifdef THREADSAFE_I18N
|
|
|
|
nsXPIDLString leafname;
|
|
|
|
rv = current->GetUnicodeLeafName(getter_Copies(leafname));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!leafname.IsEmpty()) {
|
|
|
|
// XXX - this won't work with directories with spaces
|
|
|
|
// see bug 99478 - bbaetz
|
|
|
|
nsXPIDLCString escaped;
|
|
|
|
rv = mTextToSubURI->ConvertAndEscape(mFSCharset.get(),
|
|
|
|
leafname.get(),
|
|
|
|
getter_Copies(escaped));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
mBuf.Append(escaped);
|
|
|
|
mBuf.Append(' ');
|
|
|
|
}
|
|
|
|
#else
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString leafname;
|
|
|
|
rv = current->GetNativeLeafName(leafname);
|
2001-10-03 00:43:30 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!leafname.IsEmpty()) {
|
|
|
|
char* escaped = nsEscape(leafname.get(), url_Path);
|
|
|
|
if (escaped) {
|
|
|
|
mBuf += escaped;
|
|
|
|
mBuf.Append(' ');
|
|
|
|
nsCRT::free(escaped);
|
1999-09-13 20:20:21 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-03 00:43:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
1999-09-13 20:20:21 +00:00
|
|
|
|
|
|
|
// The "content-length" field
|
2004-04-18 13:20:54 +00:00
|
|
|
mBuf.AppendInt(fileSize, 10);
|
1999-09-13 20:20:21 +00:00
|
|
|
mBuf.Append(' ');
|
|
|
|
|
|
|
|
// The "last-modified" field
|
|
|
|
PRExplodedTime tm;
|
2000-02-27 16:19:59 +00:00
|
|
|
PR_ExplodeTime(fileInfoModifyTime, PR_GMTParameters, &tm);
|
1999-09-13 20:20:21 +00:00
|
|
|
{
|
|
|
|
char buf[64];
|
|
|
|
PR_FormatTimeUSEnglish(buf, sizeof(buf), "%a,%%20%d%%20%b%%20%Y%%20%H:%M:%S%%20GMT ", &tm);
|
|
|
|
mBuf.Append(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The "file-type" field
|
2002-01-15 00:51:11 +00:00
|
|
|
PRBool isFile = PR_TRUE;
|
|
|
|
current->IsFile(&isFile);
|
2000-01-24 21:28:28 +00:00
|
|
|
if (isFile) {
|
2004-12-04 10:19:29 +00:00
|
|
|
mBuf.AppendLiteral("FILE ");
|
1999-09-13 20:20:21 +00:00
|
|
|
}
|
2000-01-24 21:28:28 +00:00
|
|
|
else {
|
|
|
|
PRBool isDir;
|
|
|
|
rv = current->IsDirectory(&isDir);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (isDir) {
|
2004-12-04 10:19:29 +00:00
|
|
|
mBuf.AppendLiteral("DIRECTORY ");
|
2000-01-24 21:28:28 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRBool isLink;
|
|
|
|
rv = current->IsSymlink(&isLink);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (isLink) {
|
2004-12-04 10:19:29 +00:00
|
|
|
mBuf.AppendLiteral("SYMBOLIC-LINK ");
|
2000-01-24 21:28:28 +00:00
|
|
|
}
|
|
|
|
}
|
1999-09-13 20:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mBuf.Append('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
// ...and once we've either run out of directory entries, or
|
|
|
|
// filled up the buffer, then we'll push it to the reader.
|
2000-07-25 05:45:56 +00:00
|
|
|
while (mOffset < (PRInt32)mBuf.Length() && aCount != 0) {
|
1999-09-13 20:20:21 +00:00
|
|
|
*(aBuf++) = char(mBuf.CharAt(mOffset++));
|
|
|
|
--aCount;
|
|
|
|
++nread;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aReadCount = nread;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-08-22 07:03:33 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDirectoryIndexStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-12 00:59:06 +00:00
|
|
|
nsDirectoryIndexStream::IsNonBlocking(PRBool *aNonBlocking)
|
2000-08-22 07:03:33 +00:00
|
|
|
{
|
2002-03-12 00:59:06 +00:00
|
|
|
*aNonBlocking = PR_FALSE;
|
|
|
|
return NS_OK;
|
2000-08-22 07:03:33 +00:00
|
|
|
}
|