Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
liblinphone
Commits
3c70511b
Commit
3c70511b
authored
Aug 24, 2017
by
Ronan
Browse files
feat(EventsDb): impl `getMessagesCount`
parent
637be814
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
30 deletions
+65
-30
src/db/abstract/abstract-db.cpp
src/db/abstract/abstract-db.cpp
+2
-3
src/db/abstract/abstract-db.h
src/db/abstract/abstract-db.h
+1
-1
src/db/events-db.cpp
src/db/events-db.cpp
+59
-23
src/db/events-db.h
src/db/events-db.h
+3
-3
No files found.
src/db/abstract/abstract-db.cpp
View file @
3c70511b
...
...
@@ -18,7 +18,6 @@
#include "abstract-db-p.h"
#include "db/provider/db-session-provider.h"
#include "logger/logger.h"
#include "abstract-db.h"
...
...
@@ -60,12 +59,12 @@ void AbstractDb::init () {
// -----------------------------------------------------------------------------
string
AbstractDb
::
primaryKeyAutoIncrementStr
()
const
{
string
AbstractDb
::
primaryKeyAutoIncrementStr
(
const
string
&
type
)
const
{
L_D
(
const
AbstractDb
);
switch
(
d
->
backend
)
{
case
Mysql
:
return
" BIGINT
UNSIGNED PRIMARY KEY AUTO_INCREMENT"
;
return
type
+
"
UNSIGNED PRIMARY KEY AUTO_INCREMENT"
;
case
Sqlite3
:
return
" INTEGER PRIMARY KEY AUTOINCREMENT"
;
}
...
...
src/db/abstract/abstract-db.h
View file @
3c70511b
...
...
@@ -50,7 +50,7 @@ protected:
virtual
void
init
();
std
::
string
primaryKeyAutoIncrementStr
()
const
;
std
::
string
primaryKeyAutoIncrementStr
(
const
std
::
string
&
type
=
"INT"
)
const
;
private:
L_DECLARE_PRIVATE
(
AbstractDb
);
...
...
src/db/events-db.cpp
View file @
3c70511b
...
...
@@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#ifdef SOCI_ENABLED
#include <soci/soci.h>
#endif // ifdef SOCI_ENABLED
...
...
@@ -44,22 +46,29 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {}
// Helpers.
// -----------------------------------------------------------------------------
inline
string
mapFilterToSqlEvent
(
EventsDb
::
Filter
filter
)
{
switch
(
filter
)
{
case
EventsDb
::
NoFilter
:
break
;
case
EventsDb
::
MessageFilter
:
return
"0"
;
case
EventsDb
::
CallFilter
:
return
"1"
;
case
EventsDb
::
ConferenceFilter
:
return
"2"
;
}
return
""
;
inline
constexpr
const
char
*
mapFilterToSqlEvent
(
EventsDb
::
Filter
filter
)
{
// Ugly. Yes. But constexpr...
return
filter
==
EventsDb
::
MessageFilter
?
"0"
:
(
filter
==
EventsDb
::
CallFilter
?
"1"
:
(
filter
==
EventsDb
::
ConferenceFilter
?
"2"
:
""
)
);
}
static
string
buildSqlEventFilter
(
const
list
<
EventsDb
::
Filter
>
&
filters
,
EventsDb
::
FilterMask
mask
)
{
L_ASSERT
(
find_if
(
filters
.
cbegin
(),
filters
.
cend
(),
[](
const
EventsDb
::
Filter
&
filter
)
{
return
filter
==
EventsDb
::
NoFilter
;
})
==
filters
.
cend
()
);
if
(
mask
==
EventsDb
::
NoFilter
)
return
""
;
bool
isStart
=
true
;
string
sql
;
for
(
const
auto
&
filter
:
filters
)
{
...
...
@@ -71,7 +80,8 @@ static string buildSqlEventFilter (const list<EventsDb::Filter> &filters, Events
sql
+=
" WHERE "
;
}
else
sql
+=
" OR "
;
sql
+=
" type = "
+
mapFilterToSqlEvent
(
filter
);
sql
+=
" event_type_id = "
;
sql
+=
mapFilterToSqlEvent
(
filter
);
}
return
sql
;
...
...
@@ -93,28 +103,39 @@ static string buildSqlEventFilter (const list<EventsDb::Filter> &filters, Events
" value VARCHAR(255) NOT NULL"
")"
;
*
session
<<
"CREATE TABLE IF NOT EXISTS event_type ("
" id"
+
primaryKeyAutoIncrementStr
(
"TINYINT"
)
+
","
" value VARCHAR(255) NOT NULL"
")"
;
*
session
<<
"CREATE TABLE IF NOT EXISTS event ("
" id"
+
primaryKeyAutoIncrementStr
()
+
","
" timestamp TIMESTAMP NOT NULL"
" event_type_id TINYINT UNSIGNED NOT NULL,"
" timestamp TIMESTAMP NOT NULL,"
" FOREIGN KEY (event_type_id)"
" REFERENCES event_type(id)"
" ON DELETE CASCADE"
")"
;
*
session
<<
"CREATE TABLE IF NOT EXISTS message_status ("
" id"
+
primaryKeyAutoIncrementStr
()
+
","
" id"
+
primaryKeyAutoIncrementStr
(
"TINYINT"
)
+
","
" status VARCHAR(255) NOT NULL"
")"
;
*
session
<<
"CREATE TABLE IF NOT EXISTS message_direction ("
" id"
+
primaryKeyAutoIncrementStr
()
+
","
" id"
+
primaryKeyAutoIncrementStr
(
"TINYINT"
)
+
","
" direction VARCHAR(255) NOT NULL"
")"
;
*
session
<<
"CREATE TABLE IF NOT EXISTS dialog ("
" local_sip_address_id BIGINT UNSIGNED NOT NULL,"
// Sip address used to communicate.
" remote_sip_address_id BIGINT UNSIGNED NOT NULL,"
// Server (for conference) or user sip address.
" id"
+
primaryKeyAutoIncrementStr
()
+
","
" local_sip_address_id INT UNSIGNED NOT NULL,"
// Sip address used to communicate.
" remote_sip_address_id INT UNSIGNED NOT NULL,"
// Server (for conference) or user sip address.
" creation_timestamp TIMESTAMP NOT NULL,"
// Dialog creation date.
" last_update_timestamp TIMESTAMP NOT NULL,"
// Last event timestamp (call, message...).
" FOREIGN KEY (local_sip_address_id)"
...
...
@@ -128,7 +149,7 @@ static string buildSqlEventFilter (const list<EventsDb::Filter> &filters, Events
*
session
<<
"CREATE TABLE IF NOT EXISTS message_event ("
" id"
+
primaryKeyAutoIncrementStr
()
+
","
" dialog_id
BIG
INT UNSIGNED NOT NULL,"
" dialog_id INT UNSIGNED NOT NULL,"
" status_id TINYINT UNSIGNED NOT NULL,"
" direction_id TINYINT UNSIGNED NOT NULL,"
" imdn_message_id VARCHAR(255) NOT NULL,"
// See: https://tools.ietf.org/html/rfc5438#section-6.3
...
...
@@ -190,9 +211,24 @@ static string buildSqlEventFilter (const list<EventsDb::Filter> &filters, Events
}
int
EventsDb
::
getMessagesCount
(
const
string
&
remoteAddress
)
const
{
// TODO.
(
void
)
remoteAddress
;
return
0
;
L_D
(
const
EventsDb
);
string
query
=
"SELECT COUNT(*) FROM message_event"
" WHERE dialog_id = ("
" SELECT id FROM dialog WHERE remote_sip_address_id =("
" SELECT id FROM sip_address WHERE value = :remote_address"
" )"
" )"
,
use
(
remoteAddress
);
int
count
=
0
;
L_BEGIN_LOG_EXCEPTION
soci
::
session
*
session
=
d
->
dbSession
.
getBackendSession
<
soci
::
session
>
();
*
session
<<
query
,
soci
::
into
(
count
);
L_END_LOG_EXCEPTION
return
count
;
}
int
EventsDb
::
getUnreadMessagesCount
(
const
string
&
remoteAddress
)
const
{
...
...
src/db/events-db.h
View file @
3c70511b
...
...
@@ -50,11 +50,11 @@ public:
int
getEventsCount
(
FilterMask
mask
=
NoFilter
)
const
;
// Messages, calls and conferences.
int
getMessagesCount
(
const
std
::
string
&
remoteAddress
)
const
;
int
getUnreadMessagesCount
(
const
std
::
string
&
remoteAddress
)
const
;
int
getMessagesCount
(
const
std
::
string
&
remoteAddress
=
""
)
const
;
int
getUnreadMessagesCount
(
const
std
::
string
&
remoteAddress
=
""
)
const
;
std
::
list
<
Event
>
getHistory
(
const
std
::
string
&
remoteAddress
,
int
nLast
,
FilterMask
mask
=
NoFilter
)
const
;
std
::
list
<
Event
>
getHistory
(
const
std
::
string
&
remoteAddress
,
int
begin
,
int
end
,
FilterMask
mask
=
NoFilter
)
const
;
void
cleanHistory
(
const
std
::
string
&
remoteAddress
);
void
cleanHistory
(
const
std
::
string
&
remoteAddress
=
""
);
protected:
void
init
()
override
;
...
...
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