Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
3aab7b07
Commit
3aab7b07
authored
Sep 09, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(LogDB): добавил функцию экранирования кавычек перед записью в БД
parent
badf49e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
4 deletions
+23
-4
LogDB.cc
extensions/LogDB/LogDB.cc
+16
-1
LogDB.h
extensions/LogDB/LogDB.h
+7
-3
No files found.
extensions/LogDB/LogDB.cc
View file @
3aab7b07
...
...
@@ -265,7 +265,7 @@ void LogDB::addLog( LogDB::Log* log, const string& txt )
<<
tm
.
tv_sec
<<
"','"
// timestamp
<<
tm
.
tv_nsec
<<
"','"
// usec
<<
log
->
name
<<
"','"
<<
txt
<<
"');"
;
<<
qEscapeString
(
txt
)
<<
"');"
;
qbuf
.
emplace
(
q
.
str
());
}
...
...
@@ -964,6 +964,21 @@ string LogDB::qDate( const string& p, const char sep )
return
p
.
substr
(
0
,
4
)
+
"-"
+
p
.
substr
(
4
,
2
)
+
"-"
+
p
.
substr
(
6
,
2
);
}
// -----------------------------------------------------------------------------
std
::
string
LogDB
::
qEscapeString
(
const
string
&
txt
)
{
ostringstream
ret
;
for
(
const
auto
&
c
:
txt
)
{
ret
<<
c
;
if
(
c
==
'\''
||
c
==
'"'
)
ret
<<
c
;
}
return
ret
.
str
();
}
// -----------------------------------------------------------------------------
void
LogDB
::
onWebSocketSession
(
Poco
::
Net
::
HTTPServerRequest
&
req
,
Poco
::
Net
::
HTTPServerResponse
&
resp
)
{
using
Poco
::
Net
::
WebSocket
;
...
...
extensions/LogDB/LogDB.h
View file @
3aab7b07
...
...
@@ -66,12 +66,13 @@ namespace uniset
и каждый лог будет генерировать не более 2-5 мегабайт записей. Поэтому sqlite должно хватить.
\section sec_LogDB_Conf Конфигурирование LogDB
\code
<LogDB name="LogDB" ...>
<logserver name="" ip=".." port=".." cmd=".." description=".."/>
<logserver name="" ip=".." port=".." cmd=".." description=".."/>
<logserver name="" ip=".." port=".." cmd=".."/>
</LogDB>
\endcode
\section sec_LogDB_DB LogDB Работа с БД
Для оптимизации, запись в БД сделана не по каждому сообщению, а через промежуточнй буффер.
...
...
@@ -87,7 +88,7 @@ namespace uniset
--prefix-httpserver-host и --prefix-httpserver-port.
Запросы обрабатываются по пути: api/version/logdb/...
\code
/help - Получение списка доступных команд
/list - список доступных логов
/logs?logname&..parameters.. - получение логов 'logname'
...
...
@@ -100,7 +101,7 @@ namespace uniset
По умолчанию: минут
/count?logname - Получить текущее количество записей
\endcode
\section sec_LogDB_WEBSOCK LogDB Поддержка web socket
...
...
@@ -195,6 +196,9 @@ namespace uniset
// преобразование в дату 'YYYY-MM-DD' из строки 'YYYYMMDD' или 'YYYY/MM/DD'
static
std
::
string
qDate
(
const
std
::
string
&
p
,
const
char
sep
=
'-'
);
// экранирование кавычек (удваивание для sqlite)
static
std
::
string
qEscapeString
(
const
std
::
string
&
s
);
std
::
shared_ptr
<
LogWebSocket
>
newWebSocket
(
Poco
::
Net
::
HTTPServerRequest
*
req
,
Poco
::
Net
::
HTTPServerResponse
*
resp
,
const
std
::
string
&
logname
);
void
delWebSocket
(
std
::
shared_ptr
<
LogWebSocket
>&
ws
);
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment