-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.cpp
More file actions
63 lines (50 loc) · 1.3 KB
/
request.cpp
File metadata and controls
63 lines (50 loc) · 1.3 KB
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
#include "request.h"
Request::Request(QObject *parent) :
QObject(parent)
{
r_free = true;
}
bool Request::isFree() {
return r_free;
}
bool Request::setFree(bool status) {
r_free = status;
return true;
}
QTcpSocket* Request::getSocket() {
if(!s) {
return 0;
}
return s;
}
bool Request::setSocket(int descriptor) {
r_free = false;
s = new QTcpSocket(this);
return s->setSocketDescriptor(descriptor);
}
void Request::discardClient() {
s->deleteLater();
delete arg;
r_free = true;
}
void Request::readClient() {
QTextStream os(s);
os.setAutoDetectUnicode(true);
if(s->canReadLine()) {
QStringList tokens = QString(s->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
if(tokens.at(0) == "GET") {
QStringList path = tokens.at(1).split("?");
arg = new Arguments(this);
if(path.length() > 1) {
QStringList variables = path.at(1).split("&");
for(int i=0; i<variables.length(); i++) {
arg->set(QString(variables.at(i).split("=").at(0)), variables.at(i).split("=").at(1));
}
}
emit route(path.at(0), arg, s);
}
if (s->state() == QTcpSocket::UnconnectedState) {
delete s;
}
}
}