make nsILineInputStream take an nsACString ref, 197166, r=darin, sr=mscott, make local msg body search cache open file stream, use nsIFile instead of nsFileSpec to cut down on seeks, improve performance, sr=mscott 240538

This commit is contained in:
bienvenu%nventure.com 2004-04-22 15:32:54 +00:00
parent 548aa6d63c
commit 4d40ab419f
30 changed files with 642 additions and 740 deletions

View File

@ -876,6 +876,7 @@ BookmarkParser::Parse(nsIRDFResource *aContainer, nsIRDFResource *aNodeType)
nsCOMPtr<nsIRDFResource> bookmarkNode = aContainer;
nsAutoString description, line;
nsCAutoString cLine;
PRBool isActiveFlag = PR_TRUE, inDescriptionFlag = PR_FALSE;
if ((mContents) && (mContentsLen > 0))
@ -927,7 +928,8 @@ BookmarkParser::Parse(nsIRDFResource *aContainer, nsIRDFResource *aNodeType)
while(NS_SUCCEEDED(rv) && isActiveFlag && moreData)
{
rv = lineInputStream->ReadLine(line, &moreData);
rv = lineInputStream->ReadLine(cLine, &moreData);
CopyASCIItoUTF16(cLine, line);
if (NS_SUCCEEDED(rv))
{

View File

@ -392,7 +392,7 @@ nsDogbertProfileMigrator::FixDogbertCookies()
if (!fileOutputStream) return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsILineInputStream> lineInputStream(do_QueryInterface(fileInputStream));
nsAutoString buffer, outBuffer;
nsCAutoString buffer, outBuffer;
PRBool moreData = PR_FALSE;
PRUint32 written = 0;
do {
@ -405,7 +405,7 @@ nsDogbertProfileMigrator::FixDogbertCookies()
// skip line if it is a comment or null line
if (buffer.IsEmpty() || buffer.CharAt(0) == '#' ||
buffer.CharAt(0) == nsCRT::CR || buffer.CharAt(0) == nsCRT::LF) {
fileOutputStream->Write((const char*)buffer.get(), buffer.Length(), &written);
fileOutputStream->Write(buffer.get(), buffer.Length(), &written);
continue;
}
@ -421,7 +421,7 @@ nsDogbertProfileMigrator::FixDogbertCookies()
continue;
// separate the expires field from the rest of the cookie line
nsAutoString prefix, expiresString, suffix;
nsCAutoString prefix, expiresString, suffix;
buffer.Mid(prefix, hostIndex, expiresIndex-hostIndex-1);
buffer.Mid(expiresString, expiresIndex, nameIndex-expiresIndex-1);
buffer.Mid(suffix, nameIndex, buffer.Length()-nameIndex);
@ -440,14 +440,12 @@ nsDogbertProfileMigrator::FixDogbertCookies()
// generate the output buffer and write it to file
outBuffer = prefix;
outBuffer.Append(PRUnichar('\t'));
outBuffer.AppendWithConversion(dateString);
outBuffer.Append(PRUnichar('\t'));
outBuffer.Append('\t');
outBuffer.Append(dateString);
outBuffer.Append('\t');
outBuffer.Append(suffix);
nsCAutoString convertedBuffer;
convertedBuffer.Assign(NS_ConvertUCS2toUTF8(outBuffer));
fileOutputStream->Write(convertedBuffer.get(), convertedBuffer.Length(), &written);
fileOutputStream->Write(outBuffer.get(), outBuffer.Length(), &written);
}
while (1);
@ -511,7 +509,7 @@ nsDogbertProfileMigrator::MigrateDogbertBookmarks()
if (!outputStream) return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsILineInputStream> lineInputStream(do_QueryInterface(fileInputStream));
nsAutoString sourceBuffer;
nsCAutoString sourceBuffer;
nsCAutoString targetBuffer;
PRBool moreData = PR_FALSE;
PRUint32 bytesWritten = 0;
@ -525,14 +523,14 @@ nsDogbertProfileMigrator::MigrateDogbertBookmarks()
PRInt32 nameOffset = sourceBuffer.Find(toolbarName);
if (nameOffset >= 0) {
// Found the personal toolbar name on a line, check to make sure it's actually a folder.
NS_NAMED_LITERAL_STRING(folderPrefix, "<DT><H3 ");
NS_NAMED_LITERAL_CSTRING(folderPrefix, "<DT><H3 ");
PRInt32 folderPrefixOffset = sourceBuffer.Find(folderPrefix);
if (folderPrefixOffset >= 0)
sourceBuffer.Insert(NS_LITERAL_STRING("PERSONAL_TOOLBAR_FOLDER=\"true\" "),
sourceBuffer.Insert(NS_LITERAL_CSTRING("PERSONAL_TOOLBAR_FOLDER=\"true\" "),
folderPrefixOffset + folderPrefix.Length());
}
targetBuffer.Assign(NS_ConvertUCS2toUTF8(sourceBuffer));
targetBuffer.Assign(sourceBuffer);
targetBuffer.Append("\r\n");
outputStream->Write(targetBuffer.get(), targetBuffer.Length(), &bytesWritten);
}

View File

@ -413,7 +413,6 @@ nsNetscapeProfileMigratorBase::ImportNetscapeCookies(nsIFile* aCookiesFile)
// This code is copied from mozilla/netwerk/cookie/src/nsCookieManager.cpp
static NS_NAMED_LITERAL_CSTRING(kTrue, "TRUE");
nsAutoString bufferUnicode;
nsCAutoString buffer;
PRBool isMore = PR_TRUE;
PRInt32 hostIndex = 0, isDomainIndex, pathIndex, secureIndex, expiresIndex, nameIndex, cookieIndex;
@ -439,11 +438,7 @@ nsNetscapeProfileMigratorBase::ImportNetscapeCookies(nsIFile* aCookiesFile)
* most-recently used come first; least-recently-used come last.
*/
while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(bufferUnicode, &isMore))) {
// downconvert to ASCII. eventually, we want to fix nsILineInputStream
// to operate on a CString buffer...
CopyUCS2toASCII(bufferUnicode, buffer);
while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(buffer, &isMore))) {
if (buffer.IsEmpty() || buffer.First() == '#')
continue;

View File

@ -917,7 +917,7 @@ nsOperaProfileMigrator::CopyHistory(PRBool aReplace)
nsCOMPtr<nsILineInputStream> lineStream = do_QueryInterface(fileStream);
nsAutoString buffer, title, url;
nsCAutoString buffer, title, url;
PRTime lastVisitDate;
PRBool moreData = PR_FALSE;
@ -948,8 +948,8 @@ nsOperaProfileMigrator::CopyHistory(PRBool aReplace)
LL_I2L(million, PR_USEC_PER_SEC);
LL_MUL(lastVisitDate, temp, million);
nsCAutoString urlStr; urlStr.AssignWithConversion(url);
hist->AddPageWithDetails(urlStr.get(), title.get(), lastVisitDate);
nsAutoString titleStr; titleStr.AssignWithConversion(title);
hist->AddPageWithDetails(url.get(), titleStr.get(), lastVisitDate);
state = TITLE;
break;
@ -1222,11 +1222,13 @@ nsOperaProfileMigrator::ParseBookmarksFolder(nsILineInputStream* aStream,
PRBool onToolbar = PR_FALSE;
NS_NAMED_LITERAL_STRING(empty, "");
do {
rv = aStream->ReadLine(buffer, &moreData);
nsCAutoString cBuffer;
rv = aStream->ReadLine(cBuffer, &moreData);
if (NS_FAILED(rv)) return rv;
if (!moreData) break;
CopyASCIItoUTF16(cBuffer, buffer);
nsXPIDLString data;
LineType type = GetLineType(buffer, getter_Copies(data));
switch(type) {

View File

@ -643,11 +643,9 @@ nsPermissionManager::Read()
mHasUnknownTypes = PR_FALSE;
nsAutoString bufferUnicode;
nsCAutoString buffer;
PRBool isMore = PR_TRUE;
while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(bufferUnicode, &isMore))) {
CopyUCS2toASCII(bufferUnicode, buffer);
while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(buffer, &isMore))) {
if (buffer.IsEmpty() || buffer.First() == '#') {
continue;
}
@ -848,11 +846,9 @@ nsPermissionManager::Write()
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsILineInputStream> lineInputStream = do_QueryInterface(fileInputStream, &rv);
if (NS_SUCCEEDED(rv)) {
nsAutoString bufferUnicode;
nsCAutoString buffer;
PRBool isMore = PR_TRUE;
while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(bufferUnicode, &isMore))) {
LossyCopyUTF16toASCII(bufferUnicode, buffer);
while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(buffer, &isMore))) {
if (buffer.IsEmpty() || buffer.First() == '#' ||
StringBeginsWith(buffer, NS_LITERAL_CSTRING(kMatchTypeHost)))
continue;

View File

@ -55,7 +55,7 @@
* ***** END LICENSE BLOCK ***** */
#include "myspAffixmgr.h"
#include "nsIFile.h"
#include "nsReadCLine.h"
#include "nsReadLine.h"
#include "nsReadableUtils.h"
#include "nsDirectoryServiceDefs.h"
#include "plstr.h"

View File

@ -42,83 +42,4 @@
#include "nsReadLine.h"
#include "nsString.h"
static nsresult
NS_ReadLine (nsIInputStream* aStream, nsLineBuffer * aBuffer,
nsACString & aLine, PRBool *more) {
nsresult rv = NS_OK;
PRUint32 bytesRead;
nsCAutoString temp;
*more = PR_TRUE;
PRBool eolStarted = PR_FALSE;
char eolchar='\0';
aLine.Truncate();
while (1) { // will be returning out of this loop on eol or eof
if (aBuffer->empty) { // buffer is empty. Read into it.
rv = aStream->Read(aBuffer->buf, kLineBufferSize, &bytesRead);
if (NS_FAILED(rv)) // read failed
return rv;
if (bytesRead == 0) { // end of file
*more = PR_FALSE;
return NS_OK;
}
aBuffer->end = aBuffer->buf + bytesRead;
aBuffer->empty = PR_FALSE;
*(aBuffer->end) = '\0'; // null-terminate this thing
}
// walk the buffer looking for an end-of-line
while (aBuffer->current < aBuffer->end) {
if (eolStarted) {
if ((eolchar == '\n' && *(aBuffer->current) == '\r') ||
(eolchar == '\r' && *(aBuffer->current) == '\n')) { // line end
(aBuffer->current)++;
aBuffer->start = aBuffer->current;
}
eolStarted = PR_FALSE;
return NS_OK;
} else if (*(aBuffer->current) == '\n' ||
*(aBuffer->current) == '\r') { // line end
eolStarted = PR_TRUE;
eolchar = *(aBuffer->current);
*(aBuffer->current) = '\0';
temp.Assign(aBuffer->start);
aLine.Append(temp);
(aBuffer->current)++;
aBuffer->start = aBuffer->current;
} else {
eolStarted = PR_FALSE;
(aBuffer->current)++;
}
}
// append whatever we currently have to the string
temp.Assign(aBuffer->start);
aLine.Append(temp);
// we've run out of buffer. Begin anew
aBuffer->current = aBuffer->start = aBuffer->buf;
aBuffer->empty = PR_TRUE;
if (eolStarted) { // have to read another char and possibly skip over it
rv = aStream->Read(aBuffer->buf, 1, &bytesRead);
if (NS_FAILED(rv)) // read failed
return rv;
if (bytesRead == 0) { // end of file
*more = PR_FALSE;
return NS_OK;
}
if ((eolchar == '\n' && *(aBuffer->buf) == '\r') ||
(eolchar == '\r' && *(aBuffer->buf) == '\n')) {
// Just return and all is good -- we've skipped the extra newline char
return NS_OK;
} else {
// we have a byte that we should look at later
aBuffer->empty = PR_FALSE;
aBuffer->end = aBuffer->buf + 1;
*(aBuffer->end) = '\0';
}
}
}
}
#endif // nsReadCLine_h__

View File

@ -38,12 +38,14 @@
#include "nsIMsgSearchSession.idl"
interface nsIFileSpec;
interface nsILocalFile;
interface nsIMsgFolder;
interface nsILineInputStream;
[scriptable, uuid(10f5c44f-5a11-44e0-9b6b-4db81ba97963)]
interface nsIMsgSearchScopeTerm : nsISupports {
readonly attribute nsIFileSpec mailPath;
readonly attribute nsILocalFile mailFile;
attribute nsIInputStream inputStream;
readonly attribute nsIMsgFolder folder;
readonly attribute nsIMsgSearchSession searchSession;
};

View File

@ -3,10 +3,9 @@
#define __nsMsgBodyHandler_h
#include "nsIMsgSearchScopeTerm.h"
#include "nsIFileSpec.h"
#include "nsILineInputStream.h"
//---------------------------------------------------------------------------
// MSG_BodyHandler: used to retrive lines from POP and IMAP offline messages.
// nsMsgBodyHandler: used to retrive lines from POP and IMAP offline messages.
// This is a helper class used by nsMsgSearchTerm::MatchBody
//---------------------------------------------------------------------------
class nsMsgBodyHandler
@ -29,8 +28,8 @@ public:
virtual ~nsMsgBodyHandler();
// returns next message line in buf, up to bufSize bytes.
PRInt32 GetNextLine(char * buf, int bufSize);
// returns next message line in buf
PRInt32 GetNextLine(nsCString &buf);
// Transformations
void SetStripHtml (PRBool strip) { m_stripHtml = strip; }
@ -42,7 +41,7 @@ protected:
// filter related methods. For filtering we always use the headers
// list instead of the database...
PRBool m_Filtering;
PRInt32 GetNextFilterLine(char * buf, PRUint32 bufSize);
PRInt32 GetNextFilterLine(nsCString &buf);
// pointer into the headers list in the original message hdr db...
const char * m_headers;
PRUint32 m_headersSize;
@ -52,10 +51,11 @@ protected:
void OpenLocalFolder();
// goes through the mail folder
PRInt32 GetNextLocalLine(char * buf, int bufSize);
PRInt32 GetNextLocalLine(nsCString &buf);
nsIMsgSearchScopeTerm *m_scope;
nsCOMPtr <nsIFileSpec> m_fileSpec;
nsCOMPtr <nsILineInputStream> m_fileLineStream;
nsCOMPtr <nsILocalFile> m_localFile;
// local file state
// XP_File *m_localFile;
// need a file stream here, I bet
@ -75,7 +75,7 @@ protected:
PRBool m_stripHtml; // PR_TRUE if we're supposed to strip off HTML tags
PRBool m_passedHeaders; // PR_TRUE if we've already skipped over the headers
PRBool m_messageIsHtml; // PR_TRUE if the Content-type header claims text/html
PRInt32 ApplyTransformations (char *buf, PRInt32 length, PRBool &returnThisLine);
void StripHtml (char *buf);
PRInt32 ApplyTransformations (nsCString &buf, PRInt32 length, PRBool &returnThisLine);
void StripHtml (nsCString &buf);
};
#endif

