Skip to content

Commit 546d595

Browse files
author
lsv
committed
fix read log server
Изменена функция чтения лог сервера для избежания ошибок некорректного формата UTF-8. Эти изменения применяются при устанавленом флаге ASUTP Style.
1 parent 9f11446 commit 546d595

File tree

1 file changed

+63
-14
lines changed

1 file changed

+63
-14
lines changed

frm/frmStatus.cpp

+63-14
Original file line numberDiff line numberDiff line change
@@ -2479,15 +2479,15 @@ void frmStatus::addLogFile(const wxString &filename, const wxDateTime timestamp,
24792479
// changed to return the csv format log files, we should handle it.
24802480

24812481
bool csv_log_format = filename.Right(4) == wxT(".csv");
2482-
2482+
24832483
if (csv_log_format && savedPartialLine.length() > 0)
24842484
{
24852485
if (read == 0) // Starting at beginning of log file
24862486
savedPartialLine.clear();
24872487
else
24882488
line = savedPartialLine;
24892489
}
2490-
wxString funcname = "pg_read_file(";
2490+
wxString funcname = "pg_read_binary_file(";
24912491
if (!settings->GetASUTPstyle()) funcname = "pg_file_read(";
24922492
while (len > read)
24932493
{
@@ -2499,24 +2499,73 @@ void frmStatus::addLogFile(const wxString &filename, const wxDateTime timestamp,
24992499
connection->IsAlive();
25002500
return;
25012501
}
2502-
char *raw = set->GetCharPtr(0);
2502+
2503+
char *raw1 = set->GetCharPtr(0);
25032504

2504-
if (!raw || !*raw)
2505+
if (!raw1 || !*raw1)
25052506
{
25062507
delete set;
25072508
break;
25082509
}
2509-
2510-
read += strlen(raw);
2511-
2512-
wxString str;
2513-
str = line + wxTextBuffer::Translate(wxString(raw, set->GetConversion()), wxTextFileType_Unix);
2514-
//if (wxString(wxString(raw, wxConvLibc).wx_str(), wxConvUTF8).Len() > 0)
2515-
// str = line + wxString(wxString(raw, wxConvLibc).wx_str(), wxConvUTF8);
2516-
//else {
2517-
// str = line + wxTextBuffer::Translate(wxString(raw, set->GetConversion()), wxTextFileType_Unix);
2518-
//}
2510+
char* raw;
2511+
unsigned char m[50001];
2512+
if (settings->GetASUTPstyle()) {
25192513

2514+
raw =( char *) &m[0];
2515+
unsigned char c;
2516+
unsigned char* startChar;
2517+
int pos = 0;
2518+
raw1 = raw1 + 2;
2519+
int utf8charLen = 0;
2520+
while (*raw1!=0) {
2521+
c = *raw1;
2522+
c = c - '0';
2523+
if (c > 9) c = *raw1 - 'a' + 10;
2524+
raw1++;
2525+
m[pos] = c << 4;
2526+
c = *raw1 - '0';
2527+
if (c > 9) c = *raw1 - 'a' + 10;
2528+
c = c | m[pos];
2529+
m[pos] = c;
2530+
// check utf-8 char
2531+
if (utf8charLen == 0) {
2532+
startChar = &m[pos];
2533+
if(c >> 7 == 0)
2534+
utf8charLen = 1;
2535+
else if (c >> 5 == 0x6)
2536+
utf8charLen = 2;
2537+
else if (c >> 4 == 0xE)
2538+
utf8charLen = 3;
2539+
else if (c >> 5 == 0x1E)
2540+
utf8charLen = 4;
2541+
else
2542+
utf8charLen=0;
2543+
// bad utf8 format
2544+
}
2545+
pos++;
2546+
raw1++;
2547+
utf8charLen--;
2548+
}
2549+
//
2550+
if (utf8charLen != 0) {
2551+
//read = startChar - &m[0];
2552+
// remove bad utf-8 char
2553+
*startChar = 0;
2554+
} else
2555+
m[pos] = 0;
2556+
} else {
2557+
raw = raw1;
2558+
}
2559+
read += strlen(raw);
2560+
2561+
wxString str;
2562+
str = line + wxTextBuffer::Translate(wxString(raw, set->GetConversion()), wxTextFileType_Unix);
2563+
//if (wxString(wxString(raw, wxConvLibc).wx_str(), wxConvUTF8).Len() > 0)
2564+
// str = line + wxString(wxString(raw, wxConvLibc).wx_str(), wxConvUTF8);
2565+
//else {
2566+
// str = line + wxTextBuffer::Translate(wxString(raw, set->GetConversion()), wxTextFileType_Unix);
2567+
//}
2568+
25202569

25212570
delete set;
25222571

0 commit comments

Comments
 (0)