Improved ContentType's asString() method

This commit is contained in:
Sylvain Berfini 2018-03-27 14:39:32 +02:00
parent 7009b68b9a
commit af2a607014
5 changed files with 11 additions and 30 deletions

View file

@ -582,7 +582,7 @@ LinphoneReason ChatMessagePrivate::receive () {
foundSupportContentType = true;
break;
} else
lError() << "Unsupported content-type: " << c->getContentType().asString();
lError() << "Unsupported content-type: " << c->getContentType();
}
if (!foundSupportContentType) {

View file

@ -98,7 +98,7 @@ ChatMessageModifier::Result CpimChatMessageModifier::decode (const shared_ptr<Ch
content = message->getContents().front();
if (content->getContentType() != ContentType::Cpim) {
lError() << "[CPIM] Message is not CPIM but " << content->getContentType().asString();
lError() << "[CPIM] Message is not CPIM but " << content->getContentType();
return ChatMessageModifier::Result::Skipped;
}

View file

@ -55,7 +55,6 @@ const ContentType ContentType::Sdp("application/sdp");
ContentType::ContentType (const string &contentType) : Header(*new ContentTypePrivate) {
L_D();
setName("Content-Type");
size_t pos = contentType.find('/');
size_t posParam = contentType.find(";");
size_t end = contentType.length();
@ -89,7 +88,6 @@ ContentType::ContentType (const string &contentType) : Header(*new ContentTypePr
ContentType::ContentType (const string &type, const string &subType) : Header(*new ContentTypePrivate) {
L_D();
setName("Content-Type");
if (setType(type) && !setSubType(subType))
d->type.clear();
}
@ -101,7 +99,6 @@ ContentType::ContentType (
) : Header(*new ContentTypePrivate) {
L_D();
setName("Content-Type");
if (setType(type) && !setSubType(subType))
d->type.clear();
addParameter(parameter);
@ -114,7 +111,6 @@ ContentType::ContentType (
) : Header(*new ContentTypePrivate) {
L_D();
setName("Content-Type");
if (setType(type) && !setSubType(subType))
d->type.clear();
addParameters(parameters);
@ -124,7 +120,6 @@ ContentType::ContentType (const ContentType &other) : ContentType(other.getType(
ContentType &ContentType::operator= (const ContentType &other) {
if (this != &other) {
setName("Content-Type");
setType(other.getType());
setSubType(other.getSubType());
cleanParameters();
@ -183,23 +178,6 @@ bool ContentType::isValid () const {
return !d->type.empty() && !d->subType.empty();
}
string ContentType::asString () const {
L_D();
if (isValid()) {
string asString = d->type + "/" + d->subType;
for (const auto &param : getParameters()) {
asString += param.asString();
}
return asString;
}
return "";
}
ostream &operator<<(ostream& stream, const ContentType& contentType) {
stream << contentType.asString();
return stream;
}
bool ContentType::isMultipart() const {
return getType() == "multipart";
}

View file

@ -58,9 +58,6 @@ public:
const std::string &getSubType () const;
bool setSubType (const std::string &subType);
std::string asString () const;
friend std::ostream &operator<<(std::ostream&, const ContentType&);
bool isMultipart() const;
static bool isFile (const ContentType &contentType);

View file

@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <sstream>
#include "linphone/utils/utils.h"
#include "linphone/utils/algorithm.h"
@ -141,11 +143,15 @@ const HeaderParam &Header::getParameter (const std::string &paramName) const {
}
string Header::asString () const {
string asString = getName() + ":" + getValue();
stringstream asString;
if (!getName().empty()) {
asString << getName() << ":";
}
asString << getValue();
for (const auto &param : getParameters()) {
asString += param.asString();
asString << param.asString();
}
return asString;
return asString.str();
}
ostream &operator<<(ostream& stream, const Header& header) {