diff --git a/src/content/content.cpp b/src/content/content.cpp
index 2003b1613..b3fd66d4e 100644
--- a/src/content/content.cpp
+++ b/src/content/content.cpp
@@ -16,22 +16,162 @@
* 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.h"
// =============================================================================
+using namespace std;
+
LINPHONE_BEGIN_NAMESPACE
class ContentPrivate : public ObjectPrivate {
-private:
+public:
+ struct Cache {
+ string type;
+ string subType;
+ string customHeaderValue;
+ string encoding;
+ };
- L_DECLARE_PUBLIC(Content);
+ SalBodyHandler *bodyHandler = nullptr;
+ void *cryptoContext = nullptr;
+ string name;
+ string key;
+
+ mutable Cache cache;
};
// -----------------------------------------------------------------------------
-Content::Content (ContentPrivate &p) : Object(p) {}
+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;
+}
+
+void Content::setType (const string &type) {
+ L_D(Content);
+ sal_body_handler_set_type(d->bodyHandler, L_STRING_TO_C(type));
+}
+
+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) {
+ 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);
+}
+
+void Content::setBuffer (const void *buffer, size_t size) {
+ 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));
+}
+
+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;
+}
LINPHONE_END_NAMESPACE
diff --git a/src/content/content.h b/src/content/content.h
index fa59de1e7..89f4b16e8 100644
--- a/src/content/content.h
+++ b/src/content/content.h
@@ -19,6 +19,9 @@
#ifndef _CONTENT_H_
#define _CONTENT_H_
+#include
+#include
+
#include "object/object.h"
// =============================================================================
@@ -27,14 +30,40 @@ LINPHONE_BEGIN_NAMESPACE
class ContentPrivate;
-class LINPHONE_PUBLIC Content : public Object {
+class Content : public Object {
friend class Core;
public:
- // Nothing for the moment.
+ const std::string &getType () const;
+ void setType (const std::string &type);
+
+ const std::string &getSubType () const;
+ void setSubType (const std::string &subType);
+
+ const void *getBuffer () const;
+ void setBuffer (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 (ContentPrivate &p);
+ Content ();
L_DECLARE_PRIVATE(Content);
L_DISABLE_COPY(Content);