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
4d85643a
Commit
4d85643a
authored
Sep 12, 2017
by
Ronan
Browse files
feat(core): add better content class
parent
44152b9f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
144 deletions
+57
-144
src/CMakeLists.txt
src/CMakeLists.txt
+0
-2
src/content/content.cpp
src/content/content.cpp
+42
-111
src/content/content.h
src/content/content.h
+15
-31
No files found.
src/CMakeLists.txt
View file @
4d85643a
...
...
@@ -69,7 +69,6 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
conference/session/port-config.h
content/content-type.h
content/content.h
content/content.h
core/core.h
db/abstract/abstract-db-p.h
db/abstract/abstract-db.h
...
...
@@ -127,7 +126,6 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
conference/session/media-session.cpp
content/content-type.cpp
content/content.cpp
content/content.cpp
core/core.cpp
db/abstract/abstract-db.cpp
db/events-db.cpp
...
...
src/content/content.cpp
View file @
4d85643a
...
...
@@ -16,11 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// From coreapi.
#include "private.h"
#include "c-wrapper/c-tools.h"
#include "object/object-p.h"
#include "content-type.h"
#include "object/clonable-object-p.h"
#include "content.h"
...
...
@@ -30,148 +27,82 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
class
ContentPrivate
:
public
ObjectPrivate
{
class
ContentPrivate
:
public
Clonable
ObjectPrivate
{
public:
struct
Cache
{
string
type
;
string
subType
;
string
customHeaderValue
;
string
encoding
;
};
SalBodyHandler
*
bodyHandler
=
nullptr
;
void
*
cryptoContext
=
nullptr
;
string
name
;
string
key
;
mutable
Cache
cache
;
vector
<
char
>
body
;
ContentType
contentType
;
};
// -----------------------------------------------------------------------------
Content
::
Content
()
:
Object
(
*
new
ContentPrivate
)
{}
const
string
&
Content
::
getType
()
const
{
L_D
(
const
Content
);
d
->
cache
.
type
=
sal_body_handler_get_subtype
(
d
->
bodyHandler
);
return
d
->
cache
.
type
;
}
Content
::
Content
()
:
ClonableObject
(
*
new
ContentPrivate
)
{}
void
Content
::
setType
(
const
string
&
typ
e
)
{
Content
::
Content
(
const
Content
&
src
)
:
ClonableObject
(
*
new
ContentPrivat
e
)
{
L_D
(
Content
);
sal_body_handler_set_type
(
d
->
bodyHandler
,
L_STRING_TO_C
(
type
));
d
->
body
=
src
.
getBody
();
d
->
contentType
=
src
.
getContentType
();
}
const
string
&
Content
::
getSubType
()
const
{
L_D
(
const
Content
);
d
->
cache
.
subType
=
sal_body_handler_get_subtype
(
d
->
bodyHandler
);
return
d
->
cache
.
subType
;
}
void
Content
::
setSubType
(
const
string
&
subType
)
{
Content
::
Content
(
Content
&&
src
)
{
L_D
(
Content
);
sal_body_handler_set_subtype
(
d
->
bodyHandler
,
L_STRING_TO_C
(
subType
));
}
const
void
*
Content
::
getBuffer
()
const
{
L_D
(
const
Content
);
return
sal_body_handler_get_data
(
d
->
bodyHandler
);
d
->
body
=
move
(
src
.
getPrivate
()
->
body
);
d
->
contentType
=
move
(
src
.
getPrivate
()
->
contentType
);
}
void
Content
::
setBuffer
(
const
void
*
buffer
,
size_t
size
)
{
Content
&
Content
::
operator
=
(
const
Content
&
src
)
{
L_D
(
Content
);
sal_body_handler_set_size
(
d
->
bodyHandler
,
size
);
void
*
data
=
belle_sip_malloc
(
size
);
sal_body_handler_set_data
(
d
->
bodyHandler
,
memcpy
(
data
,
buffer
,
size
)
);
}
if
(
this
!=
&
src
)
{
d
->
body
=
src
.
getBody
(
);
d
->
contentType
=
src
.
getContentType
(
);
}
size_t
Content
::
getSize
()
const
{
L_D
(
const
Content
);
return
sal_body_handler_get_size
(
d
->
bodyHandler
);
return
*
this
;
}
void
Content
::
setSize
(
size_t
size
)
{
Content
&
Content
::
operator
=
(
Content
&&
src
)
{
L_D
(
Content
);
sal_body_handler_set_data
(
d
->
bodyHandler
,
nullptr
);
sal_body_handler_set_size
(
d
->
bodyHandler
,
size
);
}
const
string
&
Content
::
getEncoding
()
const
{
L_D
(
const
Content
);
d
->
cache
.
encoding
=
sal_body_handler_get_encoding
(
d
->
bodyHandler
);
return
d
->
cache
.
encoding
;
}
if
(
this
!=
&
src
)
{
d
->
body
=
move
(
src
.
getPrivate
()
->
body
);
d
->
contentType
=
move
(
src
.
getPrivate
()
->
contentType
);
}
void
Content
::
setEncoding
(
const
string
&
encoding
)
{
L_D
(
Content
);
sal_body_handler_set_encoding
(
d
->
bodyHandler
,
L_STRING_TO_C
(
encoding
));
return
*
this
;
}
const
string
&
Content
::
get
Nam
e
()
const
{
const
ContentType
&
Content
::
get
ContentTyp
e
()
const
{
L_D
(
const
Content
);
return
d
->
nam
e
;
return
d
->
contentTyp
e
;
}
void
Content
::
set
Name
(
const
string
&
nam
e
)
{
void
Content
::
set
ContentType
(
const
ContentType
&
contentTyp
e
)
{
L_D
(
Content
);
d
->
name
=
nam
e
;
d
->
contentType
=
contentTyp
e
;
}
bool
Content
::
isMultipart
()
const
{
const
std
::
vector
<
char
>
&
Content
::
getBody
()
const
{
L_D
(
const
Content
);
return
sal_body_handler_is_multipart
(
d
->
bodyHandler
)
;
return
d
->
body
;
}
shared_ptr
<
Content
>
Content
::
getPart
(
int
index
)
const
{
L_D
(
const
Content
);
if
(
!
isMultipart
())
return
nullptr
;
SalBodyHandler
*
bodyHandler
=
sal_body_handler_get_part
(
d
->
bodyHandler
,
index
);
if
(
!
bodyHandler
)
return
nullptr
;
Content
*
content
=
new
Content
();
sal_body_handler_ref
(
bodyHandler
);
content
->
getPrivate
()
->
bodyHandler
=
bodyHandler
;
return
shared_ptr
<
Content
>
(
content
);
void
Content
::
setBody
(
const
std
::
vector
<
char
>
&
body
)
{
L_D
(
Content
);
d
->
body
=
body
;
}
shared_ptr
<
Content
>
Content
::
findPartByHeader
(
const
string
&
headerName
,
const
string
&
headerValue
)
const
{
L_D
(
const
Content
);
if
(
!
isMultipart
())
return
nullptr
;
SalBodyHandler
*
bodyHandler
=
sal_body_handler_find_part_by_header
(
d
->
bodyHandler
,
L_STRING_TO_C
(
headerName
),
L_STRING_TO_C
(
headerValue
)
);
if
(
!
bodyHandler
)
return
nullptr
;
Content
*
content
=
new
Content
();
sal_body_handler_ref
(
bodyHandler
);
content
->
getPrivate
()
->
bodyHandler
=
bodyHandler
;
return
shared_ptr
<
Content
>
(
content
);
void
Content
::
setBody
(
const
std
::
string
&
body
)
{
L_D
(
Content
);
d
->
body
=
vector
<
char
>
(
body
.
cbegin
(),
body
.
cend
());
}
const
string
&
Content
::
g
et
CustomHeaderValue
(
const
string
&
headerName
)
const
{
L_D
(
const
Content
);
d
->
cache
.
customHeaderValue
=
sal_body_handler_get_header
(
d
->
bodyHandler
,
L_STRING_TO_C
(
headerName
)
);
return
d
->
cache
.
customHeaderValue
;
void
Content
::
s
et
Body
(
const
void
*
buffer
,
size_t
size
)
{
L_D
(
Content
);
const
char
*
start
=
static_cast
<
const
char
*>
(
buffer
);
d
->
body
=
vector
<
char
>
(
start
,
start
+
size
)
;
}
const
string
&
Content
::
get
Key
()
const
{
size_t
Content
::
get
Size
()
const
{
L_D
(
const
Content
);
return
d
->
key
;
}
void
Content
::
setKey
(
const
string
&
key
)
{
L_D
(
Content
);
d
->
key
=
key
;
return
d
->
body
.
size
();
}
LINPHONE_END_NAMESPACE
src/content/content.h
View file @
4d85643a
...
...
@@ -19,54 +19,38 @@
#ifndef _CONTENT_H_
#define _CONTENT_H_
#include <memory>
#include <string>
#include <vector>
#include "object/object.h"
#include "object/
clonable-
object.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class
ContentPrivate
;
class
ContentType
;
class
Content
:
public
Object
{
friend
class
Core
;
class
LINPHONE_PUBLIC
Content
:
public
ClonableObject
{
public:
const
std
::
string
&
getType
()
const
;
void
setType
(
const
std
::
string
&
type
);
Content
();
Content
(
const
Content
&
src
);
Content
(
Content
&&
src
);
c
on
st
std
::
string
&
getSubType
()
const
;
void
setSubType
(
c
on
st
std
::
string
&
subType
);
C
on
tent
&
operator
=
(
const
Content
&
src
)
;
Content
&
operator
=
(
C
on
tent
&&
src
);
const
void
*
getBuffer
()
const
;
void
set
Buffer
(
const
void
*
buffer
,
size_t
siz
e
);
const
ContentType
&
getContentType
()
const
;
void
set
ContentType
(
const
ContentType
&
contentTyp
e
);
const
std
::
vector
<
char
>
&
getBody
()
const
;
void
setBody
(
const
std
::
vector
<
char
>
&
body
);
void
setBody
(
const
std
::
string
&
body
);
void
setBody
(
const
void
*
buffer
,
size_t
size
);
size_t
getSize
()
const
;
void
setSize
(
size_t
size
);
const
std
::
string
&
getEncoding
()
const
;
void
setEncoding
(
const
std
::
string
&
encoding
);
const
std
::
string
&
getName
()
const
;
void
setName
(
const
std
::
string
&
name
);
bool
isMultipart
()
const
;
std
::
shared_ptr
<
Content
>
getPart
(
int
index
)
const
;
std
::
shared_ptr
<
Content
>
findPartByHeader
(
const
std
::
string
&
headerName
,
const
std
::
string
&
headerValue
)
const
;
const
std
::
string
&
getCustomHeaderValue
(
const
std
::
string
&
headerName
)
const
;
const
std
::
string
&
getKey
()
const
;
void
setKey
(
const
std
::
string
&
key
);
private:
Content
();
L_DECLARE_PRIVATE
(
Content
);
L_DISABLE_COPY
(
Content
);
};
LINPHONE_END_NAMESPACE
...
...
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