From 68bb508cb5af4173be1bb2d8411a2bd9b73af272 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 12 Sep 2017 12:11:49 +0200 Subject: [PATCH] feat(core): add ContentType class --- src/CMakeLists.txt | 10 +++- src/content/content-type.cpp | 111 +++++++++++++++++++++++++++++++++++ src/content/content-type.h | 58 ++++++++++++++++++ 3 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 src/content/content-type.cpp create mode 100644 src/content/content-type.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 56243ca4f..e656f4111 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,13 +28,13 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES call/call-listener.h call/call-p.h call/call.h - chat/basic-chat-room.h chat/basic-chat-room-p.h + chat/basic-chat-room.h chat/chat-message.h chat/chat-room-p.h chat/chat-room.h - chat/client-group-chat-room.h chat/client-group-chat-room-p.h + chat/client-group-chat-room.h chat/cpim/cpim.h chat/cpim/header/cpim-core-headers.h chat/cpim/header/cpim-generic-header.h @@ -45,8 +45,8 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES chat/cpim/parser/cpim-parser.h chat/imdn.h chat/is-composing.h - chat/real-time-text-chat-room.h chat/real-time-text-chat-room-p.h + chat/real-time-text-chat-room.h conference/conference-listener.h conference/conference-p.h conference/conference.h @@ -63,6 +63,8 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES conference/session/call-session.h conference/session/media-session.h conference/session/port-config.h + content/content-type.h + content/content.h content/content.h core/core.h db/abstract/abstract-db-p.h @@ -117,6 +119,8 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES conference/remote-conference.cpp conference/session/call-session.cpp conference/session/media-session.cpp + content/content-type.cpp + content/content.cpp content/content.cpp core/core.cpp db/abstract/abstract-db.cpp diff --git a/src/content/content-type.cpp b/src/content/content-type.cpp new file mode 100644 index 000000000..11fae0713 --- /dev/null +++ b/src/content/content-type.cpp @@ -0,0 +1,111 @@ +/* + * content-type.cpp + * Copyright (C) 2017 Belledonne Communications SARL + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "content-type.h" +#include "object/clonable-object-p.h" + +// ============================================================================= + +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +class ContentTypePrivate : public ClonableObjectPrivate { +public: + string type; + string subType; +}; + +// ----------------------------------------------------------------------------- + +ContentType::ContentType (const string &contentType) : ClonableObject(*new ContentTypePrivate) { + L_D(ContentType); + + size_t pos = contentType.find('/'); + if (pos == string::npos) + return; + + if (setType(contentType.substr(0, pos))) { + if (!setSubType(contentType.substr(pos + 1))) + d->type.clear(); + } +} + +ContentType::ContentType (const string &type, const string &subType) : ClonableObject(*new ContentTypePrivate) { + L_D(ContentType); + + if (setType(type)) { + if (!setSubType(subType)) + d->type.clear(); + } +} + +ContentType::ContentType (const ContentType &src) : ContentType(src.getType(), src.getSubType()) {} + +ContentType &ContentType::operator= (const ContentType &src) { + if (this != &src) { + setType(src.getType()); + setSubType(src.getSubType()); + } + + return *this; +} + +bool ContentType::operator== (const ContentType &contentType) { + return getType() == contentType.getType() && getSubType() == contentType.getSubType(); +} + +const string &ContentType::getType () const { + L_D(const ContentType); + return d->type; +} + +bool ContentType::setType (const std::string &type) { + L_D(ContentType); + if (type.find('/') == string::npos) { + d->type = type; + return true; + } + return false; +} + +const string &ContentType::getSubType () const { + L_D(const ContentType); + return d->subType; +} + +bool ContentType::setSubType (const std::string &subType) { + L_D(ContentType); + if (subType.find('/') == string::npos) { + d->subType = subType; + return true; + } + return false; +} + +bool ContentType::isValid () const { + L_D(const ContentType); + return !d->type.empty() && !d->subType.empty(); +} + +string ContentType::asString () const { + L_D(const ContentType); + return isValid() ? d->type + "/" + d->subType : ""; +} + +LINPHONE_END_NAMESPACE diff --git a/src/content/content-type.h b/src/content/content-type.h new file mode 100644 index 000000000..79daa8a17 --- /dev/null +++ b/src/content/content-type.h @@ -0,0 +1,58 @@ +/* + * content-type.h + * Copyright (C) 2017 Belledonne Communications SARL + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _CONTENT_TYPE_H_ +#define _CONTENT_TYPE_H_ + +#include + +#include "object/clonable-object.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class ContentTypePrivate; + +class LINPHONE_PUBLIC ContentType : public ClonableObject { +public: + ContentType (const std::string &contentType = ""); + ContentType (const std::string &type, const std::string &subType); + ContentType (const ContentType &src); + + ContentType &operator= (const ContentType &src); + + bool operator== (const ContentType &contentType); + + bool isValid () const; + + const std::string &getType () const; + bool setType (const std::string &type); + + const std::string &getSubType () const; + bool setSubType (const std::string &subType); + + std::string asString () const; + +private: + L_DECLARE_PRIVATE(ContentType); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _CONTENT_TYPE_H_