-
Notifications
You must be signed in to change notification settings - Fork 0
/
relay.h
118 lines (90 loc) · 1.93 KB
/
relay.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef RELAY_H
#define RELAY_H
#include <QByteArray>
#include <QElapsedTimer>
#include <QSharedPointer>
#include <QString>
#include <QTcpServer>
#include <QVector>
class QTcpSocket;
class PendingConnection {
public:
QTcpSocket * socket;
QByteArray buffer;
PendingConnection ();
};
class Transfer {
public:
QTcpSocket * uploaderSocket;
QTcpSocket * downloaderSocket;
QString key;
QByteArray buffer;
qint64 bufferLimit;
qint64 totalBytesWritten;
qint64 expectedContentLength;
QElapsedTimer waitForUploaderTimer;
Transfer ();
~Transfer ();
qint64 maxRead () const;
void readData ();
void write100 ();
void write307 ();
void writeData ();
};
enum class EConnectionType {
Unknown,
Invalid,
Uploader,
Downloader,
Info
};
class ParsedHeader {
public:
EConnectionType type;
// For uploaders
QString fileName;
qint64 expectedContentLength;
// For downloaders
QString url;
ParsedHeader () {
type = EConnectionType::Unknown;
}
};
class RelaySettings {
public:
qint32 port;
RelaySettings ();
RelaySettings (int, char * []);
void setToDefaults ();
};
class Relay : public QObject
{
Q_OBJECT
public:
explicit Relay(RelaySettings, QObject *parent = 0);
signals:
public slots:
protected:
RelaySettings settings;
qint64 serialNumber;
qint64 bufferSize;
QTcpServer server;
QByteArray httpHeaderEnd;
QByteArray transferDir;
QString serverName;
QVector <PendingConnection> pendingConnections;
QVector <QSharedPointer <Transfer> > transfers;
void discardPendingConnectionBySocket (QTcpSocket *);
void discardTransferBySocket (QTcpSocket *);
int findPendingConnection (QTcpSocket *);
int findTransfer (QTcpSocket *);
int findTransfer (QString);
ParsedHeader parseHeaders (const QByteArray);
void cullFailedRedirections ();
void writeHeaders (QTcpSocket &, qint64);
protected slots:
void server_newConnection ();
void socket_disconnected ();
void socket_readyRead ();
};
#endif // RELAY_H