Verified Commit c154f307 authored by Linus Jahn's avatar Linus Jahn 🍙

Clean up everything from gloox

This only includes the sources, the build scripts and similar are all
still outdated.
parent ba27019f
......@@ -18,7 +18,6 @@ set(KAIDAN_SOURCES
${CURDIR}/LogHandler.cpp
${CURDIR}/StatusBar.cpp
${CURDIR}/UploadManager.cpp
# ${CURDIR}/QtHttpUploader.cpp
# SingleApplication
${CURDIR}/singleapp/singleapplication.cpp
......@@ -27,20 +26,6 @@ set(KAIDAN_SOURCES
# needed to trigger moc generation
${CURDIR}/Enums.h
# kaidan gloox extensions (need to be merged into gloox upstream)
# ${CURDIR}/gloox-extensions/httpuploadmanager.cpp
# ${CURDIR}/gloox-extensions/httpuploadrequest.cpp
# ${CURDIR}/gloox-extensions/httpuploadslot.cpp
# ${CURDIR}/gloox-extensions/bitsofbinarydata.cpp
# ${CURDIR}/gloox-extensions/bitsofbinarymanager.cpp
# ${CURDIR}/gloox-extensions/bitsofbinarymemorycache.cpp
# ${CURDIR}/gloox-extensions/reference.cpp
# ${CURDIR}/gloox-extensions/processinghints.cpp
# ${CURDIR}/gloox-extensions/hash.cpp
# ${CURDIR}/gloox-extensions/thumb.cpp
# ${CURDIR}/gloox-extensions/jinglefile.cpp
# ${CURDIR}/gloox-extensions/sims.cpp
# kaidan QXmpp extensions (need to be merged into QXmpp upstream)
${CURDIR}/qxmpp-exts/QXmppHttpUploadIq.cpp
${CURDIR}/qxmpp-exts/QXmppUploadRequestManager.cpp
......
......@@ -49,8 +49,7 @@ namespace Enums {
Q_ENUM_NS(ConnectionState)
/**
* Enumeration of possible disconnection reasons (compatible to gloox::
* ConnectionError)
* Enumeration of possible disconnection reasons
*/
enum class DisconnectionReason : quint8 {
ConnNoError,
......
/*
* 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 "HttpUploadHandler.h"
#include "QtHttpUploader.h"
#include "gloox-extensions/httpuploadmanager.h"
HttpUploadHandler::HttpUploadHandler(gloox::Client *client, QObject *parent)
: QObject(parent), client(client)
{
manager = new gloox::HttpUploadManager(client);
uploader = new QtHttpUploader(manager);
manager->registerHttpUploadHandler(this);
}
void HttpUploadHandler::handleUploadFailed(int id, gloox::HttpUploadError error,
const std::string &text,
const std::string &stamp)
{
}
void HttpUploadHandler::handleUploadFinished(int id, std::string &getUrl)
{
}
void HttpUploadHandler::handleUploadProcess(int id, long unsigned int sent,
long unsigned int total)
{
}
void HttpUploadHandler::handleUploadServiceRemoved(const gloox::JID &jid)
{
}
void HttpUploadHandler::handleUploadServiceAdded(const gloox::JID &jid,
unsigned long maxFileSize)
{
}
void HttpUploadHandler::handleFileSizeLimitChanged(unsigned long maxFileSize)
{
}
/*
* 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 HTTPUPLOADHANDLER_H
#define HTTPUPLOADHANDLER_H
// gloox
#include "gloox-extensions/httpuploadhandler.h"
#include "gloox-extensions/httpuploadmanager.h"
// Qt
#include <QObject>
namespace gloox {
class Client;
}
class QtHttpUploader;
/**
* @brief Class for handling and starting HTTP File Uploads
*/
class HttpUploadHandler : public QObject, public gloox::HttpUploadHandler
{
Q_OBJECT
public:
/**
* Default constructor
*/
HttpUploadHandler(gloox::Client *client, QObject *parent = nullptr);
gloox::HttpUploadManager* getUploadManager()
{
return manager;
}
protected:
/**
* Called, when a new upload service was added.
*
* @param jid The JID of the upload service that has been added
* @param maxFileSize The maximum file size for uploading to this service
*/
virtual void handleUploadServiceAdded(const gloox::JID &jid,
unsigned long maxFileSize);
/**
* Called, when an upload server has been removed.
*
* @param jid The JID of the upload service that has been removed
*/
virtual void handleUploadServiceRemoved(const gloox::JID &jid);
/**
* Called, when the file size limit has changed.
*
* @param maxFileSize The new maximum file size for uploading
*/
virtual void handleFileSizeLimitChanged(unsigned long maxFileSize);
/**
* Called, when the uploader made progress
*
* @param id Upload job id
* @param sent Number of bytes that has been sent
* @param total Number of total bytes to upload
*/
virtual void handleUploadProcess(int id, unsigned long sent,
unsigned long total);
/**
* Called, when an upload has successfully finished
*
* @param id Upload job id
* @param getUrl HTTPS GET url to share with others and download the file
*/
virtual void handleUploadFinished(int id, std::string &getUrl);
/**
* Called, when an upload job has failed
*
* @param id Upload job id
* @param error The error that has occured
* @param text An optional message about what went wrong
*/
virtual void handleUploadFailed(int id, gloox::HttpUploadError error,
const std::string &text = gloox::EmptyString,
const std::string &stamp = gloox::EmptyString);
private:
gloox::Client *client;
gloox::HttpUploadManager *manager;
QtHttpUploader *uploader;
};
#endif // HTTPUPLOADHANDLER_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 "QtHttpUploader.h"
#include "gloox-extensions/httpuploadmanager.h"
#include "gloox-extensions/httpuploadslot.h"
// Qt
#include <QFile>
#include <QFileInfo>
#include <QMimeDatabase>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
// Kaidan
#include "Globals.h"
UploadFile::UploadFile(QString name, QObject* parent) :
QFile(name, parent)
{
}
QByteArray UploadFile::read(qint64 maxSize)
{
QByteArray bytes = QFile::read(maxSize);
emit bytesRead(bytes);
return bytes;
}
QtHttpUploader::QtHttpUploader(gloox::HttpUploadManager *manager,
QObject *parent)
: QObject(parent), manager(manager)
{
manager->registerHttpUploader(this);
}
QtHttpUploader::~QtHttpUploader()
{
}
bool QtHttpUploader::busy()
{
return runningTasks != 0;
}
void QtHttpUploader::uploadFile(int id, std::string putUrl,
gloox::HeaderFieldMap putHeaders,
std::string &localPath, std::string &contentType)
{
// open file for read
UploadFile *file = new UploadFile(QString::fromStdString(localPath));
if (!file->open(QIODevice::ReadOnly)) {
manager->uploadFailed(id, gloox::UploadFileNotFound);
return;
}
// save empty data (will be used for saving hashing progress)
HashData hashData;
hashCache[id] = hashData;
// to not read the file several times, we'll generate the hashes directly
// while uploading
connect(file, &UploadFile::bytesRead, [=] (const QByteArray &bytes) {
processHashes(id, bytes);
});
//
// Create HTTP PUT request
//
QNetworkRequest request(QUrl(QString::fromStdString(putUrl)));
if (!contentType.empty())
request.setHeader(QNetworkRequest::ContentTypeHeader,
QString::fromStdString(contentType));
for (auto &field : putHeaders) {
request.setRawHeader(field.first.c_str(), field.second.c_str());
}
// send put request and start uploading
QNetworkAccessManager *netMngr = new QNetworkAccessManager();
QNetworkReply *reply = netMngr->put(request, file);
runningTasks++;
// handle finished
connect(reply, &QNetworkReply::finished, [=] () {
runningTasks--;
manager->uploadFinished(id);
// after this was handled by the manager, we can delete the hashes
hashCache.remove(id);
});
// error handling
connect(reply, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error),
[=] (QNetworkReply::NetworkError code) {
runningTasks--;
manager->uploadFailed(id, gloox::UploadHttpError);
hashCache.remove(id);
file->deleteLater();
netMngr->deleteLater();
reply->deleteLater();
});
// upload progress
connect(reply, &QNetworkReply::uploadProgress, [=] (qint64 sent, qint64 total) {
if (total < 0)
total = 0;
manager->uploadProgress(id, sent, total);
});
// delete everything when finished
connect(reply, &QNetworkReply::finished, file, &UploadFile::deleteLater);
connect(reply, &QNetworkReply::finished, netMngr, &QNetworkAccessManager::deleteLater);
connect(reply, &QNetworkReply::finished, reply, &QNetworkAccessManager::deleteLater);
}
void QtHttpUploader::processHashes(int id, const QByteArray &bytes)
{
hashCache[id].sha256->addData(bytes);
hashCache[id].sha3_256->addData(bytes);
}
QtHttpUploader::HashResult QtHttpUploader::getHashResults(int id) const
{
QtHttpUploader::HashResult result;
if (!hashCache.contains(id))
return result;
result.sha256 = hashCache[id].sha256->result();
result.sha3_256 = hashCache[id].sha3_256->result();
return result;
}
/*
* 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 QTHTTPUPLOADER_H
#define QTHTTPUPLOADER_H
#include <string.h>
#include "gloox-extensions/httpuploader.h"
#include <QObject>
#include <QFile>
#include <QCryptographicHash>
#include <QMap>
/**
* @class UploadFile Modified QFile for doing uploading and hashing, without
* reading multple times
*/
class UploadFile : public QFile
{
Q_OBJECT
public:
UploadFile(QString name, QObject *parent = nullptr);
QByteArray read(qint64 maxSize);
signals:
void bytesRead(const QByteArray &bytes);
};
/**
* @class QtHttpUploader Implementation of an HTTP File Uploader in Qt
*/
class QtHttpUploader : public QObject, public gloox::HttpUploader
{
Q_OBJECT
public:
struct HashResult {
QByteArray sha256;
QByteArray sha3_256;
};
/**
* Will register this uploader to the HttpUploadManager
*
* @param manager The HttpUploadManager this uploader will be used with
*/
QtHttpUploader(gloox::HttpUploadManager *manager, QObject *parent = nullptr);
~QtHttpUploader();
/**
* @return True, if currently uploading a file
*/
virtual bool busy();
/**
* It does supports parallel uploads
*/
virtual bool supportsParallel()
{
return true;
}
/**
* @see gloox::HttpUploader::uploadFile
*/
virtual void uploadFile(int id, std::string putUrl,
gloox::HeaderFieldMap putHeaders,
std::string &localPath, std::string &contentType);
/**
* Get all generated checksums of a file upload
*/
HashResult getHashResults(int id) const;
private:
struct HashData {
HashData()
: sha256(new QCryptographicHash(QCryptographicHash::Sha256)),
sha3_256(new QCryptographicHash(QCryptographicHash::Sha3_256))
{
};
QCryptographicHash *sha256;
QCryptographicHash *sha3_256;
};
void processHashes(int id, const QByteArray &bytes);
gloox::HttpUploadManager *manager;
unsigned int runningTasks = 0;
QMap<int, HashData> hashCache;
};
#endif // QTHTTPUPLOADER_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/>.
*/
#ifndef BITSOFBINARYCACHE_H__
#define BITSOFBINARYCACHE_H__
#include <gloox/jid.h>
namespace gloox {
class BitsOfBinaryData;
/**
* @class BitsOfBinaryCache A virtual interface that enables objects to
* cache Bits of Binary (@xep{0231}) data.
*
* XEP Version: 1.0
*
* @author Linus Jahn <lnj@kaidan.im>
* @since 1.0.21
*/
class BitsOfBinaryCache
{
public:
/**
* Checks if content ID is cached
*/
virtual bool hasCid(const std::string &cid) const = 0;
/**
* Gets a Bits of Binary data object from cache
*/
virtual BitsOfBinaryData* getByCid(const std::string& cid) = 0;
/**
* Add Bits of Binary data
*/
virtual void addBobData(BitsOfBinaryData *data) = 0;
};
}
#endif // BITSOFBINARYCACHE_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 "bitsofbinarydata.h"
#include "gloox-extensions.h"
#include <gloox/gloox.h>
#include <gloox/base64.h>
#include <gloox/sha.h>
#include <QString>
using namespace gloox;
BitsOfBinaryData::BitsOfBinaryData(std::string cid)
: StanzaExtension(EXT_BITSOFBINARY), m_cid(cid),
m_data(""), m_contentType(""), m_maxAge(-1),
m_valid(m_cid.length() >= 50)
{
}
BitsOfBinaryData::BitsOfBinaryData(std::string& data, std::string cid,
std::string contentType, long maxAge)
: StanzaExtension(EXT_BITSOFBINARY), m_cid(cid), m_data(data),
m_contentType(contentType), m_maxAge(maxAge)
{
if (!m_cid.length())
m_cid = generateContentId(m_data);
m_valid = m_cid.length() >= 58 && m_data.length();
}
BitsOfBinaryData::BitsOfBinaryData(const Tag* tag)
: StanzaExtension(EXT_BITSOFBINARY), m_valid(false), m_cid(""),
m_maxAge(-1), m_data(""), m_contentType("")
{
if (tag->name() != "data" || !tag->hasAttribute(XMLNS, XMLNS_BITSOFBINARY)) {
return;
}
m_cid = tag->findAttribute("cid");
m_contentType = tag->findAttribute("type");
m_data = tag->cdata();
if (tag->hasAttribute("max-age")) {
try {
// conversion can cause invalid_argument / out_of_range exception
m_maxAge = QString::fromStdString(tag->findAttribute("max-age")).toLong();
} catch (std::invalid_argument &e) {
// Couldn't parse size: input probably doesn't contain valid number
} catch (std::out_of_range &e) {
// Couldn't parse size: is out of range of an long
}
}
m_valid = true;
}
Tag* BitsOfBinaryData::tag() const
{
Tag* bobTag = new Tag("data", XMLNS, XMLNS_BITSOFBINARY);
// if not valid, return empty slot tag
if (!m_valid)
return bobTag;
bobTag->addAttribute("cid", m_cid);
if (m_maxAge >= 0)
bobTag->addAttribute("max-age", m_maxAge);
if (m_contentType.length() > 0)
bobTag->addAttribute("type", m_contentType);
if (m_data.length() > 0)
bobTag->addCData(m_data);
return bobTag;
}
const std::string& BitsOfBinaryData::filterString() const
{
static const std::string filter = "/iq/data[@xmlns='" + XMLNS_BITSOFBINARY +
"']";
return filter;
}
const std::string BitsOfBinaryData::generateContentId(const std::string& data,
bool isBase64)
{
std::string sha1Hex;
SHA hashGenerator;
if (isBase64)
hashGenerator.feed(Base64::decode64(data));
else
hashGenerator.feed(data);
hashGenerator.finalize();
sha1Hex = hashGenerator.hex();
return "sha1+" + sha1Hex + "@bob.xmpp.org";
}
/*
* 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