mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 19:18:06 +00:00
Added << operator for ContentType and Header
This commit is contained in:
parent
646cff8460
commit
7009b68b9a
5 changed files with 24 additions and 0 deletions
|
|
@ -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";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue