mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-24 18:55:30 +00:00
fix error when SMTP EHLO response comes in multiple packets, patch by ch.ey@gmx.net, r=bienvenu, sr=sspitzer, a=sspitzer 198573
This commit is contained in:
parent
04fb8b72d8
commit
803689ac91
@ -234,6 +234,7 @@ nsSmtpProtocol::~nsSmtpProtocol()
|
||||
PR_Free(m_addressCopy);
|
||||
PR_Free(m_verifyAddress);
|
||||
PR_Free(m_dataBuf);
|
||||
delete m_lineStreamBuffer;
|
||||
}
|
||||
|
||||
void nsSmtpProtocol::Initialize(nsIURI * aURL)
|
||||
@ -321,6 +322,8 @@ void nsSmtpProtocol::Initialize(nsIURI * aURL)
|
||||
rv = OpenNetworkSocket(aURL, nsnull, callbacks);
|
||||
}
|
||||
|
||||
m_lineStreamBuffer = new nsMsgLineStreamBuffer(OUTPUT_BUFFER_SIZE, PR_TRUE);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
}
|
||||
@ -379,39 +382,6 @@ nsresult aStatus)
|
||||
// End of nsIStreamListenerSupport
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PRInt32 nsSmtpProtocol::ReadLine(nsIInputStream * inputStream, PRUint32 length, char ** line)
|
||||
{
|
||||
nsCOMPtr<nsISearchableInputStream> bufferInputStr = do_QueryInterface(inputStream);
|
||||
PRUint32 numBytesLastRead = 0; // total number of bytes read into the current line
|
||||
|
||||
if (bufferInputStr)
|
||||
{
|
||||
// only try to read out an entire line...if we don't have a full line yet then wait for
|
||||
// more data....
|
||||
PRBool found = PR_FALSE;
|
||||
PRUint32 offset = 0;
|
||||
bufferInputStr->Search("\n", PR_TRUE, &found, &offset);
|
||||
if (found && offset < OUTPUT_BUFFER_SIZE - 1)
|
||||
{
|
||||
m_dataBuf[0] = '\0';
|
||||
inputStream->Read(m_dataBuf, offset + 1 /* + 1 to read past the \n */, &numBytesLastRead);
|
||||
m_dataBuf[numBytesLastRead] = '\0';
|
||||
|
||||
*line = m_dataBuf;
|
||||
}
|
||||
else
|
||||
return -1; // inform caller to block
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_ASSERTION(0, "uhoh.....our input stream is no longer searchable");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return numBytesLastRead;
|
||||
}
|
||||
|
||||
void nsSmtpProtocol::UpdateStatus(PRInt32 aStatusID)
|
||||
{
|
||||
if (m_statusFeedback)
|
||||
@ -440,20 +410,21 @@ void nsSmtpProtocol::UpdateStatusWithString(const PRUnichar * aStatusString)
|
||||
*/
|
||||
PRInt32 nsSmtpProtocol::SmtpResponse(nsIInputStream * inputStream, PRUint32 length)
|
||||
{
|
||||
char * line = nsnull;
|
||||
char cont_char;
|
||||
PRInt32 bytesRead = 0;
|
||||
char * line = nsnull;
|
||||
char cont_char;
|
||||
PRUint32 ln = 0;
|
||||
PRBool pauseForMoreData = PR_FALSE;
|
||||
|
||||
bytesRead = ReadLine(inputStream, length, &line);
|
||||
line = m_lineStreamBuffer->ReadNextLine(inputStream, ln, pauseForMoreData);
|
||||
|
||||
if (bytesRead < 0) // we are blocked waiting for more data...
|
||||
if(pauseForMoreData || !line)
|
||||
{
|
||||
m_nextState = SMTP_RESPONSE;
|
||||
SetFlag(SMTP_PAUSE_FOR_READ);
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_totalAmountRead += bytesRead;
|
||||
SetFlag(SMTP_PAUSE_FOR_READ); /* pause */
|
||||
PR_Free(line);
|
||||
return(ln);
|
||||
}
|
||||
|
||||
m_totalAmountRead += ln;
|
||||
|
||||
PR_LOG(SMTPLogModule, PR_LOG_ALWAYS, ("SMTP Response: %s", line));
|
||||
cont_char = ' '; /* default */
|
||||
@ -488,13 +459,8 @@ PRInt32 nsSmtpProtocol::SmtpResponse(nsIInputStream * inputStream, PRUint32 leng
|
||||
m_nextState = m_nextStateAfterResponse;
|
||||
ClearFlag(SMTP_PAUSE_FOR_READ); /* don't pause */
|
||||
}
|
||||
else
|
||||
{
|
||||
inputStream->Available(&length); // refresh the length as it has changed...
|
||||
if (!length)
|
||||
SetFlag(SMTP_PAUSE_FOR_READ);
|
||||
}
|
||||
|
||||
PR_Free(line);
|
||||
return(0); /* everything ok */
|
||||
}
|
||||
|
||||
@ -1025,7 +991,7 @@ PRInt32 nsSmtpProtocol::AuthLoginPassword()
|
||||
{
|
||||
unsigned char digest[DIGEST_LENGTH];
|
||||
char * decodedChallenge = PL_Base64Decode(m_responseText.get(),
|
||||
m_responseText.Length() - 2 /* subtract CRLF */, nsnull);
|
||||
m_responseText.Length(), nsnull);
|
||||
|
||||
if (decodedChallenge)
|
||||
rv = MSGCramMD5(decodedChallenge, strlen(decodedChallenge), password.get(), password.Length(), digest);
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "nsIMsgStatusFeedback.h"
|
||||
#include "nsIMsgLogonRedirector.h"
|
||||
#include "nsIMsgStringService.h"
|
||||
#include "nsMsgLineBuffer.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
@ -165,6 +166,7 @@ private:
|
||||
PRInt32 m_previousResponseCode;
|
||||
PRInt32 m_continuationResponse;
|
||||
nsCString m_responseText; /* text returned from Smtp server */
|
||||
nsMsgLineStreamBuffer *m_lineStreamBuffer; // used to efficiently extract lines from the incoming data stream
|
||||
|
||||
char *m_addressCopy;
|
||||
char *m_addresses;
|
||||
@ -202,8 +204,6 @@ private:
|
||||
// Communication methods --> Reading and writing protocol
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PRInt32 ReadLine(nsIInputStream * inputStream, PRUint32 length, char ** line);
|
||||
|
||||
nsCOMPtr<nsIMsgStringService> mSmtpBundle;
|
||||
void UpdateStatus(PRInt32 aStatusID);
|
||||
void UpdateStatusWithString(const PRUnichar * aStatusString);
|
||||
|
Loading…
Reference in New Issue
Block a user