SH-4653 FIX Interesting: Viewer crashes while reading chat history

fixed code that was causing abnormal thread termination in the first place
meow-7.2.2
Richard Linden 2013-12-10 16:43:23 -08:00
parent 1522c1b3bd
commit 5e55cfd49e
1 changed files with 94 additions and 94 deletions

View File

@ -845,115 +845,115 @@ bool LLChatLogParser::parse(std::string& raw, LLSD& im, const LLSD& parse_params
return true; //parsed name and message text, maybe have a timestamp too
}
LLLoadHistoryThread::LLLoadHistoryThread() : LLThread("load chat history")
{
mNewLoad = false;
}
void LLLoadHistoryThread::run()
{
while (!LLApp::isQuitting())
{
if(mNewLoad)
{
loadHistory(mFileName,mMessages,mLoadParams);
break;
}
}
}
LLLoadHistoryThread::LLLoadHistoryThread() : LLThread("load chat history")
{
mNewLoad = false;
void LLLoadHistoryThread::setHistoryParams(const std::string& file_name, const LLSD& load_params)
{
mFileName = file_name;
mLoadParams = load_params;
mNewLoad = true;
}
void LLLoadHistoryThread::loadHistory(const std::string& file_name, std::list<LLSD>& messages, const LLSD& load_params)
{
if (file_name.empty())
{
LL_WARNS("LLLogChat::loadHistory") << "Session name is Empty!" << LL_ENDL;
return ;
}
void LLLoadHistoryThread::run()
bool load_all_history = load_params.has("load_all_history") ? load_params["load_all_history"].asBoolean() : false;
LLFILE* fptr = LLFile::fopen(LLLogChat::makeLogFileName(file_name), "r");/*Flawfinder: ignore*/
if (!fptr)
{
while (!LLApp::isQuitting())
{
if(mNewLoad)
{
loadHistory(mFileName,mMessages,mLoadParams);
shutdown();
}
}
fptr = LLFile::fopen(LLLogChat::oldLogFileName(file_name), "r");/*Flawfinder: ignore*/
if (!fptr)
{
mNewLoad = false;
(*mLoadEndSignal)(messages, file_name);
return; //No previous conversation with this name.
}
}
void LLLoadHistoryThread::setHistoryParams(const std::string& file_name, const LLSD& load_params)
{
mFileName = file_name;
mLoadParams = load_params;
mNewLoad = true;
}
void LLLoadHistoryThread::loadHistory(const std::string& file_name, std::list<LLSD>& messages, const LLSD& load_params)
{
if (file_name.empty())
{
LL_WARNS("LLLogChat::loadHistory") << "Session name is Empty!" << LL_ENDL;
return ;
}
char buffer[LOG_RECALL_SIZE]; /*Flawfinder: ignore*/
char *bptr;
S32 len;
bool firstline = TRUE;
bool load_all_history = load_params.has("load_all_history") ? load_params["load_all_history"].asBoolean() : false;
LLFILE* fptr = LLFile::fopen(LLLogChat::makeLogFileName(file_name), "r");/*Flawfinder: ignore*/
if (!fptr)
{
fptr = LLFile::fopen(LLLogChat::oldLogFileName(file_name), "r");/*Flawfinder: ignore*/
if (!fptr)
{
mNewLoad = false;
(*mLoadEndSignal)(messages, file_name);
return; //No previous conversation with this name.
}
}
char buffer[LOG_RECALL_SIZE]; /*Flawfinder: ignore*/
char *bptr;
S32 len;
bool firstline = TRUE;
if (load_all_history || fseek(fptr, (LOG_RECALL_SIZE - 1) * -1 , SEEK_END))
{ //We need to load the whole historyFile or it's smaller than recall size, so get it all.
firstline = FALSE;
if (fseek(fptr, 0, SEEK_SET))
{
fclose(fptr);
mNewLoad = false;
(*mLoadEndSignal)(messages, file_name);
return;
}
}
while (fgets(buffer, LOG_RECALL_SIZE, fptr) && !feof(fptr))
{
len = strlen(buffer) - 1; /*Flawfinder: ignore*/
for (bptr = (buffer + len); (*bptr == '\n' || *bptr == '\r') && bptr>buffer; bptr--) *bptr='\0';
if (firstline)
{
firstline = FALSE;
continue;
}
std::string line(buffer);
//updated 1.23 plaint text log format requires a space added before subsequent lines in a multilined message
if (' ' == line[0])
{
line.erase(0, MULTI_LINE_PREFIX.length());
append_to_last_message(messages, '\n' + line);
}
else if (0 == len && ('\n' == line[0] || '\r' == line[0]))
{
//to support old format's multilined messages with new lines used to divide paragraphs
append_to_last_message(messages, line);
}
else
{
LLSD item;
if (!LLChatLogParser::parse(line, item, load_params))
{
item[LL_IM_TEXT] = line;
}
messages.push_back(item);
}
}
if (load_all_history || fseek(fptr, (LOG_RECALL_SIZE - 1) * -1 , SEEK_END))
{ //We need to load the whole historyFile or it's smaller than recall size, so get it all.
firstline = FALSE;
if (fseek(fptr, 0, SEEK_SET))
{
fclose(fptr);
mNewLoad = false;
(*mLoadEndSignal)(messages, file_name);
return;
}
}
//static
boost::signals2::connection LLLoadHistoryThread::setLoadEndSignal(const load_end_signal_t::slot_type& cb)
while (fgets(buffer, LOG_RECALL_SIZE, fptr) && !feof(fptr))
{
if (NULL == mLoadEndSignal)
len = strlen(buffer) - 1; /*Flawfinder: ignore*/
for (bptr = (buffer + len); (*bptr == '\n' || *bptr == '\r') && bptr>buffer; bptr--) *bptr='\0';
if (firstline)
{
mLoadEndSignal = new load_end_signal_t();
firstline = FALSE;
continue;
}
return mLoadEndSignal->connect(cb);
std::string line(buffer);
//updated 1.23 plaint text log format requires a space added before subsequent lines in a multilined message
if (' ' == line[0])
{
line.erase(0, MULTI_LINE_PREFIX.length());
append_to_last_message(messages, '\n' + line);
}
else if (0 == len && ('\n' == line[0] || '\r' == line[0]))
{
//to support old format's multilined messages with new lines used to divide paragraphs
append_to_last_message(messages, line);
}
else
{
LLSD item;
if (!LLChatLogParser::parse(line, item, load_params))
{
item[LL_IM_TEXT] = line;
}
messages.push_back(item);
}
}
fclose(fptr);
mNewLoad = false;
(*mLoadEndSignal)(messages, file_name);
}
//static
boost::signals2::connection LLLoadHistoryThread::setLoadEndSignal(const load_end_signal_t::slot_type& cb)
{
if (NULL == mLoadEndSignal)
{
mLoadEndSignal = new load_end_signal_t();
}
return mLoadEndSignal->connect(cb);
}