Commit 01694c2b authored by Ronan's avatar Ronan

feat(content): clean code

parent faa6ef52
......@@ -31,6 +31,8 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
list<Content> ContentManager::multipartToContentList (const Content &content) {
belle_sip_multipart_body_handler_t *mpbh = belle_sip_multipart_body_handler_new_from_buffer(
(void *)content.getBodyAsString().c_str(),
......
......@@ -33,7 +33,7 @@ class Content;
namespace ContentManager {
std::list<Content> multipartToContentList (const Content &content);
Content contentListToMultipart (const std::list<Content> &contents);
};
}
LINPHONE_END_NAMESPACE
......
......@@ -22,20 +22,21 @@
#include <vector>
#include "object/clonable-object-p.h"
#include "object/object-p.h"
#include "content-type.h"
#include "content.h"
#include "object/clonable-object-p.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class ContentPrivate : public ClonableObjectPrivate {
public:
private:
std::vector<char> body;
ContentType contentType;
std::string contentDisposition;
L_DECLARE_PUBLIC(Content);
};
LINPHONE_END_NAMESPACE
......
......@@ -19,9 +19,8 @@
#include "linphone/utils/utils.h"
#include "object/clonable-object-p.h"
#include "logger/logger.h"
#include "content-type.h"
#include "object/clonable-object-p.h"
// =============================================================================
......@@ -29,6 +28,8 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
class ContentTypePrivate : public ClonableObjectPrivate {
public:
string type;
......@@ -60,34 +61,32 @@ ContentType::ContentType (const string &contentType) : ClonableObject(*new Conte
return;
if (setType(contentType.substr(0, pos))) {
if (posParam != string::npos) {
if (posParam != string::npos)
end = posParam;
}
if (!setSubType(contentType.substr(pos + 1, end - (pos + 1))))
d->type.clear();
}
if (posParam != string::npos) {
setParameter(contentType.substr(posParam + 2)); // We remove the blankspace after the ;
}
if (posParam != string::npos)
setParameter(contentType.substr(posParam + 2)); // We remove the blankspace after the ;.
}
ContentType::ContentType (const string &type, const string &subType) : ClonableObject(*new ContentTypePrivate) {
L_D();
if (setType(type)) {
if (!setSubType(subType))
d->type.clear();
}
if (setType(type) && !setSubType(subType))
d->type.clear();
}
ContentType::ContentType (const string &type, const string &subType, const string &parameter) : ClonableObject(*new ContentTypePrivate) {
ContentType::ContentType (
const string &type,
const string &subType,
const string &parameter
) : ClonableObject(*new ContentTypePrivate) {
L_D();
if (setType(type)) {
if (!setSubType(subType))
d->type.clear();
}
if (setType(type) && !setSubType(subType))
d->type.clear();
setParameter(parameter);
}
......@@ -104,11 +103,13 @@ ContentType &ContentType::operator= (const ContentType &src) {
}
bool ContentType::operator== (const ContentType &contentType) const {
return getType() == contentType.getType() && getSubType() == contentType.getSubType() && getParameter() == contentType.getParameter();
return getType() == contentType.getType() &&
getSubType() == contentType.getSubType() &&
getParameter() == contentType.getParameter();
}
bool ContentType::operator!= (const ContentType &contentType) const {
return !operator==(contentType);
return !(*this == contentType);
}
const string &ContentType::getType () const {
......@@ -162,9 +163,8 @@ string ContentType::asString () const {
L_D();
if (isValid()) {
string asString = d->type + "/" + d->subType;
if (!d->parameter.empty()) {
if (!d->parameter.empty())
asString += "; " + d->parameter;
}
return asString;
}
return "";
......
......@@ -17,11 +17,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "content-type.h"
// TODO: Remove me later.
#include "linphone/core.h"
#include "content-p.h"
#include "content.h"
#include "linphone/core.h"
#include "content-type.h"
// =============================================================================
......@@ -151,14 +151,13 @@ bool Content::isEmpty () const {
return getSize() == 0;
}
bool Content::isValid() const {
bool Content::isValid () const {
L_D();
return d->contentType.isValid() || d->body.empty();
}
LinphoneContent * Content::toLinphoneContent() const {
LinphoneContent* content;
content = linphone_core_create_content(NULL);
LinphoneContent *Content::toLinphoneContent () const {
LinphoneContent *content = linphone_core_create_content(nullptr);
linphone_content_set_type(content, getContentType().getType().c_str());
linphone_content_set_subtype(content, getContentType().getSubType().c_str());
return content;
......
......@@ -62,12 +62,12 @@ public:
size_t getSize () const;
bool isValid() const;
bool isValid () const;
bool isEmpty () const;
// TODO: Remove me later.
virtual LinphoneContent *toLinphoneContent() const;
virtual LinphoneContent *toLinphoneContent () const;
protected:
explicit Content (ContentPrivate &p);
......
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