1999-03-19 22:55:08 +00:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
1999-11-06 03:43:54 +00:00
* The contents of this file are subject to the Netscape Public
* License Version 1.1 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.mozilla.org/NPL/
1999-03-19 22:55:08 +00:00
*
1999-11-06 03:43:54 +00:00
* Software distributed under the License is distributed on an " AS
* IS " basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied . See the License for the specific language governing
* rights and limitations under the License .
1999-03-19 22:55:08 +00:00
*
1999-11-06 03:43:54 +00:00
* The Original Code is mozilla . org code .
*
* The Initial Developer of the Original Code is Netscape
1999-03-19 22:55:08 +00:00
* Communications Corporation . Portions created by Netscape are
1999-11-06 03:43:54 +00:00
* Copyright ( C ) 1999 Netscape Communications Corporation . All
* Rights Reserved .
*
* Contributor ( s ) :
1999-03-19 22:55:08 +00:00
*/
# ifndef _nsMsgLineBuffer_H
# define _nsMsgLineBuffer_H
# include "msgCore.h" // precompiled header...
// I can't believe I have to have this stupid class, but I can't find
// anything suitable (nsStrImpl might be, when its done). nsIByteBuffer
// would do, if I had a stream for input, which I don't.
1999-05-18 23:55:39 +00:00
class NS_MSG_BASE nsByteArray
1999-03-19 22:55:08 +00:00
{
public :
nsByteArray ( ) ;
virtual ~ nsByteArray ( ) ;
PRUint32 GetSize ( ) { return m_bufferSize ; }
1999-04-12 20:23:04 +00:00
PRUint32 GetBufferPos ( ) { return m_bufferPos ; }
1999-03-19 22:55:08 +00:00
nsresult GrowBuffer ( PRUint32 desired_size , PRUint32 quantum = 1024 ) ;
nsresult AppendString ( const char * string ) ;
nsresult AppendBuffer ( const char * buffer , PRUint32 length ) ;
void ResetWritePos ( ) { m_bufferPos = 0 ; }
char * GetBuffer ( ) { return m_buffer ; }
protected :
char * m_buffer ;
PRUint32 m_bufferSize ;
PRUint32 m_bufferPos ; // write Pos in m_buffer - where the next byte should go.
} ;
1999-05-18 23:55:39 +00:00
class NS_MSG_BASE nsMsgLineBufferHandler : public nsByteArray
1999-03-19 22:55:08 +00:00
{
public :
virtual PRInt32 HandleLine ( char * line , PRUint32 line_length ) = 0 ;
} ;
1999-05-18 23:55:39 +00:00
class NS_MSG_BASE nsMsgLineBuffer : public nsByteArray
1999-03-19 22:55:08 +00:00
{
public :
nsMsgLineBuffer ( nsMsgLineBufferHandler * handler , PRBool convertNewlinesP ) ;
virtual ~ nsMsgLineBuffer ( ) ;
PRInt32 BufferInput ( const char * net_buffer , PRInt32 net_buffer_size ) ;
// Not sure why anyone cares, by NNTPHost seems to want to know the buf pos.
PRUint32 GetBufferPos ( ) { return m_bufferPos ; }
virtual PRInt32 HandleLine ( char * line , PRUint32 line_length ) ;
// flush last line, though it won't be CRLF terminated.
virtual PRInt32 FlushLastLine ( ) ;
protected :
nsMsgLineBuffer ( PRBool convertNewlinesP ) ;
PRInt32 ConvertAndSendBuffer ( ) ;
1999-07-24 18:15:19 +00:00
void SetLookingForCRLF ( PRBool b ) ;
1999-03-19 22:55:08 +00:00
nsMsgLineBufferHandler * m_handler ;
PRBool m_convertNewlinesP ;
1999-07-24 18:15:19 +00:00
PRBool m_lookingForCRLF ;
1999-03-19 22:55:08 +00:00
} ;
1999-04-16 22:05:33 +00:00
// I'm adding this utility class here for lack of a better place. This utility class is similar to nsMsgLineBuffer
// except it works from an input stream. It is geared towards efficiently parsing new lines out of a stream by storing
// read but unprocessed bytes in a buffer. I envision the primary use of this to be our mail protocols such as imap, news and
// pop which need to process line by line data being returned in the form of a proxied stream from the server.
class nsIInputStream ;
1999-05-18 23:55:39 +00:00
class NS_MSG_BASE nsMsgLineStreamBuffer
1999-04-16 22:05:33 +00:00
{
public :
1999-04-22 01:53:19 +00:00
// aBufferSize -- size of the buffer you want us to use for buffering stream data
1999-04-25 19:51:08 +00:00
// aEndOfLinetoken -- The delimeter string to be used for determining the end of line. This
// allows us to parse platform specific end of line endings by making it
// a parameter.
1999-04-22 01:53:19 +00:00
// aAllocateNewLines -- PR_TRUE if you want calls to ReadNextLine to allocate new memory for the line.
// if false, the char * returned is just a ptr into the buffer. Subsequent calls to
// ReadNextLine will alter the data so your ptr only has a life time of a per call.
// aEatCRLFs -- PR_TRUE if you don't want to see the CRLFs on the lines returned by ReadNextLine.
// PR_FALSE if you do want to see them.
1999-04-25 19:51:08 +00:00
nsMsgLineStreamBuffer ( PRUint32 aBufferSize , const char * aEndOfLineToken , PRBool aAllocateNewLines , PRBool aEatCRLFs = PR_TRUE ) ; // specify the size of the buffer you want the class to use....
1999-04-16 22:05:33 +00:00
virtual ~ nsMsgLineStreamBuffer ( ) ;
// Caller must free the line returned using PR_Free
1999-04-25 19:51:08 +00:00
// aEndOfLinetoken -- delimeter used to denote the end of a line.
// aNumBytesInLine -- The number of bytes in the line returned
// aPauseForMoreData -- There is not enough data in the stream to make a line at this time...
char * ReadNextLine ( nsIInputStream * aInputStream , PRUint32 & anumBytesInLine , PRBool & aPauseForMoreData ) ;
2000-04-13 05:53:56 +00:00
nsresult GrowBuffer ( PRInt32 desiredSize ) ;
1999-04-16 22:05:33 +00:00
protected :
1999-04-20 23:44:34 +00:00
PRBool m_eatCRLFs ;
1999-04-22 01:53:19 +00:00
PRBool m_allocateNewLines ;
1999-04-16 22:05:33 +00:00
char * m_dataBuffer ;
1999-04-25 19:51:08 +00:00
const char * m_endOfLineToken ;
1999-04-16 22:05:33 +00:00
PRUint32 m_dataBufferSize ;
1999-12-20 14:58:05 +00:00
PRUint32 m_startPos ;
PRUint32 m_numBytesInBuffer ;
1999-04-16 22:05:33 +00:00
} ;
1999-03-19 22:55:08 +00:00
# endif