mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-20 04:28:10 +00:00
Created Header class as parent of ContentType
This commit is contained in:
parent
acf44578ad
commit
49b93c6f9a
10 changed files with 199 additions and 75 deletions
|
|
@ -99,7 +99,9 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
|
|||
content/content.h
|
||||
content/file-content.h
|
||||
content/file-transfer-content.h
|
||||
content/header-param.h
|
||||
content/header/header.h
|
||||
content/header/header-p.h
|
||||
content/header/header-param.h
|
||||
core/core-accessor.h
|
||||
core/core-listener.h
|
||||
core/core-p.h
|
||||
|
|
@ -224,7 +226,8 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
|
|||
content/content.cpp
|
||||
content/file-content.cpp
|
||||
content/file-transfer-content.cpp
|
||||
content/header-param.cpp
|
||||
content/header/header.cpp
|
||||
content/header/header-param.cpp
|
||||
core/core-accessor.cpp
|
||||
core/core-call.cpp
|
||||
core/core-chat-room.cpp
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "content/content.h"
|
||||
#include "content/content-type.h"
|
||||
#include "content/header-param.h"
|
||||
#include "content/header/header-param.h"
|
||||
#include "content/content-manager.h"
|
||||
#include "content/file-content.h"
|
||||
#include "content/file-transfer-content.h"
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
#include "chat/modifier/file-transfer-chat-message-modifier.h"
|
||||
#include "chat/modifier/multipart-chat-message-modifier.h"
|
||||
#include "content/file-content.h"
|
||||
#include "content/header-param.h"
|
||||
#include "content/header/header-param.h"
|
||||
#include "content/content.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core-p.h"
|
||||
|
|
|
|||
|
|
@ -18,11 +18,10 @@
|
|||
*/
|
||||
|
||||
#include "linphone/utils/utils.h"
|
||||
#include "linphone/utils/algorithm.h"
|
||||
|
||||
#include "content-type.h"
|
||||
#include "header-param.h"
|
||||
#include "object/clonable-object-p.h"
|
||||
#include "header/header-p.h"
|
||||
#include "header/header-param.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
|
|
@ -32,11 +31,10 @@ LINPHONE_BEGIN_NAMESPACE
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class ContentTypePrivate : public ClonableObjectPrivate {
|
||||
class ContentTypePrivate : public HeaderPrivate {
|
||||
public:
|
||||
string type;
|
||||
string subType;
|
||||
std::list<HeaderParam> parameters;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -54,7 +52,7 @@ const ContentType ContentType::Sdp("application/sdp");
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ContentType::ContentType (const string &contentType) : ClonableObject(*new ContentTypePrivate) {
|
||||
ContentType::ContentType (const string &contentType) : Header(*new ContentTypePrivate) {
|
||||
L_D();
|
||||
|
||||
size_t pos = contentType.find('/');
|
||||
|
|
@ -86,7 +84,7 @@ ContentType::ContentType (const string &contentType) : ClonableObject(*new Conte
|
|||
}
|
||||
}
|
||||
|
||||
ContentType::ContentType (const string &type, const string &subType) : ClonableObject(*new ContentTypePrivate) {
|
||||
ContentType::ContentType (const string &type, const string &subType) : Header(*new ContentTypePrivate) {
|
||||
L_D();
|
||||
|
||||
if (setType(type) && !setSubType(subType))
|
||||
|
|
@ -97,7 +95,7 @@ ContentType::ContentType (
|
|||
const string &type,
|
||||
const string &subType,
|
||||
const HeaderParam ¶meter
|
||||
) : ClonableObject(*new ContentTypePrivate) {
|
||||
) : Header(*new ContentTypePrivate) {
|
||||
L_D();
|
||||
|
||||
if (setType(type) && !setSubType(subType))
|
||||
|
|
@ -109,7 +107,7 @@ ContentType::ContentType (
|
|||
const string &type,
|
||||
const string &subType,
|
||||
const std::list<HeaderParam> ¶meters
|
||||
) : ClonableObject(*new ContentTypePrivate) {
|
||||
) : Header(*new ContentTypePrivate) {
|
||||
L_D();
|
||||
|
||||
if (setType(type) && !setSubType(subType))
|
||||
|
|
@ -167,56 +165,6 @@ bool ContentType::setSubType (const string &subType) {
|
|||
return false;
|
||||
}
|
||||
|
||||
const std::list<HeaderParam> &ContentType::getParameters () const {
|
||||
L_D();
|
||||
|
||||
return d->parameters;
|
||||
}
|
||||
|
||||
void ContentType::addParameter (const std::string ¶mName, const std::string ¶mValue) {
|
||||
addParameter(HeaderParam(paramName, paramValue));
|
||||
}
|
||||
|
||||
void ContentType::addParameter (const HeaderParam ¶m) {
|
||||
L_D();
|
||||
removeParameter(param);
|
||||
d->parameters.push_back(param);
|
||||
}
|
||||
|
||||
void ContentType::addParameters(const std::list<HeaderParam> ¶ms) {
|
||||
for (auto it = std::begin(params); it!=std::end(params); ++it) {
|
||||
HeaderParam param = *it;
|
||||
addParameter(param.getName(), param.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
void ContentType::removeParameter (const std::string ¶mName) {
|
||||
L_D();
|
||||
auto it = findParameter(paramName);
|
||||
if (it != d->parameters.cend())
|
||||
d->parameters.remove(*it);
|
||||
}
|
||||
|
||||
void ContentType::removeParameter (const HeaderParam ¶m) {
|
||||
removeParameter(param.getName());
|
||||
}
|
||||
|
||||
std::list<HeaderParam>::const_iterator ContentType::findParameter (const std::string ¶mName) const {
|
||||
L_D();
|
||||
return findIf(d->parameters, [¶mName](const HeaderParam ¶m) {
|
||||
return param.getName() == paramName;
|
||||
});
|
||||
}
|
||||
|
||||
const HeaderParam &ContentType::getParameter (const std::string ¶mName) const {
|
||||
L_D();
|
||||
std::list<HeaderParam>::const_iterator it = findParameter(paramName);
|
||||
if (it != d->parameters.cend()) {
|
||||
return *it;
|
||||
}
|
||||
return Utils::getEmptyConstRefObject<HeaderParam>();
|
||||
}
|
||||
|
||||
bool ContentType::isEmpty () const {
|
||||
L_D();
|
||||
return d->type.empty() && d->subType.empty();
|
||||
|
|
|
|||
|
|
@ -20,9 +20,8 @@
|
|||
#ifndef _L_CONTENT_TYPE_H_
|
||||
#define _L_CONTENT_TYPE_H_
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "object/clonable-object.h"
|
||||
#include "header/header.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
|
|
@ -31,7 +30,7 @@ LINPHONE_BEGIN_NAMESPACE
|
|||
class ContentTypePrivate;
|
||||
class HeaderParam;
|
||||
|
||||
class LINPHONE_PUBLIC ContentType : public ClonableObject {
|
||||
class LINPHONE_PUBLIC ContentType : public Header {
|
||||
public:
|
||||
explicit ContentType (const std::string &contentType = "");
|
||||
ContentType (const std::string &type, const std::string &subType);
|
||||
|
|
@ -59,15 +58,6 @@ public:
|
|||
const std::string &getSubType () const;
|
||||
bool setSubType (const std::string &subType);
|
||||
|
||||
const std::list<HeaderParam> &getParameters () const;
|
||||
void addParameter (const std::string ¶mName, const std::string ¶mValue);
|
||||
void addParameter (const HeaderParam ¶m);
|
||||
void addParameters(const std::list<HeaderParam> ¶ms);
|
||||
void removeParameter (const std::string ¶mName);
|
||||
void removeParameter (const HeaderParam ¶m);
|
||||
std::list<HeaderParam>::const_iterator findParameter (const std::string ¶mName) const;
|
||||
const HeaderParam &getParameter (const std::string ¶mName) const;
|
||||
|
||||
std::string asString () const;
|
||||
|
||||
bool isMultipart() const;
|
||||
|
|
|
|||
41
src/content/header/header-p.h
Normal file
41
src/content/header/header-p.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* header-p.h
|
||||
* Copyright (C) 2010-2018 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _L_HEADER_P_H_
|
||||
#define _L_HEADER_P_H_
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "object/clonable-object-p.h"
|
||||
|
||||
#include "header.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class HeaderPrivate : public ClonableObjectPrivate {
|
||||
private:
|
||||
std::list<HeaderParam> parameters;
|
||||
L_DECLARE_PUBLIC(Header);
|
||||
};
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
||||
#endif // ifndef _L_HEADER_P_H_
|
||||
88
src/content/header/header.cpp
Normal file
88
src/content/header/header.cpp
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* header.cpp
|
||||
* Copyright (C) 2010-2018 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "linphone/utils/utils.h"
|
||||
#include "linphone/utils/algorithm.h"
|
||||
|
||||
#include "header-p.h"
|
||||
#include "header-param.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
using namespace std;
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Header::Header(HeaderPrivate &p) : ClonableObject(p) {
|
||||
|
||||
}
|
||||
|
||||
const std::list<HeaderParam> &Header::getParameters () const {
|
||||
L_D();
|
||||
|
||||
return d->parameters;
|
||||
}
|
||||
|
||||
void Header::addParameter (const std::string ¶mName, const std::string ¶mValue) {
|
||||
addParameter(HeaderParam(paramName, paramValue));
|
||||
}
|
||||
|
||||
void Header::addParameter (const HeaderParam ¶m) {
|
||||
L_D();
|
||||
removeParameter(param);
|
||||
d->parameters.push_back(param);
|
||||
}
|
||||
|
||||
void Header::addParameters(const std::list<HeaderParam> ¶ms) {
|
||||
for (auto it = std::begin(params); it!=std::end(params); ++it) {
|
||||
HeaderParam param = *it;
|
||||
addParameter(param.getName(), param.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
void Header::removeParameter (const std::string ¶mName) {
|
||||
L_D();
|
||||
auto it = findParameter(paramName);
|
||||
if (it != d->parameters.cend())
|
||||
d->parameters.remove(*it);
|
||||
}
|
||||
|
||||
void Header::removeParameter (const HeaderParam ¶m) {
|
||||
removeParameter(param.getName());
|
||||
}
|
||||
|
||||
std::list<HeaderParam>::const_iterator Header::findParameter (const std::string ¶mName) const {
|
||||
L_D();
|
||||
return findIf(d->parameters, [¶mName](const HeaderParam ¶m) {
|
||||
return param.getName() == paramName;
|
||||
});
|
||||
}
|
||||
|
||||
const HeaderParam &Header::getParameter (const std::string ¶mName) const {
|
||||
L_D();
|
||||
std::list<HeaderParam>::const_iterator it = findParameter(paramName);
|
||||
if (it != d->parameters.cend()) {
|
||||
return *it;
|
||||
}
|
||||
return Utils::getEmptyConstRefObject<HeaderParam>();
|
||||
}
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
54
src/content/header/header.h
Normal file
54
src/content/header/header.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* header.h
|
||||
* Copyright (C) 2010-2018 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _L_HEADER_H_
|
||||
#define _L_HEADER_H_
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "object/clonable-object.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class HeaderPrivate;
|
||||
class HeaderParam;
|
||||
|
||||
class LINPHONE_PUBLIC Header : public ClonableObject {
|
||||
public:
|
||||
const std::list<HeaderParam> &getParameters () const;
|
||||
void addParameter (const std::string ¶mName, const std::string ¶mValue);
|
||||
void addParameter (const HeaderParam ¶m);
|
||||
void addParameters(const std::list<HeaderParam> ¶ms);
|
||||
void removeParameter (const std::string ¶mName);
|
||||
void removeParameter (const HeaderParam ¶m);
|
||||
std::list<HeaderParam>::const_iterator findParameter (const std::string ¶mName) const;
|
||||
const HeaderParam &getParameter (const std::string ¶mName) const;
|
||||
|
||||
protected:
|
||||
explicit Header (HeaderPrivate &p);
|
||||
|
||||
private:
|
||||
L_DECLARE_PRIVATE(Header);
|
||||
};
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
||||
#endif // ifndef _L_HEADER_H_
|
||||
Loading…
Add table
Reference in a new issue