29 #ifndef TRM_QT_WEBSOCKET_PROXY_H_
30 #define TRM_QT_WEBSOCKET_PROXY_H_
35 #include <sys/syscall.h>
38 #include <QtCore/QObject>
39 #include <QtCore/QList>
40 #include <QtCore/QMap>
41 #include <QtCore/QTimer>
42 #include <QtCore/QTime>
43 #include <QtCore/QByteArray>
44 #include <QAbstractSocket>
46 #include <QtNetwork/QSslError>
49 #include "tcpOpensslProxyServer.h"
51 class QWebSocketServer;
60 explicit WebSocketProxy(
const QStringList &boundIPs, quint16 port, QObject *parent = Q_NULLPTR);
62 int onWebsocketHasDataToWriteSSL(
int clientId,
char* data,
int len);
63 void onRemoveAllOpenSslConnections();
64 std::unordered_map <int, PingPongTask*>sslProxyPingPongTasks;
71 void onSslErrors(
const QList<QSslError> &errors);
72 void onAcceptError(QAbstractSocket::SocketError socketError);
73 void onPeerVerifyError(
const QSslError &error);
75 void onNewConnection(
void);
76 void onWebsocketConnect(
void);
77 void onWebsocketBinaryMessageReceived(QByteArray byteArray);
78 void onWebsocketTextMessageReceived(QString);
79 void onWebsocketBytesWritten(qint64);
80 void onWebsocketDisconnected(
void);
81 void onWebsocketStateChanged(QAbstractSocket::SocketState);
82 void onWebSocketAboutClose(
void);
83 void onWebsocketError(QAbstractSocket::SocketError);
84 void onWebsocketHasDataToWrite(
void *,
void*);
85 void onRemoveConnection(
void *);
88 void onWebsocketConnectSSL(
int clientId, QString msg);
89 void onSslErrorsSSL(QString err);
90 void onAcceptErrorSSL(QString err);
91 void onPeerVerifyErrorSSL(QString err);
92 void onWebsocketDisconnectedSSL(
int clientId);
93 void onWebsocketErrorSSL(QString err);
96 QMap<QString, QWebSocketServer *>proxyServers;
97 QMap<QString, tcpOpensslProxyServer *>sslProxyServers;
98 std::unordered_map <int, tcpOpensslProxyServer *>sslProxyMap;
99 QList<QWebSocket *> connections;
100 QMap<QWebSocket *, PingPongTask *> pingPongTasks;
114 void onTimeout(
void);
115 void onPong(quint64 elapsedTime, QByteArray);
118 QWebSocket* wssocket;
126 #define _TRMPRX_OUT_ stdout
127 #define __TIMESTAMP() do { \
129 struct timeval __tv; \
130 gettimeofday(&__tv, NULL); \
131 localtime_r(&__tv.tv_sec, &__tm); \
132 fprintf(_TRMPRX_OUT_, "\r\n[tid=%ld]: %02d%02d%02d-%02d:%02d:%02d:%06d ", \
133 syscall(SYS_gettid), \
134 __tm.tm_year+1900-2000, \
140 (int)__tv.tv_usec); \
143 #endif //TRM_WEBSOCKET_PROXY_H_