Bug 78148. Reorg directory viewer backend to allow file and gopher to use
the html view as well. (This is currently disabled for file because of i18n issues) Should also fix dirviewer bugs 38014, 68651, 72724, 78474, and part of 83881. git-svn-id: svn://10.0.0.236/trunk@104490 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
8b05be3419
commit
aeadd6f8db
103
mozilla/netwerk/streamconv/converters/nsDirIndex.cpp
Normal file
103
mozilla/netwerk/streamconv/converters/nsDirIndex.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is the directory index parsing code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bradley Baetz.
|
||||
* Portions created by Bradley Baetz are
|
||||
* Copyright (C) 2001 Bradley Baetz.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Bradley Baetz <bbaetz@cs.mcgill.ca>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the LGPL or the GPL. 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 ----- */
|
||||
|
||||
#include "nsDirIndex.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsDirIndex,
|
||||
nsIDirIndex);
|
||||
|
||||
nsDirIndex::nsDirIndex() : mType(TYPE_UNKNOWN),
|
||||
mSize((PRUint32)(-1)),
|
||||
mLastModified(-1) {
|
||||
NS_INIT_REFCNT();
|
||||
};
|
||||
|
||||
nsDirIndex::~nsDirIndex() {};
|
||||
|
||||
NS_IMPL_GETSET(nsDirIndex, Type, PRUint32, mType);
|
||||
|
||||
// GETSET macros for modern strings would be nice...
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndex::GetContentType(char* *aContentType) {
|
||||
*aContentType = ToNewCString(mContentType);
|
||||
if (!*aContentType)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndex::SetContentType(const char* aContentType) {
|
||||
mContentType.Adopt(nsCRT::strdup(aContentType));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndex::GetLocation(char* *aLocation) {
|
||||
*aLocation = ToNewCString(mLocation);
|
||||
if (!*aLocation)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndex::SetLocation(const char* aLocation) {
|
||||
mLocation.Adopt(nsCRT::strdup(aLocation));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndex::GetDescription(PRUnichar* *aDescription) {
|
||||
*aDescription = ToNewUnicode(mDescription);
|
||||
if (!*aDescription)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndex::SetDescription(const PRUnichar* aDescription) {
|
||||
mDescription.Assign(aDescription);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_GETSET(nsDirIndex, Size, PRUint32, mSize);
|
||||
NS_IMPL_GETSET(nsDirIndex, LastModified, PRInt64, mLastModified);
|
||||
|
||||
58
mozilla/netwerk/streamconv/converters/nsDirIndex.h
Normal file
58
mozilla/netwerk/streamconv/converters/nsDirIndex.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is the directory index parsing code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bradley Baetz.
|
||||
* Portions created by Bradley Baetz are
|
||||
* Copyright (C) 2001 Bradley Baetz.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Bradley Baetz <bbaetz@cs.mcgill.ca>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the LGPL or the GPL. 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 ----- */
|
||||
|
||||
#include "nsIDirIndex.h"
|
||||
#include "nsString.h"
|
||||
|
||||
/* CID: {f6913e2e-1dd1-11b2-84be-f455dee342af} */
|
||||
|
||||
class nsDirIndex : public nsIDirIndex {
|
||||
public:
|
||||
nsDirIndex();
|
||||
virtual ~nsDirIndex();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDIRINDEX
|
||||
|
||||
protected:
|
||||
PRUint32 mType;
|
||||
nsXPIDLCString mContentType;
|
||||
nsXPIDLCString mLocation;
|
||||
nsString mDescription;
|
||||
PRUint32 mSize;
|
||||
PRInt64 mLastModified;
|
||||
};
|
||||
458
mozilla/netwerk/streamconv/converters/nsDirIndexParser.cpp
Normal file
458
mozilla/netwerk/streamconv/converters/nsDirIndexParser.cpp
Normal file
@ -0,0 +1,458 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is the Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation.
|
||||
* Portions created by Netscape Communications Corporation are
|
||||
* Copyright (C) 1998-2001 Netscape Communications Corporation.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Chris Waterson <waterson@netscape.com>
|
||||
* Robert John Churchill <rjc@netscape.com>
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
* Bradley Baetz <bbaetz@cs.mcgill.ca>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the LGPL or the GPL. 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 ----- */
|
||||
|
||||
/* This parsing code originally lived in xpfe/components/directory/ - bbaetz */
|
||||
|
||||
#include "nsDirIndexParser.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsDirIndex.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS3(nsDirIndexParser,
|
||||
nsIRequestObserver,
|
||||
nsIStreamListener,
|
||||
nsIDirIndexParser)
|
||||
|
||||
nsDirIndexParser::nsDirIndexParser() {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDirIndexParser::Init() {
|
||||
mLineStart = 0;
|
||||
mHasDescription = PR_FALSE;
|
||||
mFormat = nsnull;
|
||||
|
||||
// set initial/default encoding to ISO-8859-1 (not UTF-8)
|
||||
mEncoding.Assign("ISO-8859-1");
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (gRefCntParser++ == 0) {
|
||||
rv = nsServiceManager::GetService(NS_ITEXTTOSUBURI_CONTRACTID,
|
||||
NS_GET_IID(nsITextToSubURI),
|
||||
NS_REINTERPRET_CAST(nsISupports**, &gTextToSubURI));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsDirIndexParser::~nsDirIndexParser() {
|
||||
delete[] mFormat;
|
||||
if (--gRefCntParser == 0) {
|
||||
NS_IF_RELEASE(gTextToSubURI);
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndexParser::SetListener(nsIDirIndexListener* aListener) {
|
||||
mListener = aListener;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndexParser::GetListener(nsIDirIndexListener** aListener) {
|
||||
NS_IF_ADDREF(*aListener = mListener.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndexParser::GetComment(char** aComment) {
|
||||
*aComment = ToNewCString(mComment);
|
||||
|
||||
if (!*aComment)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndexParser::SetEncoding(const char* aEncoding) {
|
||||
mEncoding.Assign(aEncoding);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndexParser::GetEncoding(char** aEncoding) {
|
||||
*aEncoding = ToNewCString(mEncoding);
|
||||
|
||||
if (!*aEncoding)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndexParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aCtxt) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndexParser::OnStopRequest(nsIRequest *aRequest, nsISupports *aCtxt,
|
||||
nsresult aStatusCode) {
|
||||
// Finish up
|
||||
if (mBuf.Length() > (PRUint32) mLineStart) {
|
||||
ProcessData(aRequest, aCtxt);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsDirIndexParser::Field
|
||||
nsDirIndexParser::gFieldTable[] = {
|
||||
{ "Filename", FIELD_FILENAME },
|
||||
{ "Description", FIELD_DESCRIPTION },
|
||||
{ "Content-Length", FIELD_CONTENTLENGTH },
|
||||
{ "Last-Modified", FIELD_LASTMODIFIED },
|
||||
{ "Content-Type", FIELD_CONTENTTYPE },
|
||||
{ "File-Type", FIELD_FILETYPE },
|
||||
{ nsnull, FIELD_UNKNOWN }
|
||||
};
|
||||
|
||||
nsrefcnt nsDirIndexParser::gRefCntParser = 0;
|
||||
nsITextToSubURI *nsDirIndexParser::gTextToSubURI;
|
||||
|
||||
nsresult
|
||||
nsDirIndexParser::ParseFormat(const char* aFormatStr) {
|
||||
// Parse a "200" format line, and remember the fields and their
|
||||
// ordering in mFormat. Multiple 200 lines stomp on each other.
|
||||
|
||||
delete[] mFormat;
|
||||
|
||||
// Lets find out how many elements we have.
|
||||
// easier to do this then realloc
|
||||
const char* pos = aFormatStr;
|
||||
int num = 0;
|
||||
do {
|
||||
while (*pos && nsCRT::IsAsciiSpace(PRUnichar(*pos)))
|
||||
++pos;
|
||||
|
||||
++num;
|
||||
|
||||
if (! *pos)
|
||||
break;
|
||||
|
||||
while (*pos && !nsCRT::IsAsciiSpace(PRUnichar(*pos)))
|
||||
++pos;
|
||||
|
||||
} while (*pos);
|
||||
|
||||
mFormat = new int[num+1];
|
||||
mFormat[num] = -1;
|
||||
|
||||
int formatNum=0;
|
||||
do {
|
||||
while (*aFormatStr && nsCRT::IsAsciiSpace(PRUnichar(*aFormatStr)))
|
||||
++aFormatStr;
|
||||
|
||||
if (! *aFormatStr)
|
||||
break;
|
||||
|
||||
nsCAutoString name;
|
||||
PRInt32 len = 0;
|
||||
while (aFormatStr[len] && !nsCRT::IsAsciiSpace(PRUnichar(aFormatStr[len])))
|
||||
++len;
|
||||
name.SetCapacity(len + 1);
|
||||
name.Append(aFormatStr, len);
|
||||
aFormatStr += len;
|
||||
|
||||
// Okay, we're gonna monkey with the nsStr. Bold!
|
||||
name.mLength = nsUnescapeCount(name.mStr);
|
||||
|
||||
// All tokens are case-insensitive - http://www.area.com/~roeber/file_format.html
|
||||
if (name.EqualsIgnoreCase("description"))
|
||||
mHasDescription = PR_TRUE;
|
||||
|
||||
for (Field* i = gFieldTable; i->mName; ++i) {
|
||||
if (name.EqualsIgnoreCase(i->mName)) {
|
||||
mFormat[formatNum] = i->mType;
|
||||
++formatNum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} while (*aFormatStr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDirIndexParser::ParseData(nsIDirIndex *aIdx, char* aDataStr) {
|
||||
// Parse a "201" data line, using the field ordering specified in
|
||||
// mFormat.
|
||||
|
||||
if (!mFormat) {
|
||||
// Ignore if we haven't seen a format yet.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCAutoString filename;
|
||||
|
||||
for (PRInt32 i = 0; mFormat[i] != -1; ++i) {
|
||||
// If we've exhausted the data before we run out of fields, just
|
||||
// bail.
|
||||
if (! *aDataStr)
|
||||
break;
|
||||
|
||||
while (*aDataStr && nsCRT::IsAsciiSpace(*aDataStr))
|
||||
++aDataStr;
|
||||
|
||||
char *value = aDataStr;
|
||||
|
||||
if (*aDataStr == '"' || *aDataStr == '\'') {
|
||||
// it's a quoted string. snarf everything up to the next quote character
|
||||
const char quotechar = *(aDataStr++);
|
||||
++value;
|
||||
while (*aDataStr && *aDataStr != quotechar)
|
||||
++aDataStr;
|
||||
*aDataStr++ = '\0';
|
||||
|
||||
if (! aDataStr) {
|
||||
NS_WARNING("quoted value not terminated");
|
||||
}
|
||||
} else {
|
||||
// it's unquoted. snarf until we see whitespace.
|
||||
value = aDataStr;
|
||||
while (*aDataStr && (!nsCRT::IsAsciiSpace(*aDataStr)))
|
||||
++aDataStr;
|
||||
*aDataStr++ = '\0';
|
||||
}
|
||||
|
||||
fieldType t = fieldType(mFormat[i]);
|
||||
switch (t) {
|
||||
case FIELD_FILENAME: {
|
||||
// don't unescape at this point, so that UnEscapeAndConvert() can
|
||||
filename = value;
|
||||
|
||||
PRBool success = PR_FALSE;
|
||||
|
||||
nsAutoString entryuri;
|
||||
|
||||
if (gTextToSubURI) {
|
||||
PRUnichar *result = nsnull;
|
||||
if (NS_SUCCEEDED(rv = gTextToSubURI->UnEscapeAndConvert(mEncoding.get(), filename,
|
||||
&result)) && (result)) {
|
||||
if (nsCRT::strlen(result) > 0) {
|
||||
aIdx->SetLocation(filename);
|
||||
if (!mHasDescription)
|
||||
aIdx->SetDescription(result);
|
||||
success = PR_TRUE;
|
||||
}
|
||||
Recycle(result);
|
||||
} else {
|
||||
NS_WARNING("UnEscapeAndConvert error");
|
||||
}
|
||||
}
|
||||
|
||||
if (success == PR_FALSE) {
|
||||
// if unsuccessfully at charset conversion, then
|
||||
// just fallback to unescape'ing in-place
|
||||
// XXX - this shouldn't be using UTF8, should it?
|
||||
// when can we fail to get the service, anyway? - bbaetz
|
||||
aIdx->SetLocation(filename);
|
||||
if (!mHasDescription) {
|
||||
aIdx->SetDescription(NS_ConvertUTF8toUCS2(value).get());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FIELD_DESCRIPTION:
|
||||
nsUnescape(value);
|
||||
aIdx->SetDescription(NS_ConvertUTF8toUCS2(value).get());
|
||||
break;
|
||||
case FIELD_CONTENTLENGTH:
|
||||
{
|
||||
unsigned long len = strtoul(value,NULL,10);
|
||||
aIdx->SetSize(len);
|
||||
}
|
||||
break;
|
||||
case FIELD_LASTMODIFIED:
|
||||
{
|
||||
PRTime tm;
|
||||
nsUnescape(value);
|
||||
if (PR_ParseTimeString(value, PR_FALSE, &tm) == PR_SUCCESS) {
|
||||
aIdx->SetLastModified(tm);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FIELD_CONTENTTYPE:
|
||||
aIdx->SetContentType(value);
|
||||
break;
|
||||
case FIELD_FILETYPE:
|
||||
// unescape in-place
|
||||
nsUnescape(value);
|
||||
if (!nsCRT::strcasecmp(value, "directory")) {
|
||||
aIdx->SetType(nsIDirIndex::TYPE_DIRECTORY);
|
||||
} else if (!nsCRT::strcasecmp(value, "file")) {
|
||||
aIdx->SetType(nsIDirIndex::TYPE_FILE);
|
||||
} else if (!nsCRT::strcasecmp(value, "symbolic-link")) {
|
||||
aIdx->SetType(nsIDirIndex::TYPE_SYMLINK);
|
||||
} else {
|
||||
aIdx->SetType(nsIDirIndex::TYPE_UNKNOWN);
|
||||
}
|
||||
break;
|
||||
case FIELD_UNKNOWN:
|
||||
// ignore
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDirIndexParser::OnDataAvailable(nsIRequest *aRequest, nsISupports *aCtxt,
|
||||
nsIInputStream *aStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aCount) {
|
||||
if (aCount < 1)
|
||||
return NS_OK;
|
||||
|
||||
PRInt32 len = mBuf.Length();
|
||||
|
||||
// Ensure that our mBuf has capacity to hold the data we're about to
|
||||
// read.
|
||||
mBuf.SetCapacity(len + aCount + 1);
|
||||
if (! mBuf.mStr)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
// Now read the data into our buffer.
|
||||
nsresult rv;
|
||||
PRUint32 count;
|
||||
rv = aStream->Read(mBuf.mStr + len, aCount, &count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Set the string's length according to the amount of data we've read.
|
||||
//
|
||||
// XXX You'd think that mBuf.SetLength() would do this, but it
|
||||
// doesn't. It calls Truncate(), so you can't set the length to
|
||||
// something longer.
|
||||
mBuf.mLength = len + count;
|
||||
AddNullTerminator(mBuf);
|
||||
|
||||
return ProcessData(aRequest, aCtxt);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDirIndexParser::ProcessData(nsIRequest *aRequest, nsISupports *aCtxt) {
|
||||
if (!mListener)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRInt32 numItems = 0;
|
||||
|
||||
while(PR_TRUE) {
|
||||
++numItems;
|
||||
|
||||
PRInt32 eol = mBuf.FindCharInSet("\n\r", mLineStart);
|
||||
if (eol < 0) break;
|
||||
mBuf.SetCharAt(PRUnichar('\0'), eol);
|
||||
|
||||
const char *line = &mBuf.mStr[mLineStart];
|
||||
|
||||
PRInt32 lineLen = eol - mLineStart;
|
||||
mLineStart = eol + 1;
|
||||
|
||||
if (lineLen >= 4) {
|
||||
nsresult rv;
|
||||
const char *buf = line;
|
||||
|
||||
if (buf[0] == '1') {
|
||||
if (buf[1] == '0') {
|
||||
if (buf[2] == '0' && buf[3] == ':') {
|
||||
// 100. Human-readable comment line. Ignore
|
||||
} else if (buf[2] == '1' && buf[3] == ':') {
|
||||
// 101. Human-readable information line.
|
||||
mComment.Append(buf + 4);
|
||||
} else if (buf[2] == '2' && buf[3] == ':') {
|
||||
// 102. Human-readable information line, HTML.
|
||||
mComment.Append(buf + 4);
|
||||
}
|
||||
}
|
||||
} else if (buf[0] == '2') {
|
||||
if (buf[1] == '0') {
|
||||
if (buf[2] == '0' && buf[3] == ':') {
|
||||
// 200. Define field names
|
||||
rv = ParseFormat(buf + 4);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
} else if (buf[2] == '1' && buf[3] == ':') {
|
||||
// 201. Field data
|
||||
nsCOMPtr<nsIDirIndex> idx = do_CreateInstance("@mozilla.org/dirIndex;1",&rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = ParseData(idx, ((char *)buf) + 4);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
mListener->OnIndexAvailable(aRequest, aCtxt, idx);
|
||||
}
|
||||
}
|
||||
} else if (buf[0] == '3') {
|
||||
if (buf[1] == '0') {
|
||||
if (buf[2] == '0' && buf[3] == ':') {
|
||||
// 300. Self-referring URL
|
||||
} else if (buf[2] == '1' && buf[3] == ':') {
|
||||
// 301. OUR EXTENSION - encoding
|
||||
int i = 4;
|
||||
while (buf[i] && nsCRT::IsAsciiSpace(buf[i]))
|
||||
++i;
|
||||
|
||||
if (buf[i])
|
||||
SetEncoding(buf+i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
100
mozilla/netwerk/streamconv/converters/nsDirIndexParser.h
Normal file
100
mozilla/netwerk/streamconv/converters/nsDirIndexParser.h
Normal file
@ -0,0 +1,100 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is the Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation.
|
||||
* Portions created by Netscape Communications Corporation are
|
||||
* Copyright (C) 1998-2001 Netscape Communications Corporation.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Chris Waterson <waterson@netscape.com>
|
||||
* Robert John Churchill <rjc@netscape.com>
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
* Bradley Baetz <bbaetz@cs.mcgill.ca>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the LGPL or the GPL. 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 ----- */
|
||||
|
||||
#ifndef __NSDIRINDEX_H_
|
||||
#define __NSDIRINDEX_H_
|
||||
|
||||
#include "nsIDirIndex.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDirIndexListener.h"
|
||||
#include "nsITextToSubURI.h"
|
||||
|
||||
/* CID: {a0d6ad32-1dd1-11b2-aa55-a40187b54036} */
|
||||
|
||||
class nsDirIndexParser : public nsIDirIndexParser {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSIDIRINDEXPARSER
|
||||
|
||||
nsDirIndexParser();
|
||||
virtual ~nsDirIndexParser();
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIDirIndexListener> mListener;
|
||||
|
||||
nsCString mEncoding;
|
||||
nsCString mComment;
|
||||
nsCString mBuf;
|
||||
PRInt32 mLineStart;
|
||||
PRBool mHasDescription;
|
||||
int* mFormat;
|
||||
|
||||
nsresult ProcessData(nsIRequest *aRequest, nsISupports *aCtxt);
|
||||
nsresult ParseFormat(const char* buf);
|
||||
nsresult ParseData(nsIDirIndex* aIdx, char* aDataStr);
|
||||
|
||||
enum fieldType {
|
||||
FIELD_UNKNOWN = 0, // MUST be 0
|
||||
FIELD_FILENAME,
|
||||
FIELD_DESCRIPTION,
|
||||
FIELD_CONTENTLENGTH,
|
||||
FIELD_LASTMODIFIED,
|
||||
FIELD_CONTENTTYPE,
|
||||
FIELD_FILETYPE
|
||||
};
|
||||
|
||||
struct Field {
|
||||
const char *mName;
|
||||
fieldType mType;
|
||||
};
|
||||
|
||||
static Field gFieldTable[];
|
||||
|
||||
static nsrefcnt gRefCntParser;
|
||||
static nsITextToSubURI* gTextToSubURI;
|
||||
};
|
||||
|
||||
#endif
|
||||
114
mozilla/netwerk/streamconv/public/nsIDirIndex.idl
Normal file
114
mozilla/netwerk/streamconv/public/nsIDirIndex.idl
Normal file
@ -0,0 +1,114 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is the directory index parsing code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bradley Baetz.
|
||||
* Portions created by Bradley Baetz are
|
||||
* Copyright (C) 2001 Bradley Baetz.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Bradley Baetz <bbaetz@cs.mcgill.ca>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the LGPL or the GPL. 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 ----- */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/** A class holding information about a directory index.
|
||||
* These have no reference back to their original source -
|
||||
* changing these attributes won't affect the directory
|
||||
*/
|
||||
[scriptable, uuid(23bbabd0-1dd2-11b2-86b7-aad68ae7d7e0)]
|
||||
interface nsIDirIndex : nsISupports
|
||||
{
|
||||
/**
|
||||
* Entry's type is unknown
|
||||
*/
|
||||
const unsigned long TYPE_UNKNOWN = 0;
|
||||
|
||||
/**
|
||||
* Entry is a directory
|
||||
*/
|
||||
const unsigned long TYPE_DIRECTORY = 1;
|
||||
|
||||
/**
|
||||
* Entry is a file
|
||||
*/
|
||||
const unsigned long TYPE_FILE = 2;
|
||||
|
||||
/**
|
||||
* Entry is a symlink
|
||||
*/
|
||||
const unsigned long TYPE_SYMLINK = 3;
|
||||
|
||||
/**
|
||||
* The type of the entry - one of the constants above
|
||||
*/
|
||||
attribute unsigned long type;
|
||||
|
||||
/**
|
||||
* The content type - may be null if it is unknown.
|
||||
* Unspecified for directories
|
||||
*/
|
||||
attribute string contentType;
|
||||
|
||||
/**
|
||||
* The fully qualified filename, expressed as a uri
|
||||
*
|
||||
* This is encoded with the encoding specified in
|
||||
* the nsIDirIndexParser, and is also escaped.
|
||||
*/
|
||||
attribute string location;
|
||||
|
||||
/**
|
||||
* A description for the filename, which should be
|
||||
* displayed by a viewer
|
||||
*/
|
||||
attribute wstring description;
|
||||
|
||||
/**
|
||||
* File size, with -1 meaning "unknown"
|
||||
*/
|
||||
attribute unsigned long size;
|
||||
|
||||
/**
|
||||
* Last-modified time in seconds-since-epoch.
|
||||
* -1 means unknown - this is valid, because there were no
|
||||
* ftp servers in 1969
|
||||
*/
|
||||
attribute long long lastModified;
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
#define NS_DIRINDEX_CID \
|
||||
/* { f6913e2e-1dd1-11b2-84be-f455dee342af } */ \
|
||||
{ 0xf6913e2e, \
|
||||
0x1dd1, \
|
||||
0x11b2, \
|
||||
{ 0x84, 0xbe, 0xf4, 0x55, 0xde, 0xe3, 0x42, 0xaf } \
|
||||
}
|
||||
%}
|
||||
99
mozilla/netwerk/streamconv/public/nsIDirIndexListener.idl
Normal file
99
mozilla/netwerk/streamconv/public/nsIDirIndexListener.idl
Normal file
@ -0,0 +1,99 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is the directory index parsing code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bradley Baetz.
|
||||
* Portions created by Bradley Baetz are
|
||||
* Copyright (C) 2001 Bradley Baetz.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Bradley Baetz <bbaetz@cs.mcgill.ca>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the LGPL or the GPL. 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 ----- */
|
||||
|
||||
#include "nsIStreamListener.idl"
|
||||
|
||||
interface nsIDirIndex;
|
||||
|
||||
/**
|
||||
* This interface is used to receive contents of directory index listings
|
||||
* from a protocol. They can then be transformed into an output format
|
||||
* (such as rdf, html, etc)
|
||||
*/
|
||||
[scriptable, uuid(fae4e9a8-1dd1-11b2-b53c-8f3aa1bbf8f5)]
|
||||
interface nsIDirIndexListener : nsISupports {
|
||||
/**
|
||||
* Called for each directory entry
|
||||
*
|
||||
* @param request - the request
|
||||
* @param ctxt - opaque parameter
|
||||
* @param index - new index to add
|
||||
*/
|
||||
void onIndexAvailable(in nsIRequest aRequest,
|
||||
in nsISupports aCtxt,
|
||||
in nsIDirIndex aIndex);
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_IDIRINDEXLISTENER_KEY "@mozilla.org/dirIndexListener;1"
|
||||
%}
|
||||
|
||||
/**
|
||||
* A parser for application/http-index-format
|
||||
*/
|
||||
[scriptable, uuid(38e3066c-1dd2-11b2-9b59-8be515c1ee3f)]
|
||||
interface nsIDirIndexParser : nsIStreamListener {
|
||||
/**
|
||||
* The interface to use as a callback for new entries
|
||||
*/
|
||||
attribute nsIDirIndexListener listener;
|
||||
|
||||
/**
|
||||
* The comment given, if any
|
||||
* This result is only valid _after_ OnStopRequest has occurred,
|
||||
* because it can occur anywhere in the datastream
|
||||
*/
|
||||
readonly attribute string comment;
|
||||
|
||||
/**
|
||||
* The encoding to use
|
||||
*/
|
||||
attribute string encoding;
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_DIRINDEXPARSER_CID \
|
||||
{ /* a0d6ad32-1dd1-11b2-aa55-a40187b54036 */ \
|
||||
0xa0d6ad32, \
|
||||
0x1dd1, \
|
||||
0x11b2, \
|
||||
{ 0xaa, 0x55, 0xa4, 0x01, 0x87, 0xb5, 0x40, 0x36 } \
|
||||
}
|
||||
|
||||
#define NS_DIRINDEXPARSER_CONTRACTID "@mozilla.org/dirIndexParser;1"
|
||||
|
||||
%}
|
||||
Loading…
x
Reference in New Issue
Block a user