non quoted-printable multiline should work now.

This commit is contained in:
jsun%netscape.com 1998-09-11 22:07:13 +00:00
Родитель f66d587b32
Коммит 0184b0f537
2 изменённых файлов: 159 добавлений и 279 удалений

Просмотреть файл

@ -32,6 +32,11 @@
#include "prmon.h"
#include "jutility.h"
/**
* nsCapiBufferStruct is contains the data passed in by the callback in CAPI.
* This struct encapsulates the data in m_pBuf,
* and the size of the passed in data in m_pBufSize.
*/
CLASS_EXPORT_CAPI nsCapiBufferStruct
{
public:
@ -51,6 +56,7 @@ private:
/*-----------------------------
** MEMBERS
**---------------------------*/
/* current buffer of iCal information,
* when CAPI has information to return to
* the buffer, it must append to this buffer
@ -59,12 +65,14 @@ private:
* notified when CAPI gets back more information
*/
char * m_Buffer;
t_int32 m_BufferSize;
t_bool m_Init;
t_int32 m_Mark;
t_int32 m_ChunkMark;
t_int32 m_Pos;
t_int32 m_ChunkIndex;
/** encoding of stream */
JulianUtility::MimeEncoding m_Encoding;
@ -85,7 +93,7 @@ private:
UnicodeString & createLine(t_int32 oldPos, t_int32 oldChunkIndex,
t_int32 newPos, t_int32 newChunkIndex, UnicodeString & aLine);
static void deleteUnicodeStringVector(JulianPtrArray * stringVector);
static void deleteCapiBufferStructVector(JulianPtrArray * bufferVector);
nsCapiCallbackReader();
public:
@ -105,23 +113,13 @@ public:
void setFinished() { m_bFinished = TRUE; }
void setEncoding(JulianUtility::MimeEncoding encoding) { m_Encoding = encoding; }
t_bool isFinished() const { return m_bFinished; }
/**
* Sets a the buffer to read from.
* Appends the m_Buffer.
*/
/*virtual void setBuffer(const char * capiChunk);*/
/**
* Don't delete u until this object is deleted.
* @param UnicodeString * u
* @param nsCapiBufferStruct * cBuf
*
* @return void
*/
void AddChunk(UnicodeString * u);
/** buffer to contain current line, assumed to be less than 1024 bytes */
char m_pBuffer[1024];
void AddBuffer(nsCapiBufferStruct * cBuf);
/*-----------------------------
** UTILITIES
@ -139,8 +137,6 @@ public:
*/
virtual t_int8 read(ErrorCode & status);
/**
* Read the next ICAL full line of the file. The definition
* of a full ICAL line can be found in the ICAL spec.
@ -164,11 +160,6 @@ public:
* @return next line of string
*/
virtual UnicodeString & readLine(UnicodeString & aLine, ErrorCode & status);
public:
/*virtual UnicodeString & readLineZero(UnicodeString & aLine, ErrorCode & status);*/
};

Просмотреть файл

