mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 18:20:23 +00:00
New CLI flags: "-ws": Use the websocket protocols instead of tcp "-p <port number>": Use the designated port number for the server.
71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
// ===============================
|
|
// PC-BSD REST/JSON API Server
|
|
// Available under the 3-clause BSD License
|
|
// Written by: Ken Moore <ken@pcbsd.org> July 2015
|
|
// =================================
|
|
#ifndef _PCBSD_REST_WEB_SOCKET_H
|
|
#define _PCBSD_REST_WEB_SOCKET_H
|
|
|
|
#include <QWebSocket>
|
|
#include <QTcpSocket>
|
|
#include <QList>
|
|
#include <QObject>
|
|
#include <QJsonDocument>
|
|
#include <QJsonArray>
|
|
#include <QJsonObject>
|
|
#include <QJsonValue>
|
|
#include <QTimer>
|
|
|
|
|
|
#include "RestStructs.h"
|
|
#include "AuthorizationManager.h"
|
|
|
|
class WebSocket : public QObject{
|
|
Q_OBJECT
|
|
public:
|
|
WebSocket(QWebSocket*, QString ID, AuthorizationManager *auth);
|
|
WebSocket(QTcpSocket*, QString ID, AuthorizationManager *auth);
|
|
~WebSocket();
|
|
|
|
QString ID();
|
|
void setLastDispatch(QString); //used on initialization only
|
|
|
|
private:
|
|
QTimer *idletimer;
|
|
QWebSocket *SOCKET;
|
|
QTcpSocket *TSOCKET;
|
|
QString SockID, SockAuthToken, lastDispatchEvent;
|
|
AuthorizationManager *AUTHSYSTEM;
|
|
bool SendAppCafeEvents;
|
|
|
|
//Main connection comminucations procedure
|
|
void EvaluateREST(QString); //Text -> Rest/JSON struct
|
|
void EvaluateRequest(const RestInputStruct&); // Parse Rest/JSON (does auth/events)
|
|
|
|
//Simplification functions
|
|
QString JsonValueToString(QJsonValue);
|
|
QStringList JsonArrayToStringList(QJsonArray);
|
|
void SetOutputError(QJsonObject *ret, QString id, int err, QString msg);
|
|
|
|
//Backend request/reply functions (contained in WebBackend.cpp)
|
|
void EvaluateBackendRequest(QString name, const QJsonValue in_args, QJsonObject *out);
|
|
|
|
private slots:
|
|
void checkIdle(); //see if the currently-connected client is idle
|
|
void SocketClosing();
|
|
|
|
//Currently connected socket signal/slot connections
|
|
void EvaluateMessage(const QByteArray&);
|
|
void EvaluateMessage(const QString&);
|
|
void EvaluateTcpMessage();
|
|
|
|
public slots:
|
|
void AppCafeStatusUpdate(QString msg = "");
|
|
|
|
signals:
|
|
void SocketClosed(QString); //ID
|
|
|
|
};
|
|
|
|
#endif
|