mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-22 13:48:09 +00:00
Add header to Content and Multipart
This commit is contained in:
parent
c300e10f14
commit
7eb344cabd
4 changed files with 54 additions and 3 deletions
|
|
@ -90,6 +90,18 @@ Content ContentManager::contentListToMultipart (const list<Content> &contents) {
|
|||
(void *)body.c_str(), body.length(), nullptr, nullptr
|
||||
);
|
||||
belle_sip_body_handler_add_header(BELLE_SIP_BODY_HANDLER(mbh), cContentType);
|
||||
|
||||
const list<pair<string,string>> 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);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#define _L_CONTENT_P_H_
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include "content-type.h"
|
||||
#include "content.h"
|
||||
|
|
@ -35,6 +36,7 @@ private:
|
|||
std::vector<char> body;
|
||||
ContentType contentType;
|
||||
std::string contentDisposition;
|
||||
std::list<std::pair<std::string,std::string>> headers;
|
||||
|
||||
L_DECLARE_PUBLIC(Content);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
#include "linphone/core.h"
|
||||
#include "linphone/utils/utils.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#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<pair<string,string>> &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<pair<string,string>>::const_iterator Content::findHeader (const string &headerName) {
|
||||
L_D();
|
||||
return find_if(d->headers.cbegin(), d->headers.cend(), [&headerName](const pair<string,string> &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());
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#define _L_CONTENT_H_
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#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<std::pair<std::string,std::string>> &getHeaders () const;
|
||||
void removeHeader (const std::string &headerName);
|
||||
std::list<std::pair<std::string,std::string>>::const_iterator findHeader (const std::string &headerName);
|
||||
|
||||
// TODO: Remove me later.
|
||||
virtual LinphoneContent *toLinphoneContent () const;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue