/**************************************************************************** ** ** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtHttpServer module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:GPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3 or (at your option) any later version ** approved by the KDE Free Qt Foundation. The licenses are as published by ** the Free Software Foundation and appearing in the file LICENSE.GPL3 ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QHTTPSERVERROUTER_H #define QHTTPSERVERROUTER_H #include #include #include #include #include #include #include QT_BEGIN_NAMESPACE namespace QtPrivate { template struct QHttpServerRouterPlaceholder {}; } QT_END_NAMESPACE namespace std { template struct is_placeholder)> : integral_constant {}; } QT_BEGIN_NAMESPACE class QTcpSocket; class QHttpServerRequest; class QHttpServerRouterRule; class QHttpServerRouterPrivate; class Q_HTTPSERVER_EXPORT QHttpServerRouter { Q_DECLARE_PRIVATE(QHttpServerRouter) public: QHttpServerRouter(); ~QHttpServerRouter(); template bool addConverter(const QLatin1String ®exp) { static_assert(QMetaTypeId2::Defined, "Type is not registered with Qt's meta-object system: " "please apply Q_DECLARE_METATYPE() to it"); if (!QMetaType::registerConverter()) return false; addConverter(qMetaTypeId(), regexp); return true; } void addConverter(const int type, const QLatin1String ®exp); void removeConverter(const int); void clearConverters(); const QMap &converters() const; static const QMap &defaultConverters(); template> bool addRule(QHttpServerRouterRule *rule) { return addRuleHelper( rule, typename ViewTraits::Arguments::Indexes{}); } template> typename ViewTraits::BindableType bindCaptured(ViewHandler &&handler, const QRegularExpressionMatch &match) const { return bindCapturedImpl( std::forward(handler), match, typename ViewTraits::Arguments::CapturableIndexes{}, typename ViewTraits::Arguments::PlaceholdersIndexes{}); } bool handleRequest(const QHttpServerRequest &request, QTcpSocket *socket) const; private: template bool addRuleHelper(QHttpServerRouterRule *rule, QtPrivate::IndexesList) { const std::initializer_list types = { ViewTraits::Arguments::template metaTypeId()...}; return addRuleImpl(rule, types); } bool addRuleImpl(QHttpServerRouterRule *rule, const std::initializer_list &metaTypes); template typename std::enable_if::type bindCapturedImpl(ViewHandler &&handler, const QRegularExpressionMatch &match, QtPrivate::IndexesList, QtPrivate::IndexesList) const { return std::bind( std::forward(handler), QVariant(match.captured(Cx + 1)) .value::CleanType>()..., QtPrivate::QHttpServerRouterPlaceholder{}...); } template typename std::enable_if::type bindCapturedImpl(ViewHandler &&handler, const QRegularExpressionMatch &, QtPrivate::IndexesList, QtPrivate::IndexesList) const { return std::bind( std::forward(handler), QtPrivate::QHttpServerRouterPlaceholder{}...); } QScopedPointer d_ptr; }; QT_END_NAMESPACE #endif // QHTTPSERVERROUTER_H