diff --git a/src/content/content-type.cpp b/src/content/content-type.cpp index 35391783b..e5d58c7a7 100644 --- a/src/content/content-type.cpp +++ b/src/content/content-type.cpp @@ -55,6 +55,7 @@ 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(); @@ -82,11 +83,13 @@ ContentType::ContentType (const string &contentType) : Header(*new ContentTypePr params.erase(0, posParam + 1); } while (posParam != std::string::npos); } + setValue(d->type + "/" + d->subType); } ContentType::ContentType (const string &type, const string &subType) : Header(*new ContentTypePrivate) { L_D(); + setName("Content-Type"); if (setType(type) && !setSubType(subType)) d->type.clear(); } @@ -98,6 +101,7 @@ ContentType::ContentType ( ) : Header(*new ContentTypePrivate) { L_D(); + setName("Content-Type"); if (setType(type) && !setSubType(subType)) d->type.clear(); addParameter(parameter); @@ -110,6 +114,7 @@ ContentType::ContentType ( ) : Header(*new ContentTypePrivate) { L_D(); + setName("Content-Type"); if (setType(type) && !setSubType(subType)) d->type.clear(); addParameters(parameters); @@ -119,6 +124,7 @@ 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(); @@ -146,6 +152,7 @@ bool ContentType::setType (const string &type) { L_D(); if (type.find('/') == string::npos) { d->type = Utils::stringToLower(type); + setValue(d->type + "/" + d->subType); return true; } return false; @@ -160,6 +167,7 @@ bool ContentType::setSubType (const string &subType) { L_D(); if (subType.find('/') == string::npos) { d->subType = Utils::stringToLower(subType); + setValue(d->type + "/" + d->subType); return true; } return false; @@ -187,6 +195,11 @@ string ContentType::asString () const { return ""; } +ostream &operator<<(ostream& stream, const ContentType& contentType) { + stream << contentType.asString(); + return stream; +} + bool ContentType::isMultipart() const { return getType() == "multipart"; } diff --git a/src/content/content-type.h b/src/content/content-type.h index 2ed267065..10f895e4d 100644 --- a/src/content/content-type.h +++ b/src/content/content-type.h @@ -59,6 +59,7 @@ public: bool setSubType (const std::string &subType); std::string asString () const; + friend std::ostream &operator<<(std::ostream&, const ContentType&); bool isMultipart() const; diff --git a/src/content/header/header.cpp b/src/content/header/header.cpp index 561b7ce05..14ce99f85 100644 --- a/src/content/header/header.cpp +++ b/src/content/header/header.cpp @@ -148,4 +148,9 @@ string Header::asString () const { return asString; } +ostream &operator<<(ostream& stream, const Header& header) { + stream << header.asString(); + return stream; +} + LINPHONE_END_NAMESPACE \ No newline at end of file diff --git a/src/content/header/header.h b/src/content/header/header.h index a0b8083fe..5d111900d 100644 --- a/src/content/header/header.h +++ b/src/content/header/header.h @@ -59,6 +59,7 @@ public: const HeaderParam &getParameter (const std::string ¶mName) const; std::string asString () const; + friend std::ostream &operator<<(std::ostream&, const Header&); protected: explicit Header (HeaderPrivate &p); diff --git a/tester/content-manager-tester.cpp b/tester/content-manager-tester.cpp index 24c4817d5..52d461ef9 100644 --- a/tester/content-manager-tester.cpp +++ b/tester/content-manager-tester.cpp @@ -24,6 +24,7 @@ #include "content/header/header-param.h" #include "liblinphone_tester.h" #include "tester_utils.h" +#include "logger/logger.h" using namespace LinphonePrivate; using namespace std; @@ -372,6 +373,7 @@ static void content_type_parsing(void) { BC_ASSERT_STRING_EQUAL("\"https://www.linphone.org/img/linphone-open-source-voip-projectX2.png\"", contentType.getParameter("URL").getValue().c_str()); BC_ASSERT_STRING_EQUAL("", contentType.getParameter("boundary").getValue().c_str()); BC_ASSERT_EQUAL(2, contentType.getParameters().size(), int, "%d"); + lInfo() << "Content-Type is " << contentType; BC_ASSERT_TRUE(type == contentType.asString()); type = "multipart/mixed;boundary=-----------------------------14737809831466499882746641450"; @@ -381,6 +383,7 @@ static void content_type_parsing(void) { BC_ASSERT_STRING_EQUAL("-----------------------------14737809831466499882746641450", contentType.getParameter("boundary").getValue().c_str()); BC_ASSERT_STRING_EQUAL("", contentType.getParameter("access-type").getValue().c_str()); BC_ASSERT_EQUAL(1, contentType.getParameters().size(), int, "%d"); + lInfo() << "Content-Type is " << contentType; BC_ASSERT_TRUE(type == contentType.asString()); type = "plain/text"; @@ -389,6 +392,7 @@ static void content_type_parsing(void) { BC_ASSERT_STRING_EQUAL("text", contentType.getSubType().c_str()); BC_ASSERT_STRING_EQUAL("", contentType.getParameter("boundary").getValue().c_str()); BC_ASSERT_EQUAL(0, contentType.getParameters().size(), int, "%d"); + lInfo() << "Content-Type is " << contentType; BC_ASSERT_TRUE(type == contentType.asString()); }