make imap protocol logging handle large chunks of data sent to server, 232129 sr=mscott

This commit is contained in:
bienvenu%nventure.com 2004-01-26 15:52:04 +00:00
Родитель b2a7d3b752
Коммит 93c0ca4c45
1 изменённых файлов: 43 добавлений и 4 удалений

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

@ -3656,13 +3656,38 @@ void nsImapProtocol::Log(const char *logSubName, const char *extraInfo, const ch
// static const char waitingStateName[] = "W"; // static const char waitingStateName[] = "W";
const char *stateName = NULL; const char *stateName = NULL;
const char *hostName = GetImapHostName(); // initilize to empty string const char *hostName = GetImapHostName(); // initilize to empty string
PRInt32 logDataLen = PL_strlen(logData); // PL_strlen checks for null
nsCString logDataLines;
const char *logDataToLog;
PRInt32 lastLineEnd;
const int kLogDataChunkSize = 400; // nspr line length is 512, and we allow some space for the log preamble.
// break up buffers > 400 bytes on line boundaries.
if (logDataLen > kLogDataChunkSize)
{
logDataLines.Assign(logData);
lastLineEnd = logDataLines.RFindChar('\n', kLogDataChunkSize);
// null terminate the last line
if (lastLineEnd == kNotFound)
lastLineEnd = kLogDataChunkSize - 1;
logDataLines.Insert( '\0', lastLineEnd + 1);
logDataToLog = logDataLines.get();
}
else
{
logDataToLog = logData;
lastLineEnd = logDataLen;
}
switch (GetServerStateParser().GetIMAPstate()) switch (GetServerStateParser().GetIMAPstate())
{ {
case nsImapServerResponseParser::kFolderSelected: case nsImapServerResponseParser::kFolderSelected:
if (extraInfo) if (extraInfo)
PR_LOG(IMAP, PR_LOG_ALWAYS, ("%x:%s:%s-%s:%s:%s: %s", this,hostName,selectedStateName, GetServerStateParser().GetSelectedMailboxName(), logSubName, extraInfo, logData)); PR_LOG(IMAP, PR_LOG_ALWAYS, ("%x:%s:%s-%s:%s:%s: %.400s", this,hostName,selectedStateName, GetServerStateParser().GetSelectedMailboxName(), logSubName, extraInfo, logDataToLog));
else else
PR_LOG(IMAP, PR_LOG_ALWAYS, ("%x:%s:%s-%s:%s: %s", this,hostName,selectedStateName, GetServerStateParser().GetSelectedMailboxName(), logSubName, logData)); PR_LOG(IMAP, PR_LOG_ALWAYS, ("%x:%s:%s-%s:%s: %.400s", this,hostName,selectedStateName, GetServerStateParser().GetSelectedMailboxName(), logSubName, logDataToLog));
return; return;
case nsImapServerResponseParser::kNonAuthenticated: case nsImapServerResponseParser::kNonAuthenticated:
stateName = nonAuthStateName; stateName = nonAuthStateName;
@ -3673,9 +3698,23 @@ void nsImapProtocol::Log(const char *logSubName, const char *extraInfo, const ch
} }
if (extraInfo) if (extraInfo)
PR_LOG(IMAP, PR_LOG_ALWAYS, ("%x:%s:%s:%s:%s: %s", this,hostName,stateName,logSubName,extraInfo,logData)); PR_LOG(IMAP, PR_LOG_ALWAYS, ("%x:%s:%s:%s:%s: %.400s", this,hostName,stateName,logSubName,extraInfo,logDataToLog));
else else
PR_LOG(IMAP, PR_LOG_ALWAYS, ("%x:%s:%s:%s: %s",this,hostName,stateName,logSubName,logData)); PR_LOG(IMAP, PR_LOG_ALWAYS, ("%x:%s:%s:%s: %.400s",this,hostName,stateName,logSubName,logDataToLog));
// dump the rest of the string in < 400 byte chunks
while (logDataLen > kLogDataChunkSize)
{
logDataLines.Cut(0, lastLineEnd + 2); // + 2 to account for the LF and the '\0' we added
logDataLen = logDataLines.Length();
lastLineEnd = (logDataLen > kLogDataChunkSize) ? logDataLines.RFindChar('\n', kLogDataChunkSize) : kNotFound;
// null terminate the last line
if (lastLineEnd == kNotFound)
lastLineEnd = kLogDataChunkSize - 1;
logDataLines.Insert( '\0', lastLineEnd + 1);
logDataToLog = logDataLines.get();
PR_LOG(IMAP, PR_LOG_ALWAYS, ("%.400s", logDataToLog));
}
} }
} }