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
ad711417
Commit
ad711417
authored
Mar 09, 2013
by
Simon Morlat
Browse files
clean message storage API
relax requirement for sqlite3
parent
837c566c
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
292 additions
and
155 deletions
+292
-155
configure.ac
configure.ac
+18
-8
coreapi/callbacks.c
coreapi/callbacks.c
+3
-2
coreapi/chat.c
coreapi/chat.c
+59
-32
coreapi/linphonecore.c
coreapi/linphonecore.c
+23
-3
coreapi/linphonecore.h
coreapi/linphonecore.h
+9
-4
coreapi/message_storage.c
coreapi/message_storage.c
+84
-67
coreapi/private.h
coreapi/private.h
+15
-12
coreapi/sal.h
coreapi/sal.h
+2
-2
coreapi/sal_eXosip2_presence.c
coreapi/sal_eXosip2_presence.c
+20
-3
gtk/chat.c
gtk/chat.c
+49
-19
gtk/friendlist.c
gtk/friendlist.c
+3
-1
gtk/linphone.h
gtk/linphone.h
+2
-0
gtk/main.c
gtk/main.c
+5
-2
No files found.
configure.ac
View file @
ad711417
...
...
@@ -670,21 +670,31 @@ if test x$enable_tunnel = xtrue; then
fi
AC_ARG_ENABLE(msg-storage,
[AS_HELP_STRING([--enable-msg-storage=[yes/no]], [Turn on compilation of message storage (default=
yes
)])],
[AS_HELP_STRING([--enable-msg-storage=[yes/no]], [Turn on compilation of message storage (default=
auto
)])],
[case "${enableval}" in
yes) enable_msg_storage=true ;;
no) enable_msg_storage=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-msg-storage) ;;
esac],
[enable_msg_storage=
true
]
[enable_msg_storage=
auto
]
)
echo "enable_msg_storage = $enable_msg_storage"
AM_CONDITIONAL(BUILD_MSG_STORAGE, test x$enable_msg_storage = xtrue)
if test x$enable_msg_storage = xtrue; then
PKG_CHECK_MODULES(SQLITE3,[ sqlite3 >= 3.7.0],[],[
AC_MSG_ERROR([sqlite3 required for message storage not found.])] )
SQLITE3_CFLAGS+="-DMSG_STORAGE_ENABLED"
AC_SUBST(SQLITE3_CFLAGS)
AC_SUBST(SQLITE3_LIBS)
if test x$enable_msg_storage != xfalse; then
PKG_CHECK_MODULES(SQLITE3,[ sqlite3 >= 3.7.0],[
SQLITE3_CFLAGS+="-DMSG_STORAGE_ENABLED"
AC_SUBST(SQLITE3_CFLAGS)
AC_SUBST(SQLITE3_LIBS)
enable_msg_storage=true
],[
if test x$enable_msg_storage = xtrue; then
AC_MSG_ERROR([sqlite3 required for message storage not found.])
fi
enable_msg_storage=false
] )
fi
...
...
coreapi/callbacks.c
View file @
ad711417
...
...
@@ -934,10 +934,11 @@ static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status){
LinphoneChatMessage
*
chat_msg
=
(
LinphoneChatMessage
*
)
sal_op_get_user_pointer
(
op
);
const
MSList
*
calls
=
linphone_core_get_calls
(
chat_msg
->
chat_room
->
lc
);
linphone_core_set_message_state
(
chat_msg
->
chat_room
,
chat_msg
->
message
,
chatStatusSal2Linphone
(
status
),
chat_msg
->
time
);
chat_msg
->
state
=
chatStatusSal2Linphone
(
status
);
linphone_chat_message_store_state
(
chat_msg
);
if
(
chat_msg
&&
chat_msg
->
cb
)
{
chat_msg
->
cb
(
chat_msg
,
chat
StatusSal2Linphone
(
stat
us
)
,
chat
_msg
->
stat
e
,
chat_msg
->
cb_ud
);
}
linphone_chat_message_destroy
(
chat_msg
);
...
...
coreapi/chat.c
View file @
ad711417
...
...
@@ -62,16 +62,7 @@ void linphone_chat_room_destroy(LinphoneChatRoom *cr){
ms_free
(
cr
->
peer
);
}
#ifdef WIN32
static
inline
char
*
my_ctime_r
(
const
time_t
*
t
,
char
*
buf
){
strcpy
(
buf
,
ctime
(
t
));
return
buf
;
}
#else
#define my_ctime_r ctime_r
#endif
static
void
_linphone_chat_room_send_message
(
LinphoneChatRoom
*
cr
,
LinphoneChatMessage
*
msg
){
const
char
*
route
=
NULL
;
...
...
@@ -80,8 +71,6 @@ static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatM
LinphoneCall
*
call
;
char
*
content_type
;
time_t
t
=
time
(
NULL
);
char
buf
[
26
];
char
*
to
;
if
(
lp_config_get_int
(
cr
->
lc
->
config
,
"sip"
,
"chat_use_call_dialogs"
,
0
)){
if
((
call
=
linphone_core_get_call_by_remote_address
(
cr
->
lc
,
cr
->
peer
))
!=
NULL
){
...
...
@@ -109,15 +98,14 @@ static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatM
}
if
(
msg
->
external_body_url
)
{
content_type
=
ms_strdup_printf
(
"message/external-body; access-type=URL; URL=
\"
%s
\"
"
,
msg
->
external_body_url
);
sal_message_send
(
op
,
identity
,
cr
->
peer
,
content_type
,
NULL
,
my_ctime_r
(
&
t
,
buf
)
);
sal_message_send
(
op
,
identity
,
cr
->
peer
,
content_type
,
NULL
);
ms_free
(
content_type
);
}
else
{
sal_text_send
(
op
,
identity
,
cr
->
peer
,
msg
->
message
,
my_ctime_r
(
&
t
,
buf
)
);
sal_text_send
(
op
,
identity
,
cr
->
peer
,
msg
->
message
);
}
to
=
linphone_address_as_string_uri_only
(
cr
->
peer_url
);
linphone_core_set_history_message
(
cr
,
identity
,
to
,
OUTGOING
,
msg
->
message
,
my_ctime_r
(
&
t
,
buf
),
READ
,
LinphoneChatMessageStateInProgress
);
ms_free
(
to
);
msg
->
dir
=
LinphoneChatMessageOutgoing
;
msg
->
from
=
linphone_address_new
(
identity
);
linphone_chat_message_store
(
msg
);
}
/**
...
...
@@ -144,27 +132,37 @@ void linphone_chat_room_message_received(LinphoneChatRoom *cr, LinphoneCore *lc,
}
void
linphone_core_message_received
(
LinphoneCore
*
lc
,
SalOp
*
op
,
const
SalMessage
*
sal_msg
){
/**
* Retrieve an existing chat room whose peer is the supplied address, if exists.
* @param lc the linphone core
* @param add a linphone address.
* @returns the matching chatroom, or NULL if no such chatroom exists.
**/
LinphoneChatRoom
*
linphone_core_get_chat_room
(
LinphoneCore
*
lc
,
const
LinphoneAddress
*
addr
){
LinphoneChatRoom
*
cr
=
NULL
;
MSList
*
elem
;
for
(
elem
=
lc
->
chatrooms
;
elem
!=
NULL
;
elem
=
ms_list_next
(
elem
)){
cr
=
(
LinphoneChatRoom
*
)
elem
->
data
;
if
(
linphone_chat_room_matches
(
cr
,
addr
)){
break
;
}
cr
=
NULL
;
}
return
cr
;
}
void
linphone_core_message_received
(
LinphoneCore
*
lc
,
SalOp
*
op
,
const
SalMessage
*
sal_msg
){
LinphoneChatRoom
*
cr
=
NULL
;
LinphoneAddress
*
addr
;
char
*
cleanfrom
;
const
char
*
to
;
char
*
from
;
LinphoneChatMessage
*
msg
;
const
SalCustomHeader
*
ch
;
char
buf
[
26
];
addr
=
linphone_address_new
(
sal_msg
->
from
);
linphone_address_clean
(
addr
);
for
(
elem
=
lc
->
chatrooms
;
elem
!=
NULL
;
elem
=
ms_list_next
(
elem
)){
cr
=
(
LinphoneChatRoom
*
)
elem
->
data
;
if
(
linphone_chat_room_matches
(
cr
,
addr
)){
break
;
}
cr
=
NULL
;
}
to
=
linphone_core_get_identity
(
lc
);
cr
=
linphone_core_get_chat_room
(
lc
,
addr
);
cleanfrom
=
linphone_address_as_string
(
addr
);
from
=
linphone_address_as_string_uri_only
(
addr
);
if
(
cr
==
NULL
){
...
...
@@ -173,8 +171,16 @@ void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessag
}
msg
=
linphone_chat_room_create_message
(
cr
,
sal_msg
->
text
);
linphone_chat_message_set_from
(
msg
,
cr
->
peer_url
);
{
LinphoneAddress
*
to
;
to
=
sal_op_get_to
(
op
)
?
linphone_address_new
(
sal_op_get_to
(
op
))
:
linphone_address_new
(
linphone_core_get_identity
(
lc
));
msg
->
to
=
to
;
}
msg
->
time
=
sal_msg
->
time
;
msg
->
state
=
LinphoneChatMessageStateDelivered
;
msg
->
is_read
=
FALSE
;
ch
=
sal_op_get_custom_header
(
op
);
if
(
ch
)
msg
->
custom_headers
=
sal_custom_header_clone
(
ch
);
...
...
@@ -182,9 +188,7 @@ void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessag
linphone_chat_message_set_external_body_url
(
msg
,
sal_msg
->
url
);
}
linphone_address_destroy
(
addr
);
linphone_core_set_history_message
(
cr
,
to
,
from
,
INCOMING
,
msg
->
message
,
my_ctime_r
(
&
msg
->
time
,
buf
),
NOT_READ
,
LinphoneChatMessageStateDelivered
);
linphone_chat_message_store
(
msg
);
linphone_chat_room_message_received
(
cr
,
lc
,
msg
);
ms_free
(
cleanfrom
);
ms_free
(
from
);
...
...
@@ -230,6 +234,7 @@ LinphoneChatMessage* linphone_chat_room_create_message(LinphoneChatRoom *cr, con
LinphoneChatMessage
*
msg
=
ms_new0
(
LinphoneChatMessage
,
1
);
msg
->
chat_room
=
(
LinphoneChatRoom
*
)
cr
;
msg
->
message
=
message
?
ms_strdup
(
message
)
:
NULL
;
msg
->
is_read
=
TRUE
;
return
msg
;
}
...
...
@@ -327,10 +332,32 @@ void linphone_chat_message_set_from(LinphoneChatMessage* message, const Linphone
*@param message #LinphoneChatMessage obj
*@return #LinphoneAddress
*/
LinphoneAddress
*
linphone_chat_message_get_from
(
const
LinphoneChatMessage
*
message
)
{
const
LinphoneAddress
*
linphone_chat_message_get_from
(
const
LinphoneChatMessage
*
message
)
{
return
message
->
from
;
}
/**
* Get destination of the message
*@param message #LinphoneChatMessage obj
*@return #LinphoneAddress
*/
const
LinphoneAddress
*
linphone_chat_message_get_to
(
const
LinphoneChatMessage
*
message
){
if
(
message
->
to
)
return
message
->
to
;
if
(
message
->
dir
==
LinphoneChatMessageOutgoing
){
return
message
->
chat_room
->
peer_url
;
}
return
NULL
;
}
/**
* Returns the origin address of a message if it was a outgoing message, or the destination address if it was an incoming message.
*@param message #LinphoneChatMessage obj
*@return #LinphoneAddress
*/
LinphoneAddress
*
linphone_chat_message_get_local_address
(
const
LinphoneChatMessage
*
message
){
return
message
->
dir
==
LinphoneChatMessageOutgoing
?
message
->
from
:
message
->
to
;
}
/**
* Get the time the message was sent.
*/
...
...
coreapi/linphonecore.c
View file @
ad711417
...
...
@@ -1306,9 +1306,6 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta
#ifdef TUNNEL_ENABLED
lc
->
tunnel
=
linphone_core_tunnel_new
(
lc
);
if
(
lc
->
tunnel
)
linphone_tunnel_configure
(
lc
->
tunnel
);
#endif
#ifdef MSG_STORAGE_ENABLED
lc
->
db
=
linphone_message_storage_init
();
#endif
if
(
lc
->
vtable
.
display_status
)
lc
->
vtable
.
display_status
(
lc
,
_
(
"Ready"
));
...
...
@@ -5265,6 +5262,8 @@ static void linphone_core_uninit(LinphoneCore *lc)
}
linphone_core_free_payload_types
(
lc
);
linphone_core_message_storage_close
(
lc
);
ortp_exit
();
linphone_core_set_state
(
lc
,
LinphoneGlobalOff
,
"Off"
);
#ifdef TUNNEL_ENABLED
...
...
@@ -5795,3 +5794,24 @@ void linphone_core_set_video_dscp(LinphoneCore *lc, int dscp){
int
linphone_core_get_video_dscp
(
const
LinphoneCore
*
lc
){
return
lp_config_get_int
(
lc
->
config
,
"rtp"
,
"video_dscp"
,
0x2e
);
}
/**
* Sets the database filename where chat messages will be stored.
* If the file does not exist, it will be created.
* @ingroup initializing
* @param lc the linphone core
* @param path filesystem path
**/
void
linphone_core_set_chat_database_path
(
LinphoneCore
*
lc
,
const
char
*
path
){
if
(
lc
->
chat_db_file
){
ms_free
(
lc
->
chat_db_file
);
lc
->
chat_db_file
=
NULL
;
}
if
(
path
)
{
lc
->
chat_db_file
=
ms_strdup
(
path
);
linphone_core_message_storage_init
(
lc
);
}
}
coreapi/linphonecore.h
View file @
ad711417
...
...
@@ -663,12 +663,17 @@ typedef enum _LinphoneChatMessageStates {
*/
typedef
void
(
*
LinphoneChatMessageStateChangeCb
)(
LinphoneChatMessage
*
msg
,
LinphoneChatMessageState
state
,
void
*
ud
);
void
linphone_core_set_chat_database_path
(
LinphoneCore
*
lc
,
const
char
*
path
);
LinphoneChatRoom
*
linphone_core_create_chat_room
(
LinphoneCore
*
lc
,
const
char
*
to
);
LinphoneChatRoom
*
linphone_core_get_chat_room
(
LinphoneCore
*
lc
,
const
LinphoneAddress
*
addr
);
void
linphone_chat_room_destroy
(
LinphoneChatRoom
*
cr
);
LinphoneChatMessage
*
linphone_chat_room_create_message
(
LinphoneChatRoom
*
cr
,
const
char
*
message
);
const
LinphoneAddress
*
linphone_chat_room_get_peer_address
(
LinphoneChatRoom
*
cr
);
void
linphone_chat_room_send_message
(
LinphoneChatRoom
*
cr
,
const
char
*
msg
);
void
linphone_chat_room_send_message2
(
LinphoneChatRoom
*
cr
,
LinphoneChatMessage
*
msg
,
LinphoneChatMessageStateChangeCb
status_cb
,
void
*
ud
);
MSList
*
linphone_chat_room_get_history
(
LinphoneChatRoom
*
cr
,
int
nb_message
);
void
linphone_chat_room_mark_as_read
(
LinphoneChatRoom
*
cr
);
void
linphone_chat_room_delete_history
(
LinphoneChatRoom
*
cr
);
LinphoneCore
*
linphone_chat_room_get_lc
(
LinphoneChatRoom
*
cr
);
void
linphone_chat_room_set_user_data
(
LinphoneChatRoom
*
cr
,
void
*
ud
);
void
*
linphone_chat_room_get_user_data
(
LinphoneChatRoom
*
cr
);
...
...
@@ -677,7 +682,8 @@ LinphoneChatMessageState linphone_chat_message_get_state(const LinphoneChatMessa
const
char
*
linphone_chat_message_state_to_string
(
const
LinphoneChatMessageState
state
);
LinphoneChatMessage
*
linphone_chat_message_clone
(
const
LinphoneChatMessage
*
message
);
void
linphone_chat_message_set_from
(
LinphoneChatMessage
*
message
,
const
LinphoneAddress
*
from
);
LinphoneAddress
*
linphone_chat_message_get_from
(
const
LinphoneChatMessage
*
message
);
const
LinphoneAddress
*
linphone_chat_message_get_from
(
const
LinphoneChatMessage
*
message
);
const
LinphoneAddress
*
linphone_chat_message_get_to
(
const
LinphoneChatMessage
*
message
);
const
char
*
linphone_chat_message_get_external_body_url
(
const
LinphoneChatMessage
*
message
);
void
linphone_chat_message_set_external_body_url
(
LinphoneChatMessage
*
message
,
const
char
*
url
);
const
char
*
linphone_chat_message_get_text
(
const
LinphoneChatMessage
*
message
);
...
...
@@ -686,6 +692,7 @@ void* linphone_chat_message_get_user_data(const LinphoneChatMessage* message);
void
linphone_chat_message_set_user_data
(
LinphoneChatMessage
*
message
,
void
*
);
LinphoneChatRoom
*
linphone_chat_message_get_chat_room
(
LinphoneChatMessage
*
msg
);
const
LinphoneAddress
*
linphone_chat_message_get_peer_address
(
LinphoneChatMessage
*
msg
);
LinphoneAddress
*
linphone_chat_message_get_local_address
(
const
LinphoneChatMessage
*
message
);
void
linphone_chat_message_add_custom_header
(
LinphoneChatMessage
*
message
,
const
char
*
header_name
,
const
char
*
header_value
);
const
char
*
linphone_chat_message_get_custom_header
(
LinphoneChatMessage
*
message
,
const
char
*
header_name
);
...
...
@@ -1418,9 +1425,7 @@ int linphone_core_get_audio_dscp(const LinphoneCore *lc);
void
linphone_core_set_video_dscp
(
LinphoneCore
*
lc
,
int
dscp
);
int
linphone_core_get_video_dscp
(
const
LinphoneCore
*
lc
);
MSList
*
linphone_chat_room_get_history
(
const
char
*
to
,
LinphoneChatRoom
*
cr
,
int
nb_message
);
void
linphone_core_set_messages_flag_read
(
LinphoneChatRoom
*
cr
,
const
char
*
from
,
int
read
);
void
linphone_core_delete_history
(
LinphoneCore
*
lc
,
const
char
*
from
);
#ifdef __cplusplus
}
...
...
coreapi/message_storage.c
View file @
ad711417
...
...
@@ -38,44 +38,22 @@ static inline char *my_ctime_r(const time_t *t, char *buf){
static
const
char
*
days
[]
=
{
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
};
static
const
char
*
months
[]
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
#define CONFIG_FILE ".linphone-history.db"
char
*
linphone_message_storage_get_config_file
(
const
char
*
filename
){
const
int
path_max
=
1024
;
char
*
config_file
=
(
char
*
)
malloc
(
path_max
*
sizeof
(
char
));
if
(
filename
==
NULL
)
filename
=
CONFIG_FILE
;
/*try accessing a local file first if exists*/
if
(
access
(
CONFIG_FILE
,
F_OK
)
==
0
){
snprintf
(
config_file
,
path_max
,
"%s"
,
filename
);
}
else
{
#ifdef WIN32
const
char
*
appdata
=
getenv
(
"APPDATA"
);
if
(
appdata
){
snprintf
(
config_file
,
path_max
,
"%s
\\
%s"
,
appdata
,
LINPHONE_CONFIG_DIR
);
CreateDirectory
(
config_file
,
NULL
);
snprintf
(
config_file
,
path_max
,
"%s
\\
%s
\\
%s"
,
appdata
,
LINPHONE_CONFIG_DIR
,
filename
);
}
#else
const
char
*
home
=
getenv
(
"HOME"
);
if
(
home
==
NULL
)
home
=
"."
;
snprintf
(
config_file
,
path_max
,
"%s/%s"
,
home
,
filename
);
#endif
}
return
config_file
;
}
void
create_chat_message
(
char
**
argv
,
void
*
data
){
static
void
create_chat_message
(
char
**
argv
,
void
*
data
){
LinphoneChatRoom
*
cr
=
(
LinphoneChatRoom
*
)
data
;
LinphoneChatMessage
*
new_message
=
linphone_chat_room_create_message
(
cr
,
argv
[
4
]);
LinphoneAddress
*
from
;
struct
tm
ret
=
{
0
};
char
tmp1
[
80
]
=
{
0
};
char
tmp2
[
80
]
=
{
0
};
if
(
atoi
(
argv
[
3
])
==
INCOMING
){
linphone_chat_message_set_from
(
new_message
,
linphone_address_new
(
argv
[
2
])
)
;
if
(
atoi
(
argv
[
3
])
==
LinphoneChatMessageIncoming
){
from
=
linphone_address_new
(
argv
[
2
]);
}
else
{
linphone_chat_message_set_from
(
new_message
,
linphone_address_new
(
argv
[
1
])
)
;
from
=
linphone_address_new
(
argv
[
1
]);
}
linphone_chat_message_set_from
(
new_message
,
from
);
linphone_address_destroy
(
from
);
if
(
argv
[
5
]
!=
NULL
){
int
i
,
j
;
...
...
@@ -91,7 +69,7 @@ void create_chat_message(char **argv, void *data){
}
new_message
->
time
=
argv
[
5
]
!=
NULL
?
mktime
(
&
ret
)
:
time
(
NULL
);
new_message
->
state
=
atoi
(
argv
[
7
]);
cr
->
messages_hist
=
ms_list_prepend
(
cr
->
messages_hist
,
(
void
*
)
new_message
);
cr
->
messages_hist
=
ms_list_prepend
(
cr
->
messages_hist
,
new_message
);
}
static
int
callback
(
void
*
data
,
int
argc
,
char
**
argv
,
char
**
colName
){
...
...
@@ -99,58 +77,84 @@ static int callback(void *data, int argc, char **argv, char **colName){
return
0
;
}
void
linphone_sql_request_message
(
sqlite3
*
db
,
const
char
*
stmt
,
void
*
data
){
void
linphone_sql_request_message
(
sqlite3
*
db
,
const
char
*
stmt
,
LinphoneChatRoom
*
cr
){
char
*
errmsg
;
int
ret
;
ret
=
sqlite3_exec
(
db
,
stmt
,
callback
,
data
,
&
errmsg
);
ret
=
sqlite3_exec
(
db
,
stmt
,
callback
,
cr
,
&
errmsg
);
if
(
ret
!=
SQLITE_OK
)
{
printf
(
"Error in creation: %s.
\n
"
,
errmsg
);
}
}
void
linphone_sql_request
(
sqlite3
*
db
,
const
char
*
stmt
){
char
*
errmsg
;
char
*
errmsg
=
NULL
;
int
ret
;
ret
=
sqlite3_exec
(
db
,
stmt
,
0
,
0
,
&
errmsg
);
if
(
ret
!=
SQLITE_OK
)
{
printf
(
"Error in creation: %s.
\n
"
,
errmsg
);
ms_error
(
"linphone_sql_request: error sqlite3_exec(): %s.
\n
"
,
errmsg
);
sqlite3_free
(
errmsg
);
}
}
void
linphone_core_set_history_message
(
LinphoneChatRoom
*
cr
,
const
char
*
local_contact
,
const
char
*
remote_contact
,
int
direction
,
const
char
*
message
,
const
char
*
date
,
int
read
,
int
state
){
LinphoneCore
*
lc
=
linphone_chat_room_get_lc
(
cr
);
char
*
buf
=
sqlite3_mprintf
(
"insert into history values(NULL,%Q,%Q,%i,%Q,%Q,%i,%i);"
,
local_contact
,
remote_contact
,
direction
,
message
,
date
,
read
,
state
);
linphone_sql_request
(
lc
->
db
,
buf
);
void
linphone_chat_message_store
(
LinphoneChatMessage
*
msg
){
LinphoneCore
*
lc
=
linphone_chat_room_get_lc
(
msg
->
chat_room
);
if
(
lc
->
db
){
const
char
*
peer
=
msg
->
chat_room
->
peer
;
char
*
local_contact
=
linphone_address_as_string_uri_only
(
linphone_chat_message_get_local_address
(
msg
));
char
datebuf
[
26
];
char
*
buf
=
sqlite3_mprintf
(
"insert into history values(NULL,%Q,%Q,%i,%Q,%Q,%i,%i);"
,
local_contact
,
peer
,
msg
->
dir
,
msg
->
message
,
my_ctime_r
(
&
msg
->
time
,
datebuf
),
msg
->
is_read
,
msg
->
state
);
linphone_sql_request
(
lc
->
db
,
buf
);
sqlite3_free
(
buf
);
ms_free
(
local_contact
);
}
}
void
linphone_core_set_message_state
(
LinphoneChatRoom
*
cr
,
const
char
*
message
,
int
state
,
time_t
date
){
LinphoneCore
*
lc
=
linphone_chat_room_get_lc
(
cr
);
char
time_str
[
26
];
char
*
buf
=
sqlite3_mprintf
(
"update history set status=%i where message = %Q and time = %Q;"
,
state
,
message
,
my_ctime_r
(
&
date
,
time_str
));
linphone_sql_request
(
lc
->
db
,
buf
);
void
linphone_chat_message_store_state
(
LinphoneChatMessage
*
msg
){
LinphoneCore
*
lc
=
msg
->
chat_room
->
lc
;
if
(
lc
->
db
){
char
time_str
[
26
];
char
*
buf
=
sqlite3_mprintf
(
"update history set status=%i where message = %Q and time = %Q;"
,
msg
->
state
,
msg
->
message
,
my_ctime_r
(
&
msg
->
time
,
time_str
));
linphone_sql_request
(
lc
->
db
,
buf
);
sqlite3_free
(
buf
);
}
}
void
linphone_c
ore_set_messages_flag
_read
(
LinphoneChatRoom
*
cr
,
const
char
*
from
,
int
read
){
void
linphone_c
hat_room_mark_as
_read
(
LinphoneChatRoom
*
cr
){
LinphoneCore
*
lc
=
linphone_chat_room_get_lc
(
cr
);
int
read
=
1
;
if
(
lc
->
db
==
NULL
)
return
;
char
*
buf
=
sqlite3_mprintf
(
"update history set read=%i where remoteContact = %Q;"
,
read
,
from
);
read
,
cr
->
peer
);
linphone_sql_request
(
lc
->
db
,
buf
);
sqlite3_free
(
buf
);
}
void
linphone_core_delete_history
(
LinphoneCore
*
lc
,
const
char
*
from
){
char
*
buf
=
sqlite3_mprintf
(
"delete from history where remoteContact = %Q;"
,
from
);
void
linphone_chat_room_delete_history
(
LinphoneChatRoom
*
cr
){
LinphoneCore
*
lc
=
cr
->
lc
;
if
(
lc
->
db
==
NULL
)
return
;
char
*
buf
=
sqlite3_mprintf
(
"delete from history where remoteContact = %Q;"
,
cr
->
peer
);
linphone_sql_request
(
lc
->
db
,
buf
);
sqlite3_free
(
buf
);
}
MSList
*
linphone_chat_room_get_history
(
const
char
*
to
,
LinphoneChatRoom
*
cr
,
int
nb_message
){
MSList
*
linphone_chat_room_get_history
(
LinphoneChatRoom
*
cr
,
int
nb_message
){
LinphoneCore
*
lc
=
linphone_chat_room_get_lc
(
cr
);
MSList
*
ret
;
if
(
lc
->
db
==
NULL
)
return
NULL
;
cr
->
messages_hist
=
NULL
;
char
*
buf
=
sqlite3_mprintf
(
"select * from history where remoteContact = %Q order by id DESC limit %i ;"
,
to
,
nb_message
);
linphone_sql_request_message
(
lc
->
db
,
buf
,(
void
*
)
cr
);
return
cr
->
messages_hist
;
char
*
buf
=
sqlite3_mprintf
(
"select * from history where remoteContact = %Q order by id DESC limit %i ;"
,
cr
->
peer
,
nb_message
);
linphone_sql_request_message
(
lc
->
db
,
buf
,
cr
);
sqlite3_free
(
buf
);
ret
=
cr
->
messages_hist
;
cr
->
messages_hist
=
NULL
;
return
ret
;
}
void
linphone_close_storage
(
sqlite3
*
db
){
...
...
@@ -167,36 +171,49 @@ void linphone_create_table(sqlite3* db){
}
}
sqlite3
*
linphone_message_storage_init
(){
void
linphone_
core_
message_storage_init
(
LinphoneCore
*
lc
){
int
ret
;
char
*
errmsg
;
char
*
errmsg
=
NULL
;
sqlite3
*
db
;
char
*
filename
;
filename
=
linphone_message_storage_get_config_file
(
NULL
);
ret
=
sqlite3_open
(
filename
,
&
db
);
ret
=
sqlite3_open
(
lc
->
chat_db_file
,
&
db
);
if
(
ret
!=
SQLITE_OK
)
{
printf
(
"Error in the opening: %s.
\n
"
,
errmsg
);
sqlite3_close
(
db
);
sqlite3_free
(
errmsg
);
}
linphone_create_table
(
db
);
return
db
;
lc
->
db
=
db
;
}
void
linphone_core_message_storage_close
(
LinphoneCore
*
lc
){
if
(
lc
->
db
){
sqlite3_close
(
lc
->
db
);
lc
->
db
=
NULL
;
}
}
#else
void
linphone_core_set_history_message
(
LinphoneChatRoom
*
cr
,
const
char
*
local_contact
,
const
char
*
remote_contact
,
int
direction
,
const
char
*
message
,
const
char
*
date
,
int
read
,
int
state
){
void
linphone_chat_message_store
(
LinphoneChatMessage
*
cr
){
}
void
linphone_c
ore_se
t_message_state
(
LinphoneChat
Room
*
cr
,
const
char
*
message
,
int
state
,
time_t
date
){
void
linphone_c
ha
t_message_
store_
state
(
LinphoneChat
Message
*
cr
){
}
void
linphone_c
ore_set_messages_flag
_read
(
LinphoneChatRoom
*
cr
,
const
char
*
from
,
int
read
){
void
linphone_c
hat_room_mark_as
_read
(
LinphoneChatRoom
*
cr
){
}
MSList
*
linphone_chat_room_get_history
(
const
char
*
to
,
LinphoneChatRoom
*
cr
,
int
nb_message
){
MSList
*
linphone_chat_room_get_history
(
LinphoneChatRoom
*
cr
,
int
nb_message
){
return
NULL
;
}
void
linphone_core_delete_history
(
LinphoneCore
*
lc
,
const
char
*
from
){
void
linphone_chat_room_delete_history
(
LinphoneChatRoom
*
cr
){
}
void
linphone_core_message_storage_init
(
LinphoneCore
*
lc
){
}
#endif
\ No newline at end of file
void
linphone_core_message_storage_close
(
LinphoneCore
*
lc
){
}
#endif
coreapi/private.h
View file @
ad711417
...
...
@@ -119,17 +119,25 @@ typedef struct _CallCallbackObj
static
const
int
linphone_call_magic
=
0x3343
;
typedef
enum
_LinphoneChatMessageDir
{
LinphoneChatMessageIncoming
,
LinphoneChatMessageOutgoing
}
LinphoneChatMessageDir
;
struct
_LinphoneChatMessage
{
char
*
message
;
LinphoneChatRoom
*
chat_room
;
LinphoneChatMessageDir
dir
;
char
*
message
;
LinphoneChatMessageStateChangeCb
cb
;
void
*
cb_ud
;
void
*
message_userdata
;
char
*
external_body_url
;
LinphoneAddress
*
from
;
LinphoneAddress
*
from
;
LinphoneAddress
*
to
;
time_t
time
;
SalCustomHeader
*
custom_headers
;
LinphoneChatMessageState
state
;
bool_t
is_read
;
};
typedef
struct
StunCandidate
{
...
...
@@ -616,6 +624,7 @@ struct _LinphoneCore
LinphoneTunnel
*
tunnel
;
char
*
device_id
;
MSList
*
last_recv_msg_ids
;
char
*
chat_db_file
;
#ifdef MSG_STORAGE_ENABLED
sqlite3
*
db
;
#endif
...
...
@@ -700,19 +709,13 @@ void linphone_call_params_uninit(LinphoneCallParams *params);
int
linphone_upnp_init
(
LinphoneCore
*
lc
);
void
linphone_upnp_destroy
(
LinphoneCore
*
lc
);
#define OUTGOING 0
#define INCOMING 1
#define NOT_READ 0
#define READ 1
#ifdef MSG_STORAGE_ENABLED
sqlite3
*
linphone_message_storage_init
();
#endif
void
linphone_c
ore_set_history
_message
(
LinphoneChat
Room
*
cr
,
const
char
*
local_contact
,
const
char
*
remote_contact
,
int
direction
,
const
char
*
message
,
const
char
*
date
,
int
read
,
int
state
);
void
linphone_core_
set_
message_st
ate
(
LinphoneChatRoom
*
cr
,
const
char
*
message
,
int
state
,
time_t
date
);
void
linphone_c
hat
_message
_store
(
LinphoneChat
Message
*
msg
);
void
linphone_chat_message_store_state
(
LinphoneChatMessage
*
msg
);
void
linphone_core_message_st
orage_init
(
LinphoneCore
*
lc
);
void
linphone_core_message_storage_close
(
LinphoneCore
*
lc
);