View File

@ -69,67 +69,67 @@ inline PRBool IsStringAttribute (nsMsgSearchAttribValue a)
class nsMsgSearchAdapter : public nsIMsgSearchAdapter
{
public:
nsMsgSearchAdapter (nsIMsgSearchScopeTerm*, nsISupportsArray *);
virtual ~nsMsgSearchAdapter ();
nsMsgSearchAdapter (nsIMsgSearchScopeTerm*, nsISupportsArray *);
virtual ~nsMsgSearchAdapter ();
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGSEARCHADAPTER
nsIMsgSearchScopeTerm *m_scope;
nsCOMPtr<nsISupportsArray> m_searchTerms; /* linked list of criteria terms */
nsIMsgSearchScopeTerm *m_scope;
nsCOMPtr<nsISupportsArray> m_searchTerms; /* linked list of criteria terms */
PRBool m_abortCalled;
nsXPIDLString m_defaultCharset;
PRBool m_forceAsciiSearch;
PRBool m_abortCalled;
nsXPIDLString m_defaultCharset;
PRBool m_forceAsciiSearch;
static nsresult EncodeImap (char **ppEncoding,
nsISupportsArray *searchTerms,
const PRUnichar *srcCharset,
const PRUnichar *destCharset,
PRBool reallyDredd = PR_FALSE);
static nsresult EncodeImap (char **ppEncoding,
nsISupportsArray *searchTerms,
const PRUnichar *srcCharset,
const PRUnichar *destCharset,
PRBool reallyDredd = PR_FALSE);
static nsresult EncodeImapValue(char *encoding, const char *value, PRBool useQuotes, PRBool reallyDredd);
static nsresult EncodeImapValue(char *encoding, const char *value, PRBool useQuotes, PRBool reallyDredd);
static char *GetImapCharsetParam(const PRUnichar *destCharset);
static char *GetImapCharsetParam(const PRUnichar *destCharset);
static PRUnichar *EscapeSearchUrl (const PRUnichar *nntpCommand);
static PRUnichar *EscapeImapSearchProtocol(const PRUnichar *imapCommand);
static PRUnichar *EscapeQuoteImapSearchProtocol(const PRUnichar *imapCommand);
static char *UnEscapeSearchUrl (const char *commandSpecificData);
// This stuff lives in the base class because the IMAP search syntax
// is used by the Dredd SEARCH command as well as IMAP itself
static const char *m_kImapBefore;
static const char *m_kImapBody;
static const char *m_kImapCC;
static const char *m_kImapFrom;
static const char *m_kImapNot;
static const char *m_kImapOr;
static const char *m_kImapSince;
static const char *m_kImapSubject;
static const char *m_kImapTo;
static const char *m_kImapHeader;
static const char *m_kImapAnyText;
static const char *m_kImapKeyword;
static const char *m_kNntpKeywords;
static const char *m_kImapSentOn;
static const char *m_kImapSeen;
static const char *m_kImapAnswered;
static const char *m_kImapNotSeen;
static const char *m_kImapNotAnswered;
static const char *m_kImapCharset;
static const char *m_kImapUnDeleted;
// This stuff lives in the base class because the IMAP search syntax
// is used by the Dredd SEARCH command as well as IMAP itself
static const char *m_kImapBefore;
static const char *m_kImapBody;
static const char *m_kImapCC;
static const char *m_kImapFrom;
static const char *m_kImapNot;
static const char *m_kImapOr;
static const char *m_kImapSince;
static const char *m_kImapSubject;
static const char *m_kImapTo;
static const char *m_kImapHeader;
static const char *m_kImapAnyText;
static const char *m_kImapKeyword;
static const char *m_kNntpKeywords;
static const char *m_kImapSentOn;
static const char *m_kImapSeen;
static const char *m_kImapAnswered;
static const char *m_kImapNotSeen;
static const char *m_kImapNotAnswered;
static const char *m_kImapCharset;
static const char *m_kImapUnDeleted;
protected:
typedef enum _msg_TransformType
{
kOverwrite, /* "John Doe" -> "John*Doe", simple contains */
kInsert, /* "John Doe" -> "John* Doe", name completion */
kSurround /* "John Doe" -> "John* *Doe", advanced contains */
} msg_TransformType;
typedef enum _msg_TransformType
{
kOverwrite, /* "John Doe" -> "John*Doe", simple contains */
kInsert, /* "John Doe" -> "John* Doe", name completion */
kSurround /* "John Doe" -> "John* *Doe", advanced contains */
} msg_TransformType;
char *TransformSpacesToStars (const char *, msg_TransformType transformType);
nsresult OpenNewsResultInUnknownGroup (nsMsgResultElement*);
char *TransformSpacesToStars (const char *, msg_TransformType transformType);
nsresult OpenNewsResultInUnknownGroup (nsMsgResultElement*);
static nsresult EncodeImapTerm (nsIMsgSearchTerm *, PRBool reallyDredd, const PRUnichar *srcCharset, const PRUnichar *destCharset, char **ppOutTerm);
static nsresult EncodeImapTerm (nsIMsgSearchTerm *, PRBool reallyDredd, const PRUnichar *srcCharset, const PRUnichar *destCharset, char **ppOutTerm);
};
//-----------------------------------------------------------------------------
@ -146,18 +146,18 @@ protected:
class nsMsgSearchValidityTable : public nsIMsgSearchValidityTable
{
public:
nsMsgSearchValidityTable ();
NS_DECL_NSIMSGSEARCHVALIDITYTABLE
NS_DECL_ISUPPORTS
nsMsgSearchValidityTable ();
NS_DECL_NSIMSGSEARCHVALIDITYTABLE
NS_DECL_ISUPPORTS
protected:
int m_numAvailAttribs; // number of rows with at least one available operator
typedef struct vtBits
{
PRUint16 bitEnabled : 1;
PRUint16 bitAvailable : 1;
PRUint16 bitValidButNotShown : 1;
} vtBits;
int m_numAvailAttribs; // number of rows with at least one available operator
typedef struct vtBits
{
PRUint16 bitEnabled : 1;
PRUint16 bitAvailable : 1;
PRUint16 bitValidButNotShown : 1;
} vtBits;
vtBits m_table [nsMsgSearchAttrib::kNumMsgSearchAttributes][nsMsgSearchOp::kNumMsgSearchOperators];
private:
nsMsgSearchAttribValue m_defaultAttrib;

View File

@ -68,6 +68,7 @@ public:
char *m_name;
nsCOMPtr <nsIMsgFolder> m_folder;
nsCOMPtr <nsIMsgSearchAdapter> m_adapter;
nsCOMPtr <nsIInputStream> m_inputStream; // for message bodies
nsWeakPtr m_searchSession;
PRBool m_searchServer;

View File

@ -98,18 +98,11 @@ void nsMsgBodyHandler::Initialize()
nsMsgBodyHandler::~nsMsgBodyHandler()
{
if (m_fileSpec)
{
PRBool isOpen;
m_fileSpec->IsStreamOpen(&isOpen);
if (isOpen)
m_fileSpec->CloseStream();
}
}
PRInt32 nsMsgBodyHandler::GetNextLine (char * buf, int bufSize)
PRInt32 nsMsgBodyHandler::GetNextLine (nsCString &buf)
{
PRInt32 length = 0;
PRBool eatThisLine = PR_FALSE;
@ -117,7 +110,7 @@ PRInt32 nsMsgBodyHandler::GetNextLine (char * buf, int bufSize)
do {
// first, handle the filtering case...this is easy....
if (m_Filtering)
length = GetNextFilterLine(buf, bufSize);
length = GetNextFilterLine(buf);
else
{
// 3 cases: Offline IMAP, POP, or we are dealing with a news message....
@ -125,7 +118,7 @@ PRInt32 nsMsgBodyHandler::GetNextLine (char * buf, int bufSize)
// to store offline messages in berkeley format folders.
if (m_db)
{
length = GetNextLocalLine (buf, bufSize); // (2) POP
length = GetNextLocalLine (buf); // (2) POP
}
}
@ -136,20 +129,18 @@ PRInt32 nsMsgBodyHandler::GetNextLine (char * buf, int bufSize)
}
void nsMsgBodyHandler::OpenLocalFolder()
{
nsresult rv = m_scope->GetMailPath(getter_AddRefs(m_fileSpec));
PRBool isOpen = PR_FALSE;
if (NS_SUCCEEDED(rv) && m_fileSpec)
nsCOMPtr <nsIInputStream> inputStream;
nsresult rv = m_scope->GetInputStream(getter_AddRefs(inputStream));
if (inputStream)
{
m_fileSpec->IsStreamOpen(&isOpen);
if (!isOpen)
m_fileSpec->OpenStreamForReading();
m_fileSpec->Seek(m_localFileOffset);
nsCOMPtr <nsISeekableStream> seekableStream = do_QueryInterface(inputStream);
seekableStream->Seek(PR_SEEK_SET, m_localFileOffset);
}
m_fileLineStream = do_QueryInterface(inputStream);
}
PRInt32 nsMsgBodyHandler::GetNextFilterLine(char * buf, PRUint32 bufSize)
PRInt32 nsMsgBodyHandler::GetNextFilterLine(nsCString &buf)
{
// m_nextHdr always points to the next header in the list....the list is NULL terminated...
PRUint32 numBytesCopied = 0;
@ -167,10 +158,8 @@ PRInt32 nsMsgBodyHandler::GetNextFilterLine(char * buf, PRUint32 bufSize)
if (m_headersSize > 0)
{
numBytesCopied = strlen(m_headers)+1 /* + 1 to include NULL */ < bufSize ? strlen(m_headers)+1 : (PRInt32) bufSize;
memcpy(buf, m_headers, numBytesCopied);
if (numBytesCopied == bufSize)
buf[bufSize - 1] = '\0';
numBytesCopied = strlen(m_headers) + 1 ;
buf.Append(m_headers);
m_headers += numBytesCopied;
// be careful...m_headersSize is unsigned. Don't let it go negative or we overflow to 2^32....*yikes*
if (m_headersSize < numBytesCopied)
@ -182,14 +171,14 @@ PRInt32 nsMsgBodyHandler::GetNextFilterLine(char * buf, PRUint32 bufSize)
}
}
else if (m_headersSize == 0) {
buf[0] = '\0';
buf.Truncate();
}
return -1;
}
// return -1 if no more local lines, length of next line otherwise.
PRInt32 nsMsgBodyHandler::GetNextLocalLine(char * buf, int bufSize)
PRInt32 nsMsgBodyHandler::GetNextLocalLine(nsCString &buf)
// returns number of bytes copied
{
if (m_numLocalLines)
@ -197,24 +186,19 @@ PRInt32 nsMsgBodyHandler::GetNextLocalLine(char * buf, int bufSize)
if (m_passedHeaders)
m_numLocalLines--; // the line count is only for body lines
// do we need to check the return value here?
if (m_fileSpec)
if (m_fileLineStream)
{
PRBool isEof = PR_FALSE;
nsresult rv = m_fileSpec->Eof(&isEof);
if (NS_FAILED(rv) || isEof)
return -1;
PRBool wasTruncated = PR_FALSE;
rv = m_fileSpec->ReadLine(&buf, bufSize, &wasTruncated);
if (NS_SUCCEEDED(rv) && !wasTruncated)
return strlen(buf);
PRBool more = PR_FALSE;
nsresult rv = m_fileLineStream->ReadLine(buf, &more);
if (NS_SUCCEEDED(rv))
return buf.Length();
}
}
return -1;
}
PRInt32 nsMsgBodyHandler::ApplyTransformations (char *buf, PRInt32 length, PRBool &eatThisLine)
PRInt32 nsMsgBodyHandler::ApplyTransformations (nsCString &buf, PRInt32 length, PRBool &eatThisLine)
{
PRInt32 newLength = length;
eatThisLine = PR_FALSE;
@ -224,17 +208,17 @@ PRInt32 nsMsgBodyHandler::ApplyTransformations (char *buf, PRInt32 length, PRBoo
if (m_stripHeaders)
eatThisLine = PR_TRUE;
if (!nsCRT::strncasecmp(buf, "Content-Type:", 13) && PL_strcasestr (buf, "text/html"))
if (StringBeginsWith(buf, NS_LITERAL_CSTRING("Content-Type:")) && FindInReadable(buf, NS_LITERAL_CSTRING("text/html")))
m_messageIsHtml = PR_TRUE;
m_passedHeaders = EMPTY_MESSAGE_LINE(buf);
m_passedHeaders = buf.IsEmpty() || buf.First() == nsCRT::CR || buf.First() == nsCRT::LF;
}
else // buf is a line from the message body
{
if (m_stripHtml && m_messageIsHtml)
{
StripHtml (buf);
newLength = strlen (buf);
newLength = buf.Length();
}
}
@ -242,13 +226,14 @@ PRInt32 nsMsgBodyHandler::ApplyTransformations (char *buf, PRInt32 length, PRBoo
}
void nsMsgBodyHandler::StripHtml (char *pBufInOut)
void nsMsgBodyHandler::StripHtml (nsCString &pBufInOut)
{
char *pBuf = (char*) PR_Malloc (strlen(pBufInOut) + 1);
char *pBuf = (char*) PR_Malloc (pBufInOut.Length() + 1);
if (pBuf)
{
char *pWalk = pBuf;
char *pWalkInOut = pBufInOut;
char *pWalkInOut = (char *) pBufInOut.get();
PRBool inTag = PR_FALSE;
while (*pWalkInOut) // throw away everything inside < >
{
@ -264,13 +249,7 @@ void nsMsgBodyHandler::StripHtml (char *pBufInOut)
}
*pWalk = 0; // null terminator
// copy the temp buffer back to the real one
pWalk = pBuf;
pWalkInOut = pBufInOut;
while (*pWalk)
*pWalkInOut++ = *pWalk++;
*pWalkInOut = *pWalk; // null terminator
PR_Free (pBuf);
pBufInOut.Adopt(pBuf);
}
}

View File

@ -246,9 +246,9 @@ void nsMsgSearchBoolExpression::GenerateEncodeStr(nsCString * buffer)
// a ' ' to preceded the closing paren in the OR encoding.
PRUint32 lastCharPos = buffer->Length() - 1;
if (buffer->CharAt(lastCharPos) == ' ')
{
{
buffer->Truncate(lastCharPos);
}
}
*buffer += ')';
}
@ -282,9 +282,7 @@ nsMsgSearchOfflineMail::~nsMsgSearchOfflineMail ()
nsresult nsMsgSearchOfflineMail::ValidateTerms ()
{
nsresult err = NS_OK;
err = nsMsgSearchAdapter::ValidateTerms ();
return err;
return nsMsgSearchAdapter::ValidateTerms ();
}
@ -384,14 +382,14 @@ nsresult nsMsgSearchOfflineMail::ConstructExpressionTree(nsIMsgDBHdr *msgToMatch
{
PRBool result;
NS_ENSURE_ARG_POINTER(pResult);
NS_ENSURE_ARG_POINTER(pResult);
*pResult = PR_FALSE;
*pResult = PR_FALSE;
// Don't even bother to look at expunged messages awaiting compression
PRUint32 msgFlags;
msgToMatch->GetFlags(&msgFlags);
if (msgFlags & MSG_FLAG_EXPUNGED)
if (msgFlags & MSG_FLAG_EXPUNGED)
result = PR_FALSE;
PRUint32 count;
@ -478,7 +476,7 @@ nsresult nsMsgSearchOfflineMail::ProcessSearchTerm(nsIMsgDBHdr *msgToMatch,
NS_ENSURE_ARG_POINTER(pResult);
*pResult = PR_FALSE;
*pResult = PR_FALSE;
nsMsgSearchAttribValue attrib;
aTerm->GetAttrib(&attrib);
@ -629,8 +627,8 @@ nsresult nsMsgSearchOfflineMail::MatchTerms(nsIMsgDBHdr *msgToMatch,
Filtering, &expressionTree, pResult);
// evaluate the expression tree and return the result
if (NS_SUCCEEDED(err) && expressionTree)
*pResult = expressionTree->OfflineEvaluate();
if (NS_SUCCEEDED(err) && expressionTree)
*pResult = expressionTree->OfflineEvaluate();
delete expressionTree;
return err;
@ -708,24 +706,15 @@ nsresult nsMsgSearchOfflineMail::Search (PRBool *aDone)
void nsMsgSearchOfflineMail::CleanUpScope()
{
// Let go of the DB when we're done with it so we don't kill the db cache
if (m_db)
{
m_listContext = nsnull;
m_db->Close(PR_FALSE);
}
m_db = nsnull;
nsCOMPtr <nsIFileSpec> fileSpec;
nsresult rv = m_scope->GetMailPath(getter_AddRefs(fileSpec));
PRBool isOpen = PR_FALSE;
if (NS_SUCCEEDED(rv) && fileSpec)
{
fileSpec->IsStreamOpen(&isOpen);
if (isOpen)
fileSpec->CloseStream();
}
// Let go of the DB when we're done with it so we don't kill the db cache
if (m_db)
{
m_listContext = nsnull;
m_db->Close(PR_FALSE);
}
m_db = nsnull;
m_scope->SetInputStream(nsnull);
}
NS_IMETHODIMP nsMsgSearchOfflineMail::AddResultElement (nsIMsgDBHdr *pHeaders)

View File

@ -812,49 +812,49 @@ nsresult nsMsgSearchValidityManager::InitNewsExTable (nsINntpIncomingServer *new
newsHost->QuerySearchableHeader(":TEXT", &hasAttrib);
else
hasAttrib = PR_TRUE;
m_newsExTable->SetAvailable (nsMsgSearchAttrib::AnyText, nsMsgSearchOp::Contains, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::AnyText, nsMsgSearchOp::Contains, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::AnyText, nsMsgSearchOp::DoesntContain, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::AnyText, nsMsgSearchOp::DoesntContain, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::AnyText, nsMsgSearchOp::Contains, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::AnyText, nsMsgSearchOp::Contains, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::AnyText, nsMsgSearchOp::DoesntContain, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::AnyText, nsMsgSearchOp::DoesntContain, hasAttrib);
if (newsHost)
newsHost->QuerySearchableHeader("KEYWORDS", &hasAttrib);
else
hasAttrib = PR_TRUE;
m_newsExTable->SetAvailable (nsMsgSearchAttrib::Keywords, nsMsgSearchOp::Contains, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::Keywords, nsMsgSearchOp::Contains, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::Keywords, nsMsgSearchOp::DoesntContain, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::Keywords, nsMsgSearchOp::DoesntContain, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::Keywords, nsMsgSearchOp::Contains, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::Keywords, nsMsgSearchOp::Contains, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::Keywords, nsMsgSearchOp::DoesntContain, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::Keywords, nsMsgSearchOp::DoesntContain, hasAttrib);
#ifdef LATER
// Not sure whether this would be useful or not. If so, can we specify more
// than one NEWSGROUPS term to the server? If not, it would be tricky to merge
// this with the NEWSGROUPS term we generate for the scope.
hasAttrib = newsHost ? newsHost->QuerySearchableHeader("NEWSGROUPS") : PR_TRUE;
m_newsExTable->SetAvailable (nsMsgSearchAttrib::Newsgroups, nsMsgSearchOp::IsBefore, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::Newsgroups, nsMsgSearchOp::IsBefore, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::Newsgroups, nsMsgSearchOp::IsAfter, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::Newsgroups, nsMsgSearchOp::IsAfter, hasAttrib);
// Not sure whether this would be useful or not. If so, can we specify more
// than one NEWSGROUPS term to the server? If not, it would be tricky to merge
// this with the NEWSGROUPS term we generate for the scope.
hasAttrib = newsHost ? newsHost->QuerySearchableHeader("NEWSGROUPS") : PR_TRUE;
m_newsExTable->SetAvailable (nsMsgSearchAttrib::Newsgroups, nsMsgSearchOp::IsBefore, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::Newsgroups, nsMsgSearchOp::IsBefore, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::Newsgroups, nsMsgSearchOp::IsAfter, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::Newsgroups, nsMsgSearchOp::IsAfter, hasAttrib);
#endif
if (newsHost)
newsHost->QuerySearchableHeader("DATE", &hasAttrib);
else
hasAttrib = PR_TRUE;
m_newsExTable->SetAvailable (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::IsGreaterThan, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::IsGreaterThan, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::IsLessThan, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::IsLessThan, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::Is, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::Is, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::IsGreaterThan, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::IsGreaterThan, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::IsLessThan, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::IsLessThan, hasAttrib);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::Is, hasAttrib);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::Is, hasAttrib);
// it is possible that the user enters an arbitrary header that is not searchable using NNTP search extensions
m_newsExTable->SetAvailable (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::Contains, 1); // added for arbitrary headers
m_newsExTable->SetEnabled (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::Contains, 1);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::DoesntContain, 1);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::DoesntContain, 1);
}
// it is possible that the user enters an arbitrary header that is not searchable using NNTP search extensions
m_newsExTable->SetAvailable (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::Contains, 1); // added for arbitrary headers
m_newsExTable->SetEnabled (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::Contains, 1);
m_newsExTable->SetAvailable (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::DoesntContain, 1);
m_newsExTable->SetEnabled (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::DoesntContain, 1);
}
return err;
return err;
}
nsresult nsMsgSearchValidityManager::PostProcessValidityTable (nsINntpIncomingServer *host)

