Removed utils as they are now moved into common lib
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils/jsonutils.h"
|
||||||
#include "webplugin.h"
|
#include "webplugin.h"
|
||||||
#include "weblistener.h"
|
#include "weblistener.h"
|
||||||
#include "webapplication.h"
|
#include "webapplication.h"
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
QT += core network
|
QT += core network
|
||||||
QT -= gui widgets
|
QT -= gui widgets
|
||||||
|
|
||||||
DBLIBS += webserverlib
|
DBLIBS += dbcore webserverlib
|
||||||
|
|
||||||
PROJECT_ROOT = ../..
|
PROJECT_ROOT = ../..
|
||||||
|
|
||||||
|
@@ -1,47 +0,0 @@
|
|||||||
#include "utils.h"
|
|
||||||
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
|
|
||||||
QHostAddress parseHostAddress(const QString &hostAddress)
|
|
||||||
{
|
|
||||||
static const QMap<QString, QHostAddress> specialHostAddresses {
|
|
||||||
{ QStringLiteral("QHostAddress::Null"), QHostAddress::Null },
|
|
||||||
{ QStringLiteral("QHostAddress::Broadcast"), QHostAddress::Broadcast },
|
|
||||||
{ QStringLiteral("QHostAddress::LocalHost"), QHostAddress::LocalHost },
|
|
||||||
{ QStringLiteral("QHostAddress::LocalHostIPv6"), QHostAddress::LocalHostIPv6 },
|
|
||||||
{ QStringLiteral("QHostAddress::Any"), QHostAddress::Any },
|
|
||||||
{ QStringLiteral("QHostAddress::AnyIPv6"), QHostAddress::AnyIPv6 },
|
|
||||||
{ QStringLiteral("QHostAddress::AnyIPv4"), QHostAddress::AnyIPv4 }
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto iter = specialHostAddresses.find(hostAddress);
|
|
||||||
if(iter != specialHostAddresses.constEnd())
|
|
||||||
return *iter;
|
|
||||||
|
|
||||||
return QHostAddress(hostAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
QJsonDocument getJson<QJsonDocument>(const QJsonDocument &document)
|
|
||||||
{
|
|
||||||
return document;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
QJsonObject getJson<QJsonObject>(const QJsonDocument &document)
|
|
||||||
{
|
|
||||||
if(!document.isObject())
|
|
||||||
throw std::runtime_error("JSON document does not contain an object!");
|
|
||||||
|
|
||||||
return document.object();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
QJsonArray getJson<QJsonArray>(const QJsonDocument &document)
|
|
||||||
{
|
|
||||||
if(!document.isArray())
|
|
||||||
throw std::runtime_error("JSON document does not contain an object!");
|
|
||||||
|
|
||||||
return document.array();
|
|
||||||
}
|
|
@@ -1,60 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QHostAddress>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonParseError>
|
|
||||||
#include <QFile>
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
QHostAddress parseHostAddress(const QString &hostAddress);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T getJson(const QJsonDocument &document);
|
|
||||||
|
|
||||||
template<>
|
|
||||||
QJsonDocument getJson<QJsonDocument>(const QJsonDocument &document);
|
|
||||||
|
|
||||||
template<>
|
|
||||||
QJsonObject getJson<QJsonObject>(const QJsonDocument &document);
|
|
||||||
|
|
||||||
template<>
|
|
||||||
QJsonArray getJson<QJsonArray>(const QJsonDocument &document);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T getJson(const QByteArray &byteArray);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T getJson(QIODevice &device);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T getJson(const QString &filename);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T getJson(const QByteArray &byteArray)
|
|
||||||
{
|
|
||||||
QJsonParseError error;
|
|
||||||
auto document = QJsonDocument::fromJson(byteArray, &error);
|
|
||||||
if(error.error != QJsonParseError::NoError)
|
|
||||||
throw std::runtime_error(QString("Could not parse json: %0").arg(error.errorString()).toStdString());
|
|
||||||
|
|
||||||
return getJson<T>(document);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T getJson(QIODevice &device)
|
|
||||||
{
|
|
||||||
return getJson<T>(device.readAll());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T getJson(const QString &filename)
|
|
||||||
{
|
|
||||||
QFile file(filename);
|
|
||||||
if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
|
|
||||||
throw std::runtime_error(QString("Could not open json file %0: %1").arg(filename, file.errorString()).toStdString());
|
|
||||||
|
|
||||||
return getJson<T>(file);
|
|
||||||
}
|
|
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils/netutils.h"
|
||||||
#include "httpclientconnection.h"
|
#include "httpclientconnection.h"
|
||||||
|
|
||||||
WebListener::WebListener(const QJsonObject &config, const QHash<QString, WebApplication*> &applications, QObject *parent) :
|
WebListener::WebListener(const QJsonObject &config, const QHash<QString, WebApplication*> &applications, QObject *parent) :
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
QT += core network
|
QT += core network
|
||||||
QT -= gui widgets
|
QT -= gui widgets
|
||||||
|
|
||||||
|
DBLIBS += dbnetwork
|
||||||
|
|
||||||
PROJECT_ROOT = ../..
|
PROJECT_ROOT = ../..
|
||||||
|
|
||||||
DEFINES += WEBSERVERLIB_LIBRARY
|
DEFINES += WEBSERVERLIB_LIBRARY
|
||||||
@@ -9,7 +11,6 @@ SOURCES += \
|
|||||||
weblistener.cpp \
|
weblistener.cpp \
|
||||||
webapplication.cpp \
|
webapplication.cpp \
|
||||||
webplugin.cpp \
|
webplugin.cpp \
|
||||||
utils.cpp \
|
|
||||||
httpclientconnection.cpp \
|
httpclientconnection.cpp \
|
||||||
httpcontainers.cpp
|
httpcontainers.cpp
|
||||||
|
|
||||||
@@ -17,7 +18,6 @@ HEADERS += webserverlib_global.h \
|
|||||||
weblistener.h \
|
weblistener.h \
|
||||||
webapplication.h \
|
webapplication.h \
|
||||||
webplugin.h \
|
webplugin.h \
|
||||||
utils.h \
|
|
||||||
httpclientconnection.h \
|
httpclientconnection.h \
|
||||||
httpcontainers.h
|
httpcontainers.h
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user