Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liblinphone
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
10
Issues
10
List
Board
Labels
Milestones
Merge Requests
21
Merge Requests
21
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
External Wiki
External Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
BC
public
liblinphone
Commits
2154c78f
Commit
2154c78f
authored
Mar 06, 2018
by
Ronan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(ChatMessage): avoid invalid read of destroyed strings, and construct C++ cache correctly!!!
parent
cf37868b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
22 deletions
+28
-22
c-chat-message.cpp
src/c-wrapper/api/c-chat-message.cpp
+25
-19
chat-message-p.h
src/chat/chat-message/chat-message-p.h
+3
-3
No files found.
src/c-wrapper/api/c-chat-message.cpp
View file @
2154c78f
...
...
@@ -23,14 +23,14 @@
#include "ortp/b64.h"
#include "c-wrapper/c-wrapper.h"
#include "address/address.h"
#include "content/content.h"
#include "content/content-type.h"
#include "c-wrapper/c-wrapper.h"
#include "chat/chat-message/chat-message-p.h"
#include "chat/chat-room/chat-room-p.h"
#include "chat/chat-room/real-time-text-chat-room-p.h"
#include "chat/notification/imdn.h"
#include "content/content-type.h"
#include "content/content.h"
// =============================================================================
...
...
@@ -45,13 +45,18 @@ L_DECLARE_C_OBJECT_IMPL_WITH_XTORS(ChatMessage,
LinphoneAddress
*
from
;
// cache for shared_ptr<Address>
LinphoneAddress
*
to
;
// cache for shared_ptr<Address>
LinphoneChatMessageStateChangedCb
message_state_changed_cb
;
void
*
message_state_changed_user_data
;
mutable
char
*
contentTypeCache
;
mutable
std
::
string
textContentBody
;
void
*
message_state_changed_user_data
;
struct
Cache
{
string
contentType
;
string
textContentBody
;
string
customHeaderValue
;
}
mutable
cache
;
)
static
void
_linphone_chat_message_constructor
(
LinphoneChatMessage
*
msg
)
{
msg
->
cbs
=
linphone_chat_message_cbs_new
();
new
(
&
msg
->
cache
)
LinphoneChatMessage
::
Cache
();
}
static
void
_linphone_chat_message_destructor
(
LinphoneChatMessage
*
msg
)
{
...
...
@@ -61,8 +66,8 @@ static void _linphone_chat_message_destructor (LinphoneChatMessage *msg) {
linphone_address_unref
(
msg
->
from
);
if
(
msg
->
to
)
linphone_address_unref
(
msg
->
to
);
if
(
msg
->
contentTypeCache
)
ms_free
(
msg
->
contentTypeCache
);
msg
->
cache
.
~
Cache
(
);
}
// =============================================================================
...
...
@@ -160,8 +165,11 @@ void linphone_chat_message_set_file_transfer_filepath(LinphoneChatMessage *msg,
L_GET_PRIVATE_FROM_C_OBJECT
(
msg
)
->
setFileTransferFilepath
(
L_C_TO_STRING
(
filepath
));
}
void
linphone_chat_message_add_custom_header
(
LinphoneChatMessage
*
msg
,
const
char
*
header_name
,
const
char
*
header_value
)
{
void
linphone_chat_message_add_custom_header
(
LinphoneChatMessage
*
msg
,
const
char
*
header_name
,
const
char
*
header_value
)
{
L_GET_PRIVATE_FROM_C_OBJECT
(
msg
)
->
addSalCustomHeader
(
L_C_TO_STRING
(
header_name
),
L_C_TO_STRING
(
header_value
));
}
...
...
@@ -170,7 +178,8 @@ void linphone_chat_message_remove_custom_header(LinphoneChatMessage *msg, const
}
const
char
*
linphone_chat_message_get_custom_header
(
LinphoneChatMessage
*
msg
,
const
char
*
header_name
)
{
return
L_STRING_TO_C
(
L_GET_PRIVATE_FROM_C_OBJECT
(
msg
)
->
getSalCustomHeaderValue
(
L_C_TO_STRING
(
header_name
)));
msg
->
cache
.
customHeaderValue
=
L_GET_PRIVATE_FROM_C_OBJECT
(
msg
)
->
getSalCustomHeaderValue
(
L_C_TO_STRING
(
header_name
));
return
L_STRING_TO_C
(
msg
->
cache
.
customHeaderValue
);
}
const
LinphoneErrorInfo
*
linphone_chat_message_get_error_info
(
const
LinphoneChatMessage
*
msg
)
{
...
...
@@ -229,8 +238,8 @@ const char *linphone_chat_message_get_text_content(const LinphoneChatMessage *ms
const
LinphonePrivate
::
Content
*
content
=
L_GET_PRIVATE_FROM_C_OBJECT
(
msg
)
->
getTextContent
();
if
(
content
->
isEmpty
())
return
nullptr
;
msg
->
textContentBody
=
content
->
getBodyAsString
();
return
L_STRING_TO_C
(
msg
->
textContentBody
);
msg
->
cache
.
textContentBody
=
content
->
getBodyAsString
();
return
L_STRING_TO_C
(
msg
->
cache
.
textContentBody
);
}
// =============================================================================
...
...
@@ -257,12 +266,9 @@ void * linphone_chat_message_get_message_state_changed_cb_user_data(LinphoneChat
// Structure has changed, hard to keep the behavior
// =============================================================================
const
char
*
linphone_chat_message_get_content_type
(
LinphoneChatMessage
*
msg
)
{
if
(
msg
->
contentTypeCache
)
{
ms_free
(
msg
->
contentTypeCache
);
}
msg
->
contentTypeCache
=
ms_strdup
(
L_STRING_TO_C
(
L_GET_PRIVATE_FROM_C_OBJECT
(
msg
)
->
getContentType
().
asString
()));
return
msg
->
contentTypeCache
;
const
char
*
linphone_chat_message_get_content_type
(
LinphoneChatMessage
*
msg
)
{
msg
->
cache
.
contentType
=
L_GET_PRIVATE_FROM_C_OBJECT
(
msg
)
->
getContentType
().
asString
();
return
L_STRING_TO_C
(
msg
->
cache
.
contentType
);
}
void
linphone_chat_message_set_content_type
(
LinphoneChatMessage
*
msg
,
const
char
*
content_type
)
{
...
...
src/chat/chat-message/chat-message-p.h
View file @
2154c78f
...
...
@@ -102,9 +102,9 @@ public:
SalCustomHeader
*
getSalCustomHeaders
()
const
;
void
setSalCustomHeaders
(
SalCustomHeader
*
headers
);
void
addSalCustomHeader
(
const
std
::
string
&
name
,
const
std
::
string
&
value
);
void
removeSalCustomHeader
(
const
std
::
string
&
name
);
std
::
string
getSalCustomHeaderValue
(
const
std
::
string
&
name
);
void
addSalCustomHeader
(
const
std
::
string
&
name
,
const
std
::
string
&
value
);
void
removeSalCustomHeader
(
const
std
::
string
&
name
);
std
::
string
getSalCustomHeaderValue
(
const
std
::
string
&
name
);
void
loadFileTransferUrlFromBodyToContent
();
...
...
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