diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 27c42b3e2..fe9c45996 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -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
diff --git a/src/content/content.cpp b/src/content/content.cpp
index b3fd66d4e..021032f09 100644
--- a/src/content/content.cpp
+++ b/src/content/content.cpp
@@ -16,11 +16,8 @@
* along with this program. If not, see .
*/
-// 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 ClonableObjectPrivate {
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 body;
+ ContentType contentType;
};
// -----------------------------------------------------------------------------
-Content::Content () : Object(*new ContentPrivate) {}
+Content::Content () : ClonableObject(*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;
-}
-
-void Content::setType (const string &type) {
+Content::Content (const Content &src) : ClonableObject(*new ContentPrivate) {
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));
+ d->body = move(src.getPrivate()->body);
+ d->contentType = move(src.getPrivate()->contentType);
}
-const void *Content::getBuffer () const {
- L_D(const Content);
- return sal_body_handler_get_data(d->bodyHandler);
-}
-
-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();
+ }
+
+ return *this;
+}
+
+Content &Content::operator= (Content &&src) {
+ L_D(Content);
+ if (this != &src) {
+ d->body = move(src.getPrivate()->body);
+ d->contentType = move(src.getPrivate()->contentType);
+ }
+
+ return *this;
+}
+
+const ContentType &Content::getContentType () const {
+ L_D(const Content);
+ return d->contentType;
+}
+
+void Content::setContentType (const ContentType &contentType) {
+ L_D(Content);
+ d->contentType = contentType;
+}
+
+const std::vector &Content::getBody () const {
+ L_D(const Content);
+ return d->body;
+}
+
+void Content::setBody (const std::vector &body) {
+ L_D(Content);
+ d->body = body;
+}
+
+void Content::setBody (const std::string &body) {
+ L_D(Content);
+ d->body = vector(body.cbegin(), body.cend());
+}
+
+void Content::setBody (const void *buffer, size_t size) {
+ L_D(Content);
+ const char *start = static_cast(buffer);
+ d->body = vector(start, start + size);
}
size_t Content::getSize () const {
L_D(const Content);
- return sal_body_handler_get_size(d->bodyHandler);
-}
-
-void Content::setSize (size_t size) {
- 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;
-}
-
-void Content::setEncoding (const string &encoding) {
- L_D(Content);
- sal_body_handler_set_encoding(d->bodyHandler, L_STRING_TO_C(encoding));
-}
-
-const string &Content::getName () const {
- L_D(const Content);
- return d->name;
-}
-
-void Content::setName (const string &name) {
- L_D(Content);
- d->name = name;
-}
-
-bool Content::isMultipart () const {
- L_D(const Content);
- return sal_body_handler_is_multipart(d->bodyHandler);
-}
-
-shared_ptr 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);
-}
-
-shared_ptr 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);
-}
-
-const string &Content::getCustomHeaderValue (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;
-}
-
-const string &Content::getKey () 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
diff --git a/src/content/content.h b/src/content/content.h
index 89f4b16e8..1a60e7fec 100644
--- a/src/content/content.h
+++ b/src/content/content.h
@@ -19,54 +19,38 @@
#ifndef _CONTENT_H_
#define _CONTENT_H_
-#include
#include
+#include
-#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);
- const std::string &getSubType () const;
- void setSubType (const std::string &subType);
+ Content &operator= (const Content &src);
+ Content &operator= (Content &&src);
- const void *getBuffer () const;
- void setBuffer (const void *buffer, size_t size);
+ const ContentType &getContentType () const;
+ void setContentType (const ContentType &contentType);
+ const std::vector &getBody () const;
+ void setBody (const std::vector &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 getPart (int index) const;
- std::shared_ptr 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