View File

@ -60,10 +60,11 @@
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIMsgFilterPlugin.h"
#include "nsIFileSpec.h"
#include "nsIRDFService.h"
#include "nsISupportsObsolete.h"
#include "nsNetCID.h"
#include "nsIFileStreams.h"
//---------------------------------------------------------------------------
// nsMsgSearchTerm specifies one criterion, e.g. name contains phil
//---------------------------------------------------------------------------
@ -302,17 +303,17 @@ void NS_MsgGetUntranslatedStatusName (uint32 s, nsCString *outName)
PRInt32 NS_MsgGetStatusValueFromName(char *name)
{
if (!strcmp("read", name))
return MSG_FLAG_READ;
if (!strcmp("replied", name))
return MSG_FLAG_REPLIED;
if (!strcmp("forwarded", name))
return MSG_FLAG_FORWARDED;
if (!strcmp("replied and forwarded", name))
return MSG_FLAG_FORWARDED|MSG_FLAG_REPLIED;
if (!strcmp("new", name))
return MSG_FLAG_NEW;
return 0;
if (!strcmp("read", name))
return MSG_FLAG_READ;
if (!strcmp("replied", name))
return MSG_FLAG_REPLIED;
if (!strcmp("forwarded", name))
return MSG_FLAG_FORWARDED;
if (!strcmp("replied and forwarded", name))
return MSG_FLAG_FORWARDED|MSG_FLAG_REPLIED;
if (!strcmp("new", name))
return MSG_FLAG_NEW;
return 0;
}
@ -329,26 +330,26 @@ nsMsgSearchTerm::nsMsgSearchTerm()
}
nsMsgSearchTerm::nsMsgSearchTerm (
nsMsgSearchAttribValue attrib,
nsMsgSearchOpValue op,
nsIMsgSearchValue *val,
nsMsgSearchBooleanOperator boolOp,
const char * arbitraryHeader)
nsMsgSearchAttribValue attrib,
nsMsgSearchOpValue op,
nsIMsgSearchValue *val,
nsMsgSearchBooleanOperator boolOp,
const char * arbitraryHeader)
{
m_operator = op;
m_attribute = attrib;
m_booleanOp = boolOp;
if (attrib > nsMsgSearchAttrib::OtherHeader && attrib < nsMsgSearchAttrib::kNumMsgSearchAttributes && arbitraryHeader)
m_arbitraryHeader = arbitraryHeader;
nsMsgResultElement::AssignValues (val, &m_value);
m_operator = op;
m_attribute = attrib;
m_booleanOp = boolOp;
if (attrib > nsMsgSearchAttrib::OtherHeader && attrib < nsMsgSearchAttrib::kNumMsgSearchAttributes && arbitraryHeader)
m_arbitraryHeader = arbitraryHeader;
nsMsgResultElement::AssignValues (val, &m_value);
}
nsMsgSearchTerm::~nsMsgSearchTerm ()
{
if (IS_STRING_ATTRIBUTE (m_attribute) && m_value.string)
Recycle(m_value.string);
if (IS_STRING_ATTRIBUTE (m_attribute) && m_value.string)
Recycle(m_value.string);
}
NS_IMPL_ISUPPORTS1(nsMsgSearchTerm, nsIMsgSearchTerm)
@ -358,73 +359,73 @@ NS_IMPL_ISUPPORTS1(nsMsgSearchTerm, nsIMsgSearchTerm)
// Caller needs to free.
/* static */char *nsMsgSearchTerm::EscapeQuotesInStr(const char *str)
{
int numQuotes = 0;
for (const char *strPtr = str; *strPtr; strPtr++)
if (*strPtr == '"')
numQuotes++;
int escapedStrLen = PL_strlen(str) + numQuotes;
char *escapedStr = (char *) PR_Malloc(escapedStrLen + 1);
if (escapedStr)
{
char *destPtr;
for (destPtr = escapedStr; *str; str++)
{
if (*str == '"')
*destPtr++ = '\\';
*destPtr++ = *str;
}
*destPtr = '\0';
}
return escapedStr;
int numQuotes = 0;
for (const char *strPtr = str; *strPtr; strPtr++)
if (*strPtr == '"')
numQuotes++;
int escapedStrLen = PL_strlen(str) + numQuotes;
char *escapedStr = (char *) PR_Malloc(escapedStrLen + 1);
if (escapedStr)
{
char *destPtr;
for (destPtr = escapedStr; *str; str++)
{
if (*str == '"')
*destPtr++ = '\\';
*destPtr++ = *str;
}
*destPtr = '\0';
}
return escapedStr;
}
nsresult nsMsgSearchTerm::OutputValue(nsCString &outputStr)
{
if (IS_STRING_ATTRIBUTE(m_attribute) && m_value.string)
{
PRBool quoteVal = PR_FALSE;
// need to quote strings with ')' and strings starting with '"' or ' '
// filter code will escape quotes
if (PL_strchr(m_value.string, ')') ||
(m_value.string[0] == ' ') ||
(m_value.string[0] == '"'))
{
quoteVal = PR_TRUE;
outputStr += "\"";
}
if (PL_strchr(m_value.string, '"'))
{
char *escapedString = nsMsgSearchTerm::EscapeQuotesInStr(m_value.string);
if (escapedString)
{
outputStr += escapedString;
PR_Free(escapedString);
}
}
else
{
outputStr += m_value.string;
}
if (quoteVal)
outputStr += "\"";
}
else
{
switch (m_attribute)
{
case nsMsgSearchAttrib::Date:
{
PRExplodedTime exploded;
PR_ExplodeTime(m_value.u.date, PR_LocalTimeParameters, &exploded);
// wow, so tm_mon is 0 based, tm_mday is 1 based.
char dateBuf[100];
PR_FormatTimeUSEnglish (dateBuf, sizeof(dateBuf), "%d-%b-%Y", &exploded);
outputStr += dateBuf;
break;
}
if (IS_STRING_ATTRIBUTE(m_attribute) && m_value.string)
{
PRBool quoteVal = PR_FALSE;
// need to quote strings with ')' and strings starting with '"' or ' '
// filter code will escape quotes
if (PL_strchr(m_value.string, ')') ||
(m_value.string[0] == ' ') ||
(m_value.string[0] == '"'))
{
quoteVal = PR_TRUE;
outputStr += "\"";
}
if (PL_strchr(m_value.string, '"'))
{
char *escapedString = nsMsgSearchTerm::EscapeQuotesInStr(m_value.string);
if (escapedString)
{
outputStr += escapedString;
PR_Free(escapedString);
}
}
else
{
outputStr += m_value.string;
}
if (quoteVal)
outputStr += "\"";
}
else
{
switch (m_attribute)
{
case nsMsgSearchAttrib::Date:
{
PRExplodedTime exploded;
PR_ExplodeTime(m_value.u.date, PR_LocalTimeParameters, &exploded);
// wow, so tm_mon is 0 based, tm_mday is 1 based.
char dateBuf[100];
PR_FormatTimeUSEnglish (dateBuf, sizeof(dateBuf), "%d-%b-%Y", &exploded);
outputStr += dateBuf;
break;
}
case nsMsgSearchAttrib::AgeInDays:
{
outputStr.AppendInt(m_value.u.age);
@ -440,102 +441,102 @@ nsresult nsMsgSearchTerm::OutputValue(nsCString &outputStr)
outputStr.AppendInt(m_value.u.junkStatus); // only if we write to disk, right?
break;
}
case nsMsgSearchAttrib::MsgStatus:
{
nsCAutoString status;
NS_MsgGetUntranslatedStatusName (m_value.u.msgStatus, &status);
outputStr += status;
break;
}
case nsMsgSearchAttrib::Priority:
{
nsAutoString priority;
NS_MsgGetUntranslatedPriorityName( m_value.u.priority,
&priority);
outputStr.AppendWithConversion(priority);
break;
}
case nsMsgSearchAttrib::HasAttachmentStatus:
{
outputStr.Append("true"); // don't need anything here, really
break;
}
default:
NS_ASSERTION(PR_FALSE, "trying to output invalid attribute");
break;
}
}
return NS_OK;
case nsMsgSearchAttrib::MsgStatus:
{
nsCAutoString status;
NS_MsgGetUntranslatedStatusName (m_value.u.msgStatus, &status);
outputStr += status;
break;
}
case nsMsgSearchAttrib::Priority:
{
nsAutoString priority;
NS_MsgGetUntranslatedPriorityName( m_value.u.priority,
&priority);
outputStr.AppendWithConversion(priority);
break;
}
case nsMsgSearchAttrib::HasAttachmentStatus:
{
outputStr.Append("true"); // don't need anything here, really
break;
}
default:
NS_ASSERTION(PR_FALSE, "trying to output invalid attribute");
break;
}
}
return NS_OK;
}
nsresult nsMsgSearchTerm::EnStreamNew (nsCString &outStream)
{
const char *attrib, *operatorStr;
nsCAutoString outputStr;
nsresult ret;
ret = NS_MsgGetStringForAttribute(m_attribute, &attrib);
if (ret != NS_OK)
return ret;
if (m_attribute > nsMsgSearchAttrib::OtherHeader && m_attribute < nsMsgSearchAttrib::kNumMsgSearchAttributes) // if arbitrary header, use it instead!
{
outputStr = "\"";
outputStr += m_arbitraryHeader;
outputStr += "\"";
}
else
outputStr = attrib;
outputStr += ',';
ret = NS_MsgGetStringForOperator(m_operator, &operatorStr);
if (ret != NS_OK)
return ret;
outputStr += operatorStr;
outputStr += ',';
OutputValue(outputStr);
outStream = outputStr;
return NS_OK;
const char *attrib, *operatorStr;
nsCAutoString outputStr;
nsresult ret;
ret = NS_MsgGetStringForAttribute(m_attribute, &attrib);
if (ret != NS_OK)
return ret;
if (m_attribute > nsMsgSearchAttrib::OtherHeader && m_attribute < nsMsgSearchAttrib::kNumMsgSearchAttributes) // if arbitrary header, use it instead!
{
outputStr = "\"";
outputStr += m_arbitraryHeader;
outputStr += "\"";
}
else
outputStr = attrib;
outputStr += ',';
ret = NS_MsgGetStringForOperator(m_operator, &operatorStr);
if (ret != NS_OK)
return ret;
outputStr += operatorStr;
outputStr += ',';
OutputValue(outputStr);
outStream = outputStr;
return NS_OK;
}
// fill in m_value from the input stream.
nsresult nsMsgSearchTerm::ParseValue(char *inStream)
{
if (IS_STRING_ATTRIBUTE(m_attribute))
{
PRBool quoteVal = PR_FALSE;
if (IS_STRING_ATTRIBUTE(m_attribute))
{
PRBool quoteVal = PR_FALSE;
while (nsString::IsSpace(*inStream))
inStream++;
// need to remove pair of '"', if present
if (*inStream == '"')
{
quoteVal = PR_TRUE;
inStream++;
}
int valueLen = PL_strlen(inStream);
if (quoteVal && inStream[valueLen - 1] == '"')
valueLen--;
m_value.string = (char *) PR_Malloc(valueLen + 1);
PL_strncpy(m_value.string, inStream, valueLen + 1);
m_value.string[valueLen] = '\0';
}
else
{
switch (m_attribute)
{
case nsMsgSearchAttrib::Date:
PR_ParseTimeString (inStream, PR_FALSE, &m_value.u.date);
break;
case nsMsgSearchAttrib::MsgStatus:
m_value.u.msgStatus = NS_MsgGetStatusValueFromName(inStream);
break;
case nsMsgSearchAttrib::Priority:
NS_MsgGetPriorityFromString(inStream, &m_value.u.priority);
break;
// need to remove pair of '"', if present
if (*inStream == '"')
{
quoteVal = PR_TRUE;
inStream++;
}
int valueLen = PL_strlen(inStream);
if (quoteVal && inStream[valueLen - 1] == '"')
valueLen--;
m_value.string = (char *) PR_Malloc(valueLen + 1);
PL_strncpy(m_value.string, inStream, valueLen + 1);
m_value.string[valueLen] = '\0';
}
else
{
switch (m_attribute)
{
case nsMsgSearchAttrib::Date:
PR_ParseTimeString (inStream, PR_FALSE, &m_value.u.date);
break;
case nsMsgSearchAttrib::MsgStatus:
m_value.u.msgStatus = NS_MsgGetStatusValueFromName(inStream);
break;
case nsMsgSearchAttrib::Priority:
NS_MsgGetPriorityFromString(inStream, &m_value.u.priority);
break;
case nsMsgSearchAttrib::AgeInDays:
m_value.u.age = atoi(inStream);
break;
@ -548,13 +549,13 @@ nsresult nsMsgSearchTerm::ParseValue(char *inStream)
case nsMsgSearchAttrib::HasAttachmentStatus:
m_value.u.msgStatus = MSG_FLAG_ATTACHMENT;
break; // this should always be true.
default:
NS_ASSERTION(PR_FALSE, "invalid attribute parsing search term value");
break;
}
}
m_value.attribute = m_attribute;
return NS_OK;
default:
NS_ASSERTION(PR_FALSE, "invalid attribute parsing search term value");
break;
}
}
m_value.attribute = m_attribute;
return NS_OK;
}
// find the operator code for this operator string.
@ -562,16 +563,16 @@ nsresult
nsMsgSearchTerm::ParseOperator(char *inStream, nsMsgSearchOpValue *value)
{
NS_ENSURE_ARG_POINTER(value);
PRInt16 operatorVal;
while (nsString::IsSpace(*inStream))
inStream++;
char *commaSep = PL_strchr(inStream, ',');
if (commaSep)
*commaSep = '\0';
nsresult err = NS_MsgGetOperatorFromString(inStream, &operatorVal);
PRInt16 operatorVal;
while (nsString::IsSpace(*inStream))
inStream++;
char *commaSep = PL_strchr(inStream, ',');
if (commaSep)
*commaSep = '\0';
nsresult err = NS_MsgGetOperatorFromString(inStream, &operatorVal);
*value = (nsMsgSearchOpValue) operatorVal;
return err;
}
@ -634,58 +635,58 @@ nsresult nsMsgSearchTerm::DeStreamNew (char *inStream, PRInt16 /*length*/)
void nsMsgSearchTerm::StripQuotedPrintable (unsigned char *src)
{
// decode quoted printable text in place
unsigned char *dest = src;
int srcIdx = 0, destIdx = 0;
while (src[srcIdx] != 0)
{
if (src[srcIdx] == '=')
{
unsigned char *token = &src[srcIdx];
unsigned char c = 0;
// decode the first quoted char
if (token[1] >= '0' && token[1] <= '9')
c = token[1] - '0';
else if (token[1] >= 'A' && token[1] <= 'F')
c = token[1] - ('A' - 10);
else if (token[1] >= 'a' && token[1] <= 'f')
c = token[1] - ('a' - 10);
else
{
// first char after '=' isn't hex. copy the '=' as a normal char and keep going
dest[destIdx++] = src[srcIdx++]; // aka token[0]
continue;
}
// decode the second quoted char
c = (c << 4);
if (token[2] >= '0' && token[2] <= '9')
c += token[2] - '0';
else if (token[2] >= 'A' && token[2] <= 'F')
c += token[2] - ('A' - 10);
else if (token[2] >= 'a' && token[2] <= 'f')
c += token[2] - ('a' - 10);
else
{
// second char after '=' isn't hex. copy the '=' as a normal char and keep going
dest[destIdx++] = src[srcIdx++]; // aka token[0]
continue;
}
// if we got here, we successfully decoded a quoted printable sequence,
// so bump each pointer past it and move on to the next char;
dest[destIdx++] = c;
srcIdx += 3;
}
else
dest[destIdx++] = src[srcIdx++];
}
dest[destIdx] = src[srcIdx]; // null terminate
// decode quoted printable text in place
unsigned char *dest = src;
int srcIdx = 0, destIdx = 0;
while (src[srcIdx] != 0)
{
if (src[srcIdx] == '=')
{
unsigned char *token = &src[srcIdx];
unsigned char c = 0;
// decode the first quoted char
if (token[1] >= '0' && token[1] <= '9')
c = token[1] - '0';
else if (token[1] >= 'A' && token[1] <= 'F')
c = token[1] - ('A' - 10);
else if (token[1] >= 'a' && token[1] <= 'f')
c = token[1] - ('a' - 10);
else
{
// first char after '=' isn't hex. copy the '=' as a normal char and keep going
dest[destIdx++] = src[srcIdx++]; // aka token[0]
continue;
}
// decode the second quoted char
c = (c << 4);
if (token[2] >= '0' && token[2] <= '9')
c += token[2] - '0';
else if (token[2] >= 'A' && token[2] <= 'F')
c += token[2] - ('A' - 10);
else if (token[2] >= 'a' && token[2] <= 'f')
c += token[2] - ('a' - 10);
else
{
// second char after '=' isn't hex. copy the '=' as a normal char and keep going
dest[destIdx++] = src[srcIdx++]; // aka token[0]
continue;
}
// if we got here, we successfully decoded a quoted printable sequence,
// so bump each pointer past it and move on to the next char;
dest[destIdx++] = c;
srcIdx += 3;
}
else
dest[destIdx++] = src[srcIdx++];
}
dest[destIdx] = src[srcIdx]; // null terminate
}
// Looks in the MessageDB for the user specified arbitrary header, if it finds the header, it then looks for a match against
@ -702,148 +703,131 @@ nsresult nsMsgSearchTerm::MatchArbitraryHeader (nsIMsgSearchScopeTerm *scope,
PRBool ForFiltering,
PRBool *pResult)
{
NS_ENSURE_ARG_POINTER(pResult);
*pResult = PR_FALSE;
nsresult err = NS_OK;
PRBool result;
nsMsgBodyHandler * bodyHandler = new nsMsgBodyHandler (scope, offset,length, msg, db, headers, headersSize, ForFiltering);
if (!bodyHandler)
return NS_ERROR_OUT_OF_MEMORY;
bodyHandler->SetStripHeaders (PR_FALSE);
GetMatchAllBeforeDeciding(&result);
const int kBufSize = 512; // max size of a line??
char * buf = (char *) PR_Malloc(kBufSize);
if (buf)
{
PRBool searchingHeaders = PR_TRUE;
while (searchingHeaders && (bodyHandler->GetNextLine(buf, kBufSize) >=0))
{
char * buf_end = buf + PL_strlen(buf);
int headerLength = m_arbitraryHeader.Length();
if (!PL_strncasecmp(buf, m_arbitraryHeader.get(),headerLength))
{
char * headerValue = buf + headerLength; // value occurs after the header name...
if (headerValue < buf_end && headerValue[0] == ':') // + 1 to account for the colon which is MANDATORY
headerValue++;
// strip leading white space
while (headerValue < buf_end && nsString::IsSpace(*headerValue))
headerValue++; // advance to next character
// strip trailing white space
char * end = buf_end - 1;
while (end > headerValue && nsString::IsSpace(*end)) // while we haven't gone back past the start and we are white space....
{
*end = '\0'; // eat up the white space
end--; // move back and examine the previous character....
}
if (headerValue < buf_end && *headerValue) // make sure buf has info besides just the header
{
PRBool result2;
err = MatchRfc2047String(headerValue, charset, charsetOverride, &result2); // match value with the other info...
if (result != result2) // if we found a match
{
searchingHeaders = PR_FALSE; // then stop examining the headers
result = result2;
}
}
else
NS_ASSERTION(PR_FALSE, "error matching arbitrary headers"); // mscott --> i'd be curious if there is a case where this fails....
}
if (EMPTY_MESSAGE_LINE(buf))
searchingHeaders = PR_FALSE;
}
delete bodyHandler;
PR_Free(buf);
*pResult = result;
return err;
}
else
{
delete bodyHandler;
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ENSURE_ARG_POINTER(pResult);
*pResult = PR_FALSE;
nsresult err = NS_OK;
PRBool result;
nsMsgBodyHandler * bodyHandler = new nsMsgBodyHandler (scope, offset,length, msg, db, headers, headersSize, ForFiltering);
if (!bodyHandler)
return NS_ERROR_OUT_OF_MEMORY;
bodyHandler->SetStripHeaders (PR_FALSE);
GetMatchAllBeforeDeciding(&result);
nsCAutoString buf;
PRBool searchingHeaders = PR_TRUE;
while (searchingHeaders && (bodyHandler->GetNextLine(buf) >=0))
{
char * buf_end = (char *) (buf.get() + buf.Length());
int headerLength = m_arbitraryHeader.Length();
if (!PL_strncasecmp(buf.get(), m_arbitraryHeader.get(),headerLength))
{
const char * headerValue = buf.get() + headerLength; // value occurs after the header name...
if (headerValue < buf_end && headerValue[0] == ':') // + 1 to account for the colon which is MANDATORY
headerValue++;
// strip leading white space
while (headerValue < buf_end && nsString::IsSpace(*headerValue))
headerValue++; // advance to next character
// strip trailing white space
char * end = buf_end - 1;
while (end > headerValue && nsString::IsSpace(*end)) // while we haven't gone back past the start and we are white space....
{
*end = '\0'; // eat up the white space
end--; // move back and examine the previous character....
}
if (headerValue < buf_end && *headerValue) // make sure buf has info besides just the header
{
PRBool result2;
err = MatchRfc2047String(headerValue, charset, charsetOverride, &result2); // match value with the other info...
if (result != result2) // if we found a match
{
searchingHeaders = PR_FALSE; // then stop examining the headers
result = result2;
}
}
else
NS_ASSERTION(PR_FALSE, "error matching arbitrary headers"); // mscott --> i'd be curious if there is a case where this fails....
}
if (EMPTY_MESSAGE_LINE(buf))
searchingHeaders = PR_FALSE;
}
delete bodyHandler;
*pResult = result;
return err;
}
nsresult nsMsgSearchTerm::MatchBody (nsIMsgSearchScopeTerm *scope, PRUint32 offset, PRUint32 length /*in lines*/, const char *folderCharset,
nsIMsgDBHdr *msg, nsIMsgDatabase* db, PRBool *pResult)
nsIMsgDBHdr *msg, nsIMsgDatabase* db, PRBool *pResult)
{
NS_ENSURE_ARG_POINTER(pResult);
nsresult err = NS_OK;
PRBool result = PR_FALSE;
*pResult = PR_FALSE;
// Small hack so we don't look all through a message when someone has
// specified "BODY IS foo"
if ((length > 0) && (m_operator == nsMsgSearchOp::Is || m_operator == nsMsgSearchOp::Isnt))
length = PL_strlen (m_value.string);
nsMsgBodyHandler * bodyHan = new nsMsgBodyHandler (scope, offset, length, msg, db);
if (!bodyHan)
return NS_ERROR_OUT_OF_MEMORY;
const int kBufSize = 512; // max size of a line???
char *buf = (char*) PR_Malloc(kBufSize);
if (buf)
{
PRBool endOfFile = PR_FALSE; // if retValue == 0, we've hit the end of the file
uint32 lines = 0;
// Change the sense of the loop so we don't bail out prematurely
// on negative terms. i.e. opDoesntContain must look at all lines
PRBool boolContinueLoop;
GetMatchAllBeforeDeciding(&boolContinueLoop);
result = boolContinueLoop;
// If there's a '=' in the search term, then we're not going to do
// quoted printable decoding. Otherwise we assume everything is
// quoted printable. Obviously everything isn't quoted printable, but
// since we don't have a MIME parser handy, and we want to err on the
// side of too many hits rather than not enough, we'll assume in that
// general direction. Blech. ### FIX ME
// bug fix #88935: for stateful csids like JIS, we don't want to decode
// quoted printable since it contains '='.
PRBool isQuotedPrintable = /*!(mail_csid & STATEFUL) && */
(PL_strchr (m_value.string, '=') == nsnull);
while (!endOfFile && result == boolContinueLoop)
{
if (bodyHan->GetNextLine(buf, kBufSize) >= 0)
{
// Do in-place decoding of quoted printable
if (isQuotedPrintable)
StripQuotedPrintable ((unsigned char*)buf);
nsCString compare(buf);
// ConvertToUnicode(charset, buf, compare);
if (!compare.IsEmpty()) {
char startChar = (char) compare.CharAt(0);
if (startChar != nsCRT::CR && startChar != nsCRT::LF)
{
err = MatchString (compare.get(), folderCharset, &result);
lines++;
}
}
}
else
endOfFile = PR_TRUE;
}
NS_ENSURE_ARG_POINTER(pResult);
nsresult err = NS_OK;
PRBool result = PR_FALSE;
*pResult = PR_FALSE;
// Small hack so we don't look all through a message when someone has
// specified "BODY IS foo". ### Since length is in lines, this is not quite right.
if ((length > 0) && (m_operator == nsMsgSearchOp::Is || m_operator == nsMsgSearchOp::Isnt))
length = PL_strlen (m_value.string);
nsMsgBodyHandler * bodyHan = new nsMsgBodyHandler (scope, offset, length, msg, db);
if (!bodyHan)
return NS_ERROR_OUT_OF_MEMORY;
nsCAutoString buf;
PRBool endOfFile = PR_FALSE; // if retValue == 0, we've hit the end of the file
uint32 lines = 0;
// Change the sense of the loop so we don't bail out prematurely
// on negative terms. i.e. opDoesntContain must look at all lines
PRBool boolContinueLoop;
GetMatchAllBeforeDeciding(&boolContinueLoop);
result = boolContinueLoop;
// If there's a '=' in the search term, then we're not going to do
// quoted printable decoding. Otherwise we assume everything is
// quoted printable. Obviously everything isn't quoted printable, but
// since we don't have a MIME parser handy, and we want to err on the
// side of too many hits rather than not enough, we'll assume in that
// general direction. Blech. ### FIX ME
// bug fix #88935: for stateful csids like JIS, we don't want to decode
// quoted printable since it contains '='.
PRBool isQuotedPrintable = /*!(mail_csid & STATEFUL) && */
(PL_strchr (m_value.string, '=') == nsnull);
while (!endOfFile && result == boolContinueLoop)
{
if (bodyHan->GetNextLine(buf) >= 0)
{
// Do in-place decoding of quoted printable
if (isQuotedPrintable)
StripQuotedPrintable ((unsigned char*)buf.get());
nsCString compare(buf);
// ConvertToUnicode(charset, buf, compare);
if (!compare.IsEmpty()) {
char startChar = (char) compare.CharAt(0);
if (startChar != nsCRT::CR && startChar != nsCRT::LF)
{
err = MatchString (compare.get(), folderCharset, &result);
lines++;
}
}
}
else
endOfFile = PR_TRUE;
}
#ifdef DO_I18N
if(conv)
INTL_DestroyCharCodeConverter(conv);
if(conv)
INTL_DestroyCharCodeConverter(conv);
#endif
PR_FREEIF(buf);
delete bodyHan;
}
else
err = NS_ERROR_OUT_OF_MEMORY;
*pResult = result;
return err;
delete bodyHan;
*pResult = result;
return err;
}
nsresult nsMsgSearchTerm::InitializeAddressBook()
@ -1439,6 +1423,8 @@ nsMsgSearchScopeTerm::nsMsgSearchScopeTerm ()
nsMsgSearchScopeTerm::~nsMsgSearchScopeTerm ()
{
if (m_inputStream)
m_inputStream->Close();
}
NS_IMPL_ISUPPORTS1(nsMsgSearchScopeTerm, nsIMsgSearchScopeTerm)
@ -1459,14 +1445,51 @@ nsMsgSearchScopeTerm::GetSearchSession(nsIMsgSearchSession** aResult)
return NS_OK;
}
nsresult nsMsgSearchScopeTerm::GetMailPath(nsIFileSpec **aFileSpec)
NS_IMETHODIMP nsMsgSearchScopeTerm::GetMailFile(nsILocalFile **aLocalFile)
{
return (m_folder) ? m_folder->GetPath(aFileSpec) : NS_ERROR_NULL_POINTER;
NS_ENSURE_ARG_POINTER(aLocalFile);
if (!m_folder)
return NS_ERROR_NULL_POINTER;
nsCOMPtr <nsIFileSpec> fileSpec;
m_folder->GetPath(getter_AddRefs(fileSpec));
nsFileSpec realSpec;
fileSpec->GetFileSpec(&realSpec);
NS_FileSpecToIFile(&realSpec, aLocalFile);
return (*aLocalFile) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsMsgSearchScopeTerm::GetInputStream(nsIInputStream **aInputStream)
{
NS_ENSURE_ARG_POINTER(aInputStream);
nsresult rv = NS_OK;
if (!m_inputStream)
{
nsCOMPtr <nsILocalFile> localFile;
rv = GetMailFile(getter_AddRefs(localFile));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFileInputStream> fileStream = do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = fileStream->Init(localFile, PR_RDONLY, 0664, PR_FALSE); //just have to read the messages
m_inputStream = do_QueryInterface(fileStream);
}
NS_IF_ADDREF(*aInputStream = m_inputStream);
return rv;
}
NS_IMETHODIMP nsMsgSearchScopeTerm::SetInputStream(nsIInputStream *aInputStream)
{
if (!aInputStream && m_inputStream)
m_inputStream->Close();
m_inputStream = aInputStream;
return NS_OK;
}
nsresult nsMsgSearchScopeTerm::TimeSlice (PRBool *aDone)
{
return m_adapter->Search(aDone);
return m_adapter->Search(aDone);
}
nsresult nsMsgSearchScopeTerm::InitializeAdapter (nsISupportsArray *termList)

View File

@ -148,9 +148,11 @@ nsresult nsComm4xProfile::GetPrefValue(nsILocalFile *filePath, const char * pref
PRInt32 offset;
PRInt32 endOffset;
while (!found && more) {
rv = lineStream->ReadLine(buffer, &more);
nsCAutoString cLine;
rv = lineStream->ReadLine(cLine, &more);
if (NS_FAILED(rv))
break;
CopyASCIItoUTF16(cLine, buffer);
offset = buffer.Find(prefName,PR_FALSE, 0, -1);
if (offset != kNotFound) {
endOffset = buffer.Find(prefEnd,PR_FALSE, 0, -1);

View File

@ -406,13 +406,11 @@ nsMovemailService::GetNewMail(nsIMsgWindow *aMsgWindow,
// MIDDLE of the FUN : consume the mailbox data.
PRBool isMore = PR_TRUE;
nsAutoString bufferUnicode;
nsCAutoString buffer;
while (isMore &&
NS_SUCCEEDED(lineInputStream->ReadLine(bufferUnicode, &isMore)))
NS_SUCCEEDED(lineInputStream->ReadLine(buffer, &isMore)))
{
CopyUCS2toASCII(bufferUnicode, buffer);
// If first string is empty and we're now at EOF then abort parsing.
if (buffer.IsEmpty() && !isMore) {

View File

@ -246,8 +246,10 @@ nsJVMConfigManagerUnix::ParseStream(nsILineInputStream* aStream)
nsAutoString lineBuffer;
do {
nsAutoString line;
nsresult rv = aStream->ReadLine(line, &notEOF);
nsCAutoString cLine;
nsresult rv = aStream->ReadLine(cLine, &notEOF);
NS_ENSURE_SUCCESS(rv, rv);
CopyASCIItoUTF16(cLine, line);
PRInt32 slashOffset, equalsOffset;
slashOffset = line.FindChar('\\');

View File

@ -71,10 +71,9 @@ NS_InitLineBuffer (nsLineBuffer ** aBufferPtr) {
static nsresult
NS_ReadLine (nsIInputStream* aStream, nsLineBuffer * aBuffer,
nsAString & aLine, PRBool *more) {
nsACString & aLine, PRBool *more) {
nsresult rv = NS_OK;
PRUint32 bytesRead;
nsAutoString temp;
*more = PR_TRUE;
PRBool eolStarted = PR_FALSE;
char eolchar = '\0';
@ -107,8 +106,7 @@ NS_ReadLine (nsIInputStream* aStream, nsLineBuffer * aBuffer,
eolStarted = PR_TRUE;
eolchar = *(aBuffer->current);
*(aBuffer->current) = '\0';
temp.AssignWithConversion(aBuffer->start);
aLine.Append(temp);
aLine.Append(aBuffer->start);
(aBuffer->current)++;
aBuffer->start = aBuffer->current;
} else {
@ -118,8 +116,7 @@ NS_ReadLine (nsIInputStream* aStream, nsLineBuffer * aBuffer,
}
// append whatever we currently have to the string
temp.AssignWithConversion(aBuffer->start);
aLine.Append(temp);
aLine.Append(aBuffer->start);
// we've run out of buffer. Begin anew
aBuffer->current = aBuffer->start = aBuffer->buf;

View File

@ -283,8 +283,8 @@ nsFileInputStream::Init(nsIFile* aFile, PRInt32 aIOFlags, PRInt32 aPerm,
NS_IMETHODIMP
nsFileInputStream::Close()
{
// null out mLineBuffer in case Close() is called again after failing
PR_FREEIF(mLineBuffer);
mLineBuffer = nsnull; // in case Close() is called again after failing
nsresult rv = nsFileStream::Close();
if (NS_FAILED(rv)) return rv;
if (mFile && (mBehaviorFlags & DELETE_ON_CLOSE)) {
@ -336,7 +336,7 @@ nsFileInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aResult)
}
NS_IMETHODIMP
nsFileInputStream::ReadLine(nsAString& aLine, PRBool* aResult)
nsFileInputStream::ReadLine(nsACString& aLine, PRBool* aResult)
{
if (!mLineBuffer) {
nsresult rv = NS_InitLineBuffer(&mLineBuffer);
@ -367,6 +367,7 @@ nsFileInputStream::IsNonBlocking(PRBool *aNonBlocking)
NS_IMETHODIMP
nsFileInputStream::Seek(PRInt32 aWhence, PRInt64 aOffset)
{
PR_FREEIF(mLineBuffer); // this invalidates the line buffer
if (!mFD) {
if (mBehaviorFlags & REOPEN_ON_REWIND) {
nsresult rv = Reopen();

View File

@ -897,7 +897,6 @@ nsCookieService::Read()
static NS_NAMED_LITERAL_CSTRING(kTrue, "TRUE");
nsAutoString bufferUnicode;
nsCAutoString buffer;
PRBool isMore = PR_TRUE;
PRInt32 hostIndex = 0, isDomainIndex, pathIndex, secureIndex, expiresIndex, nameIndex, cookieIndex;
@ -924,11 +923,7 @@ nsCookieService::Read()
* most-recently used come first; least-recently-used come last.
*/
while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(bufferUnicode, &isMore))) {
// downconvert to ASCII. eventually, we want to fix nsILineInputStream
// to operate on a CString buffer...
CopyUCS2toASCII(bufferUnicode, buffer);
while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(buffer, &isMore))) {
if (buffer.IsEmpty() || buffer.First() == '#') {
continue;
}

View File

@ -1726,10 +1726,12 @@ FileSystemDataSource::getIEFavoriteURL(nsIRDFResource *source, nsString aFileURL
nsCOMPtr<nsILineInputStream> linereader = do_QueryInterface(strm, &rv);
nsAutoString line;
nsCAutoString cLine;
while(NS_SUCCEEDED(rv))
{
PRBool isEOF;
rv = linereader->ReadLine(line, &isEOF);
rv = linereader->ReadLine(cLine, &isEOF);
CopyASCIItoUTF16(cLine, line);
if (isEOF)
{

View File

@ -633,14 +633,13 @@ nsPasswordManager::ReadPasswords(nsIFile* aPasswordFile)
NS_ASSERTION(lineStream, "File stream is not an nsILineInputStream");
// Read the header
nsAutoString buffer;
nsCAutoString utf8Buffer;
PRBool moreData = PR_FALSE;
nsresult rv = lineStream->ReadLine(buffer, &moreData);
nsresult rv = lineStream->ReadLine(utf8Buffer, &moreData);
if (NS_FAILED(rv))
return NS_OK;
if (!buffer.Equals(NS_LITERAL_STRING("#2c"))) {
if (!utf8Buffer.Equals(NS_LITERAL_CSTRING("#2c"))) {
NS_ERROR("Unexpected version header in signon file");
return NS_OK;
}
@ -653,16 +652,10 @@ nsPasswordManager::ReadPasswords(nsIFile* aPasswordFile)
PRBool writeOnFinish = PR_FALSE;
do {
rv = lineStream->ReadLine(buffer, &moreData);
rv = lineStream->ReadLine(utf8Buffer, &moreData);
if (NS_FAILED(rv))
return NS_OK;
// |buffer| will contain UTF-8 encoded characters, so move it into
// a narrow string so we can manipulate it. If NS_ReadLine is ever
// fixed to handle character encoding, this code should be cleaned up.
utf8Buffer.AssignWithConversion(buffer);
switch (state) {
case STATE_REJECT:
if (utf8Buffer.Equals(NS_LITERAL_CSTRING(".")))

View File

@ -898,14 +898,12 @@ int main(int argc, char* argv[]){
if (!lineInputStream)
return -4;
nsAutoString bufferUnicode;
nsCAutoString buffer;
PRBool isMore = PR_TRUE;
fprintf(stdout, "Function calls that will be checked for errors:\n");
if (gEmitHTML)
fprintf(stdout, "<ul>\n");
while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(bufferUnicode, &isMore))) {
LossyCopyUTF16toASCII(bufferUnicode, buffer);
while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(buffer, &isMore))) {
if (NS_FAILED(myWatchList.mTableC.Put(buffer)) ||
NS_FAILED(myWatchList.mTableCPP.Put(buffer)))
return -1;

View File

@ -85,7 +85,7 @@ ParseMIMEType(const nsAString::const_iterator& aStart_iter,
const nsAString::const_iterator& aEnd_iter);
inline PRBool
IsNetscapeFormat(const nsAString& aBuffer);
IsNetscapeFormat(const nsACString& aBuffer);
nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
{
@ -310,13 +310,9 @@ nsOSHelperAppService::LookUpTypeAndDescription(const nsAString& aFileExtension,
}
inline PRBool
IsNetscapeFormat(const nsAString& aBuffer) {
NS_NAMED_LITERAL_STRING(netscapeHeader,
"#--Netscape Communications Corporation MIME Information");
NS_NAMED_LITERAL_STRING(MCOMHeader, "#--MCOM MIME Information");
return StringBeginsWith(aBuffer, netscapeHeader) ||
StringBeginsWith(aBuffer, MCOMHeader);
IsNetscapeFormat(const nsACString& aBuffer) {
return StringBeginsWith(aBuffer, NS_LITERAL_CSTRING("#--Netscape Communications Corporation MIME Information")) ||
StringBeginsWith(aBuffer, NS_LITERAL_CSTRING("#--MCOM MIME Information"));
}
/*
@ -329,7 +325,7 @@ nsresult
nsOSHelperAppService::CreateInputStream(const nsAString& aFilename,
nsIFileInputStream ** aFileInputStream,
nsILineInputStream ** aLineInputStream,
nsAString& aBuffer,
nsACString& aBuffer,
PRBool * aNetscapeFormat,
PRBool * aMore) {
LOG(("-- CreateInputStream"));
@ -391,14 +387,16 @@ nsOSHelperAppService::GetTypeAndDescriptionFromMimetypesFile(const nsAString& aF
nsCOMPtr<nsILineInputStream> mimeTypes;
PRBool netscapeFormat;
nsAutoString buf;
nsCAutoString cBuf;
PRBool more = PR_FALSE;
rv = CreateInputStream(aFilename, getter_AddRefs(mimeFile), getter_AddRefs(mimeTypes),
buf, &netscapeFormat, &more);
cBuf, &netscapeFormat, &more);
if (NS_FAILED(rv)) {
return rv;
}
nsAutoString extensions;
nsString entry;
entry.SetCapacity(100);
@ -407,6 +405,7 @@ nsOSHelperAppService::GetTypeAndDescriptionFromMimetypesFile(const nsAString& aF
descriptionStart, descriptionEnd;
do {
CopyASCIItoUTF16(cBuf, buf);
// read through, building up an entry. If we finish an entry, check for
// a match and return out of the loop if we match
@ -489,7 +488,7 @@ nsOSHelperAppService::GetTypeAndDescriptionFromMimetypesFile(const nsAString& aF
break;
}
// read the next line
rv = mimeTypes->ReadLine(buf, &more);
rv = mimeTypes->ReadLine(cBuf, &more);
} while (NS_SUCCEEDED(rv));
mimeFile->Close();
@ -560,9 +559,10 @@ nsOSHelperAppService::GetExtensionsAndDescriptionFromMimetypesFile(const nsAStri
nsCOMPtr<nsILineInputStream> mimeTypes;
PRBool netscapeFormat;
nsAutoString buf;
nsCAutoString cBuf;
PRBool more = PR_FALSE;
rv = CreateInputStream(aFilename, getter_AddRefs(mimeFile), getter_AddRefs(mimeTypes),
buf, &netscapeFormat, &more);
cBuf, &netscapeFormat, &more);
if (NS_FAILED(rv)) {
return rv;
@ -576,6 +576,7 @@ nsOSHelperAppService::GetExtensionsAndDescriptionFromMimetypesFile(const nsAStri
descriptionStart, descriptionEnd;
do {
CopyASCIItoUTF16(cBuf, buf);
// read through, building up an entry. If we finish an entry, check for
// a match and return out of the loop if we match
@ -650,7 +651,7 @@ nsOSHelperAppService::GetExtensionsAndDescriptionFromMimetypesFile(const nsAStri
break;
}
// read the next line
rv = mimeTypes->ReadLine(buf, &more);
rv = mimeTypes->ReadLine(cBuf, &more);
} while (NS_SUCCEEDED(rv));
mimeFile->Close();
@ -986,9 +987,10 @@ nsOSHelperAppService::GetHandlerAndDescriptionFromMailcapFile(const nsAString& a
}
nsString entry, buffer;
nsCAutoString cBuffer;
entry.SetCapacity(128);
buffer.SetCapacity(80);
rv = mailcap->ReadLine(buffer, &more);
cBuffer.SetCapacity(80);
rv = mailcap->ReadLine(cBuffer, &more);
if (NS_FAILED(rv)) {
mailcapFile->Close();
return rv;
@ -996,6 +998,7 @@ nsOSHelperAppService::GetHandlerAndDescriptionFromMailcapFile(const nsAString& a
do { // return on end-of-file in the loop
CopyASCIItoUTF16(cBuffer, buffer);
if (!buffer.IsEmpty() && buffer.First() != '#') {
entry.Append(buffer);
if (entry.Last() == '\\') { // entry continues on next line
@ -1129,7 +1132,7 @@ nsOSHelperAppService::GetHandlerAndDescriptionFromMailcapFile(const nsAString& a
rv = NS_ERROR_NOT_AVAILABLE;
break;
}
rv = mailcap->ReadLine(buffer, &more);
rv = mailcap->ReadLine(cBuffer, &more);
} while (NS_SUCCEEDED(rv));
mailcapFile->Close();
return rv;

View File

@ -88,7 +88,7 @@ private:
static nsresult CreateInputStream(const nsAString& aFilename,
nsIFileInputStream ** aFileInputStream,
nsILineInputStream ** aLineInputStream,
nsAString& aBuffer,
nsACString& aBuffer,
PRBool * aNetscapeFormat,
PRBool * aMore);

View File

@ -83,7 +83,7 @@ ParseMIMEType(const nsAString::const_iterator& aStart_iter,
const nsAString::const_iterator& aEnd_iter);
inline PRBool
IsNetscapeFormat(const nsAString& aBuffer);
IsNetscapeFormat(const nsACString& aBuffer);
nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
{
@ -306,13 +306,9 @@ nsOSHelperAppService::LookUpTypeAndDescription(const nsAString& aFileExtension,
}
inline PRBool
IsNetscapeFormat(const nsAString& aBuffer) {
NS_NAMED_LITERAL_STRING(netscapeHeader,
"#--Netscape Communications Corporation MIME Information");
NS_NAMED_LITERAL_STRING(MCOMHeader, "#--MCOM MIME Information");
return StringBeginsWith(aBuffer, netscapeHeader) ||
StringBeginsWith(aBuffer, MCOMHeader);
IsNetscapeFormat(const nsACString& aBuffer) {
return StringBeginsWith(aBuffer, NS_LITERAL_CSTRING("#--Netscape Communications Corporation MIME Information")) ||
StringBeginsWith(aBuffer, NS_LITERAL_CSTRING("#--MCOM MIME Information"));
}
/*
@ -325,7 +321,7 @@ nsresult
nsOSHelperAppService::CreateInputStream(const nsAString& aFilename,
nsIFileInputStream ** aFileInputStream,
nsILineInputStream ** aLineInputStream,
nsAString& aBuffer,
nsACString& aBuffer,
PRBool * aNetscapeFormat,
PRBool * aMore) {
LOG(("-- CreateInputStream"));
@ -387,14 +383,16 @@ nsOSHelperAppService::GetTypeAndDescriptionFromMimetypesFile(const nsAString& aF
nsCOMPtr<nsILineInputStream> mimeTypes;
PRBool netscapeFormat;
nsAutoString buf;
nsCAutoString cBuf;
PRBool more = PR_FALSE;
rv = CreateInputStream(aFilename, getter_AddRefs(mimeFile), getter_AddRefs(mimeTypes),
buf, &netscapeFormat, &more);
cBuf, &netscapeFormat, &more);
if (NS_FAILED(rv)) {
return rv;
}
CopyASCIItoUTF16(cBuf, buf);
nsAutoString extensions;
nsString entry;
entry.SetCapacity(100);
@ -485,7 +483,7 @@ nsOSHelperAppService::GetTypeAndDescriptionFromMimetypesFile(const nsAString& aF
break;
}
// read the next line
rv = mimeTypes->ReadLine(buf, &more);
rv = mimeTypes->ReadLine(cBuf, &more);
} while (NS_SUCCEEDED(rv));
mimeFile->Close();
@ -555,10 +553,11 @@ nsOSHelperAppService::GetExtensionsAndDescriptionFromMimetypesFile(const nsAStri
nsCOMPtr<nsIFileInputStream> mimeFile;
nsCOMPtr<nsILineInputStream> mimeTypes;
PRBool netscapeFormat;
nsCAutoString cBuf;
nsAutoString buf;
PRBool more = PR_FALSE;
rv = CreateInputStream(aFilename, getter_AddRefs(mimeFile), getter_AddRefs(mimeTypes),
buf, &netscapeFormat, &more);
cBuf, &netscapeFormat, &more);
if (NS_FAILED(rv)) {
return rv;
@ -572,6 +571,7 @@ nsOSHelperAppService::GetExtensionsAndDescriptionFromMimetypesFile(const nsAStri
descriptionStart, descriptionEnd;
do {
CopyASCIItoUTF16(cBuf, buf);
// read through, building up an entry. If we finish an entry, check for
// a match and return out of the loop if we match
@ -646,7 +646,7 @@ nsOSHelperAppService::GetExtensionsAndDescriptionFromMimetypesFile(const nsAStri
break;
}
// read the next line
rv = mimeTypes->ReadLine(buf, &more);
rv = mimeTypes->ReadLine(cBuf, &more);
} while (NS_SUCCEEDED(rv));
mimeFile->Close();
@ -1030,9 +1030,10 @@ nsOSHelperAppService::GetHandlerAndDescriptionFromMailcapFile(const nsAString& a
}
nsString entry, buffer;
nsCAutoString cBuffer;
entry.SetCapacity(128);
buffer.SetCapacity(80);
rv = mailcap->ReadLine(buffer, &more);
cBuffer.SetCapacity(80);
rv = mailcap->ReadLine(cBuffer, &more);
if (NS_FAILED(rv)) {
mailcapFile->Close();
return rv;
@ -1040,6 +1041,7 @@ nsOSHelperAppService::GetHandlerAndDescriptionFromMailcapFile(const nsAString& a
do { // return on end-of-file in the loop
CopyASCIItoUTF16(cBuffer, buffer);
if (!buffer.IsEmpty() && buffer.First() != '#') {
entry.Append(buffer);
if (entry.Last() == '\\') { // entry continues on next line
@ -1173,7 +1175,7 @@ nsOSHelperAppService::GetHandlerAndDescriptionFromMailcapFile(const nsAString& a
rv = NS_ERROR_NOT_AVAILABLE;
break;
}
rv = mailcap->ReadLine(buffer, &more);
rv = mailcap->ReadLine(cBuffer, &more);
} while (NS_SUCCEEDED(rv));
mailcapFile->Close();
return rv;

View File

@ -97,7 +97,7 @@ private:
static nsresult CreateInputStream(const nsAString& aFilename,
nsIFileInputStream ** aFileInputStream,
nsILineInputStream ** aLineInputStream,
nsAString& aBuffer,
nsACString& aBuffer,
PRBool * aNetscapeFormat,
PRBool * aMore);

View File

@ -38,18 +38,17 @@
#include "nsISupports.idl"
%{ C++
#include "nsString.h" // needed for AString -> nsAString, unfortunately
%}
interface nsILineInputStream;
[scriptable, uuid(e7f17108-1dd1-11b2-8b9a-fda151ea0240)]
[scriptable, uuid(c97b466c-1e6e-4773-a4ab-2b2b3190a7a6)]
interface nsILineInputStream : nsISupports
{
/**
* Read a single line from the stream
* Read a single line from the stream, where a line is a
* possibly zero length sequence of 8bit chars terminated by a
* CR, LF, CRLF, LFCR, or eof.
* The line terminator is not returned.
* Return false for end of file, true otherwise
*/
boolean readLine(out AString aLine);
boolean readLine(out ACString aLine);
};

View File

@ -928,10 +928,12 @@ BookmarkParser::Parse(nsIRDFResource *aContainer, nsIRDFResource *nodeType)
while(NS_SUCCEEDED(rv) && isActiveFlag && moreData)
{
rv = lineInputStream->ReadLine(line, &moreData);
nsCAutoString cLine;
rv = lineInputStream->ReadLine(cLine, &moreData);
if (NS_SUCCEEDED(rv))
{
CopyASCIItoUTF16(cLine, line);
rv = ProcessLine(container, nodeType, bookmarkNode,
line, description, inDescriptionFlag, isActiveFlag);
}