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
25c138a6
Commit
25c138a6
authored
Sep 22, 2017
by
Ronan
Browse files
feat(c-wrapper): getPrivate is more secure
parent
d1dc5af4
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/c-wrapper/internal/c-tools.h
View file @
25c138a6
...
...
@@ -48,16 +48,21 @@ struct CObjectInitializer {};
class
Wrapper
{
private:
template
<
typename
T
>
template
<
typename
CppType
>
struct
IsCppObject
{
enum
{
value
=
std
::
is_base_of
<
Object
,
CppType
>::
value
||
std
::
is_base_of
<
ClonableObject
,
CppType
>::
value
};
};
template
<
typename
CType
>
struct
WrappedObject
{
belle_sip_object_t
base
;
std
::
shared_ptr
<
T
>
cppPtr
;
std
::
shared_ptr
<
CType
>
cppPtr
;
};
template
<
typename
T
>
template
<
typename
CType
>
struct
WrappedClonableObject
{
belle_sip_object_t
base
;
T
*
cppPtr
;
CType
*
cppPtr
;
};
public:
...
...
@@ -65,14 +70,20 @@ public:
// Get private data of cpp Object.
// ---------------------------------------------------------------------------
template
<
typename
T
>
static
inline
decltype
(
std
::
declval
<
T
>
().
getPrivate
())
getPrivate
(
T
*
cppObject
)
{
template
<
typename
CppType
,
typename
=
typename
std
::
enable_if
<
IsCppObject
<
CppType
>
::
value
,
CppType
>::
type
>
static
inline
decltype
(
std
::
declval
<
CppType
>
().
getPrivate
())
getPrivate
(
CppType
*
cppObject
)
{
L_ASSERT
(
cppObject
);
return
cppObject
->
getPrivate
();
}
template
<
typename
T
>
static
inline
decltype
(
std
::
declval
<
T
>
().
getPrivate
())
getPrivate
(
const
std
::
shared_ptr
<
T
>
&
cppObject
)
{
template
<
typename
CppType
,
typename
=
typename
std
::
enable_if
<
IsCppObject
<
CppType
>
::
value
,
CppType
>::
type
>
static
inline
decltype
(
std
::
declval
<
CppType
>
().
getPrivate
())
getPrivate
(
const
std
::
shared_ptr
<
CppType
>
&
cppObject
)
{
L_ASSERT
(
cppObject
);
return
cppObject
->
getPrivate
();
}
...
...
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