@ -26,17 +26,6 @@ nsCapiCallbackReader::nsCapiCallbackReader()
PR_ASSERT(FALSE);
}
//---------------------------------------------------------------------
void
nsCapiCallbackReader::AddChunk(UnicodeString * u)
{
if (m_Chunks == 0)
m_Chunks = new JulianPtrArray();
PR_ASSERT(m_Chunks != 0);
if (m_Chunks != 0)
{
m_Chunks->Add(u);
}
}
void
nsCapiCallbackReader::AddBuffer(nsCapiBufferStruct * cBuf)
@ -69,14 +58,21 @@ nsCapiCallbackReader::nsCapiCallbackReader(PRMonitor * monitor,
//---------------------------------------------------------------------
void nsCapiCallbackReader::deleteUnicodeStringVector(JulianPtrArray * stringVector)
void nsCapiCallbackReader::deleteCapiBufferStructVector(JulianPtrArray * bufferVector)
{
t_int32 i;
if (stringVector != 0)
if (bufferVector != 0)
{
for (i = stringVector->GetSize() - 1; i >= 0; i--)
nsCapiBufferStruct * cbBuf;
for (i = bufferVector->GetSize() - 1; i >= 0; i--)
{
delete ((UnicodeString *) stringVector->GetAt(i));
cbBuf = (nsCapiBufferStruct *) bufferVector->GetAt(i);
if (0 != cbBuf->m_pBuf)
{
delete [] (cbBuf->m_pBuf);
cbBuf->m_pBuf = 0;
}
delete cbBuf; cbBuf = 0;
}
}
}
@ -87,7 +83,7 @@ nsCapiCallbackReader::~nsCapiCallbackReader()
{
if (m_Chunks != 0)
{
deleteUnicodeStringVector(m_Chunks);
deleteCapiBufferStructVector(m_Chunks);
delete m_Chunks; m_Chunks = 0;
}
}
@ -96,197 +92,6 @@ nsCapiCallbackReader::~nsCapiCallbackReader()
t_int8 nsCapiCallbackReader::read(ErrorCode & status)
{
#if 0
t_int32 i = 0;
while (TRUE)
{
if (m_Chunks == 0 || m_Chunks->GetSize() == 0 ||
m_ChunkIndex >= m_Chunks->GetSize())
{
status = m_NOMORECHUNKS; // no more chunks, should block
return -1;
}
else
{
// read from linked list of UnicodeString's
// delete front string when finished reading from it
UnicodeString string = *((UnicodeString *) m_Chunks->GetAt(m_ChunkIndex));
if (m_Pos < string.size())
{
// return index of this
status = ZERO_ERROR;
if (m_Encoding == JulianUtility::MimeEncoding_QuotedPrintable)
{
if ((string)[(TextOffset) m_Pos] == '=')
{
if (string.size() >= (t_int32)(m_Pos + 3))
{
if (ICalReader::isHex((t_int8) string[(TextOffset)(m_Pos + 1)]) &&
ICalReader::isHex((t_int8) string[(TextOffset)(m_Pos + 2)]))
{
t_int8 c;
c = ICalReader::convertHex(
(char) string[(TextOffset) (m_Pos + 1)],
(char) string[(TextOffset) (m_Pos + 2)]
);
m_Pos += 3;
return c;
}
else
{
return (t_int8) (string)[(TextOffset) m_Pos++];
}
}
else
{
t_int32 lenDiff = string.size() - m_Pos;
char fToken;
char sToken;
t_bool bSetFToken = FALSE;
t_int32 tempIndex = m_ChunkIndex;
UnicodeString token;
while (TRUE)
{
// lenDiff = 1, 2 always
// the =XX spans different chunks
// if last chunk, return out of chunks status
if (tempIndex == m_Chunks->GetSize() - 1)
{
status = m_NOMORECHUNKS;
return -1;
}
else
{
UnicodeString nextstring = *((UnicodeString *) m_Chunks->GetAt(tempIndex + 1));
tempIndex++;
if (nextstring.size() >= 2)
{
t_int8 c;
if (lenDiff == 2)
{
fToken = (char) string[(TextOffset) (string.size() - 1)];
sToken = (char) nextstring[(TextOffset) 0];
if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken))
{
c = ICalReader::convertHex(fToken, sToken);
m_Pos = 1;
m_ChunkIndex = tempIndex;
bSetFToken = FALSE;
return c;
}
else
{
return (t_int8) (string)[(TextOffset) m_Pos++];
}
}
else
{
// lenDiff = 1
if (bSetFToken)
{
sToken = (char)nextstring[(TextOffset) 0];
}
else
{
fToken = (char)nextstring[(TextOffset) 0];
sToken = (char)nextstring[(TextOffset) 1];
}
if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken))
{
c = ICalReader::convertHex(fToken, sToken);
m_Pos = 2;
m_ChunkIndex = tempIndex;
bSetFToken = FALSE;
return c;
}
else
{
return (t_int8) (string)[(TextOffset) m_Pos++];
}
}
}
else
{
if (nextstring.size() > 0)
{
if (!bSetFToken)
{
fToken = (char)nextstring[(TextOffset) 0];
bSetFToken = TRUE;
}
else
{
sToken = (char)nextstring[(TextOffset) 0];
if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken))
{
char c;
c = ICalReader::convertHex(fToken, sToken);
m_Pos = 1;
m_ChunkIndex = tempIndex;
bSetFToken = FALSE;
return c;
}
else
{
return (t_int8) (string)[(TextOffset) m_Pos++];
}
}
}
}
}
}
}
}
else
{
return (t_int8) (string)[(TextOffset) m_Pos++];
}
}
else
{
return (t_int8) (string)[(TextOffset) m_Pos++];
}
}
else
{
// delete front string from list, try reading from next chunk
m_Pos = 0;
t_int32 j = m_ChunkIndex;
m_ChunkIndex++;
if (-1 == m_Mark)
{
for (i = m_ChunkIndex - 1; i >=0 ; i--)
{
delete ((UnicodeString *) m_Chunks->GetAt(i));
m_Chunks->RemoveAt(i);
m_ChunkIndex--;
}
}
}
}
}
status = 1;
return -1;
#else
t_int32 i = 0;
status = ZERO_ERROR;
@ -305,9 +110,139 @@ t_int8 nsCapiCallbackReader::read(ErrorCode & status)
nsCapiBufferStruct * cbBuf = (nsCapiBufferStruct *) m_Chunks->GetAt(m_ChunkIndex);
char * buf = cbBuf->m_pBuf;
char c;
if ((size_t) m_Pos < cbBuf->m_pBufSize)
{
return buf[m_Pos++];
{
if (JulianUtility::MimeEncoding_QuotedPrintable == m_Encoding)
{
char * buf = cbBuf->m_pBuf;
c = buf[m_Pos];
if ('=' == c)
{
if (cbBuf->m_pBufSize >= (size_t) (m_Pos + 3))
{
if (ICalReader::isHex(buf[m_Pos + 1]) && ICalReader::isHex(buf[m_Pos + 2]))
{
c = ICalReader::convertHex(buf[m_Pos + 1], buf[m_Pos + 2]);
m_Pos += 3;
return c;
}
else
{
return (t_int8) buf[m_Pos++];
}
}
else
{
PRInt32 lenDiff = cbBuf->m_pBufSize - m_Pos;
char fToken, sToken;
PRBool bSetFToken = FALSE;
PRInt32 tempIndex = m_ChunkIndex;
UnicodeString token;
while (TRUE)
{
// lenDiff = 1, 2 always
// the =XX spans different chunks
// if last chunk, return out of chunks status
if (tempIndex == m_Chunks->GetSize() - 1)
{
status = m_NOMORECHUNKS;
return -1;
}
else
{
nsCapiBufferStruct * cbNextBuf = (nsCapiBufferStruct *) m_Chunks->GetAt(tempIndex + 1);
char * nextBuf = cbNextBuf->m_pBuf;
tempIndex++;
if (cbNextBuf->m_pBufSize >= 2)
{
if (lenDiff == 2)
{
fToken = buf[cbBuf->m_pBufSize - 1];
sToken = nextBuf[0];
if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken))
{
c = ICalReader::convertHex(fToken, sToken);
m_Pos = 1;
m_ChunkIndex = tempIndex;
bSetFToken = FALSE;
return c;
}
else
{
return (t_int8) buf[m_Pos++];
}
}
else
{
// lenDiff = 1
if (bSetFToken)
{
sToken = nextBuf[0];
}
else
{
fToken = nextBuf[0];
sToken = nextBuf[1];
}
if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken))
{
c = ICalReader::convertHex(fToken, sToken);
m_Pos = 2;
m_ChunkIndex = tempIndex;
bSetFToken = FALSE;
return c;
}
else
{
return (t_int8) buf[m_Pos++];
}
}
}
else
{
if (cbNextBuf->m_pBufSize > 0)
{
if (!bSetFToken)
{
fToken = nextBuf[0];
bSetFToken = TRUE;
}
else
{
sToken = nextBuf[0];
if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken))
{
c = ICalReader::convertHex(fToken, sToken);
m_Pos = 1;
m_ChunkIndex = tempIndex;
bSetFToken = FALSE;
return c;
}
else
{
return (t_int8) buf[m_Pos++];
}
}
}
}
}
}
}
}
else
{
return (t_int8) buf[m_Pos++];
}
}
else
{
return (t_int8) buf[m_Pos++];
}
}
else
{
@ -318,10 +253,10 @@ t_int8 nsCapiCallbackReader::read(ErrorCode & status)
}
status = 1;
return -1;
#endif
}
//---------------------------------------------------------------------
UnicodeString &
nsCapiCallbackReader::createLine(t_int32 oldPos, t_int32 oldChunkIndex,
t_int32 newPos, t_int32 newChunkIndex,
@ -416,52 +351,6 @@ nsCapiCallbackReader::readFullLine(UnicodeString & aLine, ErrorCode & status, t_
UnicodeString &
nsCapiCallbackReader::readLine(UnicodeString & aLine, ErrorCode & status)
{
#if 0
status = ZERO_ERROR;
t_int8 c = 0;
t_int32 oldPos = m_Pos;
t_int32 oldChunkIndex = m_ChunkIndex;
aLine = "";
c = read(status);
while (!(FAILURE(status)))
{
if (status == m_NOMORECHUNKS)
{
// block
break;
}
/* Break on '\n', '\r\n', and '\r' */
else if (c == '\n')
{
break;
}
else if (c == '\r')
{
mark();
c = read(status);
if (FAILURE(status))
{
break;
}
else if (c == '\n')
{
break;
}
else
{
reset();
break;
}
}
aLine += c;
c = read(status);
}
return aLine;
#else
aLine = "";
if (m_Chunks == 0 || m_Chunks->GetSize() == 0 ||
@ -472,12 +361,14 @@ nsCapiCallbackReader::readLine(UnicodeString & aLine, ErrorCode & status)
}
else
{
nsCapiBufferStruct * cbBuf = (nsCapiBufferStruct *) m_Chunks->GetAt(m_ChunkIndex);
nsCapiBufferStruct * cbBuf =
(nsCapiBufferStruct *) m_Chunks->GetAt(m_ChunkIndex);
char * currentBuf = cbBuf->m_pBuf;
char * line = 0;
PRInt32 i;
t_bool bFoundNewLine = FALSE;
for (i = m_Pos; 0 != currentBuf[i] && ((size_t) i < cbBuf->m_pBufSize); i++)
for (i = m_Pos; 0 != currentBuf[i] &&
((size_t) i < cbBuf->m_pBufSize); i++)
{
if ('\n' == currentBuf[i])
{
@ -505,8 +396,6 @@ nsCapiCallbackReader::readLine(UnicodeString & aLine, ErrorCode & status)
aLine = line;
return aLine;
}
#endif
}
//---------------------------------------------------------------------