mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-28 16:49:20 +00:00
feat(core): add better content class
This commit is contained in:
parent
44152b9f48
commit
4d85643a9c
3 changed files with 76 additions and 163 deletions
|
|
@ -69,7 +69,6 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
|
|||
conference/session/port-config.h
|
||||
content/content-type.h
|
||||
content/content.h
|
||||
content/content.h
|
||||
core/core.h
|
||||
db/abstract/abstract-db-p.h
|
||||
db/abstract/abstract-db.h
|
||||
|
|
@ -127,7 +126,6 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
|
|||
conference/session/media-session.cpp
|
||||
content/content-type.cpp
|
||||
content/content.cpp
|
||||
content/content.cpp
|
||||
core/core.cpp
|
||||
db/abstract/abstract-db.cpp
|
||||
db/events-db.cpp
|
||||
|
|
|
|||
|
|
@ -16,11 +16,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// From coreapi.
|
||||
#include "private.h"
|
||||
|
||||
#include "c-wrapper/c-tools.h"
|
||||
#include "object/object-p.h"
|
||||
#include "content-type.h"
|
||||
#include "object/clonable-object-p.h"
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
|
@ -30,148 +27,82 @@ using namespace std;
|
|||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class ContentPrivate : public ObjectPrivate {
|
||||
class ContentPrivate : public ClonableObjectPrivate {
|
||||
public:
|
||||
struct Cache {
|
||||
string type;
|
||||
string subType;
|
||||
string customHeaderValue;
|
||||
string encoding;
|
||||
};
|
||||
|
||||
SalBodyHandler *bodyHandler = nullptr;
|
||||
void *cryptoContext = nullptr;
|
||||
string name;
|
||||
string key;
|
||||
|
||||
mutable Cache cache;
|
||||
vector<char> body;
|
||||
ContentType contentType;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Content::Content () : Object(*new ContentPrivate) {}
|
||||
Content::Content () : ClonableObject(*new ContentPrivate) {}
|
||||
|
||||
const string &Content::getType () const {
|
||||
L_D(const Content);
|
||||
d->cache.type = sal_body_handler_get_subtype(d->bodyHandler);
|
||||
return d->cache.type;
|
||||
}
|
||||
|
||||
void Content::setType (const string &type) {
|
||||
Content::Content (const Content &src) : ClonableObject(*new ContentPrivate) {
|
||||
L_D(Content);
|
||||
sal_body_handler_set_type(d->bodyHandler, L_STRING_TO_C(type));
|
||||
d->body = src.getBody();
|
||||
d->contentType = src.getContentType();
|
||||
}
|
||||
|
||||
const string &Content::getSubType () const {
|
||||
L_D(const Content);
|
||||
d->cache.subType = sal_body_handler_get_subtype(d->bodyHandler);
|
||||
return d->cache.subType;
|
||||
}
|
||||
|
||||
void Content::setSubType (const string &subType) {
|
||||
Content::Content (Content &&src) {
|
||||
L_D(Content);
|
||||
sal_body_handler_set_subtype(d->bodyHandler, L_STRING_TO_C(subType));
|
||||
d->body = move(src.getPrivate()->body);
|
||||
d->contentType = move(src.getPrivate()->contentType);
|
||||
}
|
||||
|
||||
const void *Content::getBuffer () const {
|
||||
L_D(const Content);
|
||||
return sal_body_handler_get_data(d->bodyHandler);
|
||||
}
|
||||
|
||||
void Content::setBuffer (const void *buffer, size_t size) {
|
||||
Content &Content::operator= (const Content &src) {
|
||||
L_D(Content);
|
||||
sal_body_handler_set_size(d->bodyHandler, size);
|
||||
void *data = belle_sip_malloc(size);
|
||||
sal_body_handler_set_data(d->bodyHandler, memcpy(data, buffer, size));
|
||||
if (this != &src) {
|
||||
d->body = src.getBody();
|
||||
d->contentType = src.getContentType();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Content &Content::operator= (Content &&src) {
|
||||
L_D(Content);
|
||||
if (this != &src) {
|
||||
d->body = move(src.getPrivate()->body);
|
||||
d->contentType = move(src.getPrivate()->contentType);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const ContentType &Content::getContentType () const {
|
||||
L_D(const Content);
|
||||
return d->contentType;
|
||||
}
|
||||
|
||||
void Content::setContentType (const ContentType &contentType) {
|
||||
L_D(Content);
|
||||
d->contentType = contentType;
|
||||
}
|
||||
|
||||
const std::vector<char> &Content::getBody () const {
|
||||
L_D(const Content);
|
||||
return d->body;
|
||||
}
|
||||
|
||||
void Content::setBody (const std::vector<char> &body) {
|
||||
L_D(Content);
|
||||
d->body = body;
|
||||
}
|
||||
|
||||
void Content::setBody (const std::string &body) {
|
||||
L_D(Content);
|
||||
d->body = vector<char>(body.cbegin(), body.cend());
|
||||
}
|
||||
|
||||
void Content::setBody (const void *buffer, size_t size) {
|
||||
L_D(Content);
|
||||
const char *start = static_cast<const char *>(buffer);
|
||||
d->body = vector<char>(start, start + size);
|
||||
}
|
||||
|
||||
size_t Content::getSize () const {
|
||||
L_D(const Content);
|
||||
return sal_body_handler_get_size(d->bodyHandler);
|
||||
}
|
||||
|
||||
void Content::setSize (size_t size) {
|
||||
L_D(Content);
|
||||
sal_body_handler_set_data(d->bodyHandler, nullptr);
|
||||
sal_body_handler_set_size(d->bodyHandler, size);
|
||||
}
|
||||
|
||||
const string &Content::getEncoding () const {
|
||||
L_D(const Content);
|
||||
d->cache.encoding = sal_body_handler_get_encoding(d->bodyHandler);
|
||||
return d->cache.encoding;
|
||||
}
|
||||
|
||||
void Content::setEncoding (const string &encoding) {
|
||||
L_D(Content);
|
||||
sal_body_handler_set_encoding(d->bodyHandler, L_STRING_TO_C(encoding));
|
||||
}
|
||||
|
||||
const string &Content::getName () const {
|
||||
L_D(const Content);
|
||||
return d->name;
|
||||
}
|
||||
|
||||
void Content::setName (const string &name) {
|
||||
L_D(Content);
|
||||
d->name = name;
|
||||
}
|
||||
|
||||
bool Content::isMultipart () const {
|
||||
L_D(const Content);
|
||||
return sal_body_handler_is_multipart(d->bodyHandler);
|
||||
}
|
||||
|
||||
shared_ptr<Content> Content::getPart (int index) const {
|
||||
L_D(const Content);
|
||||
|
||||
if (!isMultipart())
|
||||
return nullptr;
|
||||
|
||||
SalBodyHandler *bodyHandler = sal_body_handler_get_part(d->bodyHandler, index);
|
||||
if (!bodyHandler)
|
||||
return nullptr;
|
||||
|
||||
Content *content = new Content();
|
||||
sal_body_handler_ref(bodyHandler);
|
||||
content->getPrivate()->bodyHandler = bodyHandler;
|
||||
return shared_ptr<Content>(content);
|
||||
}
|
||||
|
||||
shared_ptr<Content> Content::findPartByHeader (const string &headerName, const string &headerValue) const {
|
||||
L_D(const Content);
|
||||
|
||||
if (!isMultipart())
|
||||
return nullptr;
|
||||
|
||||
SalBodyHandler *bodyHandler = sal_body_handler_find_part_by_header(
|
||||
d->bodyHandler,
|
||||
L_STRING_TO_C(headerName),
|
||||
L_STRING_TO_C(headerValue)
|
||||
);
|
||||
if (!bodyHandler)
|
||||
return nullptr;
|
||||
|
||||
Content *content = new Content();
|
||||
sal_body_handler_ref(bodyHandler);
|
||||
content->getPrivate()->bodyHandler = bodyHandler;
|
||||
return shared_ptr<Content>(content);
|
||||
}
|
||||
|
||||
const string &Content::getCustomHeaderValue (const string &headerName) const {
|
||||
L_D(const Content);
|
||||
d->cache.customHeaderValue = sal_body_handler_get_header(d->bodyHandler, L_STRING_TO_C(headerName));
|
||||
return d->cache.customHeaderValue;
|
||||
}
|
||||
|
||||
const string &Content::getKey () const {
|
||||
L_D(const Content);
|
||||
return d->key;
|
||||
}
|
||||
|
||||
void Content::setKey (const string &key) {
|
||||
L_D(Content);
|
||||
d->key = key;
|
||||
return d->body.size();
|
||||
}
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -19,54 +19,38 @@
|
|||
#ifndef _CONTENT_H_
|
||||
#define _CONTENT_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "object/object.h"
|
||||
#include "object/clonable-object.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class ContentPrivate;
|
||||
class ContentType;
|
||||
|
||||
class Content : public Object {
|
||||
friend class Core;
|
||||
|
||||
class LINPHONE_PUBLIC Content : public ClonableObject {
|
||||
public:
|
||||
const std::string &getType () const;
|
||||
void setType (const std::string &type);
|
||||
Content ();
|
||||
Content (const Content &src);
|
||||
Content (Content &&src);
|
||||
|
||||
const std::string &getSubType () const;
|
||||
void setSubType (const std::string &subType);
|
||||
Content &operator= (const Content &src);
|
||||
Content &operator= (Content &&src);
|
||||
|
||||
const void *getBuffer () const;
|
||||
void setBuffer (const void *buffer, size_t size);
|
||||
const ContentType &getContentType () const;
|
||||
void setContentType (const ContentType &contentType);
|
||||
|
||||
const std::vector<char> &getBody () const;
|
||||
void setBody (const std::vector<char> &body);
|
||||
void setBody (const std::string &body);
|
||||
void setBody (const void *buffer, size_t size);
|
||||
size_t getSize () const;
|
||||
void setSize (size_t size);
|
||||
|
||||
const std::string &getEncoding () const;
|
||||
void setEncoding (const std::string &encoding);
|
||||
|
||||
const std::string &getName () const;
|
||||
void setName (const std::string &name);
|
||||
|
||||
bool isMultipart () const;
|
||||
|
||||
std::shared_ptr<Content> getPart (int index) const;
|
||||
std::shared_ptr<Content> findPartByHeader (const std::string &headerName, const std::string &headerValue) const;
|
||||
|
||||
const std::string &getCustomHeaderValue (const std::string &headerName) const;
|
||||
|
||||
const std::string &getKey () const;
|
||||
void setKey (const std::string &key);
|
||||
|
||||
private:
|
||||
Content ();
|
||||
|
||||
L_DECLARE_PRIVATE(Content);
|
||||
L_DISABLE_COPY(Content);
|
||||
};
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue