Verified Commit fe9d1e42 authored by Linus Jahn's avatar Linus Jahn 🔌 Committed by Linus Jahn
Browse files

Implement XEP-0334: Message Processing Hints (#237)

This implements XEP-0334 in version 0.3 as StanzaExtension.
parent 7b0c7458
......@@ -35,7 +35,8 @@ SOURCES += \
src/gloox-extensions/bitsofbinarydata.cpp \
src/gloox-extensions/bitsofbinarymanager.cpp \
src/gloox-extensions/bitsofbinarymemorycache.cpp \
src/gloox-extensions/reference.cpp
src/gloox-extensions/reference.cpp \
src/gloox-extensions/processinghints.cpp
HEADERS += \
src/Database.h \
......@@ -72,7 +73,8 @@ HEADERS += \
src/gloox-extensions/bitsofbinaryhandler.h \
src/gloox-extensions/bitsofbinarycache.h \
src/gloox-extensions/bitsofbinarymemorycache.h \
src/gloox-extensions/reference.h
src/gloox-extensions/reference.h \
src/gloox-extensions/processinghints.h
android: INCLUDEPATH += $$PWD/3rdparty/gloox/include
......
......@@ -39,4 +39,5 @@ set(KAIDAN_SOURCES
${CURDIR}/gloox-extensions/bitsofbinarymanager.cpp
${CURDIR}/gloox-extensions/bitsofbinarymemorycache.cpp
${CURDIR}/gloox-extensions/reference.cpp
${CURDIR}/gloox-extensions/processinghints.cpp
)
......@@ -77,6 +77,13 @@ namespace gloox {
static const std::string XMLNS_REFERENCES = "urn:xmpp:reference:0";
static const int EXT_REFERENCES = 4272;
//
// XEP-0334: Message Processing Hints
//
static const std::string XMLNS_PROCESSINGHINTS = "urn:xmpp:hints";
static const int EXT_PROCESSINGHINTS = 4273;
}
#endif // GLOOXEXTS_H__
/*
* Kaidan - A user-friendly XMPP client for every device!
*
* Copyright (C) 2018 Kaidan developers and contributors
* (see the LICENSE file for a full list of copyright authors)
*
* Kaidan 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.
*
* In addition, as a special exception, the author of Kaidan gives
* permission to link the code of its release with the OpenSSL
* project's "OpenSSL" library (or with modified versions of it that
* use the same license as the "OpenSSL" library), and distribute the
* linked executables. You must obey the GNU General Public License in
* all respects for all of the code used other than "OpenSSL". If you
* modify this file, you may extend this exception to your version of
* the file, but you are not obligated to do so. If you do not wish to
* do so, delete this exception statement from your version.
*
* Kaidan 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 Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
#include "processinghints.h"
#include "gloox-extensions.h"
using namespace gloox;
ProcessingHints::ProcessingHints(ProcessingHints::Type type)
: StanzaExtension(EXT_PROCESSINGHINTS), m_type(type), m_valid(type != None)
{
}
ProcessingHints::ProcessingHints(const Tag* tag)
: StanzaExtension(EXT_PROCESSINGHINTS), m_type(None)
{
std::map<std::string, ProcessingHints::Type> typeMap = {
{"no-permanent-store", ProcessingHints::NoPermanentStore},
{"no-store", ProcessingHints::NoStore},
{"no-copy", ProcessingHints::NoCopies},
{"store", ProcessingHints::Store}
};
if (typeMap.count(tag->name())) {
m_type = typeMap[tag->name()];
}
m_valid = m_type != None;
}
Tag* ProcessingHints::tag() const
{
std::map<std::string, ProcessingHints::Type> typeMap = {
{"no-permanent-store", ProcessingHints::NoPermanentStore},
{"no-store", ProcessingHints::NoStore},
{"no-copy", ProcessingHints::NoCopies},
{"store", ProcessingHints::Store}
};
for (std::pair<std::string, int> pair : typeMap) {
if (m_type == pair.second) {
return new Tag(pair.first, XMLNS, XMLNS_PROCESSINGHINTS);
}
}
return nullptr;
}
const std::string& ProcessingHints::filterString() const
{
static const std::string filter = "/message/*[@xmlns='" +
XMLNS_PROCESSINGHINTS + "']";
return filter;
}
/*
* Kaidan - A user-friendly XMPP client for every device!
*
* Copyright (C) 2018 Kaidan developers and contributors
* (see the LICENSE file for a full list of copyright authors)
*
* Kaidan 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.
*
* In addition, as a special exception, the author of Kaidan gives
* permission to link the code of its release with the OpenSSL
* project's "OpenSSL" library (or with modified versions of it that
* use the same license as the "OpenSSL" library), and distribute the
* linked executables. You must obey the GNU General Public License in
* all respects for all of the code used other than "OpenSSL". If you
* modify this file, you may extend this exception to your version of
* the file, but you are not obligated to do so. If you do not wish to
* do so, delete this exception statement from your version.
*
* Kaidan 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 Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PROCESSINGHINTS_H__
#define PROCESSINGHINTS_H__
#include <gloox/stanzaextension.h>
#include <gloox/tag.h>
#include <string>
namespace gloox {
/**
* @class ProcessingHints An implementation of Message Processing Hints
* (@xep{0334}) as a StanzaExtension.
*
* XEP Version: 0.3
*
* @author Linus Jahn <lnj@kaidan.im>
* @since 1.0.21
*/
class GLOOX_API ProcessingHints : public gloox::StanzaExtension
{
public:
enum Type {
None, /* No Message Processing Hint */
NoPermanentStore, /* Entities shouldn't store permanently */
NoStore, /* Entities shouldn't store at all */
NoCopies, /* Messages shouldn't be copied to other than given entity */
Store /* Message should be explicitly stored */
};
/**
* Default constructor
*
* @param type The type of processing hint
*/
ProcessingHints(Type type);
/**
* Construct from XML Tag
*/
ProcessingHints(const Tag *tag);
/**
* Clone the StanzaExtension
*/
virtual StanzaExtension* clone() const
{
return new ProcessingHints(*this);
}
/**
* Get the XML tag
*
* @warning This will return a nullptr, if the object is not valid.
*/
virtual Tag* tag() const;
/**
* Create a new instance
*/
virtual StanzaExtension* newInstance(const Tag* tag) const
{
return new ProcessingHints(tag);
}
/**
* Returns the filter string for filtering by the client
*/
virtual const std::string& filterString() const;
/**
* Get the type
*/
ProcessingHints::Type type() const
{
return m_type;
}
/**
* Check if is valid
*/
bool valid() const
{
return m_valid;
}
private:
bool m_valid;
Type m_type;
};
}
#endif // PROCESSINGHINTS_H__
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