-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdelivery.h
154 lines (104 loc) · 2.67 KB
/
delivery.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <stdint.h>
#include <QList>
#include <QString>
#include <QThread>
#include <QTcpServer>
#include <QTcpSocket>
class Transfer;
struct err_info;
enum msg_t
{
MSGT_hello, //!< hello banner
MSGT_login, //!< login to domain, area
MSGT_sendfilehdr, //!< send file header info
MSGT_
};
typedef struct msghdr_info
{
uint32_t type; //!< message type (msg_t)
uint32_t len; //!< total message length including header
} msghdr_info;
typedef struct msg_hello_info
{
int32_t version; //!< server version number
char salt [16]; //!< salt to use to encrypt password
} msg_hello_info;
typedef struct msg_login_info
{
char domain [32]; //!< domain to log into
char area [32]; //!< area to log into
char encrypted [16]; //!< password encrypted with given salt
} msg_login_info;
//int32_t frag_pos; //!< fragment position
//int32_t frag_size; //!< fragment size
typedef struct msg_info
{
msghdr_info hdr;
union
{
msg_login_info login;
// msg_sendfilehdr_info sendfilehdr;
char data [0];
};
} msg_info;
class Maxthread : public QThread
{
Q_OBJECT
public:
Maxthread (int fd, QObject *parent);
void run ();
protected:
/** send a message. A header is prepended.
\param type message type (msg_t)
\param msg pointer to message contents
\param size size of message contents */
void sendmsg (int type, void *msg, int size);
void processMsg (void);
public slots:
void readFromSocket (void);
signals:
void error (err_info *err);
private:
int _fd; //!< incoming file descriptor
QTcpSocket *_sock; //!< socket
msghdr_info _hdr; //!< header we have read (_hdr.len == 0 if none)
QByteArray _buff; //!< byte array buffer
};
/**
The server listens for incoming connections. The protocol is very simple:
*/
class Maxserver : public QTcpServer
{
Q_OBJECT
public:
Maxserver (QObject *parent = 0);
/** start the server */
void serve (void);
protected:
void incomingConnection (int fd);
private:
};
class Deliveryroot
{
public:
Deliveryroot (QString dir);
err_info *scan (void);
void showQueue (void);
int queueSize (void);
private:
QString _dir;
Transfer *_trans;
};
class Delivery
{
public:
Delivery ();
void addRoot (QString root);
err_info *scan (void);
void showQueues (void);
int rootCount (void) { return _roots.size (); }
void server (void);
private:
QList<Deliveryroot> _roots; //!< a list of delivery roots that we are aware of
Maxserver *_server; //!< point to server
};