first commit

This commit is contained in:
bing
2026-04-03 11:32:07 +08:00
commit 003be19522
1142 changed files with 185854 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm 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 XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_HTTP_COOKIE_H_
#define _QX_HTTP_COOKIE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxHttpCookie.h
* \author XDL Team
* \ingroup QxHttpServer
* \brief HTTP cookie (https://www.qxorm.com/qxorm_en/manual.html#manual_999)
*/
namespace qx
{
/*!
* \ingroup QxHttpServer
* \brief qx::QxHttpCookie : HTTP cookie (https://www.qxorm.com/qxorm_en/manual.html#manual_999)
*/
struct QX_DLL_EXPORT QxHttpCookie
{
QByteArray name; //!< Cookie name
QByteArray value; //!< Cookie value
QByteArray domain; //!< Cookie domain : specifies those hosts to which the cookie will be sent, if not specified defaults to the host portion of the current document location (but not including subdomains)
QByteArray path; //!< Cookie path : indicates a URL path that must exist in the requested resource before sending the Cookie header
qlonglong maxAge; //!< Cookie max-age : number of seconds until the cookie expires (a zero or negative number will expire the cookie immediately)
bool secure; //!< Cookie secure : a secure cookie will only be sent to the server when a request is made using SSL and the HTTPS protocol
bool httpOnly; //!< Cookie http-only : HTTP-only cookies aren't accessible via JavaScript through the Document.cookie property, the XMLHttpRequest and Request APIs to mitigate attacks against cross-site scripting
QxHttpCookie();
QxHttpCookie(const QByteArray &name_, const QByteArray &value_, const QByteArray &domain_ = QByteArray(), const QByteArray &path_ = QByteArray("/"), qlonglong maxAge_ = 0, bool secure_ = false, bool httpOnly_ = false);
~QxHttpCookie();
QByteArray toString() const;
static QHash<QByteArray, QxHttpCookie> parse(const QByteArray &cookies);
};
} // namespace qx
#endif // _QX_HTTP_COOKIE_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,94 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm 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 XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_HTTP_REQUEST_H_
#define _QX_HTTP_REQUEST_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxHttpRequest.h
* \author XDL Team
* \ingroup QxHttpServer
* \brief HTTP request (headers + body)
*/
#include <QtCore/qurl.h>
#include <QxHttpServer/QxHttpCookie.h>
namespace qx
{
class QxHttpTransaction;
/*!
* \ingroup QxHttpServer
* \brief qx::QxHttpRequest : HTTP request (headers + body)
*/
class QX_DLL_EXPORT QxHttpRequest
{
private:
struct QxHttpRequestImpl;
std::unique_ptr<QxHttpRequestImpl> m_pImpl; //!< Private implementation idiom
public:
QxHttpRequest(QxHttpTransaction *transaction);
virtual ~QxHttpRequest();
QUrl &url();
QString &command();
QString &version();
QByteArray &data();
QHash<QByteArray, QByteArray> &headers();
QByteArray header(const QByteArray &key);
QHash<QByteArray, QxHttpCookie> &cookies();
QxHttpCookie cookie(const QByteArray &name);
QHash<QString, QVariant> &dispatchParams();
QHash<QString, QString> &params();
QString param(const QString &key);
QString &sourceAddress();
long &sourcePort();
QString guid() const;
};
typedef std::shared_ptr<QxHttpRequest> QxHttpRequest_ptr;
} // namespace qx
typedef qx::QxHttpRequest qx_http_request;
#endif // _QX_HTTP_REQUEST_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,91 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm 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 XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_HTTP_RESPONSE_H_
#define _QX_HTTP_RESPONSE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxHttpResponse.h
* \author XDL Team
* \ingroup QxHttpServer
* \brief HTTP response (headers + body)
*/
#include <QxHttpServer/QxHttpCookie.h>
#ifndef Q_MOC_RUN
#include <QxCommon/QxBool.h>
#endif // Q_MOC_RUN
namespace qx
{
class QxHttpTransaction;
/*!
* \ingroup QxHttpServer
* \brief qx::QxHttpResponse : HTTP response (headers + body)
*/
class QX_DLL_EXPORT QxHttpResponse
{
private:
struct QxHttpResponseImpl;
std::unique_ptr<QxHttpResponseImpl> m_pImpl; //!< Private implementation idiom
public:
QxHttpResponse(QxHttpTransaction *transaction);
virtual ~QxHttpResponse();
int &status();
QByteArray &data();
QByteArray statusDesc();
QHash<QByteArray, QByteArray> &headers();
QByteArray header(const QByteArray &key);
QHash<QByteArray, QxHttpCookie> &cookies();
QxHttpCookie cookie(const QByteArray &name);
qx_bool writeChunked(const QByteArray &data);
bool isChunked() const;
};
typedef std::shared_ptr<QxHttpResponse> QxHttpResponse_ptr;
} // namespace qx
typedef qx::QxHttpResponse qx_http_response;
#endif // _QX_HTTP_RESPONSE_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,133 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm 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 XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef Q_MOC_RUN
#include <QxCommon/QxConfig.h> // Need to include this file for the 'moc' process
#endif // Q_MOC_RUN
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_HTTP_SERVER_H_
#define _QX_HTTP_SERVER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxHttpServer.h
* \author XDL Team
* \ingroup QxHttpServer
* \brief HTTP server which manages connections in a multi-threaded environment (support SSL/TLS, persistent connection, etc...) : https://www.qxorm.com/qxorm_en/manual.html#manual_96
*/
#ifdef _QX_NO_PRECOMPILED_HEADER
#ifndef Q_MOC_RUN
#include <QxPrecompiled.h> // Need to include precompiled header for the generated moc file
#endif // Q_MOC_RUN
#endif // _QX_NO_PRECOMPILED_HEADER
#include <QxHttpServer/QxHttpRequest.h>
#include <QxHttpServer/QxHttpResponse.h>
#include <QxHttpServer/QxHttpTransaction.h>
#ifndef Q_MOC_RUN
#include <QxService/QxTransaction.h>
#include <QxService/QxConnect.h>
#include <QxService/QxServer.h>
#endif // Q_MOC_RUN
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
class QAbstractEventDispatcher;
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
namespace qx
{
/*!
* \ingroup QxHttpServer
* \brief qx::QxHttpServer : HTTP server which manages connections in a multi-threaded environment (support SSL/TLS, persistent connection, etc...) : https://www.qxorm.com/qxorm_en/manual.html#manual_96
*/
class QX_DLL_EXPORT QxHttpServer : public QObject
{
Q_OBJECT
public:
typedef std::function<void(qx::QxHttpRequest &, qx::QxHttpResponse &)> type_fct_custom_request_handler;
private:
struct QxHttpServerImpl;
std::unique_ptr<QxHttpServerImpl> m_pImpl; //!< Private implementation idiom
public:
QxHttpServer(QObject *parent = NULL);
virtual ~QxHttpServer();
Q_INVOKABLE void startServer();
Q_INVOKABLE void stopServer();
void setCustomRequestHandler(type_fct_custom_request_handler fct);
QxHttpServer &dispatch(const QString &command, const QString &path, type_fct_custom_request_handler fct, long position = -1);
void beforeDispatching(type_fct_custom_request_handler fct);
void afterDispatching(type_fct_custom_request_handler fct);
void clearDispatcher();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
void setEventDispatcher(QAbstractEventDispatcher *pEventDispatcher);
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
static void buildResponseStaticFile(qx::QxHttpRequest &request, qx::QxHttpResponse &response, const QString &serverPath, qlonglong chunkedSize = 0);
static void buildResponseQxRestApi(qx::QxHttpRequest &request, qx::QxHttpResponse &response);
Q_SIGNALS:
void error(const QString &err, qx::QxHttpTransaction_ptr transaction);
void transactionStarted(qx::QxHttpTransaction_ptr transaction);
void transactionFinished(qx::QxHttpTransaction_ptr transaction);
void serverStatusChanged(bool bIsRunning);
private Q_SLOTS:
void onError(const QString &err, qx::service::QxTransaction_ptr transaction);
void onServerIsRunning(bool bIsRunning, qx::service::QxServer *pServer);
void onTransactionStarted(qx::service::QxTransaction_ptr transaction);
void onTransactionFinished(qx::service::QxTransaction_ptr transaction);
void onCustomRequestHandler(qx::service::QxTransaction_ptr transaction);
};
typedef std::shared_ptr<QxHttpServer> QxHttpServer_ptr;
} // namespace qx
typedef qx::QxHttpServer qx_http_server;
#endif // _QX_HTTP_SERVER_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,91 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm 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 XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_HTTP_SESSION_H_
#define _QX_HTTP_SESSION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxHttpSession.h
* \author XDL Team
* \ingroup QxHttpServer
* \brief HTTP session (https://www.qxorm.com/qxorm_en/manual.html#manual_998)
*/
namespace qx
{
class QxHttpSessionManager;
/*!
* \ingroup QxHttpServer
* \brief qx::QxHttpSession : HTTP session (https://www.qxorm.com/qxorm_en/manual.html#manual_998)
*/
class QX_DLL_EXPORT QxHttpSession
{
friend class qx::QxHttpSessionManager;
private:
struct QxHttpSessionImpl;
std::unique_ptr<QxHttpSessionImpl> m_pImpl; //!< Private implementation idiom
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
public: // Some older compilers don't support std::shared_ptr with private custom deleter, but for Qt5 we assume that all compilers should support it
#endif // (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
QxHttpSession();
~QxHttpSession();
public:
QByteArray id();
QDateTime lastAccess();
void lastAccess(const QDateTime &dt);
QVariant get(const QByteArray &key);
void set(const QByteArray &key, const QVariant &value);
QHash<QByteArray, QVariant> getAll();
void remove(const QByteArray &key);
void clear();
};
typedef std::shared_ptr<QxHttpSession> QxHttpSession_ptr;
} // namespace qx
typedef qx::QxHttpSession qx_http_session;
typedef qx::QxHttpSession_ptr qx_http_session_ptr;
#endif // _QX_HTTP_SESSION_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,103 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm 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 XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef Q_MOC_RUN
#include <QxCommon/QxConfig.h> // Need to include this file for the 'moc' process
#endif // Q_MOC_RUN
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_HTTP_SESSION_MANAGER_H_
#define _QX_HTTP_SESSION_MANAGER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxHttpSessionManager.h
* \author XDL Team
* \ingroup QxHttpServer
* \brief HTTP session manager (https://www.qxorm.com/qxorm_en/manual.html#manual_998)
*/
#ifdef _QX_NO_PRECOMPILED_HEADER
#ifndef Q_MOC_RUN
#include <QxPrecompiled.h> // Need to include precompiled header for the generated moc file
#endif // Q_MOC_RUN
#endif // _QX_NO_PRECOMPILED_HEADER
#ifndef Q_MOC_RUN
#include <QxSingleton/QxSingleton.h>
#endif // Q_MOC_RUN
#include <QxHttpServer/QxHttpSession.h>
#include <QxHttpServer/QxHttpRequest.h>
#include <QxHttpServer/QxHttpResponse.h>
namespace qx
{
/*!
* \ingroup QxHttpServer
* \brief qx::QxHttpSessionManager : HTTP session manager (https://www.qxorm.com/qxorm_en/manual.html#manual_998)
*/
class QX_DLL_EXPORT QxHttpSessionManager : public QObject, public qx::QxSingleton<QxHttpSessionManager>
{
Q_OBJECT
friend class qx::QxSingleton<QxHttpSessionManager>;
private:
struct QxHttpSessionManagerImpl;
std::unique_ptr<QxHttpSessionManagerImpl> m_pImpl; //!< Private implementation idiom
QxHttpSessionManager();
virtual ~QxHttpSessionManager();
public:
static qx::QxHttpSession_ptr getSession(qx::QxHttpRequest &request, qx::QxHttpResponse &response, const QByteArray &cookieName = QByteArray("qx_session_id"), bool autoCreateSession = true);
static qx::QxHttpSession_ptr createSession(qx::QxHttpRequest &request, qx::QxHttpResponse &response, const QByteArray &cookieName = QByteArray("qx_session_id"));
static void removeSession(qx::QxHttpRequest &request, qx::QxHttpResponse &response, const QByteArray &cookieName = QByteArray("qx_session_id"));
private Q_SLOTS:
void onCheckSessionTimeOut();
private:
static void deleteSession(qx::QxHttpSession *p);
};
} // namespace qx
QX_DLL_EXPORT_QX_SINGLETON_HPP(qx::QxHttpSessionManager)
#endif // _QX_HTTP_SESSION_MANAGER_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,99 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm 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 XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef Q_MOC_RUN
#include <QxCommon/QxConfig.h> // Need to include this file for the 'moc' process
#endif // Q_MOC_RUN
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_HTTP_TRANSACTION_H_
#define _QX_HTTP_TRANSACTION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxHttpTransaction.h
* \author XDL Team
* \ingroup QxHttpServer
* \brief HTTP transaction (contains request from client and reply from server)
*/
#ifdef _QX_NO_PRECOMPILED_HEADER
#ifndef Q_MOC_RUN
#include <QxPrecompiled.h> // Need to include precompiled header for the generated moc file
#endif // Q_MOC_RUN
#endif // _QX_NO_PRECOMPILED_HEADER
#include <QxService/QxTransaction.h>
#include <QxHttpServer/QxHttpRequest.h>
#include <QxHttpServer/QxHttpResponse.h>
namespace qx
{
/*!
* \ingroup QxHttpServer
* \brief qx::QxHttpTransaction : HTTP transaction (contains request from client and reply from server)
*/
class QX_DLL_EXPORT QxHttpTransaction : public qx::service::QxTransaction
{
Q_OBJECT
private:
struct QxHttpTransactionImpl;
std::unique_ptr<QxHttpTransactionImpl> m_pImpl; //!< Private implementation idiom
public:
QxHttpTransaction();
virtual ~QxHttpTransaction();
qx::QxHttpRequest &request();
qx::QxHttpResponse &response();
qx_bool writeChunked(const QByteArray &data);
virtual void clear();
virtual void executeServer();
virtual qx_bool writeSocketServer(QTcpSocket &socket);
virtual qx_bool readSocketServer(QTcpSocket &socket);
};
typedef std::shared_ptr<QxHttpTransaction> QxHttpTransaction_ptr;
} // namespace qx
typedef qx::QxHttpTransaction qx_http_transaction;
#endif // _QX_HTTP_TRANSACTION_H_
#endif // _QX_ENABLE_QT_NETWORK