Commit b687bf9d authored by Mickaël Turnel's avatar Mickaël Turnel Committed by Ghislain MARY
Browse files

Removed CPIM headers

parent 4ec0c6ed
......@@ -38,7 +38,6 @@ class Cpim::MessagePrivate : public ObjectPrivate {
public:
typedef list<shared_ptr<const Header> > PrivHeaderList;
shared_ptr<PrivHeaderList> cpimHeaders = make_shared<PrivHeaderList>(); // TODO: Remove this useless variable
shared_ptr<PrivHeaderList> messageHeaders = make_shared<PrivHeaderList>();
shared_ptr<PrivHeaderList> contentHeaders = make_shared<PrivHeaderList>();
string content;
......@@ -48,30 +47,6 @@ Cpim::Message::Message () : Object(*new MessagePrivate) {}
// -----------------------------------------------------------------------------
Cpim::Message::HeaderList Cpim::Message::getCpimHeaders () const {
L_D();
return d->cpimHeaders;
}
bool Cpim::Message::addCpimHeader (const Header &cpimHeader) {
L_D();
if (!cpimHeader.isValid())
return false;
d->cpimHeaders->push_back(Parser::getInstance()->cloneHeader(cpimHeader));
return true;
}
void Cpim::Message::removeCpimHeader (const Header &cpimHeader) {
L_D();
d->cpimHeaders->remove_if([&cpimHeader](const shared_ptr<const Header> &header) {
return cpimHeader.getName() == header->getName() && cpimHeader.getValue() == header->getValue();
});
}
// -----------------------------------------------------------------------------
Cpim::Message::HeaderList Cpim::Message::getMessageHeaders () const {
L_D();
return d->messageHeaders;
......@@ -80,9 +55,6 @@ Cpim::Message::HeaderList Cpim::Message::getMessageHeaders () const {
bool Cpim::Message::addMessageHeader (const Header &messageHeader) {
L_D();
if (!messageHeader.isValid())
return false;
d->messageHeaders->push_back(Parser::getInstance()->cloneHeader(messageHeader));
return true;
}
......@@ -104,9 +76,6 @@ Cpim::Message::HeaderList Cpim::Message::getContentHeaders () const {
bool Cpim::Message::addContentHeader (const Header &contentHeader) {
L_D();
if (!contentHeader.isValid())
return false;
d->contentHeaders->push_back(Parser::getInstance()->cloneHeader(contentHeader));
return true;
}
......@@ -133,29 +102,10 @@ bool Cpim::Message::setContent (const string &content) {
// -----------------------------------------------------------------------------
bool Cpim::Message::isValid () const {
L_D();
return find_if(d->cpimHeaders->cbegin(), d->cpimHeaders->cend(),
[](const shared_ptr<const Header> &header) {
return Utils::iequals(header->getName(), "content-type") && (ContentType(header->getValue()) == ContentType::Cpim);
}) != d->cpimHeaders->cend();
}
// -----------------------------------------------------------------------------
string Cpim::Message::asString () const {
L_D();
string output;
// TODO: Remove cpimHeaders
if (d->cpimHeaders->size() > 0) {
for (const auto &cpimHeader : *d->cpimHeaders)
output += cpimHeader->asString();
output += "\r\n";
}
// TODO Remove cpimHeaders
if (d->messageHeaders->size() > 0) {
for (const auto &messageHeader : *d->messageHeaders)
output += messageHeader->asString();
......
......@@ -36,12 +36,6 @@ namespace Cpim {
typedef std::shared_ptr<std::list<std::shared_ptr<const Cpim::Header> > > HeaderList;
// TODO: Remove these useless methods
HeaderList getCpimHeaders () const;
bool addCpimHeader (const Header &cpimHeader);
void removeCpimHeader (const Header &cpimHeader);
// TODO: Remove these useless methods
HeaderList getMessageHeaders () const;
bool addMessageHeader (const Header &messageHeader);
void removeMessageHeader (const Header &messageHeader);
......@@ -53,8 +47,6 @@ namespace Cpim {
std::string getContent () const;
bool setContent (const std::string &content);
bool isValid () const; // TODO: Remove this useless method
std::string asString () const;
static std::shared_ptr<const Message> createFromString (const std::string &str);
......
......@@ -38,11 +38,9 @@ LINPHONE_BEGIN_NAMESPACE
ChatMessageModifier::Result CpimChatMessageModifier::encode (const shared_ptr<ChatMessage> &message, int &errorCode) {
Cpim::Message cpimMessage;
Cpim::FromHeader cpimFromHeader;
cpimFromHeader.setValue(cpimAddressAsString(message->getFromAddress()));
Cpim::FromHeader cpimFromHeader(cpimAddressUri(message->getFromAddress()), cpimAddressDisplayName(message->getFromAddress()));
cpimMessage.addMessageHeader(cpimFromHeader);
Cpim::ToHeader cpimToHeader;
cpimToHeader.setValue(cpimAddressAsString(message->getToAddress()));
Cpim::ToHeader cpimToHeader(cpimAddressUri(message->getToAddress()), cpimAddressDisplayName(message->getToAddress()));
cpimMessage.addMessageHeader(cpimToHeader);
if (message->getPrivate()->getPositiveDeliveryNotificationRequired()
......@@ -50,8 +48,7 @@ ChatMessageModifier::Result CpimChatMessageModifier::encode (const shared_ptr<Ch
|| message->getPrivate()->getDisplayNotificationRequired()
) {
const string imdnNamespace = "imdn";
Cpim::NsHeader cpimNsHeader;
cpimNsHeader.setValue(imdnNamespace + " <urn:ietf:params:imdn>");
Cpim::NsHeader cpimNsHeader(imdnNamespace, "<urn:ietf:params:imdn>");
cpimMessage.addMessageHeader(cpimNsHeader);
char token[13];
......@@ -88,18 +85,12 @@ ChatMessageModifier::Result CpimChatMessageModifier::encode (const shared_ptr<Ch
const string contentBody = content->getBodyAsString();
if (content->getContentDisposition().isValid()) {
Cpim::GenericHeader contentDispositionHeader;
contentDispositionHeader.setName("Content-Disposition");
contentDispositionHeader.setValue(content->getContentDisposition().asString());
Cpim::GenericHeader contentDispositionHeader("Content-Disposition", content->getContentDisposition().asString());
cpimMessage.addContentHeader(contentDispositionHeader);
}
Cpim::GenericHeader contentTypeHeader;
contentTypeHeader.setName("Content-Type");
contentTypeHeader.setValue(content->getContentType().asString());
Cpim::GenericHeader contentTypeHeader("Content-Type", content->getContentType().asString());
cpimMessage.addContentHeader(contentTypeHeader);
Cpim::GenericHeader contentLengthHeader;
contentLengthHeader.setName("Content-Length");
contentLengthHeader.setValue(to_string(contentBody.size()));
Cpim::GenericHeader contentLengthHeader("Content-Length", to_string(contentBody.size()));
cpimMessage.addContentHeader(contentLengthHeader);
cpimMessage.setContent(contentBody);
......@@ -203,12 +194,12 @@ ChatMessageModifier::Result CpimChatMessageModifier::decode (const shared_ptr<Ch
return ChatMessageModifier::Result::Done;
}
string CpimChatMessageModifier::cpimAddressAsString (const Address &addr) const {
ostringstream os;
if (!addr.getDisplayName().empty())
os << addr.getDisplayName() << " ";
os << "<" << addr.asStringUriOnly() << ">";
return os.str();
string CpimChatMessageModifier::cpimAddressDisplayName (const Address &addr) const {
return addr.getDisplayName();
}
string CpimChatMessageModifier::cpimAddressUri (const Address &addr) const {
return addr.asStringUriOnly();
}
LINPHONE_END_NAMESPACE
......@@ -34,7 +34,8 @@ public:
Result decode (const std::shared_ptr<ChatMessage> &message, int &errorCode) override;
private:
std::string cpimAddressAsString (const Address &addr) const;
std::string cpimAddressDisplayName (const Address &addr) const;
std::string cpimAddressUri (const Address &addr) const;
};
LINPHONE_END_NAMESPACE
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment