From 7eb344cabdde6d82d47e4a17cb429ad6426632ca Mon Sep 17 00:00:00 2001 From: Matthieu Tanon Date: Mon, 19 Feb 2018 16:17:17 +0100 Subject: [PATCH] Add header to Content and Multipart --- src/content/content-manager.cpp | 12 +++++++++++ src/content/content-p.h | 2 ++ src/content/content.cpp | 37 ++++++++++++++++++++++++++++++--- src/content/content.h | 6 ++++++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/content/content-manager.cpp b/src/content/content-manager.cpp index fea82b66c..600f57a48 100644 --- a/src/content/content-manager.cpp +++ b/src/content/content-manager.cpp @@ -90,6 +90,18 @@ Content ContentManager::contentListToMultipart (const list &contents) { (void *)body.c_str(), body.length(), nullptr, nullptr ); belle_sip_body_handler_add_header(BELLE_SIP_BODY_HANDLER(mbh), cContentType); + + const list> headers = content.getHeaders(); + for (const auto &header : headers) { + belle_sip_header_t *additionalHeader = BELLE_SIP_HEADER( + belle_sip_header_create( + header.first.c_str(), + header.second.c_str() + ) + ); + belle_sip_body_handler_add_header(BELLE_SIP_BODY_HANDLER(mbh), additionalHeader); + } + belle_sip_multipart_body_handler_add_part(mpbh, BELLE_SIP_BODY_HANDLER(mbh)); } char *desc = belle_sip_object_to_string(mpbh); diff --git a/src/content/content-p.h b/src/content/content-p.h index e67dce5d6..65bdfc439 100644 --- a/src/content/content-p.h +++ b/src/content/content-p.h @@ -21,6 +21,7 @@ #define _L_CONTENT_P_H_ #include +#include #include "content-type.h" #include "content.h" @@ -35,6 +36,7 @@ private: std::vector body; ContentType contentType; std::string contentDisposition; + std::list> headers; L_DECLARE_PUBLIC(Content); }; diff --git a/src/content/content.cpp b/src/content/content.cpp index d1cc14628..bfbbe0511 100644 --- a/src/content/content.cpp +++ b/src/content/content.cpp @@ -21,6 +21,8 @@ #include "linphone/core.h" #include "linphone/utils/utils.h" +#include + #include "content-p.h" #include "content-type.h" @@ -38,7 +40,8 @@ Content::Content (const Content &other) : ClonableObject(*new ContentPrivate), A L_D(); d->body = other.getBody(); d->contentType = other.getContentType(); - d->contentDisposition = other.getContentDisposition(); + d->contentDisposition = other.getContentDisposition();; + d->headers = other.getHeaders(); } Content::Content (Content &&other) : ClonableObject(*new ContentPrivate), AppDataContainer(move(other)) { @@ -46,6 +49,7 @@ Content::Content (Content &&other) : ClonableObject(*new ContentPrivate), AppDat d->body = move(other.getPrivate()->body); d->contentType = move(other.getPrivate()->contentType); d->contentDisposition = move(other.getPrivate()->contentDisposition); + d->headers = other.getHeaders(); } Content::Content (ContentPrivate &p) : ClonableObject(p) {} @@ -66,8 +70,8 @@ Content &Content::operator= (const Content &other) { d->contentType = other.getContentType(); d->contentDisposition = other.getContentDisposition(); AppDataContainer::operator=(other); + d->headers = other.getHeaders(); } - return *this; } @@ -76,6 +80,7 @@ Content &Content::operator= (Content &&other) { d->body = move(other.getPrivate()->body); d->contentType = move(other.getPrivate()->contentType); d->contentDisposition = move(other.getPrivate()->contentDisposition); + d->headers = other.getHeaders(); AppDataContainer::operator=(move(other)); return *this; } @@ -84,7 +89,8 @@ bool Content::operator== (const Content &other) const { L_D(); return d->contentType == other.getContentType() && d->body == other.getBody() && - d->contentDisposition == other.getContentDisposition(); + d->contentDisposition == other.getContentDisposition() && + d->headers == other.getHeaders(); } const ContentType &Content::getContentType () const { @@ -172,6 +178,31 @@ bool Content::isFile () const { return false; } +void Content::addHeader (const string &headerName, const string &headerValue) { + L_D(); + removeHeader(headerName); + d->headers.push_back(make_pair(headerName, headerValue)); +} + +const list> &Content::getHeaders () const { + L_D(); + return d->headers; +} + +void Content::removeHeader (const string &headerName) { + L_D(); + auto it = findHeader(headerName); + if (it != d->headers.cend()) + d->headers.remove(*it); +} + +list>::const_iterator Content::findHeader (const string &headerName) { + L_D(); + return find_if(d->headers.cbegin(), d->headers.cend(), [&headerName](const pair &pair) { + return pair.first == headerName; + }); +} + LinphoneContent *Content::toLinphoneContent () const { LinphoneContent *content = linphone_core_create_content(nullptr); linphone_content_set_type(content, getContentType().getType().c_str()); diff --git a/src/content/content.h b/src/content/content.h index d639ffe15..582589f00 100644 --- a/src/content/content.h +++ b/src/content/content.h @@ -21,6 +21,7 @@ #define _L_CONTENT_H_ #include +#include #include "object/app-data-container.h" #include "object/clonable-object.h" @@ -71,6 +72,11 @@ public: virtual bool isFile () const; + void addHeader (const std::string &headerName, const std::string &headerValue); + const std::list> &getHeaders () const; + void removeHeader (const std::string &headerName); + std::list>::const_iterator findHeader (const std::string &headerName); + // TODO: Remove me later. virtual LinphoneContent *toLinphoneContent () const;