2019-09-14 13:03:34 -04:00
|
|
|
#ifndef SOCKET_H
|
|
|
|
#define SOCKET_H
|
|
|
|
|
|
|
|
// This file is part of Cmdr.
|
|
|
|
|
|
|
|
// Cmdr 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.
|
|
|
|
|
|
|
|
// Cmdr 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 Cmdr under the LICENSE.md file. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/x509.h>
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QSslSocket>
|
|
|
|
#include <QHostAddress>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QAbstractSocket>
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QTextCodec>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QXmlStreamWriter>
|
|
|
|
#include <QSsl>
|
|
|
|
#include <QSslKey>
|
|
|
|
#include <QSslCipher>
|
|
|
|
#include <QSslCertificate>
|
|
|
|
#include <QSocketNotifier>
|
2020-03-10 19:04:48 -04:00
|
|
|
#include <QTimer>
|
2019-09-14 13:03:34 -04:00
|
|
|
|
|
|
|
#include "cmd_objs/command.h"
|
|
|
|
#include "cmd_objs/bookmarks.h"
|
2019-11-23 14:37:41 -05:00
|
|
|
#include "cmd_objs/host_doc.h"
|
2019-09-14 13:03:34 -04:00
|
|
|
|
|
|
|
#define SERVER_HEADER_TAG "MRCI"
|
|
|
|
#define CLIENT_HEADER_LEN 410
|
2020-04-05 19:07:08 -04:00
|
|
|
#define SERVER_HEADER_LEN 37
|
2019-11-23 14:37:41 -05:00
|
|
|
#define FRAME_HEADER_LEN 8
|
2019-09-14 13:03:34 -04:00
|
|
|
|
|
|
|
class Session : public QSslSocket
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2020-03-10 19:04:48 -04:00
|
|
|
QTimer *progResetDelay;
|
2019-11-23 14:37:41 -05:00
|
|
|
quint32 flags;
|
|
|
|
quint32 dSize;
|
2019-09-14 13:03:34 -04:00
|
|
|
quint16 cmdId;
|
2019-11-23 14:37:41 -05:00
|
|
|
quint16 branId;
|
2019-09-14 13:03:34 -04:00
|
|
|
quint16 hook;
|
2019-11-23 14:37:41 -05:00
|
|
|
quint8 dType;
|
2020-03-10 19:04:48 -04:00
|
|
|
bool activeProg;
|
2019-09-14 13:03:34 -04:00
|
|
|
bool reconnect;
|
|
|
|
|
2019-12-04 22:01:52 -05:00
|
|
|
void cacheTxt(quint8 typeId, QString txt);
|
2019-09-14 13:03:34 -04:00
|
|
|
void dataFromHost(const QByteArray &data);
|
2019-11-23 14:37:41 -05:00
|
|
|
void procAsync(const QByteArray &data);
|
2020-03-10 19:04:48 -04:00
|
|
|
void updateProg(int value);
|
2019-11-23 14:37:41 -05:00
|
|
|
bool isAsync(quint16 id);
|
2019-09-14 13:03:34 -04:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
void dataIn();
|
|
|
|
void isConnected();
|
|
|
|
void isDisconnected();
|
|
|
|
void handShakeDone();
|
2020-03-10 19:04:48 -04:00
|
|
|
void resetProg();
|
|
|
|
void startProg();
|
2019-09-14 13:03:34 -04:00
|
|
|
void sockerr(QAbstractSocket::SocketError err);
|
2020-04-05 19:07:08 -04:00
|
|
|
void sslErrs(const QList<QSslError> &errors);
|
2019-09-14 13:03:34 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum SessionFlags : uint
|
|
|
|
{
|
|
|
|
VER_OK = 1,
|
|
|
|
DSIZE_RDY = 1 << 2,
|
|
|
|
GEN_FILE_ON = 1 << 3
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit Session(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
2019-11-23 14:37:41 -05:00
|
|
|
void hookedBinToServer(const QByteArray &data, quint8 typeId);
|
|
|
|
void binToServer(quint16 cmdId, const QByteArray &data, quint8 typeId);
|
2019-09-14 13:03:34 -04:00
|
|
|
void enableGenFile(bool state);
|
2019-12-14 13:50:36 -05:00
|
|
|
void setCmdHook(quint16 cmdId);
|
|
|
|
void idle();
|
2019-09-14 13:03:34 -04:00
|
|
|
void termHostCmd();
|
2020-03-10 19:04:48 -04:00
|
|
|
void yieldHostCmd();
|
2019-11-23 14:37:41 -05:00
|
|
|
void resumeHostCmd();
|
2019-09-14 13:03:34 -04:00
|
|
|
void connectToServ();
|
|
|
|
void disconnectFromServ();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
void hostFinished();
|
2019-12-04 22:01:52 -05:00
|
|
|
void txtInCache();
|
|
|
|
void loopDataIn();
|
2020-03-10 19:04:48 -04:00
|
|
|
void showProg(bool);
|
|
|
|
void setProg(int);
|
2019-09-14 13:03:34 -04:00
|
|
|
void setUserIO(int flgs);
|
|
|
|
void unsetUserIO(int flgs);
|
2019-11-23 14:37:41 -05:00
|
|
|
void hostCmdRemoved(quint16 id);
|
2019-09-14 13:03:34 -04:00
|
|
|
void toGenFile(const QByteArray &data);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SOCKET_H
|